// File: /workspace/github_c_makefile_star2_O1/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 0x13d7
callq 0x1b5c
leaq 0x1d6(%rip), %rdi       # 0x15b4
xorl %esi, %esi
xorl %edx, %edx
callq 0x15c0
testq %rax, %rax
je 0x14a2
movq %rax, %rbx
xorl %eax, %eax
leaq 0x8(%rsp), %r14
movq %rax, (%r14)
leaq 0x10(%rsp), %r15
movq %rax, (%r15)
movq 0x3bcc(%rip), %rbp      # 0x4fd8
movq (%rbp), %rdx
movq %r14, %rdi
movq %r15, %rsi
callq 0x1160
movq 0x8(%rsp), %r13
cmpq $-0x1, %rax
je 0x14cc
movq %rax, %r12
movq %r13, %rdi
callq 0x1090
cmpq %r12, %rax
jne 0x150c
testq %r12, %r12
jle 0x1462
incq %r12
movq 0x8(%rsp), %rax
cmpb $0xa, -0x2(%rax,%r12)
jne 0x1462
movb $0x0, -0x2(%rax,%r12)
decq %r12
cmpq $0x1, %r12
jg 0x1446
movq 0x8(%rsp), %rdi
callq 0x1180
testq %rax, %rax
je 0x1536
movq %rbx, %rdi
movq %rax, %rsi
callq 0x17d5
testl %eax, %eax
je 0x140c
leaq 0x1bb5(%rip), %rdi      # 0x3040
xorl %eax, %eax
callq 0x1cfb
callq 0x1060
movl $0x0, (%rax)
jmp 0x158e
callq 0x1060
cmpl $0x0, (%rax)
je 0x155a
movq %rax, %rbx
leaq 0x1b4a(%rip), %rdi      # 0x3004
xorl %eax, %eax
callq 0x1bdc
movl $0x0, (%rbx)
jmp 0x15a0
movq %r13, %rdi
callq 0x1030
movq %rbx, %rdi
callq 0x18db
movq %rax, 0x8(%rsp)
testq %rax, %rax
je 0x14fd
movq %rax, %rdi
callq 0x1070
movq %rbx, %rdi
callq 0x1aea
movq 0x8(%rsp), %rdi
jmp 0x14cf
movq %rbx, %rdi
callq 0x1b40
xorl %eax, %eax
jmp 0x15a5
callq 0x1060
cmpl $0x0, (%rax)
je 0x156a
movq %rax, %r14
leaq 0x1af1(%rip), %rdi      # 0x3011
movq %r12, %rsi
movq %r13, %rdx
xorl %eax, %eax
callq 0x1bdc
movl $0x0, (%r14)
jmp 0x1598
callq 0x1060
cmpl $0x0, (%rax)
je 0x1580
movq %rax, %r14
leaq 0x1aef(%rip), %rdi      # 0x3039
xorl %eax, %eax
callq 0x1bdc
movl $0x0, (%r14)
jmp 0x158e
leaq 0x1aa3(%rip), %rdi      # 0x3004
xorl %eax, %eax
callq 0x1cfb
jmp 0x15a0
leaq 0x1aa0(%rip), %rdi      # 0x3011
movq %r12, %rsi
movq %r13, %rdx
xorl %eax, %eax
callq 0x1cfb
jmp 0x1598
leaq 0x1ab2(%rip), %rdi      # 0x3039
xorl %eax, %eax
callq 0x1cfb
movq 0x8(%rsp), %rdi
callq 0x1030
movq %rbx, %rdi
callq 0x1b40
movl $0x1, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq