// File: /workspace/github_c_makefile_star2_O2/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, %r15
movq %rsi, %r14
movq %rdi, %r12
movq (%rdi), %rbp
pushq $-0x1
popq %rbx
testq %rbp, %rbp
je 0x2b4d
callq 0x20a0
movq %rax, %r13
andl $0x0, (%r13)
movq %rbp, %rdi
callq 0x2270
testq %rax, %rax
je 0x2bfb
movq %rax, %rbp
cmpb $0x2e, 0x13(%rax)
jne 0x2b09
cmpb $0x0, 0x14(%rbp)
je 0x2b03
cmpb $0x2e, 0x14(%rbp)
jne 0x2b09
cmpb $0x0, 0x15(%rbp)
jne 0x2b09
movq (%r12), %rbp
jmp 0x2ad2
addq $0x13, %rbp
leaq 0x86e0(%rip), %rsi      # 0xb1f4
movq %rbp, %rdi
callq 0x2c4c
movq %rax, (%r14)
testq %rax, %rax
je 0x2c38
leaq 0x855d(%rip), %rsi      # 0xb08c
movq %rbp, %rdi
callq 0x2c4c
movq %rax, (%r15)
testq %rax, %rax
je 0x2c30
incq 0x8(%r12)
jmp 0x2c2c
movq 0xe484(%rip), %rbp      # 0x10fd8
movq (%rbp), %rcx
leaq 0xf(%rsp), %rdi
pushq $0x1
popq %rdx
movq %rdx, %rsi
callq 0x20d0
cmpq $0x1, %rax
jne 0x2c17
movzbl 0xf(%rsp), %r13d
movq (%rbp), %rcx
leaq 0x10(%rsp), %rdi
pushq $0x1
popq %rdx
movq %r13, %rsi
callq 0x20d0
cmpq $0x1, %rax
jne 0x2c38
leaq 0x10(%rsp), %rdi
movq %r13, %rsi
callq 0x3dd4
movq %rax, (%r14)
testq %rax, %rax
je 0x2c38
movq (%rbp), %rcx
leaq 0xf(%rsp), %rdi
pushq $0x1
popq %rdx
movq %rdx, %rsi
callq 0x20d0
cmpq $0x1, %rax
jne 0x2c30
movzbl 0xf(%rsp), %r13d
movq (%rbp), %rcx
leaq 0x10(%rsp), %rdi
pushq $0x1
popq %rdx
movq %r13, %rsi
callq 0x20d0
cmpq $0x1, %rax
jne 0x2c30
leaq 0x10(%rsp), %rdi
movq %r13, %rsi
callq 0x3dd4
jmp 0x2b37
cmpl $0x0, (%r13)
je 0x2c24
leaq 0x85e3(%rip), %rdi      # 0xb1ec
xorl %eax, %eax
callq 0x3ac1
andl $0x0, (%r13)
jmp 0x2c38
movq (%rbp), %rdi
callq 0x2230
testl %eax, %eax
je 0x2c38
andq $0x0, (%r15)
andq $0x0, (%r14)
xorl %ebx, %ebx
jmp 0x2c38
movq (%r14), %rdi
callq 0x2040
movl %ebx, %eax
addq $0x118, %rsp            # imm = 0x118
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq