// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/misc3.c
// Function: de_run_red
static void de_run_red(deark *c, de_module_params *mparams)
{
	de_arch_lctx *d = NULL;
	i64 pos = 0;
	UI id;
	struct de_arch_member_data *md = NULL;
	int saved_indent_level;

	de_dbg_indent_save(c, &saved_indent_level);
	d = de_arch_create_lctx(c);
	d->is_le = 1;
	d->input_encoding = de_get_input_encoding(c, NULL, DE_ENCODING_CP437);

	while(1) {
		u8 b;

		if(pos >= c->infile->len) goto done;
		if(md) {
			de_arch_destroy_md(c, md);
			md = NULL;
		}
		md = de_arch_create_md(c, d);
		md->member_hdr_pos = pos;

		id = (UI)de_getu16be_p(&pos);
		b = de_getbyte_p(&pos); // Format version? Always 1.
		md->member_hdr_size = (i64)de_getbyte_p(&pos); // Always 41?
		if(id!=0x5252U || b!=0x01 || md->member_hdr_size<39) {
			de_err(c, "Member not found at %"I64_FMT, md->member_hdr_pos);
			goto done;
		}

		de_dbg(c, "member at %"I64_FMT, md->member_hdr_pos);
		de_dbg_indent(c, 1);

		de_arch_read_field_dttm_p(d, &md->fi->timestamp[DE_TIMESTAMPIDX_MODIFY], "mod",
			DE_ARCH_TSTYPE_DOS_TD, &pos);
		de_arch_read_field_cmpr_len_p(md, &pos);
		de_arch_read_field_orig_len_p(md, &pos);

		pos = md->member_hdr_pos + 26;
		dbuf_read_to_ucstring(c->infile, pos, 12, md->filename, DE_CONVFLAG_STOP_AT_NUL,
			d->input_encoding);
		de_dbg(c, "filename: \"%s\"", ucstring_getpsz_d(md->filename));
		// Filename field is 13 bytes.
		// Then a 2-byte field unidentified field.

		md->cmpr_pos = md->member_hdr_pos + md->member_hdr_size;
		de_dbg(c, "compressed data at %"I64_FMT", len=%"I64_FMT, md->cmpr_pos, md->cmpr_len);

		de_dbg_indent(c, -1);
		pos = md->cmpr_pos + md->cmpr_len;
	}

done:
	de_dbg_indent_restore(c, saved_indent_level);
	if(md) {
		de_arch_destroy_md(c, md);
		md = NULL;
	}
	if(d) {
		if(d->need_errmsg) {
			de_err(c, "Bad or unsupported RED file");
		}
		de_arch_destroy_lctx(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 $0x0, -0x30(%rbp)
movq -0x8(%rbp), %rdi
leaq -0x34(%rbp), %rsi
callq 0x15b580
movq -0x8(%rbp), %rdi
callq 0x17c220
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rax
movl $0x1, 0x10(%rax)
movq -0x8(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
movl $0xd, %edx
callq 0x15e4a0
movl %eax, %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x18(%rax)
movq -0x20(%rbp), %rax
movq -0x8(%rbp), %rcx
movq 0x18(%rcx), %rcx
cmpq 0x18(%rcx), %rax
jl 0x9f8df
jmp 0x9fac8
cmpq $0x0, -0x30(%rbp)
je 0x9f8fb
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rsi
callq 0x17c1a0
movq $0x0, -0x30(%rbp)
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x17c120
movq %rax, -0x30(%rbp)
movq -0x20(%rbp), %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x20(%rbp), %rsi
callq 0x165210
movl %eax, -0x24(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x20(%rbp), %rsi
callq 0x165170
movb %al, -0x35(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x20(%rbp), %rsi
callq 0x165170
movzbl %al, %eax
movl %eax, %ecx
movq -0x30(%rbp), %rax
movq %rcx, 0x20(%rax)
cmpl $0x5252, -0x24(%rbp)    # imm = 0x5252
jne 0x9f97b
movzbl -0x35(%rbp), %eax
cmpl $0x1, %eax
jne 0x9f97b
movq -0x30(%rbp), %rax
cmpq $0x27, 0x20(%rax)
jge 0x9f99a
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rax
movq 0x18(%rax), %rdx
leaq 0x112299(%rip), %rsi    # 0x1b1c27
movb $0x0, %al
callq 0x15bfb0
jmp 0x9fac8
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rax
movq 0x18(%rax), %rdx
leaq 0x1279e5(%rip), %rsi    # 0x1c7392
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movl $0x1, %esi
callq 0x15b560
movq -0x18(%rbp), %rdi
movq -0x30(%rbp), %rax
movq 0x50(%rax), %rsi
addq $0x18, %rsi
leaq 0x10451a(%rip), %rdx    # 0x1a3ef3
movl $0x4, %ecx
leaq -0x20(%rbp), %r8
callq 0x17c580
movq -0x30(%rbp), %rdi
leaq -0x20(%rbp), %rsi
callq 0x17c400
movq -0x30(%rbp), %rdi
leaq -0x20(%rbp), %rsi
callq 0x17c350
movq -0x30(%rbp), %rax
movq 0x18(%rax), %rax
addq $0x1a, %rax
movq %rax, -0x20(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x20(%rbp), %rsi
movq -0x30(%rbp), %rax
movq 0x58(%rax), %rcx
movq -0x18(%rbp), %rax
movl 0x18(%rax), %r9d
movl $0xc, %edx
movl $0x1, %r8d
callq 0x1669f0
movq -0x8(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x30(%rbp), %rax
movq 0x58(%rax), %rdi
callq 0x172650
movq -0x40(%rbp), %rdi
movq %rax, %rdx
leaq 0x127b23(%rip), %rsi    # 0x1c7583
movb $0x0, %al
callq 0x15b0d0
movq -0x30(%rbp), %rax
movq 0x18(%rax), %rcx
movq -0x30(%rbp), %rax
addq 0x20(%rax), %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x40(%rax)
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rax
movq 0x40(%rax), %rdx
movq -0x30(%rbp), %rax
movq 0x30(%rax), %rcx
leaq 0x111fce(%rip), %rsi    # 0x1b1a68
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x15b560
movq -0x30(%rbp), %rax
movq 0x40(%rax), %rax
movq -0x30(%rbp), %rcx
addq 0x30(%rcx), %rax
movq %rax, -0x20(%rbp)
jmp 0x9f8c8
movq -0x8(%rbp), %rdi
movl -0x34(%rbp), %esi
callq 0x15b5a0
cmpq $0x0, -0x30(%rbp)
je 0x9faf0
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rsi
callq 0x17c1a0
movq $0x0, -0x30(%rbp)
cmpq $0x0, -0x18(%rbp)
je 0x9fb20
movq -0x18(%rbp), %rax
cmpb $0x0, 0x14(%rax)
je 0x9fb13
movq -0x8(%rbp), %rdi
leaq 0x112133(%rip), %rsi    # 0x1b1c3f
movb $0x0, %al
callq 0x15bfb0
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x17c270
addq $0x40, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)