// File: /workspace/github_c_makefile_star2_O2/jsummers[P]deark/modules/ico.c
// Function: de_run_ico
static void de_run_ico(deark *c, de_module_params *mparams)
{
	lctx *d = NULL;
	i64 x;
	i64 num_images;
	i64 i;

	d = de_malloc(c, sizeof(lctx));
	d->extract_unused_masks = (c->extract_level>=2);

	x = de_getu16le(2);
	if(x==1) {
		d->is_cur=0;
		de_declare_fmt(c, "Windows Icon");
	}
	else if(x==2) {
		d->is_cur=1;
		de_declare_fmt(c, "Windows Cursor");
	}
	else {
		de_dbg(c, "Not an ICO/CUR file");
		goto done;
	}

	num_images = de_getu16le(4);
	de_dbg(c, "images in file: %d", (int)num_images);
	if(!de_good_image_count(c, num_images)) {
		goto done;
	}

	for(i=0; i<num_images; i++) {
		do_image_dir_entry(c, d, i, 6+16*i);
	}

done:
	de_free(c, d);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xa8, %rsp
movq %rdi, %rbx
pushq $0x8
popq %rsi
callq 0xdecaf
xorl %ecx, %ecx
cmpl $0x2, 0x90(%rbx)
setge %cl
movq %rax, 0x18(%rsp)
movl %ecx, 0x4(%rax)
movq 0x18(%rbx), %rdi
pushq $0x2
popq %rsi
callq 0xe3fa3
cmpq $0x1, %rax
je 0x72704
cmpq $0x2, %rax
jne 0x72db9
pushq $0x1
popq %rax
leaq 0xa8d01(%rip), %rsi     # 0x11b403
jmp 0x7270d
leaq 0xa8ceb(%rip), %rsi     # 0x11b3f6
xorl %eax, %eax
movq 0x18(%rsp), %rcx
movl %eax, (%rcx)
movq %rbx, %rdi
callq 0xe07f7
movq 0x18(%rbx), %rdi
pushq $0x4
popq %rsi
callq 0xe3fa3
movq %rax, %r14
leaq 0xa8cf4(%rip), %rsi     # 0x11b426
movq %rbx, %rdi
movl %r14d, %edx
xorl %eax, %eax
callq 0xde896
movq %rbx, %rdi
movq %r14, %r15
movq %r14, %rsi
callq 0xe6ccb
testl %eax, %eax
je 0x72dca
xorl %eax, %eax
testq %r15, %r15
cmovleq %rax, %r15
movq %r15, 0x38(%rsp)
pushq $0x1
popq %rbp
xorl %r12d, %r12d
movq %rbx, 0x20(%rsp)
cmpq 0x38(%rsp), %r12
je 0x72dca
movq %r12, %r14
shlq $0x4, %r14
movl $0x500, %esi            # imm = 0x500
movq %rbx, %rdi
callq 0xdecaf
movq %rax, %r13
movq %r12, (%rax)
leal 0x6(%r14), %ecx
movq %rbx, %rdi
leaq 0xa8c98(%rip), %rsi     # 0x11b439
movl %r12d, %edx
xorl %eax, %eax
callq 0xde896
movq %rbx, %rdi
movl %ebp, %esi
callq 0xdeba7
movq 0x18(%rsp), %rax
cmpl $0x0, (%rax)
je 0x727fe
movq 0x18(%rbx), %rdi
movq %r14, %rsi
orq $0xa, %rsi
callq 0xe3fa3
movl %eax, 0x18(%r13)
movq 0x18(%rbx), %rdi
movq %r14, %rsi
orq $0xc, %rsi
callq 0xe3fa3
movl %eax, 0x1c(%r13)
movl 0x18(%r13), %edx
movq %rbx, %rdi
leaq 0x9dab2(%rip), %rsi     # 0x1102a7
movl %eax, %ecx
xorl %eax, %eax
callq 0xde896
movq 0x18(%rbx), %rdi
movq %r14, %rsi
orq $0xe, %rsi
callq 0xe409f
movq %rax, 0x8(%r13)
movq 0x18(%rbx), %rdi
addq $0x12, %r14
movq %r14, %rsi
callq 0xe409f
movq %rax, 0x10(%r13)
movq 0x8(%r13), %rcx
movq %rbx, %rdi
leaq 0x9d886(%rip), %rsi     # 0x1100ba
movq %rax, %rdx
xorl %eax, %eax
callq 0xde896
movq 0x8(%r13), %r15
movq 0x10(%r13), %r14
leaq (%r15,%r14), %rax
movq 0x18(%rbx), %rsi
cmpq 0x18(%rsi), %rax
jle 0x7285c
xorl %r14d, %r14d
jmp 0x72907
movq %r12, 0x10(%rsp)
leaq 0x50(%r13), %r12
movq %rbx, %rdi
movq %r12, %rdx
movq %r14, %rcx
movq %r15, %r8
pushq $0x2
popq %r9
callq 0xebba5
testl %eax, %eax
je 0x728ee
cmpl $0x1, (%r12)
movq %r13, 0x28(%rsp)
jne 0x72958
movq 0x20(%rsp), %rbx
movq 0x18(%rbx), %rdi
leaq 0x10(%r14), %rsi
callq 0xe404f
movq %rax, %r12
movq 0x18(%rbx), %rdi
leaq 0x14(%r14), %rsi
callq 0xe404f
leaq 0x60(%rsp), %r13
movq %r13, %rdi
pushq $0x40
popq %rsi
leaq 0xa8c28(%rip), %rdx     # 0x11b4ea
movl %r12d, %ecx
movl %eax, %r8d
xorl %eax, %eax
callq 0xde40c
movq 0x18(%rbx), %rdi
movq %r14, %rsi
movq %r15, %rdx
movq %r13, %rcx
movq 0x28(%rsp), %r13
xorl %r8d, %r8d
xorl %r9d, %r9d
callq 0xe4e0b
jmp 0x728ff
movq %rbx, %rdi
leaq 0x9c4bf(%rip), %rsi     # 0x10edb7
xorl %eax, %eax
callq 0xdf2a5
xorl %r14d, %r14d
movq 0x10(%rsp), %r12
movq 0xf0(%r13), %rdi
callq 0xe7084
andq $0x0, 0xf0(%r13)
movq 0xf8(%r13), %rdi
callq 0xe7084
andq $0x0, 0xf8(%r13)
movq %rbx, %rdi
movq %r14, %rsi
callq 0xdfd24
movq %rbx, %rdi
movq %r13, %rsi
callq 0xded32
movq %rbx, %rdi
pushq $-0x1
popq %rsi
callq 0xdeba7
incq %r12
jmp 0x7276e
movq 0x80(%r13), %r9
cmpq $0x20, %r9
movq 0x20(%rsp), %rbx
ja 0x72bca
movabsq $0x101000116, %rax      # imm = 0x101000116
btq %r9, %rax
jae 0x72bb1
cmpl $0x0, 0x88(%r13)
movq 0x10(%rsp), %r12
je 0x729a7
movq %rbx, %rdi
leaq 0xa8aff(%rip), %rsi     # 0x11b49a
xorl %eax, %eax
callq 0xdf2a5
jmp 0x72854
movl %ebp, %eax
cmpq $0x20, %r9
jne 0x729b9
movl $0x1, 0x44(%r13)
xorl %eax, %eax
movl %eax, 0x40(%r13)
movl 0x70(%r13), %ecx
movl 0x78(%r13), %r8d
leaq 0x60(%rsp), %rdi
pushq $0x20
popq %rsi
leaq 0xa7bcb(%rip), %rdx     # 0x11a59f
xorl %eax, %eax
callq 0xde40c
movq 0xb0(%r13), %rax
shlq $0x3, %rax
cqto
idivq 0x80(%r13)
movq %rax, 0x30(%r13)
movq 0xc0(%r13), %rcx
shlq $0x3, %rcx
movq %rcx, 0x38(%r13)
movq 0x70(%r13), %rsi
movq 0x78(%r13), %rcx
movq %rbx, %rdi
movq %rax, %rdx
pushq $0x4
popq %r8
callq 0xe746f
movq %rax, 0xf0(%r13)
movq 0xa0(%r13), %rdx
testq %rdx, %rdx
jle 0x72a64
cmpq $0x100, %rdx            # imm = 0x100
ja 0x72854
movq 0x18(%rbx), %rdi
movq 0x68(%r13), %rsi
addq %r14, %rsi
movq 0x98(%r13), %rcx
leaq 0x100(%r13), %r8
movl $0x1, (%rsp)
movl $0x100, %r9d            # imm = 0x100
callq 0xe7963
addq 0xd8(%r13), %r14
movq %r14, 0x20(%r13)
movq 0xb8(%r13), %rcx
addq %r14, %rcx
movq %rcx, 0x28(%r13)
movq %rbx, %rdi
leaq 0xa8a39(%rip), %rsi     # 0x11b4c0
movl %r14d, %edx
xorl %eax, %eax
callq 0xde896
movq 0x38(%r13), %rdx
movq 0x70(%r13), %rsi
movq 0x78(%r13), %rcx
movq %rbx, %rdi
movl %ebp, %r8d
callq 0xe746f
movq %rax, 0xf8(%r13)
movq 0x18(%rbx), %rdi
movq 0x28(%r13), %rsi
movq 0xc0(%r13), %rdx
movq %rax, %rcx
xorl %r8d, %r8d
callq 0xe77b7
movq 0x80(%r13), %rdx
cmpq $0x20, %rdx
jne 0x72be7
movq 0xf0(%r13), %rax
movq %rax, 0x30(%rsp)
xorl %r14d, %r14d
movq 0x30(%rsp), %rax
cmpq 0x10(%rax), %r14
jge 0x72cd2
movq 0xb0(%r13), %rax
imulq %r14, %rax
addq 0x20(%r13), %rax
movq %rax, 0x40(%rsp)
xorl %r12d, %r12d
cmpq 0x30(%r13), %r12
jge 0x72b9c
movq %r14, %r13
movq 0x20(%rsp), %r14
movq 0x18(%r14), %rdi
leaq 0x40(%rsp), %r15
movq %r15, %rsi
callq 0xe3f2a
movb %al, 0xf(%rsp)
movq 0x18(%r14), %rdi
movq %r15, %rsi
callq 0xe3f2a
movl %eax, %ebx
movq 0x18(%r14), %rdi
movq %r15, %rsi
callq 0xe3f2a
movl %eax, %ebp
movq 0x18(%r14), %rdi
movq %r13, %r14
movq %r15, %rsi
callq 0xe3f2a
movzbl %al, %eax
shll $0x18, %eax
movzbl %bpl, %ecx
shll $0x10, %ecx
orl %eax, %ecx
movzbl %bl, %eax
shll $0x8, %eax
orl %ecx, %eax
movzbl 0xf(%rsp), %ecx
movq 0x28(%rsp), %r13
orl %eax, %ecx
movq 0x30(%rsp), %rdi
movq %r12, %rsi
movq %r14, %rdx
callq 0xe728c
incq %r12
jmp 0x72b0f
incq %r14
movq 0x20(%rsp), %rbx
pushq $0x1
popq %rbp
movq 0x10(%rsp), %r12
jmp 0x72ae9
cmpq $0x10, %r9
jne 0x72bca
movl (%r13), %edx
movq %rbx, %rdi
leaq 0xa888b(%rip), %rsi     # 0x11b450
pushq $0x10
popq %rcx
jmp 0x72bdb
movl (%r13), %edx
movq %rbx, %rdi
leaq 0xa889f(%rip), %rsi     # 0x11b477
movl %r9d, %ecx
xorl %eax, %eax
callq 0xdf2a5
jmp 0x728ff
movq 0xf0(%r13), %r14
cmpq $0x18, %rdx
jne 0x72c13
movq 0x18(%rbx), %rdi
movq 0x20(%r13), %rsi
movq 0xb0(%r13), %rdx
pushq $0x3
popq %rcx
movq %r14, %r8
movl %ebp, %r9d
callq 0xe7f67
jmp 0x72c42
cmpq $0x8, %rdx
jg 0x72cd2
movq 0x18(%rbx), %rdi
movq 0x20(%r13), %rsi
movq 0xb0(%r13), %rcx
movq %r13, %r8
addq $0x100, %r8             # imm = 0x100
andl $0x0, (%rsp)
movq %r14, %r9
callq 0xe7cbc
xorl %r15d, %r15d
cmpq 0x10(%r14), %r15
jge 0x72cd2
xorl %r12d, %r12d
movl $0x808000ff, %ebx       # imm = 0x808000FF
cmpq 0x70(%r13), %r12
jge 0x72cc0
movq 0xf8(%r13), %rdi
movq %r12, %rsi
movq %r15, %rdx
callq 0xe735f
testl $0xff0000, %eax         # imm = 0xFF0000
je 0x72cbb
movq 0xf0(%r13), %rdi
movq %r12, %rsi
movq %r15, %rdx
callq 0xe735f
testl $0xffffff, %eax         # imm = 0xFFFFFF
je 0x72ca7
movl $0x1, 0x48(%r13)
leal (%r15,%r12), %eax
testb $0x1, %al
movl $0x80ff0080, %ecx       # imm = 0x80FF0080
cmovel %ebx, %ecx
jmp 0x72ca9
xorl %ecx, %ecx
movq 0xf0(%r13), %rdi
movq %r12, %rsi
movq %r15, %rdx
callq 0xe728c
incq %r12
jmp 0x72c57
incq %r15
movq 0x20(%rsp), %rbx
movq 0x10(%rsp), %r12
jmp 0x72c45
cmpl $0x0, 0x48(%r13)
je 0x72ce1
movq %rbx, %rdi
callq 0x730d2
movq 0xf0(%r13), %rdi
xorl %esi, %esi
cmpq $0x20, 0x80(%r13)
sete %sil
callq 0xe84da
movq %rbx, %rdi
callq 0xdfd1a
movq %rax, %r14
movq %rbx, %rdi
movq %rax, %rsi
leaq 0x60(%rsp), %rdx
xorl %ecx, %ecx
movl %ebp, %r8d
callq 0xdffbd
movq 0x18(%rsp), %rax
cmpl $0x0, (%rax)
je 0x72d35
movb $0x1, 0xe(%r14)
movq 0x18(%r13), %rax
movq %rax, 0x98(%r14)
movq 0xf0(%r13), %rdi
movq %r14, %rsi
pushq $0x4
popq %rdx
callq 0xe70ab
movq 0x18(%rsp), %rax
cmpl $0x0, 0x4(%rax)
je 0x72907
cmpl $0x0, 0x40(%r13)
je 0x72d7a
cmpb $0x0, 0xd6(%rbx)
je 0x72907
movq 0x70(%r13), %rcx
cmpq %rcx, 0x38(%r13)
jle 0x72907
jmp 0x72d7e
movq 0x70(%r13), %rcx
movl 0x78(%r13), %r8d
movl 0x80(%r13), %r9d
leaq 0x40(%rsp), %r15
movq %r15, %rdi
pushq $0x20
popq %rsi
leaq 0xa8742(%rip), %rdx     # 0x11b4dd
xorl %eax, %eax
callq 0xde40c
movq 0xf8(%r13), %rdi
movq %r15, %rsi
pushq $0x5
popq %rdx
callq 0xe70b7
jmp 0x72907
leaq 0xa8652(%rip), %rsi     # 0x11b412
movq %rbx, %rdi
xorl %eax, %eax
callq 0xde896
movq %rbx, %rdi
movq 0x18(%rsp), %rsi
callq 0xded32
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq