// File: /workspace/github_c_makefile_star2_O2/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 0xdecaf
movq %rax, %r14
leaq 0xaf201(%rip), %rdi     # 0x117d80
pushq $0x10
popq %rdx
movq %rax, %rsi
callq 0xe1b9f
movl $0xff000000, 0x40(%r14) # imm = 0xFF000000
movq %r14, %rax
addq $0x40, %rax
movq %rax, 0x20(%rsp)
pushq $0x11
popq %rax
cmpq $0x20, %rax
je 0x68bb1
orl $-0x1, (%r14,%rax,4)
incq %rax
jmp 0x68ba1
pushq $0x1a
popq %rsi
pushq $0x1
popq %rbp
leaq 0x56(%rsi), %rax
movq 0x18(%rbx), %rdi
cmpq 0x18(%rdi), %rax
jg 0x68e36
movq %rsi, 0x80(%r14)
callq 0xe3fa3
movq %rax, 0x88(%r14)
cmpq $0x56, %rax
jl 0x68e36
addq 0x80(%r14), %rax
movq %rax, 0x90(%r14)
movq 0x18(%rbx), %rcx
cmpq 0x18(%rcx), %rax
jg 0x68e36
movq %rbx, %rdi
leaq 0x8(%rsp), %rsi
callq 0xdebae
movq 0x80(%r14), %rdx
movq %rbx, %rdi
leaq 0xafd20(%rip), %rsi     # 0x118940
xorl %eax, %eax
callq 0xde896
movq %rbx, %rdi
movl %ebp, %esi
callq 0xdeba7
movq 0x88(%r14), %rdx
movq %rbx, %rdi
leaq 0xcf623(%rip), %rsi     # 0x138265
xorl %eax, %eax
callq 0xde896
movq 0x80(%r14), %r15
addq $0x56, %r15
cmpq 0x90(%r14), %r15
jge 0x68e1e
andq $0x0, 0x98(%r14)
movq %rbx, %rdi
leaq 0xc(%rsp), %rsi
callq 0xdebae
movq %rbx, %rdi
leaq 0xafa35(%rip), %rsi     # 0x1186b5
movq %r15, %rdx
xorl %eax, %eax
callq 0xde896
movq %rbx, %rdi
movl %ebp, %esi
callq 0xdeba7
movq 0x18(%rbx), %rdi
movq %r15, %rsi
callq 0xe3fa3
movq %rbx, %rdi
leaq 0xafca8(%rip), %rsi     # 0x118952
movl %eax, %edx
xorl %eax, %eax
callq 0xde896
movq 0x18(%rbx), %rdi
leaq 0x2(%r15), %rsi
callq 0xe3fa3
movq %rax, 0x98(%r14)
movq %rbx, %rdi
leaq 0xafc93(%rip), %rsi     # 0x118964
movq %rax, %rdx
xorl %eax, %eax
callq 0xde896
movq 0x18(%rbx), %rdi
leaq 0x4(%r15), %rsi
callq 0xe3fa3
movq %rax, %r13
movq 0x18(%rbx), %rdi
leaq 0x6(%r15), %rsi
callq 0xe3fa3
movq %rax, %rbp
movq %rbx, %rdi
movq %rax, %rsi
movq %r13, %rdx
callq 0xdf038
movq %rbx, %rdi
movq %rbp, %rsi
movq %r13, %rdx
callq 0xe6be1
testl %eax, %eax
je 0x68de0
movq %rbp, %rdi
shlq $0x2, %rdi
movq %r15, 0x18(%rsp)
pushq $0x8
popq %r15
movq %r15, %rsi
callq 0xdfbb6
cqto
idivq %r15
movq %rax, 0x10(%rsp)
movq %rbx, %rdi
movq %rbp, %rsi
movq %r13, %rdx
pushq $0x4
popq %rcx
callq 0xe7437
movq %rax, %r12
movq 0x18(%rbx), %rdi
movq %r14, %r15
movq 0x18(%rsp), %rax
leaq 0x8(%rax), %r14
andl $0x0, (%rsp)
movq %r14, %rsi
pushq $0x4
popq %rdx
movq 0x10(%rsp), %rcx
movq %r15, %r8
movq %r12, %r9
callq 0xe7cbc
movq %rbx, %rdi
movq %rbp, %rsi
movq %r13, %rdx
pushq $0x1
popq %rbp
movl %ebp, %ecx
callq 0xe7437
movq %rax, %r13
movq 0x18(%rbx), %rdi
addq 0x98(%r15), %r14
andl $0x0, (%rsp)
movq %r14, %rsi
movq %r15, %r14
movq 0x18(%rsp), %r15
pushq $0x4
popq %rdx
movq 0x10(%rsp), %rcx
movq 0x20(%rsp), %r8
movq %rax, %r9
callq 0xe7cbc
movq %r12, %rdi
movq %r13, %rsi
xorl %edx, %edx
callq 0xe83f8
movq %r12, %rdi
xorl %esi, %esi
pushq $0x2
popq %rdx
callq 0xe70b7
jmp 0x68de9
xorl %r13d, %r13d
xorl %r12d, %r12d
pushq $0x1
popq %rbp
movq %r12, %rdi
callq 0xe7084
movq %r13, %rdi
callq 0xe7084
movl 0xc(%rsp), %esi
movq %rbx, %rdi
callq 0xdebb7
movq 0x98(%r14), %rax
testq %rax, %rax
je 0x68e1e
leaq (%r15,%rax,2), %r15
addq $0x8, %r15
jmp 0x68c54
movl 0x8(%rsp), %esi
movq %rbx, %rdi
callq 0xdebb7
movq 0x90(%r14), %rsi
jmp 0x68bb7
movq %rbx, %rdi
movq %r14, %rsi
callq 0xded32
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq