// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/bmp.c
// Function: do_image_16_32bit
static void do_image_16_32bit(deark *c, lctx *d, dbuf *bits, i64 bits_offset)
{
	i64 i, j;
	int has_transparency;
	u32 v;
	i64 k;
	u8 sm[4];

	if(d->bitfields_type==BF_SEGMENT) {
		has_transparency = (d->bitfields_segment_len>=16 && d->bitfield[3].mask!=0);
	}
	else if(d->bitfields_type==BF_IN_HEADER) {
		has_transparency = (d->bitfield[3].mask!=0);
	}
	else {
		has_transparency = 0;
	}

	d->img = bmp_bitmap_create(c, d, has_transparency?4:3);
	for(j=0; j<d->height; j++) {
		for(i=0; i<d->pdwidth; i++) {
			if(d->bitcount==16) {
				v = (u32)dbuf_getu16le(bits, bits_offset + j*d->rowspan + 2*i);
			}
			else {
				v = (u32)dbuf_getu32le(bits, bits_offset + j*d->rowspan + 4*i);
			}

			for(k=0; k<4; k++) {
				if(d->bitfield[k].mask!=0) {
					sm[k] = (u8)(0.5 + d->bitfield[k].scale * (double)((v&d->bitfield[k].mask) >> d->bitfield[k].shift));
				}
				else {
					if(k==3)
						sm[k] = 255; // Default alpha sample = opaque
					else
						sm[k] = 0; // Default other samples = 0
				}
			}
			de_bitmap_setpixel_rgba(d->img, i, j, DE_MAKE_RGBA(sm[0], sm[1], sm[2], sm[3]));
		}
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq -0x10(%rbp), %rax
cmpl $0x2, 0x8c(%rax)
jne 0x45686
movq -0x10(%rbp), %rcx
xorl %eax, %eax
cmpq $0x10, 0x90(%rcx)
movb %al, -0x45(%rbp)
jl 0x45679
movq -0x10(%rbp), %rax
cmpl $0x0, 0x130(%rax)
setne %al
movb %al, -0x45(%rbp)
movb -0x45(%rbp), %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, -0x34(%rbp)
jmp 0x456b4
movq -0x10(%rbp), %rax
cmpl $0x3, 0x8c(%rax)
jne 0x456ab
movq -0x10(%rbp), %rax
cmpl $0x0, 0x130(%rax)
setne %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, -0x34(%rbp)
jmp 0x456b2
movl $0x0, -0x34(%rbp)
jmp 0x456b4
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movl -0x34(%rbp), %ecx
movl $0x3, %edx
movl $0x4, %eax
cmpl $0x0, %ecx
cmovnel %eax, %edx
callq 0x45f20
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x10(%rax)
movq $0x0, -0x30(%rbp)
movq -0x30(%rbp), %rax
movq -0x10(%rbp), %rcx
cmpq 0x60(%rcx), %rax
jge 0x4587f
movq $0x0, -0x28(%rbp)
movq -0x28(%rbp), %rax
movq -0x10(%rbp), %rcx
cmpq 0x58(%rcx), %rax
jge 0x4586c
movq -0x10(%rbp), %rax
cmpq $0x10, 0x38(%rax)
jne 0x4574d
movq -0x18(%rbp), %rdi
movq -0x20(%rbp), %rsi
movq -0x30(%rbp), %rax
movq -0x10(%rbp), %rcx
imulq 0xf8(%rcx), %rax
addq %rax, %rsi
movq -0x28(%rbp), %rax
shlq %rax
addq %rax, %rsi
callq 0x165280
movl %eax, -0x38(%rbp)
jmp 0x4577b
movq -0x18(%rbp), %rdi
movq -0x20(%rbp), %rsi
movq -0x30(%rbp), %rax
movq -0x10(%rbp), %rcx
imulq 0xf8(%rcx), %rax
addq %rax, %rsi
movq -0x28(%rbp), %rax
shlq $0x2, %rax
addq %rax, %rsi
callq 0x165540
movl %eax, -0x38(%rbp)
movq $0x0, -0x40(%rbp)
cmpq $0x4, -0x40(%rbp)
jge 0x45827
movq -0x10(%rbp), %rax
addq $0x100, %rax            # imm = 0x100
movq -0x40(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
cmpl $0x0, (%rax)
je 0x457f7
movq -0x10(%rbp), %rcx
movq -0x40(%rbp), %rdx
shlq $0x4, %rdx
movsd 0x108(%rcx,%rdx), %xmm0
movl -0x38(%rbp), %eax
movl 0x100(%rcx,%rdx), %esi
andl %esi, %eax
movb 0x104(%rcx,%rdx), %cl
shrl %cl, %eax
cvtsi2sd %rax, %xmm1
mulsd %xmm1, %xmm0
movsd 0x15de55(%rip), %xmm1   # 0x1a3638
addsd %xmm1, %xmm0
cvttsd2si %xmm0, %eax
movb %al, %cl
movq -0x40(%rbp), %rax
movb %cl, -0x44(%rbp,%rax)
jmp 0x45814
cmpq $0x3, -0x40(%rbp)
jne 0x45809
movq -0x40(%rbp), %rax
movb $-0x1, -0x44(%rbp,%rax)
jmp 0x45812
movq -0x40(%rbp), %rax
movb $0x0, -0x44(%rbp,%rax)
jmp 0x45814
jmp 0x45816
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
jmp 0x45783
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rdi
movq -0x28(%rbp), %rsi
movq -0x30(%rbp), %rdx
movzbl -0x41(%rbp), %ecx
shll $0x18, %ecx
movzbl -0x44(%rbp), %eax
shll $0x10, %eax
orl %eax, %ecx
movzbl -0x43(%rbp), %eax
shll $0x8, %eax
orl %eax, %ecx
movzbl -0x42(%rbp), %eax
orl %eax, %ecx
callq 0x16b350
movq -0x28(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x28(%rbp)
jmp 0x45701
jmp 0x4586e
movq -0x30(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x30(%rbp)
jmp 0x456e7
addq $0x50, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)