// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/bmi.c
// Function: do_header
static int do_header(deark *c, lctx *d, i64 pos1)
{
	i64 pos = pos1;
	int retval = 0;

	de_dbg(c, "header at %d", (int)pos1);
	de_dbg_indent(c, 1);

	pos += 9; // signature

	d->globalimg.w = de_getu16le_p(&pos);
	d->globalimg.h = de_getu16le_p(&pos);
	de_dbg_dimensions(c, d->globalimg.w, d->globalimg.h);

	d->globalimg.palmode = (unsigned int)de_getu16le_p(&pos);
	de_dbg(c, "palette mode: %u", d->globalimg.palmode);

	d->globalimg.bpp = de_getu16le_p(&pos);
	de_dbg(c, "bits/pixel: %d", (int)d->globalimg.bpp);

	if(d->globalimg.palmode && d->globalimg.bpp>=1 && d->globalimg.bpp<=8) {
		d->globalimg.num_pal_entries = de_pow2(d->globalimg.bpp);
	}

	pos += 2;

	d->num_table_items = de_getu16le_p(&pos);
	if(d->num_table_items>100) goto done;

	d->fixed_header_size = pos - pos1;
	retval = 1;

done:
	if(!retval) {
		de_err(c, "Error reading header");
	}
	de_dbg_indent(c, -1);
	return retval;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x20(%rbp)
movl $0x0, -0x24(%rbp)
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movl %eax, %edx
leaq 0x18300a(%rip), %rsi    # 0x1c4f8e
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movl $0x1, %esi
callq 0x15b560
movq -0x20(%rbp), %rax
addq $0x9, %rax
movq %rax, -0x20(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x20(%rbp), %rsi
callq 0x1652c0
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x20(%rax)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x20(%rbp), %rsi
callq 0x1652c0
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x28(%rax)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rsi
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rdx
callq 0x15bba0
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x20(%rbp), %rsi
callq 0x1652c0
movl %eax, %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x30(%rax)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movl 0x30(%rax), %edx
leaq 0x1613b1(%rip), %rsi    # 0x1a33d3
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x20(%rbp), %rsi
callq 0x1652c0
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x38(%rax)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rax
movl %eax, %edx
leaq 0x18fb9a(%rip), %rsi    # 0x1d1bf4
movb $0x0, %al
callq 0x15b0d0
movq -0x10(%rbp), %rax
cmpl $0x0, 0x30(%rax)
je 0x42099
movq -0x10(%rbp), %rax
cmpq $0x1, 0x38(%rax)
jl 0x42099
movq -0x10(%rbp), %rax
cmpq $0x8, 0x38(%rax)
jg 0x42099
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rdi
callq 0x15ce50
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x40(%rax)
movq -0x20(%rbp), %rax
addq $0x2, %rax
movq %rax, -0x20(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x20(%rbp), %rsi
callq 0x1652c0
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x10(%rbp), %rax
cmpq $0x64, 0x10(%rax)
jle 0x420ce
jmp 0x420e5
movq -0x20(%rbp), %rcx
subq -0x18(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x8(%rax)
movl $0x1, -0x24(%rbp)
cmpl $0x0, -0x24(%rbp)
jne 0x420fd
movq -0x8(%rbp), %rdi
leaq 0x1612ee(%rip), %rsi    # 0x1a33e4
movb $0x0, %al
callq 0x15bfb0
movq -0x8(%rbp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x15b560
movl -0x24(%rbp), %eax
addq $0x30, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)