// File: /workspace/github_c_makefile_star2_O3/jsummers[P]deark/modules/diet.c
// Function: de_run_diet
static void de_run_diet(deark *c, de_module_params *mparams)
{
	lctx *d = NULL;
	const char *fmtn = NULL;

	d = de_malloc(c, sizeof(lctx));
	d->host_ei = de_malloc(c, sizeof(struct fmtutil_exe_info));
	d->raw_mode = (u8)de_get_ext_option_bool(c, "diet:raw", 0xff);

	fmtutil_collect_exe_info(c, c->infile, d->host_ei);

	identify_diet_fmt(c, &d->idd, 0, d->host_ei);
	switch(d->idd.fmt) {
	case FMT_DATA_100:
		fmtn = "file (v1.00)";
		break;
	case FMT_DATA_102:
		fmtn = "file (v1.02-1.20)";
		break;
	case FMT_DATA_144:
		fmtn = "file (v1.44-1.45)";
		break;
	case FMT_COM_100:
		fmtn = "COM (v1.00)";
		break;
	case FMT_COM_102:
		fmtn = "COM (v1.02-1.20)";
		break;
	case FMT_COM_144:
		fmtn = "COM (v1.44-1.45)";
		break;
	case FMT_EXE_100:
		fmtn = "EXE (v1.00)";
		break;
	case FMT_EXE_102:
		fmtn = "EXE (v1.02-1.20)";
		break;
	case FMT_EXE_144:
		if(d->idd.com2exe_flag)
			fmtn = "EXE-from-COM (v1.44)";
		else
			fmtn = "EXE (v1.44)";
		break;
	case FMT_EXE_145F:
		if(d->idd.com2exe_flag)
			fmtn = "EXE-from-COM (v1.45)";
		else
			fmtn = "EXE (v1.45)";
		break;
	default:
		break;
	}

	if(fmtn) {
		de_declare_fmtf(c, "DIET-compressed %s", fmtn);
	}

	if(d->idd.maybe_lglz) {
		de_warn(c, "This file might be LGLZ-compressed, not DIET");
	}

	if(!fmtn || !d->idd.cmpr_pos_known) {
		d->errflag = 1;
		d->need_errmsg = 1;
		goto done;
	}
	d->cmpr_pos = d->idd.cmpr_pos;

	read_header(c, d);
	if(d->errflag) goto done;

	check_diet_crc(c, d);

	check_unsupp_features(c, d);
	if(d->errflag) goto done;

	d->dcmpr_code = dbuf_create_membuf(c,
		(d->orig_len_known ? d->orig_len : MAX_DIET_DCMPR_LEN), 0x1);
	dbuf_enable_wbuffer(d->dcmpr_code);

	do_decompress_code(c, d);
	if(d->errflag) goto done;
	if(d->idd.ftype==FTYPE_DATA || d->idd.ftype==FTYPE_COM ||
		d->idd.com2exe_flag ||
		(d->idd.ftype==FTYPE_EXE && d->raw_mode==1))
	{
		write_data_or_com_file(c, d);
	}
	else if(d->idd.ftype==FTYPE_EXE && d->raw_mode!=1) {
		write_exe_file(c, d);
	}

done:
	if(d) {
		de_free(c, d->host_ei);
		if(d->need_errmsg) {
			de_err(c, "Bad or unsupported file");
		}
		dbuf_close(d->dcmpr_code);
		de_free(c, d);
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rdi, %rbx
movl $0x80, %esi
callq 0xe8b2b
movq %rax, %r14
movl $0xf0, %esi
movq %rbx, %rdi
callq 0xe8b2b
movq %rax, 0x50(%r14)
leaq 0xd3115(%rip), %rsi     # 0x11e4d6
movq %rbx, %rdi
movl $0xff, %edx
callq 0xe9bd0
movb %al, 0x2c(%r14)
movq 0x18(%rbx), %rsi
movq 0x50(%r14), %rdx
movq %rbx, %rdi
callq 0x104f96
movq 0x50(%r14), %rcx
movq %rbx, %rdi
movq %r14, %rsi
xorl %edx, %edx
callq 0x4bcc3
movl (%r14), %eax
decl %eax
cmpl $0x9, %eax
ja 0x4b46a
leaq 0xd3078(%rip), %rcx     # 0x11e47c
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
leaq 0xd30cb(%rip), %rdx     # 0x11e4df
jmp 0x4b486
leaq 0xd30ff(%rip), %rdx     # 0x11e51c
jmp 0x4b486
cmpb $0x0, 0xb(%r14)
leaq 0xd3166(%rip), %rax     # 0x11e591
leaq 0xd314a(%rip), %rdx     # 0x11e57c
jmp 0x4b482
leaq 0xd30c3(%rip), %rdx     # 0x11e4fe
jmp 0x4b486
leaq 0xd30cc(%rip), %rdx     # 0x11e510
jmp 0x4b486
leaq 0xd30fd(%rip), %rdx     # 0x11e54a
jmp 0x4b486
leaq 0xd3096(%rip), %rdx     # 0x11e4ec
jmp 0x4b486
leaq 0xd30ce(%rip), %rdx     # 0x11e52d
jmp 0x4b486
leaq 0xd30d6(%rip), %rdx     # 0x11e53e
jmp 0x4b486
movb $0x1, %bpl
jmp 0x4b499
cmpb $0x0, 0xb(%r14)
leaq 0xd30f5(%rip), %rax     # 0x11e570
leaq 0xd30d9(%rip), %rdx     # 0x11e55b
cmoveq %rax, %rdx
leaq 0xd3110(%rip), %rsi     # 0x11e59d
xorl %ebp, %ebp
movq %rbx, %rdi
xorl %eax, %eax
callq 0xeb152
cmpb $0x0, 0xc(%r14)
je 0x4b4b1
leaq 0xd3109(%rip), %rsi     # 0x11e5b0
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe8faa
testb %bpl, %bpl
jne 0x4b715
cmpb $0x0, 0xa(%r14)
je 0x4b715
movq 0x20(%r14), %rax
movq %rax, 0x40(%r14)
movq $0x0, 0x18(%rsp)
leaq 0x24(%rsp), %rsi
movq %rbx, %rdi
callq 0xe8a1c
movq %rbx, %rdi
callq 0xf6410
movq %rax, %r15
cmpb $0x0, 0x8(%r14)
je 0x4b5c8
movq 0x10(%r14), %rdx
leaq 0xd7e7b(%rip), %rsi     # 0x12337f
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe8617
movq %rbx, %rdi
movl $0x1, %esi
callq 0xe8a15
movq 0x10(%r14), %rax
addq $0x3, %rax
leaq 0x18(%rsp), %rsi
movq %rax, (%rsi)
movq 0x18(%rbx), %rdi
callq 0xeeb4b
movl %eax, %ebp
andb $-0x10, %al
movb %al, 0x2d(%r14)
testb %bpl, %bpl
jns 0x4b554
leaq 0xd30ab(%rip), %rsi     # 0x11e5f3
movq %r15, %rdi
callq 0xf7105
movb 0x2d(%r14), %al
testb $0x20, %al
je 0x4b56b
leaq 0xd30a8(%rip), %rsi     # 0x11e607
movq %r15, %rdi
callq 0xf7105
movb 0x2d(%r14), %al
testb $0x10, %al
je 0x4b582
leaq 0xd30a0(%rip), %rsi     # 0x11e616
movq %r15, %rdi
callq 0xf7105
movb 0x2d(%r14), %al
movzbl %al, %r12d
movq %r15, %rdi
callq 0xf705c
leaq 0xe2d33(%rip), %rsi     # 0x12e2c8
movq %rbx, %rdi
movl %r12d, %edx
movq %rax, %rcx
xorl %eax, %eax
callq 0xe8617
andb $0xf, %bpl
movzbl %bpl, %eax
shll $0x10, %eax
movq %rax, 0x30(%r14)
movq 0x18(%rbx), %rdi
leaq 0x18(%rsp), %rsi
callq 0xeebeb
orq 0x30(%r14), %rax
jmp 0x4b5e1
cmpl $0x7, (%r14)
jne 0x4b5fe
movq 0x18(%rbx), %rdi
movl $0x20, %esi
callq 0xeed61
andl $0xfffff, %eax          # imm = 0xFFFFF
movq %rax, 0x30(%r14)
leaq 0xff5f9(%rip), %rsi     # 0x14abe5
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xe8617
movb $0x1, 0x2a(%r14)
cmpb $0x0, 0x9(%r14)
je 0x4b629
movq 0x18(%rbx), %rdi
movq 0x18(%r14), %rsi
callq 0xeebc8
movl %eax, 0x48(%r14)
leaq 0xf980f(%rip), %rsi     # 0x144e2c
movq %rbx, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xe8617
cmpb $0x0, 0x8(%r14)
je 0x4b692
movq 0x10(%r14), %rax
addq $0x8, %rax
leaq 0x18(%rsp), %r12
movq %rax, (%r12)
movq 0x18(%rbx), %rdi
movq %r12, %rsi
callq 0xeeb4b
movzbl %al, %eax
movl %eax, %ecx
shll $0xe, %ecx
andl $0x3f0000, %ecx         # imm = 0x3F0000
movq %rcx, 0x38(%r14)
andb $0x3, %al
movb %al, 0x2e(%r14)
movq 0x18(%rbx), %rdi
movq %r12, %rsi
callq 0xeebeb
orq 0x38(%r14), %rax
movq %rax, 0x38(%r14)
leaq 0xc9b73(%rip), %rsi     # 0x1151f3
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xe8617
movb $0x1, 0x2b(%r14)
cmpb $0x0, 0x2a(%r14)
jne 0x4b6b4
cmpl $0x1, (%r14)
jne 0x4b6b4
movq 0x18(%rbx), %rax
movq 0x18(%rax), %rax
subq 0x40(%r14), %rax
movq %rax, 0x30(%r14)
movb $0x1, 0x2a(%r14)
movq %r15, %rdi
callq 0xf6753
movl 0x24(%rsp), %esi
movq %rbx, %rdi
callq 0xe8a25
cmpb $0x0, 0x28(%r14)
jne 0x4b71c
cmpb $0x0, 0x2a(%r14)
je 0x4b6e8
movq 0x30(%r14), %rax
addq 0x40(%r14), %rax
movq 0x18(%rbx), %rcx
cmpq 0x18(%rcx), %rax
jle 0x4b763
xorl %r15d, %r15d
movq %r15, %rdi
callq 0xeb858
cmpb $0x0, 0x2d(%r14)
js 0x4b715
cmpb $0x0, 0x28(%r14)
jne 0x4b71c
cmpb $0x0, 0x2b(%r14)
je 0x4b7c8
movq 0x38(%r14), %rsi
jmp 0x4b7cd
movw $0x101, 0x28(%r14)      # imm = 0x101
movq 0x50(%r14), %rsi
movq %rbx, %rdi
callq 0xe8be2
cmpb $0x0, 0x29(%r14)
je 0x4b740
leaq 0xcd859(%rip), %rsi     # 0x118f8f
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9295
movq 0x58(%r14), %rdi
callq 0xf052b
movq %rbx, %rdi
movq %r14, %rsi
callq 0xe8be2
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rbx, %rdi
movl $0x21, %esi
callq 0xeb499
movq %rax, %r15
movq 0x18(%rbx), %rsi
movq 0x30(%r14), %rcx
movq 0x40(%r14), %rdx
movq %rax, %rdi
callq 0xeb944
movq %r15, %rdi
callq 0xeb865
movl %eax, %ebp
leaq 0xc9b4b(%rip), %rsi     # 0x1152e3
movq %rbx, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xe8617
movl 0x48(%r14), %edx
cmpl %edx, %ebp
je 0x4b6eb
leaq 0xd2e78(%rip), %rsi     # 0x11e62f
movq %rbx, %rdi
movl %ebp, %ecx
xorl %eax, %eax
callq 0xe8faa
jmp 0x4b6eb
movl $0x400000, %esi         # imm = 0x400000
movq %rbx, %rdi
movl $0x1, %edx
callq 0xf09c5
movq %rax, 0x58(%r14)
movq %rax, %rdi
callq 0xf0855
movq 0x40(%r14), %rdx
movq 0x30(%r14), %rax
addq %rdx, %rax
movq 0x18(%rbx), %rcx
cmpq 0x18(%rcx), %rax
jle 0x4b802
movw $0x101, 0x28(%r14)      # imm = 0x101
leaq 0xd2e6d(%rip), %rsi     # 0x11e676
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe8617
movq %rbx, %rdi
movl $0x1, %esi
callq 0xe8a15
movq %rbx, %rdi
movl $0x2000, %esi           # imm = 0x2000
callq 0xfad8f
movq %rax, %r15
movq %r14, (%rax)
leaq 0x101b(%rip), %rax      # 0x4c855
movq %rax, 0x8(%r15)
movq 0x40(%r14), %rax
movq %rax, 0x68(%r14)
leaq 0x70(%r14), %rdi
movb $0x1, 0x70(%r14)
callq 0xf1bdd
cmpb $0x0, 0x28(%r14)
je 0x4b8ae
movq 0x58(%r14), %rdi
callq 0xf08ba
movq %rbx, %rdi
movq %r15, %rsi
callq 0xfaed4
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0xe8a15
cmpb $0x0, 0x28(%r14)
jne 0x4b71c
movl 0x4(%r14), %eax
leal -0x1(%rax), %ecx
cmpl $0x2, %ecx
jb 0x4b89e
cmpb $0x0, 0xb(%r14)
je 0x4bc07
movq %rbx, %rdi
movq %r14, %rsi
callq 0x4c0e8
jmp 0x4b71c
movq %r14, %rax
addq $0x68, %rax
movq %rax, 0x10(%rsp)
movq %rbx, %rdi
movq %r14, %rsi
callq 0x4c868
testb %al, %al
je 0x4b901
movq 0x18(%rbx), %rdi
movq 0x10(%rsp), %rsi
callq 0xeeb4b
cmpl $0x4, (%rbx)
movzbl %al, %ebp
jl 0x4b8f2
movq %rbx, %rdi
leaq 0xd2dac(%rip), %rsi     # 0x11e695
movl %ebp, %edx
xorl %eax, %eax
callq 0xe8617
movq %r15, %rdi
movl %ebp, %esi
callq 0xfae4e
jmp 0x4bb30
movq %rbx, %rdi
movq %r14, %rsi
callq 0x4c868
movl %eax, %r12d
movq 0x18(%rbx), %rdi
movq 0x10(%rsp), %rsi
callq 0xeeb4b
movl %eax, %ebp
movq %rbx, %rdi
movq %r14, %rsi
callq 0x4c868
movl %eax, %r13d
testb %r12b, %r12b
je 0x4b951
movq %rbx, %rdi
movq %r14, %rsi
callq 0x4c868
testb %al, %al
je 0x4b9ab
movzbl %r13b, %eax
movzbl %bpl, %ebp
xorl $0x1ff, %ebp            # imm = 0x1FF
jmp 0x4b9cc
testb %r13b, %r13b
je 0x4ba3e
movq %rbx, %rdi
movq %r14, %rsi
callq 0x4c868
movl %eax, %r12d
movq %rbx, %rdi
movq %r14, %rsi
callq 0x4c868
movl %eax, %r13d
movq %rbx, %rdi
movq %r14, %rsi
callq 0x4c868
movzbl %r12b, %ecx
shll $0xa, %ecx
movzbl %r13b, %edx
shll $0x9, %edx
movzbl %al, %eax
shll $0x8, %eax
addl %edx, %eax
movzbl %bpl, %edx
orl %ecx, %edx
addl %eax, %edx
movl $0x8ff, %ebp            # imm = 0x8FF
subl %edx, %ebp
jmp 0x4ba4f
movq %rbx, %rdi
movq %r14, %rsi
callq 0x4c868
testb %al, %al
je 0x4ba5a
movzbl %r13b, %eax
movzbl %bpl, %ebp
xorl $0x3ff, %ebp            # imm = 0x3FF
shll $0x8, %eax
subl %eax, %ebp
movl $0x3, %r13d
movq %rbx, %rdi
movq %r14, %rsi
callq 0x4c868
testb %al, %al
jne 0x4badb
incl %r13d
cmpl $0x7, %r13d
jne 0x4b9d7
movq %rbx, %rdi
movq %r14, %rsi
callq 0x4c868
movl %eax, %r12d
movq %rbx, %rdi
movq %r14, %rsi
callq 0x4c868
cmpb $0x1, %r12b
jne 0x4ba1f
movzbl %al, %r13d
addl $0x7, %r13d
jmp 0x4badb
testb %al, %al
je 0x4ba9c
movq 0x18(%rbx), %rdi
movq 0x10(%rsp), %rsi
callq 0xeeb4b
movzbl %al, %r13d
addl $0x11, %r13d
jmp 0x4badb
cmpb $-0x1, %bpl
je 0x4bb40
notb %bpl
movzbl %bpl, %ebp
movl $0x2, %r13d
jmp 0x4bae6
movq %rbx, %rdi
movq %r14, %rsi
callq 0x4c868
movl %eax, %r12d
movq %rbx, %rdi
movq %r14, %rsi
callq 0x4c868
testb %al, %al
je 0x4bb71
movzbl %r13b, %eax
movzbl %r12b, %ecx
movzbl %bpl, %ebp
xorl $0x7ff, %ebp            # imm = 0x7FF
shll $0x9, %eax
shll $0x8, %ecx
addl %eax, %ecx
subl %ecx, %ebp
jmp 0x4b9d1
movq %rbx, %rdi
movq %r14, %rsi
callq 0x4c868
movl %eax, %r12d
movq %rbx, %rdi
movq %r14, %rsi
callq 0x4c868
movl %eax, %r13d
movq %rbx, %rdi
movq %r14, %rsi
callq 0x4c868
movzbl %r12b, %ecx
movzbl %r13b, %edx
addl %edx, %edx
leal (%rdx,%rcx,4), %ecx
movzbl %al, %eax
leal (%rax,%rcx), %r13d
addl $0x9, %r13d
cmpb $0x0, 0x28(%r14)
jne 0x4b85b
cmpl $0x3, (%rbx)
jl 0x4bb02
leal 0x1(%rbp), %edx
movq %rbx, %rdi
leaq 0xd2bd6(%rip), %rsi     # 0x11e6ce
movl %r13d, %ecx
xorl %eax, %eax
callq 0xe889f
movl %ebp, %eax
cmpq %rax, 0x60(%r14)
jle 0x4bbfb
incq %rax
movl %r13d, %ecx
cmpq %rcx, %rax
jb 0x4bbfb
notl %ebp
addl 0x10(%r15), %ebp
movq %r15, %rdi
movl %ebp, %esi
movl %r13d, %edx
callq 0xfae7b
cmpb $0x0, 0x28(%r14)
je 0x4b8ba
jmp 0x4b85b
movq %rbx, %rdi
movq %r14, %rsi
callq 0x4c868
testb %al, %al
je 0x4bc2b
cmpl $0x3, 0x4(%r14)
jne 0x4bc5e
movq %rbx, %rdi
leaq 0xd2b42(%rip), %rsi     # 0x11e6aa
xorl %eax, %eax
callq 0xe889f
jmp 0x4bb30
movb %r12b, 0xf(%rsp)
movq %rbx, %rdi
movq %r14, %rsi
callq 0x4c868
movl %eax, %r12d
movq %rbx, %rdi
movq %r14, %rsi
callq 0x4c868
movzbl %r12b, %r12d
testb %al, %al
je 0x4bbc1
movzbl %r13b, %eax
movzbl 0xf(%rsp), %ecx
movzbl %bpl, %ebp
xorl $0xfff, %ebp            # imm = 0xFFF
shll $0xa, %eax
shll $0x9, %ecx
addl %eax, %ecx
shll $0x8, %r12d
addl %ecx, %r12d
subl %r12d, %ebp
jmp 0x4b9d1
movq %rbx, %rdi
movq %r14, %rsi
callq 0x4c868
movzbl %r13b, %ecx
movzbl 0xf(%rsp), %edx
movzbl %al, %eax
movzbl %bpl, %ebp
xorl $0x1fff, %ebp           # imm = 0x1FFF
shll $0xb, %ecx
shll $0xa, %edx
addl %ecx, %edx
shll $0x9, %r12d
shll $0x8, %eax
addl %r12d, %eax
addl %edx, %eax
jmp 0x4b9cf
movw $0x101, 0x28(%r14)      # imm = 0x101
jmp 0x4b85b
cmpl $0x3, %eax
jne 0x4b71c
cmpb $0x1, 0x2c(%r14)
je 0x4b89e
movq %rbx, %rdi
movq %r14, %rsi
callq 0x4c156
jmp 0x4b71c
leaq 0xd2a6e(%rip), %rsi     # 0x11e6a0
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe889f
movq 0x60(%r14), %rcx
movq 0x68(%r14), %rdx
subq 0x40(%r14), %rdx
leaq 0xc7049(%rip), %rsi     # 0x112c98
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe8617
jmp 0x4b85b
leaq 0xd2a55(%rip), %rsi     # 0x11e6ba
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9295
movb $0x1, 0x28(%r14)
jmp 0x4b85b