	.file	"190691.c"
	.intel_syntax noprefix
	.text
	.globl	countAs
	.bss
	.align 4
	.type	countAs, @object
	.size	countAs, 4
countAs:
	.zero	4
	.globl	countBs
	.align 4
	.type	countBs, @object
	.size	countBs, 4
countBs:
	.zero	4
	.globl	mutex
	.align 32
	.type	mutex, @object
	.size	mutex, 32
mutex:
	.zero	32
	.globl	as
	.align 32
	.type	as, @object
	.size	as, 32
as:
	.zero	32
	.globl	bs
	.align 32
	.type	bs, @object
	.size	bs, 32
bs:
	.zero	32
	.globl	inCriticalSection
	.type	inCriticalSection, @object
	.size	inCriticalSection, 1
inCriticalSection:
	.zero	1
	.section	.rodata
.LC0:
	.string	"%dA %dB "
.LC1:
	.string	"no threads waiting"
.LC2:
	.string	"releasing an A"
.LC3:
	.string	"releasing an B"
	.text
	.globl	pickThreadToRelease
	.type	pickThreadToRelease, @function
pickThreadToRelease:
.LFB6:
	.cfi_startproc
	endbr64
	push	rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	mov	rbp, rsp
	.cfi_def_cfa_register 6
	lea	rdi, mutex[rip]
	call	sem_wait@PLT
	mov	edx, DWORD PTR countBs[rip]
	mov	eax, DWORD PTR countAs[rip]
	mov	esi, eax
	lea	rdi, .LC0[rip]
	mov	eax, 0
	call	printf@PLT
	mov	eax, DWORD PTR countAs[rip]
	test	eax, eax
	jne	.L2
	mov	eax, DWORD PTR countBs[rip]
	test	eax, eax
	jne	.L2
	lea	rdi, .LC1[rip]
	call	puts@PLT
	mov	BYTE PTR inCriticalSection[rip], 0
	jmp	.L3
.L2:
	mov	edx, DWORD PTR countAs[rip]
	mov	eax, DWORD PTR countBs[rip]
	cmp	edx, eax
	jl	.L4
	mov	eax, DWORD PTR countAs[rip]
	sub	eax, 1
	mov	DWORD PTR countAs[rip], eax
	lea	rdi, .LC2[rip]
	call	puts@PLT
	lea	rdi, as[rip]
	call	sem_post@PLT
	jmp	.L3
.L4:
	mov	eax, DWORD PTR countBs[rip]
	sub	eax, 1
	mov	DWORD PTR countBs[rip], eax
	lea	rdi, .LC3[rip]
	call	puts@PLT
	lea	rdi, bs[rip]
	call	sem_post@PLT
.L3:
	lea	rdi, mutex[rip]
	call	sem_post@PLT
	nop
	pop	rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE6:
	.size	pickThreadToRelease, .-pickThreadToRelease
	.section	.rodata
	.align 8
.LC4:
	.string	"A thread entering critical section"
	.align 8
.LC5:
	.string	"A thread leaving critical section"
	.text
	.globl	politeA
	.type	politeA, @function
politeA:
.LFB7:
	.cfi_startproc
	endbr64
	push	rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	mov	rbp, rsp
	.cfi_def_cfa_register 6
	sub	rsp, 16
	mov	QWORD PTR -8[rbp], rdi
	lea	rdi, mutex[rip]
	call	sem_wait@PLT
	movzx	eax, BYTE PTR inCriticalSection[rip]
	xor	eax, 1
	test	al, al
	je	.L6
	mov	BYTE PTR inCriticalSection[rip], 1
	lea	rdi, mutex[rip]
	call	sem_post@PLT
	jmp	.L7
.L6:
	mov	eax, DWORD PTR countAs[rip]
	add	eax, 1
	mov	DWORD PTR countAs[rip], eax
	lea	rdi, mutex[rip]
	call	sem_post@PLT
	lea	rdi, as[rip]
	call	sem_wait@PLT
.L7:
	lea	rdi, .LC4[rip]
	call	puts@PLT
	mov	edi, 1
	call	sleep@PLT
	lea	rdi, .LC5[rip]
	call	puts@PLT
	mov	eax, 0
	call	pickThreadToRelease
	mov	eax, 0
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE7:
	.size	politeA, .-politeA
	.section	.rodata
	.align 8
.LC6:
	.string	"B thread entering critical section"
	.align 8
.LC7:
	.string	"B thread leaving critical section"
	.text
	.globl	politeB
	.type	politeB, @function
politeB:
.LFB8:
	.cfi_startproc
	endbr64
	push	rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	mov	rbp, rsp
	.cfi_def_cfa_register 6
	sub	rsp, 16
	mov	QWORD PTR -8[rbp], rdi
	lea	rdi, mutex[rip]
	call	sem_wait@PLT
	movzx	eax, BYTE PTR inCriticalSection[rip]
	xor	eax, 1
	test	al, al
	je	.L10
	mov	BYTE PTR inCriticalSection[rip], 1
	lea	rdi, mutex[rip]
	call	sem_post@PLT
	jmp	.L11
.L10:
	mov	eax, DWORD PTR countBs[rip]
	add	eax, 1
	mov	DWORD PTR countBs[rip], eax
	lea	rdi, mutex[rip]
	call	sem_post@PLT
	lea	rdi, bs[rip]
	call	sem_wait@PLT
.L11:
	lea	rdi, .LC6[rip]
	call	puts@PLT
	mov	edi, 1
	call	sleep@PLT
	lea	rdi, .LC7[rip]
	call	puts@PLT
	mov	eax, 0
	call	pickThreadToRelease
	mov	eax, 0
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE8:
	.size	politeB, .-politeB
	.section	.rodata
.LC8:
	.string	"Everything finished."
	.text
	.globl	main
	.type	main, @function
main:
.LFB9:
	.cfi_startproc
	endbr64
	push	rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	mov	rbp, rsp
	.cfi_def_cfa_register 6
	sub	rsp, 848
	mov	DWORD PTR -836[rbp], edi
	mov	QWORD PTR -848[rbp], rsi
	mov	rax, QWORD PTR fs:40
	mov	QWORD PTR -8[rbp], rax
	xor	eax, eax
	mov	DWORD PTR -820[rbp], 0
	mov	edx, 0
	mov	esi, 0
	lea	rdi, as[rip]
	call	sem_init@PLT
	mov	edx, 0
	mov	esi, 0
	lea	rdi, bs[rip]
	call	sem_init@PLT
	mov	edx, 1
	mov	esi, 0
	lea	rdi, mutex[rip]
	call	sem_init@PLT
	mov	DWORD PTR countAs[rip], 0
	mov	DWORD PTR countBs[rip], 0
	mov	BYTE PTR inCriticalSection[rip], 0
	lea	rdx, -816[rbp]
	mov	eax, DWORD PTR -820[rbp]
	cdqe
	sal	rax, 3
	add	rax, rdx
	mov	ecx, 0
	lea	rdx, politeA[rip]
	mov	esi, 0
	mov	rdi, rax
	call	pthread_create@PLT
	add	DWORD PTR -820[rbp], 1
	lea	rdx, -816[rbp]
	mov	eax, DWORD PTR -820[rbp]
	cdqe
	sal	rax, 3
	add	rax, rdx
	mov	ecx, 0
	lea	rdx, politeB[rip]
	mov	esi, 0
	mov	rdi, rax
	call	pthread_create@PLT
	add	DWORD PTR -820[rbp], 1
	mov	edi, 1
	call	sleep@PLT
	lea	rdx, -816[rbp]
	mov	eax, DWORD PTR -820[rbp]
	cdqe
	sal	rax, 3
	add	rax, rdx
	mov	ecx, 0
	lea	rdx, politeA[rip]
	mov	esi, 0
	mov	rdi, rax
	call	pthread_create@PLT
	add	DWORD PTR -820[rbp], 1
	lea	rdx, -816[rbp]
	mov	eax, DWORD PTR -820[rbp]
	cdqe
	sal	rax, 3
	add	rax, rdx
	mov	ecx, 0
	lea	rdx, politeB[rip]
	mov	esi, 0
	mov	rdi, rax
	call	pthread_create@PLT
	add	DWORD PTR -820[rbp], 1
	lea	rdx, -816[rbp]
	mov	eax, DWORD PTR -820[rbp]
	cdqe
	sal	rax, 3
	add	rax, rdx
	mov	ecx, 0
	lea	rdx, politeA[rip]
	mov	esi, 0
	mov	rdi, rax
	call	pthread_create@PLT
	add	DWORD PTR -820[rbp], 1
	lea	rdx, -816[rbp]
	mov	eax, DWORD PTR -820[rbp]
	cdqe
	sal	rax, 3
	add	rax, rdx
	mov	ecx, 0
	lea	rdx, politeA[rip]
	mov	esi, 0
	mov	rdi, rax
	call	pthread_create@PLT
	add	DWORD PTR -820[rbp], 1
	mov	DWORD PTR -824[rbp], 0
	jmp	.L14
.L15:
	mov	eax, DWORD PTR -824[rbp]
	cdqe
	mov	rax, QWORD PTR -816[rbp+rax*8]
	mov	esi, 0
	mov	rdi, rax
	call	pthread_join@PLT
	add	DWORD PTR -824[rbp], 1
.L14:
	mov	eax, DWORD PTR -824[rbp]
	cmp	eax, DWORD PTR -820[rbp]
	jl	.L15
	lea	rdi, .LC8[rip]
	call	puts@PLT
	mov	eax, 0
	mov	rcx, QWORD PTR -8[rbp]
	sub	rcx, QWORD PTR fs:40
	je	.L17
	call	__stack_chk_fail@PLT
.L17:
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE9:
	.size	main, .-main
	.ident	"GCC: (Ubuntu 10.5.0-1ubuntu1~20.04) 10.5.0"
	.section	.note.GNU-stack,"",@progbits
	.section	.note.gnu.property,"a"
	.align 8
	.long	 1f - 0f
	.long	 4f - 1f
	.long	 5
0:
	.string	 "GNU"
1:
	.align 8
	.long	 0xc0000002
	.long	 3f - 2f
2:
	.long	 0x3
3:
	.align 8
4:

	.arch armv5t
	.eabi_attribute 20, 1
	.eabi_attribute 21, 1
	.eabi_attribute 23, 3
	.eabi_attribute 24, 1
	.eabi_attribute 25, 1
	.eabi_attribute 26, 2
	.eabi_attribute 30, 6
	.eabi_attribute 34, 0
	.eabi_attribute 18, 4
	.file	"190691.c"
	.text
	.comm	countAs,4,4
	.comm	countBs,4,4
	.comm	mutex,16,4
	.comm	as,16,4
	.comm	bs,16,4
	.comm	inCriticalSection,1,1
	.section	.rodata
	.align	2
.LC0:
	.ascii	"%dA %dB \000"
	.align	2
.LC1:
	.ascii	"no threads waiting\000"
	.align	2
.LC2:
	.ascii	"releasing an A\000"
	.align	2
.LC3:
	.ascii	"releasing an B\000"
	.text
	.align	2
	.global	pickThreadToRelease
	.syntax unified
	.arm
	.fpu softvfp
	.type	pickThreadToRelease, %function
pickThreadToRelease:
	@ args = 0, pretend = 0, frame = 0
	@ frame_needed = 1, uses_anonymous_args = 0
	push	{fp, lr}
	add	fp, sp, #4
	ldr	r0, .L5
	bl	sem_wait
	ldr	r3, .L5+4
	ldr	r3, [r3]
	ldr	r2, .L5+8
	ldr	r2, [r2]
	mov	r1, r3
	ldr	r0, .L5+12
	bl	printf
	ldr	r3, .L5+4
	ldr	r3, [r3]
	cmp	r3, #0
	bne	.L2
	ldr	r3, .L5+8
	ldr	r3, [r3]
	cmp	r3, #0
	bne	.L2
	ldr	r0, .L5+16
	bl	puts
	ldr	r3, .L5+20
	mov	r2, #0
	strb	r2, [r3]
	b	.L3
.L2:
	ldr	r3, .L5+4
	ldr	r2, [r3]
	ldr	r3, .L5+8
	ldr	r3, [r3]
	cmp	r2, r3
	blt	.L4
	ldr	r3, .L5+4
	ldr	r3, [r3]
	sub	r3, r3, #1
	ldr	r2, .L5+4
	str	r3, [r2]
	ldr	r0, .L5+24
	bl	puts
	ldr	r0, .L5+28
	bl	sem_post
	b	.L3
.L4:
	ldr	r3, .L5+8
	ldr	r3, [r3]
	sub	r3, r3, #1
	ldr	r2, .L5+8
	str	r3, [r2]
	ldr	r0, .L5+32
	bl	puts
	ldr	r0, .L5+36
	bl	sem_post
.L3:
	ldr	r0, .L5
	bl	sem_post
	nop
	pop	{fp, pc}
.L6:
	.align	2
.L5:
	.word	mutex
	.word	countAs
	.word	countBs
	.word	.LC0
	.word	.LC1
	.word	inCriticalSection
	.word	.LC2
	.word	as
	.word	.LC3
	.word	bs
	.size	pickThreadToRelease, .-pickThreadToRelease
	.section	.rodata
	.align	2
.LC4:
	.ascii	"A thread entering critical section\000"
	.align	2
.LC5:
	.ascii	"A thread leaving critical section\000"
	.text
	.align	2
	.global	politeA
	.syntax unified
	.arm
	.fpu softvfp
	.type	politeA, %function
politeA:
	@ args = 0, pretend = 0, frame = 8
	@ frame_needed = 1, uses_anonymous_args = 0
	push	{fp, lr}
	add	fp, sp, #4
	sub	sp, sp, #8
	str	r0, [fp, #-8]
	ldr	r0, .L11
	bl	sem_wait
	ldr	r3, .L11+4
	ldrb	r3, [r3]	@ zero_extendqisi2
	eor	r3, r3, #1
	and	r3, r3, #255
	cmp	r3, #0
	beq	.L8
	ldr	r3, .L11+4
	mov	r2, #1
	strb	r2, [r3]
	ldr	r0, .L11
	bl	sem_post
	b	.L9
.L8:
	ldr	r3, .L11+8
	ldr	r3, [r3]
	add	r3, r3, #1
	ldr	r2, .L11+8
	str	r3, [r2]
	ldr	r0, .L11
	bl	sem_post
	ldr	r0, .L11+12
	bl	sem_wait
.L9:
	ldr	r0, .L11+16
	bl	puts
	mov	r0, #1
	bl	sleep
	ldr	r0, .L11+20
	bl	puts
	bl	pickThreadToRelease
	mov	r3, #0
	mov	r0, r3
	sub	sp, fp, #4
	@ sp needed
	pop	{fp, pc}
.L12:
	.align	2
.L11:
	.word	mutex
	.word	inCriticalSection
	.word	countAs
	.word	as
	.word	.LC4
	.word	.LC5
	.size	politeA, .-politeA
	.section	.rodata
	.align	2
.LC6:
	.ascii	"B thread entering critical section\000"
	.align	2
.LC7:
	.ascii	"B thread leaving critical section\000"
	.text
	.align	2
	.global	politeB
	.syntax unified
	.arm
	.fpu softvfp
	.type	politeB, %function
politeB:
	@ args = 0, pretend = 0, frame = 8
	@ frame_needed = 1, uses_anonymous_args = 0
	push	{fp, lr}
	add	fp, sp, #4
	sub	sp, sp, #8
	str	r0, [fp, #-8]
	ldr	r0, .L17
	bl	sem_wait
	ldr	r3, .L17+4
	ldrb	r3, [r3]	@ zero_extendqisi2
	eor	r3, r3, #1
	and	r3, r3, #255
	cmp	r3, #0
	beq	.L14
	ldr	r3, .L17+4
	mov	r2, #1
	strb	r2, [r3]
	ldr	r0, .L17
	bl	sem_post
	b	.L15
.L14:
	ldr	r3, .L17+8
	ldr	r3, [r3]
	add	r3, r3, #1
	ldr	r2, .L17+8
	str	r3, [r2]
	ldr	r0, .L17
	bl	sem_post
	ldr	r0, .L17+12
	bl	sem_wait
.L15:
	ldr	r0, .L17+16
	bl	puts
	mov	r0, #1
	bl	sleep
	ldr	r0, .L17+20
	bl	puts
	bl	pickThreadToRelease
	mov	r3, #0
	mov	r0, r3
	sub	sp, fp, #4
	@ sp needed
	pop	{fp, pc}
.L18:
	.align	2
.L17:
	.word	mutex
	.word	inCriticalSection
	.word	countBs
	.word	bs
	.word	.LC6
	.word	.LC7
	.size	politeB, .-politeB
	.section	.rodata
	.align	2
.LC8:
	.ascii	"Everything finished.\000"
	.align	2
.LC9:
	.word	__stack_chk_guard
	.text
	.align	2
	.global	main
	.syntax unified
	.arm
	.fpu softvfp
	.type	main, %function
main:
	@ args = 0, pretend = 0, frame = 424
	@ frame_needed = 1, uses_anonymous_args = 0
	push	{fp, lr}
	add	fp, sp, #4
	sub	sp, sp, #424
	str	r0, [fp, #-424]
	str	r1, [fp, #-428]
	ldr	r3, .L24
	ldr	r3, [r3]
	str	r3, [fp, #-8]
	mov	r3,#0
	mov	r3, #0
	str	r3, [fp, #-412]
	mov	r2, #0
	mov	r1, #0
	ldr	r0, .L24+4
	bl	sem_init
	mov	r2, #0
	mov	r1, #0
	ldr	r0, .L24+8
	bl	sem_init
	mov	r2, #1
	mov	r1, #0
	ldr	r0, .L24+12
	bl	sem_init
	ldr	r3, .L24+16
	mov	r2, #0
	str	r2, [r3]
	ldr	r3, .L24+20
	mov	r2, #0
	str	r2, [r3]
	ldr	r3, .L24+24
	mov	r2, #0
	strb	r2, [r3]
	sub	r2, fp, #408
	ldr	r3, [fp, #-412]
	lsl	r3, r3, #2
	add	r0, r2, r3
	mov	r3, #0
	ldr	r2, .L24+28
	mov	r1, #0
	bl	pthread_create
	ldr	r3, [fp, #-412]
	add	r3, r3, #1
	str	r3, [fp, #-412]
	sub	r2, fp, #408
	ldr	r3, [fp, #-412]
	lsl	r3, r3, #2
	add	r0, r2, r3
	mov	r3, #0
	ldr	r2, .L24+32
	mov	r1, #0
	bl	pthread_create
	ldr	r3, [fp, #-412]
	add	r3, r3, #1
	str	r3, [fp, #-412]
	mov	r0, #1
	bl	sleep
	sub	r2, fp, #408
	ldr	r3, [fp, #-412]
	lsl	r3, r3, #2
	add	r0, r2, r3
	mov	r3, #0
	ldr	r2, .L24+28
	mov	r1, #0
	bl	pthread_create
	ldr	r3, [fp, #-412]
	add	r3, r3, #1
	str	r3, [fp, #-412]
	sub	r2, fp, #408
	ldr	r3, [fp, #-412]
	lsl	r3, r3, #2
	add	r0, r2, r3
	mov	r3, #0
	ldr	r2, .L24+32
	mov	r1, #0
	bl	pthread_create
	ldr	r3, [fp, #-412]
	add	r3, r3, #1
	str	r3, [fp, #-412]
	sub	r2, fp, #408
	ldr	r3, [fp, #-412]
	lsl	r3, r3, #2
	add	r0, r2, r3
	mov	r3, #0
	ldr	r2, .L24+28
	mov	r1, #0
	bl	pthread_create
	ldr	r3, [fp, #-412]
	add	r3, r3, #1
	str	r3, [fp, #-412]
	sub	r2, fp, #408
	ldr	r3, [fp, #-412]
	lsl	r3, r3, #2
	add	r0, r2, r3
	mov	r3, #0
	ldr	r2, .L24+28
	mov	r1, #0
	bl	pthread_create
	ldr	r3, [fp, #-412]
	add	r3, r3, #1
	str	r3, [fp, #-412]
	mov	r3, #0
	str	r3, [fp, #-416]
	b	.L20
.L21:
	ldr	r3, [fp, #-416]
	lsl	r3, r3, #2
	sub	r2, fp, #4
	add	r3, r2, r3
	ldr	r3, [r3, #-404]
	mov	r1, #0
	mov	r0, r3
	bl	pthread_join
	ldr	r3, [fp, #-416]
	add	r3, r3, #1
	str	r3, [fp, #-416]
.L20:
	ldr	r2, [fp, #-416]
	ldr	r3, [fp, #-412]
	cmp	r2, r3
	blt	.L21
	ldr	r0, .L24+36
	bl	puts
	mov	r3, #0
	ldr	r2, .L24
	ldr	r1, [r2]
	ldr	r2, [fp, #-8]
	eors	r1, r2, r1
	mov	r2, #0
	beq	.L23
	bl	__stack_chk_fail
.L23:
	mov	r0, r3
	sub	sp, fp, #4
	@ sp needed
	pop	{fp, pc}
.L25:
	.align	2
.L24:
	.word	.LC9
	.word	as
	.word	bs
	.word	mutex
	.word	countAs
	.word	countBs
	.word	inCriticalSection
	.word	politeA
	.word	politeB
	.word	.LC8
	.size	main, .-main
	.ident	"GCC: (Ubuntu 9.4.0-1ubuntu1~20.04.2) 9.4.0"
	.section	.note.GNU-stack,"",%progbits
