// File: /workspace/github_c_makefile_star2_O3/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, %r15
movl $0x4, %esi
callq 0xe8b2b
movq %rax, (%rsp)
movq 0x18(%r15), %rdi
movl $0x2, %esi
callq 0xeebc8
movq %rax, %rbp
leaq 0xcf7e6(%rip), %rsi     # 0x11f231
movq %r15, %rdi
movl %ebp, %edx
xorl %eax, %eax
callq 0xe8617
movq 0x18(%r15), %rdi
movl $0x4, %esi
callq 0xeebc8
leaq 0xe9c26(%rip), %rsi     # 0x139692
movq %r15, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xe8617
movq 0x18(%r15), %rdi
movl $0x1c, %esi
callq 0xeebc8
leaq 0xcf7bc(%rip), %rsi     # 0x11f249
movq %r15, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xe8617
addq %rbp, %rbp
movq 0x18(%r15), %rax
cmpq 0x18(%rax), %rbp
jge 0x4fc30
leaq 0x131d6f(%rip), %r13    # 0x181820
movq %r15, 0x8(%rsp)
movq $0x0, 0x10(%rsp)
movq %r15, %rdi
leaq 0xe5d6e(%rip), %rsi     # 0x135837
movl %ebp, %edx
xorl %eax, %eax
callq 0xe8617
movq %r15, %rdi
movl $0x1, %esi
callq 0xe8a15
movq 0x18(%r15), %rdi
movq %rbp, %rsi
callq 0xeebc8
movq %rax, %r14
movq %rax, 0x28(%rsp)
movq 0x18(%r15), %rdi
leaq 0x2(%rbp), %rsi
callq 0xeebc8
movq %rax, %r12
movq %rax, 0x38(%rsp)
movq 0x18(%r15), %rdi
leaq 0x4(%rbp), %rsi
callq 0xeebc8
movq %r15, %rcx
movq %rax, %r15
movq %rax, 0x40(%rsp)
movq 0x18(%rcx), %rdi
leaq 0x6(%rbp), %rsi
callq 0xeebc8
movq %rax, 0x30(%rsp)
leaq (,%r12,4), %rcx
leaq (%rcx,%r15,2), %r10
leaq 0x8(%rbp), %rbx
movq %rbx, 0x18(%rsp)
leaq 0x8(,%r12,4), %rcx
addq %rbp, %rcx
movq %rcx, 0x20(%rsp)
movl $0x10, %edx
movzwl -0x10(%rdx,%r13), %ecx
cmpq %rcx, %r14
je 0x4fba7
addq $0x18, %rdx
cmpq $0x250, %rdx            # imm = 0x250
jne 0x4fb5c
movq 0x8(%rsp), %rdi
leaq 0xcf6d8(%rip), %rsi     # 0x11f258
movl %r14d, %edx
leaq 0xdc5c7(%rip), %rcx     # 0x12c151
movl %eax, %r8d
movl %r12d, %r9d
xorl %eax, %eax
movq %r10, %r12
pushq %r10
pushq %r15
movq %rdi, %r15
callq 0xe8617
addq $0x10, %rsp
jmp 0x4fc00
movq -0x8(%rdx,%r13), %rcx
movq (%rdx,%r13), %rbp
testq %rcx, %rcx
leaq 0xdc597(%rip), %rdx     # 0x12c151
cmoveq %rdx, %rcx
movq 0x8(%rsp), %rdi
leaq 0xcf68e(%rip), %rsi     # 0x11f258
movl %r14d, %edx
movl %eax, %r8d
movl %r12d, %r9d
xorl %eax, %eax
movq %r10, %r12
pushq %r10
pushq %r15
movq %rdi, %r15
callq 0xe8617
addq $0x10, %rsp
testq %rbp, %rbp
je 0x4fc00
movq %r15, %rdi
movq (%rsp), %rsi
leaq 0x10(%rsp), %rdx
callq *%rbp
movq 0x28(%rsp), %r14
movq %r15, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0xe8a15
cmpq $0xffff, %r14           # imm = 0xFFFF
je 0x4fc30
cmpq $-0x7, %r12
jl 0x4fc30
addq %r12, %rbx
movq 0x18(%r15), %rax
movq %rbx, %rbp
cmpq 0x18(%rax), %rbx
jl 0x4fab6
movq %r15, %rdi
movq (%rsp), %rsi
callq 0xe8be2
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq