// File: /workspace/github_c_makefile_star2_O3/jsummers[P]deark/modules/misc2.c
// Function: de_run_iconmgr_ica
static void de_run_iconmgr_ica(deark *c, de_module_params *mparams)
{
	struct iconmgr_ica_ctx *d = NULL;
	struct iconmgr_icon_ctx *md = NULL;
	u8 b;
	i64 pos;

	d = de_malloc(c, sizeof(struct iconmgr_ica_ctx));
	d->input_encoding = de_get_input_encoding(c, NULL, DE_ENCODING_WINDOWS1252);

	b = de_getbyte(2);
	if(b=='M') {
		d->ver = 1;
	}
	else if(b=='2') {
		d->ver = 2;
	}
	else {
		d->need_errmsg = 1;
		goto done;
	}

	d->icon_count = de_getu16le(4);
	de_dbg(c, "count: %d", (int)d->icon_count);
	d->reported_file_size = de_getu32le(4);

	de_copy_std_palette(DE_PALID_WIN16, 0, 0, d->pal, 16, 0);
	pos = 18;
	while(1) {
		if(pos>=c->infile->len || pos>=d->reported_file_size) goto done;
		if(md) {
			iconmgr_icon_destroy(c, md);
			md = NULL;
		}
		md = de_malloc(c, sizeof(struct iconmgr_icon_ctx));
		md->icon_pos = pos;
		do_iconmgr_icon(c, d, md);
		if(md->total_len<=0) goto done;
		pos += md->total_len;
	}

done:
	iconmgr_icon_destroy(c, md);
	if(d) {
		if(d->need_errmsg) {
			de_err(c, "Bad or unsupported file");
		}
		de_free(c, d);
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rdi, %rbx
movl $0x58, %esi
callq 0xe8b2b
movq %rax, %r14
movq %rax, %r13
movq %rbx, %rdi
xorl %esi, %esi
movl $0x9, %edx
callq 0xeb220
movq %r14, %r15
movl %eax, 0x4(%r14)
movq 0x18(%rbx), %rdi
movl $0x2, %esi
callq 0xeead3
cmpb $0x4d, %al
je 0x6b0fe
movzbl %al, %eax
cmpl $0x32, %eax
jne 0x6b409
movb $0x2, %al
jmp 0x6b100
movb $0x1, %al
movb %al, (%r13)
movq 0x18(%rbx), %rdi
movl $0x4, %esi
callq 0xeebc8
movq %rax, 0x8(%r13)
leaq 0xa7ab3(%rip), %rsi     # 0x112bd0
movq %rbx, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xe8617
movq 0x18(%rbx), %rdi
movl $0x4, %esi
callq 0xeed61
movq %rax, 0x10(%r13)
movq %r15, %rcx
addq $0x18, %rcx
movl $0x10, %r8d
movl $0x32, %edi
xorl %esi, %esi
xorl %edx, %edx
movq %rcx, 0x20(%rsp)
xorl %r9d, %r9d
callq 0xec55a
movq 0x18(%rbx), %rax
cmpq $0x13, 0x18(%rax)
jl 0x6b431
movl $0x12, %r14d
xorl %r12d, %r12d
movq %r13, 0x10(%rsp)
cmpq 0x10(%r13), %r14
jge 0x6b410
testq %r12, %r12
je 0x6b19f
movq 0x10(%r12), %rdi
callq 0xf6753
movq %rbx, %rdi
movq %r12, %rsi
callq 0xe8be2
movl $0x18, %esi
movq %rbx, %rdi
callq 0xe8b2b
movq %rax, %r12
movq %r14, (%rax)
movq %rbx, %rdi
leaq 0x1c(%rsp), %rsi
callq 0xe8a1c
movq (%r12), %rdx
movq %rbx, %rdi
leaq 0xba6e8(%rip), %rsi     # 0x1258b5
xorl %eax, %eax
callq 0xe8617
movq %rbx, %rdi
movl $0x1, %esi
callq 0xe8a15
movq (%r12), %rax
movq %rax, 0x8(%rsp)
movq 0x18(%rbx), %rdi
leaq 0x8(%rsp), %r13
movq %r13, %rsi
callq 0xeeb4b
movl %eax, %ebp
movq 0x18(%rbx), %rdi
movq %r13, %rsi
callq 0xeebeb
movq %rax, %r15
movq 0x18(%rbx), %rdi
movq %r13, %rsi
callq 0xeebeb
cmpb $0x4, %bpl
jne 0x6b295
cmpq $0xfff, %r15            # imm = 0xFFF
jg 0x6b295
cmpq $0x1000, %rax           # imm = 0x1000
jge 0x6b295
movq 0x10(%rsp), %r15
cmpb $0x2, (%r15)
jne 0x6b2ab
movq %rbx, %rdi
callq 0xf6410
movq %rax, 0x10(%r12)
movq 0x18(%rbx), %rdi
movq 0x8(%rsp), %rsi
movl 0x4(%r15), %r9d
movl $0x1a, %edx
movq %rax, %rcx
movl $0x1, %r8d
callq 0xefbd7
movq 0x10(%r12), %rdi
callq 0xf70f6
movq %rbx, %rdi
leaq 0xb7500(%rip), %rsi     # 0x12277b
movq %rax, %rdx
xorl %eax, %eax
callq 0xe8617
movq 0x8(%rsp), %rdx
addq $0x1a, %rdx
movq %rdx, 0x8(%rsp)
jmp 0x6b2b0
movq 0x10(%rsp), %rax
movb $0x1, 0x1(%rax)
xorl %ebp, %ebp
xorl %r15d, %r15d
xorl %r13d, %r13d
jmp 0x6b3c0
movq 0x8(%rsp), %rdx
movq %rbx, %rdi
leaq 0xcb34b(%rip), %rsi     # 0x136605
xorl %eax, %eax
callq 0xe8617
movl $0x20, %esi
movl $0x20, %edx
movq %rbx, %rdi
movl $0x4, %ecx
callq 0xf266a
movq %rax, %r13
movq 0x18(%rbx), %rdi
movq 0x8(%rsp), %rsi
movl $0x0, (%rsp)
movl $0x4, %edx
movl $0x10, %ecx
movq 0x20(%rsp), %r8
movq %rax, %r9
callq 0xf2f79
movq 0x8(%rsp), %rdx
movl $0x200, %eax            # imm = 0x200
addq %rax, %rdx
movq %rdx, 0x8(%rsp)
movq %rbx, %rdi
leaq 0xcf62b(%rip), %rsi     # 0x13a949
xorl %eax, %eax
callq 0xe8617
movl $0x20, %esi
movl $0x20, %edx
movq %rbx, %rdi
movl $0x1, %ecx
callq 0xf266a
movq %rax, %r15
movq 0x18(%rbx), %rdi
movq 0x8(%rsp), %rsi
movl $0x4, %edx
movq %rax, %rcx
xorl %r8d, %r8d
callq 0xf2a40
subq $-0x80, 0x8(%rsp)
movq %r13, %rdi
movq %r15, %rsi
movl $0x1, %edx
callq 0xf37bd
movq %rbx, %rdi
callq 0xea504
movq %rax, %rbp
cmpb $0x0, 0xd0(%rbx)
je 0x6b3a2
movq 0x10(%r12), %rdi
callq 0xf67a3
testl %eax, %eax
je 0x6b3a2
movq 0x10(%r12), %rdx
movq %rbx, %rdi
movq %rbp, %rsi
xorl %ecx, %ecx
callq 0xea53f
movq %r13, %rdi
movq %rbp, %rsi
movl $0x6, %edx
callq 0xf22d0
movq 0x8(%rsp), %rax
subq (%r12), %rax
movq %rax, 0x8(%r12)
movq %r13, %rdi
callq 0xf228d
movq %r15, %rdi
callq 0xf228d
movq %rbx, %rdi
movq %rbp, %rsi
callq 0xea50e
movl 0x1c(%rsp), %esi
movq %rbx, %rdi
callq 0xe8a25
movq 0x8(%r12), %rax
testq %rax, %rax
jle 0x6b417
addq %rax, %r14
movq 0x18(%rbx), %rax
cmpq 0x18(%rax), %r14
movq 0x10(%rsp), %r13
jl 0x6b17b
jmp 0x6b41c
movb $0x1, 0x1(%r13)
jmp 0x6b431
testq %r12, %r12
jne 0x6b41c
jmp 0x6b431
movq 0x10(%rsp), %r13
movq 0x10(%r12), %rdi
callq 0xf6753
movq %rbx, %rdi
movq %r12, %rsi
callq 0xe8be2
cmpb $0x0, 0x1(%r13)
je 0x6b449
leaq 0xadb50(%rip), %rsi     # 0x118f8f
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9295
movq %rbx, %rdi
movq %r13, %rsi
callq 0xe8be2
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq