// File: /workspace/github_c_makefile_star2_O2/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
andq $0x0, (%r15)
leaq 0x14(%rsp), %rsi
callq 0xdebae
movq %rbx, %rdi
callq 0xf16ce
movq %rax, %r14
movl $0x1, 0x10(%rax)
pushq $0xd
popq %rdx
movq %rbx, %rdi
xorl %esi, %esi
callq 0xe08d2
movl %eax, 0x18(%r14)
xorl %eax, %eax
xorl %r12d, %r12d
movq 0x18(%rbx), %rcx
cmpq 0x18(%rcx), %rax
jge 0x6bc97
testq %r12, %r12
je 0x6bb3f
movq %rbx, %rdi
movq %r12, %rsi
callq 0xf167c
movq %rbx, %rdi
movq %r14, %rsi
callq 0xf1630
movq %rax, %r12
movq 0x8(%rsp), %rax
movq %rax, 0x18(%r12)
movq 0x18(%rbx), %rdi
movq %r15, %rsi
callq 0xe3f6e
movq %rax, %rbp
movq 0x18(%rbx), %rdi
movq %r15, %rsi
callq 0xe3f2a
movl %eax, %r13d
movq 0x18(%rbx), %rdi
movq %r15, %rsi
callq 0xe3f2a
movzbl %al, %ecx
movq %rcx, 0x20(%r12)
movq 0x18(%r12), %rdx
cmpl $0x5252, %ebp           # imm = 0x5252
jne 0x6bc86
cmpb $0x1, %r13b
jne 0x6bc86
cmpb $0x26, %al
jbe 0x6bc86
movq %rbx, %rdi
leaq 0xc2cb7(%rip), %rsi     # 0x12e86d
xorl %eax, %eax
callq 0xde896
movq %rbx, %rdi
pushq $0x1
popq %rbp
movl %ebp, %esi
callq 0xdeba7
movq 0x50(%r12), %rsi
addq $0x18, %rsi
movq %r14, %rdi
leaq 0x9f509(%rip), %rdx     # 0x10b0e6
pushq $0x4
popq %rcx
movq %r15, %r8
callq 0xf1866
movq %r12, %rdi
movq %r15, %rsi
callq 0xf17ab
movq %r12, %rdi
movq %r15, %rsi
callq 0xf1766
movq 0x18(%r12), %rsi
addq $0x1a, %rsi
movq %rsi, 0x8(%rsp)
movq 0x18(%rbx), %rdi
movq 0x58(%r12), %rcx
movl 0x18(%r14), %r9d
pushq $0xc
popq %rdx
movl %ebp, %r8d
callq 0xe4c9a
movq 0x58(%r12), %rdi
callq 0xeb877
movq %rbx, %rdi
leaq 0xc2e26(%rip), %rsi     # 0x12ea5e
movq %rax, %rdx
xorl %eax, %eax
callq 0xde896
movq 0x20(%r12), %rdx
movq 0x30(%r12), %rcx
addq 0x18(%r12), %rdx
movq %rdx, 0x40(%r12)
movq %rbx, %rdi
leaq 0xad3cb(%rip), %rsi     # 0x11902b
xorl %eax, %eax
callq 0xde896
movq %rbx, %rdi
pushq $-0x1
popq %rsi
callq 0xdeba7
movq 0x30(%r12), %rax
addq 0x40(%r12), %rax
movq %rax, 0x8(%rsp)
jmp 0x6bb21
leaq 0xad55d(%rip), %rsi     # 0x1191ea
movq %rbx, %rdi
xorl %eax, %eax
callq 0xdf2a5
movl 0x14(%rsp), %esi
movq %rbx, %rdi
callq 0xdebb7
testq %r12, %r12
je 0x6bcb3
movq %rbx, %rdi
movq %r12, %rsi
callq 0xf167c
cmpb $0x0, 0x14(%r14)
je 0x6bccb
leaq 0xad541(%rip), %rsi     # 0x119202
movq %rbx, %rdi
xorl %eax, %eax
callq 0xdf2a5
movq %rbx, %rdi
movq %r14, %rsi
callq 0xf16e7
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq