#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*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ printf(char *);
void writeBench(double *timings, int maxThreads, int startNumber, int endNumber,
                char *filename) {
  FILE *fp;
  fp = fopen(filename, "w+");
  if (fp == NULL)
    printf("File opening was not successful.");
  fprintf(fp, "Benchmark results\n\n");
  fprintf(fp, "Testing on numbers from %d to %d.\n\n", startNumber, endNumber);
  fprintf(fp, "Number of threads   Elapsed time (s)  Speedup\n\n");
  int iThread;
  for (iThread = 1; iThread <= maxThreads; iThread++)
    fprintf(fp, "        %d              %lf        %.2lf\n", iThread,
            timings[iThread - 1], timings[0] / timings[iThread - 1]);
  fclose(fp);
}


x86 assembly (clang, -O0):
<writeBench>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
mov    %r8,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xe9c(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1184 <writeBench+0x44>
lea    0xe84(%rip),%rdi
call   1040 <printf@plt>
mov    -0x28(%rbp),%rdi
lea    0xe95(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%edx
mov    -0x14(%rbp),%ecx
lea    0xe91(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x28(%rbp),%rdi
lea    0xea3(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0x1,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jg     1222 <writeBench+0xe2>
mov    -0x28(%rbp),%rdi
mov    -0x2c(%rbp),%edx
mov    -0x8(%rbp),%rax
mov    -0x2c(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x8(%rbp),%rax
movsd  (%rax),%xmm1
mov    -0x8(%rbp),%rax
mov    -0x2c(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
divsd  (%rax,%rcx,8),%xmm1
lea    0xe7f(%rip),%rsi
mov    $0x2,%al
call   1050 <fprintf@plt>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    11c7 <writeBench+0x87>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<writeBench>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %ecx,%r13d
mov    %edx,%ebp
mov    %esi,%r14d
mov    %rdi,%r12
lea    0xe93(%rip),%rsi
mov    %r8,%rdi
call   1060 <fopen@plt>
mov    %rax,%r15
test   %rax,%rax
jne    1189 <writeBench+0x39>
lea    0xe7f(%rip),%rdi
call   1040 <printf@plt>
lea    0xe94(%rip),%rdi
mov    $0x1,%ebx
mov    $0x13,%esi
mov    $0x1,%edx
mov    %r15,%rcx
call   1070 <fwrite@plt>
lea    0xe8a(%rip),%rsi
mov    %r15,%rdi
mov    %ebp,%edx
mov    %r13d,%ecx
xor    %eax,%eax
call   1050 <fprintf@plt>
lea    0xe98(%rip),%rdi
mov    $0x2f,%esi
mov    $0x1,%edx
mov    %r15,%rcx
call   1070 <fwrite@plt>
test   %r14d,%r14d
jle    1219 <writeBench+0xc9>
add    $0x1,%r14d
lea    0xea6(%rip),%rbp
cs nopw 0x0(%rax,%rax,1)
movsd  -0x8(%r12,%rbx,8),%xmm0
movsd  (%r12),%xmm1
divsd  %xmm0,%xmm1
mov    %r15,%rdi
mov    %rbp,%rsi
mov    %ebx,%edx
mov    $0x2,%al
call   1050 <fprintf@plt>
add    $0x1,%rbx
cmp    %rbx,%r14
jne    11f0 <writeBench+0xa0>
mov    %r15,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <fclose@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"w+\00"
@.str.1 = [33 x i8] c"File opening was not successful.\00"
@.str.2 = [20 x i8] c"Benchmark results\0A\0A\00"
@.str.3 = [36 x i8] c"Testing on numbers from %d to %d.\0A\0A\00"
@.str.4 = [48 x i8] c"Number of threads Elapsed time (s) Speedup\0A\0A\00"
@.str.5 = [42 x i8] c" %d %lf %.2lf\0A\00"
define void @writeBench(double* %0, i32 %1, i32 %2, i32 %3, i8* %4) {
%6 = alloca double*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i32*
%12 = alloca i32
store double* %0, double** %6
store i32 %1, i32* %7
store i32 %2, i32* %8
store i32 %3, i32* %9
store i8* %4, i8** %10
%13 = load i8*, i8** %10
%14 = call i32* @fopen(i8* %13, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %14, i32** %11
%15 = load i32*, i32** %11
%16 = icmp eq i32* %15, null
br i1 %16, label %17, label %19
17: ; preds = %5
%18 = call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0))
br label %19
19: ; preds = %17, %5
%20 = load i32*, i32** %11
%21 = call i32 (i32*, i8*, ...) @fprintf(i32* %20, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
%22 = load i32*, i32** %11
%23 = load i32, i32* %8
%24 = load i32, i32* %9
%25 = call i32 (i32*, i8*, ...) @fprintf(i32* %22, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0), i32 %23, i32 %24)
%26 = load i32*, i32** %11
%27 = call i32 (i32*, i8*, ...) @fprintf(i32* %26, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.4, i64 0, i64 0))
store i32 1, i32* %12
br label %28
28: ; preds = %52, %19
%29 = load i32, i32* %12
%30 = load i32, i32* %7
%31 = icmp sle i32 %29, %30
br i1 %31, label %32, label %55
32: ; preds = %28
%33 = load i32*, i32** %11
%34 = load i32, i32* %12
%35 = load double*, double** %6
%36 = load i32, i32* %12
%37 = sub nsw i32 %36, 1
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds double, double* %35, i64 %38
%40 = load double, double* %39
%41 = load double*, double** %6
%42 = getelementptr inbounds double, double* %41, i64 0
%43 = load double, double* %42
%44 = load double*, double** %6
%45 = load i32, i32* %12
%46 = sub nsw i32 %45, 1
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds double, double* %44, i64 %47
%49 = load double, double* %48
%50 = fdiv double %43, %49
%51 = call i32 (i32*, i8*, ...) @fprintf(i32* %33, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.5, i64 0, i64 0), i32 %34, double %40, double %50)
br label %52
52: ; preds = %32
%53 = load i32, i32* %12
%54 = add nsw i32 %53, 1
store i32 %54, i32* %12
br label %28
55: ; preds = %28
%56 = load i32*, i32** %11
%57 = call i32 @fclose(i32* %56)
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"w+\00"
@.str.1 = [33 x i8] c"File opening was not successful.\00"
@.str.2 = [20 x i8] c"Benchmark results\0A\0A\00"
@.str.3 = [36 x i8] c"Testing on numbers from %d to %d.\0A\0A\00"
@.str.4 = [48 x i8] c"Number of threads Elapsed time (s) Speedup\0A\0A\00"
@.str.5 = [42 x i8] c" %d %lf %.2lf\0A\00"
define void @writeBench(double* nocapture %0, i32 %1, i32 %2, i32 %3, i8* nocapture %4) {
%6 = tail call i32* @fopen(i8* %4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%7 = icmp eq i32* %6, null
br i1 %7, label %8, label %10
8: ; preds = %5
%9 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0))
br label %10
10: ; preds = %8, %5
%11 = tail call i64 @fwrite(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i64 19, i64 1, i32* %6)
%12 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %6, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0), i32 %2, i32 %3)
%13 = tail call i64 @fwrite(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.4, i64 0, i64 0), i64 47, i64 1, i32* %6)
%14 = icmp slt i32 %1, 1
br i1 %14, label %29, label %15
15: ; preds = %10
%16 = add nuw i32 %1, 1
%17 = zext i32 %16 to i64
br label %18
18: ; preds = %15, %18
%19 = phi i64 [ 1, %15 ], [ %27, %18 ]
%20 = add nsw i64 %19, -1
%21 = getelementptr inbounds double, double* %0, i64 %20
%22 = load double, double* %21
%23 = load double, double* %0
%24 = fdiv double %23, %22
%25 = trunc i64 %19 to i32
%26 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %6, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.5, i64 0, i64 0), i32 %25, double %22, double %24)
%27 = add nuw nsw i64 %19, 1
%28 = icmp eq i64 %27, %17
br i1 %28, label %29, label %18
29: ; preds = %18, %10
%30 = tail call i32 @fclose(i32* %6)
ret void
}