// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/wmf.c
// Function: wmf_handler_BITBLT_STRETCHBLT_DIBBITBLT
static int wmf_handler_BITBLT_STRETCHBLT_DIBBITBLT(deark *c, lctx *d, struct decoder_params *dp)
{
	i64 pos = dp->dpos;
	int has_src_bitmap;
	unsigned int RasterOperation;
	i64 XSrc, YSrc;
	i64 Width, Height;
	i64 YDest, XDest;

	has_src_bitmap = (dp->recsize_words != ((i64)(dp->recfunc>>8)+3));
	de_dbg(c, "has src bitmap: %d", has_src_bitmap);
	if(!has_src_bitmap) goto done;

	RasterOperation = (unsigned int)de_getu32le(pos);
	de_dbg(c, "RasterOperation: 0x%08x", RasterOperation);
	pos += 4;

	if(dp->rectype==0x23) { // STRETCHBLT
		i64 SrcWidth, SrcHeight;
		SrcHeight = de_geti16le_p(&pos);
		SrcWidth = de_geti16le_p(&pos);
		de_dbg(c, "SrcWidth, SrcHeight: %d"DE_CHAR_TIMES"%d",
			(int)SrcWidth, (int)SrcHeight);
	}

	YSrc = de_geti16le_p(&pos);
	XSrc = de_geti16le_p(&pos);
	de_dbg(c, "XSrc, YSrc: (%d, %d)", (int)XSrc, (int)YSrc);

	Height = de_geti16le_p(&pos);
	Width = de_geti16le_p(&pos);
	de_dbg_dimensions(c, Width, Height);

	YDest = de_geti16le_p(&pos);
	XDest = de_geti16le_p(&pos);
	de_dbg(c, "XDest, YDest: (%d, %d)", (int)XDest, (int)YDest);

	// TODO: Bitmap16 object (if BITBLT or STRETCHBLT)
	if(dp->rectype==0x40) { // DIBBITBLT
		i64 dib_pos, dib_len;

		// TODO: Merge this with the DIBSTRETCHBLT, STRETCHDIB code.
		dib_pos = pos;
		dib_len = dp->dpos + dp->dlen - dib_pos;

		if(dib_len<12) goto done;
		de_dbg(c, "DIB at %d, size=%d", (int)dib_pos, (int)dib_len);

		de_dbg_indent(c, 1);
		de_run_module_by_id_on_slice(c, "dib", NULL, c->infile, dib_pos, dib_len);
		de_dbg_indent(c, -1);
	}

done:
	return 1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x80, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x18(%rbp), %rax
movq 0x20(%rax), %rax
movq %rax, -0x20(%rbp)
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x18(%rbp), %rcx
movzwl (%rcx), %ecx
sarl $0x8, %ecx
movslq %ecx, %rcx
addq $0x3, %rcx
cmpq %rcx, %rax
setne %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, -0x24(%rbp)
movq -0x8(%rbp), %rdi
movl -0x24(%rbp), %edx
leaq 0x92f3b(%rip), %rsi     # 0x1cc763
movb $0x0, %al
callq 0x15b0d0
cmpl $0x0, -0x24(%rbp)
jne 0x13983a
jmp 0x139a29
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x20(%rbp), %rsi
callq 0x165540
movl %eax, -0x28(%rbp)
movq -0x8(%rbp), %rdi
movl -0x28(%rbp), %edx
leaq 0x92f1a(%rip), %rsi     # 0x1cc776
movb $0x0, %al
callq 0x15b0d0
movq -0x20(%rbp), %rax
addq $0x4, %rax
movq %rax, -0x20(%rbp)
movq -0x18(%rbp), %rax
movzbl 0x2(%rax), %eax
cmpl $0x23, %eax
jne 0x1398c4
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x20(%rbp), %rsi
callq 0x1653f0
movq %rax, -0x68(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x20(%rbp), %rsi
callq 0x1653f0
movq %rax, -0x60(%rbp)
movq -0x8(%rbp), %rdi
movq -0x60(%rbp), %rax
movl %eax, %edx
movq -0x68(%rbp), %rax
movl %eax, %ecx
leaq 0x92ed1(%rip), %rsi     # 0x1cc78e
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x20(%rbp), %rsi
callq 0x1653f0
movq %rax, -0x38(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x20(%rbp), %rsi
callq 0x1653f0
movq %rax, -0x30(%rbp)
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rax
movl %eax, %edx
movq -0x38(%rbp), %rax
movl %eax, %ecx
leaq 0x92ea5(%rip), %rsi     # 0x1cc7aa
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x20(%rbp), %rsi
callq 0x1653f0
movq %rax, -0x48(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x20(%rbp), %rsi
callq 0x1653f0
movq %rax, -0x40(%rbp)
movq -0x8(%rbp), %rdi
movq -0x40(%rbp), %rsi
movq -0x48(%rbp), %rdx
callq 0x15bba0
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x20(%rbp), %rsi
callq 0x1653f0
movq %rax, -0x50(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x20(%rbp), %rsi
callq 0x1653f0
movq %rax, -0x58(%rbp)
movq -0x8(%rbp), %rdi
movq -0x58(%rbp), %rax
movl %eax, %edx
movq -0x50(%rbp), %rax
movl %eax, %ecx
leaq 0x92e37(%rip), %rsi     # 0x1cc7bf
movb $0x0, %al
callq 0x15b0d0
movq -0x18(%rbp), %rax
movzbl 0x2(%rax), %eax
cmpl $0x40, %eax
jne 0x139a27
movq -0x20(%rbp), %rax
movq %rax, -0x70(%rbp)
movq -0x18(%rbp), %rax
movq 0x20(%rax), %rax
movq -0x18(%rbp), %rcx
addq 0x28(%rcx), %rax
subq -0x70(%rbp), %rax
movq %rax, -0x78(%rbp)
cmpq $0xc, -0x78(%rbp)
jge 0x1399c9
jmp 0x139a29
movq -0x8(%rbp), %rdi
movq -0x70(%rbp), %rax
movl %eax, %edx
movq -0x78(%rbp), %rax
movl %eax, %ecx
leaq 0x92df6(%rip), %rsi     # 0x1cc7d6
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movl $0x1, %esi
callq 0x15b560
movq -0x8(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rcx
movq -0x70(%rbp), %r8
movq -0x78(%rbp), %r9
leaq 0x753e3(%rip), %rsi     # 0x1aedf3
xorl %eax, %eax
movl %eax, %edx
callq 0x15c9f0
movq -0x8(%rbp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x15b560
jmp 0x139a29
movl $0x1, %eax
addq $0x80, %rsp
popq %rbp
retq
nopw (%rax,%rax)