// File: /workspace/github_c_makefile_star2_O3/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 0xe8b2b
movq %rax, %r15
movl $0x1, (%rax)
movq $0x2, 0x18(%rax)
movl $0x4, %r14d
movq %r14, 0x20(%rax)
movq %rbx, %rdi
xorl %esi, %esi
movl $0x11, %edx
callq 0xeb220
movl %eax, 0x8(%r15)
movb $0x1, 0x14(%r15)
movl $0x18, %esi
movq %rbx, %rdi
callq 0xe8b2b
movq %rax, %r13
movq 0x18(%rbx), %rdi
movq 0x18(%rdi), %rax
movq $0x0, 0x8(%r13)
movq %rax, 0x10(%r13)
movq %r14, (%r13)
movq %r15, (%rsp)
movl 0x4(%r15), %edx
movl $0x4, %esi
callq 0xeeff3
movq %rax, %r12
addq %r14, (%r13)
leaq 0x8f543(%rip), %rsi     # 0x134b6f
movq %rbx, %rdi
movl %r12d, %edx
xorl %eax, %eax
callq 0xe8617
cmpq $0x2, %r12
je 0xa5653
leaq 0x8f6f8(%rip), %rsi     # 0x134d3e
movq %rbx, %rdi
movl %r12d, %edx
xorl %eax, %eax
callq 0xe8faa
movq 0x18(%rbx), %rdi
movq (%rsp), %rax
movl 0x4(%rax), %edx
movq (%r13), %rsi
callq 0xeeff3
movq %rax, %r14
addq $0x4, (%r13)
leaq 0x8f6f8(%rip), %rsi     # 0x134d6e
movq %rbx, %rdi
movl %r14d, %edx
xorl %eax, %eax
callq 0xe8617
movq %r14, 0x28(%rsp)
testq %r14, %r14
jle 0xa58bc
movq (%r13), %rcx
xorl %edx, %edx
movq %r13, 0x20(%rsp)
movq 0x10(%r13), %rax
cmpq %rax, %rcx
jge 0xa58bc
movq 0x8(%r13), %rsi
cmpq %rsi, %rcx
cmovgq %rcx, %rsi
subq %rsi, %rax
cmpq $0x1c, %rax
jl 0xa58bc
movq %rbx, %rdi
leaq 0x8f6b8(%rip), %rsi     # 0x134d83
movq %rdx, 0x30(%rsp)
xorl %eax, %eax
callq 0xe8617
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 0xe8a15
movq %rbx, %rdi
callq 0xf6410
movq %rax, %r13
movq %rbx, %rdi
movq (%rsp), %rsi
movq %rsi, %r14
movq %rax, %rdx
leaq 0x8(%rsp), %rcx
callq 0xa7614
movq %r13, %rdi
callq 0xf70f6
movq %rbx, %rdi
leaq 0x7d04c(%rip), %rsi     # 0x12277b
movq %rax, %rdx
xorl %eax, %eax
callq 0xe8617
movq 0x8(%rsp), %rdi
subq %r15, %rdi
callq 0xe9c87
movq %rax, %r12
leaq (%r15,%rax), %rbp
leaq (%r15,%rax), %rsi
addq $0x4, %rsi
movq 0x18(%rbx), %rdi
movl 0x4(%r14), %edx
callq 0xeeff3
movq %rax, %r14
addq %r12, %r15
addq $0x8, %r15
movq %rbx, %rdi
leaq 0x8f61d(%rip), %rsi     # 0x134d93
movl %r14d, %edx
xorl %eax, %eax
callq 0xe8617
movq 0x18(%rsp), %r12
testq %r14, %r14
movl $0x0, %eax
cmovgq %r14, %rax
addq %rbp, %rax
addq $0x8, %rax
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 0xf6423
movq %rbx, %rdi
movq (%rsp), %rbp
movq %rbp, %rsi
movq %r13, %rdx
leaq 0x38(%rsp), %r14
movq %r14, %rcx
callq 0xa5fe3
movq %r13, %rdi
callq 0xf705c
movq %rbx, %rdi
leaq 0x88442(%rip), %rsi     # 0x12dc31
movq %rax, %rdx
xorl %eax, %eax
callq 0xe8617
movq %rbx, %rdi
movq %rbp, %rsi
movq %r14, %rdx
leaq 0x6c991(%rip), %rcx     # 0x11219a
callq 0xa76cc
movq 0x38(%rsp), %r14
movq %rbx, %rdi
leaq 0x8f58c(%rip), %rsi     # 0x134da9
movl %r14d, %edx
xorl %eax, %eax
callq 0xe8617
movq 0x48(%rsp), %rax
movq %r14, 0x58(%rsp)
movq %r14, 0x50(%rsp)
movq %rax, 0x60(%rsp)
movq %rbx, %rdi
movl $0x1, %esi
callq 0xe8a15
movq %rbx, %rdi
movq %rbp, %rsi
leaq 0x50(%rsp), %rdx
callq 0xa8b72
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0xe8a15
movq %r13, %rdi
callq 0xf6753
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0xe8a15
movq 0x10(%rsp), %rax
movq %r12, %rdx
movl $0x0, %ecx
subq %rax, %rdx
jle 0xa589c
cmpq %r12, %r15
jle 0xa5896
movq %rdx, %rcx
jmp 0xa589c
subq %rax, %r15
movq %r15, %rcx
movq 0x20(%rsp), %r13
addq (%r13), %rcx
movq %rcx, (%r13)
movq 0x30(%rsp), %rdx
incq %rdx
cmpq %rdx, 0x28(%rsp)
jne 0xa569c
movq %rbx, %rdi
movq %r13, %rsi
callq 0xe8be2
movq %rbx, %rdi
movq (%rsp), %rsi
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xe8be2