#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 /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ free(char *);
scalar_t__ getline(char **, size_t *, int /*<<< orphan*/ *);
int sscanf(char *, char *, double *, char *);
scalar_t__ strcasecmp(char *, char *);
char *strchr(char *, char);
int strcspn(char *, char *);
scalar_t__ strncmp(char *, char *, int);
int arch__cpuinfo_freq(double *freq, char *unit) {
  FILE *f;
  char *line = NULL, *c;
  size_t len = 0;
  int ret = -1;
  if ((f = fopen("/proc/cpuinfo", "r")) == NULL) {
    return -1;
  }
  while (getline(&line, &len, f) > 0) {
    if (strncmp(line, "clock", sizeof("clock") - 1)) {
      continue;
    }
    if (sscanf(line + strcspn(line, ":") + 1, "%lf%10s", freq, unit) == 2) {
      if (strcasecmp(unit, "GHz") == 0) {
        *freq *= 1000000000;
      } else if (strcasecmp(unit, "MHz") == 0) {
        *freq *= 1000000;
      }
      break;
    }
  }
  while (getline(&line, &len, f) > 0) {
    if (strncmp(line, "platform", sizeof("sizeof") - 1)) {
      continue;
    }
    c = strchr(line, ':');
    if (c - line + 2 < len &&
        !strncmp(c + 2, "pSeries", sizeof("pSeries") - 1)) {
      ret = 0;
      break;
    }
  }
  free(line);
  fclose(f);
  return ret;
}


x86 assembly (clang, -O0):
<arch__cpuinfo_freq>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movq   $0x0,-0x28(%rbp)
movq   $0x0,-0x38(%rbp)
movl   $0xffffffff,-0x3c(%rbp)
lea    0xe52(%rip),%rdi
lea    0xe59(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    11e4 <arch__cpuinfo_freq+0x54>
movl   $0xffffffff,-0x4(%rbp)
jmp    1395 <arch__cpuinfo_freq+0x205>
jmp    11e9 <arch__cpuinfo_freq+0x59>
mov    -0x20(%rbp),%rdx
lea    -0x28(%rbp),%rdi
lea    -0x38(%rbp),%rsi
call   10b0 <getline@plt>
cmp    $0x0,%rax
jle    12da <arch__cpuinfo_freq+0x14a>
mov    -0x28(%rbp),%rdi
lea    0xe11(%rip),%rsi
mov    $0x5,%edx
call   1050 <strncmp@plt>
cmp    $0x0,%rax
je     1228 <arch__cpuinfo_freq+0x98>
jmp    11e9 <arch__cpuinfo_freq+0x59>
mov    -0x28(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x28(%rbp),%rdi
lea    0xdeb(%rip),%rsi
call   1080 <strcspn@plt>
mov    -0x48(%rbp),%rdi
cltq
add    %rax,%rdi
add    $0x1,%rdi
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
lea    0xdcc(%rip),%rsi
call   1090 <sscanf@plt>
cmp    $0x2,%eax
jne    12d5 <arch__cpuinfo_freq+0x145>
mov    -0x18(%rbp),%rdi
lea    0xdbb(%rip),%rsi
call   1040 <strcasecmp@plt>
cmp    $0x0,%rax
jne    129d <arch__cpuinfo_freq+0x10d>
mov    -0x10(%rbp),%rax
movsd  0xd78(%rip),%xmm0
mulsd  (%rax),%xmm0
movsd  %xmm0,(%rax)
jmp    12d0 <arch__cpuinfo_freq+0x140>
mov    -0x18(%rbp),%rdi
lea    0xd8c(%rip),%rsi
call   1040 <strcasecmp@plt>
cmp    $0x0,%rax
jne    12cb <arch__cpuinfo_freq+0x13b>
mov    -0x10(%rbp),%rax
movsd  0xd3d(%rip),%xmm0
mulsd  (%rax),%xmm0
movsd  %xmm0,(%rax)
jmp    12d0 <arch__cpuinfo_freq+0x140>
jmp    12da <arch__cpuinfo_freq+0x14a>
jmp    11e9 <arch__cpuinfo_freq+0x59>
jmp    12df <arch__cpuinfo_freq+0x14f>
mov    -0x20(%rbp),%rdx
lea    -0x28(%rbp),%rdi
lea    -0x38(%rbp),%rsi
call   10b0 <getline@plt>
cmp    $0x0,%rax
jle    137d <arch__cpuinfo_freq+0x1ed>
mov    -0x28(%rbp),%rdi
lea    0xd33(%rip),%rsi
mov    $0x6,%edx
call   1050 <strncmp@plt>
cmp    $0x0,%rax
je     131e <arch__cpuinfo_freq+0x18e>
jmp    12df <arch__cpuinfo_freq+0x14f>
mov    -0x28(%rbp),%rdi
mov    $0x3a,%esi
call   1070 <strchr@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
mov    -0x28(%rbp),%rcx
sub    %rcx,%rax
add    $0x2,%rax
cmp    -0x38(%rbp),%rax
jae    1378 <arch__cpuinfo_freq+0x1e8>
mov    -0x30(%rbp),%rdi
add    $0x2,%rdi
lea    0xce9(%rip),%rsi
mov    $0x7,%edx
call   1050 <strncmp@plt>
cmp    $0x0,%rax
jne    1378 <arch__cpuinfo_freq+0x1e8>
movl   $0x0,-0x3c(%rbp)
jmp    137d <arch__cpuinfo_freq+0x1ed>
jmp    12df <arch__cpuinfo_freq+0x14f>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rdi
call   1060 <fclose@plt>
mov    -0x3c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<arch__cpuinfo_freq>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%r15
mov    %rdi,0x10(%rsp)
movq   $0x0,(%rsp)
movq   $0x0,0x8(%rsp)
lea    0xe52(%rip),%rdi
lea    0xe59(%rip),%rsi
call   10a0 <fopen@plt>
test   %rax,%rax
je     1295 <arch__cpuinfo_freq+0x105>
mov    %rax,%rbx
mov    %rsp,%rdi
lea    0x8(%rsp),%rsi
mov    %rax,%rdx
call   10b0 <getline@plt>
test   %rax,%rax
jle    12b5 <arch__cpuinfo_freq+0x125>
lea    0xe2a(%rip),%rbp
mov    %rsp,%r12
lea    0x8(%rsp),%r13
jmp    1217 <arch__cpuinfo_freq+0x87>
mov    %r12,%rdi
mov    %r13,%rsi
mov    %rbx,%rdx
call   10b0 <getline@plt>
test   %rax,%rax
jle    12b5 <arch__cpuinfo_freq+0x125>
mov    (%rsp),%rdi
mov    %rbp,%rsi
mov    $0x5,%edx
call   1050 <strncmp@plt>
test   %rax,%rax
jne    1200 <arch__cpuinfo_freq+0x70>
mov    (%rsp),%r14
mov    %r14,%rdi
lea    0xdeb(%rip),%rsi
call   1080 <strcspn@plt>
cltq
lea    (%r14,%rax,1),%rdi
add    $0x1,%rdi
lea    0xdd7(%rip),%rsi
mov    0x10(%rsp),%rdx
mov    %r15,%rcx
call   1090 <sscanf@plt>
cmp    $0x2,%eax
jne    1200 <arch__cpuinfo_freq+0x70>
lea    0xdc6(%rip),%rsi
mov    %r15,%rdi
call   1040 <strcasecmp@plt>
test   %rax,%rax
je     12a0 <arch__cpuinfo_freq+0x110>
lea    0xdb6(%rip),%rsi
mov    %r15,%rdi
call   1040 <strcasecmp@plt>
test   %rax,%rax
jne    12b5 <arch__cpuinfo_freq+0x125>
movsd  0xd75(%rip),%xmm0
jmp    12a8 <arch__cpuinfo_freq+0x118>
mov    $0xffffffff,%r14d
jmp    136c <arch__cpuinfo_freq+0x1dc>
movsd  0xd58(%rip),%xmm0
mov    0x10(%rsp),%rax
mulsd  (%rax),%xmm0
movsd  %xmm0,(%rax)
mov    %rsp,%rdi
lea    0x8(%rsp),%rsi
mov    %rbx,%rdx
call   10b0 <getline@plt>
mov    $0xffffffff,%r14d
test   %rax,%rax
jle    135b <arch__cpuinfo_freq+0x1cb>
lea    0xd5d(%rip),%r12
mov    %rsp,%r13
lea    0x8(%rsp),%rbp
jmp    1303 <arch__cpuinfo_freq+0x173>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r13,%rdi
mov    %rbp,%rsi
mov    %rbx,%rdx
call   10b0 <getline@plt>
test   %rax,%rax
jle    135b <arch__cpuinfo_freq+0x1cb>
mov    (%rsp),%rdi
mov    %r12,%rsi
mov    $0x6,%edx
call   1050 <strncmp@plt>
test   %rax,%rax
jne    12f0 <arch__cpuinfo_freq+0x160>
mov    (%rsp),%r15
mov    %r15,%rdi
mov    $0x3a,%esi
call   1070 <strchr@plt>
mov    %rax,%rcx
sub    %r15,%rcx
add    $0x2,%rcx
cmp    0x8(%rsp),%rcx
jae    12f0 <arch__cpuinfo_freq+0x160>
add    $0x2,%rax
mov    %rax,%rdi
lea    0xcf8(%rip),%rsi
mov    $0x7,%edx
call   1050 <strncmp@plt>
test   %rax,%rax
jne    12f0 <arch__cpuinfo_freq+0x160>
xor    %r14d,%r14d
mov    (%rsp),%rdi
call   1030 <free@plt>
mov    %rbx,%rdi
call   1060 <fclose@plt>
mov    %r14d,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [14 x i8] c"/proc/cpuinfo\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [6 x i8] c"clock\00"
@.str.3 = [2 x i8] c":\00"
@.str.4 = [8 x i8] c"%lf%10s\00"
@.str.5 = [4 x i8] c"GHz\00"
@.str.6 = [4 x i8] c"MHz\00"
@.str.7 = [9 x i8] c"platform\00"
@.str.8 = [8 x i8] c"pSeries\00"
define i32 @arch__cpuinfo_freq(double* %0, i8* %1) {
%3 = alloca i32
%4 = alloca double*
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i32
store double* %0, double** %4
store i8* %1, i8** %5
store i8* null, i8** %7
store i64 0, i64* %9
store i32 -1, i32* %10
%11 = 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* %11, i32** %6
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %14
13: ; preds = %2
store i32 -1, i32* %3
br label %88
14: ; preds = %2
br label %15
15: ; preds = %53, %23, %14
%16 = load i32*, i32** %6
%17 = call i64 @getline(i8** %7, i64* %9, i32* %16)
%18 = icmp sgt i64 %17, 0
br i1 %18, label %19, label %54
19: ; preds = %15
%20 = load i8*, i8** %7
%21 = call i64 @strncmp(i8* %20, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 5)
%22 = icmp ne i64 %21, 0
br i1 %22, label %23, label %24
23: ; preds = %19
br label %15
24: ; preds = %19
%25 = load i8*, i8** %7
%26 = load i8*, i8** %7
%27 = call i32 @strcspn(i8* %26, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i8, i8* %25, i64 %28
%30 = getelementptr inbounds i8, i8* %29, i64 1
%31 = load double*, double** %4
%32 = load i8*, i8** %5
%33 = call i32 @sscanf(i8* %30, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), double* %31, i8* %32)
%34 = icmp eq i32 %33, 2
br i1 %34, label %35, label %53
35: ; preds = %24
%36 = load i8*, i8** %5
%37 = call i64 @strcasecmp(i8* %36, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0))
%38 = icmp eq i64 %37, 0
br i1 %38, label %39, label %43
39: ; preds = %35
%40 = load double*, double** %4
%41 = load double, double* %40
%42 = fmul double %41, 1.000000e+09
store double %42, double* %40
br label %52
43: ; preds = %35
%44 = load i8*, i8** %5
%45 = call i64 @strcasecmp(i8* %44, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0))
%46 = icmp eq i64 %45, 0
br i1 %46, label %47, label %51
47: ; preds = %43
%48 = load double*, double** %4
%49 = load double, double* %48
%50 = fmul double %49, 1.000000e+06
store double %50, double* %48
br label %51
51: ; preds = %47, %43
br label %52
52: ; preds = %51, %39
br label %54
53: ; preds = %24
br label %15
54: ; preds = %52, %15
br label %55
55: ; preds = %81, %63, %54
%56 = load i32*, i32** %6
%57 = call i64 @getline(i8** %7, i64* %9, i32* %56)
%58 = icmp sgt i64 %57, 0
br i1 %58, label %59, label %82
59: ; preds = %55
%60 = load i8*, i8** %7
%61 = call i64 @strncmp(i8* %60, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.7, i64 0, i64 0), i32 6)
%62 = icmp ne i64 %61, 0
br i1 %62, label %63, label %64
63: ; preds = %59
br label %55
64: ; preds = %59
%65 = load i8*, i8** %7
%66 = call i8* @strchr(i8* %65, i8 signext 58)
store i8* %66, i8** %8
%67 = load i8*, i8** %8
%68 = load i8*, i8** %7
%69 = ptrtoint i8* %67 to i64
%70 = ptrtoint i8* %68 to i64
%71 = sub i64 %69, %70
%72 = add nsw i64 %71, 2
%73 = load i64, i64* %9
%74 = icmp ult i64 %72, %73
br i1 %74, label %75, label %81
75: ; preds = %64
%76 = load i8*, i8** %8
%77 = getelementptr inbounds i8, i8* %76, i64 2
%78 = call i64 @strncmp(i8* %77, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.8, i64 0, i64 0), i32 7)
%79 = icmp ne i64 %78, 0
br i1 %79, label %81, label %80
80: ; preds = %75
store i32 0, i32* %10
br label %82
81: ; preds = %75, %64
br label %55
82: ; preds = %80, %55
%83 = load i8*, i8** %7
%84 = call i32 @free(i8* %83)
%85 = load i32*, i32** %6
%86 = call i32 @fclose(i32* %85)
%87 = load i32, i32* %10
store i32 %87, i32* %3
br label %88
88: ; preds = %82, %13
%89 = load i32, i32* %3
ret i32 %89
}

LLVM IR (-O2):
@.str = [14 x i8] c"/proc/cpuinfo\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [6 x i8] c"clock\00"
@.str.3 = [2 x i8] c":\00"
@.str.4 = [8 x i8] c"%lf%10s\00"
@.str.5 = [4 x i8] c"GHz\00"
@.str.6 = [4 x i8] c"MHz\00"
@.str.7 = [9 x i8] c"platform\00"
@.str.8 = [8 x i8] c"pSeries\00"
define i32 @arch__cpuinfo_freq(double* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = bitcast i8** %3 to i8*
store i8* null, i8** %3
%6 = bitcast i64* %4 to i8*
store i64 0, i64* %4
%7 = 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))
%8 = icmp eq i32* %7, null
br i1 %8, label %65, label %9
9: ; preds = %2
%10 = call i64 @getline(i8** %3, i64* %4, i32* %7)
%11 = icmp sgt i64 %10, 0
br i1 %11, label %12, label %37
12: ; preds = %9, %16
%13 = load i8*, i8** %3
%14 = call i64 @strncmp(i8* %13, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 5)
%15 = icmp eq i64 %14, 0
br i1 %15, label %19, label %16
16: ; preds = %12, %19
%17 = call i64 @getline(i8** %3, i64* %4, i32* %7)
%18 = icmp sgt i64 %17, 0
br i1 %18, label %12, label %37
19: ; preds = %12
%20 = load i8*, i8** %3
%21 = call i32 @strcspn(i8* %20, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i8, i8* %20, i64 1
%24 = getelementptr inbounds i8, i8* %23, i64 %22
%25 = call i32 @sscanf(i8* %24, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), double* %0, i8* %1)
%26 = icmp eq i32 %25, 2
br i1 %26, label %27, label %16
27: ; preds = %19
%28 = call i64 @strcasecmp(i8* %1, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0))
%29 = icmp eq i64 %28, 0
br i1 %29, label %33, label %30
30: ; preds = %27
%31 = call i64 @strcasecmp(i8* %1, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0))
%32 = icmp eq i64 %31, 0
br i1 %32, label %33, label %37
33: ; preds = %30, %27
%34 = phi double [ 1.000000e+09, %27 ], [ 1.000000e+06, %30 ]
%35 = load double, double* %0
%36 = fmul double %35, %34
store double %36, double* %0
br label %37
37: ; preds = %16, %33, %9, %30
%38 = call i64 @getline(i8** %3, i64* %4, i32* %7)
%39 = icmp sgt i64 %38, 0
br i1 %39, label %40, label %60
40: ; preds = %37, %57
%41 = load i8*, i8** %3
%42 = call i64 @strncmp(i8* %41, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.7, i64 0, i64 0), i32 6)
%43 = icmp eq i64 %42, 0
br i1 %43, label %44, label %57
44: ; preds = %40
%45 = load i8*, i8** %3
%46 = call i8* @strchr(i8* dereferenceable(1) %45, i8 signext 58)
%47 = ptrtoint i8* %46 to i64
%48 = ptrtoint i8* %45 to i64
%49 = sub i64 2, %48
%50 = add i64 %49, %47
%51 = load i64, i64* %4
%52 = icmp ult i64 %50, %51
br i1 %52, label %53, label %57
53: ; preds = %44
%54 = getelementptr inbounds i8, i8* %46, i64 2
%55 = call i64 @strncmp(i8* %54, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.8, i64 0, i64 0), i32 7)
%56 = icmp eq i64 %55, 0
br i1 %56, label %60, label %57
57: ; preds = %44, %53, %40
%58 = call i64 @getline(i8** %3, i64* %4, i32* %7)
%59 = icmp sgt i64 %58, 0
br i1 %59, label %40, label %60
60: ; preds = %57, %53, %37
%61 = phi i32 [ -1, %37 ], [ 0, %53 ], [ -1, %57 ]
%62 = load i8*, i8** %3
%63 = call i32 @free(i8* %62)
%64 = call i32 @fclose(i32* %7)
br label %65
65: ; preds = %2, %60
%66 = phi i32 [ %61, %60 ], [ -1, %2 ]
ret i32 %66
}