// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/arc.c
// Function: do_pak_ext_record
static int do_pak_ext_record(deark *c, lctx *d, i64 pos1, i64 *pbytes_consumed)
{
	i64 pos = pos1;
	u8 rectype;
	const char *rtname = "?";
	int retval = 0;
	i64 filenum;
	i64 filenum_adj = 0;
	i64 dlen;
	de_ucstring *archive_comment = NULL;
	struct persistent_member_data *pmd = NULL;
	int saved_indent_level;

	de_dbg_indent_save(c, &saved_indent_level);
	*pbytes_consumed = 0;
	if(de_getbyte_p(&pos) != 0xfe) goto done;
	de_dbg(c, "record at %"I64_FMT, pos1);
	de_dbg_indent(c, 1);

	rectype = de_getbyte_p(&pos);
	switch(rectype) {
	case 0: rtname = "end"; break;
	case 1: rtname = "remark"; break;
	case 2: rtname = "path"; break;
	case 3: rtname = "security envelope"; break;
	}
	de_dbg(c, "rectype: %d (%s)", (int)rectype, rtname);
	if(rectype==0) {
		*pbytes_consumed = 2;
		goto done;
	}

	filenum = de_getu16le_p(&pos);
	de_dbg(c, "file num: %d", (int)filenum);
	dlen = de_getu32le_p(&pos);
	de_dbg(c, "dlen: %"I64_FMT, dlen);
	if(pos+dlen > c->infile->len) goto done;

	*pbytes_consumed = 8 + dlen;
	retval = 1;

	if(filenum > 0) {
		filenum_adj = filenum - 1;
		if(filenum_adj < d->num_top_level_members) {
			pmd = &d->persistent_md[filenum_adj];
		}
	}

	if(rectype==1) { // remark
		if(filenum==0) { // archive comment
			archive_comment = ucstring_create(c);
			dbuf_read_to_ucstring_n(c->infile, pos, dlen, 16384, archive_comment,
				0, d->input_encoding_for_comments);
			de_dbg(c, "archive comment: \"%s\"", ucstring_getpsz_d(archive_comment));
		}
		else { // file comment
			if(!pmd) goto done;

			if(!pmd->comment) {
				pmd->comment = ucstring_create(c);
			}
			if(ucstring_isnonempty(pmd->comment)) goto done;
			dbuf_read_to_ucstring_n(c->infile, pos, dlen, 2048, pmd->comment,
				0, d->input_encoding_for_comments);
		}
	}
	else if(rectype==2) {
		if(!pmd) goto done;
		if(!pmd->path) {
			pmd->path = ucstring_create(c);
		}
		if(ucstring_isnonempty(pmd->path)) goto done;
		dbuf_read_to_ucstring_n(c->infile, pos, dlen, 512, pmd->path,
			0, d->input_encoding_for_comments);
	}

done:
	if(archive_comment) ucstring_destroy(archive_comment);
	de_dbg_indent_restore(c, saved_indent_level);
	return retval;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x90, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x28(%rbp)
leaq 0x186e63(%rip), %rax    # 0x1b7c2d
movq %rax, -0x38(%rbp)
movl $0x0, -0x3c(%rbp)
movq $0x0, -0x50(%rbp)
movq $0x0, -0x60(%rbp)
movq $0x0, -0x68(%rbp)
movq -0x8(%rbp), %rdi
leaq -0x6c(%rbp), %rsi
callq 0x15b580
movq -0x20(%rbp), %rax
movq $0x0, (%rax)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x28(%rbp), %rsi
callq 0x165170
movzbl %al, %eax
cmpl $0xfe, %eax
je 0x30e25
jmp 0x31102
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rdx
leaq 0x16f448(%rip), %rsi    # 0x1a027c
xorl %eax, %eax
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movl $0x1, %esi
callq 0x15b560
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x28(%rbp), %rsi
callq 0x165170
movb %al, -0x29(%rbp)
movzbl -0x29(%rbp), %eax
movq %rax, -0x78(%rbp)
subq $0x3, %rax
ja 0x30eb1
movq -0x78(%rbp), %rax
leaq 0x16f562(%rip), %rcx    # 0x1a03d8
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
leaq 0x1a8168(%rip), %rax    # 0x1d8fee
movq %rax, -0x38(%rbp)
jmp 0x30eb1
leaq 0x16f75e(%rip), %rax    # 0x1a05f1
movq %rax, -0x38(%rbp)
jmp 0x30eb1
leaq 0x18de06(%rip), %rax    # 0x1beca6
movq %rax, -0x38(%rbp)
jmp 0x30eb1
leaq 0x172e9b(%rip), %rax    # 0x1a3d48
movq %rax, -0x38(%rbp)
movq -0x8(%rbp), %rdi
movzbl -0x29(%rbp), %edx
movq -0x38(%rbp), %rcx
leaq 0x16f734(%rip), %rsi    # 0x1a05f8
movb $0x0, %al
callq 0x15b0d0
movzbl -0x29(%rbp), %eax
cmpl $0x0, %eax
jne 0x30ee4
movq -0x20(%rbp), %rax
movq $0x2, (%rax)
jmp 0x31102
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x28(%rbp), %rsi
callq 0x1652c0
movq %rax, -0x48(%rbp)
movq -0x8(%rbp), %rdi
movq -0x48(%rbp), %rax
movl %eax, %edx
leaq 0x16f6ff(%rip), %rsi    # 0x1a0609
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x28(%rbp), %rsi
callq 0x165580
movq %rax, -0x58(%rbp)
movq -0x8(%rbp), %rdi
movq -0x58(%rbp), %rdx
leaq 0x1a046f(%rip), %rsi    # 0x1d13a4
movb $0x0, %al
callq 0x15b0d0
movq -0x28(%rbp), %rax
addq -0x58(%rbp), %rax
movq -0x8(%rbp), %rcx
movq 0x18(%rcx), %rcx
cmpq 0x18(%rcx), %rax
jle 0x30f57
jmp 0x31102
movq -0x58(%rbp), %rcx
addq $0x8, %rcx
movq -0x20(%rbp), %rax
movq %rcx, (%rax)
movl $0x1, -0x3c(%rbp)
cmpq $0x0, -0x48(%rbp)
jle 0x30fa7
movq -0x48(%rbp), %rax
subq $0x1, %rax
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rax
movq -0x10(%rbp), %rcx
cmpq 0x38(%rcx), %rax
jge 0x30fa5
movq -0x10(%rbp), %rax
movq 0x58(%rax), %rax
movq -0x50(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq %rax, -0x68(%rbp)
jmp 0x30fa7
movzbl -0x29(%rbp), %eax
cmpl $0x1, %eax
jne 0x3108a
cmpq $0x0, -0x48(%rbp)
jne 0x3101b
movq -0x8(%rbp), %rdi
callq 0x1711d0
movq %rax, -0x60(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x28(%rbp), %rsi
movq -0x58(%rbp), %rdx
movq -0x60(%rbp), %r8
movq -0x10(%rbp), %rax
movl 0x14(%rax), %eax
movl $0x4000, %ecx           # imm = 0x4000
xorl %r9d, %r9d
movl %eax, (%rsp)
callq 0x166a40
movq -0x8(%rbp), %rax
movq %rax, -0x80(%rbp)
movq -0x60(%rbp), %rdi
callq 0x172650
movq -0x80(%rbp), %rdi
movq %rax, %rdx
leaq 0x16f588(%rip), %rsi    # 0x1a059a
movb $0x0, %al
callq 0x15b0d0
jmp 0x31088
cmpq $0x0, -0x68(%rbp)
jne 0x31027
jmp 0x31102
movq -0x68(%rbp), %rax
cmpq $0x0, (%rax)
jne 0x31044
movq -0x8(%rbp), %rdi
callq 0x1711d0
movq %rax, %rcx
movq -0x68(%rbp), %rax
movq %rcx, (%rax)
movq -0x68(%rbp), %rax
movq (%rax), %rdi
callq 0x1717f0
cmpl $0x0, %eax
je 0x3105a
jmp 0x31102
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x28(%rbp), %rsi
movq -0x58(%rbp), %rdx
movq -0x68(%rbp), %rax
movq (%rax), %r8
movq -0x10(%rbp), %rax
movl 0x14(%rax), %eax
movl $0x800, %ecx            # imm = 0x800
xorl %r9d, %r9d
movl %eax, (%rsp)
callq 0x166a40
jmp 0x31100
movzbl -0x29(%rbp), %eax
cmpl $0x2, %eax
jne 0x310fe
cmpq $0x0, -0x68(%rbp)
jne 0x3109c
jmp 0x31102
movq -0x68(%rbp), %rax
cmpq $0x0, 0x8(%rax)
jne 0x310bb
movq -0x8(%rbp), %rdi
callq 0x1711d0
movq %rax, %rcx
movq -0x68(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x68(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0x1717f0
cmpl $0x0, %eax
je 0x310cf
jmp 0x31102
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x28(%rbp), %rsi
movq -0x58(%rbp), %rdx
movq -0x68(%rbp), %rax
movq 0x8(%rax), %r8
movq -0x10(%rbp), %rax
movl 0x14(%rax), %eax
movl $0x200, %ecx            # imm = 0x200
xorl %r9d, %r9d
movl %eax, (%rsp)
callq 0x166a40
jmp 0x31100
jmp 0x31102
cmpq $0x0, -0x60(%rbp)
je 0x31112
movq -0x60(%rbp), %rdi
callq 0x171750
movq -0x8(%rbp), %rdi
movl -0x6c(%rbp), %esi
callq 0x15b5a0
movl -0x3c(%rbp), %eax
addq $0x90, %rsp
popq %rbp
retq
nopw (%rax,%rax)