#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*/ uint32_t;

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int find_freq_from_fid(int /*<<< orphan*/);
int find_millivolts_from_vid(int /*<<< orphan*/);
int get_fidvid(int, int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
int strtoul(char *, int /*<<< orphan*/ *, int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  int err;
  int cpu;
  uint32_t fid, vid;
  if (argc < 2) {
    cpu = 0;
  } else {
    cpu = strtoul(argv[1], NULL, 0);
  }
  err = get_fidvid(cpu, &fid, &vid);
  if (err) {
    printf("can't get fid, vid from MSR\n");
    printf("Possible trouble: you don't run a powernow-k8 capable cpu\n");
    printf("or you are not root, or the msr driver is not present\n");
    exit(1);
  }
  printf("cpu %d currently at %d MHz and %d mV\n", cpu, find_freq_from_fid(fid),
         find_millivolts_from_vid(vid));
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    118c <main+0x2c>
movl   $0x0,-0x18(%rbp)
jmp    11a2 <main+0x42>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   1070 <strtoul@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%edi
lea    -0x1c(%rbp),%rsi
lea    -0x20(%rbp),%rdx
call   1060 <get_fidvid@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     11f3 <main+0x93>
lea    0xe3a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe49(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe76(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x1c(%rbp),%edi
call   1040 <find_freq_from_fid@plt>
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%edi
call   1050 <find_millivolts_from_vid@plt>
mov    -0x28(%rbp),%esi
mov    -0x24(%rbp),%edx
mov    %eax,%ecx
lea    0xe74(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
xor    %ebx,%ebx
cmp    $0x2,%edi
jl     1189 <main+0x19>
mov    0x8(%rsi),%rdi
xor    %esi,%esi
xor    %edx,%edx
call   1080 <strtoul@plt>
mov    %eax,%ebx
lea    0x4(%rsp),%rsi
mov    %rsp,%rdx
mov    %ebx,%edi
call   1070 <get_fidvid@plt>
test   %eax,%eax
jne    11cc <main+0x5c>
mov    0x4(%rsp),%edi
call   1050 <find_freq_from_fid@plt>
mov    %eax,%ebp
mov    (%rsp),%edi
call   1060 <find_millivolts_from_vid@plt>
lea    0xe4a(%rip),%rdi
mov    %ebx,%esi
mov    %ebp,%edx
mov    %eax,%ecx
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xe53(%rip),%rdi
call   1030 <puts@plt>
lea    0xe63(%rip),%rdi
call   1030 <puts@plt>
lea    0xe91(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [29 x i8] c"can't get fid, vid from MSR\0A\00"
@.str.1 = [59 x i8] c"Possible trouble: you don't run a powernow-k8 capable cpu\0A\00"
@.str.2 = [55 x i8] c"or you are not root, or the msr driver is not present\0A\00"
@.str.3 = [38 x i8] c"cpu %d currently at %d MHz and %d mV\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp slt i32 %10, 2
br i1 %11, label %12, label %13
12: ; preds = %2
store i32 0, i32* %7
br label %18
13: ; preds = %2
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 1
%16 = load i8*, i8** %15
%17 = call i32 @strtoul(i8* %16, i32* null, i32 0)
store i32 %17, i32* %7
br label %18
18: ; preds = %13, %12
%19 = load i32, i32* %7
%20 = call i32 @get_fidvid(i32 %19, i32* %8, i32* %9)
store i32 %20, i32* %6
%21 = load i32, i32* %6
%22 = icmp ne i32 %21, 0
br i1 %22, label %23, label %28
23: ; preds = %18
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str.1, i64 0, i64 0))
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.2, i64 0, i64 0))
%27 = call i32 @exit(i32 1)
unreachable
28: ; preds = %18
%29 = load i32, i32* %7
%30 = load i32, i32* %8
%31 = call i32 @find_freq_from_fid(i32 %30)
%32 = load i32, i32* %9
%33 = call i32 @find_millivolts_from_vid(i32 %32)
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.3, i64 0, i64 0), i32 %29, i32 %31, i32 %33)
ret i32 0
}

LLVM IR (-O2):
@.str.3 = [38 x i8] c"cpu %d currently at %d MHz and %d mV\0A\00"
@str = [28 x i8] c"can't get fid, vid from MSR\00"
@str.4 = [58 x i8] c"Possible trouble: you don't run a powernow-k8 capable cpu\00"
@str.5 = [54 x i8] c"or you are not root, or the msr driver is not present\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca i32
%5 = bitcast i32* %3 to i8*
%6 = bitcast i32* %4 to i8*
%7 = icmp slt i32 %0, 2
br i1 %7, label %12, label %8
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = tail call i32 @strtoul(i8* nocapture %10, i32* null, i32 0)
br label %12
12: ; preds = %2, %8
%13 = phi i32 [ %11, %8 ], [ 0, %2 ]
%14 = call i32 @get_fidvid(i32 %13, i32* %3, i32* %4)
%15 = icmp eq i32 %14, 0
br i1 %15, label %21, label %16
16: ; preds = %12
%17 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @str, i64 0, i64 0))
%18 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([58 x i8], [58 x i8]* @str.4, i64 0, i64 0))
%19 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([54 x i8], [54 x i8]* @str.5, i64 0, i64 0))
%20 = call i32 @exit(i32 1)
unreachable
21: ; preds = %12
%22 = load i32, i32* %3
%23 = call i32 @find_freq_from_fid(i32 %22)
%24 = load i32, i32* %4
%25 = call i32 @find_millivolts_from_vid(i32 %24)
%26 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str.3, i64 0, i64 0), i32 %13, i32 %23, i32 %25)
ret i32 0
}