#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 */
typedef int /*<<< orphan*/ v;

/* Variables and functions */
int pread(int, unsigned long long *, int, unsigned int);
int /*<<< orphan*/ printf(char *, char const *, ...);
void dump_msr(int fd, const char *name, unsigned index) {
  unsigned long long v;
  if (fd != -1 && pread(fd, &v, sizeof(v), index) == sizeof(v))
    printf("  %-40s  %16llx\n", name, v);
  else
    printf("  %-40s  %16s\n", name, "n/a");
}


x86 assembly (clang, -O0):
<dump_msr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
cmpl   $0xffffffff,-0x4(%rbp)
je     1177 <dump_msr+0x57>
mov    -0x4(%rbp),%edi
mov    -0x14(%rbp),%ecx
lea    -0x20(%rbp),%rsi
mov    $0x8,%edx
call   1040 <pread@plt>
cltq
cmp    $0x8,%rax
jne    1177 <dump_msr+0x57>
mov    -0x10(%rbp),%rsi
mov    -0x20(%rbp),%rdx
lea    0xe95(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1190 <dump_msr+0x70>
mov    -0x10(%rbp),%rsi
lea    0xe8f(%rip),%rdi
lea    0xe97(%rip),%rdx
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dump_msr>:
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
cmp    $0xffffffff,%edi
je     1151 <dump_msr+0x31>
mov    %edx,%ecx
lea    0x8(%rsp),%rsi
mov    $0x8,%edx
call   1040 <pread@plt>
cmp    $0x8,%eax
jne    1151 <dump_msr+0x31>
mov    0x8(%rsp),%rdx
lea    0xeb1(%rip),%rdi
jmp    115f <dump_msr+0x3f>
lea    0xeb9(%rip),%rdi
lea    0xec1(%rip),%rdx
mov    %rbx,%rsi
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
jmp    1030 <printf@plt>

LLVM IR (-O0):
@.str = [17 x i8] c" %-40s %16llx\0A\00"
@.str.1 = [15 x i8] c" %-40s %16s\0A\00"
@.str.2 = [4 x i8] c"n/a\00"
define void @dump_msr(i32 %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i64
store i32 %0, i32* %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%8 = load i32, i32* %4
%9 = icmp ne i32 %8, -1
br i1 %9, label %10, label %20
10: ; preds = %3
%11 = load i32, i32* %4
%12 = load i32, i32* %6
%13 = call i32 @pread(i32 %11, i64* %7, i32 8, i32 %12)
%14 = sext i32 %13 to i64
%15 = icmp eq i64 %14, 8
br i1 %15, label %16, label %20
16: ; preds = %10
%17 = load i8*, i8** %5
%18 = load i64, i64* %7
%19 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* %17, i64 %18)
br label %23
20: ; preds = %10, %3
%21 = load i8*, i8** %5
%22 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8* %21, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
br label %23
23: ; preds = %20, %16
ret void
}

LLVM IR (-O2):
@.str = [17 x i8] c" %-40s %16llx\0A\00"
@.str.1 = [15 x i8] c" %-40s %16s\0A\00"
@.str.2 = [4 x i8] c"n/a\00"
define void @dump_msr(i32 %0, i8* %1, i32 %2) {
%4 = alloca i64
%5 = bitcast i64* %4 to i8*
%6 = icmp eq i32 %0, -1
br i1 %6, label %13, label %7
7: ; preds = %3
%8 = call i32 @pread(i32 %0, i64* %4, i32 8, i32 %2)
%9 = icmp eq i32 %8, 8
br i1 %9, label %10, label %13
10: ; preds = %7
%11 = load i64, i64* %4
%12 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* %1, i64 %11)
br label %15
13: ; preds = %7, %3
%14 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8* %1, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
br label %15
15: ; preds = %13, %10
ret void
}