// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/rar.c
// Function: do_rar5_file_or_service_hdr
static void do_rar5_file_or_service_hdr(deark *c, de_arch_lctx *d, struct rar5_block *rb)
{
	UI u;
	i64 namelen;
	i64 pos;
	struct rar5_file_or_svc_hdr_data *hd = NULL;

	hd = de_malloc(c, sizeof(struct rar5_file_or_svc_hdr_data));
	pos = rb->pos_after_standard_fields;

	if(rb->type==RAR5_HDRTYPE_FILE) {
		on_rar5_file_begin(c, d);
	}

	hd->file_flags = (UI)rar_get_vint_p(d, c->infile, &pos);
	de_dbg(c, "file flags: 0x%x", hd->file_flags);
	hd->orig_len = rar_get_vint_i64_p(d, c->infile, &pos);
	de_dbg(c, "original size: %"I64_FMT, hd->orig_len);
	de_sanitize_length(&hd->orig_len);
	hd->attribs = rar_get_vint_p(d, c->infile, &pos);
	de_dbg(c, "attribs: 0x%"U64_FMTx, hd->attribs);

	if(hd->file_flags & 0x2) { // TODO: Test this
		de_arch_read_field_dttm_p(d, &hd->mtime1, "mod", DE_ARCH_TSTYPE_UNIX_U, &pos);
	}
	if(hd->file_flags & 0x4) {
		hd->crc_reported = (u32)de_getu32le_p(&pos);
		de_dbg(c, "data crc: 0x%08x", (UI)hd->crc_reported);
	}

	hd->cmpr_info = (UI)rar_get_vint_p(d, c->infile, &pos);
	de_dbg(c, "cmpr info: 0x%x", hd->cmpr_info);
	de_dbg_indent(c, 1);
	u = hd->cmpr_info & 0x3f;
	de_dbg(c, "version: %u", u);
	u = (hd->cmpr_info >> 6) & 0x1;
	de_dbg(c, "solid: %u", u);
	hd->cmpr_meth = (hd->cmpr_info >> 7) & 0x7;
	de_dbg(c, "method: %u", hd->cmpr_meth);
	u = (hd->cmpr_info >> 10) & 0xf;
	de_dbg(c, "dict size: %u (%uk)", u, (UI)(128<<u));
	de_dbg_indent(c, -1);

	hd->os = (UI)rar_get_vint_p(d, c->infile, &pos);
	de_dbg(c, "os: %u", hd->os);

	namelen = rar_get_vint_i64_p(d, c->infile, &pos);
#define RAR_MAX_NAMELEN 65535
	if(namelen > RAR_MAX_NAMELEN) goto done;

	hd->name_srd = dbuf_read_string(c->infile, pos, namelen, namelen, 0,
		DE_ENCODING_UTF8);
	de_dbg(c, "name: \"%s\"", ucstring_getpsz_d(hd->name_srd->str));

	if(rb->type==RAR5_HDRTYPE_SERVICE) {
		if(!de_strcmp(hd->name_srd->sz, "CMT")) {
			do_rar5_comment(c, d, rb, hd);
		}
	}
done:
	if(hd) {
		de_destroy_stringreaderdata(c, hd->name_srd);
		de_free(c, hd);
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq $0x0, -0x38(%rbp)
movq -0x8(%rbp), %rdi
movl $0x40, %esi
callq 0x15b780
movq %rax, -0x38(%rbp)
movq -0x18(%rbp), %rax
movq 0x40(%rax), %rax
movq %rax, -0x30(%rbp)
movq -0x18(%rbp), %rax
cmpl $0x2, 0x14(%rax)
jne 0x152811
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x152dc0
movq -0x10(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rsi
leaq -0x30(%rbp), %rdx
callq 0x152690
movl %eax, %ecx
movq -0x38(%rbp), %rax
movl %ecx, (%rax)
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rax
movl (%rax), %edx
leaq 0x7e8ca(%rip), %rsi     # 0x1d1109
movb $0x0, %al
callq 0x15b0d0
movq -0x10(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rsi
leaq -0x30(%rbp), %rdx
callq 0x152640
movq %rax, %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rax
movq 0x10(%rax), %rdx
leaq 0x51690(%rip), %rsi     # 0x1a3f09
movb $0x0, %al
callq 0x15b0d0
movq -0x38(%rbp), %rdi
addq $0x10, %rdi
callq 0x15f830
movq -0x10(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rsi
leaq -0x30(%rbp), %rdx
callq 0x152690
movq %rax, %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rax
movq 0x8(%rax), %rdx
leaq 0x7e85a(%rip), %rsi     # 0x1d111a
movb $0x0, %al
callq 0x15b0d0
movq -0x38(%rbp), %rax
movl (%rax), %eax
andl $0x2, %eax
cmpl $0x0, %eax
je 0x1528f6
movq -0x10(%rbp), %rdi
movq -0x38(%rbp), %rsi
addq $0x28, %rsi
leaq 0x5160b(%rip), %rdx     # 0x1a3ef3
movl $0x2, %ecx
leaq -0x30(%rbp), %r8
callq 0x17c580
movq -0x38(%rbp), %rax
movl (%rax), %eax
andl $0x4, %eax
cmpl $0x0, %eax
je 0x152937
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x30(%rbp), %rsi
callq 0x165580
movl %eax, %ecx
movq -0x38(%rbp), %rax
movl %ecx, 0x18(%rax)
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rax
movl 0x18(%rax), %edx
leaq 0x7e7f9(%rip), %rsi     # 0x1d1129
movb $0x0, %al
callq 0x15b0d0
movq -0x10(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rsi
leaq -0x30(%rbp), %rdx
callq 0x152690
movl %eax, %ecx
movq -0x38(%rbp), %rax
movl %ecx, 0x1c(%rax)
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rax
movl 0x1c(%rax), %edx
leaq 0x7e7d3(%rip), %rsi     # 0x1d113a
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movl $0x1, %esi
callq 0x15b560
movq -0x38(%rbp), %rax
movl 0x1c(%rax), %eax
andl $0x3f, %eax
movl %eax, -0x1c(%rbp)
movq -0x8(%rbp), %rdi
movl -0x1c(%rbp), %edx
leaq 0x6fcef(%rip), %rsi     # 0x1c2686
movb $0x0, %al
callq 0x15b0d0
movq -0x38(%rbp), %rax
movl 0x1c(%rax), %eax
shrl $0x6, %eax
andl $0x1, %eax
movl %eax, -0x1c(%rbp)
movq -0x8(%rbp), %rdi
movl -0x1c(%rbp), %edx
leaq 0x7e78e(%rip), %rsi     # 0x1d114a
movb $0x0, %al
callq 0x15b0d0
movq -0x38(%rbp), %rax
movl 0x1c(%rax), %ecx
shrl $0x7, %ecx
andl $0x7, %ecx
movq -0x38(%rbp), %rax
movl %ecx, 0x20(%rax)
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rax
movl 0x20(%rax), %edx
leaq 0x5ed06(%rip), %rsi     # 0x1b16ef
movb $0x0, %al
callq 0x15b0d0
movq -0x38(%rbp), %rax
movl 0x1c(%rax), %eax
shrl $0xa, %eax
andl $0xf, %eax
movl %eax, -0x1c(%rbp)
movq -0x8(%rbp), %rdi
movl -0x1c(%rbp), %edx
movl -0x1c(%rbp), %ecx
movl $0x80, %eax
shll %cl, %eax
movl %eax, %ecx
leaq 0x7e73a(%rip), %rsi     # 0x1d1154
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x15b560
movq -0x10(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rsi
leaq -0x30(%rbp), %rdx
callq 0x152690
movl %eax, %ecx
movq -0x38(%rbp), %rax
movl %ecx, 0x24(%rax)
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rax
movl 0x24(%rax), %edx
leaq 0x7e709(%rip), %rsi     # 0x1d1168
movb $0x0, %al
callq 0x15b0d0
movq -0x10(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rsi
leaq -0x30(%rbp), %rdx
callq 0x152640
movq %rax, -0x28(%rbp)
cmpq $0xffff, -0x28(%rbp)    # imm = 0xFFFF
jle 0x152a8e
jmp 0x152b29
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x30(%rbp), %rsi
movq -0x28(%rbp), %rdx
movq -0x28(%rbp), %rcx
xorl %r8d, %r8d
movl $0x2, %r9d
callq 0x1664c0
movq %rax, %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x38(%rax)
movq -0x8(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x38(%rbp), %rax
movq 0x38(%rax), %rax
movq 0x18(%rax), %rdi
callq 0x172650
movq -0x40(%rbp), %rdi
movq %rax, %rdx
leaq 0x5b6ee(%rip), %rsi     # 0x1ae1d0
movb $0x0, %al
callq 0x15b0d0
movq -0x18(%rbp), %rax
cmpl $0x3, 0x14(%rax)
jne 0x152b27
movq -0x38(%rbp), %rax
movq 0x38(%rax), %rax
movq 0x8(%rax), %rdi
leaq 0x7e669(%rip), %rsi     # 0x1d116f
callq 0x191a0
cmpl $0x0, %eax
jne 0x152b25
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
movq -0x38(%rbp), %rcx
callq 0x152e00
jmp 0x152b27
jmp 0x152b29
cmpq $0x0, -0x38(%rbp)
je 0x152b4e
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rax
movq 0x38(%rax), %rsi
callq 0x166830
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rsi
callq 0x15b820
addq $0x40, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)