// File: /workspace/github_c_makefile_star2_O3/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 0x13e7
callq 0x1b80
leaq 0x1d9(%rip), %rdi       # 0x15c7
xorl %esi, %esi
xorl %edx, %edx
callq 0x15d4
testq %rax, %rax
je 0x14b5
movq %rax, %rbx
xorl %eax, %eax
leaq 0x8(%rsp), %r14
movq %rax, (%r14)
leaq 0x10(%rsp), %r15
movq %rax, (%r15)
movq 0x3bbc(%rip), %rbp      # 0x4fd8
movq (%rbp), %rdx
movq %r14, %rdi
movq %r15, %rsi
callq 0x1170
movq 0x8(%rsp), %r13
cmpq $-0x1, %rax
je 0x14df
movq %rax, %r12
movq %r13, %rdi
callq 0x1090
cmpq %r12, %rax
jne 0x151f
testq %r12, %r12
jle 0x1477
incq %r12
movq 0x8(%rsp), %r13
cmpb $0xa, -0x2(%r13,%r12)
jne 0x1477
movb $0x0, -0x2(%r13,%r12)
decq %r12
cmpq $0x1, %r12
jg 0x1456
movq 0x8(%rsp), %r13
movq %r13, %rdi
callq 0x1190
testq %rax, %rax
je 0x1549
movq %rbx, %rdi
movq %rax, %rsi
callq 0x17e7
testl %eax, %eax
je 0x141c
leaq 0x1ba2(%rip), %rdi      # 0x3040
xorl %eax, %eax
callq 0x1d1f
callq 0x1060
movl $0x0, (%rax)
jmp 0x15a1
callq 0x1060
cmpl $0x0, (%rax)
je 0x156d
movq %rax, %rbx
leaq 0x1b37(%rip), %rdi      # 0x3004
xorl %eax, %eax
callq 0x1c00
movl $0x0, (%rbx)
jmp 0x15b3
movq %r13, %rdi
callq 0x1030
movq %rbx, %rdi
callq 0x18f8
movq %rax, 0x8(%rsp)
testq %rax, %rax
je 0x1510
movq %rax, %rdi
callq 0x1070
movq %rbx, %rdi
callq 0x1b0d
movq 0x8(%rsp), %rdi
jmp 0x14e2
movq %rbx, %rdi
callq 0x1b63
xorl %eax, %eax
jmp 0x15b8
callq 0x1060
cmpl $0x0, (%rax)
je 0x157d
movq %rax, %r14
leaq 0x1ade(%rip), %rdi      # 0x3011
movq %r12, %rsi
movq %r13, %rdx
xorl %eax, %eax
callq 0x1c00
movl $0x0, (%r14)
jmp 0x15ab
callq 0x1060
cmpl $0x0, (%rax)
je 0x1593
movq %rax, %r14
leaq 0x1adc(%rip), %rdi      # 0x3039
xorl %eax, %eax
callq 0x1c00
movl $0x0, (%r14)
jmp 0x15a1
leaq 0x1a90(%rip), %rdi      # 0x3004
xorl %eax, %eax
callq 0x1d1f
jmp 0x15b3
leaq 0x1a8d(%rip), %rdi      # 0x3011
movq %r12, %rsi
movq %r13, %rdx
xorl %eax, %eax
callq 0x1d1f
jmp 0x15ab
leaq 0x1a9f(%rip), %rdi      # 0x3039
xorl %eax, %eax
callq 0x1d1f
movq 0x8(%rsp), %rdi
callq 0x1030
movq %rbx, %rdi
callq 0x1b63
movl $0x1, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq