// File: /workspace/github_c_makefile_star2_O1/jsummers[P]deark/modules/amiga-dsk.c
// Function: de_run_amiga_adf
static void de_run_amiga_adf(deark *c, de_module_params *mparams)
{
	lctx *d = NULL;
	i64 root_block_reported;
	int saved_indent_level;
	de_ucstring *flags_descr;

	de_dbg_indent_save(c, &saved_indent_level);

	d = de_malloc(c, sizeof(lctx));
	d->bsize = 512;

	de_dbg(c, "header at %d", 0);
	de_dbg_indent(c, 1);

	d->bootblock_flags = (de_getbyte(3) & 0x07);
	flags_descr = ucstring_create(c);

	if(d->bootblock_flags & 0x1) {
		d->is_ffs = 1;
	}
	if(d->bootblock_flags & 0x2) {
		d->intnl_mode = 1;
	}
	if(d->bootblock_flags & 0x4) {
		d->intnl_mode = 1;
		d->dirc_mode = 1;
	}
	ucstring_append_flags_item(flags_descr, d->is_ffs?"FFS":"OFS");
	if(d->intnl_mode) {
		ucstring_append_flags_item(flags_descr, "international mode");
	}
	if(d->dirc_mode) {
		ucstring_append_flags_item(flags_descr, "dircache mode");
	}
	de_dbg(c, "flags: 0x%02x (%s)", (UI)d->bootblock_flags, ucstring_getpsz_d(flags_descr));
	ucstring_destroy(flags_descr);

	de_declare_fmtf(c, "Amiga ADF, %s", d->is_ffs?"FFS":"OFS");

	root_block_reported = de_getu32be(8);
	de_dbg(c, "root block (reported): %"I64_FMT, root_block_reported);

	d->num_blocks = de_pad_to_n(c->infile->len, 512) / 512;
	if(d->num_blocks > MAX_ADF_BLOCKS) {
		d->num_blocks = MAX_ADF_BLOCKS;
	}
	de_dbg_indent(c, -1);

	if(d->dirc_mode || d->intnl_mode) {
		de_warn(c, "This type of ADF file might not be supported correctly");
	}

	if(!find_root_block(c, d, root_block_reported)) {
		de_err(c, "Root block not found");
		goto done;
	}

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

	if(!do_header_block(c, d, d->root_block)) goto done;

done:
	if(d) {
		de_free(c, d->block_used_flags);
		de_strarray_destroy(d->curpath);
		de_free(c, d);
	}
	de_dbg_indent_restore(c, saved_indent_level);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %rbx
leaq 0x4(%rsp), %rsi
callq 0xe958c
movl $0x38, %esi
movq %rbx, %rdi
callq 0xe969b
movq %rax, %r14
movq $0x200, 0x8(%rax)       # imm = 0x200
leaq 0x110a8b(%rip), %rsi    # 0x13935e
movq %rbx, %rdi
xorl %edx, %edx
xorl %eax, %eax
callq 0xe9226
movq %rbx, %rdi
movl $0x1, %esi
callq 0xe9585
movq 0x18(%rbx), %rdi
movl $0x3, %esi
callq 0xef0d5
andb $0x7, %al
movb %al, 0x24(%r14)
movq %rbx, %rdi
callq 0xf6870
movq %rax, %r15
movb 0x24(%r14), %al
testb $0x1, %al
je 0x28917
movb $0x1, (%r14)
testb $0x2, %al
je 0x28920
movb $0x1, 0x1(%r14)
testb $0x4, %al
je 0x2892b
movw $0x101, 0x1(%r14)       # imm = 0x101
cmpb $0x0, (%r14)
leaq 0xec349(%rip), %r13     # 0x114c7f
leaq 0xec33e(%rip), %r12     # 0x114c7b
movq %r12, %rsi
cmoveq %r13, %rsi
movq %r15, %rdi
callq 0xf7566
cmpb $0x0, 0x1(%r14)
je 0x28962
leaq 0xec329(%rip), %rsi     # 0x114c83
movq %r15, %rdi
callq 0xf7566
cmpb $0x0, 0x2(%r14)
je 0x28978
leaq 0xec326(%rip), %rsi     # 0x114c96
movq %r15, %rdi
callq 0xf7566
movzbl 0x24(%r14), %ebp
movq %r15, %rdi
callq 0xf7557
leaq 0x105644(%rip), %rsi    # 0x12dfd0
movq %rbx, %rdi
movl %ebp, %edx
movq %rax, %rcx
xorl %eax, %eax
callq 0xe9226
movq %r15, %rdi
callq 0xf6bb0
cmpb $0x0, (%r14)
cmoveq %r13, %r12
leaq 0xec2f2(%rip), %rsi     # 0x114ca4
movq %rbx, %rdi
movq %r12, %rdx
xorl %eax, %eax
callq 0xeb703
movq 0x18(%rbx), %rdi
movl $0x8, %esi
callq 0xef32a
movq %rax, %r15
leaq 0xec2db(%rip), %rsi     # 0x114cb2
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xe9226
movq 0x18(%rbx), %rax
movq 0x18(%rax), %rdi
movl $0x200, %esi            # imm = 0x200
callq 0xea80b
leaq 0x1ff(%rax), %rcx
testq %rax, %rax
cmovnsq %rax, %rcx
sarq $0x9, %rcx
cmpq $0x1b8200, %rax         # imm = 0x1B8200
movl $0xdc0, %eax            # imm = 0xDC0
cmovlq %rcx, %rax
movq %rax, 0x18(%r14)
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0xe9585
cmpb $0x0, 0x2(%r14)
jne 0x28a36
cmpb $0x0, 0x1(%r14)
je 0x28a47
leaq 0xec290(%rip), %rsi     # 0x114ccd
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9b27
movq 0x18(%rbx), %rax
cmpq $0x1b8000, 0x18(%rax)   # imm = 0x1B8000
jl 0x28a5c
movl $0x6e0, %edx            # imm = 0x6E0
jmp 0x28a61
movl $0x370, %edx            # imm = 0x370
movq %rbx, %rdi
movq %r14, %rsi
callq 0x299fa
testl %eax, %eax
jne 0x28a82
movq %rbx, %rdi
movq %r14, %rsi
movq %r15, %rdx
callq 0x299fa
testl %eax, %eax
je 0x28add
movl $0x1a, %esi
movq %rbx, %rdi
callq 0xf7666
movq %rax, 0x30(%r14)
movq 0x10(%r14), %rdx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x28bc9
movq 0x28(%r14), %rsi
movq %rbx, %rdi
callq 0xe9752
movq 0x30(%r14), %rdi
callq 0xf7689
movq %rbx, %rdi
movq %r14, %rsi
callq 0xe9752
movl 0x4(%rsp), %esi
movq %rbx, %rdi
callq 0xe9595
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x18(%rbx), %rax
movq 0x18(%rax), %rax
cmpq $0x1b7fff, %rax         # imm = 0x1B7FFF
jg 0x28b13
movl $0xdc000, %ecx          # imm = 0xDC000
addq 0x8(%r14), %rcx
cmpq %rcx, %rax
jl 0x28b13
movl $0x6e0, %edx            # imm = 0x6E0
movq %rbx, %rdi
movq %r14, %rsi
callq 0x299fa
testl %eax, %eax
jne 0x28a82
leaq 0xec1ea(%rip), %rsi     # 0x114d04
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9df7
jmp 0x28aa2