#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*/ binary32(unsigned long long);
int /*<<< orphan*/ binary64(unsigned long long);
int /*<<< orphan*/ printf(char *, unsigned int, ...);
int read_msr(int, unsigned int, unsigned long long *);
void dumpmsr(int cpu, unsigned int msr, int size) {
  unsigned long long val = 0;
  if (read_msr(cpu, msr, &val) == 1) {
    if (size == 32) {
      printf("MSR: 0x%08x=0x%08lx : ", msr, (unsigned long)val);
      binary32(val);
    }
    if (size == 64) {
      printf("MSR: 0x%08x=0x%016llx : ", msr, val);
      binary64(val);
    }
    return;
  }
  printf("Couldn't read MSR 0x%x\n", msr);
}


x86 assembly (clang, -O0):
<dumpmsr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
lea    -0x18(%rbp),%rdx
call   1050 <read_msr@plt>
cmp    $0x1,%eax
jne    11c6 <dumpmsr+0x86>
cmpl   $0x20,-0xc(%rbp)
jne    1199 <dumpmsr+0x59>
mov    -0x8(%rbp),%esi
mov    -0x18(%rbp),%rdx
lea    0xe77(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1040 <binary32@plt>
cmpl   $0x40,-0xc(%rbp)
jne    11c1 <dumpmsr+0x81>
mov    -0x8(%rbp),%esi
mov    -0x18(%rbp),%rdx
lea    0xe66(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1060 <binary64@plt>
jmp    11d7 <dumpmsr+0x97>
mov    -0x8(%rbp),%esi
lea    0xe60(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dumpmsr>:
push   %rbp
push   %rbx
push   %rax
mov    %edx,%ebp
mov    %esi,%ebx
movq   $0x0,(%rsp)
mov    %rsp,%rdx
call   1050 <read_msr@plt>
cmp    $0x1,%eax
jne    1185 <dumpmsr+0x45>
cmp    $0x40,%ebp
je     1197 <dumpmsr+0x57>
cmp    $0x20,%ebp
jne    11b4 <dumpmsr+0x74>
mov    (%rsp),%rdx
lea    0xe8f(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1030 <printf@plt>
mov    (%rsp),%rdi
call   1040 <binary32@plt>
jmp    11b4 <dumpmsr+0x74>
lea    0xea4(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1030 <printf@plt>
jmp    11b4 <dumpmsr+0x74>
mov    (%rsp),%rdx
lea    0xe75(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1030 <printf@plt>
mov    (%rsp),%rdi
call   1060 <binary64@plt>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [23 x i8] c"MSR: 0x%08x=0x%08lx : \00"
@.str.1 = [25 x i8] c"MSR: 0x%08x=0x%016llx : \00"
@.str.2 = [24 x i8] c"Couldn't read MSR 0x%x\0A\00"
define void @dumpmsr(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i64
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32 %2, i32* %6
store i64 0, i64* %7
%8 = load i32, i32* %4
%9 = load i32, i32* %5
%10 = call i32 @read_msr(i32 %8, i32 %9, i64* %7)
%11 = icmp eq i32 %10, 1
br i1 %11, label %12, label %31
12: ; preds = %3
%13 = load i32, i32* %6
%14 = icmp eq i32 %13, 32
br i1 %14, label %15, label %21
15: ; preds = %12
%16 = load i32, i32* %5
%17 = load i64, i64* %7
%18 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 %16, i64 %17)
%19 = load i64, i64* %7
%20 = call i32 @binary32(i64 %19)
br label %21
21: ; preds = %15, %12
%22 = load i32, i32* %6
%23 = icmp eq i32 %22, 64
br i1 %23, label %24, label %30
24: ; preds = %21
%25 = load i32, i32* %5
%26 = load i64, i64* %7
%27 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i32 %25, i64 %26)
%28 = load i64, i64* %7
%29 = call i32 @binary64(i64 %28)
br label %30
30: ; preds = %24, %21
br label %34
31: ; preds = %3
%32 = load i32, i32* %5
%33 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i32 %32)
br label %34
34: ; preds = %31, %30
ret void
}

LLVM IR (-O2):
@.str = [23 x i8] c"MSR: 0x%08x=0x%08lx : \00"
@.str.1 = [25 x i8] c"MSR: 0x%08x=0x%016llx : \00"
@.str.2 = [24 x i8] c"Couldn't read MSR 0x%x\0A\00"
define void @dumpmsr(i32 %0, i32 %1, i32 %2) {
%4 = alloca i64
%5 = bitcast i64* %4 to i8*
store i64 0, i64* %4
%6 = call i32 @read_msr(i32 %0, i32 %1, i64* %4)
%7 = icmp eq i32 %6, 1
br i1 %7, label %8, label %19
8: ; preds = %3
switch i32 %2, label %21 [
i32 32, label %9
i32 64, label %14
]
9: ; preds = %8
%10 = load i64, i64* %4
%11 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 %1, i64 %10)
%12 = load i64, i64* %4
%13 = call i32 @binary32(i64 %12)
br label %21
14: ; preds = %8
%15 = load i64, i64* %4
%16 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i32 %1, i64 %15)
%17 = load i64, i64* %4
%18 = call i32 @binary64(i64 %17)
br label %21
19: ; preds = %3
%20 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i32 %1)
br label %21
21: ; preds = %9, %14, %8, %19
ret void
}