// File: /workspace/github_c_makefile_star2_O3/jsummers[P]deark/modules/misc2.c
// Function: de_run_apple2icons
static void de_run_apple2icons(deark *c, de_module_params *mparams)
{
	struct a2icons_ctx *d = NULL;
	i64 curpos;
	i64 i;
	// Some colors here are just educated guesses.
	static const u8 dflt_pal[16*3] = {
		0,0,0, 0,0,128, 128,128,0, 128,128,128,
		128,0,0, 128,0,128, 255,128,0, 255,128,128,
		0,128,0, 0,128,128, 128,255,0, 128,255,128,
		192,192,192, 128,128,255, 255,255,128, 255,255,255 };

	d = de_malloc(c, sizeof(struct a2icons_ctx));
	de_copy_palette_from_rgb24(dflt_pal, d->pal, 16);

	d->maskpal[0] = DE_STOCKCOLOR_BLACK;
	for(i=1; i<16; i++) {
		d->maskpal[i] = DE_STOCKCOLOR_WHITE;
	}

	curpos = 26;
	while(1) {
		if(curpos+A2I_GROUP_HDR_SIZE > c->infile->len) goto done;
		d->group_startpos = curpos;
		d->group_len = de_getu16le(curpos);
		if(d->group_len<A2I_GROUP_HDR_SIZE) goto done;
		d->group_endpos = d->group_startpos+d->group_len;
		if(d->group_endpos > c->infile->len) goto done;

		do_a2i_icon_group(c, d);
		curpos = d->group_endpos;
	}

done:
	de_free(c, d);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rdi, %rbx
movl $0xa0, %esi
callq 0xe8b2b
movq %rax, %r14
leaq 0xb86eb(%rip), %rdi     # 0x124f80
movl $0x10, %edx
movq %rax, %rsi
callq 0xec5fe
movl $0xff000000, 0x40(%r14) # imm = 0xFF000000
pcmpeqd %xmm0, %xmm0
movdqu %xmm0, 0x44(%r14)
movdqu %xmm0, 0x54(%r14)
movdqu %xmm0, 0x64(%r14)
movdqu %xmm0, 0x70(%r14)
movq 0x18(%rbx), %rdi
cmpq $0x70, 0x18(%rdi)
jl 0x6cb6f
movq %r14, %rax
addq $0x40, %rax
movq %rax, 0x18(%rsp)
movl $0x1a, %esi
movq %r14, 0x8(%rsp)
movq %rsi, 0x80(%r14)
callq 0xeebc8
movq %rax, 0x88(%r14)
cmpq $0x56, %rax
jl 0x6cb6f
addq 0x80(%r14), %rax
movq %rax, 0x90(%r14)
movq 0x18(%rbx), %rcx
cmpq 0x18(%rcx), %rax
jg 0x6cb6f
movq %rbx, %rdi
leaq 0x10(%rsp), %rsi
callq 0xe8a1c
movq 0x80(%r14), %rdx
movq %rbx, %rdi
leaq 0xb91fe(%rip), %rsi     # 0x125b40
xorl %eax, %eax
callq 0xe8617
movq %rbx, %rdi
movl $0x1, %esi
callq 0xe8a15
movq 0x88(%r14), %rdx
movq %rbx, %rdi
leaq 0xd8d4e(%rip), %rsi     # 0x1456b5
xorl %eax, %eax
callq 0xe8617
movq 0x80(%r14), %r13
addq $0x56, %r13
cmpq 0x90(%r14), %r13
jge 0x6cb4a
movq $0x0, 0x98(%r14)
movq %rbx, %rdi
leaq 0x14(%rsp), %rsi
callq 0xe8a1c
movq %rbx, %rdi
leaq 0xb8f0d(%rip), %rsi     # 0x1258b5
movq %r13, %rdx
xorl %eax, %eax
callq 0xe8617
movq %rbx, %rdi
movl $0x1, %esi
callq 0xe8a15
movq 0x18(%rbx), %rdi
movq %r13, %rsi
callq 0xeebc8
movq %rbx, %rdi
leaq 0xb917d(%rip), %rsi     # 0x125b52
movl %eax, %edx
xorl %eax, %eax
callq 0xe8617
movq 0x18(%rbx), %rdi
leaq 0x2(%r13), %rsi
callq 0xeebc8
movq %rax, 0x98(%r14)
movq %rbx, %rdi
leaq 0xb9168(%rip), %rsi     # 0x125b64
movq %rax, %rdx
xorl %eax, %eax
callq 0xe8617
movq 0x18(%rbx), %rdi
leaq 0x4(%r13), %rsi
callq 0xeebc8
movq %rax, %rbp
movq 0x18(%rbx), %rdi
leaq 0x6(%r13), %rsi
callq 0xeebc8
movq %rax, %r15
movq %rbx, %rdi
movq %rax, %rsi
movq %rbp, %rdx
callq 0xe8f88
movq %rbx, %rdi
movq %r15, %rsi
movq %rbp, %rdx
callq 0xf1db1
testl %eax, %eax
je 0x6cb12
movq %r15, %rdi
shlq $0x2, %rdi
movl $0x8, %esi
callq 0xe9cb4
leaq 0x7(%rax), %r14
testq %rax, %rax
cmovnsq %rax, %r14
sarq $0x3, %r14
movq %rbx, %rdi
movq %r15, %rsi
movq %rbp, %rdx
movl $0x4, %ecx
callq 0xf266a
movq %rax, 0x20(%rsp)
movq 0x18(%rbx), %rdi
leaq 0x8(%r13), %r12
xorl %ecx, %ecx
movl %ecx, (%rsp)
movl $0x4, %edx
movq %r12, %rsi
movq %r14, %rcx
movq 0x8(%rsp), %r8
movq %rax, %r9
callq 0xf2f79
movq %rbx, %rdi
movq %r15, %rsi
movq %rbp, %rdx
movl $0x1, %ecx
callq 0xf266a
movq %rax, %r15
movq 0x18(%rbx), %rdi
movq 0x8(%rsp), %rax
addq 0x98(%rax), %r12
xorl %eax, %eax
movl %eax, (%rsp)
movl $0x4, %edx
movq %r12, %rsi
movq 0x20(%rsp), %r12
movq %r14, %rcx
movq 0x8(%rsp), %r14
movq 0x18(%rsp), %r8
movq %r15, %r9
callq 0xf2f79
movq %r12, %rdi
movq %r15, %rsi
xorl %edx, %edx
callq 0xf37bd
movq %r12, %rdi
xorl %esi, %esi
movl $0x2, %edx
callq 0xf22dc
jmp 0x6cb18
xorl %r15d, %r15d
xorl %r12d, %r12d
movq %r12, %rdi
callq 0xf228d
movq %r15, %rdi
callq 0xf228d
movl 0x14(%rsp), %esi
movq %rbx, %rdi
callq 0xe8a25
movq 0x98(%r14), %rax
testq %rax, %rax
je 0x6cb4a
leaq 0x8(%r13,%rax,2), %r13
jmp 0x6c979
movl 0x10(%rsp), %esi
movq %rbx, %rdi
callq 0xe8a25
movq 0x90(%r14), %rsi
leaq 0x56(%rsi), %rax
movq 0x18(%rbx), %rdi
cmpq 0x18(%rdi), %rax
jle 0x6c8eb
movq %rbx, %rdi
movq %r14, %rsi
callq 0xe8be2
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq