// File: /workspace/github_c_makefile_star2_O1/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdi, %rbx
leaq 0x8(%rsp), %r15
movq $0x0, (%r15)
leaq 0x14(%rsp), %rsi
callq 0xe958c
movq %rbx, %rdi
callq 0xfdb0a
movq %rax, %r14
movl $0x1, 0x10(%rax)
movq %rbx, %rdi
xorl %esi, %esi
movl $0xd, %edx
callq 0xeb7d1
movl %eax, 0x18(%r14)
xorl %r12d, %r12d
movq 0x8(%rsp), %rax
movq 0x18(%rbx), %rcx
cmpq 0x18(%rcx), %rax
jge 0x6fc30
testq %r12, %r12
je 0x6fbac
movq %rbx, %rdi
movq %r12, %rsi
callq 0xfdab8
movq %rbx, %rdi
movq %r14, %rsi
callq 0xfda6c
movq %rax, %r12
movq 0x8(%rsp), %rax
movq %rax, 0x18(%r12)
movq 0x18(%rbx), %rdi
movq %r15, %rsi
callq 0xef193
movq %rax, %r13
movq 0x18(%rbx), %rdi
movq %r15, %rsi
callq 0xef14d
movl %eax, %ebp
movq 0x18(%rbx), %rdi
movq %r15, %rsi
callq 0xef14d
movzbl %al, %eax
movq %rax, 0x20(%r12)
cmpl $0x5252, %r13d          # imm = 0x5252
setne %cl
cmpb $0x1, %bpl
setne %dl
orb %cl, %dl
cmpb $0x27, %al
setb %al
orb %dl, %al
movq 0x18(%r12), %rdx
cmpb $0x1, %al
jne 0x6fc37
xorl %ebp, %ebp
movq %rbx, %rdi
leaq 0xb6596(%rip), %rsi     # 0x1261ba
xorl %eax, %eax
callq 0xe9df7
jmp 0x6fd18
xorl %ebp, %ebp
jmp 0x6fd18
movq %rbx, %rdi
leaq 0xcbba2(%rip), %rsi     # 0x13b7e3
xorl %eax, %eax
callq 0xe9226
movq %rbx, %rdi
movl $0x1, %esi
callq 0xe9585
movq 0x50(%r12), %rsi
addq $0x18, %rsi
movq %r14, %rdi
leaq 0xa8436(%rip), %rdx     # 0x11809e
movl $0x4, %ecx
movq %r15, %r8
callq 0xfdc9b
movq %r12, %rdi
movq %r15, %rsi
callq 0xfdbe0
movq %r12, %rdi
movq %r15, %rsi
callq 0xfdb9b
movq 0x18(%r12), %rsi
addq $0x1a, %rsi
movq %rsi, 0x8(%rsp)
movq 0x18(%rbx), %rdi
movq 0x58(%r12), %rcx
movl 0x18(%r14), %r9d
movl $0xc, %edx
movl $0x1, %r8d
callq 0xf01b0
movq 0x58(%r12), %rdi
callq 0xf7557
movq %rbx, %rdi
leaq 0xcbd0a(%rip), %rsi     # 0x13b9d4
movq %rax, %rdx
xorl %eax, %eax
callq 0xe9226
movq 0x20(%r12), %rdx
movq 0x30(%r12), %rcx
addq 0x18(%r12), %rdx
movq %rdx, 0x40(%r12)
movq %rbx, %rdi
leaq 0xb6309(%rip), %rsi     # 0x125ffb
xorl %eax, %eax
callq 0xe9226
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0xe9585
movq 0x30(%r12), %rax
addq 0x40(%r12), %rax
movq %rax, 0x8(%rsp)
movb $0x1, %bpl
testb %bpl, %bpl
jne 0x6fb89
movl 0x14(%rsp), %esi
movq %rbx, %rdi
callq 0xe9595
testq %r12, %r12
je 0x6fd3d
movq %rbx, %rdi
movq %r12, %rsi
callq 0xfdab8
testq %r14, %r14
je 0x6fd65
cmpb $0x0, 0x14(%r14)
je 0x6fd5a
leaq 0xb6482(%rip), %rsi     # 0x1261d2
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9df7
movq %rbx, %rdi
movq %r14, %rsi
callq 0xfdb25
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq