// File: /workspace/github_c_makefile_star2_O0/Tarsnap[P]libcperciva/tests/heap/main.c
// Function: main
int
main(int argc, char * argv[])
{
	struct ptrheap * H;
	char * s, * dups;
	size_t buflen;
	ssize_t l;

	WARNP_INIT;

	(void)argc; /* UNUSED */
	(void)argv; /* UNUSED */

	/* Create a heap. */
	if ((H = ptrheap_init(compar, NULL, NULL)) == 0) {
		warnp("ptrheap_init");
		goto err0;
	}

	/* Suck in the input. */
	s = NULL;
	buflen = 0;
	while ((l = getline(&s, &buflen, stdin)) != -1) {
		/* Check for embedded NUL characters. */
		if (strlen(s) != (size_t)l) {
			warnp("Line of length %zu has embedded NUL: %s",
			    (size_t)l, s);
			goto err1;
		}

		/* Remove trailing '\n'. */
		while ((l > 0) && (s[l - 1] == '\n'))
			s[--l] = '\0';

		/* Duplicate string. */
		if ((dups = strdup(s)) == NULL) {
			warnp("strdup");
			goto err2;
		}

		/* Insert string. */
		if (ptrheap_add(H, dups)) {
			warn0("ptrheap_add");
			goto err2;
		}
	}

	/* Free string allocated by getline. */
	free(s);

	/* Write out the lines in order. */
	while ((s = ptrheap_getmin(H)) != NULL) {
		printf("%s\n", s);
		ptrheap_deletemin(H);
		free(s);
	}

	/* Free the heap. */
	ptrheap_free(H);

	/* Success! */
	return (0);

err2:
	free(s);
err1:
	ptrheap_free(H);
err0:
	/* Failure! */
	return (1);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x10(%rbp), %rax
cmpq $0x0, (%rax)
je 0x129c
movq -0x10(%rbp), %rax
movq (%rax), %rdi
callq 0x1f00
jmp 0x129e
leaq 0x22b(%rip), %rdi       # 0x14d0
xorl %eax, %eax
movl %eax, %edx
movq %rdx, %rsi
callq 0x1510
movq %rax, -0x18(%rbp)
cmpq $0x0, %rax
jne 0x12f7
jmp 0x12bd
callq 0x1060
cmpl $0x0, (%rax)
je 0x12e2
leaq 0x1d36(%rip), %rdi      # 0x3004
movb $0x0, %al
callq 0x1fc0
callq 0x1060
movl $0x0, (%rax)
jmp 0x12f0
leaq 0x1d1b(%rip), %rdi      # 0x3004
movb $0x0, %al
callq 0x2210
jmp 0x12f2
jmp 0x14ba
movq $0x0, -0x20(%rbp)
movq $0x0, -0x30(%rbp)
movq 0x3cca(%rip), %rax      # 0x4fd8
movq (%rax), %rdx
leaq -0x20(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x1140
movq %rax, -0x38(%rbp)
cmpq $-0x1, %rax
je 0x1454
movq -0x20(%rbp), %rdi
callq 0x1080
cmpq -0x38(%rbp), %rax
je 0x1387
jmp 0x133d
callq 0x1060
cmpl $0x0, (%rax)
je 0x136a
movq -0x38(%rbp), %rsi
movq -0x20(%rbp), %rdx
leaq 0x1cbb(%rip), %rdi      # 0x3011
movb $0x0, %al
callq 0x1fc0
callq 0x1060
movl $0x0, (%rax)
jmp 0x1380
movq -0x38(%rbp), %rsi
movq -0x20(%rbp), %rdx
leaq 0x1c98(%rip), %rdi      # 0x3011
movb $0x0, %al
callq 0x2210
jmp 0x1382
jmp 0x14b1
jmp 0x1389
xorl %eax, %eax
cmpq $0x0, -0x38(%rbp)
movb %al, -0x39(%rbp)
jle 0x13ae
movq -0x20(%rbp), %rax
movq -0x38(%rbp), %rcx
subq $0x1, %rcx
movsbl (%rax,%rcx), %eax
cmpl $0xa, %eax
sete %al
movb %al, -0x39(%rbp)
movb -0x39(%rbp), %al
testb $0x1, %al
jne 0x13b7
jmp 0x13d1
movq -0x20(%rbp), %rax
movq -0x38(%rbp), %rcx
movq %rcx, %rdx
addq $-0x1, %rdx
movq %rdx, -0x38(%rbp)
movb $0x0, -0x1(%rax,%rcx)
jmp 0x1389
movq -0x20(%rbp), %rdi
callq 0x1150
movq %rax, -0x28(%rbp)
cmpq $0x0, %rax
jne 0x1420
jmp 0x13e6
callq 0x1060
cmpl $0x0, (%rax)
je 0x140b
leaq 0x1c42(%rip), %rdi      # 0x3039
movb $0x0, %al
callq 0x1fc0
callq 0x1060
movl $0x0, (%rax)
jmp 0x1419
leaq 0x1c27(%rip), %rdi      # 0x3039
movb $0x0, %al
callq 0x2210
jmp 0x141b
jmp 0x14a8
movq -0x18(%rbp), %rdi
movq -0x28(%rbp), %rsi
callq 0x18b0
cmpl $0x0, %eax
je 0x144f
jmp 0x1434
leaq 0x1c05(%rip), %rdi      # 0x3040
movb $0x0, %al
callq 0x2210
callq 0x1060
movl $0x0, (%rax)
jmp 0x14a8
jmp 0x1307
movq -0x20(%rbp), %rdi
callq 0x1030
movq -0x18(%rbp), %rdi
callq 0x1a60
movq %rax, -0x20(%rbp)
cmpq $0x0, %rax
je 0x1496
movq -0x20(%rbp), %rsi
leaq 0x1be2(%rip), %rdi      # 0x305d
movb $0x0, %al
callq 0x1090
movq -0x18(%rbp), %rdi
callq 0x1da0
movq -0x20(%rbp), %rdi
callq 0x1030
jmp 0x145d
movq -0x18(%rbp), %rdi
callq 0x1ea0
movl $0x0, -0x4(%rbp)
jmp 0x14c1
movq -0x20(%rbp), %rdi
callq 0x1030
movq -0x18(%rbp), %rdi
callq 0x1ea0
movl $0x1, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x40, %rsp
popq %rbp
retq
nopw (%rax,%rax)