// File: /workspace/github_c_makefile_star2_O1/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
movl $0x58, %esi
callq 0xe969b
movq %rax, %r14
movl $0x1, (%rax)
movq %rbx, %rdi
movq %rax, %rsi
callq 0xa64c0
movl $0x18, %esi
movq %rbx, %rdi
callq 0xe969b
movq %rax, %r13
movq 0x18(%rbx), %rdi
movq 0x18(%rdi), %rax
xorps %xmm0, %xmm0
movups %xmm0, (%r13)
movq %rax, 0x10(%r13)
movq $0x4, (%r13)
movq %r14, (%rsp)
movl 0x4(%r14), %edx
movl $0x4, %esi
callq 0xef614
movq %rax, %r12
addq $0x4, (%r13)
leaq 0x8e7f1(%rip), %rsi     # 0x134777
movq %rbx, %rdi
movl %r12d, %edx
xorl %eax, %eax
callq 0xe9226
cmpq $0x2, %r12
je 0xa5fad
leaq 0x8e9a6(%rip), %rsi     # 0x134946
movq %rbx, %rdi
movl %r12d, %edx
xorl %eax, %eax
callq 0xe9b27
movq 0x18(%rbx), %rdi
movq (%rsp), %rax
movl 0x4(%rax), %edx
movq (%r13), %rsi
callq 0xef614
movq %rax, %r14
addq $0x4, (%r13)
leaq 0x8e9a6(%rip), %rsi     # 0x134976
movq %rbx, %rdi
movl %r14d, %edx
xorl %eax, %eax
callq 0xe9226
movq %r14, 0x28(%rsp)
testq %r14, %r14
jle 0xa6220
xorl %edx, %edx
movq %r13, 0x20(%rsp)
movq (%r13), %rcx
movq 0x10(%r13), %rdi
movq %rdi, %rax
subq %rcx, %rax
jle 0xa6013
movq 0x8(%r13), %rsi
cmpq %rsi, %rcx
jge 0xa6015
subq %rsi, %rdi
movq %rdi, %rax
jmp 0xa6015
xorl %eax, %eax
cmpq $0x1c, %rax
jl 0xa6220
movq %rbx, %rdi
leaq 0x8e962(%rip), %rsi     # 0x13498b
movq %rdx, 0x30(%rsp)
xorl %eax, %eax
callq 0xe9226
movq (%r13), %r15
movq 0x10(%r13), %rax
movq %r15, 0x10(%rsp)
movq %r15, 0x8(%rsp)
movq %rax, 0x18(%rsp)
movq %rbx, %rdi
movl $0x1, %esi
callq 0xe9585
movq %rbx, %rdi
callq 0xf6870
movq %rax, %r13
movq %rbx, %rdi
movq (%rsp), %rsi
movq %rsi, %r14
movq %rax, %rdx
leaq 0x8(%rsp), %rcx
callq 0xa803f
movq %r13, %rdi
callq 0xf7557
movq %rbx, %rdi
leaq 0x7c4e6(%rip), %rsi     # 0x122573
movq %rax, %rdx
xorl %eax, %eax
callq 0xe9226
movq 0x8(%rsp), %rdi
subq %r15, %rdi
callq 0xea7de
movq %rax, %r12
leaq (%r15,%rax), %rbp
leaq (%r15,%rax), %rsi
addq $0x4, %rsi
movq %rsi, 0x8(%rsp)
movq 0x18(%rbx), %rdi
movl 0x4(%r14), %edx
callq 0xef614
movq %rax, %r14
addq %r12, %r15
addq $0x8, %r15
movq %r15, 0x8(%rsp)
movq %rbx, %rdi
leaq 0x8e8bd(%rip), %rsi     # 0x13499b
movl %r14d, %edx
xorl %eax, %eax
callq 0xe9226
testq %r14, %r14
movl $0x0, %eax
cmovgq %r14, %rax
addq %rbp, %rax
addq $0x8, %rax
movq 0x18(%rsp), %r12
cmpq %r12, %rax
cmovgeq %r12, %rax
movq %r15, 0x40(%rsp)
movq %r15, 0x38(%rsp)
movq %rax, 0x48(%rsp)
leaq (%r14,%rbp), %r15
addq $0x8, %r15
movq %r15, 0x8(%rsp)
movq %r13, %rdi
callq 0xf6883
movq %rbx, %rdi
movq (%rsp), %rbp
movq %rbp, %rsi
movq %r13, %rdx
leaq 0x38(%rsp), %r14
movq %r14, %rcx
callq 0xa696e
movq %r13, %rdi
callq 0xf74bd
movq %rbx, %rdi
leaq 0x877e2(%rip), %rsi     # 0x12d939
movq %rax, %rdx
xorl %eax, %eax
callq 0xe9226
movq %rbx, %rdi
movq %rbp, %rsi
movq %r14, %rdx
leaq 0x6c019(%rip), %rcx     # 0x11218a
callq 0xa80fd
movq 0x38(%rsp), %r14
movq %rbx, %rdi
leaq 0x8e82c(%rip), %rsi     # 0x1349b1
movl %r14d, %edx
xorl %eax, %eax
callq 0xe9226
movq 0x48(%rsp), %rax
movq %r14, 0x58(%rsp)
movq %r14, 0x50(%rsp)
movq %rax, 0x60(%rsp)
movq %rbx, %rdi
movl $0x1, %esi
callq 0xe9585
movq %rbx, %rdi
movq %rbp, %rsi
leaq 0x50(%rsp), %rdx
callq 0xa949c
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0xe9585
movq %r13, %rdi
callq 0xf6bb0
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0xe9585
movq 0x10(%rsp), %rax
movq %r12, %rcx
movl $0x0, %edx
subq %rax, %rcx
jle 0xa6204
cmpq %r12, %r15
jle 0xa61fe
movq %rcx, %rdx
jmp 0xa6204
subq %rax, %r15
movq %r15, %rdx
movq 0x20(%rsp), %r13
addq %rdx, (%r13)
movq 0x30(%rsp), %rdx
incq %rdx
cmpq %rdx, 0x28(%rsp)
jne 0xa5ff2
movq %rbx, %rdi
movq %r13, %rsi
callq 0xe9752
movq %rbx, %rdi
movq (%rsp), %rsi
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xe9752