// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/cfb.c
// Function: read_minifat
static void read_minifat(deark *c, lctx *d)
{
	i64 i;
	i64 sec_id;
	i64 sec_offset;
	char buf[80];

	if(d->num_minifat_sectors > 1000000) {
		// TODO: Decide what limits to enforce.
		d->num_minifat_sectors = 1000000;
	}

	d->minifat = dbuf_create_membuf(c, d->num_minifat_sectors * d->sec_size, 1);

	// TODO: Use copy_normal_stream_to_dbuf
	de_dbg(c, "reading MiniFAT contents (%d sectors)", (int)d->num_minifat_sectors);
	de_dbg_indent(c, 1);

	sec_id = d->first_minifat_sec_id;

	for(i=0; i<d->num_minifat_sectors; i++) {
		if(sec_id<0) break;

		sec_offset = sec_id_to_offset(c, d, sec_id);
		describe_sec_id(c, d, sec_id, buf, sizeof(buf));
		de_dbg(c, "reading MiniFAT sector #%d, SecID=%d (%s), MiniSecIDs %d-%d",
			(int)i, (int)sec_id, buf,
			(int)(i*(d->sec_size/4)), (int)((i+1)*(d->sec_size/4)-1));
		dbuf_copy(c->infile, sec_offset, d->sec_size, d->minifat);

		sec_id = get_next_sec_id(c, d, sec_id);
	}
	de_dbg_indent(c, -1);

	dump_minifat(c, d);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xa0, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x10(%rbp), %rax
cmpq $0xf4240, 0x48(%rax)    # imm = 0xF4240
jle 0x51d3d
movq -0x10(%rbp), %rax
movq $0xf4240, 0x48(%rax)    # imm = 0xF4240
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rsi
movq -0x10(%rbp), %rax
imulq 0x20(%rax), %rsi
movl $0x1, %edx
callq 0x168020
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x88(%rax)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rax
movl %eax, %edx
leaq 0x153a11(%rip), %rsi    # 0x1a5790
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movl $0x1, %esi
callq 0x15b560
movq -0x10(%rbp), %rax
movq 0x40(%rax), %rax
movq %rax, -0x20(%rbp)
movq $0x0, -0x18(%rbp)
movq -0x18(%rbp), %rax
movq -0x10(%rbp), %rcx
cmpq 0x48(%rcx), %rax
jge 0x51ed0
cmpq $0x0, -0x20(%rbp)
jge 0x51dc6
jmp 0x51ed0
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x20(%rbp), %rdx
callq 0x52340
movq %rax, -0x28(%rbp)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x20(%rbp), %rdx
leaq -0x80(%rbp), %rcx
movl $0x50, %r8d
callq 0x52250
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movl %eax, -0x8c(%rbp)
movq -0x20(%rbp), %rax
movl %eax, %ecx
leaq -0x80(%rbp), %r8
movq -0x18(%rbp), %rax
movq %rax, -0x98(%rbp)
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rax
movl $0x4, %esi
cqto
idivq %rsi
movq %rax, %rdx
movq -0x98(%rbp), %rax
imulq %rdx, %rax
movl %eax, %r9d
movq -0x18(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x88(%rbp)
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rax
movl $0x4, %esi
cqto
idivq %rsi
movl -0x8c(%rbp), %edx
movq %rax, %rsi
movq -0x88(%rbp), %rax
imulq %rsi, %rax
subq $0x1, %rax
leaq 0x15393a(%rip), %rsi    # 0x1a57b6
movl %eax, (%rsp)
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x28(%rbp), %rsi
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rdx
movq -0x10(%rbp), %rax
movq 0x88(%rax), %rcx
callq 0x166070
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x20(%rbp), %rdx
callq 0x52470
movq %rax, -0x20(%rbp)
movq -0x18(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x18(%rbp)
jmp 0x51da8
movq -0x8(%rbp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x15b560
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x524e0
addq $0xa0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)