// File: /workspace/github_c_makefile_star2_O1/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 $0x48, %rsp
movq %rdi, %rbx
movl $0x80, %esi
callq 0xe969b
movq %rax, %r14
movl $0xf0, %esi
movq %rbx, %rdi
callq 0xe969b
movq %rax, 0x50(%r14)
leaq 0xd2f96(%rip), %rsi     # 0x11e3cf
movq %rbx, %rdi
movl $0xff, %edx
callq 0xea727
movb %al, 0x2c(%r14)
movq 0x18(%rbx), %rsi
movq 0x50(%r14), %rdx
movq %rbx, %rdi
callq 0x1053ee
movq 0x50(%r14), %rcx
xorl %r15d, %r15d
movq %rbx, %rdi
movq %r14, %rsi
xorl %edx, %edx
callq 0x4bdbb
movl (%r14), %eax
decl %eax
cmpl $0x9, %eax
ja 0x4b4e5
leaq 0xd2eed(%rip), %rcx     # 0x11e36c
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
leaq 0xd2f49(%rip), %r15     # 0x11e3d8
jmp 0x4b501
leaq 0xd2f7d(%rip), %r15     # 0x11e415
jmp 0x4b501
cmpb $0x0, 0xb(%r14)
leaq 0xd2fe4(%rip), %rax     # 0x11e48a
leaq 0xd2fc8(%rip), %r15     # 0x11e475
jmp 0x4b4fd
leaq 0xd2f41(%rip), %r15     # 0x11e3f7
jmp 0x4b501
leaq 0xd2f4a(%rip), %r15     # 0x11e409
jmp 0x4b501
leaq 0xd2f7b(%rip), %r15     # 0x11e443
jmp 0x4b501
leaq 0xd2f14(%rip), %r15     # 0x11e3e5
jmp 0x4b501
leaq 0xd2f4c(%rip), %r15     # 0x11e426
jmp 0x4b501
leaq 0xd2f54(%rip), %r15     # 0x11e437
jmp 0x4b501
movb $0x1, %bpl
jmp 0x4b503
cmpb $0x0, 0xb(%r14)
leaq 0xd2f73(%rip), %rax     # 0x11e469
leaq 0xd2f57(%rip), %r15     # 0x11e454
cmoveq %rax, %r15
xorl %ebp, %ebp
testb %bpl, %bpl
jne 0x4b51c
leaq 0xd2f87(%rip), %rsi     # 0x11e496
movq %rbx, %rdi
movq %r15, %rdx
xorl %eax, %eax
callq 0xeb703
cmpb $0x0, 0xc(%r14)
je 0x4b534
leaq 0xd2f7f(%rip), %rsi     # 0x11e4a9
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9b27
testb %bpl, %bpl
jne 0x4b646
cmpb $0x0, 0xa(%r14)
je 0x4b646
movq 0x20(%r14), %rax
movq %rax, 0x40(%r14)
movq $0x0, 0x28(%rsp)
leaq 0x34(%rsp), %rsi
movq %rbx, %rdi
callq 0xe958c
movq %rbx, %rdi
callq 0xf6870
movq %rax, %r15
cmpb $0x0, 0x8(%r14)
je 0x4b652
movq 0x10(%r14), %rdx
leaq 0xd7c18(%rip), %rsi     # 0x12319f
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9226
movq %rbx, %rdi
movl $0x1, %esi
callq 0xe9585
movq 0x10(%r14), %rax
addq $0x3, %rax
leaq 0x28(%rsp), %rsi
movq %rax, (%rsi)
movq 0x18(%rbx), %rdi
callq 0xef14d
movl %eax, %ebp
andb $-0x10, %al
movb %al, 0x2d(%r14)
testb %bpl, %bpl
jns 0x4b5d3
leaq 0xd2f21(%rip), %rsi     # 0x11e4ec
movq %r15, %rdi
callq 0xf7566
testb $0x20, 0x2d(%r14)
je 0x4b5e9
leaq 0xd2f1f(%rip), %rsi     # 0x11e500
movq %r15, %rdi
callq 0xf7566
testb $0x10, 0x2d(%r14)
je 0x4b5ff
leaq 0xd2f18(%rip), %rsi     # 0x11e50f
movq %r15, %rdi
callq 0xf7566
movzbl 0x2d(%r14), %r12d
movq %r15, %rdi
callq 0xf74bd
leaq 0xe29bd(%rip), %rsi     # 0x12dfd0
movq %rbx, %rdi
movl %r12d, %edx
movq %rax, %rcx
xorl %eax, %eax
callq 0xe9226
andb $0xf, %bpl
movzbl %bpl, %eax
shll $0x10, %eax
movq %rax, 0x30(%r14)
movq 0x18(%rbx), %rdi
leaq 0x28(%rsp), %rsi
callq 0xef1ed
orq 0x30(%r14), %rax
jmp 0x4b66b
movw $0x101, 0x28(%r14)      # imm = 0x101
jmp 0x4bd05
cmpl $0x7, (%r14)
jne 0x4b688
movq 0x18(%rbx), %rdi
movl $0x20, %esi
callq 0xef37e
andl $0xfffff, %eax          # imm = 0xFFFFF
movq %rax, 0x30(%r14)
leaq 0xfefbf(%rip), %rsi     # 0x14a635
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xe9226
movb $0x1, 0x2a(%r14)
cmpb $0x0, 0x9(%r14)
je 0x4b6b3
movq 0x18(%rbx), %rdi
movq 0x18(%r14), %rsi
callq 0xef1ca
movl %eax, 0x48(%r14)
leaq 0xf92a5(%rip), %rsi     # 0x14494c
movq %rbx, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xe9226
cmpb $0x0, 0x8(%r14)
je 0x4b71c
movq 0x10(%r14), %rax
addq $0x8, %rax
leaq 0x28(%rsp), %r12
movq %rax, (%r12)
movq 0x18(%rbx), %rdi
movq %r12, %rsi
callq 0xef14d
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 0xef1ed
orq 0x38(%r14), %rax
movq %rax, 0x38(%r14)
leaq 0xc9a39(%rip), %rsi     # 0x115143
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xe9226
movb $0x1, 0x2b(%r14)
cmpb $0x0, 0x2a(%r14)
jne 0x4b73e
cmpl $0x1, (%r14)
jne 0x4b73e
movq 0x18(%rbx), %rax
movq 0x18(%rax), %rax
subq 0x40(%r14), %rax
movq %rax, 0x30(%r14)
movb $0x1, 0x2a(%r14)
movq %r15, %rdi
callq 0xf6bb0
movl 0x34(%rsp), %esi
movq %rbx, %rdi
callq 0xe9595
cmpb $0x0, 0x28(%r14)
jne 0x4bd05
cmpb $0x0, 0x2a(%r14)
je 0x4b776
movq 0x30(%r14), %rax
addq 0x40(%r14), %rax
movq 0x18(%rbx), %rcx
cmpq 0x18(%rcx), %rax
jle 0x4b7a7
xorl %r15d, %r15d
movq %r15, %rdi
callq 0xebe1d
cmpb $0x0, 0x2d(%r14)
jns 0x4b78f
movw $0x101, 0x28(%r14)      # imm = 0x101
cmpb $0x0, 0x28(%r14)
jne 0x4bd05
cmpb $0x0, 0x2b(%r14)
je 0x4b808
movq 0x38(%r14), %rsi
jmp 0x4b80d
movq %rbx, %rdi
movl $0x21, %esi
callq 0xeba56
movq %rax, %r15
movq 0x18(%rbx), %rsi
movq 0x30(%r14), %rcx
movq 0x40(%r14), %rdx
movq %rax, %rdi
callq 0xebf09
movq %r15, %rdi
callq 0xebe2a
movl %eax, %ebp
leaq 0xc9a57(%rip), %rsi     # 0x115233
movq %rbx, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xe9226
movl 0x48(%r14), %edx
cmpl %edx, %ebp
je 0x4b779
leaq 0xd2d31(%rip), %rsi     # 0x11e528
movq %rbx, %rdi
movl %ebp, %ecx
xorl %eax, %eax
callq 0xe9b27
jmp 0x4b779
movl $0x400000, %esi         # imm = 0x400000
movq %rbx, %rdi
movl $0x1, %edx
callq 0xf0faf
movq %rax, 0x58(%r14)
movq %rax, %rdi
callq 0xf0e3f
movq 0x40(%r14), %rdx
movq 0x30(%r14), %rax
addq %rdx, %rax
movq 0x18(%rbx), %rcx
cmpq 0x18(%rcx), %rax
jle 0x4b842
movw $0x101, 0x28(%r14)      # imm = 0x101
leaq 0xd2d26(%rip), %rsi     # 0x11e56f
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9226
movq %rbx, %rdi
movl $0x1, %esi
callq 0xe9585
movq %rbx, %rdi
movl $0x2000, %esi           # imm = 0x2000
callq 0xfb2c3
movq %rax, %r15
movq %r14, (%rax)
leaq 0x1140(%rip), %rax      # 0x4c9ba
movq %rax, 0x8(%r15)
movq 0x40(%r14), %rax
leaq 0x68(%r14), %rcx
movq %rcx, 0x20(%rsp)
movq %rax, 0x68(%r14)
movq %r14, %rdi
addq $0x70, %rdi
movb $0x1, 0x70(%r14)
callq 0xf2261
movl $0x6, %eax
movl %eax, %eax
movq %rax, 0x40(%rsp)
leaq 0xd2ae1(%rip), %r12     # 0x11e394
movl $0x2, %eax
movl %eax, %eax
movq %rax, 0x38(%rsp)
movl $0x4, %eax
movl %eax, %eax
movq %rax, 0x18(%rsp)
movq %r15, 0x10(%rsp)
cmpb $0x0, 0x28(%r14)
movl $0x4, %eax
je 0x4b8e7
movl %eax, %eax
movslq (%r12,%rax,4), %rax
addq %r12, %rax
jmpq *%rax
movq %rbx, %rdi
movq %r14, %rsi
callq 0x4c9cd
testb %al, %al
je 0x4b937
movq 0x18(%rbx), %rdi
movq 0x20(%rsp), %rsi
callq 0xef14d
cmpl $0x4, (%rbx)
movzbl %al, %ebp
jl 0x4b91f
movq %rbx, %rdi
leaq 0xd2c78(%rip), %rsi     # 0x11e58e
movl %ebp, %edx
xorl %eax, %eax
callq 0xe9226
movq %r15, %rdi
movl %ebp, %esi
callq 0xfb382
movq 0x38(%rsp), %rax
movslq (%r12,%rax,4), %rax
addq %r12, %rax
jmpq *%rax
movq %rbx, %rdi
movq %r14, %rsi
callq 0x4c9cd
movl %eax, %r15d
movq 0x18(%rbx), %rdi
movq 0x20(%rsp), %rsi
callq 0xef14d
movl %eax, %r13d
movq %rbx, %rdi
movq %r14, %rsi
callq 0x4c9cd
movl %eax, %ebp
testb %r15b, %r15b
je 0x4b996
movq %rbx, %rdi
movq %r14, %rsi
callq 0x4c9cd
testb %al, %al
je 0x4b9ea
movzbl %bpl, %eax
movzbl %r13b, %r13d
xorl $0x1ff, %r13d           # imm = 0x1FF
shll $0x8, %eax
subl %eax, %r13d
movq 0x10(%rsp), %r15
jmp 0x4ba76
testb %bpl, %bpl
je 0x4ba15
movq %rbx, %rdi
movq %r14, %rsi
callq 0x4c9cd
movl %eax, %ebp
movq %rbx, %rdi
movq %r14, %rsi
callq 0x4c9cd
movl %eax, %r15d
movq %rbx, %rdi
movq %r14, %rsi
callq 0x4c9cd
movzbl %bpl, %ecx
shll $0xa, %ecx
movzbl %r15b, %edx
shll $0x9, %edx
movzbl %al, %eax
shll $0x8, %eax
addl %edx, %eax
movzbl %r13b, %edx
orl %ecx, %edx
addl %eax, %edx
movl $0x8ff, %r13d           # imm = 0x8FF
subl %edx, %r13d
jmp 0x4ba26
movq %rbx, %rdi
movq %r14, %rsi
callq 0x4c9cd
testb %al, %al
movq 0x10(%rsp), %r15
je 0x4ba35
movzbl %bpl, %eax
movzbl %r13b, %r13d
xorl $0x3ff, %r13d           # imm = 0x3FF
shll $0x8, %eax
subl %eax, %r13d
jmp 0x4ba76
cmpb $-0x1, %r13b
je 0x4bb9a
notb %r13b
movzbl %r13b, %r13d
movl $0x2, %ebp
movq 0x10(%rsp), %r15
jmp 0x4bb26
movq %rbx, %rdi
movq %r14, %rsi
callq 0x4c9cd
movb %al, 0xf(%rsp)
movq %rbx, %rdi
movq %r14, %rsi
callq 0x4c9cd
testb %al, %al
je 0x4bbd8
movzbl %bpl, %eax
movzbl 0xf(%rsp), %ecx
movzbl %r13b, %r13d
xorl $0x7ff, %r13d           # imm = 0x7FF
shll $0x9, %eax
shll $0x8, %ecx
addl %eax, %ecx
subl %ecx, %r13d
movl $0x3, %ebp
movq %rbx, %rdi
movq %r14, %rsi
callq 0x4c9cd
testb %al, %al
jne 0x4bb16
incl %ebp
cmpl $0x7, %ebp
jne 0x4ba7b
movq %rbx, %rdi
movq %r14, %rsi
callq 0x4c9cd
movl %eax, %ebp
movq %rbx, %rdi
movq %r14, %rsi
callq 0x4c9cd
cmpb $0x1, %bpl
jne 0x4babb
movzbl %al, %ebp
addl $0x7, %ebp
jmp 0x4bb16
testb %al, %al
je 0x4bad5
movq 0x18(%rbx), %rdi
movq 0x20(%rsp), %rsi
callq 0xef14d
movzbl %al, %ebp
addl $0x11, %ebp
jmp 0x4bb16
movq %rbx, %rdi
movq %r14, %rsi
callq 0x4c9cd
movl %eax, %ebp
movq %rbx, %rdi
movq %r14, %rsi
callq 0x4c9cd
movl %eax, %r15d
movq %rbx, %rdi
movq %r14, %rsi
callq 0x4c9cd
movzbl %bpl, %ecx
movzbl %r15b, %edx
movq 0x10(%rsp), %r15
addl %edx, %edx
leal (%rdx,%rcx,4), %ecx
movzbl %al, %eax
leal (%rax,%rcx), %ebp
addl $0x9, %ebp
cmpb $0x0, 0x28(%r14)
movl $0x4, %eax
jne 0x4b8dc
cmpl $0x3, (%rbx)
jl 0x4bb42
leal 0x1(%r13), %edx
movq %rbx, %rdi
leaq 0xd2a8e(%rip), %rsi     # 0x11e5c7
movl %ebp, %ecx
xorl %eax, %eax
callq 0xe9461
movl %r13d, %eax
cmpq %rax, 0x60(%r14)
jle 0x4bb6a
incq %rax
movl %ebp, %ecx
cmpq %rcx, %rax
jae 0x4bb7f
movw $0x101, 0x28(%r14)      # imm = 0x101
movq 0x18(%rsp), %rax
movslq (%r12,%rax,4), %rax
addq %r12, %rax
jmpq *%rax
movw $0x101, 0x28(%r14)      # imm = 0x101
movq 0x18(%rsp), %rax
movslq (%r12,%rax,4), %rax
addq %r12, %rax
jmpq *%rax
notl %r13d
addl 0x10(%r15), %r13d
movq %r15, %rdi
movl %r13d, %esi
movl %ebp, %edx
callq 0xfb3af
xorl %eax, %eax
jmp 0x4b8dc
movq %rbx, %rdi
movq %r14, %rsi
callq 0x4c9cd
testb %al, %al
movq 0x10(%rsp), %r15
je 0x4bc24
cmpl $0x3, 0x4(%r14)
jne 0x4bc43
movq %rbx, %rdi
leaq 0xd29e0(%rip), %rsi     # 0x11e5a3
xorl %eax, %eax
callq 0xe9461
movq 0x38(%rsp), %rax
movslq (%r12,%rax,4), %rax
addq %r12, %rax
jmpq *%rax
movq %rbx, %rdi
movq %r14, %rsi
callq 0x4c9cd
movl %eax, %r15d
movq %rbx, %rdi
movq %r14, %rsi
callq 0x4c9cd
movzbl %r15b, %r15d
testb %al, %al
je 0x4bc67
movzbl %bpl, %eax
movzbl 0xf(%rsp), %ecx
movzbl %r13b, %r13d
xorl $0xfff, %r13d           # imm = 0xFFF
shll $0xa, %eax
shll $0x9, %ecx
addl %eax, %ecx
shll $0x8, %r15d
addl %ecx, %r15d
subl %r15d, %r13d
jmp 0x4b98c
movq %rbx, %rdi
leaq 0xd296b(%rip), %rsi     # 0x11e599
xorl %eax, %eax
callq 0xe9461
movq 0x40(%rsp), %rax
movslq (%r12,%rax,4), %rax
addq %r12, %rax
jmpq *%rax
movq %rbx, %rdi
leaq 0xd2966(%rip), %rsi     # 0x11e5b3
xorl %eax, %eax
callq 0xe9df7
movb $0x1, 0x28(%r14)
movq 0x18(%rsp), %rax
movslq (%r12,%rax,4), %rax
addq %r12, %rax
jmpq *%rax
movq %rbx, %rdi
movq %r14, %rsi
callq 0x4c9cd
movzbl %bpl, %ecx
movzbl 0xf(%rsp), %edx
movzbl %al, %eax
movzbl %r13b, %r13d
xorl $0x1fff, %r13d          # imm = 0x1FFF
shll $0xb, %ecx
shll $0xa, %edx
addl %ecx, %edx
shll $0x9, %r15d
shll $0x8, %eax
addl %r15d, %eax
addl %edx, %eax
jmp 0x4b989
movq 0x60(%r14), %rcx
movq 0x68(%r14), %rdx
subq 0x40(%r14), %rdx
leaq 0xc6fd3(%rip), %rsi     # 0x112c88
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9226
movq 0x58(%r14), %rdi
callq 0xf0ea4
movq %rbx, %rdi
movq %r15, %rsi
callq 0xfb408
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0xe9585
cmpb $0x0, 0x28(%r14)
jne 0x4bd05
movl 0x4(%r14), %eax
leal -0x1(%rax), %ecx
cmpl $0x2, %ecx
jb 0x4bcfa
cmpb $0x0, 0xb(%r14)
je 0x4bd4c
movq %rbx, %rdi
movq %r14, %rsi
callq 0x4c1ff
movq 0x50(%r14), %rsi
movq %rbx, %rdi
callq 0xe9752
cmpb $0x0, 0x29(%r14)
je 0x4bd29
leaq 0xcd150(%rip), %rsi     # 0x118e6f
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9df7
movq 0x58(%r14), %rdi
callq 0xf0b13
movq %rbx, %rdi
movq %r14, %rsi
callq 0xe9752
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpl $0x3, %eax
jne 0x4bd05
cmpb $0x1, 0x2c(%r14)
je 0x4bcfa
cmpl $0x3, %eax
jne 0x4bd05
cmpb $0x1, 0x2c(%r14)
je 0x4bd05
movq %rbx, %rdi
movq %r14, %rsi
callq 0x4c26d
jmp 0x4bd05