// File: /workspace/github_c_makefile_star2_O1/jsummers[P]deark/modules/rar.c
// Function: rar_read_v4_block
static void rar_read_v4_block(deark *c, de_arch_lctx *d, struct rar4_block *rb)
{
	int saved_indent_level;
	i64 pos;
	i64 n;
	u32 crc_calc;
	de_ucstring *descr = NULL;

	de_dbg_indent_save(c, &saved_indent_level);
	pos = rb->block_pos;

	de_dbg(c, "block at %"I64_FMT, rb->block_pos);
	de_dbg_indent(c, 1);
	rb->crc_reported = (u32)de_getu16le_p(&pos);
	de_dbg(c, "crc (reported): 0x%04x", (UI)rb->crc_reported);

	rb->type = de_getbyte_p(&pos);
	de_dbg(c, "block type: 0x%02x (%s)", (UI)rb->type, rar_get_v4_blktype_name(rb->type));

	// The only nested block allowed is a comment block.
	if(rb->parent_type!=0 && rb->type!=0x75) goto done;

	if(rb->type==0x7b) {
		rb->last_block = 1;
	}

	rb->flags = (UI)de_getu16le_p(&pos);
	descr = ucstring_create(c);
	get_rar4_flags_descr(rb, descr);
	de_dbg(c, "block flags: 0x%04x (%s)", (UI)rb->flags, ucstring_getpsz_d(descr));

	rb->block_size_1 = de_getu16le_p(&pos);
	de_dbg(c, "block size (part 1): %"I64_FMT, rb->block_size_1);
	if(rb->block_pos + rb->block_size_1 > rb->block_max_endpos) goto done;

	if(rb->type==0x75) n = 11; // Special case for old-style comment blocks
	else n = rb->block_size_1-2;
	de_crcobj_reset(d->crco);
	de_crcobj_addslice(d->crco, c->infile, rb->block_pos+2, n);
	crc_calc = de_crcobj_getval(d->crco);
	crc_calc &= 0xffff;
	de_dbg(c, "crc (calculated): 0x%04x", (UI)crc_calc);

	if(rb->flags & 0x8000) {
		rb->block_size_2 = de_getu32le_p(&pos);
		de_dbg(c, "block size (part 2): %"I64_FMT, rb->block_size_2);
	}

	if((rb->type==0x74 || rb->type==0x7a) && (rb->flags & 0x0100)) {
		rb->block_size_high = de_getu32le(pos+17); // HIGH_PACK_SIZE
		if(rb->block_size_high > 0x7ffffffe) {
			// Legal, but we can't allow integer overflow (after <<32
			// then adding 0xffffffff + 0xffff).
			goto done;
		}
		rb->block_size_high <<= 32;
	}

	rb->data1_pos = pos;
	rb->data2_pos = rb->block_pos + rb->block_size_1;

	rb->block_size_full = rb->block_size_1 + rb->block_size_2 + rb->block_size_high;
	de_dbg(c, "block size (total): %"I64_FMT, rb->block_size_full);
	if(rb->block_pos + rb->block_size_full > rb->block_max_endpos) goto done;
	rb->parsed_ok = 1;

	switch(rb->type) {
	case 0x73:
		do_rar4_block_archiveheader(c, d, rb);
		break;
	case 0x74:
	case 0x7a:
		do_rar4_block_fileheader(c, d, rb);
		break;
	case 0x75:
		do_rar4_block_oldcomment(c, d, rb);
		break;
	case 0x77:
		do_rar4_block_oldsubblock(c, d, rb);
		break;
	}

done:
	ucstring_destroy(descr);
	de_dbg_indent_restore(c, saved_indent_level);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rdx, %r12
movq %rsi, %r14
movq %rdi, %rbx
leaq 0x34(%rsp), %rsi
callq 0xe958c
movq (%r12), %rdx
leaq 0x28(%rsp), %r15
movq %rdx, (%r15)
leaq 0x4d991(%rip), %rsi     # 0x13107d
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9226
movq %rbx, %rdi
movl $0x1, %esi
callq 0xe9585
movq 0x18(%rbx), %rdi
movq %r15, %rsi
callq 0xef1ed
movl %eax, 0x10(%r12)
leaq 0x61231(%rip), %rsi     # 0x14494c
movq %rbx, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xe9226
movq 0x18(%rbx), %rdi
movq %r15, %rsi
callq 0xef14d
movb %al, 0x18(%r12)
movzbl %al, %edx
leal -0x72(%rdx), %eax
cmpb $0x9, %al
ja 0xe3755
movzbl %al, %eax
leaq 0x61590(%rip), %rsi     # 0x144cdc
movslq (%rsi,%rax,4), %rcx
addq %rsi, %rcx
jmp 0xe375c
leaq 0x4870d(%rip), %rcx     # 0x12be69
leaq 0x616fd(%rip), %rsi     # 0x144e60
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9226
cmpb $0x0, 0x19(%r12)
je 0xe3781
cmpb $0x75, 0x18(%r12)
jne 0xe3908
cmpb $0x7b, 0x18(%r12)
jne 0xe378f
movb $0x1, 0x1b(%r12)
movq 0x18(%rbx), %rdi
leaq 0x28(%rsp), %rsi
callq 0xef1ed
movl %eax, 0x14(%r12)
movq %rbx, %rdi
callq 0xf6870
movq %rax, %r15
movl 0x14(%r12), %ebp
movq %rax, %rdi
callq 0xf6883
movzbl 0x18(%r12), %eax
cmpl $0x7a, %eax
je 0xe3873
cmpl $0x74, %eax
je 0xe3873
cmpl $0x73, %eax
jne 0xe39c5
testb $0x1, %bpl
je 0xe37f2
leaq 0x4ee22(%rip), %rsi     # 0x13260a
movq %r15, %rdi
callq 0xf7566
decl %ebp
testb $0x2, %bpl
je 0xe380a
leaq 0x6170f(%rip), %rsi     # 0x144f0e
movq %r15, %rdi
callq 0xf7566
addl $-0x2, %ebp
testb $0x4, %bpl
je 0xe3822
leaq 0x4b246(%rip), %rsi     # 0x12ea5d
movq %r15, %rdi
callq 0xf7566
addl $-0x4, %ebp
testb $0x8, %bpl
je 0xe383a
leaq 0x3a76c(%rip), %rsi     # 0x11df9b
movq %r15, %rdi
callq 0xf7566
addl $-0x8, %ebp
testb $0x20, %bpl
je 0xe3852
leaq 0x616d9(%rip), %rsi     # 0x144f20
movq %r15, %rdi
callq 0xf7566
addl $-0x20, %ebp
testb $0x40, %bpl
je 0xe39c5
leaq 0x616d1(%rip), %rsi     # 0x144f34
movq %r15, %rdi
callq 0xf7566
addl $-0x40, %ebp
jmp 0xe39c5
testb $0x1, %bpl
je 0xe388a
leaq 0x616c8(%rip), %rsi     # 0x144f48
movq %r15, %rdi
callq 0xf7566
decl %ebp
testb $0x2, %bpl
je 0xe38a2
leaq 0x616c9(%rip), %rsi     # 0x144f60
movq %r15, %rdi
callq 0xf7566
addl $-0x2, %ebp
testb $0x4, %bpl
je 0xe38ba
leaq 0x5e538(%rip), %rsi     # 0x141de7
movq %r15, %rdi
callq 0xf7566
addl $-0x4, %ebp
testb $0x8, %bpl
je 0xe38d2
leaq 0x61647(%rip), %rsi     # 0x144f0e
movq %r15, %rdi
callq 0xf7566
addl $-0x8, %ebp
testb $0x10, %bpl
je 0xe38ea
leaq 0x3a6bc(%rip), %rsi     # 0x11df9b
movq %r15, %rdi
callq 0xf7566
addl $-0x10, %ebp
movl %ebp, %ecx
shrl $0x5, %ecx
andl $0x7, %ecx
cmpl $0x7, %ecx
jne 0xe3910
leaq 0x30274(%rip), %rsi     # 0x113b72
movq %r15, %rdi
callq 0xf7566
jmp 0xe3928
xorl %r15d, %r15d
jmp 0xe403a
movl $0x40, %edx
shll %cl, %edx
leaq 0x61658(%rip), %rsi     # 0x144f76
movq %r15, %rdi
xorl %eax, %eax
callq 0xf7593
movl %ebp, %r13d
andl $0xffffff1f, %r13d      # imm = 0xFFFFFF1F
btl $0x8, %ebp
jae 0xe394e
leaq 0x478c0(%rip), %rsi     # 0x12b1ff
movq %r15, %rdi
callq 0xf7566
addl $0xffffff00, %r13d      # imm = 0xFFFFFF00
btl $0x9, %r13d
jae 0xe396b
leaq 0x61623(%rip), %rsi     # 0x144f7f
movq %r15, %rdi
callq 0xf7566
addl $0xfffffe00, %r13d      # imm = 0xFFFFFE00
btl $0xa, %r13d
jae 0xe3988
leaq 0x61617(%rip), %rsi     # 0x144f90
movq %r15, %rdi
callq 0xf7566
addl $0xfffffc00, %r13d      # imm = 0xFFFFFC00
btl $0xb, %r13d
jae 0xe39a5
leaq 0x615ff(%rip), %rsi     # 0x144f95
movq %r15, %rdi
callq 0xf7566
addl $0xfffff800, %r13d      # imm = 0xFFFFF800
btl $0xc, %r13d
jae 0xe39c2
leaq 0x615ee(%rip), %rsi     # 0x144fa1
movq %r15, %rdi
callq 0xf7566
addl $0xfffff000, %r13d      # imm = 0xFFFFF000
movl %r13d, %ebp
btl $0xe, %ebp
jae 0xe39e0
leaq 0x615e2(%rip), %rsi     # 0x144fb4
movq %r15, %rdi
callq 0xf7566
addl $0xffffc000, %ebp       # imm = 0xFFFFC000
testw %bp, %bp
jns 0xe39fa
leaq 0x615d7(%rip), %rsi     # 0x144fc3
movq %r15, %rdi
callq 0xf7566
addl $0xffff8000, %ebp       # imm = 0xFFFF8000
testl %ebp, %ebp
je 0xe3a11
leaq 0x42470(%rip), %rsi     # 0x125e75
movq %r15, %rdi
movl %ebp, %edx
xorl %eax, %eax
callq 0xf7593
movl 0x14(%r12), %ebp
movq %r15, %rdi
callq 0xf7557
leaq 0x61453(%rip), %rsi     # 0x144e78
movq %rbx, %rdi
movl %ebp, %edx
movq %rax, %rcx
xorl %eax, %eax
callq 0xe9226
movq 0x18(%rbx), %rdi
leaq 0x28(%rsp), %rsi
callq 0xef1ed
movq %rax, 0x28(%r12)
leaq 0x61443(%rip), %rsi     # 0x144e91
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xe9226
movq 0x28(%r12), %rax
movq (%r12), %rcx
addq %rax, %rcx
cmpq 0x8(%r12), %rcx
jg 0xe403a
addq $-0x2, %rax
cmpb $0x75, 0x18(%r12)
movl $0xb, %r13d
cmovneq %rax, %r13
movq 0x30(%r14), %rdi
callq 0xebdc3
movq 0x30(%r14), %rdi
movq 0x18(%rbx), %rsi
movq (%r12), %rdx
addq $0x2, %rdx
movq %r13, %rcx
callq 0xebf09
movq 0x30(%r14), %rdi
callq 0xebe2a
movzwl %ax, %edx
leaq 0x31779(%rip), %rsi     # 0x115233
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9226
testb $-0x80, 0x15(%r12)
je 0xe3af3
movq 0x18(%rbx), %rdi
leaq 0x28(%rsp), %rsi
callq 0xef3a0
movq %rax, 0x38(%r12)
leaq 0x613c4(%rip), %rsi     # 0x144eaa
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xe9226
movzbl 0x18(%r12), %eax
cmpl $0x7a, %eax
je 0xe3b03
cmpl $0x74, %eax
jne 0xe3b37
testb $0x1, 0x15(%r12)
je 0xe3b37
movq 0x18(%rbx), %rdi
movq 0x28(%rsp), %rsi
addq $0x11, %rsi
callq 0xef37e
movq %rax, 0x40(%r12)
cmpq $0x7ffffffe, %rax       # imm = 0x7FFFFFFE
jg 0xe403a
shlq $0x20, %rax
movq %rax, 0x40(%r12)
movq 0x28(%rsp), %rax
movq %rax, 0x20(%r12)
movq 0x28(%r12), %rdx
movq (%r12), %rax
addq %rdx, %rax
movq %rax, 0x30(%r12)
addq 0x38(%r12), %rdx
addq 0x40(%r12), %rdx
movq %rdx, 0x48(%r12)
leaq 0x6135b(%rip), %rsi     # 0x144ec3
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9226
movq 0x48(%r12), %rax
addq (%r12), %rax
cmpq 0x8(%r12), %rax
jg 0xe403a
movb $0x1, 0x1a(%r12)
movzbl 0x18(%r12), %eax
addl $-0x73, %eax
cmpl $0x7, %eax
ja 0xe403a
leaq 0x610db(%rip), %rcx     # 0x144c80
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq %rbx, %rdi
movq %r14, %rsi
callq 0xfda6c
movq %rax, %rdi
movq 0x20(%r12), %rax
leaq 0x10(%rsp), %r13
movq %rax, (%r13)
movq 0x30(%r12), %rax
movq %rax, 0x40(%rdi)
movq 0x40(%r12), %rax
addq 0x38(%r12), %rax
movq %rax, 0x30(%rdi)
movq %rdi, 0x18(%rsp)
movq %r13, %rsi
callq 0xfdb9b
movq 0x18(%rbx), %rdi
movq %r13, %rsi
callq 0xef14d
movb %al, 0x20(%rsp)
movzbl %al, %edx
leaq 0x48261(%rip), %rcx     # 0x12be69
cmpb $0x4, %dl
ja 0xe3c1d
movl %edx, %eax
leaq 0x610ee(%rip), %rsi     # 0x144d04
movslq (%rsi,%rax,4), %rcx
addq %rsi, %rcx
leaq 0x343c2(%rip), %rsi     # 0x117fe6
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9226
movq 0x18(%rbx), %rdi
leaq 0x10(%rsp), %rbp
movq %rbp, %rsi
callq 0xef3a0
leaq 0x61388(%rip), %rsi     # 0x144fce
movq %rbx, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xe9226
movq 0x18(%rsp), %r13
movq 0x50(%r13), %rsi
addq $0x18, %rsi
leaq 0x34438(%rip), %rdx     # 0x11809e
movq %r14, %rdi
movl $0x4, %ecx
movq %rbp, %r8
callq 0xfdc9b
movq 0x18(%rbx), %rdi
movq %rbp, %rsi
callq 0xef14d
movzbl %al, %edx
leaq 0x61146(%rip), %rsi     # 0x144dd2
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9226
movq 0x18(%rbx), %rdi
movq %rbp, %rsi
callq 0xef14d
movzbl %al, %edx
movl %edx, 0x90(%r13)
leal -0x30(%rdx), %eax
cmpl $0x5, %eax
leaq 0x481b0(%rip), %rcx     # 0x12be69
ja 0xe3cc8
movl %eax, %eax
leaq 0xaaa0c(%rip), %rcx     # 0x18e6d0
movq (%rcx,%rax,8), %rcx
leaq 0x61310(%rip), %rsi     # 0x144fdf
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9226
movq 0x18(%rbx), %rdi
leaq 0x10(%rsp), %r13
movq %r13, %rsi
callq 0xef1ed
movq %rax, %rbp
movq 0x18(%rbx), %rdi
movq %r13, %rsi
callq 0xef3a0
movq %rax, %r13
leaq 0x612f6(%rip), %rsi     # 0x144ff9
movq %rbx, %rdi
movl %r13d, %edx
xorl %eax, %eax
callq 0xe9226
cmpb $0x2, 0x20(%rsp)
ja 0xe3d3f
movq %rbx, %rdi
movl $0x1, %esi
callq 0xe9585
movzbl %r13b, %esi
movq 0x18(%rsp), %rdi
callq 0xfdc20
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0xe9585
movq %r14, 0x20(%rsp)
testb $0x1, 0x15(%r12)
je 0xe3d52
addq $0x8, 0x10(%rsp)
movq 0x18(%rbx), %rdi
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %r14
movq 0x58(%r14), %r8
movq 0x20(%rsp), %rax
movl 0x18(%rax), %eax
movl %eax, (%rsp)
movl $0x800, %ecx            # imm = 0x800
movq %rbp, %rdx
movl $0x1, %r9d
callq 0xf0203
cmpb $0x7a, 0x18(%r12)
leaq 0x60e41(%rip), %rax     # 0x144bd0
leaq 0x64f95(%rip), %r13     # 0x148d2b
cmoveq %rax, %r13
movq 0x58(%r14), %rdi
callq 0xf7557
leaq 0x6125f(%rip), %rsi     # 0x145009
movq %rbx, %rdi
movq %r13, %rdx
movq %rax, %rcx
xorl %eax, %eax
callq 0xe9226
addq 0x10(%rsp), %rbp
movq %rbp, 0x10(%rsp)
movl 0x14(%r12), %eax
btl $0xa, %eax
jae 0xe3dd8
addq $0x8, %rbp
movq %rbp, 0x10(%rsp)
movl %eax, %ecx
notl %ecx
testl $0x1008, %ecx           # imm = 0x1008
je 0xe3e61
testb $0x8, %al
je 0xe3df0
cmpb $0x7a, 0x18(%r12)
je 0xe3e61
testb $0x8, %al
je 0xe3e43
movl $0x50, %esi
movq %rbx, %rdi
callq 0xe969b
movq %rax, %r13
movq 0x10(%rsp), %rax
movq %rax, (%r13)
movq 0x30(%r12), %rax
movq %rax, 0x8(%r13)
movb 0x18(%r12), %al
movb %al, 0x19(%r13)
movq %rbx, %rdi
movq 0x20(%rsp), %rsi
movq %r13, %rdx
callq 0xe36b8
movq 0x48(%r13), %rax
addq %rax, 0x10(%rsp)
movq %rbx, %rdi
movq %r13, %rsi
callq 0xe9752
movq 0x18(%rsp), %rax
movq 0x30(%rax), %rcx
movq 0x40(%rax), %rdx
leaq 0x60fcb(%rip), %rsi     # 0x144e22
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9226
movq %rbx, %rdi
movq 0x18(%rsp), %rsi
callq 0xfdab8
jmp 0xe403a
testb $0x2, 0x14(%r12)
je 0xe403a
movq 0x20(%r12), %rbp
addq $0x6, %rbp
movl $0x50, %esi
movq %rbx, %rdi
callq 0xe969b
movq %rax, %r13
movq %rbp, (%rax)
movq 0x30(%r12), %rax
movq %rax, 0x8(%r13)
movb 0x18(%r12), %al
movb %al, 0x19(%r13)
movq %rbx, %rdi
movq %r14, %rsi
movq %r13, %rdx
callq 0xe36b8
movq %rbx, %rdi
movq %r13, %rsi
callq 0xe9752
jmp 0xe403a
movq 0x20(%r12), %rax
leaq 0x10(%rsp), %r13
movq %rax, (%r13)
movb 0x19(%r12), %bpl
movq 0x18(%rbx), %rdi
movq %r13, %rsi
callq 0xef1ed
leaq 0x61125(%rip), %rsi     # 0x145016
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xe9226
movq 0x18(%rbx), %rdi
movq %r13, %rsi
callq 0xef14d
movzbl %al, %edx
leaq 0x6111c(%rip), %rsi     # 0x145030
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9226
movq 0x18(%rbx), %rdi
movq %r13, %rsi
callq 0xef14d
movzbl %al, %edx
leal -0x30(%rdx), %eax
cmpl $0x5, %eax
movb %bpl, 0x18(%rsp)
ja 0xe3f8e
movl %eax, %eax
leaq 0xaa78d(%rip), %rcx     # 0x18e6d0
movq (%rcx,%rax,8), %rcx
jmp 0xe3f95
movq 0x20(%r12), %rax
leaq 0x10(%rsp), %rsi
movq %rax, (%rsi)
movq 0x18(%rbx), %rdi
callq 0xef1ed
cmpl $0x100, %eax            # imm = 0x100
leaq 0x6111a(%rip), %rdx     # 0x145085
leaq 0x47ef7(%rip), %rcx     # 0x12be69
cmoveq %rdx, %rcx
leaq 0x610ed(%rip), %rsi     # 0x14506a
movq %rbx, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xe9226
jmp 0xe403a
leaq 0x47ed4(%rip), %rcx     # 0x12be69
leaq 0x61043(%rip), %rsi     # 0x144fdf
movq %rbx, %rdi
movq %rdx, 0x20(%rsp)
xorl %eax, %eax
callq 0xe9226
movq 0x18(%rbx), %rdi
leaq 0x10(%rsp), %rbp
movq %rbp, %rsi
callq 0xef1ed
leaq 0x60989(%rip), %rsi     # 0x14494c
movq %rbx, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xe9226
movb 0x18(%rsp), %r13b
cmpb $0x74, %r13b
movq 0x30(%r12), %r12
movq (%rbp), %rcx
leaq 0x64d43(%rip), %rax     # 0x148d2b
leaq 0x32d04(%rip), %rdx     # 0x116cf3
cmoveq %rax, %rdx
subq %rcx, %r12
leaq 0x61052(%rip), %rsi     # 0x14504f
setle %bpl
movq %rbx, %rdi
movq %r12, %r8
xorl %eax, %eax
callq 0xe9226
cmpl $0x30, 0x20(%rsp)
setne %al
orb %bpl, %al
jne 0xe403a
xorl %r8d, %r8d
cmpb $0x74, %r13b
sete %r8b
movq 0x10(%rsp), %rsi
movl 0x18(%r14), %ecx
movq %rbx, %rdi
movq %r12, %rdx
callq 0xe35e2
movq %r15, %rdi
callq 0xf6bb0
movl 0x34(%rsp), %esi
movq %rbx, %rdi
callq 0xe9595
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nopl (%rax)