// File: /workspace/github_c_makefile_star2_O3/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 0xe8b2b
movq %rax, %r14
movq %rbx, %rdi
xorl %esi, %esi
movl $0xd, %edx
callq 0xeb220
movl %eax, (%r14)
movq 0x18(%rbx), %rdi
movl $0x49, %esi
callq 0xeebc8
movq %rax, 0x8(%r14)
leaq 0xc8858(%rip), %rsi     # 0x12c50c
movq %rbx, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xe8617
movq 0x18(%rbx), %rdi
movl $0x4b, %esi
callq 0xeead3
movb %al, 0x4(%r14)
movzbl %al, %edx
leaq 0xd6b0c(%rip), %rsi     # 0x13a7e8
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe8617
movq %rbx, %rdi
movl $0x1, %esi
callq 0xe8a15
movb 0x4(%r14), %al
cmpb $0x4, %al
leaq 0xc03ae(%rip), %rcx     # 0x1240ae
leaq 0xc03b0(%rip), %rdx     # 0x1240b7
cmoveq %rcx, %rdx
cmpb $0x2, %al
cmovbq %rcx, %rdx
leaq 0xc03a9(%rip), %rsi     # 0x1240c1
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe8617
movzbl 0x4(%r14), %ecx
movl $0x4, %eax
leal -0x4(%rcx), %edx
cmpl $0x2, %edx
jb 0x63d53
leaq 0xb2345(%rip), %rdx     # 0x116080
cmpl $0x1, %ecx
je 0x63d5f
cmpl $0x3, %ecx
je 0x63d5f
leaq 0xc0385(%rip), %rdx     # 0x1240d1
movl $0x1, %eax
jmp 0x63d5f
movb $0x1, 0x6(%r14)
leaq 0xb2267(%rip), %rdx     # 0x115fc6
movq %rax, 0x18(%r14)
leaq 0xc036f(%rip), %rsi     # 0x1240d9
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe8617
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0xe8a15
movq 0x18(%rbx), %rdi
movl $0x57, %esi
callq 0xeebc8
movq %rax, 0x10(%r14)
leaq 0xc034e(%rip), %rsi     # 0x1240e8
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xe8617
cmpb $0x5, 0x4(%r14)
ja 0x63dd0
movq 0x10(%r14), %rax
cmpq $0x289, %rax            # imm = 0x289
jl 0x63dd0
movq 0x8(%r14), %rcx
imulq %rcx, %rax
addq $0x61, %rax
movq 0x18(%rbx), %rdx
cmpq 0x18(%rdx), %rax
jle 0x63e0a
movb $0x1, 0x5(%r14)
cmpb $0x0, 0x5(%r14)
je 0x63ded
leaq 0xc0314(%rip), %rsi     # 0x1240f7
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9295
movq %rbx, %rdi
movq %r14, %rsi
callq 0xe8be2
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
testq %rcx, %rcx
jle 0x63dd5
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 0xe8a1c
movl $0x458, %esi            # imm = 0x458
movq %rbx, %rdi
callq 0xe8b2b
movq %rax, %r12
movq %rbx, %rdi
leaq 0xccd88(%rip), %rsi     # 0x130bdb
movq %r15, 0x30(%rsp)
movq %r15, %rdx
xorl %eax, %eax
callq 0xe8617
movq %rbx, %rdi
movl $0x1, %esi
callq 0xe8a15
movq 0x18(%rbx), %rdi
leaq 0x8(%rsp), %r15
movq %r15, %rsi
callq 0xeee2f
leaq 0x38(%r12), %r13
movq %rax, %rdi
movq %r13, %rsi
movl $0x1, %edx
callq 0xea7f5
movl $0x40, %edx
movq %r13, 0x28(%rsp)
movq %r13, %rdi
leaq 0x40(%rsp), %r13
movq %r13, %rsi
xorl %ecx, %ecx
callq 0xeaf46
movq %rbx, %rdi
leaq 0xe54c7(%rip), %rbp     # 0x149382
movq %rbp, %rsi
leaq 0xcb55b(%rip), %rdx     # 0x12f420
movq %r13, %rcx
xorl %eax, %eax
callq 0xe8617
movq 0x18(%rbx), %rdi
movq %r15, %rsi
callq 0xeee2f
leaq 0x48(%r12), %r15
movq %rax, %rdi
movq %r15, %rsi
movl $0x1, %edx
callq 0xea7f5
movl $0x40, %edx
movq %r15, 0x20(%rsp)
movq %r15, %rdi
movq %r13, %rsi
xorl %ecx, %ecx
callq 0xeaf46
movq %rbx, %rdi
movq %rbp, %rsi
leaq 0xca140(%rip), %rdx     # 0x12e054
movq %r13, %rcx
xorl %eax, %eax
callq 0xe8617
addq $0x1c, 0x8(%rsp)
movq %rbx, %rdi
callq 0xf6410
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 0xefbd7
movq 0x28(%r12), %rdi
callq 0xf70f6
movq %rbx, %rdi
leaq 0xc01b3(%rip), %rsi     # 0x124117
movq %rax, %rdx
xorl %eax, %eax
callq 0xe8617
addq $0x51, 0x8(%rsp)
movq %rbx, %rdi
callq 0xf6410
movq %rax, %r15
movq %rax, 0x30(%r12)
movq 0x28(%r12), %r13
movq %rax, %rdi
callq 0xf6423
movq 0x10(%r13), %r14
testq %r14, %r14
jle 0x63fc7
xorl %ebp, %ebp
movq 0x8(%r13), %rax
movl (%rax,%rbp,4), %esi
cmpl $0x5c, %esi
je 0x63fad
cmpl $0x2f, %esi
jne 0x63fb7
movq %r15, %rdi
callq 0xf6423
jmp 0x63fbf
movq %r15, %rdi
callq 0xf6542
incq %rbp
cmpq %rbp, %r14
jne 0x63f9c
addq $0x210, 0x8(%rsp)       # imm = 0x210
movq 0x18(%rbx), %rdi
leaq 0x8(%rsp), %r14
movq %r14, %rsi
callq 0xeebeb
incq %rax
movq %rax, (%r12)
movq 0x18(%rbx), %rdi
movq %r14, %rsi
callq 0xeebeb
leaq 0x1(%rax), %rdx
movq %rdx, 0x10(%r12)
movq (%r12), %rsi
movq %rbx, %rdi
callq 0xe8f88
movq (%r12), %rsi
movq 0x10(%r12), %rdx
movq %rbx, %rdi
callq 0xf1db1
testl %eax, %eax
je 0x64083
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 0x64095
movb $0x1, 0x5(%r14)
movb $0x1, %r13b
xorl %ebp, %ebp
xorl %r15d, %r15d
jmp 0x641c8
xorl %ebp, %ebp
xorl %r15d, %r15d
xorl %r13d, %r13d
movq 0x18(%rsp), %r14
jmp 0x641c8
xorl %eax, %eax
cmpb $0x0, 0x6(%r14)
setne %al
leal 0x1(,%rax,2), %r8d
movq %rbx, %rdi
callq 0xf26a5
movq %rax, %rbp
movq %rbx, %rdi
callq 0xea504
movq %rax, %r15
cmpb $0x0, 0x6(%r14)
je 0x64101
movaps 0xc0155(%rip), %xmm0    # 0x124220
movups %xmm0, 0x88(%r12)
movaps 0xc0135(%rip), %xmm0    # 0x124210
movups %xmm0, 0x78(%r12)
movaps 0xc0118(%rip), %xmm0    # 0x124200
movups %xmm0, 0x68(%r12)
movaps 0xc00fb(%rip), %xmm0    # 0x1241f0
movups %xmm0, 0x58(%r12)
movq 0x18(%r14), %rdx
jmp 0x64158
movq 0x18(%r14), %rdx
cmpq $0x1, %rdx
jne 0x64121
movabsq $-0xc0c0c01000000, %rax # imm = 0xFFF3F3F3FF000000
movq %rax, 0x58(%r12)
movl $0x1, %edx
jmp 0x64158
movaps 0xbfeb8(%rip), %xmm0    # 0x123fe0
movups %xmm0, 0x58(%r12)
movaps 0xbfebb(%rip), %xmm0    # 0x123ff0
movups %xmm0, 0x68(%r12)
movaps 0xbfebe(%rip), %xmm0    # 0x124000
movups %xmm0, 0x78(%r12)
movaps 0xbfec1(%rip), %xmm0    # 0x124010
movups %xmm0, 0x88(%r12)
movq 0x18(%rbx), %rdi
movq 0x8(%rsp), %rsi
movq 0x18(%r12), %r8
movq %r8, %rcx
imulq %rdx, %rcx
movq %r12, %r9
addq $0x58, %r9
pushq $0x0
pushq %rbp
callq 0xf30b3
addq $0x10, %rsp
cmpb $0x0, 0xd0(%rbx)
je 0x6419b
movq 0x30(%r12), %rdx
movq %rbx, %rdi
movq %r15, %rsi
xorl %ecx, %ecx
callq 0xea53f
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 0xf22d0
xorl %r13d, %r13d
movl 0x14(%rsp), %esi
movq %rbx, %rdi
callq 0xe8a25
movq %rbx, %rdi
movq %r15, %rsi
callq 0xea50e
movq %rbp, %rdi
callq 0xf228d
movq 0x28(%r12), %rdi
callq 0xf6753
movq 0x30(%r12), %rdi
callq 0xf6753
movq %rbx, %rdi
movq %r12, %rsi
callq 0xe8be2
testb %r13b, %r13b
movq 0x38(%rsp), %rax
jne 0x63dd5
incq %rax
cmpq 0x8(%r14), %rax
jl 0x63e16
jmp 0x63dd5