// File: /workspace/github_c_makefile_star2_O1/jsummers[P]deark/modules/gws.c
// Function: de_run_imggal_alch
static void de_run_imggal_alch(deark *c, de_module_params *mparams)
{
	struct imggal_ctx *d = NULL;
	const char *s;
	i64 i;

	d = de_malloc(c, sizeof(struct imggal_ctx));
	d->input_encoding = de_get_input_encoding(c, NULL, DE_ENCODING_CP437);

	// 8: gallery comment

	d->item_count = de_getu16le(73);
	de_dbg(c, "number of items: %d", (int)d->item_count);

	d->imgtype = de_getbyte(75);
	de_dbg(c, "image type: %u", (UI)d->imgtype);
	de_dbg_indent(c, 1);

	s = (d->imgtype<=1 || d->imgtype==4) ? "portrait" : "landscape";
	de_dbg(c, "orientation: %s", s);

	if(d->imgtype==1 || d->imgtype==3) {
		s = "grayscale";
		d->bpp = 4;
	}
	else if(d->imgtype==4 || d->imgtype==5) {
		s = "color";
		d->is_color = 1;
		d->bpp = 4;
	}
	else {
		s = "bilevel";
		d->bpp = 1;
	}
	de_dbg(c, "color mode: %s", s);

	de_dbg_indent(c, -1);

	d->item_size = de_getu16le(87);
	de_dbg(c, "item size: %"I64_FMT, d->item_size);

	// 89: gallery creation time
	// 93: gallery last-modified time

	if(d->imgtype>5) {
		d->need_errmsg = 1;
		goto done;
	}

	if(d->item_size<649 || (IMGGAL_HDRSIZE+d->item_count*d->item_size > c->infile->len)) {
		d->need_errmsg = 1;
		goto done;
	}

	for(i=0; i<d->item_count; i++) {
		if(!do_imggal_member(c, d, i, IMGGAL_HDRSIZE+i*d->item_size)) {
			goto done;
		}
	}

done:
	if(d) {
		if(d->need_errmsg) {
			de_err(c, "Invalid or unsupported GAL file");
		}
		de_free(c, d);
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
movq %rdi, %rbx
movl $0x20, %esi
callq 0xe969b
movq %rax, %r14
movq %rbx, %rdi
xorl %esi, %esi
movl $0xd, %edx
callq 0xeb7d1
movl %eax, (%r14)
movq 0x18(%rbx), %rdi
movl $0x49, %esi
callq 0xef1ca
movq %rax, 0x8(%r14)
leaq 0xc8394(%rip), %rsi     # 0x12c224
movq %rbx, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xe9226
movq 0x18(%rbx), %rdi
movl $0x4b, %esi
callq 0xef0d5
movb %al, 0x4(%r14)
movzbl %al, %edx
leaq 0xd65b0(%rip), %rsi     # 0x13a468
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9226
movq %rbx, %rdi
movl $0x1, %esi
callq 0xe9585
movb 0x4(%r14), %al
cmpb $0x4, %al
leaq 0xbffb0(%rip), %rcx     # 0x123e8c
leaq 0xbffb2(%rip), %rdx     # 0x123e95
cmoveq %rcx, %rdx
cmpb $0x2, %al
cmovbq %rcx, %rdx
leaq 0xbffab(%rip), %rsi     # 0x123e9f
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9226
movzbl 0x4(%r14), %ecx
movl $0x4, %eax
leal -0x4(%rcx), %edx
cmpl $0x2, %edx
jb 0x63f2f
leaq 0xb20b9(%rip), %rdx     # 0x115fd0
cmpl $0x1, %ecx
je 0x63f3b
cmpl $0x3, %ecx
je 0x63f3b
leaq 0xbff87(%rip), %rdx     # 0x123eaf
movl $0x1, %eax
jmp 0x63f3b
movb $0x1, 0x6(%r14)
leaq 0xb1fdb(%rip), %rdx     # 0x115f16
movq %rax, 0x18(%r14)
leaq 0xbff71(%rip), %rsi     # 0x123eb7
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9226
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0xe9585
movq 0x18(%rbx), %rdi
movl $0x57, %esi
callq 0xef1ca
movq %rax, 0x10(%r14)
leaq 0xbff50(%rip), %rsi     # 0x123ec6
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xe9226
cmpb $0x5, 0x4(%r14)
ja 0x63fa9
movq 0x10(%r14), %rax
cmpq $0x289, %rax            # imm = 0x289
jl 0x63fa9
imulq 0x8(%r14), %rax
addq $0x61, %rax
movq 0x18(%rbx), %rcx
cmpq 0x18(%rcx), %rax
jle 0x63fe3
movb $0x1, 0x5(%r14)
cmpb $0x0, 0x5(%r14)
je 0x63fc6
leaq 0xbff19(%rip), %rsi     # 0x123ed5
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9df7
movq %rbx, %rdi
movq %r14, %rsi
callq 0xe9752
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpq $0x0, 0x8(%r14)
jle 0x63fae
leaq 0x8(%rsp), %r13
xorl %eax, %eax
movq %r14, 0x18(%rsp)
movq 0x10(%r14), %r15
movq %rax, 0x38(%rsp)
imulq %rax, %r15
addq $0x61, %r15
movq %r15, 0x8(%rsp)
movq %rbx, %rdi
leaq 0x14(%rsp), %rsi
callq 0xe958c
movl $0x458, %esi            # imm = 0x458
movq %rbx, %rdi
callq 0xe969b
movq %rax, %r12
movq %rbx, %rdi
leaq 0xcc86d(%rip), %rsi     # 0x1308a0
movq %r15, 0x30(%rsp)
movq %r15, %rdx
xorl %eax, %eax
callq 0xe9226
movq %rbx, %rdi
movl $0x1, %esi
callq 0xe9585
movq 0x18(%rbx), %rdi
movq %r13, %rsi
callq 0xef475
leaq 0x38(%r12), %r15
movq %rax, %rdi
movq %r15, %rsi
movl $0x1, %edx
callq 0xeace2
movl $0x40, %edx
movq %r15, 0x28(%rsp)
movq %r15, %rdi
leaq 0x40(%rsp), %r15
movq %r15, %rsi
xorl %ecx, %ecx
callq 0xeb4f8
movq %rbx, %rdi
leaq 0xe4d54(%rip), %rbp     # 0x148dea
movq %rbp, %rsi
leaq 0xcb09d(%rip), %rdx     # 0x12f13d
movq %r15, %rcx
xorl %eax, %eax
callq 0xe9226
movq 0x18(%rbx), %rdi
movq %r13, %rsi
callq 0xef475
leaq 0x48(%r12), %r13
movq %rax, %rdi
movq %r13, %rsi
movl $0x1, %edx
callq 0xeace2
movl $0x40, %edx
movq %r13, 0x20(%rsp)
movq %r13, %rdi
movq %r15, %rsi
xorl %ecx, %ecx
callq 0xeb4f8
movq %rbx, %rdi
movq %rbp, %rsi
leaq 0xc9c6d(%rip), %rdx     # 0x12dd5c
movq %r15, %rcx
xorl %eax, %eax
callq 0xe9226
addq $0x1c, 0x8(%rsp)
movq %rbx, %rdi
callq 0xf6870
movq %rax, 0x28(%r12)
movq 0x18(%rbx), %rdi
movq 0x8(%rsp), %rsi
movl (%r14), %r9d
movl $0x50, %edx
movq %rax, %rcx
movl $0x1, %r8d
callq 0xf01b0
movq 0x28(%r12), %rdi
callq 0xf7557
movq %rbx, %rdi
leaq 0xbfdb6(%rip), %rsi     # 0x123ef5
movq %rax, %rdx
xorl %eax, %eax
callq 0xe9226
addq $0x51, 0x8(%rsp)
movq %rbx, %rdi
callq 0xf6870
movq %rax, %r15
movq %rax, 0x30(%r12)
movq 0x28(%r12), %r13
movq %rax, %rdi
callq 0xf6883
movq 0x10(%r13), %r14
testq %r14, %r14
jle 0x641a2
xorl %ebp, %ebp
movq 0x8(%r13), %rax
movl (%rax,%rbp,4), %esi
cmpl $0x5c, %esi
je 0x64188
cmpl $0x2f, %esi
jne 0x64192
movq %r15, %rdi
callq 0xf6883
jmp 0x6419a
movq %r15, %rdi
callq 0xf69a2
incq %rbp
cmpq %rbp, %r14
jne 0x64177
addq $0x210, 0x8(%rsp)       # imm = 0x210
movq 0x18(%rbx), %rdi
leaq 0x8(%rsp), %r13
movq %r13, %rsi
callq 0xef1ed
incq %rax
movq %rax, (%r12)
movq 0x18(%rbx), %rdi
movq %r13, %rsi
callq 0xef1ed
leaq 0x1(%rax), %rdx
movq %rdx, 0x10(%r12)
movq (%r12), %rsi
movq %rbx, %rdi
callq 0xe9b05
movq (%r12), %rsi
movq 0x10(%r12), %rdx
movq %rbx, %rdi
callq 0xf241d
testl %eax, %eax
je 0x6425e
movq (%r12), %rsi
leaq 0x7(%rsi), %rax
leaq 0xe(%rsi), %rdx
testq %rax, %rax
cmovnsq %rax, %rdx
movq 0x10(%r12), %rcx
movq %rdx, %rax
sarq $0x3, %rax
movq %rax, 0x18(%r12)
movq 0x18(%rsp), %r14
imulq 0x18(%r14), %rax
movq %rax, 0x20(%r12)
andq $-0x8, %rdx
movq %rdx, 0x8(%r12)
imulq %rcx, %rax
addq 0x8(%rsp), %rax
movq 0x30(%rsp), %rdi
addq 0x10(%r14), %rdi
cmpq %rdi, %rax
jle 0x64270
movb $0x1, 0x5(%r14)
movb $0x1, %r13b
xorl %ebp, %ebp
xorl %r15d, %r15d
jmp 0x6438f
xorl %ebp, %ebp
xorl %r15d, %r15d
xorl %r13d, %r13d
movq 0x18(%rsp), %r14
jmp 0x6438f
xorl %eax, %eax
cmpb $0x0, 0x6(%r14)
setne %al
leal 0x1(,%rax,2), %r8d
movq %rbx, %rdi
callq 0xf2ce6
movq %rax, %rbp
movq %rbx, %rdi
callq 0xea9a9
movq %rax, %r15
cmpb $0x0, 0x6(%r14)
je 0x642d8
movaps 0xbfd5a(%rip), %xmm0    # 0x124000
movups %xmm0, 0x88(%r12)
movaps 0xbfd3a(%rip), %xmm0    # 0x123ff0
movups %xmm0, 0x78(%r12)
movaps 0xbfd1d(%rip), %xmm0    # 0x123fe0
movups %xmm0, 0x68(%r12)
movaps 0xbfd00(%rip), %xmm0    # 0x123fd0
movups %xmm0, 0x58(%r12)
jmp 0x6431b
cmpq $0x1, 0x18(%r14)
jne 0x642f0
movabsq $-0xc0c0c01000000, %rax # imm = 0xFFF3F3F3FF000000
movq %rax, 0x58(%r12)
jmp 0x6431b
leaq 0x58(%r12), %rax
xorl %ecx, %ecx
movl %ecx, %edx
shrl $0x2, %edx
imull $0x10101, %edx, %edx    # imm = 0x10101
orl $0xff000000, %edx       # imm = 0xFF000000
movl %edx, (%rax)
addq $0x41, %rcx
addq $0x4, %rax
cmpq $0x410, %rcx            # imm = 0x410
jne 0x642f7
movq 0x18(%rbx), %rdi
movq 0x8(%rsp), %rsi
movq 0x18(%r14), %rdx
movq 0x18(%r12), %r8
movq %r8, %rcx
imulq %rdx, %rcx
movq %r12, %r9
addq $0x58, %r9
pushq $0x0
pushq %rbp
callq 0xf36f9
addq $0x10, %rsp
cmpb $0x0, 0xd0(%rbx)
je 0x64362
movq 0x30(%r12), %rdx
movq %rbx, %rdi
movq %r15, %rsi
xorl %ecx, %ecx
callq 0xea9e4
movq 0x20(%rsp), %rax
movups (%rax), %xmm0
movups %xmm0, 0x18(%r15)
movq 0x28(%rsp), %rax
movups (%rax), %xmm0
movups %xmm0, 0x28(%r15)
movq %rbp, %rdi
movq %r15, %rsi
movl $0x2, %edx
callq 0xf2917
xorl %r13d, %r13d
movl 0x14(%rsp), %esi
movq %rbx, %rdi
callq 0xe9595
movq %rbx, %rdi
movq %r15, %rsi
callq 0xea9b3
movq %rbp, %rdi
callq 0xf28d4
movq 0x28(%r12), %rdi
callq 0xf6bb0
movq 0x30(%r12), %rdi
callq 0xf6bb0
movq %rbx, %rdi
movq %r12, %rsi
callq 0xe9752
testb %r13b, %r13b
movq 0x38(%rsp), %rax
leaq 0x8(%rsp), %r13
jne 0x63fae
incq %rax
cmpq 0x8(%r14), %rax
jl 0x63ff6
jmp 0x63fae