// File: /workspace/github_c_makefile_star2_O3/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 0x2c(%rsp), %rsi
callq 0xe8a1c
movq (%r12), %rdx
leaq 0x18(%rsp), %r15
movq %rdx, (%r15)
leaq 0x4e8c7(%rip), %rsi     # 0x1313bd
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe8617
movq %rbx, %rdi
movl $0x1, %esi
callq 0xe8a15
movq 0x18(%rbx), %rdi
movq %r15, %rsi
callq 0xeebeb
movl %eax, 0x10(%r12)
leaq 0x62307(%rip), %rsi     # 0x144e2c
movq %rbx, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xe8617
movq 0x18(%rbx), %rdi
movq %r15, %rsi
callq 0xeeb4b
movb %al, 0x18(%r12)
movzbl %al, %edx
leal -0x72(%rdx), %eax
cmpb $0x9, %al
ja 0xe2b5f
movzbl %al, %eax
leaq 0x62666(%rip), %rsi     # 0x1451bc
movslq (%rsi,%rax,4), %rcx
addq %rsi, %rcx
jmp 0xe2b66
leaq 0x495eb(%rip), %rcx     # 0x12c151
leaq 0x627d3(%rip), %rsi     # 0x145340
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe8617
cmpb $0x0, 0x19(%r12)
movb 0x18(%r12), %al
je 0xe2b90
cmpb $0x75, %al
je 0xe2b9a
xorl %r15d, %r15d
jmp 0xe3440
cmpb $0x7b, %al
jne 0xe2b9a
movb $0x1, 0x1b(%r12)
movq 0x18(%rbx), %rdi
leaq 0x18(%rsp), %rsi
callq 0xeebeb
movl %eax, 0x14(%r12)
movq %rbx, %rdi
callq 0xf6410
movq %rax, %r15
movl 0x14(%r12), %ebp
movq %rax, %rdi
callq 0xf6423
movzbl 0x18(%r12), %eax
cmpl $0x7a, %eax
je 0xe2c7e
cmpl $0x74, %eax
je 0xe2c7e
cmpl $0x73, %eax
jne 0xe2dc8
testb $0x1, %bpl
je 0xe2bfd
leaq 0x4fdaf(%rip), %rsi     # 0x1329a2
movq %r15, %rdi
callq 0xf7105
decl %ebp
testb $0x2, %bpl
je 0xe2c15
leaq 0x627e4(%rip), %rsi     # 0x1453ee
movq %r15, %rdi
callq 0xf7105
addl $-0x2, %ebp
testb $0x4, %bpl
je 0xe2c2d
leaq 0x4c14b(%rip), %rsi     # 0x12ed6d
movq %r15, %rdi
callq 0xf7105
addl $-0x4, %ebp
testb $0x8, %bpl
je 0xe2c45
leaq 0x3b471(%rip), %rsi     # 0x11e0ab
movq %r15, %rdi
callq 0xf7105
addl $-0x8, %ebp
testb $0x20, %bpl
je 0xe2c5d
leaq 0x627ae(%rip), %rsi     # 0x145400
movq %r15, %rdi
callq 0xf7105
addl $-0x20, %ebp
testb $0x40, %bpl
je 0xe2dc8
leaq 0x627a6(%rip), %rsi     # 0x145414
movq %r15, %rdi
callq 0xf7105
addl $-0x40, %ebp
jmp 0xe2dc8
testb $0x1, %bpl
je 0xe2c95
leaq 0x6279d(%rip), %rsi     # 0x145428
movq %r15, %rdi
callq 0xf7105
decl %ebp
testb $0x2, %bpl
je 0xe2cad
leaq 0x6279e(%rip), %rsi     # 0x145440
movq %r15, %rdi
callq 0xf7105
addl $-0x2, %ebp
testb $0x4, %bpl
je 0xe2cc5
leaq 0x5f60d(%rip), %rsi     # 0x1422c7
movq %r15, %rdi
callq 0xf7105
addl $-0x4, %ebp
testb $0x8, %bpl
je 0xe2cdd
leaq 0x6271c(%rip), %rsi     # 0x1453ee
movq %r15, %rdi
callq 0xf7105
addl $-0x8, %ebp
testb $0x10, %bpl
je 0xe2cf5
leaq 0x3b3c1(%rip), %rsi     # 0x11e0ab
movq %r15, %rdi
callq 0xf7105
addl $-0x10, %ebp
movl %ebp, %ecx
shrl $0x5, %ecx
andl $0x7, %ecx
cmpl $0x7, %ecx
jne 0xe2d13
leaq 0x30f19(%rip), %rsi     # 0x113c22
movq %r15, %rdi
callq 0xf7105
jmp 0xe2d2b
movl $0x40, %edx
shll %cl, %edx
leaq 0x62735(%rip), %rsi     # 0x145456
movq %r15, %rdi
xorl %eax, %eax
callq 0xf7132
movl %ebp, %r13d
andl $0xffffff1f, %r13d      # imm = 0xFFFFFF1F
btl $0x8, %ebp
jae 0xe2d51
leaq 0x4878d(%rip), %rsi     # 0x12b4cf
movq %r15, %rdi
callq 0xf7105
addl $0xffffff00, %r13d      # imm = 0xFFFFFF00
btl $0x9, %r13d
jae 0xe2d6e
leaq 0x62700(%rip), %rsi     # 0x14545f
movq %r15, %rdi
callq 0xf7105
addl $0xfffffe00, %r13d      # imm = 0xFFFFFE00
btl $0xa, %r13d
jae 0xe2d8b
leaq 0x626f4(%rip), %rsi     # 0x145470
movq %r15, %rdi
callq 0xf7105
addl $0xfffffc00, %r13d      # imm = 0xFFFFFC00
btl $0xb, %r13d
jae 0xe2da8
leaq 0x626dc(%rip), %rsi     # 0x145475
movq %r15, %rdi
callq 0xf7105
addl $0xfffff800, %r13d      # imm = 0xFFFFF800
btl $0xc, %r13d
jae 0xe2dc5
leaq 0x626cb(%rip), %rsi     # 0x145481
movq %r15, %rdi
callq 0xf7105
addl $0xfffff000, %r13d      # imm = 0xFFFFF000
movl %r13d, %ebp
btl $0xe, %ebp
jae 0xe2de3
leaq 0x626bf(%rip), %rsi     # 0x145494
movq %r15, %rdi
callq 0xf7105
addl $0xffffc000, %ebp       # imm = 0xFFFFC000
testw %bp, %bp
jns 0xe2dfd
leaq 0x626b4(%rip), %rsi     # 0x1454a3
movq %r15, %rdi
callq 0xf7105
addl $0xffff8000, %ebp       # imm = 0xFFFF8000
testl %ebp, %ebp
je 0xe2e14
leaq 0x4329d(%rip), %rsi     # 0x1260a5
movq %r15, %rdi
movl %ebp, %edx
xorl %eax, %eax
callq 0xf7132
movl 0x14(%r12), %ebp
movq %r15, %rdi
callq 0xf70f6
leaq 0x62530(%rip), %rsi     # 0x145358
movq %rbx, %rdi
movl %ebp, %edx
movq %rax, %rcx
xorl %eax, %eax
callq 0xe8617
movq 0x18(%rbx), %rdi
leaq 0x18(%rsp), %rsi
callq 0xeebeb
movq %rax, 0x28(%r12)
leaq 0x62520(%rip), %rsi     # 0x145371
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xe8617
movq 0x28(%r12), %rax
movq (%r12), %rcx
addq %rax, %rcx
cmpq 0x8(%r12), %rcx
jg 0xe3440
addq $-0x2, %rax
cmpb $0x75, 0x18(%r12)
movl $0xb, %r13d
cmovneq %rax, %r13
movq 0x30(%r14), %rdi
callq 0xeb7fe
movq 0x30(%r14), %rdi
movq 0x18(%rbx), %rsi
movq (%r12), %rdx
addq $0x2, %rdx
movq %r13, %rcx
callq 0xeb944
movq 0x30(%r14), %rdi
callq 0xeb865
movzwl %ax, %edx
leaq 0x32426(%rip), %rsi     # 0x1152e3
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe8617
testb $-0x80, 0x15(%r12)
je 0xe2ef6
movq 0x18(%rbx), %rdi
leaq 0x18(%rsp), %rsi
callq 0xeed83
movq %rax, 0x38(%r12)
leaq 0x624a1(%rip), %rsi     # 0x14538a
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xe8617
movzbl 0x18(%r12), %eax
cmpl $0x7a, %eax
je 0xe2f06
cmpl $0x74, %eax
jne 0xe2f3a
testb $0x1, 0x15(%r12)
je 0xe2f3a
movq 0x18(%rbx), %rdi
movq 0x18(%rsp), %rsi
addq $0x11, %rsi
callq 0xeed61
movq %rax, 0x40(%r12)
cmpq $0x7ffffffe, %rax       # imm = 0x7FFFFFFE
jg 0xe3440
shlq $0x20, %rax
movq %rax, 0x40(%r12)
movq 0x18(%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 0x62438(%rip), %rsi     # 0x1453a3
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe8617
movq 0x48(%r12), %rax
addq (%r12), %rax
cmpq 0x8(%r12), %rax
jg 0xe3440
movb $0x1, 0x1a(%r12)
movzbl 0x18(%r12), %eax
addl $-0x73, %eax
cmpl $0x7, %eax
ja 0xe3440
leaq 0x621cc(%rip), %rcx     # 0x145174
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq %rbx, %rdi
movq %r14, %rsi
callq 0xfd414
movq %rax, %rdi
movq 0x20(%r12), %rax
leaq 0x8(%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, 0x10(%rsp)
movq %r13, %rsi
callq 0xfd538
movq 0x18(%rbx), %rdi
movq %r13, %rsi
callq 0xeeb4b
movb %al, 0x20(%rsp)
movzbl %al, %edx
leaq 0x49146(%rip), %rcx     # 0x12c151
cmpb $0x4, %dl
ja 0xe3020
movl %edx, %eax
leaq 0x621cb(%rip), %rsi     # 0x1451e4
movslq (%rsi,%rax,4), %rcx
addq %rsi, %rcx
leaq 0x350f7(%rip), %rsi     # 0x11811e
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe8617
movq 0x18(%rbx), %rdi
leaq 0x8(%rsp), %rbp
movq %rbp, %rsi
callq 0xeed83
leaq 0x62465(%rip), %rsi     # 0x1454ae
movq %rbx, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xe8617
movq 0x10(%rsp), %r13
movq 0x50(%r13), %rsi
addq $0x18, %rsi
leaq 0x3516d(%rip), %rdx     # 0x1181d6
movq %r14, %rdi
movl $0x4, %ecx
movq %rbp, %r8
callq 0xfd638
movq 0x18(%rbx), %rdi
movq %rbp, %rsi
callq 0xeeb4b
movzbl %al, %edx
leaq 0x62223(%rip), %rsi     # 0x1452b2
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe8617
movq 0x18(%rbx), %rdi
movq %rbp, %rsi
callq 0xeeb4b
movzbl %al, %edx
movl %edx, 0x90(%r13)
leal -0x30(%rdx), %eax
cmpl $0x5, %eax
leaq 0x49095(%rip), %rcx     # 0x12c151
ja 0xe30cb
movl %eax, %eax
leaq 0xab609(%rip), %rcx     # 0x18e6d0
movq (%rcx,%rax,8), %rcx
leaq 0x623ed(%rip), %rsi     # 0x1454bf
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe8617
movq 0x18(%rbx), %rdi
leaq 0x8(%rsp), %r13
movq %r13, %rsi
callq 0xeebeb
movq %rax, %rbp
movq 0x18(%rbx), %rdi
movq %r13, %rsi
callq 0xeed83
movq %rax, %r13
leaq 0x623d3(%rip), %rsi     # 0x1454d9
movq %rbx, %rdi
movl %r13d, %edx
xorl %eax, %eax
callq 0xe8617
cmpb $0x2, 0x20(%rsp)
ja 0xe3142
movq %rbx, %rdi
movl $0x1, %esi
callq 0xe8a15
movzbl %r13b, %esi
movq 0x10(%rsp), %rdi
callq 0xfd5bd
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0xe8a15
testb $0x1, 0x15(%r12)
movq 0x8(%rsp), %rsi
movq %r14, 0x30(%rsp)
je 0xe315d
addq $0x8, %rsi
movq %rsi, 0x8(%rsp)
movq 0x18(%rbx), %rdi
movq 0x10(%rsp), %r14
movq 0x58(%r14), %r8
movq 0x30(%rsp), %rax
movl 0x18(%rax), %eax
movl %eax, (%rsp)
movl $0x800, %ecx            # imm = 0x800
movq %rbp, %rdx
movl $0x1, %r9d
callq 0xefc2a
cmpb $0x7a, 0x18(%r12)
leaq 0x61f1b(%rip), %rax     # 0x1450b0
leaq 0x66127(%rip), %r13     # 0x1492c3
cmoveq %rax, %r13
movq 0x58(%r14), %rdi
callq 0xf70f6
leaq 0x62339(%rip), %rsi     # 0x1454e9
movq %rbx, %rdi
movq %r13, %rdx
movq %rax, %rcx
xorl %eax, %eax
callq 0xe8617
addq 0x8(%rsp), %rbp
movq %rbp, 0x8(%rsp)
movl 0x14(%r12), %eax
btl $0xa, %eax
jae 0xe31de
addq $0x8, %rbp
movq %rbp, 0x8(%rsp)
movl %eax, %ecx
notl %ecx
testl $0x1008, %ecx           # imm = 0x1008
je 0xe3267
testb $0x8, %al
je 0xe31f6
cmpb $0x7a, 0x18(%r12)
je 0xe3267
testb $0x8, %al
je 0xe3249
movl $0x50, %esi
movq %rbx, %rdi
callq 0xe8b2b
movq %rax, %r13
movq 0x8(%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 0x30(%rsp), %rsi
movq %r13, %rdx
callq 0xe2ac2
movq 0x48(%r13), %rax
addq %rax, 0x8(%rsp)
movq %rbx, %rdi
movq %r13, %rsi
callq 0xe8be2
movq 0x10(%rsp), %rax
movq 0x30(%rax), %rcx
movq 0x40(%rax), %rdx
leaq 0x620a5(%rip), %rsi     # 0x145302
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe8617
movq %rbx, %rdi
movq 0x10(%rsp), %rsi
callq 0xfd460
jmp 0xe3440
testb $0x2, 0x14(%r12)
je 0xe3440
movq 0x20(%r12), %rbp
addq $0x6, %rbp
movl $0x50, %esi
movq %rbx, %rdi
callq 0xe8b2b
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 0xe2ac2
movq %rbx, %rdi
movq %r13, %rsi
callq 0xe8be2
jmp 0xe3440
movq 0x20(%r12), %rax
leaq 0x8(%rsp), %r13
movq %rax, (%r13)
movb 0x19(%r12), %bpl
movq 0x18(%rbx), %rdi
movq %r13, %rsi
callq 0xeebeb
leaq 0x621ff(%rip), %rsi     # 0x1454f6
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xe8617
movq 0x18(%rbx), %rdi
movq %r13, %rsi
callq 0xeeb4b
movzbl %al, %edx
leaq 0x621f6(%rip), %rsi     # 0x145510
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe8617
movq 0x18(%rbx), %rdi
movq %r13, %rsi
callq 0xeeb4b
movzbl %al, %edx
leal -0x30(%rdx), %eax
cmpl $0x5, %eax
movb %bpl, 0x10(%rsp)
ja 0xe3394
movl %eax, %eax
leaq 0xab387(%rip), %rcx     # 0x18e6d0
movq (%rcx,%rax,8), %rcx
jmp 0xe339b
movq 0x20(%r12), %rax
leaq 0x8(%rsp), %rsi
movq %rax, (%rsi)
movq 0x18(%rbx), %rdi
callq 0xeebeb
cmpl $0x100, %eax            # imm = 0x100
leaq 0x621f4(%rip), %rdx     # 0x145565
leaq 0x48dd9(%rip), %rcx     # 0x12c151
cmoveq %rdx, %rcx
leaq 0x621c7(%rip), %rsi     # 0x14554a
movq %rbx, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xe8617
jmp 0xe3440
leaq 0x48db6(%rip), %rcx     # 0x12c151
leaq 0x6211d(%rip), %rsi     # 0x1454bf
movq %rbx, %rdi
movq %rdx, 0x20(%rsp)
xorl %eax, %eax
callq 0xe8617
movq 0x18(%rbx), %rdi
leaq 0x8(%rsp), %rbp
movq %rbp, %rsi
callq 0xeebeb
leaq 0x61a63(%rip), %rsi     # 0x144e2c
movq %rbx, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xe8617
movb 0x10(%rsp), %r13b
cmpb $0x74, %r13b
movq 0x30(%r12), %r12
movq (%rbp), %rcx
leaq 0x65ed5(%rip), %rax     # 0x1492c3
leaq 0x339ae(%rip), %rdx     # 0x116da3
cmoveq %rax, %rdx
subq %rcx, %r12
leaq 0x6212c(%rip), %rsi     # 0x14552f
setle %bpl
movq %rbx, %rdi
movq %r12, %r8
xorl %eax, %eax
callq 0xe8617
cmpl $0x30, 0x20(%rsp)
setne %al
orb %bpl, %al
jne 0xe3440
xorl %r8d, %r8d
cmpb $0x74, %r13b
sete %r8b
movq 0x8(%rsp), %rsi
movl 0x18(%r14), %ecx
movq %rbx, %rdi
movq %r12, %rdx
callq 0xe29ec
movq %r15, %rdi
callq 0xf6753
movl 0x2c(%rsp), %esi
movq %rbx, %rdi
callq 0xe8a25
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq