// File: /workspace/github_c_makefile_star2_O2/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 0xdebae
movq (%r12), %rdx
leaq 0x18(%rsp), %r15
movq %rdx, (%r15)
leaq 0x4b069(%rip), %rsi     # 0x1240cd
movq %rbx, %rdi
xorl %eax, %eax
callq 0xde896
pushq $0x1
popq %rsi
movq %rbx, %rdi
callq 0xdeba7
movq 0x18(%rbx), %rdi
movq %r15, %rsi
callq 0xe3fc4
movl %eax, 0x10(%r12)
leaq 0x5e94b(%rip), %rsi     # 0x1379dc
movq %rbx, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xde896
movq 0x18(%rbx), %rdi
movq %r15, %rsi
callq 0xe3f2a
movb %al, 0x18(%r12)
movzbl %al, %edx
leal -0x72(%rdx), %eax
cmpb $0x9, %al
ja 0xd90cb
movzbl %al, %eax
leaq 0x5ecaa(%rip), %rsi     # 0x137d6c
movslq (%rsi,%rax,4), %rcx
addq %rsi, %rcx
jmp 0xd90d2
leaq 0x45e0f(%rip), %rcx     # 0x11eee1
leaq 0x5ee17(%rip), %rsi     # 0x137ef0
movq %rbx, %rdi
xorl %eax, %eax
callq 0xde896
cmpb $0x0, 0x19(%r12)
movb 0x18(%r12), %al
je 0xd90fc
cmpb $0x75, %al
je 0xd9106
xorl %r15d, %r15d
jmp 0xd999b
cmpb $0x7b, %al
jne 0xd9106
movb $0x1, 0x1b(%r12)
movq 0x18(%rbx), %rdi
leaq 0x18(%rsp), %rsi
callq 0xe3fc4
movl %eax, 0x14(%r12)
movq %rbx, %rdi
callq 0xeac74
movq %rax, %r15
movl 0x14(%r12), %ebp
movq %rax, %rdi
callq 0xeac85
movzbl 0x18(%r12), %eax
cmpl $0x7a, %eax
je 0xd91ea
cmpl $0x74, %eax
je 0xd91ea
cmpl $0x73, %eax
jne 0xd9332
testb $0x1, %bpl
je 0xd9169
leaq 0x4c543(%rip), %rsi     # 0x1256a2
movq %r15, %rdi
callq 0xeb884
decl %ebp
testb $0x2, %bpl
je 0xd9181
leaq 0x5ee28(%rip), %rsi     # 0x137f9e
movq %r15, %rdi
callq 0xeb884
addl $-0x2, %ebp
testb $0x4, %bpl
je 0xd9199
leaq 0x48957(%rip), %rsi     # 0x121ae5
movq %r15, %rdi
callq 0xeb884
addl $-0x4, %ebp
testb $0x8, %bpl
je 0xd91b1
leaq 0x37e31(%rip), %rsi     # 0x110fd7
movq %r15, %rdi
callq 0xeb884
addl $-0x8, %ebp
testb $0x20, %bpl
je 0xd91c9
leaq 0x5edf2(%rip), %rsi     # 0x137fb0
movq %r15, %rdi
callq 0xeb884
addl $-0x20, %ebp
testb $0x40, %bpl
je 0xd9332
leaq 0x5edea(%rip), %rsi     # 0x137fc4
movq %r15, %rdi
callq 0xeb884
addl $-0x40, %ebp
jmp 0xd9332
testb $0x1, %bpl
je 0xd9201
leaq 0x5ede1(%rip), %rsi     # 0x137fd8
movq %r15, %rdi
callq 0xeb884
decl %ebp
testb $0x2, %bpl
je 0xd9219
leaq 0x5ede2(%rip), %rsi     # 0x137ff0
movq %r15, %rdi
callq 0xeb884
addl $-0x2, %ebp
testb $0x4, %bpl
je 0xd9231
leaq 0x5bc51(%rip), %rsi     # 0x134e77
movq %r15, %rdi
callq 0xeb884
addl $-0x4, %ebp
testb $0x8, %bpl
je 0xd9249
leaq 0x5ed60(%rip), %rsi     # 0x137f9e
movq %r15, %rdi
callq 0xeb884
addl $-0x8, %ebp
testb $0x10, %bpl
je 0xd9261
leaq 0x37d81(%rip), %rsi     # 0x110fd7
movq %r15, %rdi
callq 0xeb884
addl $-0x10, %ebp
movl %ebp, %ecx
shrl $0x5, %ecx
andl $0x7, %ecx
cmpl $0x7, %ecx
jne 0xd927f
leaq 0x2d94d(%rip), %rsi     # 0x106bc2
movq %r15, %rdi
callq 0xeb884
jmp 0xd9295
pushq $0x40
popq %rdx
shll %cl, %edx
leaq 0x5ed7b(%rip), %rsi     # 0x138006
movq %r15, %rdi
xorl %eax, %eax
callq 0xeb8af
movl %ebp, %r13d
andl $0xffffff1f, %r13d      # imm = 0xFFFFFF1F
btl $0x8, %ebp
jae 0xd92bb
leaq 0x44fb3(%rip), %rsi     # 0x11e25f
movq %r15, %rdi
callq 0xeb884
addl $0xffffff00, %r13d      # imm = 0xFFFFFF00
btl $0x9, %r13d
jae 0xd92d8
leaq 0x5ed46(%rip), %rsi     # 0x13800f
movq %r15, %rdi
callq 0xeb884
addl $0xfffffe00, %r13d      # imm = 0xFFFFFE00
btl $0xa, %r13d
jae 0xd92f5
leaq 0x5ed3a(%rip), %rsi     # 0x138020
movq %r15, %rdi
callq 0xeb884
addl $0xfffffc00, %r13d      # imm = 0xFFFFFC00
btl $0xb, %r13d
jae 0xd9312
leaq 0x5ed22(%rip), %rsi     # 0x138025
movq %r15, %rdi
callq 0xeb884
addl $0xfffff800, %r13d      # imm = 0xFFFFF800
btl $0xc, %r13d
jae 0xd932f
leaq 0x5ed11(%rip), %rsi     # 0x138031
movq %r15, %rdi
callq 0xeb884
addl $0xfffff000, %r13d      # imm = 0xFFFFF000
movl %r13d, %ebp
btl $0xe, %ebp
jae 0xd934d
leaq 0x5ed05(%rip), %rsi     # 0x138044
movq %r15, %rdi
callq 0xeb884
addl $0xffffc000, %ebp       # imm = 0xFFFFC000
testw %bp, %bp
jns 0xd9367
leaq 0x5ecfa(%rip), %rsi     # 0x138053
movq %r15, %rdi
callq 0xeb884
addl $0xffff8000, %ebp       # imm = 0xFFFF8000
testl %ebp, %ebp
je 0xd937e
leaq 0x3fb33(%rip), %rsi     # 0x118ea5
movq %r15, %rdi
movl %ebp, %edx
xorl %eax, %eax
callq 0xeb8af
movl 0x14(%r12), %ebp
movq %r15, %rdi
callq 0xeb877
leaq 0x5eb76(%rip), %rsi     # 0x137f08
movq %rbx, %rdi
movl %ebp, %edx
movq %rax, %rcx
xorl %eax, %eax
callq 0xde896
movq 0x18(%rbx), %rdi
leaq 0x18(%rsp), %rsi
callq 0xe3fc4
movq %rax, 0x28(%r12)
leaq 0x5eb66(%rip), %rsi     # 0x137f21
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xde896
movq 0x28(%r12), %rax
movq (%r12), %rcx
addq %rax, %rcx
cmpq 0x8(%r12), %rcx
jg 0xd999b
addq $-0x2, %rax
cmpb $0x75, 0x18(%r12)
pushq $0xb
popq %r13
cmovneq %rax, %r13
movq 0x30(%r14), %rdi
callq 0xe0e44
movq 0x30(%r14), %rdi
movq 0x18(%rbx), %rsi
movq (%r12), %rdx
addq $0x2, %rdx
movq %r13, %rcx
callq 0xe0f33
movq 0x30(%r14), %rdi
callq 0xe0e95
movzwl %ax, %edx
leaq 0x2ee32(%rip), %rsi     # 0x108257
movq %rbx, %rdi
xorl %eax, %eax
callq 0xde896
testb $-0x80, 0x15(%r12)
je 0xd945e
movq 0x18(%rbx), %rdi
leaq 0x18(%rsp), %rsi
callq 0xe40bf
movq %rax, 0x38(%r12)
leaq 0x5eae9(%rip), %rsi     # 0x137f3a
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xde896
movzbl 0x18(%r12), %eax
cmpl $0x7a, %eax
je 0xd946e
cmpl $0x74, %eax
jne 0xd94a2
testb $0x1, 0x15(%r12)
je 0xd94a2
movq 0x18(%rbx), %rdi
movq 0x18(%rsp), %rsi
addq $0x11, %rsi
callq 0xe409f
movq %rax, 0x40(%r12)
cmpq $0x7ffffffe, %rax       # imm = 0x7FFFFFFE
jg 0xd999b
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 0x5ea80(%rip), %rsi     # 0x137f53
movq %rbx, %rdi
xorl %eax, %eax
callq 0xde896
movq 0x48(%r12), %rax
addq (%r12), %rax
cmpq 0x8(%r12), %rax
jg 0xd999b
movb $0x1, 0x1a(%r12)
movzbl 0x18(%r12), %eax
addl $-0x73, %eax
cmpl $0x7, %eax
ja 0xd999b
leaq 0x5e800(%rip), %rcx     # 0x137d10
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq %rbx, %rdi
movq %r14, %rsi
callq 0xf1630
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 0xf1766
movq 0x18(%rbx), %rdi
movq %r13, %rsi
callq 0xe3f2a
movb %al, 0x20(%rsp)
movzbl %al, %edx
leaq 0x4596e(%rip), %rcx     # 0x11eee1
cmpb $0x4, %dl
ja 0xd9588
movl %edx, %eax
leaq 0x5e813(%rip), %rsi     # 0x137d94
movslq (%rsi,%rax,4), %rcx
addq %rsi, %rcx
leaq 0x31a9f(%rip), %rsi     # 0x10b02e
movq %rbx, %rdi
xorl %eax, %eax
callq 0xde896
movq 0x18(%rbx), %rdi
leaq 0x8(%rsp), %rbp
movq %rbp, %rsi
callq 0xe40bf
leaq 0x5eaad(%rip), %rsi     # 0x13805e
movq %rbx, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xde896
movq 0x10(%rsp), %r13
movq 0x50(%r13), %rsi
addq $0x18, %rsi
leaq 0x31b15(%rip), %rdx     # 0x10b0e6
pushq $0x4
popq %rcx
movq %r14, %rdi
movq %rbp, %r8
callq 0xf1866
movq 0x18(%rbx), %rdi
movq %rbp, %rsi
callq 0xe3f2a
movzbl %al, %edx
leaq 0x5e86d(%rip), %rsi     # 0x137e62
movq %rbx, %rdi
xorl %eax, %eax
callq 0xde896
movq 0x18(%rbx), %rdi
movq %rbp, %rsi
callq 0xe3f2a
movzbl %al, %edx
movl %edx, 0x90(%r13)
leal -0x30(%rdx), %eax
cmpl $0x5, %eax
leaq 0x458bf(%rip), %rcx     # 0x11eee1
ja 0xd9631
movl %eax, %eax
leaq 0xb80a3(%rip), %rcx     # 0x1916d0
movq (%rcx,%rax,8), %rcx
leaq 0x5ea37(%rip), %rsi     # 0x13806f
movq %rbx, %rdi
xorl %eax, %eax
callq 0xde896
movq 0x18(%rbx), %rdi
leaq 0x8(%rsp), %r13
movq %r13, %rsi
callq 0xe3fc4
movq %rax, %rbp
movq 0x18(%rbx), %rdi
movq %r13, %rsi
callq 0xe40bf
movq %rax, %r13
leaq 0x5ea1d(%rip), %rsi     # 0x138089
movq %rbx, %rdi
movl %r13d, %edx
xorl %eax, %eax
callq 0xde896
cmpb $0x2, 0x20(%rsp)
ja 0xd96a4
pushq $0x1
popq %rsi
movq %rbx, %rdi
callq 0xdeba7
movzbl %r13b, %esi
movq 0x10(%rsp), %rdi
callq 0xf17eb
pushq $-0x1
popq %rsi
movq %rbx, %rdi
callq 0xdeba7
testb $0x1, 0x15(%r12)
movq 0x8(%rsp), %rsi
movq %r14, 0x30(%rsp)
je 0xd96bf
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)
pushq $0x1
popq %r9
movl $0x800, %ecx            # imm = 0x800
movq %rbp, %rdx
callq 0xe4ced
cmpb $0x7a, 0x18(%r12)
leaq 0x5e56b(%rip), %rax     # 0x137c60
leaq 0x626f7(%rip), %r13     # 0x13bdf3
cmoveq %rax, %r13
movq 0x58(%r14), %rdi
callq 0xeb877
leaq 0x5e989(%rip), %rsi     # 0x138099
movq %rbx, %rdi
movq %r13, %rdx
movq %rax, %rcx
xorl %eax, %eax
callq 0xde896
addq 0x8(%rsp), %rbp
movq %rbp, 0x8(%rsp)
movl 0x14(%r12), %eax
btl $0xa, %eax
jae 0xd973e
addq $0x8, %rbp
movq %rbp, 0x8(%rsp)
movl %eax, %ecx
notl %ecx
testw $0x1008, %cx            # imm = 0x1008
je 0xd97c4
testb $0x8, %al
je 0xd9755
cmpb $0x7a, 0x18(%r12)
je 0xd97c4
testb $0x8, %al
je 0xd97a6
pushq $0x50
popq %rsi
movq %rbx, %rdi
callq 0xdecaf
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 0xd9030
movq 0x48(%r13), %rax
addq %rax, 0x8(%rsp)
movq %rbx, %rdi
movq %r13, %rsi
callq 0xded32
movq 0x10(%rsp), %rax
movq 0x30(%rax), %rcx
movq 0x40(%rax), %rdx
leaq 0x5e6f8(%rip), %rsi     # 0x137eb2
movq %rbx, %rdi
xorl %eax, %eax
callq 0xde896
movq %rbx, %rdi
movq 0x10(%rsp), %rsi
callq 0xf167c
jmp 0xd999b
testb $0x2, 0x14(%r12)
je 0xd999b
movq 0x20(%r12), %rbp
addq $0x6, %rbp
pushq $0x50
popq %rsi
movq %rbx, %rdi
callq 0xdecaf
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 0xd9030
movq %rbx, %rdi
movq %r13, %rsi
callq 0xded32
jmp 0xd999b
movq 0x20(%r12), %rax
leaq 0x8(%rsp), %r13
movq %rax, (%r13)
movb 0x19(%r12), %bpl
movq 0x18(%rbx), %rdi
movq %r13, %rsi
callq 0xe3fc4
leaq 0x5e854(%rip), %rsi     # 0x1380a6
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xde896
movq 0x18(%rbx), %rdi
movq %r13, %rsi
callq 0xe3f2a
movzbl %al, %edx
leaq 0x5e84b(%rip), %rsi     # 0x1380c0
movq %rbx, %rdi
xorl %eax, %eax
callq 0xde896
movq 0x18(%rbx), %rdi
movq %r13, %rsi
callq 0xe3f2a
movzbl %al, %edx
leal -0x30(%rdx), %eax
cmpl $0x5, %eax
movb %bpl, 0x10(%rsp)
ja 0xd98ef
movl %eax, %eax
leaq 0xb7e2c(%rip), %rcx     # 0x1916d0
movq (%rcx,%rax,8), %rcx
jmp 0xd98f6
movq 0x20(%r12), %rax
leaq 0x8(%rsp), %rsi
movq %rax, (%rsi)
movq 0x18(%rbx), %rdi
callq 0xe3fc4
cmpl $0x100, %eax            # imm = 0x100
leaq 0x5e849(%rip), %rdx     # 0x138115
leaq 0x4560e(%rip), %rcx     # 0x11eee1
cmoveq %rdx, %rcx
leaq 0x5e81c(%rip), %rsi     # 0x1380fa
movq %rbx, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xde896
jmp 0xd999b
leaq 0x455eb(%rip), %rcx     # 0x11eee1
leaq 0x5e772(%rip), %rsi     # 0x13806f
movq %rbx, %rdi
movq %rdx, 0x20(%rsp)
xorl %eax, %eax
callq 0xde896
movq 0x18(%rbx), %rdi
leaq 0x8(%rsp), %rbp
movq %rbp, %rsi
callq 0xe3fc4
leaq 0x5e0b8(%rip), %rsi     # 0x1379dc
movq %rbx, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xde896
movb 0x10(%rsp), %r13b
cmpb $0x74, %r13b
movq 0x30(%r12), %r12
movq (%rbp), %rcx
leaq 0x624aa(%rip), %rax     # 0x13bdf3
leaq 0x303c3(%rip), %rdx     # 0x109d13
cmoveq %rax, %rdx
subq %rcx, %r12
leaq 0x5e781(%rip), %rsi     # 0x1380df
setle %bpl
movq %rbx, %rdi
movq %r12, %r8
xorl %eax, %eax
callq 0xde896
cmpl $0x30, 0x20(%rsp)
setne %al
orb %bpl, %al
jne 0xd999b
xorl %r8d, %r8d
cmpb $0x74, %r13b
sete %r8b
movq 0x8(%rsp), %rsi
movl 0x18(%r14), %ecx
movq %rbx, %rdi
movq %r12, %rdx
callq 0xd8f5c
movq %r15, %rdi
callq 0xeaf3c
movl 0x2c(%rsp), %esi
movq %rbx, %rdi
callq 0xdebb7
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq