// File: /workspace/github_c_makefile_star2_O1/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 0xe969b
movq %rax, %r14
leaq 0xb8292(%rip), %rdi     # 0x124d60
movl $0x10, %edx
movq %rax, %rsi
callq 0xecc60
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 0x6cda8
movq %r14, %rax
addq $0x40, %rax
movq %rax, 0x18(%rsp)
movl $0x1a, %esi
movq %r14, 0x8(%rsp)
movq %rsi, 0x80(%r14)
callq 0xef1ca
movq %rax, 0x88(%r14)
cmpq $0x56, %rax
jl 0x6cda8
addq 0x80(%r14), %rax
movq %rax, 0x90(%r14)
movq 0x18(%rbx), %rcx
cmpq 0x18(%rcx), %rax
jg 0x6cda8
movq %rbx, %rdi
leaq 0x10(%rsp), %rsi
callq 0xe958c
movq 0x80(%r14), %rdx
movq %rbx, %rdi
leaq 0xb8d95(%rip), %rsi     # 0x125910
xorl %eax, %eax
callq 0xe9226
movq %rbx, %rdi
movl $0x1, %esi
callq 0xe9585
movq 0x88(%r14), %rdx
movq %rbx, %rdi
leaq 0xd8635(%rip), %rsi     # 0x1451d5
xorl %eax, %eax
callq 0xe9226
movq 0x80(%r14), %r13
addq $0x56, %r13
cmpq 0x90(%r14), %r13
jge 0x6cd83
movq $0x0, 0x98(%r14)
movq %rbx, %rdi
leaq 0x14(%rsp), %rsi
callq 0xe958c
movq %rbx, %rdi
leaq 0xb8aa4(%rip), %rsi     # 0x125685
movq %r13, %rdx
xorl %eax, %eax
callq 0xe9226
movq %rbx, %rdi
movl $0x1, %esi
callq 0xe9585
movq 0x18(%rbx), %rdi
movq %r13, %rsi
callq 0xef1ca
movq %rbx, %rdi
leaq 0xb8d14(%rip), %rsi     # 0x125922
movl %eax, %edx
xorl %eax, %eax
callq 0xe9226
movq 0x18(%rbx), %rdi
leaq 0x2(%r13), %rsi
callq 0xef1ca
movq %rax, 0x98(%r14)
movq %rbx, %rdi
leaq 0xb8cff(%rip), %rsi     # 0x125934
movq %rax, %rdx
xorl %eax, %eax
callq 0xe9226
movq 0x18(%rbx), %rdi
leaq 0x4(%r13), %rsi
callq 0xef1ca
movq %rax, %rbp
movq 0x18(%rbx), %rdi
leaq 0x6(%r13), %rsi
callq 0xef1ca
movq %rax, %r15
movq %rbx, %rdi
movq %rax, %rsi
movq %rbp, %rdx
callq 0xe9b05
movq %rbx, %rdi
movq %r15, %rsi
movq %rbp, %rdx
callq 0xf241d
testl %eax, %eax
je 0x6cd4b
movq %r15, %rdi
shlq $0x2, %rdi
movl $0x8, %esi
callq 0xea80b
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 0xf2cab
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 0xf35b8
movq %rbx, %rdi
movq %r15, %rsi
movq %rbp, %rdx
movl $0x1, %ecx
callq 0xf2cab
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 0xf35b8
movq %r12, %rdi
movq %r15, %rsi
xorl %edx, %edx
callq 0xf3e1c
movq %r12, %rdi
xorl %esi, %esi
movl $0x2, %edx
callq 0xf2923
jmp 0x6cd51
xorl %r15d, %r15d
xorl %r12d, %r12d
movq %r12, %rdi
callq 0xf28d4
movq %r15, %rdi
callq 0xf28d4
movl 0x14(%rsp), %esi
movq %rbx, %rdi
callq 0xe9595
movq 0x98(%r14), %rax
testq %rax, %rax
je 0x6cd83
leaq 0x8(%r13,%rax,2), %r13
jmp 0x6cbb2
movl 0x10(%rsp), %esi
movq %rbx, %rdi
callq 0xe9595
movq 0x90(%r14), %rsi
leaq 0x56(%rsi), %rax
movq 0x18(%rbx), %rdi
cmpq 0x18(%rdi), %rax
jle 0x6cb24
movq %rbx, %rdi
movq %r14, %rsi
callq 0xe9752
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq