// File: /workspace/github_c_makefile_star2_O0/begriffs[P]pthread-test/alarm_mutex.c
// Function: main
int main(void)
{
	int status;
	char line[128];
	struct alarm *a, *next, **last;
	pthread_t thread;

	status = pthread_create(&thread, NULL, alarm_thread, NULL);
	while (printf("Alarm> ") && fgets(line, sizeof(line), stdin))
	{
		if (strlen(line) <= 1)
			continue;

		if (!(a = malloc(sizeof(*a))))
		{
			fputs("Failed to allocate alarm\n", stderr);
			return EXIT_FAILURE;
		}
		if (sscanf(line, "%d %64[^\n]", &a->seconds, a->message) < 2)
		{
			fputs("Bad command\n", stderr);
			free(a);
		}
		else
		{
			pthread_mutex_lock(&g_alarm_mutex);
			a->time = time(NULL) + a->seconds;

			/* insert alarm into ordered list */
			last = &g_alarm_list;
			next = *last;
			while (next)
			{
				if (next->time >= a->time)
				{
					a->link = next;
					*last = a;
					break;
				}
				last = &next->link;
				next = next->link;
			}
			/* if hit end of list */
			if (!next)
			{
				*last = a;
				a->link = NULL;
			}
			pthread_mutex_unlock(&g_alarm_mutex);
		}
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xc0, %rsp
movl $0x0, -0x4(%rbp)
leaq -0xb0(%rbp), %rdi
xorl %eax, %eax
movl %eax, %ecx
leaq -0x104(%rip), %rdx      # 0x1200
movq %rcx, %rsi
callq 0x10d0
movl %eax, -0x8(%rbp)
leaq 0xcf7(%rip), %rdi       # 0x200d
movb $0x0, %al
callq 0x1050
movl %eax, %ecx
xorl %eax, %eax
cmpl $0x0, %ecx
movb %al, -0xb1(%rbp)
je 0x1354
leaq -0x90(%rbp), %rdi
movq 0x2c9e(%rip), %rax      # 0x3fd8
movq (%rax), %rdx
movl $0x80, %esi
callq 0x1080
cmpq $0x0, %rax
setne %al
movb %al, -0xb1(%rbp)
movb -0xb1(%rbp), %al
testb $0x1, %al
jne 0x1363
jmp 0x14f8
leaq -0x90(%rbp), %rdi
callq 0x1040
cmpq $0x1, %rax
ja 0x1377
jmp 0x130f
movl $0x58, %edi
callq 0x10b0
movq %rax, -0x98(%rbp)
cmpq $0x0, %rax
jne 0x13b0
movq 0x2c63(%rip), %rax      # 0x3ff8
movq (%rax), %rsi
leaq 0xc76(%rip), %rdi       # 0x2015
callq 0x1060
movl $0x1, -0x4(%rbp)
jmp 0x14f8
leaq -0x90(%rbp), %rdi
movq -0x98(%rbp), %rdx
addq $0x10, %rdx
movq -0x98(%rbp), %rcx
addq $0x14, %rcx
leaq 0xc5b(%rip), %rsi       # 0x202f
movb $0x0, %al
callq 0x10c0
cmpl $0x2, %eax
jge 0x1407
movq 0x2c11(%rip), %rax      # 0x3ff8
movq (%rax), %rsi
leaq 0xc49(%rip), %rdi       # 0x203a
callq 0x1060
movq -0x98(%rbp), %rdi
callq 0x1030
jmp 0x14f3
leaq 0x2c8a(%rip), %rdi      # 0x4098
callq 0x10f0
xorl %eax, %eax
movl %eax, %edi
callq 0x1090
movq %rax, %rcx
movq -0x98(%rbp), %rax
movslq 0x10(%rax), %rax
addq %rax, %rcx
movq -0x98(%rbp), %rax
movq %rcx, 0x8(%rax)
leaq 0x2c81(%rip), %rax      # 0x40c0
movq %rax, -0xa8(%rbp)
movq -0xa8(%rbp), %rax
movq (%rax), %rax
movq %rax, -0xa0(%rbp)
cmpq $0x0, -0xa0(%rbp)
je 0x14be
movq -0xa0(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x98(%rbp), %rcx
cmpq 0x8(%rcx), %rax
jl 0x149d
movq -0xa0(%rbp), %rcx
movq -0x98(%rbp), %rax
movq %rcx, (%rax)
movq -0x98(%rbp), %rcx
movq -0xa8(%rbp), %rax
movq %rcx, (%rax)
jmp 0x14be
movq -0xa0(%rbp), %rax
movq %rax, -0xa8(%rbp)
movq -0xa0(%rbp), %rax
movq (%rax), %rax
movq %rax, -0xa0(%rbp)
jmp 0x1457
cmpq $0x0, -0xa0(%rbp)
jne 0x14e7
movq -0x98(%rbp), %rcx
movq -0xa8(%rbp), %rax
movq %rcx, (%rax)
movq -0x98(%rbp), %rax
movq $0x0, (%rax)
leaq 0x2baa(%rip), %rdi      # 0x4098
callq 0x10a0
jmp 0x130f
movl -0x4(%rbp), %eax
addq $0xc0, %rsp
popq %rbp
retq