// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/fat.c
// Function: do_read_fat
static int do_read_fat(deark *c, lctx *d)
{
	i64 pos1;
	i64 pos;
	i64 fat_idx_to_read = 0;
	int retval = 0;
	i64 i;

	pos1 = sectornum_to_offset(c, d, d->num_rsvd_sectors + fat_idx_to_read*d->num_sectors_per_fat);
	de_dbg(c, "FAT#%d at %"I64_FMT, (int)fat_idx_to_read, pos1);
	de_dbg_indent(c, 1);

	if(d->num_cluster_identifiers > (i64)(DE_MAX_SANE_OBJECT_SIZE/sizeof(u32))) goto done;
	d->num_fat_entries = d->num_cluster_identifiers;
	d->fat_nextcluster = de_mallocarray(c, d->num_fat_entries, sizeof(u32));
	d->cluster_used_flags = de_malloc(c, d->num_fat_entries);

	pos = pos1;
	if(d->num_fat_bits==12) {
		for(i=0; i<d->num_fat_entries+1; i+=2) {
			UI val;

			val = (UI)dbuf_getint_ext(c->infile, pos, 3, 1, 0);
			pos += 3;
			if(i < d->num_fat_entries) {
				d->fat_nextcluster[i] = (u32)(val & 0xfff);
			}
			if(i+1 < d->num_fat_entries) {
				d->fat_nextcluster[i+1] = (u32)(val >> 12);
			}
		}
	}
	else if(d->num_fat_bits==16) {
		for(i=0; i<d->num_fat_entries; i++) {
			d->fat_nextcluster[i] = (u32)de_getu16le_p(&pos);
		}
	}
	else {
		de_err(c, "This type of FAT is not supported");
		goto done;
	}

	if(c->debug_level>=3) {
		for(i=0; i<d->num_fat_entries; i++) {
			de_dbg3(c, "fat[%"I64_FMT"]: %"I64_FMT, i, (i64)d->fat_nextcluster[i]);
		}
	}

	retval = 1;
done:
	de_dbg_indent(c, -1);
	return retval;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq $0x0, -0x28(%rbp)
movl $0x0, -0x2c(%rbp)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x10(%rbp), %rax
movq 0x50(%rax), %rdx
movq -0x28(%rbp), %rax
movq -0x10(%rbp), %rcx
imulq 0x60(%rcx), %rax
addq %rax, %rdx
callq 0x83e80
movq %rax, -0x18(%rbp)
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rax
movl %eax, %edx
movq -0x18(%rbp), %rcx
leaq 0x12aa18(%rip), %rsi    # 0x1ae1f5
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movl $0x1, %esi
callq 0x15b560
movq -0x10(%rbp), %rax
cmpq $0x17d7840, 0x78(%rax)  # imm = 0x17D7840
jle 0x83805
jmp 0x83a0e
movq -0x10(%rbp), %rax
movq 0x78(%rax), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x88(%rax)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x88(%rax), %rsi
movl $0x4, %edx
callq 0x15c450
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x90(%rax)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x88(%rax), %rsi
callq 0x15b780
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x98(%rax)
movq -0x18(%rbp), %rax
movq %rax, -0x20(%rbp)
movq -0x10(%rbp), %rax
movzbl 0x14(%rax), %eax
cmpl $0xc, %eax
jne 0x8393a
movq $0x0, -0x38(%rbp)
movq -0x38(%rbp), %rax
movq -0x10(%rbp), %rcx
movq 0x88(%rcx), %rcx
addq $0x1, %rcx
cmpq %rcx, %rax
jge 0x83938
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x20(%rbp), %rsi
movl $0x3, %edx
movl $0x1, %ecx
xorl %r8d, %r8d
callq 0x165a80
movl %eax, -0x3c(%rbp)
movq -0x20(%rbp), %rax
addq $0x3, %rax
movq %rax, -0x20(%rbp)
movq -0x38(%rbp), %rax
movq -0x10(%rbp), %rcx
cmpq 0x88(%rcx), %rax
jge 0x838f7
movl -0x3c(%rbp), %edx
andl $0xfff, %edx            # imm = 0xFFF
movq -0x10(%rbp), %rax
movq 0x90(%rax), %rax
movq -0x38(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq -0x10(%rbp), %rcx
cmpq 0x88(%rcx), %rax
jge 0x83925
movl -0x3c(%rbp), %edx
shrl $0xc, %edx
movq -0x10(%rbp), %rax
movq 0x90(%rax), %rax
movq -0x38(%rbp), %rcx
movl %edx, 0x4(%rax,%rcx,4)
jmp 0x83927
movq -0x38(%rbp), %rax
addq $0x2, %rax
movq %rax, -0x38(%rbp)
jmp 0x83882
jmp 0x839ab
movq -0x10(%rbp), %rax
movzbl 0x14(%rax), %eax
cmpl $0x10, %eax
jne 0x83995
movq $0x0, -0x38(%rbp)
movq -0x38(%rbp), %rax
movq -0x10(%rbp), %rcx
cmpq 0x88(%rcx), %rax
jge 0x83993
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x20(%rbp), %rsi
callq 0x1652c0
movl %eax, %edx
movq -0x10(%rbp), %rax
movq 0x90(%rax), %rax
movq -0x38(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0x8394f
jmp 0x839a9
movq -0x8(%rbp), %rdi
leaq 0x12a863(%rip), %rsi    # 0x1ae203
movb $0x0, %al
callq 0x15bfb0
jmp 0x83a0e
jmp 0x839ab
movq -0x8(%rbp), %rax
cmpl $0x3, (%rax)
jl 0x83a07
movq $0x0, -0x38(%rbp)
movq -0x38(%rbp), %rax
movq -0x10(%rbp), %rcx
cmpq 0x88(%rcx), %rax
jge 0x83a05
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rdx
movq -0x10(%rbp), %rax
movq 0x90(%rax), %rax
movq -0x38(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, %ecx
leaq 0x12a835(%rip), %rsi    # 0x1ae225
movb $0x0, %al
callq 0x15b400
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0x839bc
jmp 0x83a07
movl $0x1, -0x2c(%rbp)
movq -0x8(%rbp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x15b560
movl -0x2c(%rbp), %eax
addq $0x40, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)