// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/fat.c
// Function: de_run_fat
static void de_run_fat(deark *c, de_module_params *mparams)
{
	lctx *d = NULL;
	const char *s;
	int got_root_dir = 0;
	de_encoding default_encoding =  DE_ENCODING_CP437_G;

	if(mparams) {
		// out_params.flags:
		//  0x1 = No valid FAT directory structure found
		mparams->out_params.flags = 0;
	}

	d = de_malloc(c, sizeof(lctx));

	d->prescan_root_dir = (u8)de_get_ext_option_bool(c, "fat:scanroot", 1);
	d->opt_check_root_dir = (u8)de_get_ext_option_bool(c, "fat:checkroot", 1);
	s = de_get_ext_option(c, "fat:subfmt");
	if(s) {
		if(!de_strcmp(s, "pc")) {
			d->subfmt_req = FAT_SUBFMT_PC;
		}
		else if(!de_strcmp(s, "atarist")) {
			d->subfmt_req = FAT_SUBFMT_ATARIST;
		}
	}
	d->subfmt = d->subfmt_req;
	if(d->subfmt==FAT_SUBFMT_ATARIST) {
		default_encoding = DE_ENCODING_ATARIST;
	}

	d->input_encoding = de_get_input_encoding(c, mparams, default_encoding);

	// TODO: Detect MBR?
	if(!do_boot_sector(c, d, 0)) goto done;
	if(d->num_fat_bits==0) goto done;

	switch(d->platform) {
	case FAT_PLATFORM_PC:
		de_declare_fmtf(c, "FAT%d - PC", d->num_fat_bits);
		break;
	case FAT_PLATFORM_ATARIST:
		de_declare_fmtf(c, "FAT%d - Atari ST", d->num_fat_bits);
		break;
	default:
		de_declare_fmtf(c, "FAT%d - Unknown platform", d->num_fat_bits);
		break;
	}

	if(!do_read_fat(c, d)) goto done;

	if(d->opt_check_root_dir) {
		if(!root_dir_seems_valid(c, d)) {
			de_warn(c, "This file does not appear to contain a valid FAT "
				"directory structure. (\"-opt fat:checkroot=0\" to try anyway)");
			goto done;
		}
	}

	d->curpath = de_strarray_create(c, MAX_NESTING_LEVEL+10);
	got_root_dir = 1;
	do_root_dir(c, d);

done:
	if(!got_root_dir) {
		// Inform the parent module that we failed to do anything.
		if(mparams) {
			mparams->out_params.flags |= 0x1;
		}
	}

	if(d) {
		de_free(c, d->fat_nextcluster);
		de_free(c, d->cluster_used_flags);
		de_free(c, d->cluster_used_flags_saved);
		if(d->curpath) de_strarray_destroy(d->curpath);
		if(d->ea_data) dbuf_close(d->ea_data);
		de_free(c, d);
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq $0x0, -0x18(%rbp)
movl $0x0, -0x24(%rbp)
movl $0xd, -0x28(%rbp)
cmpq $0x0, -0x10(%rbp)
je 0x827f8
movq -0x10(%rbp), %rax
movl $0x0, 0x40(%rax)
movq -0x8(%rbp), %rdi
movl $0xb0, %esi
callq 0x15b780
movq %rax, -0x18(%rbp)
movq -0x8(%rbp), %rdi
leaq 0x12b645(%rip), %rsi    # 0x1ade5a
movl $0x1, %edx
callq 0x15cbc0
movb %al, %cl
movq -0x18(%rbp), %rax
movb %cl, 0x5(%rax)
movq -0x8(%rbp), %rdi
leaq 0x12b634(%rip), %rsi    # 0x1ade67
movl $0x1, %edx
callq 0x15cbc0
movb %al, %cl
movq -0x18(%rbp), %rax
movb %cl, 0x4(%rax)
movq -0x8(%rbp), %rdi
leaq 0x12b624(%rip), %rsi    # 0x1ade75
callq 0x15cb30
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
je 0x828a7
movq -0x20(%rbp), %rdi
leaq 0x144741(%rip), %rsi    # 0x1c6fad
callq 0x191a0
cmpl $0x0, %eax
jne 0x82883
movq -0x18(%rbp), %rax
movl $0x1, 0x8(%rax)
jmp 0x828a5
movq -0x20(%rbp), %rdi
leaq 0x12b5f2(%rip), %rsi    # 0x1ade80
callq 0x191a0
cmpl $0x0, %eax
jne 0x828a3
movq -0x18(%rbp), %rax
movl $0x2, 0x8(%rax)
jmp 0x828a5
jmp 0x828a7
movq -0x18(%rbp), %rax
movl 0x8(%rax), %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0xc(%rax)
movq -0x18(%rbp), %rax
cmpl $0x2, 0xc(%rax)
jne 0x828c6
movl $0x12, -0x28(%rbp)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movl -0x28(%rbp), %edx
callq 0x15e4a0
movl %eax, %ecx
movq -0x18(%rbp), %rax
movl %ecx, (%rax)
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
xorl %eax, %eax
movl %eax, %edx
callq 0x83040
cmpl $0x0, %eax
jne 0x828f9
jmp 0x829ee
movq -0x18(%rbp), %rax
movzbl 0x14(%rax), %eax
cmpl $0x0, %eax
jne 0x8290b
jmp 0x829ee
movq -0x18(%rbp), %rax
movl 0x10(%rax), %eax
movl %eax, -0x2c(%rbp)
subl $0x1, %eax
je 0x82926
jmp 0x8291c
movl -0x2c(%rbp), %eax
subl $0x2, %eax
je 0x82942
jmp 0x8295e
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movzbl 0x14(%rax), %edx
leaq 0x12b54f(%rip), %rsi    # 0x1ade88
movb $0x0, %al
callq 0x15e3d0
jmp 0x82978
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movzbl 0x14(%rax), %edx
leaq 0x12b53e(%rip), %rsi    # 0x1ade93
movb $0x0, %al
callq 0x15e3d0
jmp 0x82978
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movzbl 0x14(%rax), %edx
leaq 0x12b533(%rip), %rsi    # 0x1adea4
movb $0x0, %al
callq 0x15e3d0
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x83780
cmpl $0x0, %eax
jne 0x8298c
jmp 0x829ee
movq -0x18(%rbp), %rax
cmpb $0x0, 0x4(%rax)
je 0x829be
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x83a30
cmpl $0x0, %eax
jne 0x829bc
movq -0x8(%rbp), %rdi
leaq 0x12b50a(%rip), %rsi    # 0x1adebd
movb $0x0, %al
callq 0x15bc10
jmp 0x829ee
jmp 0x829be
movq -0x8(%rbp), %rdi
movl $0x1a, %esi
callq 0x1727a0
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x80(%rax)
movl $0x1, -0x24(%rbp)
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x83be0
cmpl $0x0, -0x24(%rbp)
jne 0x82a0a
cmpq $0x0, -0x10(%rbp)
je 0x82a08
movq -0x10(%rbp), %rax
movl 0x40(%rax), %ecx
orl $0x1, %ecx
movl %ecx, 0x40(%rax)
jmp 0x82a0a
cmpq $0x0, -0x18(%rbp)
je 0x82a9a
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x90(%rax), %rsi
callq 0x15b820
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x98(%rax), %rsi
callq 0x15b820
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0xa0(%rax), %rsi
callq 0x15b820
movq -0x18(%rbp), %rax
cmpq $0x0, 0x80(%rax)
je 0x82a6f
movq -0x18(%rbp), %rax
movq 0x80(%rax), %rdi
callq 0x1727f0
movq -0x18(%rbp), %rax
cmpq $0x0, 0xa8(%rax)
je 0x82a8d
movq -0x18(%rbp), %rax
movq 0xa8(%rax), %rdi
callq 0x1676a0
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x15b820
addq $0x30, %rsp
popq %rbp
retq