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

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ fgets(unsigned char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
scalar_t__ isspace(unsigned char);
int sscanf(unsigned char *, char *, double *, int *);
size_t strlen(unsigned char *);
scalar_t__ strncasecmp(unsigned char *, char *, int);
int cpu_get_bogomips(void) {
  FILE *f = 0;
  unsigned char buf[1024], *s;
  size_t buflen;
  int value = 0, n;
  double dv;
  if (!(f = fopen("/proc/cpuinfo", "r")))
    goto failure;
  while (fgets(buf, sizeof(buf), f)) {
    buflen = strlen(buf);
    if (buflen > sizeof(buf) - 3)
      goto failure;
    while (buflen > 0 && isspace(buf[buflen - 1]))
      buf[--buflen] = 0;
    if (strncasecmp(buf, "bogomips", 8))
      continue;
    s = buf + 8;
    while (*s && isspace(*s))
      s++;
    if (*s != ':')
      goto failure;
    s++;
    if (sscanf(s, "%lf%n", &dv, &n) != 1 || s[n])
      goto failure;
    if (dv <= 0 || dv > 1e10)
      goto failure;
    value = (int)(dv + 0.5);
    break;
  }
  fclose(f);
  return value;
failure:
  if (f)
    fclose(f);
  return -1;
}


x86 assembly (clang, -O0):
<cpu_get_bogomips>:
push   %rbp
mov    %rsp,%rbp
sub    $0x440,%rsp
movq   $0x0,-0x10(%rbp)
movl   $0x0,-0x424(%rbp)
lea    0xe7c(%rip),%rdi
lea    0xe83(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    11b3 <cpu_get_bogomips+0x43>
jmp    13e4 <cpu_get_bogomips+0x274>
jmp    11b8 <cpu_get_bogomips+0x48>
lea    -0x410(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x400,%esi
call   1060 <fgets@plt>
cmp    $0x0,%rax
je     13cd <cpu_get_bogomips+0x25d>
lea    -0x410(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x420(%rbp)
cmpq   $0x3fd,-0x420(%rbp)
jbe    1200 <cpu_get_bogomips+0x90>
jmp    13e4 <cpu_get_bogomips+0x274>
jmp    1205 <cpu_get_bogomips+0x95>
xor    %eax,%eax
cmpq   $0x0,-0x420(%rbp)
mov    %al,-0x431(%rbp)
jbe    1240 <cpu_get_bogomips+0xd0>
mov    -0x420(%rbp),%rax
sub    $0x1,%rax
movzbl -0x410(%rbp,%rax,1),%edi
ff
call   1050 <isspace@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x431(%rbp)
mov    -0x431(%rbp),%al
test   $0x1,%al
jne    1253 <cpu_get_bogomips+0xe3>
jmp    1275 <cpu_get_bogomips+0x105>
mov    -0x420(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x420(%rbp)
movb   $0x0,-0x411(%rbp,%rax,1)
jmp    1205 <cpu_get_bogomips+0x95>
lea    -0x410(%rbp),%rdi
lea    0xd9d(%rip),%rsi
mov    $0x8,%edx
call   1070 <strncasecmp@plt>
cmp    $0x0,%rax
je     129c <cpu_get_bogomips+0x12c>
jmp    11b8 <cpu_get_bogomips+0x48>
lea    -0x410(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x418(%rbp)
mov    -0x418(%rbp),%rax
movzbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x432(%rbp)
je     12e5 <cpu_get_bogomips+0x175>
mov    -0x418(%rbp),%rax
movzbl (%rax),%edi
call   1050 <isspace@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x432(%rbp)
mov    -0x432(%rbp),%al
test   $0x1,%al
jne    12f8 <cpu_get_bogomips+0x188>
jmp    130f <cpu_get_bogomips+0x19f>
mov    -0x418(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x418(%rbp)
jmp    12ae <cpu_get_bogomips+0x13e>
mov    -0x418(%rbp),%rax
movzbl (%rax),%eax
cmp    $0x3a,%eax
je     1327 <cpu_get_bogomips+0x1b7>
jmp    13e4 <cpu_get_bogomips+0x274>
mov    -0x418(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x418(%rbp)
mov    -0x418(%rbp),%rdi
lea    0xce2(%rip),%rsi
lea    -0x430(%rbp),%rdx
lea    -0x428(%rbp),%rcx
call   1080 <sscanf@plt>
cmp    $0x1,%eax
jne    137e <cpu_get_bogomips+0x20e>
mov    -0x418(%rbp),%rax
movslq -0x428(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
je     1383 <cpu_get_bogomips+0x213>
jmp    13e4 <cpu_get_bogomips+0x274>
xorps  %xmm0,%xmm0
ucomisd -0x430(%rbp),%xmm0
ff
jae    13ae <cpu_get_bogomips+0x23e>
movsd  -0x430(%rbp),%xmm0
ff
movsd  0xc5c(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    13b3 <cpu_get_bogomips+0x243>
jmp    13e4 <cpu_get_bogomips+0x274>
movsd  0xc4d(%rip),%xmm0
addsd  -0x430(%rbp),%xmm0
ff
cvttsd2si %xmm0,%eax
mov    %eax,-0x424(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x424(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    13ff <cpu_get_bogomips+0x28f>
cmpq   $0x0,-0x10(%rbp)
je     13f8 <cpu_get_bogomips+0x288>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x440,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cpu_get_bogomips>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x410,%rsp
lea    0xe8a(%rip),%rdi
lea    0xe91(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     122c <cpu_get_bogomips+0xbc>
mov    %rax,%r14
lea    0x10(%rsp),%r12
lea    0xe76(%rip),%r15
mov    $0xffffffff,%ebp
jmp    11d5 <cpu_get_bogomips+0x65>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r12,%rdi
mov    %r15,%rsi
mov    $0x8,%edx
call   1070 <strncasecmp@plt>
test   %rax,%rax
je     123d <cpu_get_bogomips+0xcd>
mov    %r12,%rdi
mov    $0x400,%esi
mov    %r14,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     1236 <cpu_get_bogomips+0xc6>
mov    %r12,%rdi
call   1040 <strlen@plt>
cmp    $0x3fd,%rax
ja     12bf <cpu_get_bogomips+0x14f>
mov    %rax,%rbx
test   %rax,%rax
je     11c0 <cpu_get_bogomips+0x50>
cs nopw 0x0(%rax,%rax,1)
movzbl 0xf(%rsp,%rbx,1),%edi
call   1050 <isspace@plt>
test   %rax,%rax
je     11c0 <cpu_get_bogomips+0x50>
movb   $0x0,0xf(%rsp,%rbx,1)
add    $0xffffffffffffffff,%rbx
jne    1210 <cpu_get_bogomips+0xa0>
jmp    11c0 <cpu_get_bogomips+0x50>
mov    $0xffffffff,%ebp
jmp    12c7 <cpu_get_bogomips+0x157>
xor    %ebp,%ebp
jmp    12bf <cpu_get_bogomips+0x14f>
mov    0x18(%rsp),%al
test   %al,%al
je     12bf <cpu_get_bogomips+0x14f>
lea    0x19(%rsp),%rbx
xchg   %ax,%ax
movzbl %al,%edi
call   1050 <isspace@plt>
test   %rax,%rax
je     126a <cpu_get_bogomips+0xfa>
movzbl (%rbx),%eax
add    $0x1,%rbx
test   %al,%al
jne    1250 <cpu_get_bogomips+0xe0>
jmp    12bf <cpu_get_bogomips+0x14f>
cmpb   $0x3a,-0x1(%rbx)
jne    12bf <cpu_get_bogomips+0x14f>
lea    0xdb2(%rip),%rsi
lea    0x8(%rsp),%rdx
lea    0x4(%rsp),%rcx
mov    %rbx,%rdi
call   1080 <sscanf@plt>
cmp    $0x1,%eax
jne    12bf <cpu_get_bogomips+0x14f>
movslq 0x4(%rsp),%rax
cmpb   $0x0,(%rbx,%rax,1)
jne    12bf <cpu_get_bogomips+0x14f>
movsd  0x8(%rsp),%xmm0
xorpd  %xmm1,%xmm1
ucomisd %xmm0,%xmm1
jae    12bf <cpu_get_bogomips+0x14f>
ucomisd 0xd4f(%rip),%xmm0
ja     12bf <cpu_get_bogomips+0x14f>
addsd  0xd4d(%rip),%xmm0
cvttsd2si %xmm0,%ebp
mov    %r14,%rdi
call   1030 <fclose@plt>
mov    %ebp,%eax
add    $0x410,%rsp
pop    %rbx
pop    %r12
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 = [9 x i8] c"bogomips\00"
@.str.3 = [6 x i8] c"%lf%n\00"
define i32 @cpu_get_bogomips() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca [1024 x i8]
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i32
%7 = alloca i32
%8 = alloca double
store i32* null, i32** %2
store i32 0, i32* %6
%9 = 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* %9, i32** %2
%10 = icmp ne i32* %9, null
br i1 %10, label %12, label %11
11: ; preds = %0
br label %100
12: ; preds = %0
br label %13
13: ; preds = %45, %12
%14 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%15 = load i32*, i32** %2
%16 = call i64 @fgets(i8* %14, i32 1024, i32* %15)
%17 = icmp ne i64 %16, 0
br i1 %17, label %18, label %96
18: ; preds = %13
%19 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%20 = call i64 @strlen(i8* %19)
store i64 %20, i64* %5
%21 = load i64, i64* %5
%22 = icmp ugt i64 %21, 1021
br i1 %22, label %23, label %24
23: ; preds = %18
br label %100
24: ; preds = %18
br label %25
25: ; preds = %37, %24
%26 = load i64, i64* %5
%27 = icmp ugt i64 %26, 0
br i1 %27, label %28, label %35
28: ; preds = %25
%29 = load i64, i64* %5
%30 = sub i64 %29, 1
%31 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 %30
%32 = load i8, i8* %31
%33 = call i64 @isspace(i8 zeroext %32)
%34 = icmp ne i64 %33, 0
br label %35
35: ; preds = %28, %25
%36 = phi i1 [ false, %25 ], [ %34, %28 ]
br i1 %36, label %37, label %41
37: ; preds = %35
%38 = load i64, i64* %5
%39 = add i64 %38, -1
store i64 %39, i64* %5
%40 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 %39
store i8 0, i8* %40
br label %25
41: ; preds = %35
%42 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%43 = call i64 @strncasecmp(i8* %42, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 8)
%44 = icmp ne i64 %43, 0
br i1 %44, label %45, label %46
45: ; preds = %41
br label %13
46: ; preds = %41
%47 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%48 = getelementptr inbounds i8, i8* %47, i64 8
store i8* %48, i8** %4
br label %49
49: ; preds = %61, %46
%50 = load i8*, i8** %4
%51 = load i8, i8* %50
%52 = zext i8 %51 to i32
%53 = icmp ne i32 %52, 0
br i1 %53, label %54, label %59
54: ; preds = %49
%55 = load i8*, i8** %4
%56 = load i8, i8* %55
%57 = call i64 @isspace(i8 zeroext %56)
%58 = icmp ne i64 %57, 0
br label %59
59: ; preds = %54, %49
%60 = phi i1 [ false, %49 ], [ %58, %54 ]
br i1 %60, label %61, label %64
61: ; preds = %59
%62 = load i8*, i8** %4
%63 = getelementptr inbounds i8, i8* %62, i32 1
store i8* %63, i8** %4
br label %49
64: ; preds = %59
%65 = load i8*, i8** %4
%66 = load i8, i8* %65
%67 = zext i8 %66 to i32
%68 = icmp ne i32 %67, 58
br i1 %68, label %69, label %70
69: ; preds = %64
br label %100
70: ; preds = %64
%71 = load i8*, i8** %4
%72 = getelementptr inbounds i8, i8* %71, i32 1
store i8* %72, i8** %4
%73 = load i8*, i8** %4
%74 = call i32 @sscanf(i8* %73, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), double* %8, i32* %7)
%75 = icmp ne i32 %74, 1
br i1 %75, label %84, label %76
76: ; preds = %70
%77 = load i8*, i8** %4
%78 = load i32, i32* %7
%79 = sext i32 %78 to i64
%80 = getelementptr inbounds i8, i8* %77, i64 %79
%81 = load i8, i8* %80
%82 = zext i8 %81 to i32
%83 = icmp ne i32 %82, 0
br i1 %83, label %84, label %85
84: ; preds = %76, %70
br label %100
85: ; preds = %76
%86 = load double, double* %8
%87 = fcmp ole double %86, 0.000000e+00
br i1 %87, label %91, label %88
88: ; preds = %85
%89 = load double, double* %8
%90 = fcmp ogt double %89, 1.000000e+10
br i1 %90, label %91, label %92
91: ; preds = %88, %85
br label %100
92: ; preds = %88
%93 = load double, double* %8
%94 = fadd double %93, 5.000000e-01
%95 = fptosi double %94 to i32
store i32 %95, i32* %6
br label %96
96: ; preds = %92, %13
%97 = load i32*, i32** %2
%98 = call i32 @fclose(i32* %97)
%99 = load i32, i32* %6
store i32 %99, i32* %1
br label %107
100: ; preds = %91, %84, %69, %23, %11
%101 = load i32*, i32** %2
%102 = icmp ne i32* %101, null
br i1 %102, label %103, label %106
103: ; preds = %100
%104 = load i32*, i32** %2
%105 = call i32 @fclose(i32* %104)
br label %106
106: ; preds = %103, %100
store i32 -1, i32* %1
br label %107
107: ; preds = %106, %96
%108 = load i32, i32* %1
ret i32 %108
}

LLVM IR (-O2):
@.str = [14 x i8] c"/proc/cpuinfo\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [9 x i8] c"bogomips\00"
@.str.3 = [6 x i8] c"%lf%n\00"
define i32 @cpu_get_bogomips() {
%1 = alloca [1024 x i8]
%2 = alloca i32
%3 = alloca double
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 0
%5 = bitcast i32* %2 to i8*
%6 = bitcast double* %3 to i8*
%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 %66, label %9
9: ; preds = %0, %26
%10 = call i64 @fgets(i8* %4, i32 1024, i32* %7)
%11 = icmp eq i64 %10, 0
br i1 %11, label %63, label %12
12: ; preds = %9
%13 = call i64 @strlen(i8* %4)
%14 = icmp ugt i64 %13, 1021
br i1 %14, label %63, label %15
15: ; preds = %12
%16 = icmp eq i64 %13, 0
br i1 %16, label %26, label %17
17: ; preds = %15, %24
%18 = phi i64 [ %19, %24 ], [ %13, %15 ]
%19 = add i64 %18, -1
%20 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 %19
%21 = load i8, i8* %20
%22 = call i64 @isspace(i8 zeroext %21)
%23 = icmp eq i64 %22, 0
br i1 %23, label %26, label %24
24: ; preds = %17
store i8 0, i8* %20
%25 = icmp eq i64 %19, 0
br i1 %25, label %26, label %17
26: ; preds = %17, %24, %15
%27 = call i64 @strncasecmp(i8* %4, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 8)
%28 = icmp eq i64 %27, 0
br i1 %28, label %29, label %9
29: ; preds = %26
%30 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 8
%31 = load i8, i8* %30
%32 = icmp eq i8 %31, 0
br i1 %32, label %63, label %33
33: ; preds = %29, %38
%34 = phi i8 [ %40, %38 ], [ %31, %29 ]
%35 = phi i8* [ %39, %38 ], [ %30, %29 ]
%36 = call i64 @isspace(i8 zeroext %34)
%37 = icmp eq i64 %36, 0
br i1 %37, label %42, label %38
38: ; preds = %33
%39 = getelementptr inbounds i8, i8* %35, i64 1
%40 = load i8, i8* %39
%41 = icmp eq i8 %40, 0
br i1 %41, label %63, label %33
42: ; preds = %33
%43 = load i8, i8* %35
%44 = icmp eq i8 %43, 58
br i1 %44, label %45, label %63
45: ; preds = %42
%46 = getelementptr inbounds i8, i8* %35, i64 1
%47 = call i32 @sscanf(i8* %46, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), double* %3, i32* %2)
%48 = icmp eq i32 %47, 1
br i1 %48, label %49, label %63
49: ; preds = %45
%50 = load i32, i32* %2
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds i8, i8* %46, i64 %51
%53 = load i8, i8* %52
%54 = icmp eq i8 %53, 0
br i1 %54, label %55, label %63
55: ; preds = %49
%56 = load double, double* %3
%57 = fcmp ole double %56, 0.000000e+00
%58 = fcmp ogt double %56, 1.000000e+10
%59 = or i1 %57, %58
br i1 %59, label %63, label %60
60: ; preds = %55
%61 = fadd double %56, 5.000000e-01
%62 = fptosi double %61 to i32
br label %63
63: ; preds = %12, %9, %38, %29, %55, %45, %49, %42, %60
%64 = phi i32 [ %62, %60 ], [ -1, %42 ], [ -1, %49 ], [ -1, %45 ], [ -1, %55 ], [ -1, %29 ], [ -1, %38 ], [ 0, %9 ], [ -1, %12 ]
%65 = call i32 @fclose(i32* %7)
br label %66
66: ; preds = %63, %0
%67 = phi i32 [ -1, %0 ], [ %64, %63 ]
ret i32 %67
}