// File: /workspace/github_c_makefile_star2_O2/jsummers[P]deark/modules/portfolio.c
// Function: de_run_pgx
static void de_run_pgx(deark *c, de_module_params *mparams)
{
	lctx *d = NULL;
	i64 pos;
	i64 frame_size;
	int ret;
	int executable = 0;

	if(dbuf_memcmp(c->infile, 0, "PGX", 3)) {
		// Some "PGX" files are actually .COM files with an embedded PGX file.
		// The ones I've seen always have the PGX file at offset 1248, so look
		// for it there.
		if(dbuf_memcmp(c->infile, 0, "PGX", 1248)) {
			executable = 1;
		}
	}

	if(executable) {
		de_declare_fmt(c, "PGX (Portfolio Animation, executable)");
		pos = 1248;
	}
	else{
		de_declare_fmt(c, "PGX (Portfolio Animation)");
		pos = 0;
	}

	d = de_malloc(c, sizeof(lctx));

	d->version = de_getbyte(pos+3);
	de_dbg(c, "Version: %d", (int)d->version);

	pos += 8;
	while(1) {
		if(pos >= c->infile->len) break;
		ret = do_process_frame(c, d, pos, &frame_size);
		if(!ret || !frame_size) break;
		pos += frame_size;
	}

	de_free(c, d);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %rbx
movq 0x18(%rdi), %rdi
leaq 0x7a25f(%rip), %rdx     # 0x12ac54
pushq $0x3
popq %rcx
xorl %esi, %esi
callq 0xe4d48
testl %eax, %eax
je 0xb0a2d
movq 0x18(%rbx), %rdi
leaq 0x7a246(%rip), %rdx     # 0x12ac54
movl $0x4e0, %r14d           # imm = 0x4E0
movl $0x4e0, %ecx            # imm = 0x4E0
xorl %esi, %esi
callq 0xe4d48
testl %eax, %eax
je 0xb0a2d
leaq 0x7a22d(%rip), %rsi     # 0x12ac58
jmp 0xb0a37
leaq 0x7a24a(%rip), %rsi     # 0x12ac7e
xorl %r14d, %r14d
movq %rbx, %rdi
callq 0xe07f7
pushq $0x1
popq %rsi
movq %rbx, %rdi
callq 0xdecaf
movq %rax, %r15
movq 0x18(%rbx), %rdi
movq %r14, %rsi
orq $0x3, %rsi
callq 0xe3eb4
movq %r15, (%rsp)
movb %al, (%r15)
movzbl %al, %edx
leaq 0x7a22a(%rip), %rsi     # 0x12ac98
movq %rbx, %rdi
xorl %eax, %eax
callq 0xde896
orq $0x8, %r14
pushq $-0x1
popq %r12
movq 0x18(%rbx), %rax
cmpq 0x18(%rax), %r14
jge 0xb0bf1
movq %rbx, %rdi
leaq 0x7a20c(%rip), %rsi     # 0x12aca4
movl %r14d, %edx
xorl %eax, %eax
callq 0xde896
movq %rbx, %rdi
pushq $0x1
popq %rsi
callq 0xdeba7
movq 0x18(%rbx), %rdi
movq %r14, %rsi
callq 0xe3eb4
movzbl %al, %r13d
movq %rbx, %rdi
leaq 0x767d8(%rip), %rsi     # 0x12729f
movl %r13d, %edx
xorl %eax, %eax
callq 0xde896
movq 0x18(%rbx), %rdi
leaq 0x1(%r14), %rsi
callq 0xe3fa3
movq %rax, %rbp
movq %rbx, %rdi
leaq 0x7a1c5(%rip), %rsi     # 0x12acb0
movl %ebp, %edx
xorl %eax, %eax
callq 0xde896
leaq (%r14,%rbp), %rax
addq $0x8, %rax
movq 0x18(%rbx), %rcx
cmpq 0x18(%rcx), %rax
jle 0xb0b22
xorl %r15d, %r15d
movq %rbx, %rdi
leaq 0x7a1b7(%rip), %rsi     # 0x12acca
xorl %eax, %eax
callq 0xdf2a5
pushq $0x8
popq %rbp
jmp 0xb0baf
cmpl $0xff, %r13d
je 0xb0bcd
cmpl $0x1, %r13d
je 0xb0b96
cmpl $0xfe, %r13d
je 0xb0b8d
testl %r13d, %r13d
jne 0xb0bd5
leaq 0x8(%r14), %r13
movq %rbx, %rdi
leaq 0x7a0d5(%rip), %rsi     # 0x12ac2a
xorl %edx, %edx
xorl %ecx, %ecx
callq 0xe4e62
movq %rax, %r15
movq %rax, %rdi
leaq 0x7a1c6(%rip), %rsi     # 0x12ad31
pushq $0x3
popq %rdx
callq 0xe46ba
movq 0x18(%rbx), %rdi
movq %r13, %rsi
movq %rbp, %rdx
movq %r15, %rcx
callq 0xe45f4
movq %r15, %rdi
callq 0xe5591
addq $0x8, %rbp
movb $0x1, %r15b
jmp 0xb0baf
movq %rbx, %rdi
leaq 0x7a148(%rip), %rsi     # 0x12ace8
xorl %eax, %eax
callq 0xdf05a
movb $0x1, %r15b
movl $0x148, %ebp            # imm = 0x148
movq %rbx, %rdi
movl %r12d, %esi
callq 0xdeba7
testb %r15b, %r15b
je 0xb0bf1
addq %rbp, %r14
testq %rbp, %rbp
jne 0xb0a80
jmp 0xb0bf1
xorl %r15d, %r15d
jmp 0xb0b1a
xorl %r15d, %r15d
movq %rbx, %rdi
leaq 0x7a137(%rip), %rsi     # 0x12ad19
movl %r13d, %edx
xorl %eax, %eax
callq 0xdf2a5
jmp 0xb0b1a
movq %rbx, %rdi
movq (%rsp), %rsi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xded32