#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*/ EXIT_SUCCESS;
scalar_t__ HardSum(float);
scalar_t__ RAND_MAX;
float *calloc(long const, int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ free(float *);
int /*<<< orphan*/ printf(char *, double);
scalar_t__ rand();
int /*<<< orphan*/ srand(int);
int main(void) {
  const long dataSize = 4 * 1024 * 1024;
  float *data = calloc(dataSize, sizeof(float));
  srand(13);
  for (long d = 0; d < dataSize; d++) {
    data[d] = (float)(rand() + 1.0) / (float)RAND_MAX;
  }
  double sum = 0.0;
#pragma omp parallel for
  for (long d = 0; d < dataSize; d++) {
#pragma omp atomic
    sum += HardSum(data[d]);
  }
  printf("% 20f \n", sum);
  free(data);
  exit(EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0x400000,-0x10(%rbp)
mov    $0x400000,%edi
mov    $0x4,%esi
call   1060 <calloc@plt>
mov    %rax,-0x18(%rbp)
mov    $0xd,%edi
call   1050 <srand@plt>
movq   $0x0,-0x20(%rbp)
cmpq   $0x400000,-0x20(%rbp)
jge    1204 <main+0x94>
mov    $0x0,%al
call   1090 <rand@plt>
cvtsi2sd %rax,%xmm0
movsd  0xe32(%rip),%xmm1
addsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
mov    0x2e0b(%rip),%rax
cvtsi2ssq (%rax),%xmm1
divss  %xmm1,%xmm0
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%rcx
movss  %xmm0,(%rax,%rcx,4)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    11ac <main+0x3c>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
cmpq   $0x400000,-0x30(%rbp)
jge    1254 <main+0xe4>
mov    -0x18(%rbp),%rax
mov    -0x30(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm0
call   1070 <HardSum@plt>
cvtsi2sd %rax,%xmm0
addsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    1214 <main+0xa4>
movsd  -0x28(%rbp),%xmm0
lea    0xda8(%rip),%rdi
call   1040 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    0x2d63(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    $0x400000,%edi
mov    $0x4,%esi
call   1060 <calloc@plt>
mov    %rax,%r15
mov    $0xd,%edi
call   1050 <srand@plt>
mov    0x2e4c(%rip),%r14
xor    %ebx,%ebx
xchg   %ax,%ax
xor    %eax,%eax
call   1090 <rand@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
addsd  0xe49(%rip),%xmm0
cvtsd2ss %xmm0,%xmm0
xorps  %xmm1,%xmm1
cvtsi2ssq (%r14),%xmm1
divss  %xmm1,%xmm0
movss  %xmm0,(%r15,%rbx,4)
add    $0x1,%rbx
cmp    $0x400000,%rbx
jne    11a0 <main+0x30>
xorps  %xmm0,%xmm0
xor    %ebx,%ebx
nop
movsd  %xmm0,0x8(%rsp)
movss  (%r15,%rbx,4),%xmm0
call   1070 <HardSum@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
movsd  0x8(%rsp),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,0x8(%rsp)
movsd  0x8(%rsp),%xmm0
add    $0x1,%rbx
cmp    $0x400000,%rbx
jne    11e0 <main+0x70>
lea    0xde5(%rip),%rdi
call   1040 <printf@plt>
mov    %r15,%rdi
call   1030 <free@plt>
mov    0x2da1(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@RAND_MAX = global i64 0
@.str = [8 x i8] c"% 20f \0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i64
%3 = alloca float*
%4 = alloca i64
%5 = alloca double
%6 = alloca i64
store i32 0, i32* %1
store i64 4194304, i64* %2
%7 = call float* @calloc(i64 4194304, i32 4)
store float* %7, float** %3
%8 = call i32 @srand(i32 13)
store i64 0, i64* %4
br label %9
9: ; preds = %23, %0
%10 = load i64, i64* %4
%11 = icmp slt i64 %10, 4194304
br i1 %11, label %12, label %26
12: ; preds = %9
%13 = call i64 (...) @rand()
%14 = sitofp i64 %13 to double
%15 = fadd double %14, 1.000000e+00
%16 = fptrunc double %15 to float
%17 = load i64, i64* @RAND_MAX
%18 = sitofp i64 %17 to float
%19 = fdiv float %16, %18
%20 = load float*, float** %3
%21 = load i64, i64* %4
%22 = getelementptr inbounds float, float* %20, i64 %21
store float %19, float* %22
br label %23
23: ; preds = %12
%24 = load i64, i64* %4
%25 = add nsw i64 %24, 1
store i64 %25, i64* %4
br label %9
26: ; preds = %9
store double 0.000000e+00, double* %5
store i64 0, i64* %6
br label %27
27: ; preds = %39, %26
%28 = load i64, i64* %6
%29 = icmp slt i64 %28, 4194304
br i1 %29, label %30, label %42
30: ; preds = %27
%31 = load float*, float** %3
%32 = load i64, i64* %6
%33 = getelementptr inbounds float, float* %31, i64 %32
%34 = load float, float* %33
%35 = call i64 @HardSum(float %34)
%36 = sitofp i64 %35 to double
%37 = load double, double* %5
%38 = fadd double %37, %36
store double %38, double* %5
br label %39
39: ; preds = %30
%40 = load i64, i64* %6
%41 = add nsw i64 %40, 1
store i64 %41, i64* %6
br label %27
42: ; preds = %27
%43 = load double, double* %5
%44 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), double %43)
%45 = load float*, float** %3
%46 = call i32 @free(float* %45)
%47 = load i32, i32* @EXIT_SUCCESS
%48 = call i32 @exit(i32 %47)
unreachable
}

LLVM IR (-O2):
@RAND_MAX = global i64 0
@.str = [8 x i8] c"% 20f \0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = tail call float* @calloc(i64 4194304, i32 4)
%2 = tail call i32 @srand(i32 13)
br label %3
3: ; preds = %0, %3
%4 = phi i64 [ 0, %0 ], [ %13, %3 ]
%5 = tail call i64 (...) @rand()
%6 = sitofp i64 %5 to double
%7 = fadd double %6, 1.000000e+00
%8 = fptrunc double %7 to float
%9 = load i64, i64* @RAND_MAX
%10 = sitofp i64 %9 to float
%11 = fdiv float %8, %10
%12 = getelementptr inbounds float, float* %1, i64 %4
store float %11, float* %12
%13 = add nuw nsw i64 %4, 1
%14 = icmp eq i64 %13, 4194304
br i1 %14, label %20, label %3
15: ; preds = %20
%16 = tail call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), double %27)
%17 = tail call i32 @free(float* %1)
%18 = load i32, i32* @EXIT_SUCCESS
%19 = tail call i32 @exit(i32 %18)
unreachable
20: ; preds = %3, %20
%21 = phi i64 [ %28, %20 ], [ 0, %3 ]
%22 = phi double [ %27, %20 ], [ 0.000000e+00, %3 ]
%23 = getelementptr inbounds float, float* %1, i64 %21
%24 = load float, float* %23
%25 = tail call i64 @HardSum(float %24)
%26 = sitofp i64 %25 to double
%27 = fadd double %22, %26
%28 = add nuw nsw i64 %21, 1
%29 = icmp eq i64 %28, 4194304
br i1 %29, label %15, label %20
}