// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq $0x0, -0x18(%rbp)
movq $0x0, -0x20(%rbp)
movq -0x8(%rbp), %rdi
movl $0x80, %esi
callq 0x15b780
movq %rax, -0x18(%rbp)
movq -0x8(%rbp), %rdi
movl $0xf0, %esi
callq 0x15b780
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x50(%rax)
movq -0x8(%rbp), %rdi
leaq 0x140b1d(%rip), %rsi    # 0x1aa073
movl $0xff, %edx
callq 0x15cbc0
movb %al, %cl
movq -0x18(%rbp), %rax
movb %cl, 0x2c(%rax)
movq -0x8(%rbp), %rdi
movq 0x18(%rdi), %rsi
movq -0x18(%rbp), %rax
movq 0x50(%rax), %rdx
callq 0x188930
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq 0x50(%rsi), %rcx
xorl %edx, %edx
callq 0x698f0
movq -0x18(%rbp), %rax
movl (%rax), %eax
decl %eax
movl %eax, %ecx
movq %rcx, -0x28(%rbp)
subl $0x9, %eax
ja 0x69675
movq -0x28(%rbp), %rax
leaq 0x140a79(%rip), %rcx    # 0x1aa02c
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
leaq 0x140ab9(%rip), %rax    # 0x1aa07c
movq %rax, -0x20(%rbp)
jmp 0x69677
leaq 0x140ab6(%rip), %rax    # 0x1aa089
movq %rax, -0x20(%rbp)
jmp 0x69677
leaq 0x140ab8(%rip), %rax    # 0x1aa09b
movq %rax, -0x20(%rbp)
jmp 0x69677
leaq 0x140aba(%rip), %rax    # 0x1aa0ad
movq %rax, -0x20(%rbp)
jmp 0x69677
leaq 0x140ab9(%rip), %rax    # 0x1aa0b9
movq %rax, -0x20(%rbp)
jmp 0x69677
leaq 0x140abd(%rip), %rax    # 0x1aa0ca
movq %rax, -0x20(%rbp)
jmp 0x69677
leaq 0x140ac1(%rip), %rax    # 0x1aa0db
movq %rax, -0x20(%rbp)
jmp 0x69677
leaq 0x140ac0(%rip), %rax    # 0x1aa0e7
movq %rax, -0x20(%rbp)
jmp 0x69677
movq -0x18(%rbp), %rax
cmpb $0x0, 0xb(%rax)
je 0x69644
leaq 0x140aba(%rip), %rax    # 0x1aa0f8
movq %rax, -0x20(%rbp)
jmp 0x6964f
leaq 0x140ac2(%rip), %rax    # 0x1aa10d
movq %rax, -0x20(%rbp)
jmp 0x69677
movq -0x18(%rbp), %rax
cmpb $0x0, 0xb(%rax)
je 0x69668
leaq 0x140ab7(%rip), %rax    # 0x1aa119
movq %rax, -0x20(%rbp)
jmp 0x69673
leaq 0x140abf(%rip), %rax    # 0x1aa12e
movq %rax, -0x20(%rbp)
jmp 0x69677
jmp 0x69677
cmpq $0x0, -0x20(%rbp)
je 0x69694
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rdx
leaq 0x140aad(%rip), %rsi    # 0x1aa13a
movb $0x0, %al
callq 0x15e3d0
movq -0x18(%rbp), %rax
cmpb $0x0, 0xc(%rax)
je 0x696b0
movq -0x8(%rbp), %rdi
leaq 0x140aa4(%rip), %rsi    # 0x1aa14d
movb $0x0, %al
callq 0x15bc10
cmpq $0x0, -0x20(%rbp)
je 0x696c1
movq -0x18(%rbp), %rax
cmpb $0x0, 0xa(%rax)
jne 0x696d6
movq -0x18(%rbp), %rax
movb $0x1, 0x28(%rax)
movq -0x18(%rbp), %rax
movb $0x1, 0x29(%rax)
jmp 0x6980b
movq -0x18(%rbp), %rax
movq 0x20(%rax), %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x40(%rax)
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x69ed0
movq -0x18(%rbp), %rax
cmpb $0x0, 0x28(%rax)
je 0x69702
jmp 0x6980b
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x6a200
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x6a2e0
movq -0x18(%rbp), %rax
cmpb $0x0, 0x28(%rax)
je 0x6972b
jmp 0x6980b
movq -0x8(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x18(%rbp), %rax
movzbl 0x2b(%rax), %eax
cmpl $0x0, %eax
je 0x6974e
movq -0x18(%rbp), %rax
movq 0x38(%rax), %rax
movq %rax, -0x38(%rbp)
jmp 0x69759
movl $0x400000, %eax         # imm = 0x400000
movq %rax, -0x38(%rbp)
jmp 0x69759
movq -0x30(%rbp), %rdi
movq -0x38(%rbp), %rsi
movl $0x1, %edx
callq 0x168020
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x58(%rax)
movq -0x18(%rbp), %rax
movq 0x58(%rax), %rdi
callq 0x167b90
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x6a320
movq -0x18(%rbp), %rax
cmpb $0x0, 0x28(%rax)
je 0x6979c
jmp 0x6980b
movq -0x18(%rbp), %rax
cmpl $0x1, 0x4(%rax)
je 0x697d4
movq -0x18(%rbp), %rax
cmpl $0x2, 0x4(%rax)
je 0x697d4
movq -0x18(%rbp), %rax
movzbl 0xb(%rax), %eax
cmpl $0x0, %eax
jne 0x697d4
movq -0x18(%rbp), %rax
cmpl $0x3, 0x4(%rax)
jne 0x697e3
movq -0x18(%rbp), %rax
movzbl 0x2c(%rax), %eax
cmpl $0x1, %eax
jne 0x697e3
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x6a7f0
jmp 0x69809
movq -0x18(%rbp), %rax
cmpl $0x3, 0x4(%rax)
jne 0x69807
movq -0x18(%rbp), %rax
movzbl 0x2c(%rax), %eax
cmpl $0x1, %eax
je 0x69807
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x6a8a0
jmp 0x69809
jmp 0x6980b
cmpq $0x0, -0x18(%rbp)
je 0x69859
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x50(%rax), %rsi
callq 0x15b820
movq -0x18(%rbp), %rax
cmpb $0x0, 0x29(%rax)
je 0x6983f
movq -0x8(%rbp), %rdi
leaq 0x13b3f7(%rip), %rsi    # 0x1a4c2f
movb $0x0, %al
callq 0x15bfb0
movq -0x18(%rbp), %rax
movq 0x58(%rax), %rdi
callq 0x1676a0
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x15b820
addq $0x40, %rsp
popq %rbp
retq
nop