// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/xwd.c
// Function: read_image_rgb
static void read_image_rgb(deark *c, lctx *d, dbuf *inf, i64 inf_pos1,
	de_bitmap *img)
{
	i64 i, j;

	for(j=0; j<d->height; j++) {
		i64 rowpos;

		rowpos = inf_pos1 + j*d->rowspan;

		for(i=0; i<d->width; i++) {
			de_color clr = 0;
			u32 v;
			u32 cs[3];
			UI k;

			if(d->bytes_per_pixel==4) {
				v = (u32)dbuf_getu32x(inf, rowpos+i*d->bytes_per_pixel, d->pixel_byte_order);
			}
			else {
				v = (u32)dbuf_getint_ext(inf, rowpos+i*d->bytes_per_pixel,
					(UI)d->bytes_per_pixel, d->pixel_byte_order, 0);
			}
			for(k=0; k<3; k++) {
				UI v2;

				v2 = v & d->hf[HF_RMASK+k];
				v2 = v2 >> d->sample_bit_shift[k];

				if(d->sample_maxval[k]==255) {
					cs[k] = (u8)v2;
				}
				else {
					cs[k] = de_scale_n_to_255(d->sample_maxval[k], v2);
				}
			}
			clr = DE_MAKE_RGB(cs[0], cs[1], cs[2]);
			de_bitmap_setpixel_rgb(img, i, j, clr);
		}
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movq $0x0, -0x38(%rbp)
movq -0x38(%rbp), %rax
movq -0x10(%rbp), %rcx
cmpq 0xc0(%rcx), %rax
jge 0x15a7f7
movq -0x20(%rbp), %rax
movq -0x38(%rbp), %rcx
movq -0x10(%rbp), %rdx
imulq 0xc8(%rdx), %rcx
addq %rcx, %rax
movq %rax, -0x40(%rbp)
movq $0x0, -0x30(%rbp)
movq -0x30(%rbp), %rax
movq -0x10(%rbp), %rcx
cmpq 0xb8(%rcx), %rax
jge 0x15a7e4
movl $0x0, -0x44(%rbp)
movq -0x10(%rbp), %rax
cmpq $0x4, 0xa8(%rax)
jne 0x15a6d5
movq -0x18(%rbp), %rdi
movq -0x40(%rbp), %rsi
movq -0x30(%rbp), %rax
movq -0x10(%rbp), %rcx
imulq 0xa8(%rcx), %rax
addq %rax, %rsi
movq -0x10(%rbp), %rax
movl 0xa0(%rax), %edx
callq 0x1658c0
movl %eax, -0x48(%rbp)
jmp 0x15a712
movq -0x18(%rbp), %rdi
movq -0x40(%rbp), %rsi
movq -0x30(%rbp), %rax
movq -0x10(%rbp), %rcx
imulq 0xa8(%rcx), %rax
addq %rax, %rsi
movq -0x10(%rbp), %rax
movq 0xa8(%rax), %rax
movl %eax, %edx
movq -0x10(%rbp), %rax
movl 0xa0(%rax), %ecx
xorl %r8d, %r8d
callq 0x165a80
movl %eax, -0x48(%rbp)
movl $0x0, -0x58(%rbp)
cmpl $0x3, -0x58(%rbp)
jae 0x15a7a6
movl -0x48(%rbp), %eax
movq -0x10(%rbp), %rcx
movl -0x58(%rbp), %edx
addl $0xe, %edx
movl %edx, %edx
andl 0x4(%rcx,%rdx,4), %eax
movl %eax, -0x5c(%rbp)
movl -0x5c(%rbp), %eax
movq -0x10(%rbp), %rcx
movl -0x58(%rbp), %edx
movl 0xe0(%rcx,%rdx,4), %ecx
shrl %cl, %eax
movl %eax, -0x5c(%rbp)
movq -0x10(%rbp), %rax
movl -0x58(%rbp), %ecx
cmpq $0xff, 0xf0(%rax,%rcx,8)
jne 0x15a773
movl -0x5c(%rbp), %eax
movzbl %al, %ecx
movl -0x58(%rbp), %eax
movl %ecx, -0x54(%rbp,%rax,4)
jmp 0x15a796
movq -0x10(%rbp), %rax
movl -0x58(%rbp), %ecx
movq 0xf0(%rax,%rcx,8), %rdi
movl -0x5c(%rbp), %eax
movl %eax, %esi
callq 0x1617b0
movzbl %al, %ecx
movl -0x58(%rbp), %eax
movl %ecx, -0x54(%rbp,%rax,4)
jmp 0x15a798
movl -0x58(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x58(%rbp)
jmp 0x15a719
movl -0x54(%rbp), %eax
shll $0x10, %eax
orl $0xff000000, %eax       # imm = 0xFF000000
movl -0x50(%rbp), %ecx
shll $0x8, %ecx
orl %ecx, %eax
orl -0x4c(%rbp), %eax
movl %eax, -0x44(%rbp)
movq -0x28(%rbp), %rdi
movq -0x30(%rbp), %rsi
movq -0x38(%rbp), %rdx
movl -0x44(%rbp), %ecx
callq 0x16b310
movq -0x30(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x30(%rbp)
jmp 0x15a67c
jmp 0x15a7e6
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0x15a644
addq $0x60, %rsp
popq %rbp
retq
nopl (%rax)