// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq $0x0, -0x20(%rbp)
movq $0x0, -0x38(%rbp)
movq -0x8(%rbp), %rdi
leaq -0x3c(%rbp), %rsi
callq 0x15b580
movq -0x8(%rbp), %rdi
movl $0x438, %esi            # imm = 0x438
callq 0x15b780
movq %rax, -0x20(%rbp)
movq -0x8(%rbp), %rdi
leaq 0x180058(%rip), %rsi    # 0x19d2c2
callq 0x15e380
movq $0xa, -0x28(%rbp)
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rax
movl %eax, %edx
leaq 0x180051(%rip), %rsi    # 0x19d2d9
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movl $0x1, %esi
callq 0x15b560
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x28(%rbp), %rsi
callq 0x165280
movq %rax, %rcx
movq -0x20(%rbp), %rax
movq %rcx, (%rax)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x28(%rbp), %rsi
addq $0x2, %rsi
callq 0x165280
movq %rax, %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rax
movq (%rax), %rsi
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rdx
callq 0x15bba0
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rax
movq (%rax), %rsi
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rdx
callq 0x16a850
cmpl $0x0, %eax
jne 0x1d312
jmp 0x1d58f
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x28(%rbp), %rsi
addq $0x4, %rsi
callq 0x165280
movq %rax, %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rax
movq 0x18(%rax), %rax
movl %eax, %edx
leaq 0x1b48ad(%rip), %rsi    # 0x1d1bf4
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x28(%rbp), %rsi
addq $0x6, %rsi
callq 0x165280
movl %eax, -0x14(%rbp)
movl -0x14(%rbp), %ecx
andl $0x1, %ecx
movq -0x20(%rbp), %rax
movl %ecx, 0x20(%rax)
movl -0x14(%rbp), %ecx
shrl %ecx
andl $0x1, %ecx
movq -0x20(%rbp), %rax
movl %ecx, 0x24(%rax)
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rax
movl 0x20(%rax), %edx
leaq 0x17ff69(%rip), %rsi    # 0x19d2fd
movb $0x0, %al
callq 0x15b0d0
movq -0x20(%rbp), %rax
cmpl $0x0, 0x20(%rax)
je 0x1d3be
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rax
movl 0x24(%rax), %edx
leaq 0x17ff56(%rip), %rsi    # 0x19d30d
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x28(%rbp), %rsi
addq $0x8, %rsi
callq 0x165280
movq %rax, %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x28(%rax)
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rax
movq 0x28(%rax), %rax
movl %eax, %edx
leaq 0x190267(%rip), %rsi    # 0x1ad65a
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x15b560
movq -0x28(%rbp), %rax
addq $0x46, %rax
movq %rax, -0x28(%rbp)
movq -0x20(%rbp), %rax
cmpl $0x0, 0x20(%rax)
je 0x1d477
movq -0x20(%rbp), %rax
cmpl $0x0, 0x24(%rax)
je 0x1d44a
movq -0x20(%rbp), %rax
cmpq $0x8, 0x18(%rax)
jg 0x1d44a
movq -0x8(%rbp), %rdi
leaq 0x17fee2(%rip), %rsi    # 0x19d320
movb $0x0, %al
callq 0x15bfb0
jmp 0x1d58f
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rsi
movq -0x28(%rbp), %rdx
leaq -0x30(%rbp), %rcx
callq 0x1d630
cmpl $0x0, %eax
jne 0x1d469
jmp 0x1d58f
movq -0x30(%rbp), %rax
addq -0x28(%rbp), %rax
movq %rax, -0x28(%rbp)
jmp 0x1d49b
movq -0x20(%rbp), %rax
cmpq $0x8, 0x18(%rax)
jg 0x1d499
movq -0x8(%rbp), %rdi
leaq 0x17feb2(%rip), %rsi    # 0x19d33f
movb $0x0, %al
callq 0x15bfb0
jmp 0x1d58f
jmp 0x1d49b
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rax
movl %eax, %edx
leaq 0x1a4cfc(%rip), %rsi    # 0x1c21a8
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movl $0x1, %esi
callq 0x15b560
movq -0x20(%rbp), %rax
cmpq $0x0, 0x28(%rax)
je 0x1d501
movq -0x8(%rbp), %rdi
movl $0x8000, %esi           # imm = 0x8000
xorl %edx, %edx
callq 0x168020
movq %rax, -0x38(%rbp)
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rsi
movq -0x28(%rbp), %rdx
movq -0x38(%rbp), %rcx
callq 0x1d740
cmpl $0x0, %eax
jne 0x1d4ff
jmp 0x1d58f
jmp 0x1d526
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x28(%rbp), %rsi
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x18(%rax), %rdx
subq -0x28(%rbp), %rdx
callq 0x1691b0
movq %rax, -0x38(%rbp)
movq -0x20(%rbp), %rax
cmpq $0x1, 0x18(%rax)
je 0x1d570
movq -0x20(%rbp), %rax
cmpq $0x4, 0x18(%rax)
je 0x1d570
movq -0x20(%rbp), %rax
cmpq $0x8, 0x18(%rax)
je 0x1d570
movq -0x20(%rbp), %rax
cmpq $0x18, 0x18(%rax)
je 0x1d570
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rax
movq 0x18(%rax), %rax
movl %eax, %edx
leaq 0x17fe16(%rip), %rsi    # 0x19d37d
movb $0x0, %al
callq 0x15bfb0
jmp 0x1d58f
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rsi
movq -0x38(%rbp), %rdx
callq 0x1d8d0
movq -0x8(%rbp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x15b560
movq -0x8(%rbp), %rdi
movl -0x3c(%rbp), %esi
callq 0x15b5a0
movq -0x38(%rbp), %rdi
callq 0x1676a0
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rsi
callq 0x15b820
addq $0x40, %rsp
popq %rbp
retq
nopw (%rax,%rax)