#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, v;
  cpuid_fn(0x0a, results);
  eax = results[0];
  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("Length of EBX bit vector        %3u\n",
         ((eax >> 24) & (~(~0U << (31 - 24 + 1)))));
  printf("\n");
  ebx = results[1];
  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    -0x14(%rbp),%esi
lea    0xeba(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x14(%rbp),%esi
shr    $0x0,%esi
and    $0xff,%esi
mov    %esi,-0x1c(%rbp)
lea    0xea7(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
cmpl   $0x0,-0x1c(%rbp)
jne    1187 <cpuid_arch_perf+0x67>
lea    0xeb4(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    12e5 <cpuid_arch_perf+0x1c5>
mov    -0x14(%rbp),%esi
shr    $0x8,%esi
and    $0xff,%esi
lea    0xecf(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x14(%rbp),%esi
shr    $0x10,%esi
and    $0xff,%esi
lea    0xeda(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x14(%rbp),%esi
shr    $0x18,%esi
and    $0xff,%esi
lea    0xee5(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe8b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x18(%rbp)
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    0xed2(%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    0xec9(%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    0xec0(%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    0xeb7(%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    0xeae(%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    0xea5(%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    0xe9c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cpuid_arch_perf>:
push   %rbx
sub    $0x10,%rsp
mov    %rsp,%rsi
mov    $0xa,%edi
call   1040 <cpuid_fn@plt>
mov    (%rsp),%ebx
lea    0xea4(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xe9e(%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     1272 <cpuid_arch_perf+0x132>
movzbl %bh,%esi
lea    0xe9c(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %ebx,%eax
shr    $0x10,%eax
movzbl %al,%esi
lea    0xeab(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
shr    $0x18,%ebx
lea    0xebf(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    0x4(%rsp),%ebx
mov    %ebx,%esi
not    %esi
and    $0x1,%esi
lea    0xebf(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
xor    %esi,%esi
test   $0x2,%bl
sete   %sil
lea    0xec3(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
xor    %esi,%esi
test   $0x4,%bl
sete   %sil
lea    0xec7(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
xor    %esi,%esi
test   $0x8,%bl
sete   %sil
lea    0xecb(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
xor    %esi,%esi
test   $0x10,%bl
sete   %sil
lea    0xecf(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
xor    %esi,%esi
test   $0x20,%bl
sete   %sil
lea    0xed3(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
xor    %esi,%esi
test   $0x40,%bl
sete   %sil
lea    0xed7(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
jmp    127e <cpuid_arch_perf+0x13e>
lea    0xee2(%rip),%rdi
call   1050 <puts@plt>
add    $0x10,%rsp
pop    %rbx
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 = [37 x i8] c"Length of EBX bit vector %3u\0A\00"
@.str.6 = [2 x i8] c"\0A\00"
@.str.7 = [27 x i8] c"Core cycle %u\0A\00"
@.str.8 = [27 x i8] c"Instr retired %u\0A\00"
@.str.9 = [27 x i8] c"Ref. cycles %u\0A\00"
@.str.10 = [27 x i8] c"Last Level Cache Ref. %u\0A\00"
@.str.11 = [27 x i8] c"Last Level Cache Miss %u\0A\00"
@.str.12 = [27 x i8] c"Branch Instr. retired %u\0A\00"
@.str.13 = [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 = getelementptr inbounds [4 x i32], [4 x i32]* %1, i64 0, i64 0
%6 = call i32 @cpuid_fn(i32 10, i32* %5)
%7 = getelementptr inbounds [4 x i32], [4 x i32]* %1, i64 0, i64 0
%8 = load i32, i32* %7
store i32 %8, i32* %2
%9 = load i32, i32* %2
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %9)
%11 = load i32, i32* %2
%12 = lshr i32 %11, 0
%13 = and i32 %12, 255
store i32 %13, i32* %4
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), i32 %13)
%15 = load i32, i32* %4
%16 = icmp ne i32 %15, 0
br i1 %16, label %19, label %17
17: ; preds = %0
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.2, i64 0, i64 0))
br label %84
19: ; preds = %0
%20 = load i32, i32* %2
%21 = lshr i32 %20, 8
%22 = and i32 %21, 255
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.3, i64 0, i64 0), i32 %22)
%24 = load i32, i32* %2
%25 = lshr i32 %24, 16
%26 = and i32 %25, 255
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.4, i64 0, i64 0), i32 %26)
%28 = load i32, i32* %2
%29 = lshr i32 %28, 24
%30 = and i32 %29, 255
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.5, i64 0, i64 0), i32 %30)
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
%33 = getelementptr inbounds [4 x i32], [4 x i32]* %1, i64 0, i64 1
%34 = load i32, i32* %33
store i32 %34, i32* %3
%35 = load i32, i32* %3
%36 = lshr i32 %35, 0
%37 = and i32 %36, 1
%38 = icmp ne i32 %37, 0
%39 = xor i1 %38, true
%40 = zext i1 %39 to i32
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.7, i64 0, i64 0), i32 %40)
%42 = load i32, i32* %3
%43 = lshr i32 %42, 1
%44 = and i32 %43, 1
%45 = icmp ne i32 %44, 0
%46 = xor i1 %45, true
%47 = zext i1 %46 to i32
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.8, i64 0, i64 0), i32 %47)
%49 = load i32, i32* %3
%50 = lshr i32 %49, 2
%51 = and i32 %50, 1
%52 = icmp ne i32 %51, 0
%53 = xor i1 %52, true
%54 = zext i1 %53 to i32
%55 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.9, i64 0, i64 0), i32 %54)
%56 = load i32, i32* %3
%57 = lshr i32 %56, 3
%58 = and i32 %57, 1
%59 = icmp ne i32 %58, 0
%60 = xor i1 %59, true
%61 = zext i1 %60 to i32
%62 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.10, i64 0, i64 0), i32 %61)
%63 = load i32, i32* %3
%64 = lshr i32 %63, 4
%65 = and i32 %64, 1
%66 = icmp ne i32 %65, 0
%67 = xor i1 %66, true
%68 = zext i1 %67 to i32
%69 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.11, i64 0, i64 0), i32 %68)
%70 = load i32, i32* %3
%71 = lshr i32 %70, 5
%72 = and i32 %71, 1
%73 = icmp ne i32 %72, 0
%74 = xor i1 %73, true
%75 = zext i1 %74 to i32
%76 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.12, i64 0, i64 0), i32 %75)
%77 = load i32, i32* %3
%78 = lshr i32 %77, 6
%79 = and i32 %78, 1
%80 = icmp ne i32 %79, 0
%81 = xor i1 %80, true
%82 = zext i1 %81 to i32
%83 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.13, i64 0, i64 0), i32 %82)
br label %84
84: ; preds = %19, %17
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 = [37 x i8] c"Length of EBX bit vector %3u\0A\00"
@.str.7 = [27 x i8] c"Core cycle %u\0A\00"
@.str.8 = [27 x i8] c"Instr retired %u\0A\00"
@.str.9 = [27 x i8] c"Ref. cycles %u\0A\00"
@.str.10 = [27 x i8] c"Last Level Cache Ref. %u\0A\00"
@.str.11 = [27 x i8] c"Last Level Cache Miss %u\0A\00"
@.str.12 = [27 x i8] c"Branch Instr. retired %u\0A\00"
@.str.13 = [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 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %5)
%7 = and i32 %5, 255
%8 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), i32 %7)
%9 = icmp eq i32 %7, 0
br i1 %9, label %10, label %12
10: ; preds = %0
%11 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([57 x i8], [57 x i8]* @str, i64 0, i64 0))
br label %51
12: ; preds = %0
%13 = lshr i32 %5, 8
%14 = and i32 %13, 255
%15 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str.3, i64 0, i64 0), i32 %14)
%16 = lshr i32 %5, 16
%17 = and i32 %16, 255
%18 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str.4, i64 0, i64 0), i32 %17)
%19 = lshr i32 %5, 24
%20 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str.5, i64 0, i64 0), i32 %19)
%21 = call i32 @putchar(i32 10)
%22 = getelementptr inbounds [4 x i32], [4 x i32]* %1, i64 0, i64 1
%23 = load i32, i32* %22
%24 = and i32 %23, 1
%25 = xor i32 %24, 1
%26 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.7, i64 0, i64 0), i32 %25)
%27 = lshr i32 %23, 1
%28 = and i32 %27, 1
%29 = xor i32 %28, 1
%30 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.8, i64 0, i64 0), i32 %29)
%31 = lshr i32 %23, 2
%32 = and i32 %31, 1
%33 = xor i32 %32, 1
%34 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.9, i64 0, i64 0), i32 %33)
%35 = lshr i32 %23, 3
%36 = and i32 %35, 1
%37 = xor i32 %36, 1
%38 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.10, i64 0, i64 0), i32 %37)
%39 = lshr i32 %23, 4
%40 = and i32 %39, 1
%41 = xor i32 %40, 1
%42 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.11, i64 0, i64 0), i32 %41)
%43 = lshr i32 %23, 5
%44 = and i32 %43, 1
%45 = xor i32 %44, 1
%46 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.12, i64 0, i64 0), i32 %45)
%47 = lshr i32 %23, 6
%48 = and i32 %47, 1
%49 = xor i32 %48, 1
%50 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.13, i64 0, i64 0), i32 %49)
br label %51
51: ; preds = %12, %10
ret void
}