// File: /workspace/github_c_makefile_star2_O0/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 %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq $0x0, -0x18(%rbp)
movq -0x8(%rbp), %rdi
movl $0x518, %esi            # imm = 0x518
callq 0x15b780
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rdi
callq 0xa74c0
movq -0x18(%rbp), %rax
movb $0x1, 0x8(%rax)
movq -0x18(%rbp), %rax
movb $0x51, 0x9(%rax)
movq -0x18(%rbp), %rax
movb $0x51, 0xa(%rax)
movq -0x8(%rbp), %rdi
leaq 0x10b799(%rip), %rsi    # 0x1b292f
callq 0x15cb30
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
je 0xa71b8
movq -0x20(%rbp), %rdi
callq 0x15cca0
movb %al, %cl
movq -0x18(%rbp), %rax
movb %cl, 0x8(%rax)
movq -0x8(%rbp), %rdi
leaq 0x10b777(%rip), %rsi    # 0x1b293a
callq 0x15cb30
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
je 0xa71e5
movq -0x20(%rbp), %rdi
callq 0x15cca0
movb %al, %cl
movq -0x18(%rbp), %rax
movb %cl, 0x9(%rax)
movq -0x8(%rbp), %rdi
leaq 0x10b755(%rip), %rsi    # 0x1b2945
callq 0x15cb30
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
je 0xa7212
movq -0x20(%rbp), %rdi
callq 0x15cca0
movb %al, %cl
movq -0x18(%rbp), %rax
movb %cl, 0xa(%rax)
movq -0x8(%rbp), %rdi
leaq 0x10b734(%rip), %rsi    # 0x1b2951
xorl %edx, %edx
callq 0x15cbc0
movb %al, %cl
movq -0x18(%rbp), %rax
movb %cl, 0xb(%rax)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movl $0x4, %esi
callq 0x165470
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, (%rax)
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movq (%rax), %rax
movl %eax, %edx
leaq 0x104c8f(%rip), %rsi    # 0x1abeec
movb $0x0, %al
callq 0x15b0d0
movq -0x18(%rbp), %rax
movq (%rax), %rax
movq -0x8(%rbp), %rcx
movq 0x18(%rcx), %rcx
cmpq 0x18(%rcx), %rax
jle 0xa728c
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x18(%rax), %rcx
movq -0x18(%rbp), %rax
movq %rcx, (%rax)
movq -0x8(%rbp), %rdi
leaq 0x10b6c8(%rip), %rsi    # 0x1b295f
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movl $0x1, %esi
callq 0x15b560
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
movl $0x1, %edx
callq 0xa7590
movq -0x8(%rbp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x15b560
movq -0x18(%rbp), %rax
cmpb $0x0, 0xb(%rax)
je 0xa72e5
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0xa7a50
jmp 0xa7325
movq -0x8(%rbp), %rdi
leaq 0x10b685(%rip), %rsi    # 0x1b2975
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movl $0x1, %esi
callq 0x15b560
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
movl $0x2, %edx
callq 0xa7590
movq -0x8(%rbp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x15b560
cmpq $0x0, -0x18(%rbp)
je 0xa73fe
movl $0x0, -0x24(%rbp)
cmpl $0x8, -0x24(%rbp)
jge 0xa73f1
movq -0x18(%rbp), %rax
addq $0x10, %rax
movslq -0x24(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
cmpq $0x0, 0x18(%rax)
je 0xa73e1
movq -0x18(%rbp), %rax
addq $0x10, %rax
movslq -0x24(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
cmpb $0x0, 0x8(%rax)
jne 0xa73aa
movq -0x18(%rbp), %rax
cmpb $0x0, 0xb(%rax)
jne 0xa73aa
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
addq $0x10, %rax
movslq -0x24(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq (%rax), %rdx
leaq 0x10b5f4(%rip), %rsi    # 0x1b2997
movb $0x0, %al
callq 0x15b0d0
movq -0x18(%rbp), %rax
addq $0x10, %rax
movslq -0x24(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq 0x18(%rax), %rdi
callq 0x16af60
movq -0x18(%rbp), %rax
addq $0x10, %rax
movslq -0x24(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq $0x0, 0x18(%rax)
jmp 0xa73e3
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0xa7337
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x15b820
addq $0x30, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)