// File: /workspace/github_c_makefile_star2_O0/enzo1982[P]smooth/libraries/libcpuid/libcpuid_util.c
// Function: decode_deterministic_cache_info_x86
void decode_deterministic_cache_info_x86(uint32_t cache_regs[][NUM_REGS],
                                         uint8_t subleaf_count,
                                         struct cpu_id_t* data,
                                         struct internal_id_info_t* internal)
{
	uint8_t i;
	uint32_t cache_level, cache_type, ways, partitions, linesize, sets, size, num_sharing_cache, index_msb;
	cache_type_t type;

	for (i = 0; i < subleaf_count; i++) {
		cache_level = EXTRACTS_BITS(cache_regs[i][EAX], 7, 5);
		cache_type  = EXTRACTS_BITS(cache_regs[i][EAX], 4, 0);
		if ((cache_level == 0) || (cache_type == 0))
			break;
		if (cache_level == 1 && cache_type == 1)
			type = L1D;
		else if (cache_level == 1 && cache_type == 2)
			type = L1I;
		else if (cache_level == 2 && cache_type == 3)
			type = L2;
		else if (cache_level == 3 && cache_type == 3)
			type = L3;
		else if (cache_level == 4 && cache_type == 3)
			type = L4;
		else {
			warnf("deterministic_cache: unknown level/typenumber combo (%d/%d), cannot\n", cache_level, cache_type);
			warnf("deterministic_cache: recognize cache type\n");
			continue;
		}
		num_sharing_cache       = EXTRACTS_BITS(cache_regs[i][EAX], 25, 14) + 1;
		ways                    = EXTRACTS_BITS(cache_regs[i][EBX], 31, 22) + 1;
		partitions              = EXTRACTS_BITS(cache_regs[i][EBX], 21, 12) + 1;
		linesize                = EXTRACTS_BITS(cache_regs[i][EBX], 11,  0) + 1;
		sets                    = EXTRACTS_BITS(cache_regs[i][ECX], 31,  0) + 1;
		size                    = ways * partitions * linesize * sets / 1024;
		index_msb               = get_count_order(num_sharing_cache);
		internal->cache_mask[i] = ~((1 << index_msb) - 1);
		assign_cache_data(1, type, size, ways, linesize, data);
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movb %sil, %al
movq %rdi, -0x8(%rbp)
movb %al, -0x9(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movb $0x0, -0x21(%rbp)
movzbl -0x21(%rbp), %eax
movzbl -0x9(%rbp), %ecx
cmpl %ecx, %eax
jge 0x136812
movq -0x8(%rbp), %rax
movzbl -0x21(%rbp), %ecx
shlq $0x4, %rcx
addq %rcx, %rax
movl (%rax), %eax
shrl $0x5, %eax
movl %eax, %eax
andq $0x7, %rax
movl %eax, -0x28(%rbp)
movq -0x8(%rbp), %rax
movzbl -0x21(%rbp), %ecx
shlq $0x4, %rcx
addq %rcx, %rax
movl (%rax), %eax
shrl $0x0, %eax
movl %eax, %eax
andq $0x1f, %rax
movl %eax, -0x2c(%rbp)
cmpl $0x0, -0x28(%rbp)
je 0x136654
cmpl $0x0, -0x2c(%rbp)
jne 0x136659
jmp 0x136812
cmpl $0x1, -0x28(%rbp)
jne 0x136671
cmpl $0x1, -0x2c(%rbp)
jne 0x136671
movl $0x1, -0x4c(%rbp)
jmp 0x1366f4
cmpl $0x1, -0x28(%rbp)
jne 0x136686
cmpl $0x2, -0x2c(%rbp)
jne 0x136686
movl $0x0, -0x4c(%rbp)
jmp 0x1366f2
cmpl $0x2, -0x28(%rbp)
jne 0x13669b
cmpl $0x3, -0x2c(%rbp)
jne 0x13669b
movl $0x2, -0x4c(%rbp)
jmp 0x1366f0
cmpl $0x3, -0x28(%rbp)
jne 0x1366b0
cmpl $0x3, -0x2c(%rbp)
jne 0x1366b0
movl $0x3, -0x4c(%rbp)
jmp 0x1366ee
cmpl $0x4, -0x28(%rbp)
jne 0x1366c5
cmpl $0x3, -0x2c(%rbp)
jne 0x1366c5
movl $0x4, -0x4c(%rbp)
jmp 0x1366ec
movl -0x28(%rbp), %esi
movl -0x2c(%rbp), %edx
leaq 0x71b3b(%rip), %rdi     # 0x1a820d
movb $0x0, %al
callq 0x1356a0
leaq 0x71b72(%rip), %rdi     # 0x1a8252
movb $0x0, %al
callq 0x1356a0
jmp 0x136805
jmp 0x1366ee
jmp 0x1366f0
jmp 0x1366f2
jmp 0x1366f4
movq -0x8(%rbp), %rax
movzbl -0x21(%rbp), %ecx
shlq $0x4, %rcx
addq %rcx, %rax
movl (%rax), %eax
shrl $0xe, %eax
movl %eax, %eax
andq $0xfff, %rax            # imm = 0xFFF
addq $0x1, %rax
movl %eax, -0x44(%rbp)
movq -0x8(%rbp), %rax
movzbl -0x21(%rbp), %ecx
shlq $0x4, %rcx
addq %rcx, %rax
movl 0x4(%rax), %eax
shrl $0x16, %eax
movl %eax, %eax
andq $0x3ff, %rax            # imm = 0x3FF
addq $0x1, %rax
movl %eax, -0x30(%rbp)
movq -0x8(%rbp), %rax
movzbl -0x21(%rbp), %ecx
shlq $0x4, %rcx
addq %rcx, %rax
movl 0x4(%rax), %eax
shrl $0xc, %eax
movl %eax, %eax
andq $0x3ff, %rax            # imm = 0x3FF
addq $0x1, %rax
movl %eax, -0x34(%rbp)
movq -0x8(%rbp), %rax
movzbl -0x21(%rbp), %ecx
shlq $0x4, %rcx
addq %rcx, %rax
movl 0x4(%rax), %eax
shrl $0x0, %eax
movl %eax, %eax
andq $0xfff, %rax            # imm = 0xFFF
addq $0x1, %rax
movl %eax, -0x38(%rbp)
movq -0x8(%rbp), %rax
movzbl -0x21(%rbp), %ecx
shlq $0x4, %rcx
addq %rcx, %rax
movl 0x8(%rax), %eax
shrl $0x0, %eax
movl %eax, %eax
movabsq $0xffffffff, %rcx       # imm = 0xFFFFFFFF
andq %rcx, %rax
addq $0x1, %rax
movl %eax, -0x3c(%rbp)
movl -0x30(%rbp), %eax
imull -0x34(%rbp), %eax
imull -0x38(%rbp), %eax
imull -0x3c(%rbp), %eax
shrl $0xa, %eax
movl %eax, -0x40(%rbp)
movl -0x44(%rbp), %edi
callq 0x136820
movl %eax, -0x48(%rbp)
movl -0x48(%rbp), %ecx
movl $0x1, %edx
shll %cl, %edx
subl $0x1, %edx
xorl $-0x1, %edx
movq -0x20(%rbp), %rax
movzbl -0x21(%rbp), %ecx
movl %edx, 0x14(%rax,%rcx,4)
movl -0x4c(%rbp), %esi
movl -0x40(%rbp), %edx
movl -0x30(%rbp), %ecx
movl -0x38(%rbp), %r8d
movq -0x18(%rbp), %r9
movl $0x1, %edi
callq 0x1363c0
movb -0x21(%rbp), %al
addb $0x1, %al
movb %al, -0x21(%rbp)
jmp 0x1365fe
addq $0x50, %rsp
popq %rbp
retq
nopl (%rax,%rax)