// File: /workspace/github_c_makefile_star2_O2/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 0x8593(%rip), %rsi      # 0xb1f6
leaq 0x8(%rsp), %rdi
xorl %eax, %eax
callq 0x2ea8
cmpl $-0x1, %eax
je 0x2cd2
movq 0x8(%rsp), %rdi
leaq 0x8585(%rip), %rsi      # 0xb205
callq 0x2310
testq %rax, %rax
je 0x2cf8
movq %rax, %rbx
movq %rax, %rdi
callq 0x2260
leaq 0x10(%rsp), %rsi
movl %eax, %edi
callq 0x23a0
testl %eax, %eax
je 0x2d1d
callq 0x20a0
cmpl $0x0, (%rax)
movq 0x8(%rsp), %rsi
je 0x2d6d
movq %rax, %r14
leaq 0x8550(%rip), %rdi      # 0xb212
xorl %eax, %eax
callq 0x3ac1
andl $0x0, (%r14)
jmp 0x2da8
callq 0x20a0
cmpl $0x0, (%rax)
je 0x2d57
movq %rax, %rbx
leaq 0x8516(%rip), %rdi      # 0xb1fc
xorl %r14d, %r14d
xorl %eax, %eax
callq 0x3ac1
andl $0x0, (%rbx)
jmp 0x2def
callq 0x20a0
cmpl $0x0, (%rax)
movq 0x8(%rsp), %rsi
je 0x2d7d
movq %rax, %rbx
leaq 0x84f7(%rip), %rdi      # 0xb208
xorl %eax, %eax
callq 0x3ac1
jmp 0x2dcf
movl $0xf000, %eax           # imm = 0xF000
andl 0x28(%rsp), %eax
cmpl $0x8000, %eax           # imm = 0x8000
jne 0x2d8d
movq 0x40(%rsp), %r14
cmpq $0x100, %r14            # imm = 0x100
jl 0x2dfd
movq 0x8(%rsp), %rdx
leaq 0x84e8(%rip), %rdi      # 0xb233
movq %r14, %rsi
xorl %eax, %eax
callq 0x3c50
jmp 0x2da0
leaq 0x849e(%rip), %rdi      # 0xb1fc
xorl %r14d, %r14d
xorl %eax, %eax
callq 0x3c50
jmp 0x2def
leaq 0x849e(%rip), %rdi      # 0xb212
xorl %eax, %eax
callq 0x3c50
jmp 0x2da8
leaq 0x8484(%rip), %rdi      # 0xb208
xorl %eax, %eax
callq 0x3c50
jmp 0x2de2
movq 0x8(%rsp), %rsi
leaq 0x8483(%rip), %rdi      # 0xb21c
xorl %eax, %eax
callq 0x3c50
callq 0x20a0
andl $0x0, (%rax)
movq %rbx, %rdi
callq 0x2120
testl %eax, %eax
je 0x2de2
callq 0x20a0
cmpl $0x0, (%rax)
je 0x2dd4
movq %rax, %rbx
leaq 0x8497(%rip), %rdi      # 0xb25f
xorl %eax, %eax
callq 0x3ac1
andl $0x0, (%rbx)
jmp 0x2de2
leaq 0x8484(%rip), %rdi      # 0xb25f
xorl %eax, %eax
callq 0x3c50
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
pushq $0x1
popq %rdx
movq %r14, %rsi
movq %rbx, %rcx
callq 0x20d0
cmpq $0x1, %rax
jne 0x2e61
leaq 0xa0(%rsp), %rdi
movq %r14, %rsi
callq 0x3dd4
testq %rax, %rax
je 0x2da8
movq %rax, %r14
movq %rbx, %rdi
callq 0x2120
testl %eax, %eax
je 0x2e99
callq 0x20a0
cmpl $0x0, (%rax)
je 0x2e8b
movq %rax, %rbx
leaq 0x840a(%rip), %rdi      # 0xb25f
xorl %eax, %eax
callq 0x3ac1
andl $0x0, (%rbx)
jmp 0x2e99
callq 0x20a0
cmpl $0x0, (%rax)
movq 0x8(%rsp), %rsi
je 0x2e7f
movq %rax, %r14
leaq 0x83db(%rip), %rdi      # 0xb255
jmp 0x2cc2
leaq 0x83cf(%rip), %rdi      # 0xb255
jmp 0x2d74
leaq 0x83cd(%rip), %rdi      # 0xb25f
xorl %eax, %eax
callq 0x3c50
movq 0x8(%rsp), %rdi
callq 0x2040
jmp 0x2def