// File: /workspace/github_c_makefile_star2_O3/Tarsnap[P]kivaloo/kvlds-undump/main.c
// Function: readfile
static struct kvldskey *
readfile(const char * dir, const char * fname)
{
	char * s;
	FILE * f;
	struct stat sb;
	uint8_t buf[255];
	struct kvldskey * k;

	/* Construct file name. */
	if (asprintf(&s, "%s/%s", dir, fname) == -1) {
		warnp("asprintf");
		goto err0;
	}

	/* Open file. */
	if ((f = fopen(s, "rb")) == NULL) {
		warnp("fopen(%s)", s);
		goto err1;
	}

	/* Figure out how large the file is. */
	if (fstat(fileno(f), &sb)) {
		warnp("fstat(%s)", s);
		goto err2;
	}

	/* Sanity-check. */
	if (!S_ISREG(sb.st_mode)) {
		warn0("Not a regular file: %s", s);
		goto err2;
	}
	if (sb.st_size > 255) {
		warn0("File is too large (%ju bytes): %s",
		    (intmax_t)(sb.st_size), s);
		goto err2;
	}

	/* Read value. */
	if (fread(buf, (size_t)sb.st_size, 1, f) != 1) {
		warnp("fread(%s)", s);
		goto err2;
	}

	/* Construct kvlds key. */
	if ((k = kvldskey_create(buf, (size_t)sb.st_size)) == NULL)
		goto err2;

	/* Close file and free file name. */
	if (fclose(f))
		warnp("fclose");
	free(s);

	/* Success! */
	return (k);

err2:
	if (fclose(f))
		warnp("fclose");
err1:
	free(s);
err0:
	/* Failure! */
	return (NULL);
}

// Assembly:
pushq %r14
pushq %rbx
subq $0x1a8, %rsp            # imm = 0x1A8
movq %rsi, %rcx
movq %rdi, %rdx
leaq 0x9075(%rip), %rsi      # 0xc1f6
leaq 0x8(%rsp), %rdi
xorl %eax, %eax
callq 0x33d8
cmpl $-0x1, %eax
je 0x31f3
movq 0x8(%rsp), %rdi
leaq 0x9067(%rip), %rsi      # 0xc205
callq 0x2320
testq %rax, %rax
je 0x321c
movq %rax, %rbx
movq %rax, %rdi
callq 0x2270
leaq 0x10(%rsp), %rsi
movl %eax, %edi
callq 0x23b0
testl %eax, %eax
je 0x3241
callq 0x20a0
cmpl $0x0, (%rax)
movq 0x8(%rsp), %rsi
je 0x3291
movq %rax, %r14
leaq 0x9032(%rip), %rdi      # 0xc212
xorl %eax, %eax
callq 0x3e30
movl $0x0, (%r14)
jmp 0x32cf
callq 0x20a0
cmpl $0x0, (%rax)
je 0x327b
movq %rax, %rbx
leaq 0x8ff5(%rip), %rdi      # 0xc1fc
xorl %r14d, %r14d
xorl %eax, %eax
callq 0x3e30
movl $0x0, (%rbx)
jmp 0x3319
callq 0x20a0
cmpl $0x0, (%rax)
movq 0x8(%rsp), %rsi
je 0x32a1
movq %rax, %rbx
leaq 0x8fd3(%rip), %rdi      # 0xc208
xorl %eax, %eax
callq 0x3e30
jmp 0x32f6
movl $0xf000, %eax           # imm = 0xF000
andl 0x28(%rsp), %eax
cmpl $0x8000, %eax           # imm = 0x8000
jne 0x32b1
movq 0x40(%rsp), %r14
cmpq $0x100, %r14            # imm = 0x100
jl 0x3327
movq 0x8(%rsp), %rdx
leaq 0x8fc4(%rip), %rdi      # 0xc233
movq %r14, %rsi
xorl %eax, %eax
callq 0x3f4f
jmp 0x32c4
leaq 0x8f7a(%rip), %rdi      # 0xc1fc
xorl %r14d, %r14d
xorl %eax, %eax
callq 0x3f4f
jmp 0x3319
leaq 0x8f7a(%rip), %rdi      # 0xc212
xorl %eax, %eax
callq 0x3f4f
jmp 0x32cf
leaq 0x8f60(%rip), %rdi      # 0xc208
xorl %eax, %eax
callq 0x3f4f
jmp 0x330c
movq 0x8(%rsp), %rsi
leaq 0x8f5f(%rip), %rdi      # 0xc21c
xorl %eax, %eax
callq 0x3f4f
callq 0x20a0
movl $0x0, (%rax)
movq %rbx, %rdi
callq 0x2120
testl %eax, %eax
je 0x330c
callq 0x20a0
cmpl $0x0, (%rax)
je 0x32fe
movq %rax, %rbx
leaq 0x8f70(%rip), %rdi      # 0xc25f
xorl %eax, %eax
callq 0x3e30
movl $0x0, (%rbx)
jmp 0x330c
leaq 0x8f5a(%rip), %rdi      # 0xc25f
xorl %eax, %eax
callq 0x3f4f
movq 0x8(%rsp), %rdi
callq 0x2040
xorl %r14d, %r14d
movq %r14, %rax
addq $0x1a8, %rsp            # imm = 0x1A8
popq %rbx
popq %r14
retq
leaq 0xa0(%rsp), %rdi
movl $0x1, %edx
movq %r14, %rsi
movq %rbx, %rcx
callq 0x20d0
cmpq $0x1, %rax
jne 0x3390
leaq 0xa0(%rsp), %rdi
movq %r14, %rsi
callq 0x4074
testq %rax, %rax
je 0x32cf
movq %rax, %r14
movq %rbx, %rdi
callq 0x2120
testl %eax, %eax
je 0x33c8
callq 0x20a0
cmpl $0x0, (%rax)
je 0x33ba
movq %rax, %rbx
leaq 0x8ede(%rip), %rdi      # 0xc25f
xorl %eax, %eax
callq 0x3e30
movl $0x0, (%rbx)
jmp 0x33c8
callq 0x20a0
cmpl $0x0, (%rax)
movq 0x8(%rsp), %rsi
je 0x33ae
movq %rax, %r14
leaq 0x8eac(%rip), %rdi      # 0xc255
jmp 0x31e0
leaq 0x8ea0(%rip), %rdi      # 0xc255
jmp 0x3298
leaq 0x8e9e(%rip), %rdi      # 0xc25f
xorl %eax, %eax
callq 0x3f4f
movq 0x8(%rsp), %rdi
callq 0x2040
jmp 0x3319
nop