// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/amigaicon.c
// Function: do_scan_file
static void do_scan_file(deark *c, lctx *d)
{
	i64 main_width;
	i64 main_height;
	i64 pos;
	i64 i;
	i64 x;
	i64 bytesused;
	i64 version;
	int saved_indent_level;

	de_dbg_indent_save(c, &saved_indent_level);
	de_dbg(c, "DiskObject at %d, len=%d", 0, 78);
	de_dbg_indent(c, 1);

	version = de_getu16be(2);
	de_dbg(c, "version: %d", (int)version);

	de_dbg(c, "Gadget at %d, len=%d", 4, 44);
	de_dbg_indent(c, 1);

	main_width = de_getu16be(12);
	main_height = de_getu16be(14);
	de_dbg(c, "main canvas size: %d"DE_CHAR_TIMES"%d", (int)main_width, (int)main_height);

	x = de_getu32be(26);
	de_dbg(c, "SelectRender: 0x%08x", (unsigned int)x);
	d->num_main_icons = (x==0) ? 1 : 2;
	de_dbg_indent(c, 1);
	de_dbg(c, "number of (original) icons: %d", (int)d->num_main_icons);
	de_dbg_indent(c, -1);

	d->icon_revision = de_getu32be(44) & 0xff;
	de_dbg(c, "icon revision: %d", (int)d->icon_revision);

	de_dbg_indent(c, -1); // end of embedded "Gadget" object

	d->icon_type = de_getbyte(48);
	de_dbg(c, "icon type: %d (%s)", (int)d->icon_type, get_icon_type_name(d->icon_type));

	x = de_getu32be(50);
	d->has_defaulttool = (x!=0);
	de_dbg(c, "defaulttool: 0x%08x", (unsigned int)x);

	x = de_getu32be(54);
	d->has_tooltypes = (x!=0);
	de_dbg(c, "tooltypes: 0x%08x", (unsigned int)x);

	x = de_getu32be(66);
	d->has_drawerdata = (x!=0);
	de_dbg(c, "drawerdata: 0x%08x", (unsigned int)x);

	x = de_getu32be(70);
	d->has_toolwindow = (x!=0);
	de_dbg(c, "toolwindow: 0x%08x", (unsigned int)x);

	de_dbg_indent(c, -1);

	pos = 78;

	// DrawerData segment
	if(d->has_drawerdata) {
		const i64 ddlen = 56;
		de_dbg(c, "DrawerData at %"I64_FMT", len=%"I64_FMT, pos, ddlen);
		if(c->debug_level>=2) {
			de_dbg_indent(c, 1);
			de_dbg_hexdump(c, c->infile, pos, ddlen, 256, NULL, 0x1);
			de_dbg_indent(c, -1);
		}
		pos += ddlen;
	}

	// Record the location of the main (original-style) icons
	for(i=0; i<d->num_main_icons; i++) {
		d->main_icon_pos[i] = pos;
		get_main_icon_size(c, d, pos, &bytesused);
		de_dbg(c, "main icon #%d data at %"I64_FMT", len=%"I64_FMT, (int)i,
			d->main_icon_pos[i], bytesused);
		pos += bytesused;
	}

	// DefaultTool segment
	if(d->has_defaulttool) {
		x = de_getu32be(pos);
		de_dbg(c, "DefaultTool at %"I64_FMT", dpos=%"I64_FMT", dlen=%"I64_FMT,
			pos, pos+4, x);
		pos += 4;
		if(c->debug_level>=2) {
			de_dbg_indent(c, 1);
			de_dbg_hexdump(c, c->infile, pos, x, 256, NULL, 0x1);
			de_dbg_indent(c, -1);
		}
		pos += x;
	}

	if(d->has_tooltypes) {
		// This will also read NewIcons-style icons.
		if(!do_read_tooltypes_table(c, d, pos, &bytesused))
			goto done;
		pos += bytesused;
	}

	// Skip the ToolWindow segment (untested)
	if(d->has_toolwindow) {
		x = de_getu32be(pos);
		de_dbg(c, "ToolWindow: %d bytes at %d", (int)(4+x), (int)pos);
		pos += 4+x;
	}

	// DrawerData2
	if(d->has_drawerdata && d->icon_revision==1) {
		const i64 dd2len = 6;
		de_dbg(c, "DrawerData2 at %"I64_FMT", len=%"I64_FMT, pos, dd2len);
		if(c->debug_level>=2) {
			de_dbg_indent(c, 1);
			de_dbg_hexdump(c, c->infile, pos, dd2len, 256, NULL, 0x1);
			de_dbg_indent(c, -1);
		}
		pos += dd2len;
	}

	if(do_detect_glowicons(c, d, pos)) {
		d->has_glowicons = 1;
		d->glowicons_pos = pos;
	}

done:
	de_dbg_indent_restore(c, saved_indent_level);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x80, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rdi
leaq -0x4c(%rbp), %rsi
callq 0x15b580
movq -0x8(%rbp), %rdi
leaq 0x17f8e2(%rip), %rsi    # 0x19d50d
xorl %edx, %edx
movl $0x4e, %ecx
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movl $0x1, %esi
callq 0x15b560
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movl $0x2, %esi
callq 0x1651d0
movq %rax, -0x48(%rbp)
movq -0x8(%rbp), %rdi
movq -0x48(%rbp), %rax
movl %eax, %edx
leaq 0x1a25a2(%rip), %rsi    # 0x1c0210
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
leaq 0x17f8a6(%rip), %rsi    # 0x19d526
movl $0x4, %edx
movl $0x2c, %ecx
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movl $0x1, %esi
callq 0x15b560
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movl $0xc, %esi
callq 0x1651d0
movq %rax, -0x18(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movl $0xe, %esi
callq 0x1651d0
movq %rax, -0x20(%rbp)
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movl %eax, %edx
movq -0x20(%rbp), %rax
movl %eax, %ecx
leaq 0x17f859(%rip), %rsi    # 0x19d53b
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movl $0x1a, %esi
callq 0x165470
movq %rax, -0x38(%rbp)
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rax
movl %eax, %edx
leaq 0x17f844(%rip), %rsi    # 0x19d554
movb $0x0, %al
callq 0x15b0d0
movq -0x38(%rbp), %rdx
movl $0x2, %eax
movl $0x1, %ecx
cmpq $0x0, %rdx
cmovel %ecx, %eax
movslq %eax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x20(%rax)
movq -0x8(%rbp), %rdi
movl $0x1, %esi
callq 0x15b560
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rax
movl %eax, %edx
leaq 0x17f80f(%rip), %rsi    # 0x19d569
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x15b560
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movl $0x2c, %esi
callq 0x165470
movq %rax, %rcx
andq $0xff, %rcx
movq -0x10(%rbp), %rax
movq %rcx, (%rax)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movq (%rax), %rax
movl %eax, %edx
leaq 0x17f7e2(%rip), %rsi    # 0x19d588
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x15b560
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movl $0x30, %esi
callq 0x165060
movb %al, %cl
movq -0x10(%rbp), %rax
movb %cl, 0x8(%rax)
movq -0x8(%rbp), %rax
movq %rax, -0x70(%rbp)
movq -0x10(%rbp), %rax
movzbl 0x8(%rax), %eax
movl %eax, -0x64(%rbp)
movq -0x10(%rbp), %rax
movzbl 0x8(%rax), %edi
callq 0x1ebc0
movq -0x70(%rbp), %rdi
movl -0x64(%rbp), %edx
movq %rax, %rcx
leaq 0x17f793(%rip), %rsi    # 0x19d59a
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movl $0x32, %esi
callq 0x165470
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x38(%rbp)
setne %al
andb $0x1, %al
movzbl %al, %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x14(%rax)
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rax
movl %eax, %edx
leaq 0x17f764(%rip), %rsi    # 0x19d5ad
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movl $0x36, %esi
callq 0x165470
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x38(%rbp)
setne %al
andb $0x1, %al
movzbl %al, %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x18(%rax)
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rax
movl %eax, %edx
leaq 0x17f736(%rip), %rsi    # 0x19d5c1
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movl $0x42, %esi
callq 0x165470
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x38(%rbp)
setne %al
andb $0x1, %al
movzbl %al, %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0xc(%rax)
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rax
movl %eax, %edx
leaq 0x17f706(%rip), %rsi    # 0x19d5d3
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movl $0x46, %esi
callq 0x165470
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x38(%rbp)
setne %al
andb $0x1, %al
movzbl %al, %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x10(%rax)
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rax
movl %eax, %edx
leaq 0x17f6d7(%rip), %rsi    # 0x19d5e6
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x15b560
movq $0x4e, -0x28(%rbp)
movq -0x10(%rbp), %rax
cmpl $0x0, 0xc(%rax)
je 0x1dfba
movq $0x38, -0x58(%rbp)
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rdx
leaq 0x17f6a8(%rip), %rsi    # 0x19d5f9
movl $0x38, %ecx
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rax
cmpl $0x2, (%rax)
jl 0x1dfae
movq -0x8(%rbp), %rdi
movl $0x1, %esi
callq 0x15b560
movq -0x8(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rsi
movq -0x28(%rbp), %rdx
movl $0x38, %ecx
movl $0x100, %r8d            # imm = 0x100
xorl %eax, %eax
movl %eax, %r9d
movl $0x1, (%rsp)
callq 0x15b840
movq -0x8(%rbp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x15b560
movq -0x28(%rbp), %rax
addq $0x38, %rax
movq %rax, -0x28(%rbp)
movq $0x0, -0x30(%rbp)
movq -0x30(%rbp), %rax
movq -0x10(%rbp), %rcx
cmpq 0x20(%rcx), %rax
jge 0x1e039
movq -0x28(%rbp), %rdx
movq -0x10(%rbp), %rax
movq -0x30(%rbp), %rcx
movq %rdx, 0x28(%rax,%rcx,8)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x28(%rbp), %rdx
leaq -0x40(%rbp), %rcx
callq 0x1ec70
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rax
movl %eax, %edx
movq -0x10(%rbp), %rax
movq -0x30(%rbp), %rcx
movq 0x28(%rax,%rcx,8), %rcx
movq -0x40(%rbp), %r8
leaq 0x17f5fc(%rip), %rsi    # 0x19d614
movb $0x0, %al
callq 0x15b0d0
movq -0x40(%rbp), %rax
addq -0x28(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x30(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x30(%rbp)
jmp 0x1dfc2
movq -0x10(%rbp), %rax
cmpl $0x0, 0x14(%rax)
je 0x1e0e6
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x28(%rbp), %rsi
callq 0x165470
movq %rax, -0x38(%rbp)
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rdx
movq -0x28(%rbp), %rcx
addq $0x4, %rcx
movq -0x38(%rbp), %r8
leaq 0x17f5c0(%rip), %rsi    # 0x19d637
movb $0x0, %al
callq 0x15b0d0
movq -0x28(%rbp), %rax
addq $0x4, %rax
movq %rax, -0x28(%rbp)
movq -0x8(%rbp), %rax
cmpl $0x2, (%rax)
jl 0x1e0da
movq -0x8(%rbp), %rdi
movl $0x1, %esi
callq 0x15b560
movq -0x8(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rsi
movq -0x28(%rbp), %rdx
movq -0x38(%rbp), %rcx
movl $0x100, %r8d            # imm = 0x100
xorl %eax, %eax
movl %eax, %r9d
movl $0x1, (%rsp)
callq 0x15b840
movq -0x8(%rbp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x15b560
movq -0x38(%rbp), %rax
addq -0x28(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x10(%rbp), %rax
cmpl $0x0, 0x18(%rax)
je 0x1e11b
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x28(%rbp), %rdx
leaq -0x40(%rbp), %rcx
callq 0x1ed20
cmpl $0x0, %eax
jne 0x1e10f
jmp 0x1e237
movq -0x40(%rbp), %rax
addq -0x28(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x10(%rbp), %rax
cmpl $0x0, 0x10(%rax)
je 0x1e16c
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x28(%rbp), %rsi
callq 0x165470
movq %rax, -0x38(%rbp)
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rax
addq $0x4, %rax
movl %eax, %edx
movq -0x28(%rbp), %rax
movl %eax, %ecx
leaq 0x17f509(%rip), %rsi    # 0x19d65e
movb $0x0, %al
callq 0x15b0d0
movq -0x38(%rbp), %rax
addq $0x4, %rax
addq -0x28(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x10(%rbp), %rax
cmpl $0x0, 0xc(%rax)
je 0x1e208
movq -0x10(%rbp), %rax
cmpq $0x1, (%rax)
jne 0x1e208
movq $0x6, -0x60(%rbp)
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rdx
leaq 0x17f4da(%rip), %rsi    # 0x19d679
movl $0x6, %ecx
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rax
cmpl $0x2, (%rax)
jl 0x1e1fc
movq -0x8(%rbp), %rdi
movl $0x1, %esi
callq 0x15b560
movq -0x8(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rsi
movq -0x28(%rbp), %rdx
movl $0x6, %ecx
movl $0x100, %r8d            # imm = 0x100
xorl %eax, %eax
movl %eax, %r9d
movl $0x1, (%rsp)
callq 0x15b840
movq -0x8(%rbp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x15b560
movq -0x28(%rbp), %rax
addq $0x6, %rax
movq %rax, -0x28(%rbp)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x28(%rbp), %rdx
callq 0x1eed0
cmpl $0x0, %eax
je 0x1e235
movq -0x10(%rbp), %rax
movl $0x1, 0x68(%rax)
movq -0x28(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x70(%rax)
jmp 0x1e237
movq -0x8(%rbp), %rdi
movl -0x4c(%rbp), %esi
callq 0x15b5a0
addq $0x80, %rsp
popq %rbp
retq
nopl (%rax)