// File: /workspace/github_c_makefile_star2_O3/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 0xe8a1c
movl $0x438, %esi            # imm = 0x438
movq %rbx, %rdi
callq 0xe8b2b
movq %rax, %r14
leaq 0xf670c(%rip), %rsi     # 0x1112e9
movq %rbx, %rdi
callq 0xeb125
leaq 0xf6714(%rip), %rsi     # 0x111300
xorl %r15d, %r15d
movq %rbx, %rdi
movl $0xa, %edx
xorl %eax, %eax
callq 0xe8617
movq %rbx, %rdi
movl $0x1, %esi
callq 0xe8a15
movq 0x18(%rbx), %rdi
movl $0xa, %esi
callq 0xeebc8
movq %rax, (%r14)
movq 0x18(%rbx), %rdi
movl $0xc, %esi
callq 0xeebc8
movq %rax, 0x8(%r14)
movq (%r14), %rsi
movq %rbx, %rdi
movq %rax, %rdx
callq 0xe8f88
movq (%r14), %rsi
movq 0x8(%r14), %rdx
movq %rbx, %rdi
callq 0xf1db1
testl %eax, %eax
je 0x1aff8
movq 0x18(%rbx), %rdi
movl $0xe, %esi
callq 0xeebc8
movq %rax, 0x18(%r14)
leaq 0x12b4c2(%rip), %rsi    # 0x14612e
movq %rbx, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xe8617
movq 0x18(%rbx), %rdi
movl $0x10, %esi
callq 0xeebc8
movl %eax, %edx
andl $0x1, %edx
movl %edx, 0x20(%r14)
shrl %eax
andl $0x1, %eax
movl %eax, 0x24(%r14)
leaq 0xf6685(%rip), %rsi     # 0x111324
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe8617
cmpl $0x0, 0x20(%r14)
je 0x1acc5
movl 0x24(%r14), %edx
leaq 0xf6679(%rip), %rsi     # 0x111334
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe8617
movq 0x18(%rbx), %rdi
movl $0x12, %esi
callq 0xeebc8
movq %rax, 0x28(%r14)
leaq 0x106dd3(%rip), %rsi    # 0x121ab1
movq %rbx, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xe8617
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0xe8a15
cmpl $0x0, 0x20(%r14)
je 0x1ad73
cmpl $0x0, 0x24(%r14)
je 0x1ad15
cmpq $0x8, 0x18(%r14)
jg 0x1ad15
leaq 0xf6634(%rip), %rsi     # 0x111347
jmp 0x1ad87
leaq 0x11574d(%rip), %rsi    # 0x130469
movq %rbx, %rdi
movl $0x50, %edx
xorl %eax, %eax
callq 0xe8617
movq %rbx, %rdi
movl $0x1, %esi
callq 0xe8a15
movq 0x18(%rbx), %rdi
movl $0x50, %esi
callq 0xeebc8
leaq 0x1(%rax), %rdx
movq %rdx, 0x30(%r14)
leaq 0xf666e(%rip), %rsi     # 0x1113c3
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe8617
cmpl $0x0, 0x24(%r14)
movq 0x30(%r14), %rdx
je 0x1ad99
addq %rdx, %rdx
leaq (%rdx,%rdx,2), %r12
jmp 0x1adc1
movl $0x50, %r12d
cmpq $0x8, 0x18(%r14)
jg 0x1add2
leaq 0xf65df(%rip), %rsi     # 0x111366
xorl %r15d, %r15d
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9295
jmp 0x1aff8
leaq (%rdx,%rdx,2), %r12
movq 0x18(%rbx), %rdi
leaq 0x38(%r14), %r8
movl $0x0, (%rsp)
movl $0x52, %esi
movl $0x3, %ecx
movl $0x100, %r9d            # imm = 0x100
callq 0xf2c4e
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0xe8a15
addq $0x52, %r12
leaq 0x11bacd(%rip), %rsi    # 0x1368a6
movq %rbx, %rdi
movl %r12d, %edx
xorl %eax, %eax
callq 0xe8617
movq %rbx, %rdi
movl $0x1, %esi
callq 0xe8a15
cmpq $0x0, 0x28(%r14)
je 0x1aef0
movl $0x8000, %esi           # imm = 0x8000
movq %rbx, %rdi
xorl %edx, %edx
callq 0xf09c5
movq %rax, %r15
leaq 0xf65c9(%rip), %rsi     # 0x1113e0
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe8617
leaq 0x20(%rsp), %r13
leaq 0x38(%rsp), %rbp
movq %rbx, %rdi
xorl %esi, %esi
movq %r13, %rdx
movq %rbp, %rcx
callq 0xfa1dc
movq %r15, 0x18(%rsp)
movq %r15, (%r13)
leaq 0xdf731(%rip), %rsi     # 0xfa57c
movq %rbx, %rdi
xorl %edx, %edx
movq %r13, %rcx
movq %rbp, %r8
callq 0xfa325
movq %rax, %r13
cmpq $0x0, 0x8(%r14)
movq %r12, 0x10(%rsp)
movq %r12, %rbp
jle 0x1aeb6
xorl %r12d, %r12d
movq 0x10(%rsp), %rbp
movq 0x18(%rbx), %rdi
movq %rbp, %rsi
callq 0xeebc8
movq %rax, %r15
leaq 0x2(%rbp), %rdx
movq 0x18(%rbx), %rsi
movq %r13, %rdi
movq %rax, %rcx
callq 0xfa404
movq %r13, %rdi
movl $0x1, %esi
xorl %edx, %edx
callq 0xfa3ab
addq %r15, %rbp
addq $0x2, %rbp
incq %r12
cmpq 0x8(%r14), %r12
jl 0x1ae75
movq %r13, %rdi
callq 0xfa3c8
cmpl $0x0, 0x38(%rsp)
je 0x1af08
leaq 0x38(%rsp), %rsi
movq %rbx, %rdi
callq 0xfa1a4
leaq 0xf9e86(%rip), %rsi     # 0x114d5f
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xe9295
movq 0x18(%rsp), %r15
jmp 0x1aff8
movq 0x18(%rbx), %rdi
movq 0x18(%rdi), %rdx
subq %r12, %rdx
movq %r12, %rsi
callq 0xf1388
movq %rax, %r15
jmp 0x1af30
subl 0x10(%rsp), %ebp
movq 0x18(%rsp), %r15
movl 0x18(%r15), %ecx
leaq 0xf64d9(%rip), %rsi     # 0x1113f5
movq %rbx, %rdi
movl %ebp, %edx
xorl %eax, %eax
callq 0xe8617
movq %r13, %rdi
callq 0xfa3d4
movq 0x18(%r14), %rdx
cmpq $0x18, %rdx
ja 0x1b029
movl $0x1000112, %eax        # imm = 0x1000112
btq %rdx, %rax
jae 0x1b029
movq (%r14), %rdi
imulq %rdx, %rdi
movl $0x8, %esi
callq 0xe9cb4
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 0xf26a5
movq %rax, %r13
movq 0x18(%r14), %rdx
cmpq $0x8, %rdx
jg 0x1afbc
movq %r14, %r8
addq $0x38, %r8
movl $0x0, (%rsp)
movq %r15, %rdi
xorl %esi, %esi
movq %r12, %rcx
movq %r13, %r9
callq 0xf2f79
jmp 0x1afd4
movl $0x3, %ecx
movq %r15, %rdi
xorl %esi, %esi
movq %r12, %rdx
movq %r13, %r8
xorl %r9d, %r9d
callq 0xf3279
movq %r13, %rdi
xorl %esi, %esi
movl $0x2, %edx
callq 0xf22dc
movq %r13, %rdi
callq 0xf228d
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0xe8a15
movl 0xc(%rsp), %esi
movq %rbx, %rdi
callq 0xe8a25
movq %r15, %rdi
callq 0xf052b
movq %rbx, %rdi
movq %r14, %rsi
callq 0xe8be2
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xf6374(%rip), %rsi     # 0x1113a4
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9295
jmp 0x1aff8