// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/bmp.c
// Function: de_run_dib
static void de_run_dib(deark *c, de_module_params *mparams)
{
	struct de_bmpinfo bi;
	UI createflags = 0;
	dbuf *outf = NULL;
	int implicit_size = 0;
	i64 dib_len;
	const char *ext = "bmp";
	de_finfo *fi_to_use = NULL;

	if(mparams) {
		// If flags&0x01, try to calculate the proper file size, instead of trusting
		// the length of the input file.
		if(mparams->in_params.flags & 0x01) implicit_size = 1;

		if(mparams->in_params.flags & 0x80) ext = "preview.bmp";

		fi_to_use = mparams->in_params.fi;
	}

	if(de_havemodcode(c, mparams, 'X')) {
		createflags |= DE_CREATEFLAG_IS_AUX;
	}

	if(!fmtutil_get_bmpinfo(c, c->infile, &bi, 0, c->infile->len, 0)) {
		de_err(c, "Invalid DIB, or not a DIB file");
		goto done;
	}

	if(implicit_size) {
		dib_len = bi.total_size;
		if(dib_len > c->infile->len) {
			dib_len = c->infile->len;
		}
	}
	else {
		dib_len = c->infile->len;
	}

	outf = dbuf_create_output_file(c, ext, fi_to_use, createflags);

	de_dbg(c, "writing a BMP FILEHEADER");
	fmtutil_generate_bmpfileheader(c, outf, &bi, 14+dib_len);

	de_dbg(c, "copying DIB file");
	dbuf_copy(c->infile, 0, dib_len, outf);

done:
	dbuf_close(outf);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xe0, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl $0x0, -0xb4(%rbp)
movq $0x0, -0xc0(%rbp)
movl $0x0, -0xc4(%rbp)
leaq 0x16962e(%rip), %rax    # 0x1acd07
movq %rax, -0xd8(%rbp)
movq $0x0, -0xe0(%rbp)
cmpq $0x0, -0x10(%rbp)
je 0x43739
movq -0x10(%rbp), %rax
movl 0x8(%rax), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x4370b
movl $0x1, -0xc4(%rbp)
movq -0x10(%rbp), %rax
movl 0x8(%rax), %eax
andl $0x80, %eax
cmpl $0x0, %eax
je 0x4372a
leaq 0x160420(%rip), %rax    # 0x1a3b43
movq %rax, -0xd8(%rbp)
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rax
movq %rax, -0xe0(%rbp)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movl $0x58, %edx
callq 0x15d1d0
cmpl $0x0, %eax
je 0x4375f
movl -0xb4(%rbp), %eax
orl $0x1, %eax
movl %eax, -0xb4(%rbp)
movq -0x8(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rsi
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x18(%rax), %r8
leaq -0xb0(%rbp), %rdx
xorl %eax, %eax
movl %eax, %ecx
xorl %r9d, %r9d
callq 0x172d70
cmpl $0x0, %eax
jne 0x437a6
movq -0x8(%rbp), %rdi
leaq 0x1603b5(%rip), %rsi    # 0x1a3b4f
movb $0x0, %al
callq 0x15bfb0
jmp 0x43880
cmpl $0x0, -0xc4(%rbp)
je 0x437e4
movq -0x20(%rbp), %rax
movq %rax, -0xd0(%rbp)
movq -0xd0(%rbp), %rax
movq -0x8(%rbp), %rcx
movq 0x18(%rcx), %rcx
cmpq 0x18(%rcx), %rax
jle 0x437e2
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x18(%rax), %rax
movq %rax, -0xd0(%rbp)
jmp 0x437f7
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x18(%rax), %rax
movq %rax, -0xd0(%rbp)
movq -0x8(%rbp), %rdi
movq -0xd8(%rbp), %rsi
movq -0xe0(%rbp), %rdx
movl -0xb4(%rbp), %ecx
callq 0x166c60
movq %rax, -0xc0(%rbp)
movq -0x8(%rbp), %rdi
leaq 0x160348(%rip), %rsi    # 0x1a3b6e
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movq -0xc0(%rbp), %rsi
movq -0xd0(%rbp), %rcx
addq $0xe, %rcx
leaq -0xb0(%rbp), %rdx
callq 0x1734e0
movq -0x8(%rbp), %rdi
leaq 0x16032d(%rip), %rsi    # 0x1a3b87
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0xd0(%rbp), %rdx
movq -0xc0(%rbp), %rcx
xorl %eax, %eax
movl %eax, %esi
callq 0x166070
movq -0xc0(%rbp), %rdi
callq 0x1676a0
addq $0xe0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)