int detectCpu(void) {
  printf("\nCPU INFO:\n");
  unsigned long ebx, unused;
  __asm__("cpuid"
          : "=a"(unused), "=b"(ebx), "=c"(unused), "=d"(unused)
          : "a"(0));
  ;
  switch (ebx) {
  case 0x756e6547:
    do_intel();
    break;
  case 0x68747541:
    do_amd();
    break;
  default:
    printf("Unknown x86 CPU Detected\n");
    break;
  }
  return 0;
}


x86 assembly (clang, -O0):
<detectCpu>:
push   %rbp
mov    %rsp,%rbp
push   %rbx
sub    $0x28,%rsp
lea    0xec0(%rip),%rdi
xor    %eax,%eax
mov    %eax,-0x24(%rbp)
call   1040 <printf@plt>
mov    -0x24(%rbp),%eax
cpuid
mov    %rax,-0x18(%rbp)
mov    %rbx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
sub    $0x68747541,%rax
je     1199 <detectCpu+0x69>
jmp    1178 <detectCpu+0x48>
mov    -0x20(%rbp),%rax
sub    $0x756e6547,%rax
jne    11a5 <detectCpu+0x75>
jmp    118d <detectCpu+0x5d>
mov    $0x0,%al
call   1050 <do_intel@plt>
jmp    11b3 <detectCpu+0x83>
mov    $0x0,%al
call   1030 <do_amd@plt>
jmp    11b3 <detectCpu+0x83>
lea    0xe60(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %rbp
ret

x86 assembly (clang, -O2):
<detectCpu>:
push   %rbx
lea    0xec8(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
cpuid
cmp    $0x68747541,%rbx
je     115c <detectCpu+0x2c>
cmp    $0x756e6547,%rbx
jne    1165 <detectCpu+0x35>
xor    %eax,%eax
call   1050 <do_intel@plt>
jmp    1171 <detectCpu+0x41>
xor    %eax,%eax
call   1040 <do_amd@plt>
jmp    1171 <detectCpu+0x41>
lea    0xe9f(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [12 x i8] c"\0ACPU INFO:\0A\00"
@.str.1 = [26 x i8] c"Unknown x86 CPU Detected\0A\00"
define i32 @detectCpu() {
%1 = alloca i64
%2 = alloca i64
%3 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%4 = call { i64, i64, i64, i64 } asm "cpuid", "={ax},={bx},={cx},={dx},{ax},~{dirflag},~{fpsr},~{flags}"(i32 0)
%5 = extractvalue { i64, i64, i64, i64 } %4, 0
%6 = extractvalue { i64, i64, i64, i64 } %4, 1
%7 = extractvalue { i64, i64, i64, i64 } %4, 2
%8 = extractvalue { i64, i64, i64, i64 } %4, 3
store i64 %5, i64* %2
store i64 %6, i64* %1
store i64 %7, i64* %2
store i64 %8, i64* %2
%9 = load i64, i64* %1
switch i64 %9, label %14 [
i64 1970169159, label %10
i64 1752462657, label %12
]
10: ; preds = %0
%11 = call i32 (...) @do_intel()
br label %16
12: ; preds = %0
%13 = call i32 (...) @do_amd()
br label %16
14: ; preds = %0
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
br label %16
16: ; preds = %14, %12, %10
ret i32 0
}

LLVM IR (-O2):
@str = [11 x i8] c"\0ACPU INFO:\00"
@str.2 = [25 x i8] c"Unknown x86 CPU Detected\00"
define i32 @detectCpu() {
%1 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @str, i64 0, i64 0))
%2 = tail call { i64, i64, i64, i64 } asm "cpuid", "={ax},={bx},={cx},={dx},{ax},~{dirflag},~{fpsr},~{flags}"(i32 0)
%3 = extractvalue { i64, i64, i64, i64 } %2, 1
switch i64 %3, label %8 [
i64 1970169159, label %4
i64 1752462657, label %6
]
4: ; preds = %0
%5 = tail call i32 (...) @do_intel()
br label %10
6: ; preds = %0
%7 = tail call i32 (...) @do_amd()
br label %10
8: ; preds = %0
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str.2, i64 0, i64 0))
br label %10
10: ; preds = %8, %6, %4
ret i32 0
}