// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/misc2.c
// Function: de_run_pm_xv
static void de_run_pm_xv(deark *c, de_module_params *mparams)
{
	de_bitmap *img = NULL;
	int is_le;
	i64 width, height;
	i64 nplanes;
	i64 nbands;
	i64 pixelformat;
	i64 commentsize;
	i64 i, j;
	i64 plane;
	i64 rowspan;
	i64 planespan;
	i64 pos;
	u8 b;

	if(!dbuf_memcmp(c->infile, 0, "WEIV", 4))
		is_le = 1;
	else
		is_le = 0;

	nplanes = dbuf_geti32x(c->infile, 4, is_le);
	de_dbg(c, "planes: %d", (int)nplanes);

	height = dbuf_geti32x(c->infile, 8, is_le);
	width = dbuf_geti32x(c->infile, 12, is_le);
	de_dbg_dimensions(c, width, height);
	if(!de_good_image_dimensions(c, width, height)) goto done;

	nbands = dbuf_geti32x(c->infile, 16, is_le);
	de_dbg(c, "bands: %d", (int)nbands);

	pixelformat = dbuf_geti32x(c->infile, 20, is_le);
	de_dbg(c, "pixel format: 0x%04x", (unsigned int)pixelformat);

	commentsize = dbuf_geti32x(c->infile, 24, is_le);
	de_dbg(c, "comment size: %d", (int)commentsize);

	pos = 28;

	if((pixelformat==0x8001 && nplanes==3 && nbands==1) ||
		(pixelformat==0x8001 && nplanes==1 && nbands==1))
	{
		;
	}
	else {
		de_err(c, "Unsupported image type (pixel format=0x%04x, "
			"planes=%d, bands=%d)", (unsigned int)pixelformat,
			(int)nplanes, (int)nbands);
		goto done;
	}

	rowspan = width;
	planespan = rowspan*height;

	img = de_bitmap_create(c, width, height, (int)nplanes);

	for(plane=0; plane<nplanes; plane++) {
		for(j=0; j<height; j++) {
			for(i=0; i<width; i++) {
				b = de_getbyte(pos + plane*planespan + j*rowspan + i);
				if(nplanes==3) {
					de_bitmap_setsample(img, i, j, plane, b);
				}
				else {
					de_bitmap_setpixel_gray(img, i, j, b);
				}
			}
		}
	}
	de_bitmap_write_to_file(img, NULL, 0);

done:
	de_bitmap_destroy(img);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x90, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq $0x0, -0x18(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
xorl %eax, %eax
movl %eax, %esi
leaq 0x119dd4(%rip), %rdx    # 0x1b0932
movl $0x4, %ecx
callq 0x166ab0
cmpl $0x0, %eax
jne 0x96b76
movl $0x1, -0x1c(%rbp)
jmp 0x96b7d
movl $0x0, -0x1c(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movl -0x1c(%rbp), %edx
movl $0x4, %esi
callq 0x165910
movq %rax, -0x38(%rbp)
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rax
movl %eax, %edx
leaq 0x130158(%rip), %rsi    # 0x1c6cff
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movl -0x1c(%rbp), %edx
movl $0x8, %esi
callq 0x165910
movq %rax, -0x30(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movl -0x1c(%rbp), %edx
movl $0xc, %esi
callq 0x165910
movq %rax, -0x28(%rbp)
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rsi
movq -0x30(%rbp), %rdx
callq 0x15bba0
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rsi
movq -0x30(%rbp), %rdx
callq 0x16a850
cmpl $0x0, %eax
jne 0x96c0c
jmp 0x96e2e
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movl -0x1c(%rbp), %edx
movl $0x10, %esi
callq 0x165910
movq %rax, -0x40(%rbp)
movq -0x8(%rbp), %rdi
movq -0x40(%rbp), %rax
movl %eax, %edx
leaq 0x119d01(%rip), %rsi    # 0x1b0937
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movl -0x1c(%rbp), %edx
movl $0x14, %esi
callq 0x165910
movq %rax, -0x48(%rbp)
movq -0x8(%rbp), %rdi
movq -0x48(%rbp), %rax
movl %eax, %edx
leaq 0x119cda(%rip), %rsi    # 0x1b0941
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movl -0x1c(%rbp), %edx
movl $0x18, %esi
callq 0x165910
movq %rax, -0x50(%rbp)
movq -0x8(%rbp), %rdi
movq -0x50(%rbp), %rax
movl %eax, %edx
leaq 0x119cbe(%rip), %rsi    # 0x1b0956
movb $0x0, %al
callq 0x15b0d0
movq $0x1c, -0x80(%rbp)
cmpq $0x8001, -0x48(%rbp)    # imm = 0x8001
jne 0x96cbf
cmpq $0x3, -0x38(%rbp)
jne 0x96cbf
cmpq $0x1, -0x40(%rbp)
je 0x96cd7
cmpq $0x8001, -0x48(%rbp)    # imm = 0x8001
jne 0x96cd9
cmpq $0x1, -0x38(%rbp)
jne 0x96cd9
cmpq $0x1, -0x40(%rbp)
jne 0x96cd9
jmp 0x96d03
movq -0x8(%rbp), %rdi
movq -0x48(%rbp), %rax
movl %eax, %edx
movq -0x38(%rbp), %rax
movl %eax, %ecx
movq -0x40(%rbp), %rax
movl %eax, %r8d
leaq 0x119c70(%rip), %rsi    # 0x1b0967
movb $0x0, %al
callq 0x15bfb0
jmp 0x96e2e
movq -0x28(%rbp), %rax
movq %rax, -0x70(%rbp)
movq -0x70(%rbp), %rax
imulq -0x30(%rbp), %rax
movq %rax, -0x78(%rbp)
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rsi
movq -0x30(%rbp), %rdx
movq -0x38(%rbp), %rax
movl %eax, %ecx
callq 0x16b750
movq %rax, -0x18(%rbp)
movq $0x0, -0x68(%rbp)
movq -0x68(%rbp), %rax
cmpq -0x38(%rbp), %rax
jge 0x96e1f
movq $0x0, -0x60(%rbp)
movq -0x60(%rbp), %rax
cmpq -0x30(%rbp), %rax
jge 0x96e0c
movq $0x0, -0x58(%rbp)
movq -0x58(%rbp), %rax
cmpq -0x28(%rbp), %rax
jge 0x96df9
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x80(%rbp), %rsi
movq -0x68(%rbp), %rax
imulq -0x78(%rbp), %rax
addq %rax, %rsi
movq -0x60(%rbp), %rax
imulq -0x70(%rbp), %rax
addq %rax, %rsi
addq -0x58(%rbp), %rsi
callq 0x165060
movb %al, -0x81(%rbp)
cmpq $0x3, -0x38(%rbp)
jne 0x96dce
movq -0x18(%rbp), %rdi
movq -0x58(%rbp), %rsi
movq -0x60(%rbp), %rdx
movq -0x68(%rbp), %rcx
movzbl -0x81(%rbp), %r8d
callq 0x16b060
jmp 0x96de6
movq -0x18(%rbp), %rdi
movq -0x58(%rbp), %rsi
movq -0x60(%rbp), %rdx
movzbl -0x81(%rbp), %ecx
callq 0x16b1c0
jmp 0x96de8
movq -0x58(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x58(%rbp)
jmp 0x96d67
jmp 0x96dfb
movq -0x60(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x60(%rbp)
jmp 0x96d51
jmp 0x96e0e
movq -0x68(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x68(%rbp)
jmp 0x96d3b
movq -0x18(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
xorl %edx, %edx
callq 0x16afd0
movq -0x18(%rbp), %rdi
callq 0x16af60
addq $0x90, %rsp
popq %rbp
retq