// File: /workspace/github_c_makefile_star2_O2/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 $0xa8, %rsp
movq %rdi, %rbx
leaq 0x14(%rsp), %rsi
callq 0xdebae
movl $0x438, %esi            # imm = 0x438
movq %rbx, %rdi
callq 0xdecaf
movq %rax, %r12
leaq 0xe99b9(%rip), %rsi     # 0x1042c6
movq %rbx, %rdi
callq 0xe07f7
leaq 0xe99c1(%rip), %rsi     # 0x1042dd
xorl %r14d, %r14d
pushq $0xa
popq %rdx
movq %rbx, %rdi
xorl %eax, %eax
callq 0xde896
pushq $0x1
popq %rsi
movq %rbx, %rdi
callq 0xdeba7
movq 0x18(%rbx), %rdi
pushq $0xa
popq %rsi
callq 0xe3fa3
movq %rax, (%r12)
movq 0x18(%rbx), %rdi
pushq $0xc
popq %rsi
callq 0xe3fa3
movq %rax, 0x8(%r12)
movq (%r12), %rsi
movq %rbx, %rdi
movq %rax, %rdx
callq 0xdf038
movq (%r12), %rsi
movq 0x8(%r12), %rdx
movq %rbx, %rdi
callq 0xe6be1
testl %eax, %eax
je 0x1ad1d
movq 0x18(%rbx), %rdi
pushq $0xe
popq %rsi
callq 0xe3fa3
movq %rax, 0x18(%r12)
leaq 0x11e346(%rip), %rsi    # 0x138cde
movq %rbx, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xde896
movq 0x18(%rbx), %rdi
pushq $0x10
popq %rsi
callq 0xe3fa3
movl %eax, %edx
andl $0x1, %edx
movl %edx, 0x20(%r12)
shrl %eax
andl $0x1, %eax
movl %eax, 0x24(%r12)
leaq 0xe9936(%rip), %rsi     # 0x104301
movq %rbx, %rdi
xorl %eax, %eax
callq 0xde896
cmpl $0x0, 0x20(%r12)
je 0x1a9f3
movl 0x24(%r12), %edx
leaq 0xe9928(%rip), %rsi     # 0x104311
movq %rbx, %rdi
xorl %eax, %eax
callq 0xde896
movq 0x18(%rbx), %rdi
pushq $0x12
popq %rsi
callq 0xe3fa3
movq %rax, 0x28(%r12)
leaq 0xf9fb6(%rip), %rsi     # 0x1149c1
movq %rbx, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xde896
pushq $-0x1
popq %rsi
movq %rbx, %rdi
callq 0xdeba7
cmpl $0x0, 0x20(%r12)
je 0x1aa9b
cmpl $0x0, 0x24(%r12)
je 0x1aa43
cmpq $0x8, 0x18(%r12)
jg 0x1aa43
leaq 0xe98e3(%rip), %rsi     # 0x104324
jmp 0x1aaaa
leaq 0x10877e(%rip), %rsi    # 0x1231c8
pushq $0x50
popq %rdx
movq %rbx, %rdi
xorl %eax, %eax
callq 0xde896
pushq $0x1
popq %rsi
movq %rbx, %rdi
callq 0xdeba7
movq 0x18(%rbx), %rdi
pushq $0x50
popq %rsi
callq 0xe3fa3
leaq 0x1(%rax), %rdx
movq %rdx, 0x30(%r12)
leaq 0xe9922(%rip), %rsi     # 0x1043a0
movq %rbx, %rdi
xorl %eax, %eax
callq 0xde896
cmpl $0x0, 0x24(%r12)
movq 0x30(%r12), %rdx
je 0x1aac2
imulq $0x6, %rdx, %r15
jmp 0x1aae4
cmpq $0x8, 0x18(%r12)
jg 0x1aabc
leaq 0xe9899(%rip), %rsi     # 0x104343
xorl %r14d, %r14d
movq %rbx, %rdi
xorl %eax, %eax
callq 0xdf2a5
jmp 0x1ad1d
pushq $0x50
popq %r15
jmp 0x1aaf3
leaq (%rdx,%rdx,2), %r15
movq 0x18(%rbx), %rdi
leaq 0x38(%r12), %r8
andl $0x0, (%rsp)
pushq $0x52
popq %rsi
pushq $0x3
popq %rcx
movl $0x100, %r9d            # imm = 0x100
callq 0xe7963
pushq $-0x1
popq %rsi
movq %rbx, %rdi
callq 0xdeba7
addq $0x52, %r15
leaq 0x10eaac(%rip), %rsi    # 0x1295a6
movq %rbx, %rdi
movl %r15d, %edx
xorl %eax, %eax
callq 0xde896
pushq $0x1
popq %rsi
movq %rbx, %rdi
callq 0xdeba7
cmpq $0x0, 0x28(%r12)
movq %r12, 0x28(%rsp)
je 0x1ac14
xorl %r14d, %r14d
movl $0x8000, %esi           # imm = 0x8000
movq %rbx, %rdi
xorl %edx, %edx
callq 0xe59cd
movq %r15, 0x20(%rsp)
movq %rax, %rbp
leaq 0xe9879(%rip), %rsi     # 0x1043bd
movq %rbx, %rdi
xorl %eax, %eax
callq 0xde896
leaq 0x30(%rsp), %r15
leaq 0x48(%rsp), %r13
movq %rbx, %rdi
xorl %esi, %esi
movq %r15, %rdx
movq %r13, %rcx
callq 0xee7ee
movq %rbp, 0x18(%rsp)
movq %rbp, (%r15)
leaq 0xd3f84(%rip), %rsi     # 0xeeafb
movq %rbx, %rdi
xorl %edx, %edx
movq %r15, %rcx
movq %r13, %r8
callq 0xee930
movq %rax, %r13
pushq $0x1
popq %r15
movq 0x20(%rsp), %rbp
cmpq 0x8(%r12), %r14
jge 0x1abda
movq 0x18(%rbx), %rdi
movq %rbp, %rsi
callq 0xe3fa3
movq %rax, %r12
leaq 0x2(%rbp), %rdx
movq 0x18(%rbx), %rsi
movq %r13, %rdi
movq %rax, %rcx
callq 0xeea0d
movq %r13, %rdi
movl %r15d, %esi
xorl %edx, %edx
callq 0xee9b4
addq %r12, %rbp
addq $0x2, %rbp
movq 0x28(%rsp), %r12
incq %r14
jmp 0x1ab93
movq %r13, %rdi
callq 0xee9d1
cmpl $0x0, 0x48(%rsp)
je 0x1ac2c
leaq 0x48(%rsp), %rsi
movq %rbx, %rdi
callq 0xee7bc
leaq 0xed102(%rip), %rsi     # 0x107cff
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xdf2a5
movq 0x18(%rsp), %r14
jmp 0x1ad1d
movq 0x18(%rbx), %rdi
movq 0x18(%rdi), %rdx
subq %r15, %rdx
movq %r15, %rsi
callq 0xe6248
movq %rax, %r14
jmp 0x1ac54
subl 0x20(%rsp), %ebp
movq 0x18(%rsp), %r14
movl 0x18(%r14), %ecx
leaq 0xe9792(%rip), %rsi     # 0x1043d2
movq %rbx, %rdi
movl %ebp, %edx
xorl %eax, %eax
callq 0xde896
movq %r13, %rdi
callq 0xee9dd
movq 0x18(%r12), %rdx
cmpq $0x18, %rdx
ja 0x1ad4e
movl $0x1000112, %eax        # imm = 0x1000112
btq %rdx, %rax
jae 0x1ad4e
movq (%r12), %rdi
imulq %rdx, %rdi
pushq $0x8
popq %r15
movq %r15, %rsi
callq 0xdfbb6
movq %rax, %rcx
cqto
idivq %r15
movq %rax, %r13
movq %rcx, %rax
cqto
idivq 0x18(%r12)
movq %rax, 0x10(%r12)
movq (%r12), %rsi
movq 0x8(%r12), %rcx
pushq $0x3
popq %r8
movq %rbx, %rdi
movq %rax, %rdx
callq 0xe746f
movq %r12, %r8
movq %rax, %r12
movq 0x18(%r8), %rdx
cmpq $0x8, %rdx
jg 0x1ace2
addq $0x38, %r8
andl $0x0, (%rsp)
movq %r14, %rdi
xorl %esi, %esi
movq %r13, %rcx
movq %r12, %r9
callq 0xe7cbc
jmp 0x1acf8
pushq $0x3
popq %rcx
movq %r14, %rdi
xorl %esi, %esi
movq %r13, %rdx
movq %r12, %r8
xorl %r9d, %r9d
callq 0xe7f67
pushq $0x2
popq %rdx
movq %r12, %rdi
xorl %esi, %esi
callq 0xe70b7
movq %r12, %rdi
callq 0xe7084
pushq $-0x1
popq %rsi
movq %rbx, %rdi
callq 0xdeba7
movq 0x28(%rsp), %r12
movl 0x14(%rsp), %esi
movq %rbx, %rdi
callq 0xdebb7
movq %r14, %rdi
callq 0xe5591
movq %rbx, %rdi
movq %r12, %rsi
callq 0xded32
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xe962c(%rip), %rsi     # 0x104381
movq %rbx, %rdi
xorl %eax, %eax
callq 0xdf2a5
jmp 0x1ad1d