#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
int /*<<< orphan*/ cpuid(int, long *);
int /*<<< orphan*/ testflag(int);
long getcputype() {
  long i, cpb[4], cpid[4];
  if (!testflag(0x200000))
    return (0);
  cpuid(0, cpid);
  if (!cpid[0])
    return (0);
  cpuid(1, cpb);
  i = (cpb[3] & ~((1 << 22) | (1 << 30) | (1 << 31)));
  cpuid(0x80000000, cpb);
  if (((unsigned long)cpb[0]) > 0x8000000) {
    cpuid(0x80000001, cpb);
    i |= (cpb[3] & (1 << 31));
    if (!((cpid[1] ^ 0x68747541) | (cpid[3] ^ 0x69746e65) |
          (cpid[2] ^ 0x444d4163)))
      i |= (cpb[3] & ((1 << 22) | (1 << 30)));
  }
  if (i & (1 << 25))
    i |= (1 << 22);
  return (i);
}


x86 assembly (clang, -O0):
<getcputype>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    $0x200000,%edi
call   1040 <testflag@plt>
cmp    $0x0,%eax
jne    1148 <getcputype+0x28>
movq   $0x0,-0x8(%rbp)
jmp    1234 <getcputype+0x114>
lea    -0x50(%rbp),%rsi
xor    %edi,%edi
call   1030 <cpuid@plt>
cmpq   $0x0,-0x50(%rbp)
jne    116b <getcputype+0x4b>
movq   $0x0,-0x8(%rbp)
jmp    1234 <getcputype+0x114>
lea    -0x30(%rbp),%rsi
mov    $0x1,%edi
call   1030 <cpuid@plt>
mov    -0x18(%rbp),%rax
and    $0x3fbfffff,%rax
mov    %rax,-0x10(%rbp)
lea    -0x30(%rbp),%rsi
mov    $0x80000000,%edi
call   1030 <cpuid@plt>
cmpq   $0x8000000,-0x30(%rbp)
08
jbe    120a <getcputype+0xea>
lea    -0x30(%rbp),%rsi
mov    $0x80000001,%edi
call   1030 <cpuid@plt>
mov    -0x18(%rbp),%rax
and    $0xffffffff80000000,%rax
or     -0x10(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x48(%rbp),%rax
xor    $0x68747541,%rax
mov    -0x38(%rbp),%rcx
xor    $0x69746e65,%rcx
or     %rcx,%rax
mov    -0x40(%rbp),%rcx
xor    $0x444d4163,%rcx
or     %rcx,%rax
cmp    $0x0,%rax
jne    1205 <getcputype+0xe5>
mov    -0x18(%rbp),%rax
and    $0x40400000,%rax
or     -0x10(%rbp),%rax
mov    %rax,-0x10(%rbp)
jmp    120a <getcputype+0xea>
mov    -0x10(%rbp),%rax
and    $0x2000000,%rax
cmp    $0x0,%rax
je     122c <getcputype+0x10c>
mov    -0x10(%rbp),%rax
or     $0x400000,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getcputype>:
push   %r14
push   %rbx
sub    $0x48,%rsp
mov    $0x200000,%edi
call   1040 <testflag@plt>
xor    %ebx,%ebx
test   %eax,%eax
je     11e5 <getcputype+0xc5>
mov    %rsp,%rsi
xor    %edi,%edi
call   1030 <cpuid@plt>
cmpq   $0x0,(%rsp)
je     11e5 <getcputype+0xc5>
lea    0x20(%rsp),%rbx
mov    $0x1,%edi
mov    %rbx,%rsi
call   1030 <cpuid@plt>
mov    0x38(%rsp),%r14
and    $0x3fbfffff,%r14d
mov    $0x80000000,%edi
mov    %rbx,%rsi
call   1030 <cpuid@plt>
cmpq   $0x8000001,0x20(%rsp)
jb     11d5 <getcputype+0xb5>
lea    0x20(%rsp),%rsi
mov    $0x80000001,%edi
call   1030 <cpuid@plt>
mov    0x38(%rsp),%rax
mov    %rax,%rcx
and    $0xffffffff80000000,%rcx
or     %rcx,%r14
mov    $0x68747541,%ecx
xor    0x8(%rsp),%rcx
mov    $0x69746e65,%edx
xor    0x18(%rsp),%rdx
or     %rcx,%rdx
mov    $0x444d4163,%ecx
xor    0x10(%rsp),%rcx
or     %rdx,%rcx
jne    11d5 <getcputype+0xb5>
and    $0x40400000,%eax
or     %rax,%r14
mov    %r14,%rbx
shr    $0x3,%rbx
and    $0x400000,%ebx
or     %r14,%rbx
mov    %rbx,%rax
add    $0x48,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i64 @getcputype() {
%1 = alloca i64
%2 = alloca i64
%3 = alloca [4 x i64]
%4 = alloca [4 x i64]
%5 = call i32 @testflag(i32 2097152)
%6 = icmp ne i32 %5, 0
br i1 %6, label %8, label %7
7: ; preds = %0
store i64 0, i64* %1
br label %62
8: ; preds = %0
%9 = getelementptr inbounds [4 x i64], [4 x i64]* %4, i64 0, i64 0
%10 = call i32 @cpuid(i32 0, i64* %9)
%11 = getelementptr inbounds [4 x i64], [4 x i64]* %4, i64 0, i64 0
%12 = load i64, i64* %11
%13 = icmp ne i64 %12, 0
br i1 %13, label %15, label %14
14: ; preds = %8
store i64 0, i64* %1
br label %62
15: ; preds = %8
%16 = getelementptr inbounds [4 x i64], [4 x i64]* %3, i64 0, i64 0
%17 = call i32 @cpuid(i32 1, i64* %16)
%18 = getelementptr inbounds [4 x i64], [4 x i64]* %3, i64 0, i64 3
%19 = load i64, i64* %18
%20 = and i64 %19, 1069547519
store i64 %20, i64* %2
%21 = getelementptr inbounds [4 x i64], [4 x i64]* %3, i64 0, i64 0
%22 = call i32 @cpuid(i32 -2147483648, i64* %21)
%23 = getelementptr inbounds [4 x i64], [4 x i64]* %3, i64 0, i64 0
%24 = load i64, i64* %23
%25 = icmp ugt i64 %24, 134217728
br i1 %25, label %26, label %53
26: ; preds = %15
%27 = getelementptr inbounds [4 x i64], [4 x i64]* %3, i64 0, i64 0
%28 = call i32 @cpuid(i32 -2147483647, i64* %27)
%29 = getelementptr inbounds [4 x i64], [4 x i64]* %3, i64 0, i64 3
%30 = load i64, i64* %29
%31 = and i64 %30, -2147483648
%32 = load i64, i64* %2
%33 = or i64 %32, %31
store i64 %33, i64* %2
%34 = getelementptr inbounds [4 x i64], [4 x i64]* %4, i64 0, i64 1
%35 = load i64, i64* %34
%36 = xor i64 %35, 1752462657
%37 = getelementptr inbounds [4 x i64], [4 x i64]* %4, i64 0, i64 3
%38 = load i64, i64* %37
%39 = xor i64 %38, 1769238117
%40 = or i64 %36, %39
%41 = getelementptr inbounds [4 x i64], [4 x i64]* %4, i64 0, i64 2
%42 = load i64, i64* %41
%43 = xor i64 %42, 1145913699
%44 = or i64 %40, %43
%45 = icmp ne i64 %44, 0
br i1 %45, label %52, label %46
46: ; preds = %26
%47 = getelementptr inbounds [4 x i64], [4 x i64]* %3, i64 0, i64 3
%48 = load i64, i64* %47
%49 = and i64 %48, 1077936128
%50 = load i64, i64* %2
%51 = or i64 %50, %49
store i64 %51, i64* %2
br label %52
52: ; preds = %46, %26
br label %53
53: ; preds = %52, %15
%54 = load i64, i64* %2
%55 = and i64 %54, 33554432
%56 = icmp ne i64 %55, 0
br i1 %56, label %57, label %60
57: ; preds = %53
%58 = load i64, i64* %2
%59 = or i64 %58, 4194304
store i64 %59, i64* %2
br label %60
60: ; preds = %57, %53
%61 = load i64, i64* %2
store i64 %61, i64* %1
br label %62
62: ; preds = %60, %14, %7
%63 = load i64, i64* %1
ret i64 %63
}

LLVM IR (-O2):
define i64 @getcputype() {
%1 = alloca [4 x i64]
%2 = alloca [4 x i64]
%3 = bitcast [4 x i64]* %1 to i8*
%4 = bitcast [4 x i64]* %2 to i8*
%5 = tail call i32 @testflag(i32 2097152)
%6 = icmp eq i32 %5, 0
br i1 %6, label %46, label %7
7: ; preds = %0
%8 = getelementptr inbounds [4 x i64], [4 x i64]* %2, i64 0, i64 0
%9 = call i32 @cpuid(i32 0, i64* %8)
%10 = load i64, i64* %8
%11 = icmp eq i64 %10, 0
br i1 %11, label %46, label %12
12: ; preds = %7
%13 = getelementptr inbounds [4 x i64], [4 x i64]* %1, i64 0, i64 0
%14 = call i32 @cpuid(i32 1, i64* %13)
%15 = getelementptr inbounds [4 x i64], [4 x i64]* %1, i64 0, i64 3
%16 = load i64, i64* %15
%17 = and i64 %16, 1069547519
%18 = call i32 @cpuid(i32 -2147483648, i64* %13)
%19 = load i64, i64* %13
%20 = icmp ugt i64 %19, 134217728
br i1 %20, label %21, label %41
21: ; preds = %12
%22 = call i32 @cpuid(i32 -2147483647, i64* %13)
%23 = load i64, i64* %15
%24 = and i64 %23, -2147483648
%25 = or i64 %24, %17
%26 = getelementptr inbounds [4 x i64], [4 x i64]* %2, i64 0, i64 1
%27 = load i64, i64* %26
%28 = xor i64 %27, 1752462657
%29 = getelementptr inbounds [4 x i64], [4 x i64]* %2, i64 0, i64 3
%30 = load i64, i64* %29
%31 = xor i64 %30, 1769238117
%32 = or i64 %31, %28
%33 = getelementptr inbounds [4 x i64], [4 x i64]* %2, i64 0, i64 2
%34 = load i64, i64* %33
%35 = xor i64 %34, 1145913699
%36 = or i64 %32, %35
%37 = icmp eq i64 %36, 0
br i1 %37, label %38, label %41
38: ; preds = %21
%39 = and i64 %23, 1077936128
%40 = or i64 %25, %39
br label %41
41: ; preds = %21, %38, %12
%42 = phi i64 [ %25, %21 ], [ %40, %38 ], [ %17, %12 ]
%43 = lshr i64 %42, 3
%44 = and i64 %43, 4194304
%45 = or i64 %44, %42
br label %46
46: ; preds = %7, %0, %41
%47 = phi i64 [ %45, %41 ], [ 0, %0 ], [ 0, %7 ]
ret i64 %47
}