// File: /workspace/github_c_makefile_star2_O3/jsummers[P]deark/modules/psd.c
// Function: do_pattern_internal
static int do_pattern_internal(deark *c, lctx *d, zztype *zz)
{
	i64 pat_color_mode;
	i64 ver;
	i64 w, h;
	de_ucstring *s = NULL;
	zztype vmalzz; // for virtual memory array list
	int retval = 0;

	ver = psd_getu32zz(zz);
	de_dbg(c, "version: %d", (int)ver);
	if(ver!=1) goto done;

	pat_color_mode = psd_getu32zz(zz);
	de_dbg(c, "color mode: %d (%s)", (int)pat_color_mode, get_colormode_name(pat_color_mode));

	h = psd_getu16zz(zz);
	w = psd_getu16zz(zz);
	de_dbg_dimensions(c, w, h);

	s = ucstring_create(c);
	read_unicode_string(c, d, s, zz);
	de_dbg(c, "name: \"%s\"", ucstring_getpsz_d(s));

	ucstring_empty(s);
	read_pascal_string_to_ucstring(c, d, s, zz);
	de_dbg(c, "id: \"%s\"", ucstring_getpsz_d(s));

	if(pat_color_mode==PSD_CM_PALETTE) {
		de_dbg(c, "palette at %d", (int)zz->pos);
		zz->pos += 3*256;
	}

	zz_init(&vmalzz, zz);
	do_vm_array_list(c, d, &vmalzz);
	zz->pos += zz_used(&vmalzz);
	retval = 1;
done:
	ucstring_destroy(s);
	return retval;
}

// Assembly:
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x20, %rsp
movq %rdx, %rbx
movq %rsi, %r14
movq %rdi, %r15
movq 0x18(%rdi), %rdi
movl 0x4(%rsi), %edx
movq (%rbx), %rsi
callq 0xeeff3
movq %rax, %r12
addq $0x4, (%rbx)
leaq 0x89506(%rip), %rsi     # 0x1347c9
xorl %r13d, %r13d
movq %r15, %rdi
movl %r12d, %edx
xorl %eax, %eax
callq 0xe8617
cmpq $0x1, %r12
jne 0xab303
movq 0x18(%r15), %rdi
movl 0x4(%r14), %edx
movq (%rbx), %rsi
callq 0xeeff3
movq %rax, %r13
addq $0x4, (%rbx)
cmpq $0x9, %rax
ja 0xab30b
leaq 0xdab53(%rip), %rax     # 0x185e50
movq (%rax,%r13,8), %rcx
jmp 0xab312
xorl %r12d, %r12d
jmp 0xab444
leaq 0x80e3f(%rip), %rcx     # 0x12c151
leaq 0x89084(%rip), %rsi     # 0x13439d
movq %r15, %rdi
movl %r13d, %edx
xorl %eax, %eax
callq 0xe8617
movq 0x18(%r15), %rdi
movl 0x4(%r14), %edx
movq (%rbx), %rsi
callq 0xeef43
movq %rax, %r12
movq (%rbx), %rsi
addq $0x2, %rsi
movq %rsi, (%rbx)
movq 0x18(%r15), %rdi
movl 0x4(%r14), %edx
callq 0xeef43
addq $0x2, (%rbx)
movq %r15, %rdi
movq %rax, %rsi
movq %r12, %rdx
callq 0xe8f88
movq %r15, %rdi
callq 0xf6410
movq %rax, %r12
movq %r15, %rdi
movq %r14, %rsi
movq %rax, %rdx
movq %rbx, %rcx
callq 0xa7614
movq %r12, %rdi
callq 0xf70f6
leaq 0x773ee(%rip), %rsi     # 0x12277b
movq %r15, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xe8617
movq %r12, %rdi
callq 0xf6423
movq %r15, %rdi
movq %r14, %rsi
movq %r12, %rdx
movq %rbx, %rcx
callq 0xa5fe3
movq %r12, %rdi
callq 0xf70f6
leaq 0x8286f(%rip), %rsi     # 0x12dc31
movq %r15, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xe8617
movq (%rbx), %rdx
cmpq $0x2, %r13
jne 0xab3f4
leaq 0x8508a(%rip), %rsi     # 0x130469
movq %r15, %rdi
xorl %eax, %eax
callq 0xe8617
movl $0x300, %edx            # imm = 0x300
addq (%rbx), %rdx
movq %rdx, (%rbx)
movq 0x10(%rbx), %rax
leaq 0x8(%rsp), %r13
movq %rdx, 0x8(%r13)
movq %rdx, (%r13)
movq %rax, 0x10(%r13)
movq %r15, %rdi
movq %r14, %rsi
movq %r13, %rdx
callq 0xab45d
movq 0x8(%r13), %rcx
movq 0x10(%r13), %rsi
movq %rsi, %rax
subq %rcx, %rax
jle 0xab439
movq 0x8(%rsp), %rdx
cmpq %rsi, %rdx
jg 0xab43b
subq %rcx, %rdx
movq %rdx, %rax
jmp 0xab43b
xorl %eax, %eax
addq %rax, (%rbx)
movl $0x1, %r13d
movq %r12, %rdi
callq 0xf6753
movl %r13d, %eax
addq $0x20, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq