// File: /workspace/github_c_makefile_star2_O1/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 0xe969b
movq %rax, %r12
movq %rbx, %rdi
xorl %esi, %esi
movl $0x9, %edx
callq 0xeb7d1
movl %eax, 0x4(%r12)
movq 0x18(%rbx), %rdi
movl $0x2, %esi
callq 0xef0d5
cmpb $0x4d, %al
je 0x6b36c
movzbl %al, %eax
cmpl $0x32, %eax
jne 0x6b672
movb $0x2, %al
jmp 0x6b36e
movb $0x1, %al
movb %al, (%r12)
movq 0x18(%rbx), %rdi
movl $0x4, %esi
callq 0xef1ca
movq %rax, 0x8(%r12)
leaq 0xa7834(%rip), %rsi     # 0x112bc0
xorl %r15d, %r15d
movq %rbx, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xe9226
movq 0x18(%rbx), %rdi
movl $0x4, %esi
callq 0xef37e
movq %rax, 0x10(%r12)
leaq 0x18(%r12), %rcx
movl $0x10, %r8d
movl $0x32, %edi
xorl %esi, %esi
xorl %edx, %edx
movq %rcx, 0x20(%rsp)
xorl %r9d, %r9d
callq 0xecbbc
movq 0x18(%rbx), %rax
cmpq $0x13, 0x18(%rax)
jl 0x6b682
movl $0x12, %r14d
xorl %r15d, %r15d
movq %r12, 0x10(%rsp)
cmpq 0x10(%r12), %r14
jge 0x6b682
testq %r15, %r15
je 0x6b410
movq 0x10(%r15), %rdi
callq 0xf6bb0
movq %rbx, %rdi
movq %r15, %rsi
callq 0xe9752
movl $0x18, %esi
movq %rbx, %rdi
callq 0xe969b
movq %rax, %r15
movq %r14, (%rax)
movq %rbx, %rdi
leaq 0x1c(%rsp), %rsi
callq 0xe958c
movq (%r15), %rdx
movq %rbx, %rdi
leaq 0xba248(%rip), %rsi     # 0x125685
xorl %eax, %eax
callq 0xe9226
movq %rbx, %rdi
movl $0x1, %esi
callq 0xe9585
movq (%r15), %rax
movq %rax, 0x8(%rsp)
movq 0x18(%rbx), %rdi
leaq 0x8(%rsp), %r13
movq %r13, %rsi
callq 0xef14d
movl %eax, %ebp
movq 0x18(%rbx), %rdi
movq %r13, %rsi
callq 0xef1ed
movq %rax, %r12
movq 0x18(%rbx), %rdi
movq %r13, %rsi
callq 0xef1ed
cmpb $0x4, %bpl
jne 0x6b619
cmpq $0xfff, %r12            # imm = 0xFFF
jg 0x6b619
cmpq $0x1000, %rax           # imm = 0x1000
jge 0x6b619
movq 0x10(%rsp), %r12
cmpb $0x2, (%r12)
jne 0x6b506
movq %rbx, %rdi
callq 0xf6870
movq %rax, 0x10(%r15)
movq 0x18(%rbx), %rdi
movq 0x8(%rsp), %rsi
movl 0x4(%r12), %r9d
movl $0x1a, %edx
movq %rax, %rcx
movl $0x1, %r8d
callq 0xf01b0
movq 0x10(%r15), %rdi
callq 0xf7557
movq %rbx, %rdi
leaq 0xb707d(%rip), %rsi     # 0x122573
movq %rax, %rdx
xorl %eax, %eax
callq 0xe9226
addq $0x1a, 0x8(%rsp)
movq 0x8(%rsp), %rdx
movq %rbx, %rdi
leaq 0xcacad(%rip), %rsi     # 0x1361c2
xorl %eax, %eax
callq 0xe9226
movl $0x20, %esi
movl $0x20, %edx
movq %rbx, %rdi
movl $0x4, %ecx
callq 0xf2cab
movq %rax, %rbp
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 0xf35b8
movq 0x8(%rsp), %rdx
movl $0x200, %eax            # imm = 0x200
addq %rax, %rdx
movq %rdx, 0x8(%rsp)
movq %rbx, %rdi
leaq 0xcf050(%rip), %rsi     # 0x13a5c9
xorl %eax, %eax
callq 0xe9226
movl $0x20, %esi
movl $0x20, %edx
movq %rbx, %rdi
movl $0x1, %ecx
callq 0xf2cab
movq %rax, %r12
movq 0x18(%rbx), %rdi
movq 0x8(%rsp), %rsi
movl $0x4, %edx
movq %rax, %rcx
xorl %r8d, %r8d
callq 0xf3081
subq $-0x80, 0x8(%rsp)
movq %rbp, %rdi
movq %r12, %rsi
movl $0x1, %edx
callq 0xf3e1c
movq %rbx, %rdi
callq 0xea9a9
movq %rax, %r13
cmpb $0x0, 0xd0(%rbx)
je 0x6b5fb
movq 0x10(%r15), %rdi
callq 0xf6c00
testl %eax, %eax
je 0x6b5fb
movq 0x10(%r15), %rdx
movq %rbx, %rdi
movq %r13, %rsi
xorl %ecx, %ecx
callq 0xea9e4
movq %rbp, %rdi
movq %r13, %rsi
movl $0x6, %edx
callq 0xf2917
movq 0x8(%rsp), %rax
subq (%r15), %rax
movq %rax, 0x8(%r15)
jmp 0x6b62a
movq 0x10(%rsp), %rax
movb $0x1, 0x1(%rax)
xorl %r13d, %r13d
xorl %r12d, %r12d
xorl %ebp, %ebp
movq %rbp, %rdi
callq 0xf28d4
movq %r12, %rdi
callq 0xf28d4
movq %rbx, %rdi
movq %r13, %rsi
callq 0xea9b3
movl 0x1c(%rsp), %esi
movq %rbx, %rdi
callq 0xe9595
movq 0x8(%r15), %rax
testq %rax, %rax
jle 0x6b67d
addq %rax, %r14
movq 0x18(%rbx), %rax
cmpq 0x18(%rax), %r14
movq 0x10(%rsp), %r12
jl 0x6b3ec
jmp 0x6b682
movb $0x1, 0x1(%r12)
xorl %r15d, %r15d
jmp 0x6b682
movq 0x10(%rsp), %r12
testq %r15, %r15
je 0x6b69b
movq 0x10(%r15), %rdi
callq 0xf6bb0
movq %rbx, %rdi
movq %r15, %rsi
callq 0xe9752
testq %r12, %r12
je 0x6b6c4
cmpb $0x0, 0x1(%r12)
je 0x6b6b9
leaq 0xad7c0(%rip), %rsi     # 0x118e6f
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9df7
movq %rbx, %rdi
movq %r12, %rsi
callq 0xe9752
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq