#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 */

/* Variables and functions */
int /*<<< orphan*/ bench(unsigned int, double *, unsigned int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ stderr;
void runBench(double *buffer, unsigned long bufferSize, unsigned int nbThread) {
  unsigned int i = 0;
  if (bufferSize < (4096 * 1024 / sizeof(double))) {
    fprintf(stderr, "Error, buffer is too short\n");
    exit(1);
  }
  for (i = 0; i < 14UL * 1024 * 1024 / sizeof(double); i++)
    buffer[i] = 0.0;
  for (i = 0; i <= (156 * 1024 / sizeof(double)); i += 128)
    bench(i, buffer, nbThread);
  fprintf(stderr, "____PASS 128K_____\n");
  for (; i <= (256 * 1024 / sizeof(double)); i += 256)
    bench(i, buffer, nbThread);
  fprintf(stderr, "____PASS 256K_____\n");
  for (; i <= (512 * 1024 / sizeof(double)); i += 512)
    bench(i, buffer, nbThread);
  fprintf(stderr, "____PASS 512K_____\n");
  for (; i <= (4096 * 1024 / sizeof(double)); i += 1024)
    bench(i, buffer, nbThread);
  fprintf(stderr, "____PASS 4096K_____\n");
  for (; i <= 14UL * 1024 * 1024 / sizeof(double); i += 4096)
    bench(i, buffer, nbThread);
  fprintf(stderr, "____PASS %ldK_____\n", 14UL * 1024 * 1024 / 1024);
}


x86 assembly (clang, -O0):
<runBench>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
cmpq   $0x80000,-0x10(%rbp)
jae    1179 <runBench+0x49>
mov    0x2e81(%rip),%rax
mov    (%rax),%edi
lea    0xe98(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    $0x1c0000,%rax
jae    11ac <runBench+0x7c>
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%ecx
xorps  %xmm0,%xmm0
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1180 <runBench+0x50>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    $0x4e00,%rax
ja     11e1 <runBench+0xb1>
mov    -0x18(%rbp),%edi
mov    -0x8(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1030 <bench@plt>
mov    -0x18(%rbp),%eax
add    $0x80,%eax
mov    %eax,-0x18(%rbp)
jmp    11b3 <runBench+0x83>
mov    0x2df8(%rip),%rax
mov    (%rax),%edi
lea    0xe2b(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x18(%rbp),%eax
cmp    $0x8000,%rax
ja     1226 <runBench+0xf6>
mov    -0x18(%rbp),%edi
mov    -0x8(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1030 <bench@plt>
mov    -0x18(%rbp),%eax
add    $0x100,%eax
mov    %eax,-0x18(%rbp)
jmp    11f8 <runBench+0xc8>
mov    0x2db3(%rip),%rax
mov    (%rax),%edi
lea    0xdfa(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x18(%rbp),%eax
cmp    $0x10000,%rax
ja     126b <runBench+0x13b>
mov    -0x18(%rbp),%edi
mov    -0x8(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1030 <bench@plt>
mov    -0x18(%rbp),%eax
add    $0x200,%eax
mov    %eax,-0x18(%rbp)
jmp    123d <runBench+0x10d>
mov    0x2d6e(%rip),%rax
mov    (%rax),%edi
lea    0xdc9(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x18(%rbp),%eax
cmp    $0x80000,%rax
ja     12b0 <runBench+0x180>
mov    -0x18(%rbp),%edi
mov    -0x8(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1030 <bench@plt>
mov    -0x18(%rbp),%eax
add    $0x400,%eax
mov    %eax,-0x18(%rbp)
jmp    1282 <runBench+0x152>
mov    0x2d29(%rip),%rax
mov    (%rax),%edi
lea    0xd98(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x18(%rbp),%eax
cmp    $0x1c0000,%rax
ja     12f5 <runBench+0x1c5>
mov    -0x18(%rbp),%edi
mov    -0x8(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1030 <bench@plt>
mov    -0x18(%rbp),%eax
add    $0x1000,%eax
mov    %eax,-0x18(%rbp)
jmp    12c7 <runBench+0x197>
mov    0x2ce4(%rip),%rax
mov    (%rax),%edi
lea    0xd68(%rip),%rsi
mov    $0x3800,%edx
mov    $0x0,%al
call   1040 <fprintf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<runBench>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
cmp    $0x80000,%rsi
jb     12aa <runBench+0x16a>
mov    %edx,%r14d
mov    %rdi,%r15
mov    $0xe00000,%edx
xor    %esi,%esi
call   1040 <memset@plt>
mov    $0xffffff80,%ebp
nopl   0x0(%rax)
sub    $0xffffff80,%ebp
mov    %ebp,%edi
mov    %r15,%rsi
mov    %r14d,%edx
call   1030 <bench@plt>
cmp    $0x4d81,%ebp
jb     1170 <runBench+0x30>
mov    0x2e51(%rip),%r12
mov    (%r12),%edi
lea    0xe82(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0x4d80,%ebp
cs nopw 0x0(%rax,%rax,1)
add    $0x100,%ebp
mov    %ebp,%edi
mov    %r15,%rsi
mov    %r14d,%edx
call   1030 <bench@plt>
cmp    $0x7f01,%ebp
jb     11b0 <runBench+0x70>
mov    (%r12),%edi
lea    0xe5a(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0x7080,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
lea    0x1000(%rbp),%ebx
mov    %ebx,%edi
mov    %r15,%rsi
mov    %r14d,%edx
call   1030 <bench@plt>
add    $0x200,%ebp
cmp    $0xfe01,%ebx
jb     11f0 <runBench+0xb0>
mov    (%r12),%edi
lea    0xe28(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
lea    0x1000(%rbp),%ebx
mov    %ebx,%edi
mov    %r15,%rsi
mov    %r14d,%edx
call   1030 <bench@plt>
add    $0x400,%ebp
cmp    $0x7fc01,%ebx
jb     1230 <runBench+0xf0>
mov    (%r12),%edi
lea    0xdfc(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
add    $0x1000,%ebp
mov    %ebp,%edi
mov    %r15,%rsi
mov    %r14d,%edx
call   1030 <bench@plt>
cmp    $0x1bf001,%ebp
jb     1270 <runBench+0x130>
mov    (%r12),%edi
lea    0xdd7(%rip),%rsi
mov    $0x3800,%edx
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <fprintf@plt>
mov    0x2d2f(%rip),%rax
mov    (%rax),%edi
lea    0xd46(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [28 x i8] c"Error, buffer is too short\0A\00"
@.str.1 = [20 x i8] c"____PASS 128K_____\0A\00"
@.str.2 = [20 x i8] c"____PASS 256K_____\0A\00"
@.str.3 = [20 x i8] c"____PASS 512K_____\0A\00"
@.str.4 = [21 x i8] c"____PASS 4096K_____\0A\00"
@.str.5 = [20 x i8] c"____PASS %ldK_____\0A\00"
define void @runBench(double* %0, i64 %1, i32 %2) {
%4 = alloca double*
%5 = alloca i64
%6 = alloca i32
%7 = alloca i32
store double* %0, double** %4
store i64 %1, i64* %5
store i32 %2, i32* %6
store i32 0, i32* %7
%8 = load i64, i64* %5
%9 = icmp ult i64 %8, 524288
br i1 %9, label %10, label %14
10: ; preds = %3
%11 = load i32, i32* @stderr
%12 = call i32 (i32, i8*, ...) @fprintf(i32 %11, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
%13 = call i32 @exit(i32 1)
unreachable
14: ; preds = %3
store i32 0, i32* %7
br label %15
15: ; preds = %24, %14
%16 = load i32, i32* %7
%17 = zext i32 %16 to i64
%18 = icmp ult i64 %17, 1835008
br i1 %18, label %19, label %27
19: ; preds = %15
%20 = load double*, double** %4
%21 = load i32, i32* %7
%22 = zext i32 %21 to i64
%23 = getelementptr inbounds double, double* %20, i64 %22
store double 0.000000e+00, double* %23
br label %24
24: ; preds = %19
%25 = load i32, i32* %7
%26 = add i32 %25, 1
store i32 %26, i32* %7
br label %15
27: ; preds = %15
store i32 0, i32* %7
br label %28
28: ; preds = %37, %27
%29 = load i32, i32* %7
%30 = zext i32 %29 to i64
%31 = icmp ule i64 %30, 19968
br i1 %31, label %32, label %40
32: ; preds = %28
%33 = load i32, i32* %7
%34 = load double*, double** %4
%35 = load i32, i32* %6
%36 = call i32 @bench(i32 %33, double* %34, i32 %35)
br label %37
37: ; preds = %32
%38 = load i32, i32* %7
%39 = add i32 %38, 128
store i32 %39, i32* %7
br label %28
40: ; preds = %28
%41 = load i32, i32* @stderr
%42 = call i32 (i32, i8*, ...) @fprintf(i32 %41, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
br label %43
43: ; preds = %52, %40
%44 = load i32, i32* %7
%45 = zext i32 %44 to i64
%46 = icmp ule i64 %45, 32768
br i1 %46, label %47, label %55
47: ; preds = %43
%48 = load i32, i32* %7
%49 = load double*, double** %4
%50 = load i32, i32* %6
%51 = call i32 @bench(i32 %48, double* %49, i32 %50)
br label %52
52: ; preds = %47
%53 = load i32, i32* %7
%54 = add i32 %53, 256
store i32 %54, i32* %7
br label %43
55: ; preds = %43
%56 = load i32, i32* @stderr
%57 = call i32 (i32, i8*, ...) @fprintf(i32 %56, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
br label %58
58: ; preds = %67, %55
%59 = load i32, i32* %7
%60 = zext i32 %59 to i64
%61 = icmp ule i64 %60, 65536
br i1 %61, label %62, label %70
62: ; preds = %58
%63 = load i32, i32* %7
%64 = load double*, double** %4
%65 = load i32, i32* %6
%66 = call i32 @bench(i32 %63, double* %64, i32 %65)
br label %67
67: ; preds = %62
%68 = load i32, i32* %7
%69 = add i32 %68, 512
store i32 %69, i32* %7
br label %58
70: ; preds = %58
%71 = load i32, i32* @stderr
%72 = call i32 (i32, i8*, ...) @fprintf(i32 %71, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0))
br label %73
73: ; preds = %82, %70
%74 = load i32, i32* %7
%75 = zext i32 %74 to i64
%76 = icmp ule i64 %75, 524288
br i1 %76, label %77, label %85
77: ; preds = %73
%78 = load i32, i32* %7
%79 = load double*, double** %4
%80 = load i32, i32* %6
%81 = call i32 @bench(i32 %78, double* %79, i32 %80)
br label %82
82: ; preds = %77
%83 = load i32, i32* %7
%84 = add i32 %83, 1024
store i32 %84, i32* %7
br label %73
85: ; preds = %73
%86 = load i32, i32* @stderr
%87 = call i32 (i32, i8*, ...) @fprintf(i32 %86, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0))
br label %88
88: ; preds = %97, %85
%89 = load i32, i32* %7
%90 = zext i32 %89 to i64
%91 = icmp ule i64 %90, 1835008
br i1 %91, label %92, label %100
92: ; preds = %88
%93 = load i32, i32* %7
%94 = load double*, double** %4
%95 = load i32, i32* %6
%96 = call i32 @bench(i32 %93, double* %94, i32 %95)
br label %97
97: ; preds = %92
%98 = load i32, i32* %7
%99 = add i32 %98, 4096
store i32 %99, i32* %7
br label %88
100: ; preds = %88
%101 = load i32, i32* @stderr
%102 = call i32 (i32, i8*, ...) @fprintf(i32 %101, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0), i64 14336)
ret void
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [28 x i8] c"Error, buffer is too short\0A\00"
@.str.1 = [20 x i8] c"____PASS 128K_____\0A\00"
@.str.2 = [20 x i8] c"____PASS 256K_____\0A\00"
@.str.3 = [20 x i8] c"____PASS 512K_____\0A\00"
@.str.4 = [21 x i8] c"____PASS 4096K_____\0A\00"
@.str.5 = [20 x i8] c"____PASS %ldK_____\0A\00"
define void @runBench(double* %0, i64 %1, i32 %2) {
%4 = icmp ult i64 %1, 524288
br i1 %4, label %7, label %5
5: ; preds = %3
%6 = bitcast double* %0 to i8*
br label %11
7: ; preds = %3
%8 = load i32, i32* @stderr
%9 = tail call i32 (i32, i8*, ...) @fprintf(i32 %8, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
%10 = tail call i32 @exit(i32 1)
unreachable
11: ; preds = %5, %11
%12 = phi i32 [ %14, %11 ], [ 0, %5 ]
%13 = tail call i32 @bench(i32 %12, double* %0, i32 %2)
%14 = add nuw nsw i32 %12, 128
%15 = icmp ult i32 %12, 19841
br i1 %15, label %11, label %16
16: ; preds = %11
%17 = load i32, i32* @stderr
%18 = tail call i32 (i32, i8*, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
br label %19
19: ; preds = %16, %19
%20 = phi i32 [ %22, %19 ], [ 20096, %16 ]
%21 = tail call i32 @bench(i32 %20, double* %0, i32 %2)
%22 = add nuw nsw i32 %20, 256
%23 = icmp ult i32 %20, 32513
br i1 %23, label %19, label %24
24: ; preds = %19
%25 = load i32, i32* @stderr
%26 = tail call i32 (i32, i8*, ...) @fprintf(i32 %25, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
br label %27
27: ; preds = %24, %27
%28 = phi i32 [ %30, %27 ], [ 32896, %24 ]
%29 = tail call i32 @bench(i32 %28, double* %0, i32 %2)
%30 = add nuw nsw i32 %28, 512
%31 = icmp ult i32 %28, 65025
br i1 %31, label %27, label %32
32: ; preds = %27
%33 = load i32, i32* @stderr
%34 = tail call i32 (i32, i8*, ...) @fprintf(i32 %33, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0))
br label %35
35: ; preds = %32, %35
%36 = phi i32 [ %38, %35 ], [ %30, %32 ]
%37 = tail call i32 @bench(i32 %36, double* %0, i32 %2)
%38 = add nuw nsw i32 %36, 1024
%39 = icmp ult i32 %36, 523265
br i1 %39, label %35, label %40
40: ; preds = %35
%41 = load i32, i32* @stderr
%42 = tail call i32 (i32, i8*, ...) @fprintf(i32 %41, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0))
br label %43
43: ; preds = %40, %43
%44 = phi i32 [ %46, %43 ], [ %38, %40 ]
%45 = tail call i32 @bench(i32 %44, double* %0, i32 %2)
%46 = add nuw nsw i32 %44, 4096
%47 = icmp ult i32 %44, 1830913
br i1 %47, label %43, label %48
48: ; preds = %43
%49 = load i32, i32* @stderr
%50 = tail call i32 (i32, i8*, ...) @fprintf(i32 %49, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0), i64 14336)
ret void
}