// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq $0x0, -0x40(%rbp)
movq -0x8(%rbp), %rdi
leaq -0x1c(%rbp), %rsi
callq 0x15b580
movq -0x18(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x28(%rbp)
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movq (%rax), %rdx
leaq 0x6bbe3(%rip), %rsi     # 0x1bcdf9
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movl $0x1, %esi
callq 0x15b560
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x28(%rbp), %rsi
callq 0x1652c0
movl %eax, %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x10(%rax)
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movl 0x10(%rax), %edx
leaq 0x7f6f5(%rip), %rsi     # 0x1d094c
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x28(%rbp), %rsi
callq 0x165170
movb %al, %cl
movq -0x18(%rbp), %rax
movb %cl, 0x18(%rax)
movq -0x8(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x18(%rbp), %rax
movzbl 0x18(%rax), %eax
movl %eax, -0x44(%rbp)
movq -0x18(%rbp), %rax
movzbl 0x18(%rax), %edi
callq 0x1515f0
movq -0x50(%rbp), %rdi
movl -0x44(%rbp), %edx
movq %rax, %rcx
leaq 0x7fba7(%rip), %rsi     # 0x1d0e50
movb $0x0, %al
callq 0x15b0d0
movq -0x18(%rbp), %rax
movzbl 0x19(%rax), %eax
cmpl $0x0, %eax
je 0x1512cf
movq -0x18(%rbp), %rax
movzbl 0x18(%rax), %eax
cmpl $0x75, %eax
je 0x1512cf
jmp 0x1515d2
movq -0x18(%rbp), %rax
movzbl 0x18(%rax), %eax
cmpl $0x7b, %eax
jne 0x1512e4
movq -0x18(%rbp), %rax
movb $0x1, 0x1b(%rax)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x28(%rbp), %rsi
callq 0x1652c0
movl %eax, %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x14(%rax)
movq -0x8(%rbp), %rdi
callq 0x1711d0
movq %rax, -0x40(%rbp)
movq -0x18(%rbp), %rdi
movq -0x40(%rbp), %rsi
callq 0x1516d0
movq -0x8(%rbp), %rax
movq %rax, -0x60(%rbp)
movq -0x18(%rbp), %rax
movl 0x14(%rax), %eax
movl %eax, -0x54(%rbp)
movq -0x40(%rbp), %rdi
callq 0x172650
movq -0x60(%rbp), %rdi
movl -0x54(%rbp), %edx
movq %rax, %rcx
leaq 0x7fb24(%rip), %rsi     # 0x1d0e68
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x28(%rbp), %rsi
callq 0x1652c0
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x28(%rax)
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x28(%rax), %rdx
leaq 0x7fb07(%rip), %rsi     # 0x1d0e81
movb $0x0, %al
callq 0x15b0d0
movq -0x18(%rbp), %rax
movq (%rax), %rax
movq -0x18(%rbp), %rcx
addq 0x28(%rcx), %rax
movq -0x18(%rbp), %rcx
cmpq 0x8(%rcx), %rax
jle 0x15139f
jmp 0x1515d2
movq -0x18(%rbp), %rax
movzbl 0x18(%rax), %eax
cmpl $0x75, %eax
jne 0x1513b6
movq $0xb, -0x30(%rbp)
jmp 0x1513c6
movq -0x18(%rbp), %rax
movq 0x28(%rax), %rax
subq $0x2, %rax
movq %rax, -0x30(%rbp)
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rdi
callq 0x15f250
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rdi
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rsi
movq -0x18(%rbp), %rax
movq (%rax), %rdx
addq $0x2, %rdx
movq -0x30(%rbp), %rcx
callq 0x15f500
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rdi
callq 0x15f340
movl %eax, -0x34(%rbp)
movl -0x34(%rbp), %eax
andl $0xffff, %eax           # imm = 0xFFFF
movl %eax, -0x34(%rbp)
movq -0x8(%rbp), %rdi
movl -0x34(%rbp), %edx
leaq 0x4fc67(%rip), %rsi     # 0x1a1087
movb $0x0, %al
callq 0x15b0d0
movq -0x18(%rbp), %rax
movl 0x14(%rax), %eax
andl $0x8000, %eax           # imm = 0x8000
cmpl $0x0, %eax
je 0x15146e
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x28(%rbp), %rsi
callq 0x165580
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x38(%rax)
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x38(%rax), %rdx
leaq 0x7fa33(%rip), %rsi     # 0x1d0e9a
movb $0x0, %al
callq 0x15b0d0
movq -0x18(%rbp), %rax
movzbl 0x18(%rax), %eax
cmpl $0x74, %eax
je 0x151488
movq -0x18(%rbp), %rax
movzbl 0x18(%rax), %eax
cmpl $0x7a, %eax
jne 0x1514dc
movq -0x18(%rbp), %rax
movl 0x14(%rax), %eax
andl $0x100, %eax            # imm = 0x100
cmpl $0x0, %eax
je 0x1514dc
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x28(%rbp), %rsi
addq $0x11, %rsi
callq 0x165540
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x40(%rax)
movq -0x18(%rbp), %rax
cmpq $0x7ffffffe, 0x40(%rax) # imm = 0x7FFFFFFE
jle 0x1514cc
jmp 0x1515d2
movq -0x18(%rbp), %rax
movq 0x40(%rax), %rcx
shlq $0x20, %rcx
movq %rcx, 0x40(%rax)
movq -0x28(%rbp), %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x20(%rax)
movq -0x18(%rbp), %rax
movq (%rax), %rcx
movq -0x18(%rbp), %rax
addq 0x28(%rax), %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x30(%rax)
movq -0x18(%rbp), %rax
movq 0x28(%rax), %rcx
movq -0x18(%rbp), %rax
addq 0x38(%rax), %rcx
movq -0x18(%rbp), %rax
addq 0x40(%rax), %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x48(%rax)
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x48(%rax), %rdx
leaq 0x7f981(%rip), %rsi     # 0x1d0eb3
movb $0x0, %al
callq 0x15b0d0
movq -0x18(%rbp), %rax
movq (%rax), %rax
movq -0x18(%rbp), %rcx
addq 0x48(%rcx), %rax
movq -0x18(%rbp), %rcx
cmpq 0x8(%rcx), %rax
jle 0x151554
jmp 0x1515d2
movq -0x18(%rbp), %rax
movb $0x1, 0x1a(%rax)
movq -0x18(%rbp), %rax
movzbl 0x18(%rax), %eax
addl $-0x73, %eax
movl %eax, %ecx
movq %rcx, -0x68(%rbp)
subl $0x7, %eax
ja 0x1515d0
movq -0x68(%rbp), %rax
leaq 0x7f6eb(%rip), %rcx     # 0x1d0c68
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
callq 0x151a50
jmp 0x1515d0
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
callq 0x151b00
jmp 0x1515d0
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
callq 0x151ed0
jmp 0x1515d0
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
callq 0x152050
jmp 0x1515d2
movq -0x40(%rbp), %rdi
callq 0x171750
movq -0x8(%rbp), %rdi
movl -0x1c(%rbp), %esi
callq 0x15b5a0
addq $0x70, %rsp
popq %rbp
retq
nopl (%rax)