// File: /workspace/github_c_makefile_star2_O1/Tarsnap[P]kivaloo/kvlds-undump/main.c
// Function: callback_pair
static int
callback_pair(void * cookie, struct kvldskey ** key, struct kvldskey ** value)
{
	struct undumpstate * C = cookie;
	struct dirent * d;
	uint8_t len;
	uint8_t buf[255];

	/* Filesystem or stdout? */
	if (C->d != NULL) {
		/* Find a directory. */
		do {
			errno = 0;
			if ((d = readdir(C->d)) == NULL) {
				if (errno == 0)
					goto nomore;
				warnp("readdir");
				goto err0;
			}

			/* Skip "." and "..". */
			if ((strcmp(d->d_name, ".") != 0) &&
			    (strcmp(d->d_name, "..") != 0))
				break;
		} while (1);

		/* Read key and value. */
		if ((*key = readfile(d->d_name, "k")) == NULL)
			goto err0;
		if ((*value = readfile(d->d_name, "v")) == NULL)
			goto err1;
	} else {
		/* Read key from stdin. */
		if (fread(&len, 1, 1, stdin) != 1) {
			if (feof(stdin))
				goto nomore;
			goto err0;
		}
		/*
		 * len is uint8_t, so it will be 0..255 (inclusive).
		 * Read that many bytes from stdin; we don't accept eof here
		 * because that would indicate a buffer underrun in buf.
		 */
		if (fread(&buf, len, 1, stdin) != 1)
			goto err0;
		if ((*key = kvldskey_create(buf, len)) == NULL)
			goto err0;

		/* Read value from stdin (same security rationale as above). */
		if (fread(&len, 1, 1, stdin) != 1)
			goto err1;
		if (fread(&buf, len, 1, stdin) != 1)
			goto err1;
		if ((*value = kvldskey_create(buf, len)) == NULL)
			goto err1;
	}

	/* Done another key-value pair. */
	C->N++;

	/* Success! */
	return (0);

nomore:
	/* No more key-value pairs; but we were successful. */
	*key = *value = NULL;
	return (0);

err1:
	kvldskey_free(*key);
err0:
	/* Failure! */
	return (-1);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x118, %rsp            # imm = 0x118
movq %rdx, %rbp
movq %rsi, %rbx
movq %rdi, %r15
cmpq $0x0, (%rdi)
je 0x3012
movq %rbp, 0x8(%rsp)
callq 0x20a0
movq %rax, %r12
movl $0x0, (%rax)
movq (%r15), %rdi
callq 0x2280
testq %rax, %rax
je 0x2fe7
movq %rax, %r13
leaq 0x9253(%rip), %rbp      # 0xc1f5
leaq 0x924b(%rip), %r14      # 0xc1f4
addq $0x13, %r13
movq %r13, %rdi
movq %rbp, %rsi
callq 0x2220
testl %eax, %eax
je 0x2fcf
movq %r13, %rdi
movq %r14, %rsi
callq 0x2220
testl %eax, %eax
jne 0x30f0
movl $0x0, (%r12)
movq (%r15), %rdi
callq 0x2280
movq %rax, %r13
testq %rax, %rax
jne 0x2fa9
cmpl $0x0, (%r12)
movq 0x8(%rsp), %rbp
je 0x30e4
leaq 0x91ee(%rip), %rdi      # 0xc1ec
xorl %eax, %eax
callq 0x3d70
movl $0x0, (%r12)
jmp 0x3134
movq 0xefbf(%rip), %r13      # 0x11fd8
movq (%r13), %rcx
leaq 0x7(%rsp), %rdi
movl $0x1, %esi
movl $0x1, %edx
callq 0x20d0
cmpq $0x1, %rax
jne 0x30d7
movzbl 0x7(%rsp), %r14d
movq (%r13), %rcx
leaq 0x10(%rsp), %rdi
movl $0x1, %edx
movq %r14, %rsi
callq 0x20d0
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
cmpq $0x1, %rax
jne 0x313a
leaq 0x10(%rsp), %rdi
movq %r14, %rsi
callq 0x3fb4
movq %rax, (%rbx)
testq %rax, %rax
je 0x313a
movq (%r13), %rcx
leaq 0x7(%rsp), %rdi
movl $0x1, %esi
movl $0x1, %edx
callq 0x20d0
cmpq $0x1, %rax
jne 0x312c
movzbl 0x7(%rsp), %r14d
movq (%r13), %rcx
leaq 0x10(%rsp), %rdi
movl $0x1, %edx
movq %r14, %rsi
callq 0x20d0
cmpq $0x1, %rax
jne 0x312c
leaq 0x10(%rsp), %rdi
movq %r14, %rsi
callq 0x3fb4
movq %rax, (%rbp)
jmp 0x311e
movq (%r13), %rdi
callq 0x2240
testl %eax, %eax
je 0x3134
xorl %r12d, %r12d
movq %r12, (%rbp)
movq %r12, (%rbx)
jmp 0x313a
leaq 0x9100(%rip), %rsi      # 0xc1f7
movq %r13, %rdi
callq 0x314f
movq %rax, (%rbx)
testq %rax, %rax
je 0x3134
leaq 0x8f7e(%rip), %rsi      # 0xc08c
movq %r13, %rdi
callq 0x314f
movq 0x8(%rsp), %rcx
movq %rax, (%rcx)
testq %rax, %rax
je 0x312c
incq 0x8(%r15)
xorl %r12d, %r12d
jmp 0x313a
movq (%rbx), %rdi
callq 0x2040
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
movl %r12d, %eax
addq $0x118, %rsp            # imm = 0x118
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq