// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq $0x0, -0x18(%rbp)
movq -0x8(%rbp), %rdi
leaq -0x24(%rbp), %rsi
callq 0x15b580
movq -0x8(%rbp), %rdi
movl $0x38, %esi
callq 0x15b780
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rax
movq $0x200, 0x8(%rax)       # imm = 0x200
movq -0x8(%rbp), %rdi
leaq 0x191c10(%rip), %rsi    # 0x1c4f8e
xorl %edx, %edx
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movl $0x1, %esi
callq 0x15b560
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movl $0x3, %esi
callq 0x165060
movzbl %al, %eax
andl $0x7, %eax
movb %al, %cl
movq -0x18(%rbp), %rax
movb %cl, 0x24(%rax)
movq -0x8(%rbp), %rdi
callq 0x1711d0
movq %rax, -0x30(%rbp)
movq -0x18(%rbp), %rax
movzbl 0x24(%rax), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x333da
movq -0x18(%rbp), %rax
movb $0x1, (%rax)
movq -0x18(%rbp), %rax
movzbl 0x24(%rax), %eax
andl $0x2, %eax
cmpl $0x0, %eax
je 0x333f2
movq -0x18(%rbp), %rax
movb $0x1, 0x1(%rax)
movq -0x18(%rbp), %rax
movzbl 0x24(%rax), %eax
andl $0x4, %eax
cmpl $0x0, %eax
je 0x33412
movq -0x18(%rbp), %rax
movb $0x1, 0x1(%rax)
movq -0x18(%rbp), %rax
movb $0x1, 0x2(%rax)
movq -0x30(%rbp), %rdi
movq -0x18(%rbp), %rax
movzbl (%rax), %ecx
leaq 0x16d6db(%rip), %rsi    # 0x1a0aff
leaq 0x16d6d0(%rip), %rax    # 0x1a0afb
cmpl $0x0, %ecx
cmovneq %rax, %rsi
callq 0x172680
movq -0x18(%rbp), %rax
cmpb $0x0, 0x1(%rax)
je 0x33451
movq -0x30(%rbp), %rdi
leaq 0x16d6b7(%rip), %rsi    # 0x1a0b03
callq 0x172680
movq -0x18(%rbp), %rax
cmpb $0x0, 0x2(%rax)
je 0x3346b
movq -0x30(%rbp), %rdi
leaq 0x16d6b0(%rip), %rsi    # 0x1a0b16
callq 0x172680
movq -0x8(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x18(%rbp), %rax
movzbl 0x24(%rax), %eax
movl %eax, -0x34(%rbp)
movq -0x30(%rbp), %rdi
callq 0x172650
movq -0x40(%rbp), %rdi
movl -0x34(%rbp), %edx
movq %rax, %rcx
leaq 0x18694e(%rip), %rsi    # 0x1b9de6
movb $0x0, %al
callq 0x15b0d0
movq -0x30(%rbp), %rdi
callq 0x171750
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movzbl (%rax), %ecx
leaq 0x16d645(%rip), %rdx    # 0x1a0aff
leaq 0x16d63a(%rip), %rax    # 0x1a0afb
cmpl $0x0, %ecx
cmovneq %rax, %rdx
leaq 0x16d655(%rip), %rsi    # 0x1a0b24
movb $0x0, %al
callq 0x15e3d0
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movl $0x8, %esi
callq 0x165470
movq %rax, -0x20(%rbp)
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rdx
leaq 0x16d637(%rip), %rsi    # 0x1a0b32
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x18(%rax), %rdi
movl $0x200, %esi            # imm = 0x200
callq 0x15ce90
movl $0x200, %ecx            # imm = 0x200
cqto
idivq %rcx
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x18(%rbp), %rax
cmpq $0xdc0, 0x18(%rax)      # imm = 0xDC0
jle 0x33547
movq -0x18(%rbp), %rax
movq $0xdc0, 0x18(%rax)      # imm = 0xDC0
movq -0x8(%rbp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x15b560
movq -0x18(%rbp), %rax
movzbl 0x2(%rax), %eax
cmpl $0x0, %eax
jne 0x3356f
movq -0x18(%rbp), %rax
movzbl 0x1(%rax), %eax
cmpl $0x0, %eax
je 0x33581
movq -0x8(%rbp), %rdi
leaq 0x16d5d3(%rip), %rsi    # 0x1a0b4d
movb $0x0, %al
callq 0x15bc10
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
callq 0x33720
cmpl $0x0, %eax
jne 0x335ab
movq -0x8(%rbp), %rdi
leaq 0x16d5e2(%rip), %rsi    # 0x1a0b84
movb $0x0, %al
callq 0x15bfb0
jmp 0x335e2
movq -0x8(%rbp), %rdi
movl $0x1a, %esi
callq 0x1727a0
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x30(%rax)
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rdx
callq 0x33810
cmpl $0x0, %eax
jne 0x335e0
jmp 0x335e2
jmp 0x335e2
cmpq $0x0, -0x18(%rbp)
je 0x33614
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x28(%rax), %rsi
callq 0x15b820
movq -0x18(%rbp), %rax
movq 0x30(%rax), %rdi
callq 0x1727f0
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x15b820
movq -0x8(%rbp), %rdi
movl -0x24(%rbp), %esi
callq 0x15b5a0
addq $0x40, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)