// File: /workspace/github_c_makefile_star2_O0/dlbeer[P]ufat/main.c
// Function: cmd_read
static int cmd_read(struct ufat *uf, const struct options *opt)
{
	FILE *out;
	struct ufat_dirent ent;
	struct ufat_file file;
	int err;

	if (!opt->argc) {
		fprintf(stderr, "You must specify a file path\n");
		return -1;
	}

	if (require_file(uf, opt->argv[0], &ent) < 0)
		return -1;

	err = ufat_open_file(uf, &file, &ent);
	if (err < 0) {
		fprintf(stderr, "ufat_open_file: %s\n", ufat_strerror(err));
		return -1;
	}

	out = open_output(opt->out_file);
	if (!out)
		return -1;

	for (;;) {
		char buf[16384];
		int req_size = sizeof(buf);
		int len;

		if (opt->flags & OPTION_RANDOMIZE)
			req_size = random() % sizeof(buf) + 1;

		len = ufat_file_read(&file, buf, req_size);
		if (len < 0) {
			fprintf(stderr, "ufat_file_read: %s\n",
				ufat_strerror(len));
			close_output(opt->out_file, out);
			return -1;
		}

		if (!len)
			break;

		if (fwrite(buf, 1, len, out) != (size_t)len) {
			perror("fwrite");
			close_output(opt->out_file, out);
			return -1;
		}
	}

	return close_output(opt->out_file, out);
}

// Assembly:
subq $0x40b8, %rsp           # imm = 0x40B8
movq %rdi, 0x40a8(%rsp)
movq %rsi, 0x40a0(%rsp)
movq 0x40a0(%rsp), %rax
cmpl $0x0, 0x40(%rax)
jne 0x9d8d
movq 0x628c(%rip), %rax      # 0xfff8
movq (%rax), %rdi
leaq 0x2e25(%rip), %rsi      # 0xcb9b
movb $0x0, %al
callq 0x2120
movl $0xffffffff, 0x40b4(%rsp) # imm = 0xFFFFFFFF
jmp 0x9f96
movq 0x40a8(%rsp), %rdi
movq 0x40a0(%rsp), %rax
movq 0x38(%rax), %rax
movq (%rax), %rsi
leaq 0x4050(%rsp), %rdx
callq 0xad00
cmpl $0x0, %eax
jge 0x9dc6
movl $0xffffffff, 0x40b4(%rsp) # imm = 0xFFFFFFFF
jmp 0x9f96
movq 0x40a8(%rsp), %rdi
leaq 0x4028(%rsp), %rsi
leaq 0x4050(%rsp), %rdx
callq 0x4f00
movl %eax, 0x4024(%rsp)
cmpl $0x0, 0x4024(%rsp)
jge 0x9e35
movq 0x61fd(%rip), %rax      # 0xfff8
movq (%rax), %rax
movq %rax, 0x10(%rsp)
movl 0x4024(%rsp), %edi
callq 0x2c40
movq 0x10(%rsp), %rdi
movq %rax, %rdx
leaq 0x2ed4(%rip), %rsi      # 0xccf2
movb $0x0, %al
callq 0x2120
movl $0xffffffff, 0x40b4(%rsp) # imm = 0xFFFFFFFF
jmp 0x9f96
movq 0x40a0(%rsp), %rax
movq 0x20(%rax), %rdi
callq 0x9330
movq %rax, 0x4098(%rsp)
cmpq $0x0, 0x4098(%rsp)
jne 0x9e69
movl $0xffffffff, 0x40b4(%rsp) # imm = 0xFFFFFFFF
jmp 0x9f96
jmp 0x9e6b
movl $0x4000, 0x1c(%rsp)     # imm = 0x4000
movq 0x40a0(%rsp), %rax
movl (%rax), %eax
andl $0x2, %eax
cmpl $0x0, %eax
je 0x9e98
callq 0x2160
andq $0x3fff, %rax           # imm = 0x3FFF
addq $0x1, %rax
movl %eax, 0x1c(%rsp)
leaq 0x20(%rsp), %rsi
movl 0x1c(%rsp), %edx
leaq 0x4028(%rsp), %rdi
callq 0x5130
movl %eax, 0x18(%rsp)
cmpl $0x0, 0x18(%rsp)
jge 0x9f10
movq 0x6138(%rip), %rax      # 0xfff8
movq (%rax), %rax
movq %rax, 0x8(%rsp)
movl 0x18(%rsp), %edi
callq 0x2c40
movq 0x8(%rsp), %rdi
movq %rax, %rdx
leaq 0x2e26(%rip), %rsi      # 0xcd06
movb $0x0, %al
callq 0x2120
movq 0x40a0(%rsp), %rax
movq 0x20(%rax), %rdi
movq 0x4098(%rsp), %rsi
callq 0x9500
movl $0xffffffff, 0x40b4(%rsp) # imm = 0xFFFFFFFF
jmp 0x9f96
cmpl $0x0, 0x18(%rsp)
jne 0x9f19
jmp 0x9f76
leaq 0x20(%rsp), %rdi
movslq 0x18(%rsp), %rdx
movq 0x4098(%rsp), %rcx
movl $0x1, %esi
callq 0x21c0
movslq 0x18(%rsp), %rcx
cmpq %rcx, %rax
je 0x9f71
leaq 0x30b7(%rip), %rdi      # 0xcffd
callq 0x2190
movq 0x40a0(%rsp), %rax
movq 0x20(%rax), %rdi
movq 0x4098(%rsp), %rsi
callq 0x9500
movl $0xffffffff, 0x40b4(%rsp) # imm = 0xFFFFFFFF
jmp 0x9f96
jmp 0x9e6b
movq 0x40a0(%rsp), %rax
movq 0x20(%rax), %rdi
movq 0x4098(%rsp), %rsi
callq 0x9500
movl %eax, 0x40b4(%rsp)
movl 0x40b4(%rsp), %eax
addq $0x40b8, %rsp           # imm = 0x40B8
retq
nopw %cs:(%rax,%rax)