// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/nufx.c
// Function: do_nufx_record_header
static void do_nufx_record_header(deark *c,
	struct nufx_ctx *d, struct nufx_record *rec)
{
	i64 pos;
	i64 pos_of_fnlen_field;
	i64 pos_after_fnlen_field;
	i64 fnlen;
	u32 rh_crc_calc;
	UI tidx;
	int saved_indent_level;

	de_dbg_indent_save(c, &saved_indent_level);
	de_dbg(c, "record header at %"I64_FMT, rec->hdr_pos);
	de_dbg_indent(c, 1);

	pos = rec->hdr_pos+4;
	rec->header_crc = (u32)de_getu16le_p(&pos);
	de_dbg(c, "record header crc (reported): 0x%04x", (UI)rec->header_crc);

	rec->attrib_count = de_getu16le_p(&pos);
	de_dbg(c, "attrib count: %"I64_FMT, rec->attrib_count);
	pos_after_fnlen_field = rec->hdr_pos + rec->attrib_count;
	pos_of_fnlen_field = pos_after_fnlen_field - 2;

	rec->version = (UI)de_getu16le_p(&pos);
	de_dbg(c, "record version: %u", (UI)rec->version);

	rec->num_threads = (UI)de_getu32le_p(&pos);
	de_dbg(c, "total threads: %u", rec->num_threads);
	if(rec->num_threads > MAX_THREADS_PER_RECORD) {
		d->fatalerrflag = 1;
		d->need_errmsg = 1;
		goto done;
	}

	rec->filesys_id = (UI)de_getu16le_p(&pos);
	de_dbg(c, "filesys id: 0x%04x", rec->filesys_id);
	rec->filesys_info = (UI)de_getu16le_p(&pos);
	de_dbg(c, "filesys info: 0x%04x", rec->filesys_info);
	rec->access_code = (UI)de_getu32le_p(&pos);
	de_dbg(c, "access: 0x%08x", rec->access_code);
	rec->file_type = (u32)de_getu32le_p(&pos);
	de_dbg(c, "file type: 0x%08x", (UI)rec->file_type);
	rec->extra_type = (u32)de_getu32le_p(&pos);
	de_dbg(c, "extra type: 0x%08x", (UI)rec->extra_type);
	rec->storage_type = (UI)de_getu16le_p(&pos);
	de_dbg(c, "storage type: 0x%04x", rec->storage_type);

	nufx_read_datetime_to_timestamp_p(c->infile, &pos, &rec->create_time);
	dbg_timestamp(c, &rec->create_time, "create time");
	nufx_read_datetime_to_timestamp_p(c->infile, &pos, &rec->mod_time);
	dbg_timestamp(c, &rec->mod_time, "mod time");
	nufx_read_datetime_to_timestamp_p(c->infile, &pos, &rec->archived_time);
	dbg_timestamp(c, &rec->archived_time, "archived time");

	if(rec->version<1) goto read_fnlen;
	if(pos+2 > pos_of_fnlen_field) goto read_fnlen;

	rec->option_size = de_getu16le_p(&pos);
	if(pos+rec->option_size > pos_of_fnlen_field)  {
		rec->option_size = 0;
	}
	de_dbg(c, "option size: %"I64_FMT, rec->option_size);
	if(c->debug_level>=2) {
		de_dbg_hexdump(c, c->infile, pos, rec->option_size, 256, NULL, 0x1);
	}
	// Note: The spec. says something about padding option_size to an even
	// number of bytes, but we don't do anything that would rely on that.

read_fnlen:
	pos = pos_of_fnlen_field;
	fnlen = de_getu16le_p(&pos);
	if(fnlen>0 && !rec->filename_old) {
		rec->filename_old = ucstring_create(c);
		nufx_filename_to_ucstring(c, d, rec, c->infile, pos, fnlen, rec->filename_old);
		de_dbg(c, "filename (old style): \"%s\"",
			ucstring_getpsz_d(rec->filename_old));
	}
	pos += fnlen;

	rec->hdr_len = (pos + 16*(i64)rec->num_threads) - rec->hdr_pos;

	de_crcobj_reset(d->crco_misc);
	de_crcobj_addslice(d->crco_misc, c->infile, rec->hdr_pos+6,
		rec->hdr_len-6);
	rh_crc_calc = de_crcobj_getval(d->crco_misc);
	de_dbg(c, "record header crc (calculated): 0x%04x", (UI)rh_crc_calc);

	rec->threads = de_mallocarray(c, rec->num_threads, sizeof(struct nufx_thread));

	rec->cur_data_pos = rec->hdr_pos + rec->hdr_len;

	for(tidx=0; tidx<rec->num_threads; tidx++) {
		struct nufx_thread *t;

		t = &rec->threads[tidx];
		t->idx = tidx;
		read_thread_header(c, d, rec, t, pos);
		if(d->fatalerrflag) goto done;
		pos += 16;
	}

	d->next_record_pos = rec->cur_data_pos;

done:
	de_dbg_indent_restore(c, saved_indent_level);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x8(%rbp), %rdi
leaq -0x44(%rbp), %rsi
callq 0x15b580
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rdx
leaq 0xe4942(%rip), %rsi     # 0x1baf76
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movl $0x1, %esi
callq 0x15b560
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
addq $0x4, %rax
movq %rax, -0x20(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x20(%rbp), %rsi
callq 0x1652c0
movl %eax, %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x28(%rax)
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movl 0x28(%rax), %edx
leaq 0xe4906(%rip), %rsi     # 0x1baf8b
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x20(%rbp), %rsi
callq 0x1652c0
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x20(%rax)
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x20(%rax), %rdx
leaq 0xe48f5(%rip), %rsi     # 0x1bafb0
movb $0x0, %al
callq 0x15b0d0
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x18(%rbp), %rcx
addq 0x20(%rcx), %rax
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rax
subq $0x2, %rax
movq %rax, -0x28(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x20(%rbp), %rsi
callq 0x1652c0
movl %eax, %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0xc(%rax)
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movl 0xc(%rax), %edx
leaq 0xc9c40(%rip), %rsi     # 0x1a034e
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x20(%rbp), %rsi
callq 0x165580
movl %eax, %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x2c(%rax)
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movl 0x2c(%rax), %edx
leaq 0xe4881(%rip), %rsi     # 0x1bafc2
movb $0x0, %al
callq 0x15b0d0
movq -0x18(%rbp), %rax
cmpl $0x10, 0x2c(%rax)
jbe 0xd6766
movq -0x10(%rbp), %rax
movb $0x1, (%rax)
movq -0x10(%rbp), %rax
movb $0x1, 0x1(%rax)
jmp 0xd6bd5
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x20(%rbp), %rsi
callq 0x1652c0
movl %eax, %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x30(%rax)
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movl 0x30(%rax), %edx
leaq 0xe4842(%rip), %rsi     # 0x1bafd4
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x20(%rbp), %rsi
callq 0x1652c0
movl %eax, %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x34(%rax)
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movl 0x34(%rax), %edx
leaq 0xe4822(%rip), %rsi     # 0x1bafe7
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x20(%rbp), %rsi
callq 0x165580
movl %eax, %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x38(%rax)
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movl 0x38(%rax), %edx
leaq 0xe4804(%rip), %rsi     # 0x1baffc
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x20(%rbp), %rsi
callq 0x165580
movl %eax, %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x3c(%rax)
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movl 0x3c(%rax), %edx
leaq 0xe47e0(%rip), %rsi     # 0x1bb00b
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x20(%rbp), %rsi
callq 0x165580
movl %eax, %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x40(%rax)
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movl 0x40(%rax), %edx
leaq 0xe47bf(%rip), %rsi     # 0x1bb01d
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x20(%rbp), %rsi
callq 0x1652c0
movl %eax, %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x44(%rax)
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movl 0x44(%rax), %edx
leaq 0xdb631(%rip), %rsi     # 0x1b1ec2
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x18(%rbp), %rdx
addq $0x60, %rdx
leaq -0x20(%rbp), %rsi
callq 0xd64a0
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
addq $0x60, %rsi
leaq 0xe4658(%rip), %rdx     # 0x1baf1c
callq 0xd65b0
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x18(%rbp), %rdx
addq $0x70, %rdx
leaq -0x20(%rbp), %rsi
callq 0xd64a0
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
addq $0x70, %rsi
leaq 0xe327d(%rip), %rdx     # 0x1b9b72
callq 0xd65b0
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x18(%rbp), %rdx
addq $0x80, %rdx
leaq -0x20(%rbp), %rsi
callq 0xd64a0
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
addq $0x80, %rsi
leaq 0xe4704(%rip), %rdx     # 0x1bb030
callq 0xd65b0
movq -0x18(%rbp), %rax
cmpl $0x1, 0xc(%rax)
jae 0xd6940
jmp 0xd69e1
movq -0x20(%rbp), %rax
addq $0x2, %rax
cmpq -0x28(%rbp), %rax
jle 0xd6953
jmp 0xd69e1
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x20(%rbp), %rsi
callq 0x1652c0
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x50(%rax)
movq -0x20(%rbp), %rax
movq -0x18(%rbp), %rcx
addq 0x50(%rcx), %rax
cmpq -0x28(%rbp), %rax
jle 0xd698d
movq -0x18(%rbp), %rax
movq $0x0, 0x50(%rax)
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x50(%rax), %rdx
leaq 0xe469e(%rip), %rsi     # 0x1bb03e
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rax
cmpl $0x2, (%rax)
jl 0xd69df
movq -0x8(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rsi
movq -0x20(%rbp), %rdx
movq -0x18(%rbp), %rax
movq 0x50(%rax), %rcx
movl $0x100, %r8d            # imm = 0x100
xorl %eax, %eax
movl %eax, %r9d
movl $0x1, (%rsp)
callq 0x15b840
jmp 0xd69e1
movq -0x28(%rbp), %rax
movq %rax, -0x20(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x20(%rbp), %rsi
callq 0x1652c0
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x38(%rbp)
jle 0xd6a8b
movq -0x18(%rbp), %rax
cmpq $0x0, 0x90(%rax)
jne 0xd6a8b
movq -0x8(%rbp), %rdi
callq 0x1711d0
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x90(%rax)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rcx
movq -0x20(%rbp), %r8
movq -0x38(%rbp), %r9
movq -0x18(%rbp), %rax
movq 0x90(%rax), %rax
movq %rax, (%rsp)
callq 0xd6e90
movq -0x8(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x18(%rbp), %rax
movq 0x90(%rax), %rdi
callq 0x172650
movq -0x58(%rbp), %rdi
movq %rax, %rdx
leaq 0xe45cb(%rip), %rsi     # 0x1bb04f
movb $0x0, %al
callq 0x15b0d0
movq -0x38(%rbp), %rax
addq -0x20(%rbp), %rax
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rcx
movq -0x18(%rbp), %rax
movl 0x2c(%rax), %eax
shlq $0x4, %rax
addq %rax, %rcx
movq -0x18(%rbp), %rax
subq 0x10(%rax), %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x10(%rbp), %rax
movq 0x50(%rax), %rdi
callq 0x15f250
movq -0x10(%rbp), %rax
movq 0x50(%rax), %rdi
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rsi
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rdx
addq $0x6, %rdx
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rcx
subq $0x6, %rcx
callq 0x15f500
movq -0x10(%rbp), %rax
movq 0x50(%rax), %rdi
callq 0x15f340
movl %eax, -0x3c(%rbp)
movq -0x8(%rbp), %rdi
movl -0x3c(%rbp), %edx
leaq 0xe4559(%rip), %rsi     # 0x1bb06a
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movl 0x2c(%rax), %eax
movl %eax, %esi
movl $0x50, %edx
callq 0x15c450
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0xa0(%rax)
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rcx
movq -0x18(%rbp), %rax
addq 0x18(%rax), %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x58(%rax)
movl $0x0, -0x40(%rbp)
movl -0x40(%rbp), %eax
movq -0x18(%rbp), %rcx
cmpl 0x2c(%rcx), %eax
jae 0xd6bc5
movq -0x18(%rbp), %rax
movq 0xa0(%rax), %rax
movl -0x40(%rbp), %ecx
imulq $0x50, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x50(%rbp)
movl -0x40(%rbp), %ecx
movq -0x50(%rbp), %rax
movl %ecx, (%rax)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
movq -0x50(%rbp), %rcx
movq -0x20(%rbp), %r8
callq 0xd6fc0
movq -0x10(%rbp), %rax
cmpb $0x0, (%rax)
je 0xd6bae
jmp 0xd6bd5
movq -0x20(%rbp), %rax
addq $0x10, %rax
movq %rax, -0x20(%rbp)
movl -0x40(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x40(%rbp)
jmp 0xd6b5c
movq -0x18(%rbp), %rax
movq 0x58(%rax), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x28(%rax)
movq -0x8(%rbp), %rdi
movl -0x44(%rbp), %esi
callq 0x15b5a0
addq $0x60, %rsp
popq %rbp
retq
nopw (%rax,%rax)