// File: /workspace/github_c_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl %ecx, 0x4(%rsp)
movq %rdx, %r14
movq %rsi, %rbx
movq %rdi, %r15
pushq $0x3
popq %r13
movl $0x100, %ebp            # imm = 0x100
xorl %r12d, %r12d
cmpq $0x5, %r12
je 0xc2d6f
movl 0x14(%r14,%r12,4), %ecx
testl %ecx, %ecx
je 0xc2d35
andl (%rbx), %ecx
movl %ecx, 0x10(%rbx,%r12,4)
movl %ecx, %eax
cltd
idivl %ebp
leaq (%r15,%rdx,8), %rsi
movl (%rsi,%r13,4), %eax
testl %eax, %eax
je 0xc2d3d
cmpl %ecx, %eax
je 0xc2d3d
leaq 0x41938(%rip), %rdi     # 0x104660
movl %edx, %esi
movl %eax, %edx
xorl %eax, %eax
callq 0xc340e
jmp 0xc2d63
orl $-0x1, 0x10(%rbx,%r12,4)
jmp 0xc2d63
movzwl -0x4(%rsi,%r13,4), %eax
testw %ax, %ax
jne 0xc2d57
incb (%r15,%r12)
movl 0x10(%rbx,%r12,4), %ecx
movzwl -0x4(%rsi,%r13,4), %eax
movl %ecx, (%rsi,%r13,4)
incl %eax
movw %ax, -0x4(%rsi,%r13,4)
incq %r12
addq $0x200, %r13            # imm = 0x200
jmp 0xc2cf6
cmpb $0x0, 0x4(%rsp)
je 0xc2dbd
movzwl 0x24(%rbx), %edx
movl (%rbx), %ecx
movl 0x4(%rbx), %r8d
movl 0x8(%rbx), %r9d
movl 0xc(%rbx), %r10d
movl 0x10(%rbx), %r11d
movl 0x14(%rbx), %r14d
movl 0x18(%rbx), %r15d
movl 0x1c(%rbx), %r12d
movl 0x20(%rbx), %ebx
leaq 0x41906(%rip), %rsi     # 0x1046a8
pushq $0x3
popq %rdi
xorl %eax, %eax
pushq %rbx
pushq %r12
pushq %r15
pushq %r14
pushq %r11
pushq %r10
callq 0xc34c6
addq $0x38, %rsp
jmp 0xc2dc1
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq