#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*/ decode(unsigned int);
int /*<<< orphan*/ printf(char *, ...);
int rdmsr(unsigned int, int, unsigned int *, unsigned int *);
int decode_live(unsigned int cpu) {
  unsigned int lo, hi;
  int err;
  err = rdmsr(cpu, 0x198, &lo, &hi);
  if (err) {
    printf("can't get MSR_IA32_PERF_STATUS for cpu %d\n", cpu);
    printf(
        "Possible trouble: you don't run an Enhanced SpeedStep capable cpu\n");
    printf("or you are not root, or the msr driver is not present\n");
    return 1;
  }
  decode(lo);
  return 0;
}


x86 assembly (clang, -O0):
<decode_live>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%edi
mov    $0x198,%esi
lea    -0xc(%rbp),%rdx
lea    -0x10(%rbp),%rcx
call   1040 <rdmsr@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     1196 <decode_live+0x66>
mov    -0x8(%rbp),%esi
lea    0xe99(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xeb6(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xeeb(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    11a5 <decode_live+0x75>
mov    -0xc(%rbp),%edi
call   1050 <decode@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<decode_live>:
push   %rbx
sub    $0x10,%rsp
mov    %edi,%ebx
lea    0x8(%rsp),%rdx
lea    0xc(%rsp),%rcx
mov    $0x198,%esi
call   1050 <rdmsr@plt>
test   %eax,%eax
je     118e <decode_live+0x4e>
lea    0xe9a(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xeb5(%rip),%rdi
call   1030 <puts@plt>
lea    0xeeb(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%eax
jmp    1199 <decode_live+0x59>
mov    0x8(%rsp),%edi
call   1060 <decode@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [43 x i8] c"can't get MSR_IA32_PERF_STATUS for cpu %d\0A\00"
@.str.1 = [67 x i8] c"Possible trouble: you don't run an Enhanced SpeedStep capable cpu\0A\00"
@.str.2 = [55 x i8] c"or you are not root, or the msr driver is not present\0A\00"
define i32 @decode_live(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 %0, i32* %3
%7 = load i32, i32* %3
%8 = call i32 @rdmsr(i32 %7, i32 408, i32* %4, i32* %5)
store i32 %8, i32* %6
%9 = load i32, i32* %6
%10 = icmp ne i32 %9, 0
br i1 %10, label %11, label %16
11: ; preds = %1
%12 = load i32, i32* %3
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0), i32 %12)
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([67 x i8], [67 x i8]* @.str.1, i64 0, i64 0))
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %2
br label %19
16: ; preds = %1
%17 = load i32, i32* %4
%18 = call i32 @decode(i32 %17)
store i32 0, i32* %2
br label %19
19: ; preds = %16, %11
%20 = load i32, i32* %2
ret i32 %20
}

LLVM IR (-O2):
@.str = [43 x i8] c"can't get MSR_IA32_PERF_STATUS for cpu %d\0A\00"
@str = [66 x i8] c"Possible trouble: you don't run an Enhanced SpeedStep capable cpu\00"
@str.3 = [54 x i8] c"or you are not root, or the msr driver is not present\00"
define i32 @decode_live(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = bitcast i32* %2 to i8*
%5 = bitcast i32* %3 to i8*
%6 = call i32 @rdmsr(i32 %0, i32 408, i32* %2, i32* %3)
%7 = icmp eq i32 %6, 0
br i1 %7, label %12, label %8
8: ; preds = %1
%9 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0), i32 %0)
%10 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([66 x i8], [66 x i8]* @str, i64 0, i64 0))
%11 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([54 x i8], [54 x i8]* @str.3, i64 0, i64 0))
br label %15
12: ; preds = %1
%13 = load i32, i32* %2
%14 = call i32 @decode(i32 %13)
br label %15
15: ; preds = %12, %8
%16 = phi i32 [ 1, %8 ], [ 0, %12 ]
ret i32 %16
}