#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_fn(int, unsigned int *);
int /*<<< orphan*/ printf(char *, ...);
void cpuid_arch_perf() {
  unsigned int results[4];
  unsigned int eax, ebx, edx, v;
  cpuid_fn(0x0a, results);
  eax = results[0];
  ebx = results[1];
  edx = results[3];
  printf("eax=0x%x\n", eax);
  printf("Version ID                      %3u\n",
         v = ((eax >> 0) & (~(~0U << (7 - 0 + 1)))));
  if (!v) {
    printf("This processor doesn't support architectural perf. cntrs\n");
    return;
  }
  printf("Perf. mon. cntr / logical cpu   %3u\n",
         ((eax >> 8) & (~(~0U << (15 - 8 + 1)))));
  printf("Perf. mon. cntr Bit width       %3u\n",
         ((eax >> 16) & (~(~0U << (23 - 16 + 1)))));
  printf("Fixed perf. mon. cntr / logical cpu %3u\n",
         ((edx >> 0) & (~(~0U << (4 - 0 + 1)))));
  printf("Fixed perf. mon. cntr Bit width %3u\n",
         ((edx >> 5) & (~(~0U << (12 - 5 + 1)))));
  printf("Length of EBX bit vector        %3u\n",
         ((eax >> 24) & (~(~0U << (31 - 24 + 1)))));
  printf("\n");
  printf("Core cycle             %u\n",
         !((ebx >> 0) & (~(~0U << (0 - 0 + 1)))));
  printf("Instr retired          %u\n",
         !((ebx >> 1) & (~(~0U << (1 - 1 + 1)))));
  printf("Ref. cycles            %u\n",
         !((ebx >> 2) & (~(~0U << (2 - 2 + 1)))));
  printf("Last Level Cache Ref.  %u\n",
         !((ebx >> 3) & (~(~0U << (3 - 3 + 1)))));
  printf("Last Level Cache Miss  %u\n",
         !((ebx >> 4) & (~(~0U << (4 - 4 + 1)))));
  printf("Branch Instr. retired  %u\n",
         !((ebx >> 5) & (~(~0U << (5 - 5 + 1)))));
  printf("Branch Miss retired    %u\n",
         !((ebx >> 6) & (~(~0U << (6 - 6 + 1)))));
}


x86 assembly (clang, -O0):
<cpuid_arch_perf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    -0x10(%rbp),%rsi
mov    $0xa,%edi
call   1030 <cpuid_fn@plt>
mov    -0x10(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x14(%rbp),%esi
lea    0xeae(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x14(%rbp),%esi
shr    $0x0,%esi
and    $0xff,%esi
mov    %esi,-0x20(%rbp)
lea    0xe9b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
cmpl   $0x0,-0x20(%rbp)
jne    1193 <cpuid_arch_perf+0x73>
lea    0xea8(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    131c <cpuid_arch_perf+0x1fc>
mov    -0x14(%rbp),%esi
shr    $0x8,%esi
and    $0xff,%esi
lea    0xec3(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x14(%rbp),%esi
shr    $0x10,%esi
and    $0xff,%esi
lea    0xece(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x1c(%rbp),%esi
shr    $0x0,%esi
and    $0x1f,%esi
lea    0xedc(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x1c(%rbp),%esi
shr    $0x5,%esi
and    $0xff,%esi
lea    0xeeb(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x14(%rbp),%esi
shr    $0x18,%esi
and    $0xff,%esi
lea    0xef6(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe4e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%eax
shr    $0x0,%eax
and    $0x1,%eax
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%esi
lea    0xee9(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%eax
shr    $0x1,%eax
and    $0x1,%eax
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%esi
lea    0xee0(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%eax
shr    $0x2,%eax
and    $0x1,%eax
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%esi
lea    0xed7(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%eax
shr    $0x3,%eax
and    $0x1,%eax
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%esi
lea    0xece(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%eax
shr    $0x4,%eax
and    $0x1,%eax
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%esi
lea    0xec5(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%eax
shr    $0x5,%eax
and    $0x1,%eax
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%esi
lea    0xebc(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%eax
shr    $0x6,%eax
and    $0x1,%eax
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%esi
lea    0xeb3(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cpuid_arch_perf>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsp,%rsi
mov    $0xa,%edi
call   1040 <cpuid_fn@plt>
mov    (%rsp),%ebx
mov    0x4(%rsp),%r14d
mov    0xc(%rsp),%ebp
lea    0xe98(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xe92(%rip),%rdi
mov    %ebx,%eax
and    $0xff,%eax
mov    %eax,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %ebx,%eax
and    $0xff,%eax
je     12a9 <cpuid_arch_perf+0x169>
movzbl %bh,%esi
lea    0xe90(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %ebx,%eax
shr    $0x10,%eax
movzbl %al,%esi
lea    0xe9f(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %ebp,%esi
and    $0x1f,%esi
lea    0xeb1(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
shr    $0x5,%ebp
movzbl %bpl,%esi
lea    0xec5(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
shr    $0x18,%ebx
lea    0xed9(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %r14d,%esi
not    %esi
and    $0x1,%esi
lea    0xedc(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
xor    %esi,%esi
test   $0x2,%r14b
sete   %sil
lea    0xedf(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
xor    %esi,%esi
test   $0x4,%r14b
sete   %sil
lea    0xee2(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
xor    %esi,%esi
test   $0x8,%r14b
sete   %sil
lea    0xee5(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
xor    %esi,%esi
test   $0x10,%r14b
sete   %sil
lea    0xee8(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
xor    %esi,%esi
test   $0x20,%r14b
sete   %sil
lea    0xeeb(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
xor    %esi,%esi
test   $0x40,%r14b
sete   %sil
lea    0xeee(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
jmp    12b5 <cpuid_arch_perf+0x175>
lea    0xef9(%rip),%rdi
call   1050 <puts@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [10 x i8] c"eax=0x%x\0A\00"
@.str.1 = [37 x i8] c"Version ID %3u\0A\00"
@.str.2 = [58 x i8] c"This processor doesn't support architectural perf. cntrs\0A\00"
@.str.3 = [37 x i8] c"Perf. mon. cntr / logical cpu %3u\0A\00"
@.str.4 = [37 x i8] c"Perf. mon. cntr Bit width %3u\0A\00"
@.str.5 = [41 x i8] c"Fixed perf. mon. cntr / logical cpu %3u\0A\00"
@.str.6 = [37 x i8] c"Fixed perf. mon. cntr Bit width %3u\0A\00"
@.str.7 = [37 x i8] c"Length of EBX bit vector %3u\0A\00"
@.str.8 = [2 x i8] c"\0A\00"
@.str.9 = [27 x i8] c"Core cycle %u\0A\00"
@.str.10 = [27 x i8] c"Instr retired %u\0A\00"
@.str.11 = [27 x i8] c"Ref. cycles %u\0A\00"
@.str.12 = [27 x i8] c"Last Level Cache Ref. %u\0A\00"
@.str.13 = [27 x i8] c"Last Level Cache Miss %u\0A\00"
@.str.14 = [27 x i8] c"Branch Instr. retired %u\0A\00"
@.str.15 = [27 x i8] c"Branch Miss retired %u\0A\00"
define void @cpuid_arch_perf() {
%1 = alloca [4 x i32]
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = getelementptr inbounds [4 x i32], [4 x i32]* %1, i64 0, i64 0
%7 = call i32 @cpuid_fn(i32 10, i32* %6)
%8 = getelementptr inbounds [4 x i32], [4 x i32]* %1, i64 0, i64 0
%9 = load i32, i32* %8
store i32 %9, i32* %2
%10 = getelementptr inbounds [4 x i32], [4 x i32]* %1, i64 0, i64 1
%11 = load i32, i32* %10
store i32 %11, i32* %3
%12 = getelementptr inbounds [4 x i32], [4 x i32]* %1, i64 0, i64 3
%13 = load i32, i32* %12
store i32 %13, i32* %4
%14 = load i32, i32* %2
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %14)
%16 = load i32, i32* %2
%17 = lshr i32 %16, 0
%18 = and i32 %17, 255
store i32 %18, i32* %5
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), i32 %18)
%20 = load i32, i32* %5
%21 = icmp ne i32 %20, 0
br i1 %21, label %24, label %22
22: ; preds = %0
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.2, i64 0, i64 0))
br label %95
24: ; preds = %0
%25 = load i32, i32* %2
%26 = lshr i32 %25, 8
%27 = and i32 %26, 255
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.3, i64 0, i64 0), i32 %27)
%29 = load i32, i32* %2
%30 = lshr i32 %29, 16
%31 = and i32 %30, 255
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.4, i64 0, i64 0), i32 %31)
%33 = load i32, i32* %4
%34 = lshr i32 %33, 0
%35 = and i32 %34, 31
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.5, i64 0, i64 0), i32 %35)
%37 = load i32, i32* %4
%38 = lshr i32 %37, 5
%39 = and i32 %38, 255
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.6, i64 0, i64 0), i32 %39)
%41 = load i32, i32* %2
%42 = lshr i32 %41, 24
%43 = and i32 %42, 255
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.7, i64 0, i64 0), i32 %43)
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i64 0, i64 0))
%46 = load i32, i32* %3
%47 = lshr i32 %46, 0
%48 = and i32 %47, 1
%49 = icmp ne i32 %48, 0
%50 = xor i1 %49, true
%51 = zext i1 %50 to i32
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.9, i64 0, i64 0), i32 %51)
%53 = load i32, i32* %3
%54 = lshr i32 %53, 1
%55 = and i32 %54, 1
%56 = icmp ne i32 %55, 0
%57 = xor i1 %56, true
%58 = zext i1 %57 to i32
%59 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.10, i64 0, i64 0), i32 %58)
%60 = load i32, i32* %3
%61 = lshr i32 %60, 2
%62 = and i32 %61, 1
%63 = icmp ne i32 %62, 0
%64 = xor i1 %63, true
%65 = zext i1 %64 to i32
%66 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.11, i64 0, i64 0), i32 %65)
%67 = load i32, i32* %3
%68 = lshr i32 %67, 3
%69 = and i32 %68, 1
%70 = icmp ne i32 %69, 0
%71 = xor i1 %70, true
%72 = zext i1 %71 to i32
%73 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.12, i64 0, i64 0), i32 %72)
%74 = load i32, i32* %3
%75 = lshr i32 %74, 4
%76 = and i32 %75, 1
%77 = icmp ne i32 %76, 0
%78 = xor i1 %77, true
%79 = zext i1 %78 to i32
%80 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.13, i64 0, i64 0), i32 %79)
%81 = load i32, i32* %3
%82 = lshr i32 %81, 5
%83 = and i32 %82, 1
%84 = icmp ne i32 %83, 0
%85 = xor i1 %84, true
%86 = zext i1 %85 to i32
%87 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.14, i64 0, i64 0), i32 %86)
%88 = load i32, i32* %3
%89 = lshr i32 %88, 6
%90 = and i32 %89, 1
%91 = icmp ne i32 %90, 0
%92 = xor i1 %91, true
%93 = zext i1 %92 to i32
%94 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.15, i64 0, i64 0), i32 %93)
br label %95
95: ; preds = %24, %22
ret void
}

LLVM IR (-O2):
@.str = [10 x i8] c"eax=0x%x\0A\00"
@.str.1 = [37 x i8] c"Version ID %3u\0A\00"
@.str.3 = [37 x i8] c"Perf. mon. cntr / logical cpu %3u\0A\00"
@.str.4 = [37 x i8] c"Perf. mon. cntr Bit width %3u\0A\00"
@.str.5 = [41 x i8] c"Fixed perf. mon. cntr / logical cpu %3u\0A\00"
@.str.6 = [37 x i8] c"Fixed perf. mon. cntr Bit width %3u\0A\00"
@.str.7 = [37 x i8] c"Length of EBX bit vector %3u\0A\00"
@.str.9 = [27 x i8] c"Core cycle %u\0A\00"
@.str.10 = [27 x i8] c"Instr retired %u\0A\00"
@.str.11 = [27 x i8] c"Ref. cycles %u\0A\00"
@.str.12 = [27 x i8] c"Last Level Cache Ref. %u\0A\00"
@.str.13 = [27 x i8] c"Last Level Cache Miss %u\0A\00"
@.str.14 = [27 x i8] c"Branch Instr. retired %u\0A\00"
@.str.15 = [27 x i8] c"Branch Miss retired %u\0A\00"
@str = [57 x i8] c"This processor doesn't support architectural perf. cntrs\00"
define void @cpuid_arch_perf() {
%1 = alloca [4 x i32]
%2 = bitcast [4 x i32]* %1 to i8*
%3 = getelementptr inbounds [4 x i32], [4 x i32]* %1, i64 0, i64 0
%4 = call i32 @cpuid_fn(i32 10, i32* %3)
%5 = load i32, i32* %3
%6 = getelementptr inbounds [4 x i32], [4 x i32]* %1, i64 0, i64 1
%7 = load i32, i32* %6
%8 = getelementptr inbounds [4 x i32], [4 x i32]* %1, i64 0, i64 3
%9 = load i32, i32* %8
%10 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %5)
%11 = and i32 %5, 255
%12 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), i32 %11)
%13 = icmp eq i32 %11, 0
br i1 %13, label %14, label %16
14: ; preds = %0
%15 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([57 x i8], [57 x i8]* @str, i64 0, i64 0))
br label %58
16: ; preds = %0
%17 = lshr i32 %5, 8
%18 = and i32 %17, 255
%19 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str.3, i64 0, i64 0), i32 %18)
%20 = lshr i32 %5, 16
%21 = and i32 %20, 255
%22 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str.4, i64 0, i64 0), i32 %21)
%23 = and i32 %9, 31
%24 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @.str.5, i64 0, i64 0), i32 %23)
%25 = lshr i32 %9, 5
%26 = and i32 %25, 255
%27 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str.6, i64 0, i64 0), i32 %26)
%28 = lshr i32 %5, 24
%29 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str.7, i64 0, i64 0), i32 %28)
%30 = call i32 @putchar(i32 10)
%31 = and i32 %7, 1
%32 = xor i32 %31, 1
%33 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.9, i64 0, i64 0), i32 %32)
%34 = lshr i32 %7, 1
%35 = and i32 %34, 1
%36 = xor i32 %35, 1
%37 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.10, i64 0, i64 0), i32 %36)
%38 = lshr i32 %7, 2
%39 = and i32 %38, 1
%40 = xor i32 %39, 1
%41 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.11, i64 0, i64 0), i32 %40)
%42 = lshr i32 %7, 3
%43 = and i32 %42, 1
%44 = xor i32 %43, 1
%45 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.12, i64 0, i64 0), i32 %44)
%46 = lshr i32 %7, 4
%47 = and i32 %46, 1
%48 = xor i32 %47, 1
%49 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.13, i64 0, i64 0), i32 %48)
%50 = lshr i32 %7, 5
%51 = and i32 %50, 1
%52 = xor i32 %51, 1
%53 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.14, i64 0, i64 0), i32 %52)
%54 = lshr i32 %7, 6
%55 = and i32 %54, 1
%56 = xor i32 %55, 1
%57 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.15, i64 0, i64 0), i32 %56)
br label %58
58: ; preds = %16, %14
ret void
}