#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_FAILURE;
double INFINITY;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
void benchmarkSave(double time) {
  FILE *fp;
  double meanDelay = INFINITY;
  double meanSymbolTime = INFINITY;
  double meanSymbolRate = 0;
  int guardInterval = 0;
  int lSub = 16;
  const char mode[12] = "MultiKernel";
  int cCount = 0;
  meanDelay = time / 1000;
  meanSymbolTime = time / (6144 * 1000);
  meanSymbolRate = 6144 * 1e6 / time;
  fp = fopen("speedLog.dat", "a");
  if (fp == NULL) {
    fprintf(stderr, "Failed to load speedLog.dat\nUnable to save results\n");
    exit(EXIT_FAILURE);
  }
  cCount =
      fprintf(fp, "%-19.2f %-17.2f %-13.2f %-25d %-23d %s\n", meanSymbolRate,
              meanSymbolTime, meanDelay, lSub, guardInterval, mode);
  if (cCount == 0) {
    fprintf(stderr, "Error: Could not write to file\n->Benchmark results lost");
    fclose(fp);
    exit(EXIT_FAILURE);
  }
  fprintf(stdout, "Benchmark results written to speedLog.dat\n");
  fclose(fp);
}


x86 assembly (clang, -O0):
<benchmarkSave>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movsd  %xmm0,-0x8(%rbp)
mov    0x2e94(%rip),%rax
movsd  (%rax),%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    0x2e84(%rip),%rax
movsd  (%rax),%xmm0
movsd  %xmm0,-0x20(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
movl   $0x10,-0x30(%rbp)
mov    0xe8e(%rip),%rax
mov    %rax,-0x3c(%rbp)
mov    0xe8c(%rip),%eax
mov    %eax,-0x34(%rbp)
movl   $0x0,-0x40(%rbp)
movsd  -0x8(%rbp),%xmm0
movsd  0xe65(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x8(%rbp),%xmm0
movsd  0xe47(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  0xe2e(%rip),%xmm0
divsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
lea    0xe41(%rip),%rdi
lea    0xe47(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1223 <benchmarkSave+0xe3>
mov    0x2dd3(%rip),%rax
mov    (%rax),%edi
lea    0xe25(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    0x2db4(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
mov    -0x10(%rbp),%rax
mov    %eax,%edi
movsd  -0x28(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm1
movsd  -0x18(%rbp),%xmm2
mov    -0x30(%rbp),%edx
mov    -0x2c(%rbp),%ecx
lea    -0x3c(%rbp),%r8
lea    0xe1e(%rip),%rsi
mov    $0x3,%al
call   1040 <fprintf@plt>
mov    %eax,-0x40(%rbp)
cmpl   $0x0,-0x40(%rbp)
jne    128b <benchmarkSave+0x14b>
mov    0x2d74(%rip),%rax
mov    (%rax),%edi
lea    0xe22(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
mov    0x2d4c(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
mov    0x2d36(%rip),%rax
mov    (%rax),%edi
lea    0xe2c(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<benchmarkSave>:
push   %rbx
sub    $0x20,%rsp
movsd  %xmm0,0x8(%rsp)
movabs $0x72654b69746c754d,%rax
4b 65 72
mov    %rax,0x10(%rsp)
movl   $0x6c656e,0x18(%rsp)
lea    0xebb(%rip),%rdi
lea    0xec1(%rip),%rsi
call   1050 <fopen@plt>
test   %rax,%rax
je     11e8 <benchmarkSave+0xa8>
mov    %rax,%rbx
movsd  0xe7b(%rip),%xmm0
movsd  0x8(%rsp),%xmm2
divsd  %xmm2,%xmm0
movapd %xmm2,%xmm1
divsd  0xe6d(%rip),%xmm1
divsd  0xe6d(%rip),%xmm2
lea    0xebd(%rip),%rsi
lea    0x10(%rsp),%r8
mov    %ebx,%edi
mov    $0x10,%edx
xor    %ecx,%ecx
mov    $0x3,%al
call   1040 <fprintf@plt>
test   %eax,%eax
je     1201 <benchmarkSave+0xc1>
mov    0x2e06(%rip),%rax
mov    (%rax),%edi
lea    0xef4(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
add    $0x20,%rsp
pop    %rbx
ret
mov    0x2df1(%rip),%rax
mov    (%rax),%edi
lea    0xe3b(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
jmp    1220 <benchmarkSave+0xe0>
mov    0x2dd8(%rip),%rax
mov    (%rax),%edi
lea    0xe7e(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    0x2db1(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@INFINITY = global double 0.000000e+00
@__const.benchmarkSave.mode = [12 x i8] c"MultiKernel\00"
@.str = [13 x i8] c"speedLog.dat\00"
@.str.1 = [2 x i8] c"a\00"
@stderr = global i32 0
@.str.2 = [52 x i8] c"Failed to load speedLog.dat\0AUnable to save results\0A\00"
@EXIT_FAILURE = global i32 0
@.str.3 = [40 x i8] c"%-19.2f %-17.2f %-13.2f %-25d %-23d %s\0A\00"
@.str.4 = [56 x i8] c"Error: Could not write to file\0A->Benchmark results lost\00"
@stdout = global i32 0
@.str.5 = [43 x i8] c"Benchmark results written to speedLog.dat\0A\00"
define void @benchmarkSave(double %0) {
%2 = alloca double
%3 = alloca i32*
%4 = alloca double
%5 = alloca double
%6 = alloca double
%7 = alloca i32
%8 = alloca i32
%9 = alloca [12 x i8]
%10 = alloca i32
store double %0, double* %2
%11 = load double, double* @INFINITY
store double %11, double* %4
%12 = load double, double* @INFINITY
store double %12, double* %5
store double 0.000000e+00, double* %6
store i32 0, i32* %7
store i32 16, i32* %8
%13 = bitcast [12 x i8]* %9 to i8*
store i32 0, i32* %10
%14 = load double, double* %2
%15 = fdiv double %14, 1.000000e+03
store double %15, double* %4
%16 = load double, double* %2
%17 = fdiv double %16, 6.144000e+06
store double %17, double* %5
%18 = load double, double* %2
%19 = fdiv double 6.144000e+09, %18
store double %19, double* %6
%20 = call i32* @fopen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %20, i32** %3
%21 = load i32*, i32** %3
%22 = icmp eq i32* %21, null
br i1 %22, label %23, label %28
23: ; preds = %1
%24 = load i32, i32* @stderr
%25 = call i32 (i32, i8*, ...) @fprintf(i32 %24, i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.2, i64 0, i64 0))
%26 = load i32, i32* @EXIT_FAILURE
%27 = call i32 @exit(i32 %26)
unreachable
28: ; preds = %1
%29 = load i32*, i32** %3
%30 = ptrtoint i32* %29 to i32
%31 = load double, double* %6
%32 = load double, double* %5
%33 = load double, double* %4
%34 = load i32, i32* %8
%35 = load i32, i32* %7
%36 = getelementptr inbounds [12 x i8], [12 x i8]* %9, i64 0, i64 0
%37 = call i32 (i32, i8*, ...) @fprintf(i32 %30, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.3, i64 0, i64 0), double %31, double %32, double %33, i32 %34, i32 %35, i8* %36)
store i32 %37, i32* %10
%38 = load i32, i32* %10
%39 = icmp eq i32 %38, 0
br i1 %39, label %40, label %47
40: ; preds = %28
%41 = load i32, i32* @stderr
%42 = call i32 (i32, i8*, ...) @fprintf(i32 %41, i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.4, i64 0, i64 0))
%43 = load i32*, i32** %3
%44 = call i32 @fclose(i32* %43)
%45 = load i32, i32* @EXIT_FAILURE
%46 = call i32 @exit(i32 %45)
unreachable
47: ; preds = %28
%48 = load i32, i32* @stdout
%49 = call i32 (i32, i8*, ...) @fprintf(i32 %48, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.5, i64 0, i64 0))
%50 = load i32*, i32** %3
%51 = call i32 @fclose(i32* %50)
ret void
}

LLVM IR (-O2):
@INFINITY = global double 0.000000e+00
@__const.benchmarkSave.mode = [12 x i8] c"MultiKernel\00"
@.str = [13 x i8] c"speedLog.dat\00"
@.str.1 = [2 x i8] c"a\00"
@stderr = global i32 0
@.str.2 = [52 x i8] c"Failed to load speedLog.dat\0AUnable to save results\0A\00"
@EXIT_FAILURE = global i32 0
@.str.3 = [40 x i8] c"%-19.2f %-17.2f %-13.2f %-25d %-23d %s\0A\00"
@.str.4 = [56 x i8] c"Error: Could not write to file\0A->Benchmark results lost\00"
@stdout = global i32 0
@.str.5 = [43 x i8] c"Benchmark results written to speedLog.dat\0A\00"
define void @benchmarkSave(double %0) {
%2 = alloca [12 x i8]
%3 = getelementptr inbounds [12 x i8], [12 x i8]* %2, i64 0, i64 0
%4 = tail call i32* @fopen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %6, label %11
6: ; preds = %1
%7 = load i32, i32* @stderr
%8 = tail call i32 (i32, i8*, ...) @fprintf(i32 %7, i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.2, i64 0, i64 0))
%9 = load i32, i32* @EXIT_FAILURE
%10 = tail call i32 @exit(i32 %9)
unreachable
11: ; preds = %1
%12 = fdiv double 6.144000e+09, %0
%13 = fdiv double %0, 6.144000e+06
%14 = fdiv double %0, 1.000000e+03
%15 = ptrtoint i32* %4 to i64
%16 = trunc i64 %15 to i32
%17 = call i32 (i32, i8*, ...) @fprintf(i32 %16, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.3, i64 0, i64 0), double %12, double %13, double %14, i32 16, i32 0, i8* %3)
%18 = icmp eq i32 %17, 0
br i1 %18, label %19, label %25
19: ; preds = %11
%20 = load i32, i32* @stderr
%21 = call i32 (i32, i8*, ...) @fprintf(i32 %20, i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.4, i64 0, i64 0))
%22 = call i32 @fclose(i32* %4)
%23 = load i32, i32* @EXIT_FAILURE
%24 = call i32 @exit(i32 %23)
unreachable
25: ; preds = %11
%26 = load i32, i32* @stdout
%27 = call i32 (i32, i8*, ...) @fprintf(i32 %26, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.5, i64 0, i64 0))
%28 = call i32 @fclose(i32* %4)
ret void
}