// File: /workspace/github_c_makefile_star2_O3/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
movq $0x0, 0x10(%rsp)
leaq 0xc(%rsp), %rsi
callq 0xe8a1c
movq %rbx, %rdi
callq 0xfd4b2
movq %rax, %r14
movl $0x1, 0x10(%rax)
movq %rbx, %rdi
xorl %esi, %esi
movl $0xd, %edx
callq 0xeb220
movl %eax, 0x18(%r14)
movq 0x18(%rbx), %rax
cmpq $0x0, 0x18(%rax)
jle 0x6faab
leaq 0x10(%rsp), %r12
xorl %r15d, %r15d
testq %r15, %r15
je 0x6f95d
movq %rbx, %rdi
movq %r15, %rsi
callq 0xfd460
movq %rbx, %rdi
movq %r14, %rsi
callq 0xfd414
movq %rax, %r15
movq 0x10(%rsp), %rax
movq %rax, 0x18(%r15)
movq 0x18(%rbx), %rdi
movq %r12, %rsi
callq 0xeeb91
movq %rax, %rbp
movq 0x18(%rbx), %rdi
movq %r12, %rsi
callq 0xeeb4b
movl %eax, %r13d
movq 0x18(%rbx), %rdi
movq %r12, %rsi
callq 0xeeb4b
movzbl %al, %ecx
movq %rcx, 0x20(%r15)
movq 0x18(%r15), %rdx
cmpl $0x5252, %ebp           # imm = 0x5252
jne 0x6fab9
cmpb $0x1, %r13b
jne 0x6fab9
cmpb $0x26, %al
jbe 0x6fab9
movq %rbx, %rdi
leaq 0xcc18c(%rip), %rsi     # 0x13bb5d
xorl %eax, %eax
callq 0xe8617
movq %rbx, %rdi
movl $0x1, %esi
callq 0xe8a15
movq 0x50(%r15), %rsi
addq $0x18, %rsi
movq %r14, %rdi
leaq 0xa87df(%rip), %rdx     # 0x1181d6
movl $0x4, %ecx
movq %r12, %r8
callq 0xfd638
movq %r15, %rdi
movq %r12, %rsi
callq 0xfd57d
movq %r15, %rdi
movq %r12, %rsi
callq 0xfd538
movq 0x18(%r15), %rsi
addq $0x1a, %rsi
movq %rsi, 0x10(%rsp)
movq 0x18(%rbx), %rdi
movq 0x58(%r15), %rcx
movl 0x18(%r14), %r9d
movl $0xc, %edx
movl $0x1, %r8d
callq 0xefbd7
movq 0x58(%r15), %rdi
callq 0xf70f6
movq %rbx, %rdi
leaq 0xcc2f8(%rip), %rsi     # 0x13bd4e
movq %rax, %rdx
xorl %eax, %eax
callq 0xe8617
movq 0x20(%r15), %rdx
movq 0x30(%r15), %rcx
addq 0x18(%r15), %rdx
movq %rdx, 0x40(%r15)
movq %rbx, %rdi
leaq 0xb67b1(%rip), %rsi     # 0x12622b
xorl %eax, %eax
callq 0xe8617
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0xe8a15
movq 0x30(%r15), %rax
addq 0x40(%r15), %rax
movq %rax, 0x10(%rsp)
movq 0x18(%rbx), %rcx
cmpq 0x18(%rcx), %rax
jl 0x6f94d
jmp 0x6faca
movl 0xc(%rsp), %esi
movq %rbx, %rdi
callq 0xe8a25
jmp 0x6fae1
leaq 0xb692a(%rip), %rsi     # 0x1263ea
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9295
movl 0xc(%rsp), %esi
movq %rbx, %rdi
callq 0xe8a25
movq %rbx, %rdi
movq %r15, %rsi
callq 0xfd460
cmpb $0x0, 0x14(%r14)
je 0x6faf9
leaq 0xb6913(%rip), %rsi     # 0x126402
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9295
movq %rbx, %rdi
movq %r14, %rsi
callq 0xfd4cd
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq