// File: /workspace/github_c_makefile_star2_O2/jsummers[P]deark/modules/grasp.c
// Function: de_run_graspgl
static void de_run_graspgl(deark *c, de_module_params *mparams)
{
	lctx *d = NULL;
	i64 num_files;
	i64 pos = 0;
	i64 i;

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

	if((UI)de_getu32be(0)==0x41470100U) {
		// Ref: Aminet : gl2p1.lzh
		d->is_amiga = 1;
	}

	if(d->is_amiga) {
		de_declare_fmt(c, "Amiga GRASP GL");
		pos += 4;
	}
	else {
		de_declare_fmt(c, "GRASP GL");
		d->is_le = 1;
	}

	d->input_encoding = de_get_input_encoding(c, NULL,
		(d->is_amiga ? DE_ENCODING_LATIN1 : DE_ENCODING_CP437));

	d->index_size = dbuf_getu16x(c->infile, pos, d->is_le);
	pos += 2;

	d->index_pos = pos;
	de_dbg(c, "index size: %"I64_FMT, d->index_size);

	// 17 bytes per file entry
	num_files = (d->index_size+16)/17;
	de_dbg(c, "max number of files: %d", (int)num_files);

	for(i=0; i<num_files; i++) {
		if(!do_extract_file(c, d, i))
			break;
	}

	de_free(c, d);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rdi, %rbx
pushq $0x20
popq %rsi
callq 0xdecaf
movq %rax, %r15
movq 0x18(%rbx), %rdi
xorl %esi, %esi
callq 0xe404f
cmpl $0x41470100, %eax       # imm = 0x41470100
jne 0x50651
movb $0x1, 0x8(%r15)
jmp 0x5065c
cmpb $0x0, 0x8(%r15)
je 0x50919
leaq 0xc2b1b(%rip), %rsi     # 0x11317e
movq %rbx, %rdi
callq 0xe07f7
pushq $0x4
popq %r14
pushq $0x4
popq %r13
xorl %eax, %eax
cmpb $0x0, 0x8(%r15)
sete %al
leal 0x5(,%rax,8), %edx
movq %r15, %r12
xorl %r15d, %r15d
movq %rbx, %rdi
xorl %esi, %esi
callq 0xe08d2
movl %eax, (%r12)
movq 0x18(%rbx), %rdi
movl 0x4(%r12), %edx
movq %r14, %rsi
callq 0xe41b1
movq %rax, 0x18(%r12)
orq $0x2, %r14
movq %r14, 0x10(%r12)
leaq 0xc2acf(%rip), %rsi     # 0x11318d
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xde896
movq %r12, 0x10(%rsp)
movq 0x18(%r12), %rax
addq $0x10, %rax
pushq $0x11
popq %rcx
cqto
idivq %rcx
movq %rax, %r14
leaq 0xc2ab2(%rip), %rsi     # 0x11319d
movq %rbx, %rdi
movl %r14d, %edx
xorl %eax, %eax
callq 0xde896
testq %r14, %r14
cmovleq %r15, %r14
movq %r14, 0x18(%rsp)
xorl %eax, %eax
cmpq %rax, 0x18(%rsp)
movq 0x10(%rsp), %r15
je 0x508ff
movq %rax, (%rsp)
movq %rbx, %rdi
leaq 0xc(%rsp), %rsi
callq 0xdebae
movq 0x10(%r15), %r14
leaq (%r14,%r13), %r12
addq $-0x4, %r12
movq 0x18(%rbx), %rdi
movl 0x4(%r15), %edx
movq %r12, %rsi
callq 0xe41cb
testq %rax, %rax
je 0x508ad
movq %rax, %rbp
movq %rbx, %rdi
leaq 0xc2a7a(%rip), %rsi     # 0x1131d3
movq (%rsp), %rdx
xorl %eax, %eax
callq 0xde896
movq %rbx, %rdi
pushq $0x1
popq %rsi
callq 0xdeba7
movq %rbx, %rdi
leaq 0xc2a63(%rip), %rsi     # 0x1131dc
movq %r12, %rdx
xorl %eax, %eax
callq 0xde896
movq %rbx, %rdi
leaq 0xc2a64(%rip), %rsi     # 0x1131f1
movq %rbp, %rdx
xorl %eax, %eax
callq 0xde896
cmpq 0x18(%r15), %rbp
jl 0x508a5
movq 0x18(%rbx), %rdi
addq %r13, %r14
movq %r14, %rsi
callq 0xe3eb4
testb %al, %al
je 0x508a5
movq %r13, 0x20(%rsp)
movq %rbx, %rdi
callq 0xdfd1a
movq %rax, %r12
movq %rbx, %rdi
callq 0xeac74
movq %rax, %r13
movq 0x18(%rbx), %rdi
movl (%r15), %r9d
movq %r14, %rsi
pushq $0xd
popq %rdx
movq %rax, %rcx
pushq $0x1
popq %r8
callq 0xe4c9a
movq %rbx, %rdi
movq %r12, %rsi
movq %r13, %rdx
xorl %ecx, %ecx
callq 0xdfd55
movb $0x1, 0x8(%r12)
movq %r13, %rdi
callq 0xeb877
movq %rbx, %rdi
leaq 0xd67da(%rip), %rsi     # 0x126fee
movq %rax, %rdx
xorl %eax, %eax
callq 0xde896
movq 0x18(%rbx), %rdi
movl 0x4(%r15), %edx
movq %rbp, %rsi
callq 0xe41cb
movq %rax, %r14
leaq 0x4(%rbp), %r15
movq %rbx, %rdi
leaq 0xd9f5c(%rip), %rsi     # 0x12a79b
movq %r15, %rdx
movq %rax, %rcx
xorl %eax, %eax
callq 0xde896
leaq (%r14,%rbp), %rax
addq $0x4, %rax
movq 0x18(%rbx), %rdi
cmpq 0x18(%rdi), %rax
jg 0x508c6
movq %r15, %rsi
movq %r14, %rdx
xorl %ecx, %ecx
movq %r12, %r8
xorl %r9d, %r9d
callq 0xe4e0b
movq %rbx, %rdi
movq %r12, %rsi
callq 0xdfd24
movq %r13, %rdi
callq 0xeaf3c
movl 0xc(%rsp), %esi
movq %rbx, %rdi
callq 0xdebb7
movq (%rsp), %rax
incq %rax
movq 0x20(%rsp), %r13
addq $0x11, %r13
jmp 0x50706
xorl %r12d, %r12d
xorl %r13d, %r13d
jmp 0x508cb
leaq 0xc2901(%rip), %rsi     # 0x1131b5
xorl %r13d, %r13d
movq %rbx, %rdi
xorl %eax, %eax
callq 0xde896
xorl %r12d, %r12d
jmp 0x508e0
movq 0x10(%rsp), %r15
movq (%rsp), %rdx
leaq 0xc292f(%rip), %rsi     # 0x113205
movq %rbx, %rdi
xorl %eax, %eax
callq 0xdf2a5
movq %rbx, %rdi
movq %r12, %rsi
callq 0xdfd24
movq %r13, %rdi
callq 0xeaf3c
movl 0xc(%rsp), %esi
movq %rbx, %rdi
callq 0xdebb7
movq %rbx, %rdi
movq %r15, %rsi
callq 0xded32
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xc2864(%rip), %rsi     # 0x113184
movq %rbx, %rdi
callq 0xe07f7
movl $0x1, 0x4(%r15)
xorl %r14d, %r14d
jmp 0x5066f