// File: /workspace/github_c_makefile_star2_O1/jsummers[P]deark/modules/icns.c
// Function: de_run_icns
static void de_run_icns(deark *c, de_module_params *mparams)
{
	lctx *d = NULL;
	const char *s;

	d = de_malloc(c, sizeof(lctx));
	init_masktype_info(d);

	// (If these options are undocumented, it's because they're still in
	// development/testing.)
	// 81 = Use 8-bit mask if present, otherwise 1-bit mask
	// 18 = Use 1-bit mask if present, otherwise 8-bit mask
	// 8 = Use 8-bit mask only
	// 1 = Use 1-bit mask only
	// 0 = No transparency
	//
	// TODO: Maybe set opt_mask1 = 81
	d->opt_mask1 = 1; // Setting for (most) 1bpp icons
	d->opt_mask8 = 81; // Setting for 4 and 8bpp icons
	d->opt_mask24 = 81; // Setting for 24bpp icons
	s = de_get_ext_option(c, "icns:mask1");
	if(s) {
		d->opt_mask1 = (u8)de_atoi(s);
	}
	s = de_get_ext_option(c, "icns:mask8");
	if(s) {
		d->opt_mask8 = (u8)de_atoi(s);
	}
	s = de_get_ext_option(c, "icns:mask24");
	if(s) {
		d->opt_mask24 = (u8)de_atoi(s);
	}

	d->opt_getmasks = de_get_ext_option_bool(c, "icns:getmasks", 0);

	d->file_size = de_getu32be(4);
	de_dbg(c, "reported file size: %d", (int)d->file_size);
	if(d->file_size > c->infile->len) d->file_size = c->infile->len;

	de_dbg(c, "pass 1: reading masks");
	de_dbg_indent(c, 1);
	de_run_icns_pass(c, d, 1);
	de_dbg_indent(c, -1);

	if(d->opt_getmasks) {
		extract_masks(c, d);
		goto done;
	}

	de_dbg(c, "pass 2: decoding/extracting icons");
	de_dbg_indent(c, 1);
	de_run_icns_pass(c, d, 2);
	de_dbg_indent(c, -1);

done:
	if(d) {
		int i;

		for(i=0; i<NUM_MASKTYPES; i++) {
			if(d->mask[i].img) {
				if(!d->mask[i].used_flag && !d->opt_getmasks) {
					de_dbg(c, "[mask at %"I64_FMT" was not used]", d->mask[i].segment_pos);
				}
				de_bitmap_destroy(d->mask[i].img);
				d->mask[i].img = NULL;
			}
		}
		de_free(c, d);
	}
}

// Assembly:
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x20, %rsp
movq %rdi, %rbx
movl $0x518, %esi            # imm = 0x518
callq 0xe969b
movq %rax, %r14
addq $0x10, %rax
movl $0x8, %ecx
leaq 0xb3490(%rip), %rdx     # 0x126ef0
movb -0x7(%rcx,%rdx), %sil
movzbl -0x8(%rcx,%rdx), %edi
shll $0x5, %edi
movb %sil, 0x9(%rax,%rdi)
movq -0x4(%rcx,%rdx), %rsi
movq %rsi, 0xc(%rax,%rdi)
addq $0xc, %rcx
cmpq $0x68, %rcx
jne 0x73a60
movw $0x5101, 0x8(%r14)      # imm = 0x5101
movb $0x51, 0xa(%r14)
leaq 0xb38e3(%rip), %rsi     # 0x12737c
movq %rbx, %rdi
callq 0xea6cb
testq %rax, %rax
je 0x73ab2
movq %rax, %rdi
callq 0xea781
movb %al, 0x8(%r14)
leaq 0xb38ce(%rip), %rsi     # 0x127387
movq %rbx, %rdi
callq 0xea6cb
testq %rax, %rax
je 0x73ad2
movq %rax, %rdi
callq 0xea781
movb %al, 0x9(%r14)
leaq 0xb38b9(%rip), %rsi     # 0x127392
movq %rbx, %rdi
callq 0xea6cb
testq %rax, %rax
je 0x73af2
movq %rax, %rdi
callq 0xea781
movb %al, 0xa(%r14)
leaq 0xb38a5(%rip), %rsi     # 0x12739e
movq %rbx, %rdi
xorl %edx, %edx
callq 0xea727
movb %al, 0xb(%r14)
movq 0x18(%rbx), %rdi
movl $0x4, %esi
callq 0xef32a
movq %rax, (%r14)
leaq 0xac783(%rip), %rsi     # 0x1202a2
movq %rbx, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xe9226
movq 0x18(%rbx), %rax
movq 0x18(%rax), %rax
cmpq %rax, (%r14)
jle 0x73b3b
movq %rax, (%r14)
leaq 0xb386a(%rip), %rsi     # 0x1273ac
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9226
movq %rbx, %rdi
movl $0x1, %esi
callq 0xe9585
movq %rbx, %rdi
movq %r14, %rsi
movl $0x1, %edx
callq 0x73cf0
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0xe9585
cmpb $0x0, 0xb(%r14)
je 0x73be6
leaq 0xb3ac7(%rip), %rsi     # 0x12764b
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9226
leaq 0xb3ac7(%rip), %r15     # 0x12765c
movq %rsp, %r12
xorl %r13d, %r13d
cmpq $0x0, 0x28(%r14,%r13)
je 0x73bd7
movl 0x1c(%r14,%r13), %ecx
movl 0x20(%r14,%r13), %r8d
movzbl 0x19(%r14,%r13), %r9d
movl $0x20, %esi
movq %r12, %rdi
movq %r15, %rdx
xorl %eax, %eax
callq 0xe8d67
movq 0x28(%r14,%r13), %rdi
movq %r12, %rsi
movl $0x2, %edx
callq 0xf2923
addq $0x20, %r13
cmpq $0x100, %r13            # imm = 0x100
jne 0x73b9b
jmp 0x73c21
leaq 0xb37d5(%rip), %rsi     # 0x1273c2
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9226
movq %rbx, %rdi
movl $0x1, %esi
callq 0xe9585
movq %rbx, %rdi
movq %r14, %rsi
movl $0x2, %edx
callq 0x73cf0
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0xe9585
movl $0x28, %r12d
leaq 0xb37b6(%rip), %r15     # 0x1273e4
cmpq $0x0, (%r14,%r12)
je 0x73c67
cmpb $0x0, -0x10(%r14,%r12)
jne 0x73c56
cmpb $0x0, 0xb(%r14)
jne 0x73c56
movq -0x18(%r14,%r12), %rdx
movq %rbx, %rdi
movq %r15, %rsi
xorl %eax, %eax
callq 0xe9226
movq (%r14,%r12), %rdi
callq 0xf28d4
movq $0x0, (%r14,%r12)
addq $0x20, %r12
cmpq $0x128, %r12            # imm = 0x128
jne 0x73c2e
movq %rbx, %rdi
movq %r14, %rsi
callq 0xe9752
addq $0x20, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq