// File: /workspace/github_c_makefile_star2_O0/enzo1982[P]smooth/libraries/libcpuid/cpuid_main.c
// Function: update_cache_instances
static void update_cache_instances(struct internal_cache_instances_t* caches,
                                   struct internal_apic_info_t* apic_info,
                                   struct internal_id_info_t* id_info,
                                   bool debugf_is_needed)
{
	uint32_t cache_id_index = 0;
	cache_type_t level;

	for (level = 0; level < NUM_CACHE_TYPES; level++) {
		if (id_info->cache_mask[level] == 0x00000000) {
			apic_info->cache_id[level] = -1;
			continue;
		}
		apic_info->cache_id[level] = apic_info->apic_id & id_info->cache_mask[level];
		cache_id_index             = apic_info->cache_id[level] % CACHES_HTABLE_SIZE;
		if ((caches->htable[level][cache_id_index].cache_id == 0) || (caches->htable[level][cache_id_index].cache_id == apic_info->cache_id[level])) {
			if (caches->htable[level][cache_id_index].num_logical_cpu == 0)
				caches->instances[level]++;
			caches->htable[level][cache_id_index].cache_id = apic_info->cache_id[level];
			caches->htable[level][cache_id_index].num_logical_cpu++;
		}
		else {
			warnf("update_cache_instances: collision at index %u (cache ID is %i, not %i)\n",
				cache_id_index, caches->htable[level][cache_id_index].cache_id, apic_info->cache_id[level]);
		}
	}

	if (debugf_is_needed)
		debugf(3, "Logical CPU %4u: APIC ID %4i, package ID %4i, core ID %4i, thread %i, L1I$ ID %4i, L1D$ ID %4i, L2$ ID %4i, L3$ ID %4i, L4$ ID %4i\n",
			apic_info->logical_cpu, apic_info->apic_id, apic_info->package_id, apic_info->core_id, apic_info->smt_id,
			apic_info->cache_id[L1I], apic_info->cache_id[L1D], apic_info->cache_id[L2], apic_info->cache_id[L3], apic_info->cache_id[L4]);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %rbx
subq $0x58, %rsp
movb %cl, %al
movq %rdi, -0x20(%rbp)
movq %rsi, -0x28(%rbp)
movq %rdx, -0x30(%rbp)
andb $0x1, %al
movb %al, -0x31(%rbp)
movl $0x0, -0x38(%rbp)
movl $0x0, -0x3c(%rbp)
cmpl $0x5, -0x3c(%rbp)
jae 0x134738
movq -0x30(%rbp), %rax
movl -0x3c(%rbp), %ecx
cmpl $0x0, 0x14(%rax,%rcx,4)
jne 0x13460a
movq -0x28(%rbp), %rax
movl -0x3c(%rbp), %ecx
movl $0xffffffff, 0x10(%rax,%rcx,4) # imm = 0xFFFFFFFF
jmp 0x13472a
movq -0x28(%rbp), %rax
movl (%rax), %edx
movq -0x30(%rbp), %rax
movl -0x3c(%rbp), %ecx
andl 0x14(%rax,%rcx,4), %edx
movq -0x28(%rbp), %rax
movl -0x3c(%rbp), %ecx
movl %edx, 0x10(%rax,%rcx,4)
movq -0x28(%rbp), %rax
movl -0x3c(%rbp), %ecx
movl 0x10(%rax,%rcx,4), %eax
movl $0x100, %ecx            # imm = 0x100
cltd
idivl %ecx
movl %edx, -0x38(%rbp)
movq -0x20(%rbp), %rax
addq $0x8, %rax
movl -0x3c(%rbp), %ecx
shlq $0xb, %rcx
addq %rcx, %rax
movl -0x38(%rbp), %ecx
cmpl $0x0, 0x4(%rax,%rcx,8)
je 0x13467e
movq -0x20(%rbp), %rax
addq $0x8, %rax
movl -0x3c(%rbp), %ecx
shlq $0xb, %rcx
addq %rcx, %rax
movl -0x38(%rbp), %ecx
movl 0x4(%rax,%rcx,8), %eax
movq -0x28(%rbp), %rcx
movl -0x3c(%rbp), %edx
cmpl 0x10(%rcx,%rdx,4), %eax
jne 0x1346f3
movq -0x20(%rbp), %rax
addq $0x8, %rax
movl -0x3c(%rbp), %ecx
shlq $0xb, %rcx
addq %rcx, %rax
movl -0x38(%rbp), %ecx
movzwl (%rax,%rcx,8), %eax
cmpl $0x0, %eax
jne 0x1346ac
movq -0x20(%rbp), %rax
movl -0x3c(%rbp), %ecx
movb (%rax,%rcx), %dl
addb $0x1, %dl
movb %dl, (%rax,%rcx)
movq -0x28(%rbp), %rax
movl -0x3c(%rbp), %ecx
movl 0x10(%rax,%rcx,4), %edx
movq -0x20(%rbp), %rax
addq $0x8, %rax
movl -0x3c(%rbp), %ecx
shlq $0xb, %rcx
addq %rcx, %rax
movl -0x38(%rbp), %ecx
movl %edx, 0x4(%rax,%rcx,8)
movq -0x20(%rbp), %rax
addq $0x8, %rax
movl -0x3c(%rbp), %ecx
shlq $0xb, %rcx
addq %rcx, %rax
movl -0x38(%rbp), %ecx
movw (%rax,%rcx,8), %dx
addw $0x1, %dx
movw %dx, (%rax,%rcx,8)
jmp 0x134728
movl -0x38(%rbp), %esi
movq -0x20(%rbp), %rax
addq $0x8, %rax
movl -0x3c(%rbp), %ecx
shlq $0xb, %rcx
addq %rcx, %rax
movl -0x38(%rbp), %ecx
movl 0x4(%rax,%rcx,8), %edx
movq -0x28(%rbp), %rax
movl -0x3c(%rbp), %ecx
movl 0x10(%rax,%rcx,4), %ecx
leaq 0x73941(%rip), %rdi     # 0x1a8062
movb $0x0, %al
callq 0x1356a0
jmp 0x13472a
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x1345de
testb $0x1, -0x31(%rbp)
je 0x1347b8
movq -0x28(%rbp), %rax
movzwl 0x24(%rax), %edx
movq -0x28(%rbp), %rax
movl (%rax), %ecx
movq -0x28(%rbp), %rax
movl 0x4(%rax), %r8d
movq -0x28(%rbp), %rax
movl 0x8(%rax), %r9d
movq -0x28(%rbp), %rax
movl 0xc(%rax), %r15d
movq -0x28(%rbp), %rax
movl 0x10(%rax), %r14d
movq -0x28(%rbp), %rax
movl 0x14(%rax), %ebx
movq -0x28(%rbp), %rax
movl 0x18(%rax), %r11d
movq -0x28(%rbp), %rax
movl 0x1c(%rax), %r10d
movq -0x28(%rbp), %rax
movl 0x20(%rax), %eax
movl $0x3, %edi
leaq 0x73914(%rip), %rsi     # 0x1a80aa
movl %r15d, (%rsp)
movl %r14d, 0x8(%rsp)
movl %ebx, 0x10(%rsp)
movl %r11d, 0x18(%rsp)
movl %r10d, 0x20(%rsp)
movl %eax, 0x28(%rsp)
movb $0x0, %al
callq 0x135780
addq $0x58, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
nopw %cs:(%rax,%rax)