// File: /workspace/github_c_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq (%rsi), %rdi
testq %rdi, %rdi
je 0x12c7
callq 0x19c0
leaq 0x1b9(%rip), %rdi       # 0x1487
xorl %esi, %esi
xorl %edx, %edx
callq 0x1494
testq %rax, %rax
je 0x13c4
movq %rax, %rbx
leaq 0x8(%rsp), %r14
andq $0x0, (%r14)
leaq 0x10(%rsp), %r15
andq $0x0, (%r15)
movq 0x3cdc(%rip), %rbp      # 0x4fd8
movq (%rbp), %rdx
movq %r14, %rdi
movq %r15, %rsi
callq 0x1170
movq 0x8(%rsp), %r12
cmpq $-0x1, %rax
je 0x139b
movq %rax, %r13
movq %r12, %rdi
callq 0x1090
cmpq %r13, %rax
jne 0x13e7
testq %r13, %r13
jle 0x134b
cmpb $0xa, -0x1(%r12,%r13)
jne 0x134b
movb $0x0, -0x1(%r12,%r13)
decq %r13
movq 0x8(%rsp), %r12
jmp 0x132e
movq %r12, %rdi
callq 0x1190
testq %rax, %rax
je 0x140e
movq %rbx, %rdi
movq %rax, %rsi
callq 0x1685
testl %eax, %eax
je 0x12fc
leaq 0x1cce(%rip), %rdi      # 0x3040
xorl %eax, %eax
callq 0x1bcc
callq 0x1060
andl $0x0, (%rax)
jmp 0x1463
movq %rax, %rdi
callq 0x1070
movq %rbx, %rdi
callq 0x194e
movq 0x8(%rsp), %r12
movq %r12, %rdi
callq 0x1030
movq %rbx, %rdi
callq 0x1779
movq %rax, 0x8(%rsp)
testq %rax, %rax
jne 0x1386
movq %rbx, %rdi
callq 0x19a4
xorl %eax, %eax
jmp 0x1478
callq 0x1060
cmpl $0x0, (%rax)
je 0x142f
movq %rax, %rbx
leaq 0x1c2c(%rip), %rdi      # 0x3004
xorl %eax, %eax
callq 0x1a3d
andl $0x0, (%rbx)
jmp 0x1475
callq 0x1060
cmpl $0x0, (%rax)
je 0x143f
movq %rax, %r14
leaq 0x1c16(%rip), %rdi      # 0x3011
movq %r13, %rsi
movq %r12, %rdx
xorl %eax, %eax
callq 0x1a3d
andl $0x0, (%r14)
jmp 0x146d
callq 0x1060
cmpl $0x0, (%rax)
je 0x1455
movq %rax, %r14
leaq 0x1c17(%rip), %rdi      # 0x3039
xorl %eax, %eax
callq 0x1a3d
andl $0x0, (%r14)
jmp 0x1463
leaq 0x1bce(%rip), %rdi      # 0x3004
xorl %eax, %eax
callq 0x1bcc
jmp 0x1475
leaq 0x1bcb(%rip), %rdi      # 0x3011
movq %r13, %rsi
movq %r12, %rdx
xorl %eax, %eax
callq 0x1bcc
jmp 0x146d
leaq 0x1bdd(%rip), %rdi      # 0x3039
xorl %eax, %eax
callq 0x1bcc
movq 0x8(%rsp), %rdi
callq 0x1030
movq %rbx, %rdi
callq 0x19a4
pushq $0x1
popq %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq