// File: /workspace/github_c_makefile_star2_O1/jsummers[P]deark/modules/gemmeta.c
// Function: de_run_gemmeta
static void de_run_gemmeta(deark *c, de_module_params *mparams)
{
	lctx *d = NULL;
	i64 pos;
	i64 hdrlen_words;
	i64 version;
	i64 imgflag;
	i64 bytesused;

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

	pos = 0;
	hdrlen_words = de_getu16le(pos+2);
	de_dbg(c, "header length: %d words", (int)hdrlen_words);
	version = de_getu16le(pos+4);
	de_dbg(c, "version number: %d", (int)version);
	// TODO: Read more header fields.
	imgflag = de_getu16le(pos+28);
	de_dbg(c, "image flag: %d", (int)imgflag);

	pos += hdrlen_words*2;

	while(1) {
		if(pos >= c->infile->len) break;
		if(!do_record(c, d, pos, &bytesused)) break;
		if(bytesused<=0) break;
		pos += bytesused;
	}
	de_free(c, d);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rdi, %rbx
movl $0x4, %esi
callq 0xe969b
movq %rax, 0x8(%rsp)
movq 0x18(%rbx), %rdi
movl $0x2, %esi
callq 0xef1ca
movq %rax, %r15
leaq 0xcf5a9(%rip), %rsi     # 0x11f129
movq %rbx, %rdi
movl %r15d, %edx
xorl %eax, %eax
callq 0xe9226
movq 0x18(%rbx), %rdi
movl $0x4, %esi
callq 0xef1ca
leaq 0xe9760(%rip), %rsi     # 0x139302
movq %rbx, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xe9226
movq 0x18(%rbx), %rdi
movl $0x1c, %esi
callq 0xef1ca
leaq 0xcf57e(%rip), %rsi     # 0x11f141
movq %rbx, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xe9226
addq %r15, %r15
movq 0x18(%rbx), %rax
cmpq 0x18(%rax), %r15
jge 0x4fd46
leaq 0x131b99(%rip), %rbp    # 0x181780
leaq 0xcf562(%rip), %r13     # 0x11f150
xorps %xmm0, %xmm0
movaps %xmm0, 0x30(%rsp)
movaps %xmm0, 0x20(%rsp)
movaps %xmm0, 0x10(%rsp)
movq $0x0, 0x40(%rsp)
movq %rbx, %rdi
leaq 0xe5898(%rip), %rsi     # 0x1354ab
movl %r15d, %edx
xorl %eax, %eax
callq 0xe9226
movq %rbx, %rdi
movl $0x1, %esi
callq 0xe9585
movq 0x18(%rbx), %rdi
movq %r15, %rsi
callq 0xef1ca
movq %rax, 0x28(%rsp)
movq 0x18(%rbx), %rdi
leaq 0x2(%r15), %rsi
callq 0xef1ca
movq %rax, 0x38(%rsp)
movq 0x18(%rbx), %rdi
leaq 0x4(%r15), %rsi
callq 0xef1ca
movq %rax, 0x40(%rsp)
movq 0x18(%rbx), %rdi
leaq 0x6(%r15), %rsi
callq 0xef1ca
movq %rax, 0x30(%rsp)
movq 0x28(%rsp), %rdx
movq 0x38(%rsp), %r9
leaq (,%r9,4), %rcx
movq 0x40(%rsp), %r10
leaq (%rcx,%r10,2), %r14
leaq 0x8(%r15), %rcx
movq %rcx, 0x18(%rsp)
leaq (%r15,%r9,4), %rcx
addq $0x8, %rcx
movq %rcx, 0x20(%rsp)
xorl %r12d, %r12d
movzwl (%r12,%rbp), %ecx
cmpq %rcx, %rdx
je 0x4fcc1
addq $0x18, %r12
cmpq $0x240, %r12            # imm = 0x240
jne 0x4fca5
xorl %r12d, %r12d
jmp 0x4fcc4
addq %rbp, %r12
testq %r12, %r12
je 0x4fcd3
movq 0x8(%r12), %rcx
testq %rcx, %rcx
jne 0x4fcda
leaq 0xdc18f(%rip), %rcx     # 0x12be69
movq %rbx, %rdi
movq %r13, %rsi
movl %eax, %r8d
xorl %eax, %eax
pushq %r14
pushq %r10
callq 0xe9226
addq $0x10, %rsp
testq %r12, %r12
je 0x4fd10
movq 0x10(%r12), %rax
testq %rax, %rax
je 0x4fd10
movq %rbx, %rdi
movq 0x8(%rsp), %rsi
leaq 0x10(%rsp), %rdx
callq *%rax
movq 0x28(%rsp), %r12
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0xe9585
cmpq $0xffff, %r12           # imm = 0xFFFF
je 0x4fd46
cmpq $-0x7, %r14
jl 0x4fd46
addq %r14, %r15
addq $0x8, %r15
movq 0x18(%rbx), %rax
cmpq 0x18(%rax), %r15
jl 0x4fbee
movq %rbx, %rdi
movq 0x8(%rsp), %rsi
callq 0xe9752
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq