// File: /workspace/github_c_makefile_star2_O1/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 $0x38, %rsp
movq %rdi, %rbx
movl $0x20, %esi
callq 0xe969b
movq %rax, %r15
movq 0x18(%rbx), %rdi
xorl %esi, %esi
callq 0xef32a
cmpl $0x41470100, %eax       # imm = 0x41470100
jne 0x5318d
movb $0x1, 0x8(%r15)
cmpb $0x0, 0x8(%r15)
je 0x531ab
leaq 0xccfad(%rip), %rsi     # 0x120148
movq %rbx, %rdi
callq 0xeb6d6
movl $0x4, %r14d
jmp 0x531c5
leaq 0xccf9c(%rip), %rsi     # 0x12014e
movq %rbx, %rdi
callq 0xeb6d6
movl $0x1, 0x4(%r15)
xorl %r14d, %r14d
xorl %eax, %eax
cmpb $0x0, 0x8(%r15)
sete %al
leal 0x5(,%rax,8), %edx
movq %rbx, %rdi
xorl %esi, %esi
callq 0xeb7d1
movl %eax, (%r15)
movq 0x18(%rbx), %rdi
movl 0x4(%r15), %edx
movq %r14, %rsi
callq 0xef570
movq %rax, 0x18(%r15)
orq $0x2, %r14
movq %r14, 0x10(%r15)
leaq 0xccf51(%rip), %rsi     # 0x120157
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xe9226
movq %r15, 0x8(%rsp)
movq 0x18(%r15), %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 0xccf22(%rip), %rsi     # 0x120167
movq %rbx, %rdi
movl %r14d, %edx
xorl %eax, %eax
callq 0xe9226
testq %r15, %r15
jle 0x53496
cmpq $0x2, %r14
movl $0x1, %eax
cmovgeq %r14, %rax
decq %rax
movq %rax, 0x30(%rsp)
movl $0x4, %r13d
movq $0x0, 0x10(%rsp)
movq %rbx, %rdi
leaq 0x24(%rsp), %rsi
callq 0xe958c
movq 0x8(%rsp), %rbp
movq 0x10(%rbp), %r14
leaq (%r14,%r13), %r12
addq $-0x4, %r12
movq 0x18(%rbx), %rdi
movl 0x4(%rbp), %edx
movq %r12, %rsi
callq 0xef614
testq %rax, %rax
je 0x533f6
movq %rax, %r15
movq %rbx, %rdi
leaq 0xccedb(%rip), %rsi     # 0x12019d
movq 0x10(%rsp), %rdx
xorl %eax, %eax
callq 0xe9226
movq %rbx, %rdi
movl $0x1, %esi
callq 0xe9585
movq %rbx, %rdi
leaq 0xccec1(%rip), %rsi     # 0x1201a6
movq %r12, %rdx
xorl %eax, %eax
callq 0xe9226
movq %rbx, %rdi
leaq 0xccec2(%rip), %rsi     # 0x1201bb
movq %r15, %rdx
xorl %eax, %eax
callq 0xe9226
movb $0x1, %r12b
cmpq 0x18(%rbp), %r15
jl 0x533ec
movq 0x18(%rbx), %rdi
addq %r13, %r14
movq %r14, %rsi
callq 0xef0d5
testb %al, %al
je 0x533ec
movq %rbx, %rdi
callq 0xea9a9
movq %rax, 0x18(%rsp)
movq %rbx, %rdi
callq 0xf6870
movq %rax, %rbp
movq 0x18(%rbx), %rdi
movq 0x8(%rsp), %rax
movl (%rax), %r9d
movl $0xd, %edx
movq %r14, %rsi
movq %rbp, %rcx
movl $0x1, %r8d
callq 0xf01b0
movq %rbx, %rdi
movq 0x18(%rsp), %r14
movq %r14, %rsi
movq %rbp, %rdx
xorl %ecx, %ecx
callq 0xea9e4
movb $0x1, 0x8(%r14)
movq %rbp, 0x28(%rsp)
movq %rbp, %rdi
callq 0xf7557
movq %rbx, %rdi
leaq 0xe0b3c(%rip), %rsi     # 0x133ece
movq %rax, %rdx
xorl %eax, %eax
callq 0xe9226
movq 0x18(%rbx), %rdi
movq 0x8(%rsp), %rax
movl 0x4(%rax), %edx
movq %r15, %rsi
callq 0xef614
movq %rax, %r14
leaq 0x4(%r15), %rbp
movq %rbx, %rdi
leaq 0xe4332(%rip), %rsi     # 0x1376f3
movq %rbp, %rdx
movq %rax, %rcx
xorl %eax, %eax
callq 0xe9226
leaq (%r14,%r15), %rax
addq $0x4, %rax
movq 0x18(%rbx), %rdi
cmpq 0x18(%rdi), %rax
jle 0x53414
movq 0x18(%rsp), %r14
movq 0x28(%rsp), %r15
jmp 0x533f2
xorl %r14d, %r14d
xorl %r15d, %r15d
xorl %eax, %eax
jmp 0x53436
movq %rbx, %rdi
leaq 0xccd7f(%rip), %rsi     # 0x12017f
xorl %eax, %eax
callq 0xe9226
movb $0x1, %al
xorl %r14d, %r14d
xorl %r15d, %r15d
movb $0x1, %r12b
jmp 0x53436
xorl %r12d, %r12d
movq %rbp, %rsi
movq %r14, %rdx
xorl %ecx, %ecx
movq 0x18(%rsp), %r14
movq %r14, %r8
xorl %r9d, %r9d
callq 0xf0321
movb $0x1, %al
movq 0x28(%rsp), %r15
testb %al, %al
jne 0x53450
movq %rbx, %rdi
leaq 0xccd8b(%rip), %rsi     # 0x1201cf
movq 0x10(%rsp), %rdx
xorl %eax, %eax
callq 0xe9df7
movq %rbx, %rdi
movq %r14, %rsi
callq 0xea9b3
movq %r15, %rdi
callq 0xf6bb0
movl 0x24(%rsp), %esi
movq %rbx, %rdi
callq 0xe9595
movq 0x10(%rsp), %rax
cmpq %rax, 0x30(%rsp)
leaq 0x1(%rax), %rbp
sete %al
orb %al, %r12b
addq $0x11, %r13
movq %rbp, 0x10(%rsp)
cmpb $0x1, %r12b
jne 0x5327f
movq %rbx, %rdi
movq 0x8(%rsp), %rsi
callq 0xe9752
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq