// File: /workspace/github_c_makefile_star2_O0/enzo1982[P]smooth/classes/system/cpu.cpp
// Function: smooth::System::CPU::GetCPUID() const
S::Errors::Error S::System::CPU::GetCPUID() const
{
	static Bool	 initialized = False;
	static Bool	 failed	     = False;

	/* Return if we are already initialized or failed before.
	 */
	if (initialized) return Success();
	if (failed)	 return Error();

	/* Find total number of CPUs if CPUID is not available.
	 */
	if (!cpuid_present())
	{
		/* Set to initialized and get number of CPUs.
		 */
		initialized    = True;

		numCores       = cpuid_get_total_cpus();
		numLogicalCPUs = numCores;

#if defined __APPLE__ && defined __aarch64__
		/* Apple uses an HMP architecture with power efficient cores
		 * showing performance characteristics similar to threads in
		 * an SMT system. We assume there are 4 power efficient cores
		 * and treat them the same way as SMT threads.
		 */
		if (numCores >= 6) numCores -= 4;
#endif

		return Success();
	}

	/* Get actual CPUID data.
	 */
	cpu_raw_data_array_t	 raw;
	system_id_t		 system;

	failed	       = True;

	if (cpuid_get_all_raw_data(&raw)    < 0) return Error();
	if (cpu_identify_all(&raw, &system) < 0) return Error();

	/* OK, set to initialized.
	 */
	initialized    = True;
	failed	       = False;

	/* Set vendor and brand strings.
	 */
	cpu_id_t& data = system.cpu_types[0];

	vendorString   = data.vendor_str;
	brandString    = data.brand_str;

	if (brandString == NIL) brandString = data.cpu_codename;

	/* Find number of cores and logical CPUs per processor.
	 */
	numCores       = 0;
	numLogicalCPUs = 0;

	for (Int i = 0; i < system.num_cpu_types; i++)
	{
		numCores       += system.cpu_types[i].num_cores;
		numLogicalCPUs += system.cpu_types[i].num_logical_cpus;
	}

	/* Find number of processors and mutiply core numbers.
	 */
	Int	 numTotalCPUs  = cpuid_get_total_cpus();
	Int	 numProcessors = numTotalCPUs / numLogicalCPUs;

	numCores       *= numProcessors;
	numLogicalCPUs *= numProcessors;

	/* Set feature flags.
	 */
	hasMMX	       = data.flags[CPU_FEATURE_MMX];
	hasMMXExt      = data.flags[CPU_FEATURE_MMXEXT];

	hasSSE	       = data.flags[CPU_FEATURE_SSE];
	hasSSE2	       = data.flags[CPU_FEATURE_SSE2];
	hasSSE3	       = data.flags[CPU_FEATURE_PNI];
	hasSSSE3       = data.flags[CPU_FEATURE_SSSE3];
	hasSSE4_1      = data.flags[CPU_FEATURE_SSE4_1];
	hasSSE4_2      = data.flags[CPU_FEATURE_SSE4_2];
	hasSSE4a       = data.flags[CPU_FEATURE_SSE4A];

	hasAVX	       = data.flags[CPU_FEATURE_AVX];
	hasAVX2	       = data.flags[CPU_FEATURE_AVX2];

	has3DNow       = data.flags[CPU_FEATURE_3DNOW];
	has3DNowExt    = data.flags[CPU_FEATURE_3DNOWEXT];

	hasHT	       = data.flags[CPU_FEATURE_HT];
	hasNX	       = data.flags[CPU_FEATURE_NX];

	hasVMX	       = data.flags[CPU_FEATURE_VMX];
	hasSVM	       = data.flags[CPU_FEATURE_SVM];

	/* Free CPUID data.
	 */
	cpuid_free_system_id(&system);
	cpuid_free_raw_data_array(&raw);

	return Success();
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xd0, %rsp
movq %rdi, -0xb0(%rbp)
movq %rdi, %rax
movq %rax, -0xa8(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
testb $0x1, 0x10d74e(%rip)    # 0x213b49
je 0x10644a
leaq -0x20(%rbp), %rdi
movq %rdi, -0xb8(%rbp)
callq 0x5ca80
movq -0xb0(%rbp), %rdi
movq -0xb8(%rbp), %rsi
callq 0x5aed0
jmp 0x106422
leaq -0x20(%rbp), %rdi
callq 0x5a410
jmp 0x106852
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
leaq -0x20(%rbp), %rdi
callq 0x5a410
jmp 0x106862
testb $0x1, 0x10d6f9(%rip)    # 0x213b4a
je 0x106469
movq -0xb0(%rbp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x5a9c0
jmp 0x106852
callq 0x1316e0
cmpl $0x0, %eax
jne 0x1064e2
movb $0x1, 0x10d6cf(%rip)    # 0x213b49
callq 0x1316c0
movl %eax, %ecx
movq 0x102080(%rip), %rax    # 0x208508
movl %ecx, (%rax)
movl (%rax), %ecx
movq 0x1022ad(%rip), %rax    # 0x208740
movl %ecx, (%rax)
leaq -0x40(%rbp), %rdi
movq %rdi, -0xc0(%rbp)
callq 0x5ca80
movq -0xb0(%rbp), %rdi
movq -0xc0(%rbp), %rsi
callq 0x5aed0
jmp 0x1064ba
leaq -0x40(%rbp), %rdi
callq 0x5a410
jmp 0x106852
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
leaq -0x40(%rbp), %rdi
callq 0x5a410
jmp 0x106862
movb $0x1, 0x10d661(%rip)    # 0x213b4a
leaq -0x50(%rbp), %rdi
callq 0x131ab0
cmpl $0x0, %eax
jge 0x10650d
movq -0xb0(%rbp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x5a9c0
jmp 0x106852
leaq -0x50(%rbp), %rdi
leaq -0x78(%rbp), %rsi
callq 0x133880
cmpl $0x0, %eax
jge 0x106535
movq -0xb0(%rbp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x5a9c0
jmp 0x106852
movb $0x1, 0x10d60d(%rip)    # 0x213b49
movb $0x0, 0x10d607(%rip)    # 0x213b4a
movq -0x70(%rbp), %rax
movq %rax, -0x80(%rbp)
movq -0x80(%rbp), %rsi
addq $0x4, %rsi
movq 0x10211e(%rip), %rdi    # 0x208678
callq 0x5a230
movq -0x80(%rbp), %rsi
addq $0x14, %rsi
movq 0x10225a(%rip), %rdi    # 0x2087c8
callq 0x5a230
movq 0x10224e(%rip), %rdi    # 0x2087c8
xorl %esi, %esi
callq 0x59320
testb $0x1, %al
jne 0x106587
jmp 0x10659e
movq -0x80(%rbp), %rsi
addq $0x150, %rsi            # imm = 0x150
movq 0x10222f(%rip), %rdi    # 0x2087c8
callq 0x5a230
movq 0x101f63(%rip), %rax    # 0x208508
movl $0x0, (%rax)
movq 0x10218e(%rip), %rax    # 0x208740
movl $0x0, (%rax)
movl $0x0, -0x84(%rbp)
movl -0x84(%rbp), %eax
movzbl -0x78(%rbp), %ecx
cmpl %ecx, %eax
jge 0x10663b
movq -0x70(%rbp), %rax
movslq -0x84(%rbp), %rcx
imulq $0x21e0, %rcx, %rcx     # imm = 0x21E0
addq %rcx, %rax
movl 0xec(%rax), %ecx
movq 0x101f16(%rip), %rax    # 0x208508
addl (%rax), %ecx
movq 0x101f0d(%rip), %rax    # 0x208508
movl %ecx, (%rax)
movq -0x70(%rbp), %rax
movslq -0x84(%rbp), %rcx
imulq $0x21e0, %rcx, %rcx     # imm = 0x21E0
addq %rcx, %rax
movl 0xf0(%rax), %ecx
movq 0x102121(%rip), %rax    # 0x208740
addl (%rax), %ecx
movq 0x102118(%rip), %rax    # 0x208740
movl %ecx, (%rax)
movl -0x84(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x84(%rbp)
jmp 0x1065c2
callq 0x1316c0
movl %eax, -0x88(%rbp)
movl -0x88(%rbp), %eax
movq 0x1020ed(%rip), %rcx    # 0x208740
movq %rcx, -0xd0(%rbp)
movl (%rcx), %ecx
cltd
idivl %ecx
movl %eax, %ecx
movq -0xd0(%rbp), %rax
movl %ecx, -0x8c(%rbp)
movl -0x8c(%rbp), %esi
movq 0x101e8d(%rip), %rcx    # 0x208508
movl (%rcx), %edx
imull %esi, %edx
movl %edx, (%rcx)
movl -0x8c(%rbp), %edx
movl (%rax), %ecx
imull %edx, %ecx
movl %ecx, (%rax)
movq -0x80(%rbp), %rax
movb 0x6d(%rax), %al
testb %al, %al
movq 0x101de1(%rip), %rax    # 0x208480
setne (%rax)
movq -0x80(%rbp), %rax
movb 0x8f(%rax), %al
testb %al, %al
movq 0x1027fb(%rip), %rax    # 0x208eb0
setne (%rax)
movq -0x80(%rbp), %rax
movb 0x6f(%rax), %al
testb %al, %al
movq 0x101ce8(%rip), %rax    # 0x2083b0
setne (%rax)
movq -0x80(%rbp), %rax
movb 0x70(%rax), %al
testb %al, %al
movq 0x1021ad(%rip), %rax    # 0x208888
setne (%rax)
movq -0x80(%rbp), %rax
movb 0x76(%rax), %al
testb %al, %al
movq 0x10259a(%rip), %rax    # 0x208c88
setne (%rax)
movq -0x80(%rbp), %rax
movb 0x7f(%rax), %al
testb %al, %al
movq 0x101e27(%rip), %rax    # 0x208528
setne (%rax)
movq -0x80(%rbp), %rax
movb 0x85(%rax), %al
testb %al, %al
movq 0x102211(%rip), %rax    # 0x208928
setne (%rax)
movq -0x80(%rbp), %rax
movb 0x86(%rax), %al
testb %al, %al
movq 0x101df3(%rip), %rax    # 0x208520
setne (%rax)
movq -0x80(%rbp), %rax
movb 0x9b(%rax), %al
testb %al, %al
movq 0x101f95(%rip), %rax    # 0x2086d8
setne (%rax)
movq -0x80(%rbp), %rax
movb 0x8e(%rax), %al
testb %al, %al
movq 0x1020df(%rip), %rax    # 0x208838
setne (%rax)
movq -0x80(%rbp), %rax
movb 0xb6(%rax), %al
testb %al, %al
movq 0x102771(%rip), %rax    # 0x208ee0
setne (%rax)
movq -0x80(%rbp), %rax
movb 0x90(%rax), %al
testb %al, %al
movq 0x10227b(%rip), %rax    # 0x208a00
setne (%rax)
movq -0x80(%rbp), %rax
movb 0x91(%rax), %al
testb %al, %al
movq 0x1023f5(%rip), %rax    # 0x208b90
setne (%rax)
movq -0x80(%rbp), %rax
movb 0x72(%rax), %al
testb %al, %al
movq 0x101c4a(%rip), %rax    # 0x2083f8
setne (%rax)
movq -0x80(%rbp), %rax
movb 0x92(%rax), %al
testb %al, %al
movq 0x1021f4(%rip), %rax    # 0x2089b8
setne (%rax)
movq -0x80(%rbp), %rax
movb 0x7b(%rax), %al
testb %al, %al
movq 0x101c81(%rip), %rax    # 0x208458
setne (%rax)
movq -0x80(%rbp), %rax
movb 0x98(%rax), %al
testb %al, %al
movq 0x102333(%rip), %rax    # 0x208b20
setne (%rax)
leaq -0x78(%rbp), %rdi
callq 0x1352f0
leaq -0x50(%rbp), %rdi
callq 0x1352b0
leaq -0xa0(%rbp), %rdi
movq %rdi, -0xc8(%rbp)
callq 0x5ca80
movq -0xb0(%rbp), %rdi
movq -0xc8(%rbp), %rsi
callq 0x5aed0
jmp 0x10682a
leaq -0xa0(%rbp), %rdi
callq 0x5a410
jmp 0x106852
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
leaq -0xa0(%rbp), %rdi
callq 0x5a410
jmp 0x106862
movq -0xa8(%rbp), %rax
addq $0xd0, %rsp
popq %rbp
retq
movq -0x28(%rbp), %rdi
callq 0x5b6b0
nopl (%rax,%rax)