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

/* Variables and functions */
int atof(char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ getline(char **, int *, int /*<<< orphan*/ *);
char *malloc(int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ strcmp(char *, char *);
unsigned long long cycles_per_ms(void) {
  FILE *fd = fopen("/proc/cpuinfo", "r");
  int size = 512;
  char *line;
  char *field, *value;
  if (fd == NULL) {
    perror("While opening cpuinfo");
    exit(-1);
  }
  line = malloc(size * sizeof(char));
  while (!feof(fd)) {
    memset(line, 0, size);
    getline(&line, &size, fd);
    field = line;
    field[7] = '\0';
    if (!strcmp(field, "cpu MHz")) {
      int i = 0;
      unsigned long long retval;
      while (field[i] != ':' && i < size)
        i++;
      if (i == 512) {
        printf("Could not parse proc entry\n");
        exit(-1);
      }
      i += 2;
      value = &field[i];
      while (field[i] != '\n' && field[i] != ' ')
        i++;
      field[i] = '\0';
      fclose(fd);
      retval = (unsigned long long)(atof(value) * 1000);
      free(line);
      return retval;
    }
  }
  printf("Unable to determine cpu MHz from /proc/cpuinfo");
  fclose(fd);
  free(line);
  exit(-1);
}


x86 assembly (clang, -O0):
<cycles_per_ms>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
lea    0xe8e(%rip),%rdi
lea    0xe2a(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x8(%rbp)
movl   $0x200,-0xc(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    1207 <cycles_per_ms+0x47>
lea    0xe0a(%rip),%rdi
call   10c0 <perror@plt>
mov    $0xffffffff,%edi
call   10e0 <exit@plt>
movslq -0xc(%rbp),%rax
shl    $0x0,%rax
mov    %eax,%edi
call   10a0 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1090 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1238 <cycles_per_ms+0x78>
jmp    1395 <cycles_per_ms+0x1d5>
mov    -0x18(%rbp),%rdi
mov    -0xc(%rbp),%edx
xor    %esi,%esi
call   1070 <memset@plt>
mov    -0x8(%rbp),%rdx
lea    -0x18(%rbp),%rdi
lea    -0xc(%rbp),%rsi
call   10d0 <getline@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
movb   $0x0,0x7(%rax)
mov    -0x20(%rbp),%rdi
lea    0xda6(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%eax
jne    1390 <cycles_per_ms+0x1d0>
movl   $0x0,-0x2c(%rbp)
mov    -0x20(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsbl (%rax,%rcx,1),%ecx
xor    %eax,%eax
cmp    $0x3a,%ecx
mov    %al,-0x39(%rbp)
je     12ad <cycles_per_ms+0xed>
mov    -0x2c(%rbp),%eax
cmp    -0xc(%rbp),%eax
setl   %al
mov    %al,-0x39(%rbp)
mov    -0x39(%rbp),%al
test   $0x1,%al
jne    12bd <cycles_per_ms+0xfd>
jmp    12cb <cycles_per_ms+0x10b>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1287 <cycles_per_ms+0xc7>
cmpl   $0x200,-0x2c(%rbp)
jne    12ee <cycles_per_ms+0x12e>
lea    0xd41(%rip),%rdi
call   1060 <printf@plt>
mov    $0xffffffff,%edi
call   10e0 <exit@plt>
mov    -0x2c(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x20(%rbp),%rax
movslq -0x2c(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsbl (%rax,%rcx,1),%ecx
xor    %eax,%eax
cmp    $0xa,%ecx
mov    %al,-0x3a(%rbp)
je     1335 <cycles_per_ms+0x175>
mov    -0x20(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x20,%eax
setne  %al
mov    %al,-0x3a(%rbp)
mov    -0x3a(%rbp),%al
test   $0x1,%al
jne    1345 <cycles_per_ms+0x185>
jmp    1353 <cycles_per_ms+0x193>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1306 <cycles_per_ms+0x146>
mov    -0x20(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x8(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x28(%rbp),%rdi
call   1040 <atof@plt>
imul   $0x3e8,%eax,%eax
cltq
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x38(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret
jmp    121a <cycles_per_ms+0x5a>
lea    0xca0(%rip),%rdi
call   1060 <printf@plt>
mov    -0x8(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    $0xffffffff,%edi
call   10e0 <exit@plt>

x86 assembly (clang, -O2):
<cycles_per_ms>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
lea    0xe5d(%rip),%rdi
lea    0xe15(%rip),%rsi
call   10c0 <fopen@plt>
movl   $0x200,0x4(%rsp)
test   %rax,%rax
je     1339 <cycles_per_ms+0x169>
mov    %rax,%r14
mov    $0x200,%edi
call   10b0 <malloc@plt>
mov    %rax,0x8(%rsp)
lea    0x8(%rsp),%r15
lea    0x4(%rsp),%r12
lea    0xdf4(%rip),%r13
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r14,%rdi
call   10a0 <feof@plt>
test   %eax,%eax
jne    1311 <cycles_per_ms+0x141>
mov    0x8(%rsp),%rdi
mov    0x4(%rsp),%edx
xor    %esi,%esi
call   1080 <memset@plt>
mov    %r15,%rdi
mov    %r12,%rsi
mov    %r14,%rdx
call   10e0 <getline@plt>
mov    0x8(%rsp),%rbx
movb   $0x0,0x7(%rbx)
mov    %rbx,%rdi
mov    %r13,%rsi
call   1090 <strcmp@plt>
test   %eax,%eax
jne    1230 <cycles_per_ms+0x60>
movslq 0x4(%rsp),%rcx
mov    $0xffffffffffffffff,%rax
xor    %edx,%edx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
add    $0xffffffffffffffff,%rax
cmpb   $0x3a,(%rbx,%rdx,1)
je     12a6 <cycles_per_ms+0xd6>
lea    0x1(%rdx),%rsi
cmp    %rcx,%rdx
mov    %rsi,%rdx
jl     1290 <cycles_per_ms+0xc0>
cmp    $0xfffffdfe,%eax
je     134f <cycles_per_ms+0x17f>
mov    %rax,%rcx
neg    %rcx
nopw   0x0(%rax,%rax,1)
movzbl (%rbx,%rcx,1),%edx
cmp    $0xa,%dl
je     12d4 <cycles_per_ms+0x104>
cmp    $0x20,%dl
je     12d4 <cycles_per_ms+0x104>
add    $0x1,%rcx
jmp    12c0 <cycles_per_ms+0xf0>
mov    %ecx,%ecx
movb   $0x0,(%rbx,%rcx,1)
sub    %rax,%rbx
mov    %r14,%rdi
call   1060 <fclose@plt>
mov    %rbx,%rdi
call   1050 <atof@plt>
imul   $0x3e8,%eax,%eax
movslq %eax,%rbx
mov    0x8(%rsp),%rdi
call   1030 <free@plt>
mov    %rbx,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret
lea    0xd08(%rip),%rdi
call   1070 <printf@plt>
mov    %r14,%rdi
call   1060 <fclose@plt>
mov    0x8(%rsp),%rdi
call   1030 <free@plt>
mov    $0xffffffff,%edi
call   10f0 <exit@plt>
lea    0xcc2(%rip),%rdi
call   10d0 <perror@plt>
mov    $0xffffffff,%edi
call   10f0 <exit@plt>
lea    0xcf9(%rip),%rdi
call   1040 <puts@plt>
mov    $0xffffffff,%edi
call   10f0 <exit@plt>

LLVM IR (-O0):
@.str = [14 x i8] c"/proc/cpuinfo\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [22 x i8] c"While opening cpuinfo\00"
@.str.3 = [8 x i8] c"cpu MHz\00"
@.str.4 = [28 x i8] c"Could not parse proc entry\0A\00"
@.str.5 = [47 x i8] c"Unable to determine cpu MHz from /proc/cpuinfo\00"
define i64 @cycles_per_ms() {
%1 = alloca i32*
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i64
%8 = call i32* @fopen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %8, i32** %1
store i32 512, i32* %2
%9 = load i32*, i32** %1
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %14
11: ; preds = %0
%12 = call i32 @perror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0))
%13 = call i32 @exit(i32 -1)
unreachable
14: ; preds = %0
%15 = load i32, i32* %2
%16 = sext i32 %15 to i64
%17 = mul i64 %16, 1
%18 = trunc i64 %17 to i32
%19 = call i8* @malloc(i32 %18)
store i8* %19, i8** %3
br label %20
20: ; preds = %103, %14
%21 = load i32*, i32** %1
%22 = call i32 @feof(i32* %21)
%23 = icmp ne i32 %22, 0
%24 = xor i1 %23, true
br i1 %24, label %25, label %104
25: ; preds = %20
%26 = load i8*, i8** %3
%27 = load i32, i32* %2
%28 = call i32 @memset(i8* %26, i32 0, i32 %27)
%29 = load i32*, i32** %1
%30 = call i32 @getline(i8** %3, i32* %2, i32* %29)
%31 = load i8*, i8** %3
store i8* %31, i8** %4
%32 = load i8*, i8** %4
%33 = getelementptr inbounds i8, i8* %32, i64 7
store i8 0, i8* %33
%34 = load i8*, i8** %4
%35 = call i32 @strcmp(i8* %34, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
%36 = icmp ne i32 %35, 0
br i1 %36, label %103, label %37
37: ; preds = %25
store i32 0, i32* %6
br label %38
38: ; preds = %52, %37
%39 = load i8*, i8** %4
%40 = load i32, i32* %6
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds i8, i8* %39, i64 %41
%43 = load i8, i8* %42
%44 = sext i8 %43 to i32
%45 = icmp ne i32 %44, 58
br i1 %45, label %46, label %50
46: ; preds = %38
%47 = load i32, i32* %6
%48 = load i32, i32* %2
%49 = icmp slt i32 %47, %48
br label %50
50: ; preds = %46, %38
%51 = phi i1 [ false, %38 ], [ %49, %46 ]
br i1 %51, label %52, label %55
52: ; preds = %50
%53 = load i32, i32* %6
%54 = add nsw i32 %53, 1
store i32 %54, i32* %6
br label %38
55: ; preds = %50
%56 = load i32, i32* %6
%57 = icmp eq i32 %56, 512
br i1 %57, label %58, label %61
58: ; preds = %55
%59 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0))
%60 = call i32 @exit(i32 -1)
unreachable
61: ; preds = %55
%62 = load i32, i32* %6
%63 = add nsw i32 %62, 2
store i32 %63, i32* %6
%64 = load i8*, i8** %4
%65 = load i32, i32* %6
%66 = sext i32 %65 to i64
%67 = getelementptr inbounds i8, i8* %64, i64 %66
store i8* %67, i8** %5
br label %68
68: ; preds = %86, %61
%69 = load i8*, i8** %4
%70 = load i32, i32* %6
%71 = sext i32 %70 to i64
%72 = getelementptr inbounds i8, i8* %69, i64 %71
%73 = load i8, i8* %72
%74 = sext i8 %73 to i32
%75 = icmp ne i32 %74, 10
br i1 %75, label %76, label %84
76: ; preds = %68
%77 = load i8*, i8** %4
%78 = load i32, i32* %6
%79 = sext i32 %78 to i64
%80 = getelementptr inbounds i8, i8* %77, i64 %79
%81 = load i8, i8* %80
%82 = sext i8 %81 to i32
%83 = icmp ne i32 %82, 32
br label %84
84: ; preds = %76, %68
%85 = phi i1 [ false, %68 ], [ %83, %76 ]
br i1 %85, label %86, label %89
86: ; preds = %84
%87 = load i32, i32* %6
%88 = add nsw i32 %87, 1
store i32 %88, i32* %6
br label %68
89: ; preds = %84
%90 = load i8*, i8** %4
%91 = load i32, i32* %6
%92 = sext i32 %91 to i64
%93 = getelementptr inbounds i8, i8* %90, i64 %92
store i8 0, i8* %93
%94 = load i32*, i32** %1
%95 = call i32 @fclose(i32* %94)
%96 = load i8*, i8** %5
%97 = call i32 @atof(i8* %96)
%98 = mul nsw i32 %97, 1000
%99 = sext i32 %98 to i64
store i64 %99, i64* %7
%100 = load i8*, i8** %3
%101 = call i32 @free(i8* %100)
%102 = load i64, i64* %7
ret i64 %102
103: ; preds = %25
br label %20
104: ; preds = %20
%105 = call i32 @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.5, i64 0, i64 0))
%106 = load i32*, i32** %1
%107 = call i32 @fclose(i32* %106)
%108 = load i8*, i8** %3
%109 = call i32 @free(i8* %108)
%110 = call i32 @exit(i32 -1)
unreachable
}

LLVM IR (-O2):
@.str = [14 x i8] c"/proc/cpuinfo\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [22 x i8] c"While opening cpuinfo\00"
@.str.3 = [8 x i8] c"cpu MHz\00"
@.str.5 = [47 x i8] c"Unable to determine cpu MHz from /proc/cpuinfo\00"
@str = [27 x i8] c"Could not parse proc entry\00"
define i64 @cycles_per_ms() {
%1 = alloca i32
%2 = alloca i8*
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%4 = bitcast i32* %1 to i8*
store i32 512, i32* %1
%5 = bitcast i8** %2 to i8*
%6 = icmp eq i32* %3, null
br i1 %6, label %7, label %10
7: ; preds = %0
%8 = tail call i32 @perror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0))
%9 = tail call i32 @exit(i32 -1)
unreachable
10: ; preds = %0
%11 = tail call dereferenceable_or_null(512) i8* @malloc(i32 512)
store i8* %11, i8** %2
br label %12
12: ; preds = %15, %10
%13 = call i32 @feof(i32* %3)
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %61
15: ; preds = %12
%16 = load i8*, i8** %2
%17 = load i32, i32* %1
%18 = call i32 @memset(i8* %16, i32 0, i32 %17)
%19 = call i32 @getline(i8** %2, i32* %1, i32* %3)
%20 = load i8*, i8** %2
%21 = getelementptr inbounds i8, i8* %20, i64 7
store i8 0, i8* %21
%22 = call i32 @strcmp(i8* dereferenceable(1) %20, i8* dereferenceable(8) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
%23 = icmp eq i32 %22, 0
br i1 %23, label %24, label %12
24: ; preds = %15
%25 = load i32, i32* %1
%26 = sext i32 %25 to i64
br label %27
27: ; preds = %27, %24
%28 = phi i64 [ %34, %27 ], [ 0, %24 ]
%29 = getelementptr inbounds i8, i8* %20, i64 %28
%30 = load i8, i8* %29
%31 = icmp ne i8 %30, 58
%32 = icmp slt i64 %28, %26
%33 = select i1 %31, i1 %32, i1 false
%34 = add nuw nsw i64 %28, 1
br i1 %33, label %27, label %35
35: ; preds = %27
%36 = trunc i64 %28 to i32
%37 = icmp eq i32 %36, 512
br i1 %37, label %38, label %41
38: ; preds = %35
%39 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str, i64 0, i64 0))
%40 = call i32 @exit(i32 -1)
unreachable
41: ; preds = %35
%42 = add nuw nsw i64 %28, 2
br label %43
43: ; preds = %47, %41
%44 = phi i64 [ %48, %47 ], [ %42, %41 ]
%45 = getelementptr inbounds i8, i8* %20, i64 %44
%46 = load i8, i8* %45
switch i8 %46, label %47 [
i8 10, label %49
i8 32, label %49
]
47: ; preds = %43
%48 = add nuw i64 %44, 1
br label %43
49: ; preds = %43, %43
%50 = add nuw i64 %28, 2
%51 = and i64 %44, 4294967295
%52 = getelementptr inbounds i8, i8* %20, i64 %51
%53 = and i64 %50, 4294967295
%54 = getelementptr inbounds i8, i8* %20, i64 %53
store i8 0, i8* %52
%55 = call i32 @fclose(i32* %3)
%56 = call i32 @atof(i8* %54)
%57 = mul nsw i32 %56, 1000
%58 = sext i32 %57 to i64
%59 = load i8*, i8** %2
%60 = call i32 @free(i8* %59)
ret i64 %58
61: ; preds = %12
%62 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([47 x i8], [47 x i8]* @.str.5, i64 0, i64 0))
%63 = call i32 @fclose(i32* %3)
%64 = load i8*, i8** %2
%65 = call i32 @free(i8* %64)
%66 = call i32 @exit(i32 -1)
unreachable
}