// File: /workspace/github_c_makefile_star2_O1/jsummers[P]deark/modules/alphabmp.c
// Function: de_run_alphabmp
static void de_run_alphabmp(deark *c, de_module_params *mparams)
{
	unsigned int flags;
	lctx *d = NULL;
	i64 pos;
	i64 palsize;
	dbuf *unc_pixels = NULL;
	int saved_indent_level;

	de_dbg_indent_save(c, &saved_indent_level);

	d = de_malloc(c, sizeof(lctx));
	de_declare_fmt(c, "Alpha Microsystems BMP");

	pos = 10;

	de_dbg(c, "bitmap image definition block at %d", (int)pos);
	de_dbg_indent(c, 1);

	d->npwidth = de_getu16le(pos);
	d->h = de_getu16le(pos+2);
	de_dbg_dimensions(c, d->npwidth, d->h);
	if(!de_good_image_dimensions(c, d->npwidth, d->h)) goto done;

	d->bpp = de_getu16le(pos+4);
	de_dbg(c, "bits/pixel: %d", (int)d->bpp);

	flags = (unsigned int)de_getu16le(pos+6);
	d->has_palette = flags & 0x01;
	d->palette_is_hls = (flags>>1) & 0x01;
	de_dbg(c, "has-palette: %d", (int)d->has_palette);
	if(d->has_palette)
		de_dbg(c, "palette-is-HLS: %d", (int)d->palette_is_hls);

	d->compression = de_getu16le(pos+8);
	de_dbg(c, "compression: %d", (int)d->compression);
	de_dbg_indent(c, -1);

	pos += 70;

	if(d->has_palette) {
		if(d->palette_is_hls && d->bpp<=8) {
			de_err(c, "HLS palettes are not supported");
			goto done;
		}
		if(!do_read_palette(c, d, pos, &palsize)) goto done;
		pos += palsize;
	}
	else if(d->bpp<=8) {
		de_err(c, "Paletted images without an embedded palette are not supported");
		goto done;
	}

	de_dbg(c, "bitmap at %d", (int)pos);
	de_dbg_indent(c, 1);

	if(d->compression) {
		unc_pixels = dbuf_create_membuf(c, 32768, 0);
		if(!do_uncompress_image(c, d, pos, unc_pixels)) goto done;
	}
	else {
		unc_pixels = dbuf_open_input_subfile(c->infile, pos, c->infile->len - pos);
	}

	if(d->bpp!=1 && d->bpp!=4 && d->bpp!=8 && d->bpp!=24) {
		de_err(c, "%d bits/pixel is not supported", (int)d->bpp);
		goto done;
	}

	do_bitmap(c, d, unc_pixels);
	de_dbg_indent(c, -1);

done:
	de_dbg_indent_restore(c, saved_indent_level);
	dbuf_close(unc_pixels);
	de_free(c, d);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x98, %rsp
movq %rdi, %rbx
leaq 0xc(%rsp), %rsi
callq 0xe958c
movl $0x438, %esi            # imm = 0x438
movq %rbx, %rdi
callq 0xe969b
movq %rax, %r14
leaq 0xf6821(%rip), %rsi     # 0x1112da
movq %rbx, %rdi
callq 0xeb6d6
leaq 0xf6829(%rip), %rsi     # 0x1112f1
xorl %r15d, %r15d
movq %rbx, %rdi
movl $0xa, %edx
xorl %eax, %eax
callq 0xe9226
movq %rbx, %rdi
movl $0x1, %esi
callq 0xe9585
movq 0x18(%rbx), %rdi
movl $0xa, %esi
callq 0xef1ca
movq %rax, (%r14)
movq 0x18(%rbx), %rdi
movl $0xc, %esi
callq 0xef1ca
movq %rax, 0x8(%r14)
movq (%r14), %rsi
movq %rbx, %rdi
movq %rax, %rdx
callq 0xe9b05
movq (%r14), %rsi
movq 0x8(%r14), %rdx
movq %rbx, %rdi
callq 0xf241d
testl %eax, %eax
je 0x1aeed
movq 0x18(%rbx), %rdi
movl $0xe, %esi
callq 0xef1ca
movq %rax, 0x18(%r14)
leaq 0x12b0fc(%rip), %rsi    # 0x145c44
movq %rbx, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xe9226
movq 0x18(%rbx), %rdi
movl $0x10, %esi
callq 0xef1ca
movl %eax, %edx
andl $0x1, %edx
movl %edx, 0x20(%r14)
shrl %eax
andl $0x1, %eax
movl %eax, 0x24(%r14)
leaq 0xf679a(%rip), %rsi     # 0x111315
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9226
cmpl $0x0, 0x20(%r14)
je 0x1aba1
movl 0x24(%r14), %edx
leaq 0xf678e(%rip), %rsi     # 0x111325
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9226
movq 0x18(%rbx), %rdi
movl $0x12, %esi
callq 0xef1ca
movq %rax, 0x28(%r14)
leaq 0x106deb(%rip), %rsi    # 0x1219a5
movq %rbx, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xe9226
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0xe9585
cmpl $0x0, 0x20(%r14)
je 0x1ac99
cmpl $0x0, 0x24(%r14)
je 0x1abf8
cmpq $0x8, 0x18(%r14)
jg 0x1abf8
leaq 0xf6745(%rip), %rsi     # 0x111338
jmp 0x1acad
leaq 0x115571(%rip), %rsi    # 0x130170
movq %rbx, %rdi
movl $0x50, %edx
xorl %eax, %eax
callq 0xe9226
movq %rbx, %rdi
movl $0x1, %esi
callq 0xe9585
movq 0x18(%rbx), %rdi
movl $0x50, %esi
callq 0xef1ca
leaq 0x1(%rax), %rdx
movq %rdx, 0x30(%r14)
leaq 0xf677c(%rip), %rsi     # 0x1113b4
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9226
movl 0x24(%r14), %eax
xorl %ecx, %ecx
testl %eax, %eax
setne %cl
leaq (%rcx,%rcx,2), %r12
addq $0x3, %r12
imulq 0x30(%r14), %r12
testl %eax, %eax
jne 0x1ac86
movq 0x18(%rbx), %rdi
movq 0x30(%r14), %rdx
leaq 0x38(%r14), %r8
movl $0x0, (%rsp)
movl $0x52, %esi
movl $0x3, %ecx
movl $0x100, %r9d            # imm = 0x100
callq 0xf328f
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0xe9585
addq $0x52, %r12
jmp 0x1acbf
movl $0x50, %r12d
cmpq $0x8, 0x18(%r14)
jg 0x1acbf
leaq 0xf66aa(%rip), %rsi     # 0x111357
xorl %r15d, %r15d
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9df7
jmp 0x1aeed
leaq 0x11b816(%rip), %rsi    # 0x1364dc
movq %rbx, %rdi
movl %r12d, %edx
xorl %eax, %eax
callq 0xe9226
movq %rbx, %rdi
movl $0x1, %esi
callq 0xe9585
cmpq $0x0, 0x28(%r14)
je 0x1add8
movl $0x8000, %esi           # imm = 0x8000
movq %rbx, %rdi
xorl %edx, %edx
callq 0xf0faf
movq %rax, %r15
leaq 0xf66cd(%rip), %rsi     # 0x1113d1
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9226
leaq 0x20(%rsp), %r13
leaq 0x38(%rsp), %rbp
movq %rbx, %rdi
xorl %esi, %esi
movq %r13, %rdx
movq %rbp, %rcx
callq 0xfa6e0
movq %r15, 0x18(%rsp)
movq %r15, (%r13)
leaq 0xdfd3c(%rip), %rsi     # 0xfaa74
movq %rbx, %rdi
xorl %edx, %edx
movq %r13, %rcx
movq %rbp, %r8
callq 0xfa829
movq %rax, %r13
cmpq $0x0, 0x8(%r14)
movq %r12, 0x10(%rsp)
movq %r12, %rbp
jle 0x1ada3
xorl %r12d, %r12d
movq 0x10(%rsp), %rbp
movq 0x18(%rbx), %rdi
movq %rbp, %rsi
callq 0xef1ca
movq %rax, %r15
leaq 0x2(%rbp), %rdx
movq 0x18(%rbx), %rsi
movq %r13, %rdi
movq %rax, %rcx
callq 0xfa908
movq %r13, %rdi
movl $0x1, %esi
xorl %edx, %edx
callq 0xfa8af
addq %r15, %rbp
addq $0x2, %rbp
incq %r12
cmpq 0x8(%r14), %r12
jl 0x1ad62
movq %r13, %rdi
callq 0xfa8cc
movl 0x38(%rsp), %r15d
testl %r15d, %r15d
je 0x1adf0
leaq 0x38(%rsp), %rsi
movq %rbx, %rdi
callq 0xfa6a8
leaq 0xf9ee6(%rip), %rsi     # 0x114caf
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xe9df7
jmp 0x1ae17
movq 0x18(%rbx), %rdi
movq 0x18(%rdi), %rdx
subq %r12, %rdx
movq %r12, %rsi
callq 0xf1988
movq %rax, %r15
jmp 0x1ae25
subl 0x10(%rsp), %ebp
movq 0x18(%rsp), %rax
movl 0x18(%rax), %ecx
leaq 0xf65e3(%rip), %rsi     # 0x1113e6
movq %rbx, %rdi
movl %ebp, %edx
xorl %eax, %eax
callq 0xe9226
movq %r13, %rdi
callq 0xfa8d8
testl %r15d, %r15d
movq 0x18(%rsp), %r15
jne 0x1aeed
movq 0x18(%r14), %rdx
cmpq $0x18, %rdx
ja 0x1af1e
movl $0x1000112, %eax        # imm = 0x1000112
btq %rdx, %rax
jae 0x1af1e
movq (%r14), %rdi
imulq %rdx, %rdi
movl $0x8, %esi
callq 0xea80b
leaq 0x7(%rax), %r12
testq %rax, %rax
cmovnsq %rax, %r12
sarq $0x3, %r12
cqto
idivq 0x18(%r14)
movq %rax, 0x10(%r14)
movq (%r14), %rsi
movq 0x8(%r14), %rcx
movq %rbx, %rdi
movq %rax, %rdx
movl $0x3, %r8d
callq 0xf2ce6
movq %rax, %r13
movq 0x18(%r14), %rdx
cmpq $0x8, %rdx
jg 0x1aeb1
movq %r14, %r8
addq $0x38, %r8
movl $0x0, (%rsp)
movq %r15, %rdi
xorl %esi, %esi
movq %r12, %rcx
movq %r13, %r9
callq 0xf35b8
jmp 0x1aec9
movl $0x3, %ecx
movq %r15, %rdi
xorl %esi, %esi
movq %r12, %rdx
movq %r13, %r8
xorl %r9d, %r9d
callq 0xf38d9
movq %r13, %rdi
xorl %esi, %esi
movl $0x2, %edx
callq 0xf2923
movq %r13, %rdi
callq 0xf28d4
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0xe9585
movl 0xc(%rsp), %esi
movq %rbx, %rdi
callq 0xe9595
movq %r15, %rdi
callq 0xf0b13
movq %rbx, %rdi
movq %r14, %rsi
callq 0xe9752
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xf6470(%rip), %rsi     # 0x111395
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9df7
jmp 0x1aeed