// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/psd.c
// Function: de_run_psd
static void de_run_psd(deark *c, de_module_params *mparams)
{
	lctx *d = NULL;
	i64 x;
	zztype *zz = NULL;
	zztype czz;
	int whattodo = 0;

	d = de_malloc(c, sizeof(lctx));
	zz = de_malloc(c, sizeof(zztype));
	zz_init_absolute(zz, 0, c->infile->len);

	if(de_havemodcode(c, mparams, 'R')) {
		whattodo = 'R';
	}
	else if(de_havemodcode(c, mparams, 'T')) {
		whattodo = 'T';
	}
	else if(de_havemodcode(c, mparams, 'B')) {
		whattodo = 'B';
	}
	else if(!dbuf_memcmp(c->infile, 0, "8BIM", 4)) {
		// Assume this is a raw resources file (maybe extracted from an
		// .8bimtiff file)
		whattodo = 'R';
	}

	if(whattodo=='R') { // Image resources
		de_declare_fmt(c, "Photoshop resources");
		d->version = 1;
		init_version_specific_info(c, d);
		do_image_resource_blocks(c, d, zz);
		if(mparams) {
			// .out_params.flags: 0x02: has_iptc
			mparams->out_params.flags = 0;
			if(d->has_iptc) mparams->out_params.flags |= 0x02;
		}
		goto done;
	}
	else if(whattodo=='T') { // Tagged blocks
		d->version = 1;
		init_version_specific_info(c, d);
		do_external_tagged_blocks(c, d, zz);
		goto done;
	}
	else if(whattodo=='B') { // Tagged blocks, PSB-format
		d->version = 2;
		init_version_specific_info(c, d);
		do_external_tagged_blocks(c, d, zz);
		goto done;
	}

	d->main_iinfo = de_malloc(c, sizeof(struct image_info));

	if(!do_psd_header(c, d, zz->pos)) goto done;
	zz->pos += 26;

	de_dbg(c, "color mode data section at %d", (int)zz->pos);
	de_dbg_indent(c, 1);
	x = psd_getu32zz(zz);
	zz_init_with_len(&czz, zz, x);
	do_psd_color_mode_data(c, d, &czz);
	zz->pos += x;
	de_dbg_indent(c, -1);

	de_dbg(c, "image resources section at %d", (int)zz->pos);
	de_dbg_indent(c, 1);
	x = psd_getu32zz(zz); // Length of Image Resources
	// The PSD spec is ambiguous, but in practice the "length" field's value
	// does not include the size of the "length" field itself.
	de_dbg(c, "image resources data at %d, len=%d", (int)zz->pos, (int)x);

	if(x>0) {
		if(de_get_ext_option_bool(c, "extract8bim", 0)) {
			fmtutil_handle_photoshop_rsrc(c, c->infile, zz->pos, x, 0x1);
		}
		else {
			de_dbg_indent(c, 1);
			zz_init_with_len(&czz, zz, x);
			do_image_resource_blocks(c, d, &czz);
			de_dbg_indent(c, -1);
		}
	}
	zz->pos += x;
	de_dbg_indent(c, -1);

	zz_init(&czz, zz);
	if(!do_layer_and_mask_info_section(c, d, &czz)) goto done;
	zz->pos += zz_used(&czz);

	zz_init(&czz, zz);
	do_image_data(c, d, &czz);

done:
	de_free(c, zz);
	if(d) {
		de_free(c, d->main_iinfo);
		de_free(c, d);
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq $0x0, -0x18(%rbp)
movq $0x0, -0x28(%rbp)
movl $0x0, -0x44(%rbp)
movq -0x8(%rbp), %rdi
movl $0x58, %esi
callq 0x15b780
movq %rax, -0x18(%rbp)
movq -0x8(%rbp), %rdi
movl $0x18, %esi
callq 0x15b780
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x18(%rax), %rdx
xorl %eax, %eax
movl %eax, %esi
callq 0xf2f00
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movl $0x52, %edx
callq 0x15d1d0
cmpl $0x0, %eax
je 0xf1d84
movl $0x52, -0x44(%rbp)
jmp 0xf1df3
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movl $0x54, %edx
callq 0x15d1d0
cmpl $0x0, %eax
je 0xf1da4
movl $0x54, -0x44(%rbp)
jmp 0xf1df1
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movl $0x42, %edx
callq 0x15d1d0
cmpl $0x0, %eax
je 0xf1dc4
movl $0x42, -0x44(%rbp)
jmp 0xf1def
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
xorl %eax, %eax
movl %eax, %esi
leaq 0xe417e(%rip), %rdx     # 0x1d5f55
movl $0x4, %ecx
callq 0x166ab0
cmpl $0x0, %eax
jne 0xf1ded
movl $0x52, -0x44(%rbp)
jmp 0xf1def
jmp 0xf1df1
jmp 0xf1df3
cmpl $0x52, -0x44(%rbp)
jne 0xf1e61
movq -0x8(%rbp), %rdi
leaq 0xc4b27(%rip), %rsi     # 0x1b692b
callq 0x15e380
movq -0x18(%rbp), %rax
movl $0x1, (%rax)
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0xf2f40
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x28(%rbp), %rdx
callq 0xf2fc0
cmpq $0x0, -0x10(%rbp)
je 0xf1e5c
movq -0x10(%rbp), %rax
movl $0x0, 0x40(%rax)
movq -0x18(%rbp), %rax
cmpb $0x0, 0x30(%rax)
je 0xf1e5a
movq -0x10(%rbp), %rax
movl 0x40(%rax), %ecx
orl $0x2, %ecx
movl %ecx, 0x40(%rax)
jmp 0xf1e5c
jmp 0xf20f0
cmpl $0x54, -0x44(%rbp)
jne 0xf1e94
movq -0x18(%rbp), %rax
movl $0x1, (%rax)
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0xf2f40
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x28(%rbp), %rdx
callq 0xf3030
jmp 0xf20f0
cmpl $0x42, -0x44(%rbp)
jne 0xf1ec7
movq -0x18(%rbp), %rax
movl $0x2, (%rax)
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0xf2f40
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x28(%rbp), %rdx
callq 0xf3030
jmp 0xf20f0
jmp 0xf1ec9
jmp 0xf1ecb
movq -0x8(%rbp), %rdi
movl $0x448, %esi            # imm = 0x448
callq 0x15b780
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x50(%rax)
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x28(%rbp), %rax
movq (%rax), %rdx
callq 0xf30b0
cmpl $0x0, %eax
jne 0xf1f02
jmp 0xf20f0
movq -0x28(%rbp), %rax
movq (%rax), %rcx
addq $0x1a, %rcx
movq %rcx, (%rax)
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rax
movq (%rax), %rax
movl %eax, %edx
leaq 0xcc9f6(%rip), %rsi     # 0x1be91a
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movl $0x1, %esi
callq 0x15b560
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x28(%rbp), %rsi
movq -0x18(%rbp), %rax
movl 0x4(%rax), %edx
callq 0xf3330
movq %rax, -0x20(%rbp)
movq -0x28(%rbp), %rsi
movq -0x20(%rbp), %rdx
leaq -0x40(%rbp), %rdi
callq 0xf3380
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
leaq -0x40(%rbp), %rdx
callq 0xf33f0
movq -0x20(%rbp), %rcx
movq -0x28(%rbp), %rax
addq (%rax), %rcx
movq %rcx, (%rax)
movq -0x8(%rbp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x15b560
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rax
movq (%rax), %rax
movl %eax, %edx
leaq 0xcc991(%rip), %rsi     # 0x1be938
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movl $0x1, %esi
callq 0x15b560
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x28(%rbp), %rsi
movq -0x18(%rbp), %rax
movl 0x4(%rax), %edx
callq 0xf3330
movq %rax, -0x20(%rbp)
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rax
movq (%rax), %rax
movl %eax, %edx
movq -0x20(%rbp), %rax
movl %eax, %ecx
leaq 0xcc964(%rip), %rsi     # 0x1be956
movb $0x0, %al
callq 0x15b0d0
cmpq $0x0, -0x20(%rbp)
jle 0xf207b
movq -0x8(%rbp), %rdi
leaq 0xcc96e(%rip), %rsi     # 0x1be979
xorl %edx, %edx
callq 0x15cbc0
cmpl $0x0, %eax
je 0xf203b
movq -0x8(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rsi
movq -0x28(%rbp), %rax
movq (%rax), %rdx
movq -0x20(%rbp), %rcx
movl $0x1, %r8d
callq 0x173bd0
jmp 0xf2079
movq -0x8(%rbp), %rdi
movl $0x1, %esi
callq 0x15b560
movq -0x28(%rbp), %rsi
movq -0x20(%rbp), %rdx
leaq -0x40(%rbp), %rdi
callq 0xf3380
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
leaq -0x40(%rbp), %rdx
callq 0xf2fc0
movq -0x8(%rbp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x15b560
jmp 0xf207b
movq -0x20(%rbp), %rcx
movq -0x28(%rbp), %rax
addq (%rax), %rcx
movq %rcx, (%rax)
movq -0x8(%rbp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x15b560
movq -0x28(%rbp), %rsi
leaq -0x40(%rbp), %rdi
callq 0xf3580
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
leaq -0x40(%rbp), %rdx
callq 0xf35b0
cmpl $0x0, %eax
jne 0xf20bc
jmp 0xf20f0
leaq -0x40(%rbp), %rdi
callq 0xf3820
movq %rax, %rcx
movq -0x28(%rbp), %rax
addq (%rax), %rcx
movq %rcx, (%rax)
movq -0x28(%rbp), %rsi
leaq -0x40(%rbp), %rdi
callq 0xf3580
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
leaq -0x40(%rbp), %rdx
callq 0xf3890
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rsi
callq 0x15b820
cmpq $0x0, -0x18(%rbp)
je 0xf2122
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x50(%rax), %rsi
callq 0x15b820
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x15b820
addq $0x50, %rsp
popq %rbp
retq
nopl (%rax,%rax)