// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/packit.c
// Function: packit_read_member_header
static void packit_read_member_header(deark *c, struct packit_ctx *d,
	struct packit_md *pmd)
{
	i64 pos = pmd->hdr_pos_in_inf;
	i64 n;
	u32 hdr_crc_reported;
	u32 hdr_crc_calc;
	char timestamp_buf[64];

	pmd->namelen = (i64)dbuf_getbyte_p(pmd->inf, &pos);
	if(pmd->namelen<1 || pmd->namelen>63) {
		d->fatalerrflag = 1;
		d->need_errmsg = 1;
		goto done;
	}
	pmd->fname = dbuf_read_string(pmd->inf, pos, pmd->namelen, pmd->namelen,
		0, DE_ENCODING_MACROMAN);
	de_dbg(c, "filename: \"%s\"", ucstring_getpsz(pmd->fname->str));
	pos += 63;

	dbuf_read_fourcc(pmd->inf, pos, &pmd->filetype, 4, 0x0);
	de_dbg(c, "filetype: '%s'", pmd->filetype.id_dbgstr);
	de_memcpy(pmd->advf->typecode, pmd->filetype.bytes, 4);
	pmd->advf->has_typecode = 1;
	pos += 4;
	dbuf_read_fourcc(pmd->inf, pos, &pmd->creator, 4, 0x0);
	de_dbg(c, "creator: '%s'", pmd->creator.id_dbgstr);
	de_memcpy(pmd->advf->creatorcode, pmd->creator.bytes, 4);
	pmd->advf->has_creatorcode = 1;
	pos += 4;

	pmd->finder_flags = (UI)dbuf_getu16be_p(pmd->inf, &pos);
	de_dbg(c, "finder flags: 0x%04x", pmd->finder_flags);
	pmd->advf->finderflags = (u16)pmd->finder_flags;
	pmd->advf->has_finderflags = 1;

	pos += 2; // "locked"

	pmd->dfork_pos = pmd->hdr_pos_in_inf + 94;
	pmd->dfork_len = dbuf_getu32be_p(pmd->inf, &pos);
	de_dbg(c, "data fork len: %"I64_FMT, pmd->dfork_len);
	pmd->advf->mainfork.fork_len = pmd->dfork_len;

	pmd->rfork_pos = pmd->dfork_pos + pmd->dfork_len;
	pmd->rfork_len = dbuf_getu32be_p(pmd->inf, &pos);
	de_dbg(c, "rsrc fork len: %"I64_FMT, pmd->rfork_len);
	pmd->advf->rsrcfork.fork_len = pmd->rfork_len;

	pmd->advf->mainfork.fork_exists = (pmd->dfork_len!=0 ||
		pmd->rfork_len==0);
	pmd->advf->rsrcfork.fork_exists = (pmd->rfork_len!=0);

	n = dbuf_getu32be_p(pmd->inf, &pos);
	de_mac_time_to_timestamp(n, &pmd->create_time);
	de_timestamp_to_string(&pmd->create_time, timestamp_buf, sizeof(timestamp_buf), 0);
	de_dbg(c, "create time: %"I64_FMT" (%s)", n, timestamp_buf);
	if(n > 100000000) {
		pmd->advf->mainfork.fi->timestamp[DE_TIMESTAMPIDX_CREATE] = pmd->create_time;
	}

	n = dbuf_getu32be_p(pmd->inf, &pos);
	de_mac_time_to_timestamp(n, &pmd->mod_time);
	de_timestamp_to_string(&pmd->mod_time, timestamp_buf, sizeof(timestamp_buf), 0);
	de_dbg(c, "mod time: %"I64_FMT" (%s)", n, timestamp_buf);
	// TODO: Many files have nonsense timestamps, and there's probably a reason.
	// Maybe they can be decoded.
	if(n > 100000000) {
		pmd->advf->mainfork.fi->timestamp[DE_TIMESTAMPIDX_MODIFY] = pmd->mod_time;
	}

	hdr_crc_reported = (u32)dbuf_getu16be_p(pmd->inf, &pos);
	de_dbg(c, "header crc (reported): 0x%04x", (UI)hdr_crc_reported);

	de_crcobj_reset(d->crco_hdr);
	de_crcobj_addslice(d->crco_hdr, pmd->inf, pmd->hdr_pos_in_inf, 92);
	hdr_crc_calc = de_crcobj_getval(d->crco_hdr);
	de_dbg(c, "header crc (calculated): 0x%04x", (UI)hdr_crc_calc);
	if(hdr_crc_reported != hdr_crc_calc) {
		// TODO: Maybe should be a warning? Or nonfatal?
		de_err(c, "Bad header CRC (reported 0x%04x, calculated 0x%04x)", (UI)hdr_crc_reported,
			(UI)hdr_crc_calc);
		d->fatalerrflag = 1;
		goto done;
	}

done:
	;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x80, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x20(%rbp)
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x20(%rbp), %rsi
callq 0x165170
movzbl %al, %eax
movl %eax, %ecx
movq -0x18(%rbp), %rax
movq %rcx, 0x28(%rax)
movq -0x18(%rbp), %rax
cmpq $0x1, 0x28(%rax)
jl 0x111ce7
movq -0x18(%rbp), %rax
cmpq $0x3f, 0x28(%rax)
jle 0x111cfb
movq -0x10(%rbp), %rax
movb $0x1, (%rax)
movq -0x10(%rbp), %rax
movb $0x1, 0x1(%rax)
jmp 0x1121a0
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x20(%rbp), %rsi
movq -0x18(%rbp), %rax
movq 0x28(%rax), %rdx
movq -0x18(%rbp), %rax
movq 0x28(%rax), %rcx
xorl %r8d, %r8d
movl $0x11, %r9d
callq 0x1664c0
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x40(%rax)
movq -0x8(%rbp), %rax
movq %rax, -0x80(%rbp)
movq -0x18(%rbp), %rax
movq 0x40(%rax), %rax
movq 0x18(%rax), %rdi
callq 0x172500
movq -0x80(%rbp), %rdi
movq %rax, %rdx
leaq 0xb582c(%rip), %rsi     # 0x1c7583
movb $0x0, %al
callq 0x15b0d0
movq -0x20(%rbp), %rax
addq $0x3f, %rax
movq %rax, -0x20(%rbp)
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x20(%rbp), %rsi
movq -0x18(%rbp), %rdx
addq $0x48, %rdx
movl $0x4, %ecx
xorl %r8d, %r8d
callq 0x169860
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rdx
addq $0x48, %rdx
addq $0x10, %rdx
leaq 0x8e965(%rip), %rsi     # 0x1a0707
movb $0x0, %al
callq 0x15b0d0
movq -0x18(%rbp), %rax
movq 0x38(%rax), %rax
movq -0x18(%rbp), %rcx
movl 0x48(%rcx), %ecx
movl %ecx, 0x90(%rax)
movq -0x18(%rbp), %rax
movq 0x38(%rax), %rax
movb $0x1, 0x7b(%rax)
movq -0x20(%rbp), %rax
addq $0x4, %rax
movq %rax, -0x20(%rbp)
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x20(%rbp), %rsi
movq -0x18(%rbp), %rdx
addq $0x78, %rdx
movl $0x4, %ecx
xorl %r8d, %r8d
callq 0x169860
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rdx
addq $0x78, %rdx
addq $0x10, %rdx
leaq 0xadf24(%rip), %rsi     # 0x1bfd32
movb $0x0, %al
callq 0x15b0d0
movq -0x18(%rbp), %rax
movq 0x38(%rax), %rax
movq -0x18(%rbp), %rcx
movl 0x78(%rcx), %ecx
movl %ecx, 0x94(%rax)
movq -0x18(%rbp), %rax
movq 0x38(%rax), %rax
movb $0x1, 0x7c(%rax)
movq -0x20(%rbp), %rax
addq $0x4, %rax
movq %rax, -0x20(%rbp)
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x20(%rbp), %rsi
callq 0x165210
movl %eax, %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x30(%rax)
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movl 0x30(%rax), %edx
leaq 0x8e8a8(%rip), %rsi     # 0x1a0716
movb $0x0, %al
callq 0x15b0d0
movq -0x18(%rbp), %rax
movl 0x30(%rax), %eax
movw %ax, %cx
movq -0x18(%rbp), %rax
movq 0x38(%rax), %rax
movw %cx, 0x7e(%rax)
movq -0x18(%rbp), %rax
movq 0x38(%rax), %rax
movb $0x1, 0x7d(%rax)
movq -0x20(%rbp), %rax
addq $0x2, %rax
movq %rax, -0x20(%rbp)
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rcx
addq $0x5e, %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0xc8(%rax)
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x20(%rbp), %rsi
callq 0x1654b0
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0xd0(%rax)
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0xd0(%rax), %rdx
leaq 0x8e83c(%rip), %rsi     # 0x1a072b
movb $0x0, %al
callq 0x15b0d0
movq -0x18(%rbp), %rax
movq 0xd0(%rax), %rcx
movq -0x18(%rbp), %rax
movq 0x38(%rax), %rax
movq %rcx, 0x18(%rax)
movq -0x18(%rbp), %rax
movq 0xc8(%rax), %rcx
movq -0x18(%rbp), %rax
addq 0xd0(%rax), %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0xd8(%rax)
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x20(%rbp), %rsi
callq 0x1654b0
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0xe0(%rax)
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0xe0(%rax), %rdx
leaq 0x8e7db(%rip), %rsi     # 0x1a073e
movb $0x0, %al
callq 0x15b0d0
movq -0x18(%rbp), %rax
movq 0xe0(%rax), %rcx
movq -0x18(%rbp), %rax
movq 0x38(%rax), %rax
movq %rcx, 0x40(%rax)
movq -0x18(%rbp), %rcx
movb $0x1, %al
cmpq $0x0, 0xd0(%rcx)
movb %al, -0x71(%rbp)
jne 0x111fa6
movq -0x18(%rbp), %rax
cmpq $0x0, 0xe0(%rax)
sete %al
movb %al, -0x71(%rbp)
movb -0x71(%rbp), %al
andb $0x1, %al
movzbl %al, %eax
movb %al, %cl
movq -0x18(%rbp), %rax
movq 0x38(%rax), %rax
movb %cl, 0x10(%rax)
movq -0x18(%rbp), %rax
cmpq $0x0, 0xe0(%rax)
setne %al
andb $0x1, %al
movzbl %al, %eax
movb %al, %cl
movq -0x18(%rbp), %rax
movq 0x38(%rax), %rax
movb %cl, 0x38(%rax)
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x20(%rbp), %rsi
callq 0x1654b0
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rdi
movq -0x18(%rbp), %rsi
addq $0xb8, %rsi
callq 0x15d720
movq -0x18(%rbp), %rdi
addq $0xb8, %rdi
leaq -0x70(%rbp), %rsi
movl $0x40, %edx
xorl %ecx, %ecx
callq 0x15e130
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rdx
leaq -0x70(%rbp), %rcx
leaq 0xb1c42(%rip), %rsi     # 0x1c3c75
movb $0x0, %al
callq 0x15b0d0
cmpq $0x5f5e100, -0x28(%rbp) # imm = 0x5F5E100
jle 0x11206a
movq -0x18(%rbp), %rax
movq 0x38(%rax), %rax
movq 0x20(%rax), %rax
movq -0x18(%rbp), %rcx
movq 0xb8(%rcx), %rdx
movq %rdx, 0x28(%rax)
movq 0xc0(%rcx), %rcx
movq %rcx, 0x30(%rax)
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x20(%rbp), %rsi
callq 0x1654b0
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rdi
movq -0x18(%rbp), %rsi
addq $0xa8, %rsi
callq 0x15d720
movq -0x18(%rbp), %rdi
addq $0xa8, %rdi
leaq -0x70(%rbp), %rsi
movl $0x40, %edx
xorl %ecx, %ecx
callq 0x15e130
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rdx
leaq -0x70(%rbp), %rcx
leaq 0x8c00b(%rip), %rsi     # 0x19e0cc
movb $0x0, %al
callq 0x15b0d0
cmpq $0x5f5e100, -0x28(%rbp) # imm = 0x5F5E100
jle 0x1120f8
movq -0x18(%rbp), %rax
movq 0x38(%rax), %rax
movq 0x20(%rax), %rax
movq -0x18(%rbp), %rcx
movq 0xa8(%rcx), %rdx
movq %rdx, 0x18(%rax)
movq 0xb0(%rcx), %rcx
movq %rcx, 0x20(%rax)
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x20(%rbp), %rsi
callq 0x165210
movl %eax, -0x2c(%rbp)
movq -0x8(%rbp), %rdi
movl -0x2c(%rbp), %edx
leaq 0xa601f(%rip), %rsi     # 0x1b8139
movb $0x0, %al
callq 0x15b0d0
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rdi
callq 0x15f250
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rdi
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rsi
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rdx
movl $0x5c, %ecx
callq 0x15f500
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rdi
callq 0x15f340
movl %eax, -0x30(%rbp)
movq -0x8(%rbp), %rdi
movl -0x30(%rbp), %edx
leaq 0xa8f03(%rip), %rsi     # 0x1bb071
movb $0x0, %al
callq 0x15b0d0
movl -0x2c(%rbp), %eax
cmpl -0x30(%rbp), %eax
je 0x11219e
movq -0x8(%rbp), %rdi
movl -0x2c(%rbp), %edx
movl -0x30(%rbp), %ecx
leaq 0xb1afd(%rip), %rsi     # 0x1c3c8b
movb $0x0, %al
callq 0x15bfb0
movq -0x10(%rbp), %rax
movb $0x1, (%rax)
jmp 0x1121a0
jmp 0x1121a0
addq $0x80, %rsp
popq %rbp
retq
nopl (%rax)