// File: /workspace/github_c_makefile_star2_O3/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, %r14
movq %rsi, %rbx
movq %rdi, %r15
movq (%rdi), %r13
testq %r13, %r13
je 0x3033
callq 0x20a0
movq %rax, %r12
movl $0x0, (%rax)
movq %r13, %rdi
callq 0x2280
testq %rax, %rax
je 0x300d
movq %rax, %r13
cmpb $0x2e, 0x13(%r13)
jne 0x30f4
cmpb $0x0, 0x14(%r13)
je 0x2ff5
cmpb $0x2e, 0x14(%r13)
jne 0x30f4
cmpb $0x0, 0x15(%r13)
jne 0x30f4
movl $0x0, (%r12)
movq (%r15), %rdi
callq 0x2280
movq %rax, %r13
testq %rax, %rax
jne 0x2fcd
cmpl $0x0, (%r12)
je 0x313c
leaq 0x91cd(%rip), %rdi      # 0xc1ec
xorl %eax, %eax
callq 0x3e30
movl $0x0, (%r12)
jmp 0x314f
movq 0xef9e(%rip), %rbp      # 0x11fd8
movq (%rbp), %rcx
leaq 0xf(%rsp), %rdi
movl $0x1, %esi
movl $0x1, %edx
callq 0x20d0
cmpq $0x1, %rax
jne 0x312f
movzbl 0xf(%rsp), %r13d
movq (%rbp), %rcx
leaq 0x10(%rsp), %rdi
movl $0x1, %edx
movq %r13, %rsi
callq 0x20d0
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
cmpq $0x1, %rax
jne 0x3155
leaq 0x10(%rsp), %rdi
movq %r13, %rsi
callq 0x4074
movq %rax, (%rbx)
testq %rax, %rax
je 0x3155
movq (%rbp), %rcx
leaq 0xf(%rsp), %rdi
movl $0x1, %esi
movl $0x1, %edx
callq 0x20d0
cmpq $0x1, %rax
jne 0x3147
movzbl 0xf(%rsp), %r12d
movq (%rbp), %rcx
leaq 0x10(%rsp), %rdi
movl $0x1, %edx
movq %r12, %rsi
callq 0x20d0
cmpq $0x1, %rax
jne 0x3147
leaq 0x10(%rsp), %rdi
movq %r12, %rsi
callq 0x4074
jmp 0x311e
addq $0x13, %r13
leaq 0x90f5(%rip), %rsi      # 0xc1f4
movq %r13, %rdi
callq 0x316a
movq %rax, (%rbx)
testq %rax, %rax
je 0x314f
leaq 0x8f76(%rip), %rsi      # 0xc08c
movq %r13, %rdi
callq 0x316a
movq %rax, (%r14)
testq %rax, %rax
je 0x3147
incq 0x8(%r15)
xorl %r12d, %r12d
jmp 0x3155
movq (%rbp), %rdi
callq 0x2240
testl %eax, %eax
je 0x314f
xorl %r12d, %r12d
movq %r12, (%r14)
movq %r12, (%rbx)
jmp 0x3155
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