// File: /workspace/github_c_makefile_star2_O1/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 0x9093(%rip), %rsi      # 0xc1f9
leaq 0x8(%rsp), %rdi
xorl %eax, %eax
callq 0x33bc
cmpl $-0x1, %eax
je 0x31d8
movq 0x8(%rsp), %rdi
leaq 0x9085(%rip), %rsi      # 0xc208
callq 0x2320
testq %rax, %rax
je 0x3201
movq %rax, %rbx
movq %rax, %rdi
callq 0x2270
leaq 0x10(%rsp), %rsi
movl %eax, %edi
callq 0x23b0
testl %eax, %eax
je 0x3226
callq 0x20a0
cmpl $0x0, (%rax)
movq 0x8(%rsp), %rsi
je 0x3276
movq %rax, %r14
leaq 0x9050(%rip), %rdi      # 0xc215
xorl %eax, %eax
callq 0x3d70
movl $0x0, (%r14)
jmp 0x32b4
callq 0x20a0
cmpl $0x0, (%rax)
je 0x3260
movq %rax, %rbx
leaq 0x9013(%rip), %rdi      # 0xc1ff
xorl %r14d, %r14d
xorl %eax, %eax
callq 0x3d70
movl $0x0, (%rbx)
jmp 0x32fe
callq 0x20a0
cmpl $0x0, (%rax)
movq 0x8(%rsp), %rsi
je 0x3286
movq %rax, %rbx
leaq 0x8ff1(%rip), %rdi      # 0xc20b
xorl %eax, %eax
callq 0x3d70
jmp 0x32db
movl $0xf000, %eax           # imm = 0xF000
andl 0x28(%rsp), %eax
cmpl $0x8000, %eax           # imm = 0x8000
jne 0x3296
movq 0x40(%rsp), %r14
cmpq $0x100, %r14            # imm = 0x100
jl 0x330c
movq 0x8(%rsp), %rdx
leaq 0x8fe2(%rip), %rdi      # 0xc236
movq %r14, %rsi
xorl %eax, %eax
callq 0x3e8f
jmp 0x32a9
leaq 0x8f98(%rip), %rdi      # 0xc1ff
xorl %r14d, %r14d
xorl %eax, %eax
callq 0x3e8f
jmp 0x32fe
leaq 0x8f98(%rip), %rdi      # 0xc215
xorl %eax, %eax
callq 0x3e8f
jmp 0x32b4
leaq 0x8f7e(%rip), %rdi      # 0xc20b
xorl %eax, %eax
callq 0x3e8f
jmp 0x32f1
movq 0x8(%rsp), %rsi
leaq 0x8f7d(%rip), %rdi      # 0xc21f
xorl %eax, %eax
callq 0x3e8f
callq 0x20a0
movl $0x0, (%rax)
movq %rbx, %rdi
callq 0x2120
testl %eax, %eax
je 0x32f1
callq 0x20a0
cmpl $0x0, (%rax)
je 0x32e3
movq %rax, %rbx
leaq 0x8f8e(%rip), %rdi      # 0xc262
xorl %eax, %eax
callq 0x3d70
movl $0x0, (%rbx)
jmp 0x32f1
leaq 0x8f78(%rip), %rdi      # 0xc262
xorl %eax, %eax
callq 0x3e8f
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 0x3375
leaq 0xa0(%rsp), %rdi
movq %r14, %rsi
callq 0x3fb4
testq %rax, %rax
je 0x32b4
movq %rax, %r14
movq %rbx, %rdi
callq 0x2120
testl %eax, %eax
je 0x33ad
callq 0x20a0
cmpl $0x0, (%rax)
je 0x339f
movq %rax, %rbx
leaq 0x8efc(%rip), %rdi      # 0xc262
xorl %eax, %eax
callq 0x3d70
movl $0x0, (%rbx)
jmp 0x33ad
callq 0x20a0
cmpl $0x0, (%rax)
movq 0x8(%rsp), %rsi
je 0x3393
movq %rax, %r14
leaq 0x8eca(%rip), %rdi      # 0xc258
jmp 0x31c5
leaq 0x8ebe(%rip), %rdi      # 0xc258
jmp 0x327d
leaq 0x8ebc(%rip), %rdi      # 0xc262
xorl %eax, %eax
callq 0x3e8f
movq 0x8(%rsp), %rdi
callq 0x2040
jmp 0x32fe