// File: /workspace/github_c_makefile_star2_O2/jsummers[P]deark/modules/psd.c
// Function: de_run_ps_csh
static void de_run_ps_csh(deark *c, de_module_params *mparams)
{
	lctx *d = NULL;
	zztype *zz = NULL;
	i64 csh_ver;
	i64 num_shapes;
	i64 i;
	zztype czz;

	d = de_malloc(c, sizeof(lctx));
	d->version = 1;
	init_version_specific_info(c, d);

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

	zz->pos += 4; // Skip over 'cush' signature

	csh_ver = psd_getu32zz(zz);
	de_dbg(c, "file version: %d", (int)csh_ver);

	if(csh_ver!=2) {
		de_warn(c, "CSH v%d format might not be supported correctly", (int)csh_ver);
	}

	num_shapes = psd_getu32zz(zz);
	de_dbg(c, "number of shapes: %d", (int)num_shapes);

	for(i=0; i<num_shapes; i++) {
		if(zz_avail(zz)<28) break;
		de_dbg(c, "shape[%d] at %d", (int)i, (int)zz->pos);
		zz_init(&czz, zz);
		de_dbg_indent(c, 1);
		do_custom_shape(c, d, &czz);
		de_dbg_indent(c, -1);
		zz->pos += zz_used(&czz);
	}

	de_free(c, zz);
	de_free(c, d);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movq %rdi, %rbx
pushq $0x58
popq %rsi
callq 0xdecaf
movq %rax, %r14
movl $0x1, (%rax)
movq %rbx, %rdi
movq %rax, %rsi
callq 0x9f9fe
pushq $0x18
popq %rsi
movq %rbx, %rdi
callq 0xdecaf
movq %rax, %r15
movq 0x18(%rbx), %rdi
movq 0x18(%rdi), %rax
andq $0x0, 0x8(%r15)
movq %rax, 0x10(%r15)
movq $0x4, (%r15)
movq %r14, (%rsp)
movl 0x4(%r14), %edx
movq %r15, %rsi
callq 0x9fe70
movq %rax, %r12
leaq 0x8836c(%rip), %rsi     # 0x127897
movq %rbx, %rdi
movl %r12d, %edx
xorl %eax, %eax
callq 0xde896
cmpq $0x2, %r12
je 0x9f552
leaq 0x88521(%rip), %rsi     # 0x127a66
movq %rbx, %rdi
movl %r12d, %edx
xorl %eax, %eax
callq 0xdf05a
movq 0x18(%rbx), %rdi
movq (%rsp), %rax
movl 0x4(%rax), %edx
movq %r15, %rsi
callq 0x9fe70
movq %rax, %r12
leaq 0x88527(%rip), %rsi     # 0x127a96
xorl %r14d, %r14d
movq %rbx, %rdi
movl %r12d, %edx
xorl %eax, %eax
callq 0xde896
testq %r12, %r12
cmovleq %r14, %r12
movq %r12, 0x28(%rsp)
xorl %r14d, %r14d
movq %r15, 0x20(%rsp)
cmpq %r14, 0x28(%rsp)
je 0x9f791
movq %r15, %rdi
callq 0x9ff2f
cmpq $0x1c, %rax
jl 0x9f791
movl (%r15), %ecx
movq %rbx, %rdi
leaq 0x884ee(%rip), %rsi     # 0x127aab
movq %r14, 0x30(%rsp)
movl %r14d, %edx
xorl %eax, %eax
callq 0xde896
movq (%r15), %r14
movq 0x10(%r15), %rax
movq %r14, 0x10(%rsp)
movq %r14, 0x8(%rsp)
movq %rax, 0x18(%rsp)
movq %rbx, %rdi
pushq $0x1
popq %rsi
callq 0xdeba7
movq %rbx, %rdi
callq 0xeac74
movq %rax, %r13
movq %rbx, %rdi
movq (%rsp), %rbp
movq %rbp, %rsi
movq %rax, %rdx
leaq 0x8(%rsp), %r15
movq %r15, %rcx
callq 0xa1369
movq %r13, %rdi
callq 0xeb877
movq %rbx, %rdi
leaq 0x75f97(%rip), %rsi     # 0x1155bb
movq %rax, %rdx
xorl %eax, %eax
callq 0xde896
movq 0x8(%rsp), %rdi
subq %r14, %rdi
callq 0xdfb90
addq %r14, %rax
addq $0x4, %rax
movq %rax, 0x8(%rsp)
movq 0x18(%rbx), %rdi
movl 0x4(%rbp), %edx
movq %r15, %rsi
callq 0x9fe70
movq %rax, %r12
movq %rbx, %rdi
leaq 0x88458(%rip), %rsi     # 0x127abb
movl %r12d, %edx
xorl %eax, %eax
callq 0xde896
testq %r12, %r12
movl $0x0, %eax
cmovgq %r12, %rax
movq 0x8(%rsp), %r14
movq 0x18(%rsp), %r15
addq %r14, %rax
cmpq %r15, %rax
cmovgeq %r15, %rax
movq %r14, 0x40(%rsp)
movq %r14, 0x38(%rsp)
movq %rax, 0x48(%rsp)
addq %r12, %r14
movq %r14, 0x8(%rsp)
movq %r13, %rdi
callq 0xeac85
movq %rbx, %rdi
movq %rbp, %rsi
movq %r13, %rdx
leaq 0x38(%rsp), %r12
movq %r12, %rcx
callq 0x9fec2
movq %r13, %rdi
callq 0xeb7e4
movq %rbx, %rdi
leaq 0x812ed(%rip), %rsi     # 0x1209c1
movq %rax, %rdx
xorl %eax, %eax
callq 0xde896
movq %rbx, %rdi
movq %rbp, %rsi
movq %r12, %rdx
leaq 0x65a8c(%rip), %rcx     # 0x10517a
callq 0xa1409
movq 0x38(%rsp), %r12
movq %rbx, %rdi
leaq 0x883cf(%rip), %rsi     # 0x127ad1
movl %r12d, %edx
xorl %eax, %eax
callq 0xde896
movq 0x48(%rsp), %rax
movq %r12, 0x58(%rsp)
movq %r12, 0x50(%rsp)
movq %rax, 0x60(%rsp)
movq %rbx, %rdi
pushq $0x1
popq %rsi
callq 0xdeba7
movq %rbx, %rdi
movq %rbp, %rsi
leaq 0x50(%rsp), %rdx
callq 0xa2645
movq %rbx, %rdi
pushq $-0x1
popq %rbp
movl %ebp, %esi
callq 0xdeba7
movq %r13, %rdi
callq 0xeaf3c
movq %rbx, %rdi
movl %ebp, %esi
callq 0xdeba7
movq 0x10(%rsp), %rax
movq %r15, %rcx
movl $0x0, %edx
subq %rax, %rcx
jle 0x9f77c
cmpq %r15, %r14
jle 0x9f776
movq %rcx, %rdx
jmp 0x9f77c
subq %rax, %r14
movq %r14, %rdx
movq 0x20(%rsp), %r15
addq %rdx, (%r15)
movq 0x30(%rsp), %r14
incq %r14
jmp 0x9f593
movq %rbx, %rdi
movq %r15, %rsi
callq 0xded32
movq %rbx, %rdi
movq (%rsp), %rsi
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xded32