// File: /workspace/github_c_makefile_star2_O3/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
movl $0x20, %esi
callq 0xe8b2b
movq %rax, %r15
movq 0x18(%rbx), %rdi
xorl %esi, %esi
callq 0xeed0d
cmpl $0x41470100, %eax       # imm = 0x41470100
jne 0x530e3
movb $0x1, 0x8(%r15)
jmp 0x530ee
cmpb $0x0, 0x8(%r15)
je 0x5336b
leaq 0xcd17b(%rip), %rsi     # 0x120270
movq %rbx, %rdi
callq 0xeb125
movl $0x4, %r14d
xorl %eax, %eax
cmpb $0x0, 0x8(%r15)
sete %al
leal 0x5(,%rax,8), %edx
movq %rbx, %rdi
xorl %esi, %esi
callq 0xeb220
movl %eax, (%r15)
movq 0x18(%rbx), %rdi
movl 0x4(%r15), %edx
movq %r14, %rsi
callq 0xeef43
movq %rax, 0x18(%r15)
orq $0x2, %r14
movq %r14, 0x10(%r15)
leaq 0xcd13b(%rip), %rsi     # 0x12027f
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xe8617
movq %r15, 0x8(%rsp)
movq 0x8(%rsp), %rax
movq 0x18(%rax), %r15
leaq 0x10(%r15), %rax
movabsq $0x7878787878787879, %rcx # imm = 0x7878787878787879
imulq %rcx
movq %rdx, %r14
movq %rdx, %rax
shrq $0x3f, %rax
sarq $0x3, %r14
addq %rax, %r14
leaq 0xcd107(%rip), %rsi     # 0x12028f
movq %rbx, %rdi
movl %r14d, %edx
xorl %eax, %eax
callq 0xe8617
testq %r15, %r15
movq 0x8(%rsp), %r15
jle 0x533dc
cmpq $0x2, %r14
movl $0x1, %eax
cmovgeq %r14, %rax
movq %rax, 0x20(%rsp)
movl $0x4, %r12d
xorl %ebp, %ebp
movq %rbx, %rdi
leaq 0x4(%rsp), %rsi
callq 0xe8a1c
movq 0x10(%r15), %r14
movq %r12, 0x18(%rsp)
addq %r14, %r12
addq $-0x4, %r12
movq 0x18(%rbx), %rdi
movl 0x4(%r15), %edx
movq %r12, %rsi
callq 0xeeff3
testq %rax, %rax
je 0x5338a
movq %rax, %r13
movq %rbx, %rdi
leaq 0xcd0c5(%rip), %rsi     # 0x1202c5
movl %ebp, %edx
xorl %eax, %eax
callq 0xe8617
movq %rbx, %rdi
movl $0x1, %esi
callq 0xe8a15
movq %rbx, %rdi
leaq 0xcd0ae(%rip), %rsi     # 0x1202ce
movq %r12, %rdx
xorl %eax, %eax
callq 0xe8617
movq %rbx, %rdi
leaq 0xcd0af(%rip), %rsi     # 0x1202e3
movq %r13, %rdx
xorl %eax, %eax
callq 0xe8617
cmpq 0x18(%r15), %r13
movq %rbp, 0x10(%rsp)
jl 0x53364
movq 0x18(%rbx), %rdi
addq 0x18(%rsp), %r14
movq %r14, %rsi
callq 0xeead3
testb %al, %al
je 0x53364
movq %rbx, %rdi
callq 0xea504
movq %rax, %r12
movq %rbx, %rdi
callq 0xf6410
movq %rax, %rbp
movq 0x18(%rbx), %rdi
movl (%r15), %r9d
movl $0xd, %edx
movq %r14, %rsi
movq %rax, %rcx
movl $0x1, %r8d
callq 0xefbd7
movq %rbx, %rdi
movq %r12, %rsi
movq %rbp, %rdx
xorl %ecx, %ecx
callq 0xea53f
movb $0x1, 0x8(%r12)
movq %rbp, %rdi
callq 0xf70f6
movq %rbx, %rdi
leaq 0xe1005(%rip), %rsi     # 0x1342c6
movq %rax, %rdx
xorl %eax, %eax
callq 0xe8617
movq 0x18(%rbx), %rdi
movl 0x4(%r15), %edx
movq %r13, %rsi
callq 0xeeff3
movq %rax, %r14
leaq 0x4(%r13), %r15
movq %rbx, %rdi
leaq 0xe478f(%rip), %rsi     # 0x137a7b
movq %r15, %rdx
movq %rax, %rcx
xorl %eax, %eax
callq 0xe8617
leaq (%r14,%r13), %rax
addq $0x4, %rax
movq 0x18(%rbx), %rdi
cmpq 0x18(%rdi), %rax
jg 0x533a2
movq %r15, %rsi
movq %r14, %rdx
xorl %ecx, %ecx
movq %r12, %r8
xorl %r9d, %r9d
callq 0xefd48
movq %rbx, %rdi
movq %r12, %rsi
callq 0xea50e
movq %rbp, %rdi
callq 0xf6753
movl 0x4(%rsp), %esi
movq %rbx, %rdi
callq 0xe8a25
movq 0x10(%rsp), %rbp
incq %rbp
movq 0x18(%rsp), %r12
addq $0x11, %r12
cmpq %rbp, 0x20(%rsp)
movq 0x8(%rsp), %r15
jne 0x531bd
jmp 0x533dc
xorl %r12d, %r12d
xorl %ebp, %ebp
jmp 0x533a7
leaq 0xccf04(%rip), %rsi     # 0x120276
movq %rbx, %rdi
callq 0xeb125
movl $0x1, 0x4(%r15)
xorl %r14d, %r14d
jmp 0x53103
leaq 0xccf16(%rip), %rsi     # 0x1202a7
xorl %ebp, %ebp
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe8617
xorl %r12d, %r12d
jmp 0x533bd
movq 0x8(%rsp), %r15
leaq 0xccf49(%rip), %rsi     # 0x1202f7
movq %rbx, %rdi
movq 0x10(%rsp), %rdx
xorl %eax, %eax
callq 0xe9295
movq %rbx, %rdi
movq %r12, %rsi
callq 0xea50e
movq %rbp, %rdi
callq 0xf6753
movl 0x4(%rsp), %esi
movq %rbx, %rdi
callq 0xe8a25
movq %rbx, %rdi
movq %r15, %rsi
callq 0xe8be2
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq