#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 */
struct timespec {
  long tv_sec;
  long tv_nsec;
};
typedef int /*<<< orphan*/ old_tsc;
typedef int /*<<< orphan*/ old_mperf;
typedef int /*<<< orphan*/ old_aperf;
typedef int /*<<< orphan*/ new_tsc;
typedef int /*<<< orphan*/ new_mperf;
typedef int /*<<< orphan*/ new_aperf;
typedef int /*<<< orphan*/ cpu_set_t;

/* Variables and functions */
int /*<<< orphan*/ CLOCK_MONOTONIC;
int /*<<< orphan*/ CPU_SET(unsigned int, int /*<<< orphan*/ *);
int /*<<< orphan*/ CPU_ZERO(int /*<<< orphan*/ *);
int /*<<< orphan*/ O_RDONLY;
scalar_t__ clock_gettime(int /*<<< orphan*/, struct timespec *);
scalar_t__ errno;
unsigned int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ pread(unsigned int, long long *, int, int);
int /*<<< orphan*/ printf(char *, long long, ...);
scalar_t__ sched_setaffinity(int /*<<< orphan*/, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ sprintf(char *, char *, unsigned int);
int /*<<< orphan*/ sqrt(unsigned int);
char *strerror(scalar_t__);
unsigned int strtol(char *, char **, int);
int /*<<< orphan*/ usage(char *);
int main(int argc, char **argv) {
  unsigned int i, cpu, fd;
  char msr_file_name[64];
  long long tsc, old_tsc, new_tsc;
  long long aperf, old_aperf, new_aperf;
  long long mperf, old_mperf, new_mperf;
  struct timespec before, after;
  long long int start, finish, total;
  cpu_set_t cpuset;
  if (argc != 2) {
    usage(argv[0]);
    return 1;
  }
  errno = 0;
  cpu = strtol(argv[1], (char **)NULL, 10);
  if (errno) {
    usage(argv[0]);
    return 1;
  }
  sprintf(msr_file_name, "/dev/cpu/%d/msr", cpu);
  fd = open(msr_file_name, O_RDONLY);
  if (fd == -1) {
    printf("/dev/cpu/%d/msr: %s\n", cpu, strerror(errno));
    return 4;
  }
  CPU_ZERO(&cpuset);
  CPU_SET(cpu, &cpuset);
  if (sched_setaffinity(0, sizeof(cpu_set_t), &cpuset)) {
    perror("Failed to set cpu affinity");
    return 1;
  }
  if (clock_gettime(CLOCK_MONOTONIC, &before) < 0) {
    perror("clock_gettime");
    return 1;
  }
  pread(fd, &old_tsc, sizeof(old_tsc), 0x10);
  pread(fd, &old_aperf, sizeof(old_mperf), 0xe7);
  pread(fd, &old_mperf, sizeof(old_aperf), 0xe8);
  for (i = 0; i < 0x8fffffff; i++) {
    sqrt(i);
  }
  if (clock_gettime(CLOCK_MONOTONIC, &after) < 0) {
    perror("clock_gettime");
    return 1;
  }
  pread(fd, &new_tsc, sizeof(new_tsc), 0x10);
  pread(fd, &new_aperf, sizeof(new_mperf), 0xe7);
  pread(fd, &new_mperf, sizeof(new_aperf), 0xe8);
  tsc = new_tsc - old_tsc;
  aperf = new_aperf - old_aperf;
  mperf = new_mperf - old_mperf;
  start = before.tv_sec * 1000L + before.tv_nsec / 1000000L;
  finish = after.tv_sec * 1000L + after.tv_nsec / 1000000L;
  total = finish - start;
  printf("runTime: %4.2f\n", 1.0 * total / 1000L);
  printf("freq: %7.0f\n", tsc / (1.0 * aperf / (1.0 * mperf)) / total);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x100,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     120b <main+0x3b>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1070 <usage@plt>
movl   $0x1,-0x4(%rbp)
jmp    1588 <main+0x3b8>
mov    0x2dbe(%rip),%rax
movq   $0x0,(%rax)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   1060 <strtol@plt>
mov    %eax,-0x18(%rbp)
mov    0x2d97(%rip),%rax
cmpq   $0x0,(%rax)
je     125b <main+0x8b>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1070 <usage@plt>
movl   $0x1,-0x4(%rbp)
jmp    1588 <main+0x3b8>
lea    -0x60(%rbp),%rdi
mov    -0x18(%rbp),%edx
lea    0xda7(%rip),%rsi
call   10d0 <sprintf@plt>
lea    -0x60(%rbp),%rdi
mov    0x2d6f(%rip),%rax
mov    (%rax),%esi
call   1090 <open@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    12ca <main+0xfa>
mov    -0x18(%rbp),%eax
mov    %rax,-0xf0(%rbp)
mov    0x2d32(%rip),%rax
mov    (%rax),%rdi
call   10e0 <strerror@plt>
mov    -0xf0(%rbp),%rsi
mov    %rax,%rdx
lea    0xd69(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x4,-0x4(%rbp)
jmp    1588 <main+0x3b8>
lea    -0xe4(%rbp),%rdi
call   1080 <CPU_ZERO@plt>
mov    -0x18(%rbp),%edi
lea    -0xe4(%rbp),%rsi
call   10f0 <CPU_SET@plt>
xor    %edi,%edi
mov    $0x4,%esi
lea    -0xe4(%rbp),%rdx
call   1050 <sched_setaffinity@plt>
cmp    $0x0,%rax
je     131a <main+0x14a>
lea    0xd2c(%rip),%rdi
call   10a0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1588 <main+0x3b8>
mov    0x2cbf(%rip),%rax
mov    (%rax),%edi
lea    -0xb8(%rbp),%rsi
call   1030 <clock_gettime@plt>
cmp    $0x0,%rax
jge    1351 <main+0x181>
lea    0xd10(%rip),%rdi
call   10a0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1588 <main+0x3b8>
mov    -0x1c(%rbp),%edi
lea    -0x70(%rbp),%rsi
mov    $0x8,%edx
mov    $0x10,%ecx
call   10c0 <pread@plt>
mov    -0x1c(%rbp),%edi
lea    -0x88(%rbp),%rsi
mov    $0x8,%edx
mov    $0xe7,%ecx
call   10c0 <pread@plt>
mov    -0x1c(%rbp),%edi
lea    -0xa0(%rbp),%rsi
mov    $0x8,%edx
mov    $0xe8,%ecx
call   10c0 <pread@plt>
movl   $0x0,-0x14(%rbp)
cmpl   $0x8fffffff,-0x14(%rbp)
jae    13c3 <main+0x1f3>
mov    -0x14(%rbp),%edi
call   10b0 <sqrt@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    13a0 <main+0x1d0>
mov    0x2c16(%rip),%rax
mov    (%rax),%edi
lea    -0xc8(%rbp),%rsi
call   1030 <clock_gettime@plt>
cmp    $0x0,%rax
jge    13fa <main+0x22a>
lea    0xc67(%rip),%rdi
call   10a0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1588 <main+0x3b8>
mov    -0x1c(%rbp),%edi
lea    -0x78(%rbp),%rsi
mov    $0x8,%edx
mov    $0x10,%ecx
call   10c0 <pread@plt>
mov    -0x1c(%rbp),%edi
lea    -0x90(%rbp),%rsi
mov    $0x8,%edx
mov    $0xe7,%ecx
call   10c0 <pread@plt>
mov    -0x1c(%rbp),%edi
lea    -0xa8(%rbp),%rsi
mov    $0x8,%edx
mov    $0xe8,%ecx
call   10c0 <pread@plt>
mov    -0x78(%rbp),%rax
sub    -0x70(%rbp),%rax
mov    %rax,-0x68(%rbp)
mov    -0x90(%rbp),%rax
sub    -0x88(%rbp),%rax
mov    %rax,-0x80(%rbp)
mov    -0xa8(%rbp),%rax
sub    -0xa0(%rbp),%rax
mov    %rax,-0x98(%rbp)
imul   $0x3e8,-0xb8(%rbp),%rax
mov    %rax,-0x100(%rbp)
mov    -0xb0(%rbp),%rax
mov    $0xf4240,%ecx
cqto
idiv   %rcx
mov    %rax,%rcx
mov    -0x100(%rbp),%rax
add    %rcx,%rax
mov    %rax,-0xd0(%rbp)
imul   $0x3e8,-0xc8(%rbp),%rax
mov    %rax,-0xf8(%rbp)
mov    -0xc0(%rbp),%rax
mov    $0xf4240,%ecx
cqto
idiv   %rcx
mov    %rax,%rcx
mov    -0xf8(%rbp),%rax
add    %rcx,%rax
mov    %rax,-0xd8(%rbp)
mov    -0xd8(%rbp),%rax
sub    -0xd0(%rbp),%rax
mov    %rax,-0xe0(%rbp)
cvtsi2sdq -0xe0(%rbp),%xmm1
ff ff
movsd  0xaf7(%rip),%xmm0
mulsd  %xmm1,%xmm0
movsd  0xaf3(%rip),%xmm1
divsd  %xmm1,%xmm0
cvttsd2si %xmm0,%rsi
lea    0xb39(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
cvtsi2sdq -0x68(%rbp),%xmm0
cvtsi2sdq -0x80(%rbp),%xmm2
movsd  0xac0(%rip),%xmm1
mulsd  %xmm2,%xmm1
cvtsi2sdq -0x98(%rbp),%xmm3
ff ff
movsd  0xaab(%rip),%xmm2
mulsd  %xmm3,%xmm2
divsd  %xmm2,%xmm1
divsd  %xmm1,%xmm0
cvtsi2sdq -0xe0(%rbp),%xmm1
ff ff
divsd  %xmm1,%xmm0
cvttsd2si %xmm0,%rsi
lea    0xaf4(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x100,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0xa8,%rsp
mov    %rsi,%rbp
cmp    $0x2,%edi
jne    1209 <main+0x39>
mov    0x2de4(%rip),%r15
movq   $0x0,(%r15)
mov    0x8(%rbp),%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1060 <strtol@plt>
cmpq   $0x0,(%r15)
je     1227 <main+0x57>
mov    0x0(%rbp),%rdi
call   1070 <usage@plt>
mov    $0x1,%ebx
mov    %ebx,%eax
add    $0xa8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %eax,%ebx
lea    0xdd8(%rip),%rsi
lea    0x60(%rsp),%rbp
mov    %rbp,%rdi
mov    %eax,%edx
call   10d0 <sprintf@plt>
mov    0x2da2(%rip),%rax
mov    (%rax),%esi
mov    %rbp,%rdi
call   1090 <open@plt>
cmp    $0xffffffff,%eax
je     148d <main+0x2bd>
mov    %eax,%r14d
lea    0x3c(%rsp),%rbp
mov    %rbp,%rdi
call   1080 <CPU_ZERO@plt>
mov    %ebx,%edi
mov    %rbp,%rsi
call   10f0 <CPU_SET@plt>
xor    %edi,%edi
mov    $0x4,%esi
mov    %rbp,%rdx
call   1050 <sched_setaffinity@plt>
test   %rax,%rax
jne    14be <main+0x2ee>
mov    0x2d4e(%rip),%rbp
mov    0x0(%rbp),%edi
lea    0x50(%rsp),%rsi
call   1030 <clock_gettime@plt>
test   %rax,%rax
js     14b5 <main+0x2e5>
lea    0x30(%rsp),%rsi
mov    %r14d,%edi
mov    $0x8,%edx
mov    $0x10,%ecx
call   10c0 <pread@plt>
lea    0x20(%rsp),%rsi
mov    %r14d,%edi
mov    $0x8,%edx
mov    $0xe7,%ecx
call   10c0 <pread@plt>
lea    0x10(%rsp),%rsi
mov    %r14d,%edi
mov    $0x8,%edx
mov    $0xe8,%ecx
call   10c0 <pread@plt>
xor    %ebx,%ebx
nop
mov    %ebx,%edi
call   10b0 <sqrt@plt>
lea    0x1(%rbx),%edi
call   10b0 <sqrt@plt>
lea    0x2(%rbx),%edi
call   10b0 <sqrt@plt>
lea    0x3(%rbx),%edi
call   10b0 <sqrt@plt>
lea    0x4(%rbx),%edi
call   10b0 <sqrt@plt>
lea    0x5(%rbx),%edi
call   10b0 <sqrt@plt>
lea    0x6(%rbx),%edi
call   10b0 <sqrt@plt>
lea    0x7(%rbx),%edi
call   10b0 <sqrt@plt>
lea    0x8(%rbx),%edi
call   10b0 <sqrt@plt>
lea    0x9(%rbx),%edi
call   10b0 <sqrt@plt>
lea    0xa(%rbx),%edi
call   10b0 <sqrt@plt>
lea    0xb(%rbx),%edi
call   10b0 <sqrt@plt>
lea    0xc(%rbx),%edi
call   10b0 <sqrt@plt>
add    $0xd,%ebx
cmp    $0x8fffffff,%ebx
jne    12f0 <main+0x120>
mov    0x0(%rbp),%edi
lea    0x40(%rsp),%rsi
call   1030 <clock_gettime@plt>
test   %rax,%rax
js     14b5 <main+0x2e5>
lea    0x28(%rsp),%rsi
mov    %r14d,%edi
mov    $0x8,%edx
mov    $0x10,%ecx
call   10c0 <pread@plt>
lea    0x18(%rsp),%rsi
mov    %r14d,%edi
mov    $0x8,%edx
mov    $0xe7,%ecx
call   10c0 <pread@plt>
lea    0x8(%rsp),%rsi
mov    %r14d,%edi
mov    $0x8,%edx
mov    $0xe8,%ecx
call   10c0 <pread@plt>
mov    0x28(%rsp),%r14
sub    0x30(%rsp),%r14
mov    0x18(%rsp),%r15
sub    0x20(%rsp),%r15
mov    0x8(%rsp),%rbp
movabs $0xbce4217d2849cb25,%rax
21 e4 bc
imulq  0x58(%rsp)
mov    %rdx,%rcx
sub    0x10(%rsp),%rbp
mov    %rdx,%rsi
shr    $0x3f,%rsi
sar    $0x12,%rcx
movabs $0x431bde82d7b634db,%rax
de 1b 43
imulq  0x48(%rsp)
add    %rsi,%rcx
mov    0x40(%rsp),%rax
mov    %rdx,%rsi
shr    $0x3f,%rsi
sar    $0x12,%rdx
add    %rsi,%rdx
add    %rcx,%rdx
sub    0x50(%rsp),%rax
imul   $0x3e8,%rax,%rax
add    %rdx,%rax
cvtsi2sd %rax,%xmm0
movsd  %xmm0,(%rsp)
divsd  0xbbf(%rip),%xmm0
cvttsd2si %xmm0,%rsi
lea    0xc09(%rip),%rdi
xor    %ebx,%ebx
xor    %eax,%eax
call   1040 <printf@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %r14,%xmm0
cvtsi2sd %r15,%xmm1
cvtsi2sd %rbp,%xmm2
divsd  %xmm2,%xmm1
divsd  %xmm1,%xmm0
divsd  (%rsp),%xmm0
cvttsd2si %xmm0,%rsi
lea    0xbe5(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    1217 <main+0x47>
mov    %ebx,%ebx
mov    (%r15),%rdi
call   10e0 <strerror@plt>
lea    0xb7a(%rip),%rdi
mov    %rbx,%rsi
mov    %rax,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x4,%ebx
jmp    1217 <main+0x47>
lea    0xb8c(%rip),%rdi
jmp    14c5 <main+0x2f5>
lea    0xb68(%rip),%rdi
call   10a0 <perror@plt>
jmp    1212 <main+0x42>

LLVM IR (-O0):
%struct.timespec = type { i64, i64 }
@errno = global i64 0
@.str = [16 x i8] c"/dev/cpu/%d/msr\00"
@O_RDONLY = global i32 0
@.str.1 = [21 x i8] c"/dev/cpu/%d/msr: %s\0A\00"
@.str.2 = [27 x i8] c"Failed to set cpu affinity\00"
@CLOCK_MONOTONIC = global i32 0
@.str.3 = [14 x i8] c"clock_gettime\00"
@.str.4 = [16 x i8] c"runTime: %4.2f\0A\00"
@.str.5 = [13 x i8] c"freq: %7.0f\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 [64 x i8]
%10 = alloca i64
%11 = alloca i64
%12 = alloca i64
%13 = alloca i64
%14 = alloca i64
%15 = alloca i64
%16 = alloca i64
%17 = alloca i64
%18 = alloca i64
%19 = alloca %struct.timespec
%20 = alloca %struct.timespec
%21 = alloca i64
%22 = alloca i64
%23 = alloca i64
%24 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%25 = load i32, i32* %4
%26 = icmp ne i32 %25, 2
br i1 %26, label %27, label %32
27: ; preds = %2
%28 = load i8**, i8*** %5
%29 = getelementptr inbounds i8*, i8** %28, i64 0
%30 = load i8*, i8** %29
%31 = call i32 @usage(i8* %30)
store i32 1, i32* %3
br label %149
32: ; preds = %2
store i64 0, i64* @errno
%33 = load i8**, i8*** %5
%34 = getelementptr inbounds i8*, i8** %33, i64 1
%35 = load i8*, i8** %34
%36 = call i32 @strtol(i8* %35, i8** null, i32 10)
store i32 %36, i32* %7
%37 = load i64, i64* @errno
%38 = icmp ne i64 %37, 0
br i1 %38, label %39, label %44
39: ; preds = %32
%40 = load i8**, i8*** %5
%41 = getelementptr inbounds i8*, i8** %40, i64 0
%42 = load i8*, i8** %41
%43 = call i32 @usage(i8* %42)
store i32 1, i32* %3
br label %149
44: ; preds = %32
%45 = getelementptr inbounds [64 x i8], [64 x i8]* %9, i64 0, i64 0
%46 = load i32, i32* %7
%47 = call i32 @sprintf(i8* %45, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 %46)
%48 = getelementptr inbounds [64 x i8], [64 x i8]* %9, i64 0, i64 0
%49 = load i32, i32* @O_RDONLY
%50 = call i32 @open(i8* %48, i32 %49)
store i32 %50, i32* %8
%51 = load i32, i32* %8
%52 = icmp eq i32 %51, -1
br i1 %52, label %53, label %59
53: ; preds = %44
%54 = load i32, i32* %7
%55 = zext i32 %54 to i64
%56 = load i64, i64* @errno
%57 = call i8* @strerror(i64 %56)
%58 = call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i64 %55, i8* %57)
store i32 4, i32* %3
br label %149
59: ; preds = %44
%60 = call i32 @CPU_ZERO(i32* %24)
%61 = load i32, i32* %7
%62 = call i32 @CPU_SET(i32 %61, i32* %24)
%63 = call i64 @sched_setaffinity(i32 0, i32 4, i32* %24)
%64 = icmp ne i64 %63, 0
br i1 %64, label %65, label %67
65: ; preds = %59
%66 = call i32 @perror(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %3
br label %149
67: ; preds = %59
%68 = load i32, i32* @CLOCK_MONOTONIC
%69 = call i64 @clock_gettime(i32 %68, %struct.timespec* %19)
%70 = icmp slt i64 %69, 0
br i1 %70, label %71, label %73
71: ; preds = %67
%72 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0))
store i32 1, i32* %3
br label %149
73: ; preds = %67
%74 = load i32, i32* %8
%75 = call i32 @pread(i32 %74, i64* %11, i32 8, i32 16)
%76 = load i32, i32* %8
%77 = call i32 @pread(i32 %76, i64* %14, i32 8, i32 231)
%78 = load i32, i32* %8
%79 = call i32 @pread(i32 %78, i64* %17, i32 8, i32 232)
store i32 0, i32* %6
br label %80
80: ; preds = %86, %73
%81 = load i32, i32* %6
%82 = icmp ult i32 %81, -1879048193
br i1 %82, label %83, label %89
83: ; preds = %80
%84 = load i32, i32* %6
%85 = call i32 @sqrt(i32 %84)
br label %86
86: ; preds = %83
%87 = load i32, i32* %6
%88 = add i32 %87, 1
store i32 %88, i32* %6
br label %80
89: ; preds = %80
%90 = load i32, i32* @CLOCK_MONOTONIC
%91 = call i64 @clock_gettime(i32 %90, %struct.timespec* %20)
%92 = icmp slt i64 %91, 0
br i1 %92, label %93, label %95
93: ; preds = %89
%94 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0))
store i32 1, i32* %3
br label %149
95: ; preds = %89
%96 = load i32, i32* %8
%97 = call i32 @pread(i32 %96, i64* %12, i32 8, i32 16)
%98 = load i32, i32* %8
%99 = call i32 @pread(i32 %98, i64* %15, i32 8, i32 231)
%100 = load i32, i32* %8
%101 = call i32 @pread(i32 %100, i64* %18, i32 8, i32 232)
%102 = load i64, i64* %12
%103 = load i64, i64* %11
%104 = sub nsw i64 %102, %103
store i64 %104, i64* %10
%105 = load i64, i64* %15
%106 = load i64, i64* %14
%107 = sub nsw i64 %105, %106
store i64 %107, i64* %13
%108 = load i64, i64* %18
%109 = load i64, i64* %17
%110 = sub nsw i64 %108, %109
store i64 %110, i64* %16
%111 = getelementptr inbounds %struct.timespec, %struct.timespec* %19, i32 0, i32 0
%112 = load i64, i64* %111
%113 = mul nsw i64 %112, 1000
%114 = getelementptr inbounds %struct.timespec, %struct.timespec* %19, i32 0, i32 1
%115 = load i64, i64* %114
%116 = sdiv i64 %115, 1000000
%117 = add nsw i64 %113, %116
store i64 %117, i64* %21
%118 = getelementptr inbounds %struct.timespec, %struct.timespec* %20, i32 0, i32 0
%119 = load i64, i64* %118
%120 = mul nsw i64 %119, 1000
%121 = getelementptr inbounds %struct.timespec, %struct.timespec* %20, i32 0, i32 1
%122 = load i64, i64* %121
%123 = sdiv i64 %122, 1000000
%124 = add nsw i64 %120, %123
store i64 %124, i64* %22
%125 = load i64, i64* %22
%126 = load i64, i64* %21
%127 = sub nsw i64 %125, %126
store i64 %127, i64* %23
%128 = load i64, i64* %23
%129 = sitofp i64 %128 to double
%130 = fmul double 1.000000e+00, %129
%131 = fdiv double %130, 1.000000e+03
%132 = fptosi double %131 to i64
%133 = call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0), i64 %132)
%134 = load i64, i64* %10
%135 = sitofp i64 %134 to double
%136 = load i64, i64* %13
%137 = sitofp i64 %136 to double
%138 = fmul double 1.000000e+00, %137
%139 = load i64, i64* %16
%140 = sitofp i64 %139 to double
%141 = fmul double 1.000000e+00, %140
%142 = fdiv double %138, %141
%143 = fdiv double %135, %142
%144 = load i64, i64* %23
%145 = sitofp i64 %144 to double
%146 = fdiv double %143, %145
%147 = fptosi double %146 to i64
%148 = call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0), i64 %147)
store i32 0, i32* %3
br label %149
149: ; preds = %95, %93, %71, %65, %53, %39, %27
%150 = load i32, i32* %3
ret i32 %150
}

LLVM IR (-O2):
%struct.timespec = type { i64, i64 }
@errno = global i64 0
@.str = [16 x i8] c"/dev/cpu/%d/msr\00"
@O_RDONLY = global i32 0
@.str.1 = [21 x i8] c"/dev/cpu/%d/msr: %s\0A\00"
@.str.2 = [27 x i8] c"Failed to set cpu affinity\00"
@CLOCK_MONOTONIC = global i32 0
@.str.3 = [14 x i8] c"clock_gettime\00"
@.str.4 = [16 x i8] c"runTime: %4.2f\0A\00"
@.str.5 = [13 x i8] c"freq: %7.0f\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [64 x i8]
%4 = alloca i64
%5 = alloca i64
%6 = alloca i64
%7 = alloca i64
%8 = alloca i64
%9 = alloca i64
%10 = alloca %struct.timespec
%11 = alloca %struct.timespec
%12 = alloca i32
%13 = getelementptr inbounds [64 x i8], [64 x i8]* %3, i64 0, i64 0
%14 = bitcast i64* %4 to i8*
%15 = bitcast i64* %5 to i8*
%16 = bitcast i64* %6 to i8*
%17 = bitcast i64* %7 to i8*
%18 = bitcast i64* %8 to i8*
%19 = bitcast i64* %9 to i8*
%20 = bitcast %struct.timespec* %10 to i8*
%21 = bitcast %struct.timespec* %11 to i8*
%22 = bitcast i32* %12 to i8*
%23 = icmp eq i32 %0, 2
br i1 %23, label %27, label %24
24: ; preds = %2
%25 = load i8*, i8** %1
%26 = tail call i32 @usage(i8* %25)
br label %137
27: ; preds = %2
store i64 0, i64* @errno
%28 = getelementptr inbounds i8*, i8** %1, i64 1
%29 = load i8*, i8** %28
%30 = tail call i32 @strtol(i8* nocapture %29, i8** null, i32 10)
%31 = load i64, i64* @errno
%32 = icmp eq i64 %31, 0
br i1 %32, label %36, label %33
33: ; preds = %27
%34 = load i8*, i8** %1
%35 = tail call i32 @usage(i8* %34)
br label %137
36: ; preds = %27
%37 = call i32 @sprintf(i8* %13, i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 %30)
%38 = load i32, i32* @O_RDONLY
%39 = call i32 @open(i8* %13, i32 %38)
%40 = icmp eq i32 %39, -1
br i1 %40, label %41, label %46
41: ; preds = %36
%42 = zext i32 %30 to i64
%43 = load i64, i64* @errno
%44 = tail call i8* @strerror(i64 %43)
%45 = tail call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i64 %42, i8* %44)
br label %137
46: ; preds = %36
%47 = call i32 @CPU_ZERO(i32* %12)
%48 = call i32 @CPU_SET(i32 %30, i32* %12)
%49 = call i64 @sched_setaffinity(i32 0, i32 4, i32* %12)
%50 = icmp eq i64 %49, 0
br i1 %50, label %53, label %51
51: ; preds = %46
%52 = call i32 @perror(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
br label %137
53: ; preds = %46
%54 = load i32, i32* @CLOCK_MONOTONIC
%55 = call i64 @clock_gettime(i32 %54, %struct.timespec* %10)
%56 = icmp slt i64 %55, 0
br i1 %56, label %57, label %59
57: ; preds = %53
%58 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0))
br label %137
59: ; preds = %53
%60 = call i32 @pread(i32 %39, i64* %4, i32 8, i32 16)
%61 = call i32 @pread(i32 %39, i64* %6, i32 8, i32 231)
%62 = call i32 @pread(i32 %39, i64* %8, i32 8, i32 232)
br label %63
63: ; preds = %63, %59
%64 = phi i32 [ 0, %59 ], [ %90, %63 ]
%65 = call i32 @sqrt(i32 %64)
%66 = add nuw i32 %64, 1
%67 = call i32 @sqrt(i32 %66)
%68 = add nuw i32 %64, 2
%69 = call i32 @sqrt(i32 %68)
%70 = add nuw i32 %64, 3
%71 = call i32 @sqrt(i32 %70)
%72 = add nuw i32 %64, 4
%73 = call i32 @sqrt(i32 %72)
%74 = add nuw i32 %64, 5
%75 = call i32 @sqrt(i32 %74)
%76 = add nuw i32 %64, 6
%77 = call i32 @sqrt(i32 %76)
%78 = add nuw i32 %64, 7
%79 = call i32 @sqrt(i32 %78)
%80 = add nuw i32 %64, 8
%81 = call i32 @sqrt(i32 %80)
%82 = add nuw i32 %64, 9
%83 = call i32 @sqrt(i32 %82)
%84 = add nuw i32 %64, 10
%85 = call i32 @sqrt(i32 %84)
%86 = add nuw i32 %64, 11
%87 = call i32 @sqrt(i32 %86)
%88 = add nuw i32 %64, 12
%89 = call i32 @sqrt(i32 %88)
%90 = add nuw i32 %64, 13
%91 = icmp eq i32 %90, -1879048193
br i1 %91, label %92, label %63
92: ; preds = %63
%93 = load i32, i32* @CLOCK_MONOTONIC
%94 = call i64 @clock_gettime(i32 %93, %struct.timespec* %11)
%95 = icmp slt i64 %94, 0
br i1 %95, label %96, label %98
96: ; preds = %92
%97 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0))
br label %137
98: ; preds = %92
%99 = call i32 @pread(i32 %39, i64* %5, i32 8, i32 16)
%100 = call i32 @pread(i32 %39, i64* %7, i32 8, i32 231)
%101 = call i32 @pread(i32 %39, i64* %9, i32 8, i32 232)
%102 = load i64, i64* %5
%103 = load i64, i64* %4
%104 = sub nsw i64 %102, %103
%105 = load i64, i64* %7
%106 = load i64, i64* %6
%107 = sub nsw i64 %105, %106
%108 = load i64, i64* %9
%109 = load i64, i64* %8
%110 = sub nsw i64 %108, %109
%111 = getelementptr inbounds %struct.timespec, %struct.timespec* %10, i64 0, i32 0
%112 = load i64, i64* %111
%113 = getelementptr inbounds %struct.timespec, %struct.timespec* %10, i64 0, i32 1
%114 = load i64, i64* %113
%115 = sdiv i64 %114, -1000000
%116 = getelementptr inbounds %struct.timespec, %struct.timespec* %11, i64 0, i32 0
%117 = load i64, i64* %116
%118 = getelementptr inbounds %struct.timespec, %struct.timespec* %11, i64 0, i32 1
%119 = load i64, i64* %118
%120 = sdiv i64 %119, 1000000
%121 = sub i64 %117, %112
%122 = mul i64 %121, 1000
%123 = add nsw i64 %120, %115
%124 = add i64 %123, %122
%125 = sitofp i64 %124 to double
%126 = fdiv double %125, 1.000000e+03
%127 = fptosi double %126 to i64
%128 = call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0), i64 %127)
%129 = sitofp i64 %104 to double
%130 = sitofp i64 %107 to double
%131 = sitofp i64 %110 to double
%132 = fdiv double %130, %131
%133 = fdiv double %129, %132
%134 = fdiv double %133, %125
%135 = fptosi double %134 to i64
%136 = call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0), i64 %135)
br label %137
137: ; preds = %98, %96, %57, %51, %41, %33, %24
%138 = phi i32 [ 1, %24 ], [ 1, %33 ], [ 4, %41 ], [ 1, %51 ], [ 1, %57 ], [ 1, %96 ], [ 0, %98 ]
ret i32 %138
}