#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*/ exit(int);
int fscanf(int /*<<< orphan*/ *, char *, double *);
int /*<<< orphan*/ pclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *popen(char *, char *);
int /*<<< orphan*/ printf(char *);
double SetMHz() {
  double mhz;
  FILE *f;
  f = popen("/bin/sed -n '/cpu MHz/s/[^:]*://p' /proc/cpuinfo", "r");
  if (!f) {
    printf("RDTSC: Error reading cpu speed\n");
    exit(-1);
  }
  if (fscanf(f, "%lf", &mhz) != 1) {
    printf("RDTSC: Error reading cpu speed.\n");
    exit(-1);
  }
  pclose(f);
  return mhz;
}


x86 assembly (clang, -O0):
<SetMHz>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xea1(%rip),%rdi
lea    0xecb(%rip),%rsi
call   1060 <popen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1190 <SetMHz+0x40>
lea    0xeb2(%rip),%rdi
call   1030 <printf@plt>
mov    $0xffffffff,%edi
call   1070 <exit@plt>
mov    -0x10(%rbp),%rdi
lea    0xeb8(%rip),%rsi
lea    -0x8(%rbp),%rdx
call   1050 <fscanf@plt>
cmp    $0x1,%eax
je     11c3 <SetMHz+0x73>
lea    0xea3(%rip),%rdi
call   1030 <printf@plt>
mov    $0xffffffff,%edi
call   1070 <exit@plt>
mov    -0x10(%rbp),%rdi
call   1040 <pclose@plt>
movsd  -0x8(%rbp),%xmm0
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<SetMHz>:
push   %rbx
sub    $0x10,%rsp
lea    0xea4(%rip),%rdi
lea    0xece(%rip),%rsi
call   1060 <popen@plt>
test   %rax,%rax
je     119d <SetMHz+0x4d>
mov    %rax,%rbx
lea    0xebc(%rip),%rsi
lea    0x8(%rsp),%rdx
mov    %rax,%rdi
call   1050 <fscanf@plt>
cmp    $0x1,%eax
jne    11a6 <SetMHz+0x56>
mov    %rbx,%rdi
call   1040 <pclose@plt>
movsd  0x8(%rsp),%xmm0
add    $0x10,%rsp
pop    %rbx
ret
lea    0xe93(%rip),%rdi
jmp    11ad <SetMHz+0x5d>
lea    0xea9(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [49 x i8] c"/bin/sed -n '/cpu MHz/s/[^:]*://p' /proc/cpuinfo\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [32 x i8] c"RDTSC: Error reading cpu speed\0A\00"
@.str.3 = [4 x i8] c"%lf\00"
@.str.4 = [33 x i8] c"RDTSC: Error reading cpu speed.\0A\00"
define double @SetMHz() {
%1 = alloca double
%2 = alloca i32*
%3 = call i32* @popen(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %3, i32** %2
%4 = load i32*, i32** %2
%5 = icmp ne i32* %4, null
br i1 %5, label %9, label %6
6: ; preds = %0
%7 = call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0))
%8 = call i32 @exit(i32 -1)
unreachable
9: ; preds = %0
%10 = load i32*, i32** %2
%11 = call i32 @fscanf(i32* %10, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), double* %1)
%12 = icmp ne i32 %11, 1
br i1 %12, label %13, label %16
13: ; preds = %9
%14 = call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0))
%15 = call i32 @exit(i32 -1)
unreachable
16: ; preds = %9
%17 = load i32*, i32** %2
%18 = call i32 @pclose(i32* %17)
%19 = load double, double* %1
ret double %19
}

LLVM IR (-O2):
@.str = [49 x i8] c"/bin/sed -n '/cpu MHz/s/[^:]*://p' /proc/cpuinfo\00"
@.str.1 = [2 x i8] c"r\00"
@.str.3 = [4 x i8] c"%lf\00"
@str = [31 x i8] c"RDTSC: Error reading cpu speed\00"
@str.5 = [32 x i8] c"RDTSC: Error reading cpu speed.\00"
define double @SetMHz() {
%1 = alloca double
%2 = bitcast double* %1 to i8*
%3 = tail call i32* @popen(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %5, label %8
5: ; preds = %0
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @str, i64 0, i64 0))
%7 = tail call i32 @exit(i32 -1)
unreachable
8: ; preds = %0
%9 = call i32 @fscanf(i32* %3, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), double* %1)
%10 = icmp eq i32 %9, 1
br i1 %10, label %14, label %11
11: ; preds = %8
%12 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @str.5, i64 0, i64 0))
%13 = call i32 @exit(i32 -1)
unreachable
14: ; preds = %8
%15 = call i32 @pclose(i32* %3)
%16 = load double, double* %1
ret double %16
}