#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*/ free(float *);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, float);
float reduce(float *);
int main(int argc, char *argv[]) {
  float *g1;
  size_t nelms = 16 * 16 * 16;
  g1 = (float *)malloc(sizeof(float) * nelms);
  int i;
  for (i = 0; i < (int)nelms; i++) {
    g1[i] = i;
  }
  float v = reduce(g1);
  printf("%f\n", v);
  free(g1);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x1000,-0x20(%rbp)
mov    -0x20(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    -0x20(%rbp),%rcx
cmp    %ecx,%eax
jge    11a7 <main+0x67>
cvtsi2ssl -0x24(%rbp),%xmm0
mov    -0x18(%rbp),%rax
movslq -0x24(%rbp),%rcx
movss  %xmm0,(%rax,%rcx,4)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1178 <main+0x38>
mov    -0x18(%rbp),%rdi
call   1040 <reduce@plt>
movss  %xmm0,-0x28(%rbp)
movss  -0x28(%rbp),%xmm0
lea    0xe3f(%rip),%rdi
call   1050 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    $0x4000,%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
movdqa 0xeaa(%rip),%xmm0
mov    $0xc,%eax
movdqa 0xead(%rip),%xmm1
movdqa 0xeb5(%rip),%xmm2
movdqa 0xebd(%rip),%xmm3
movdqa 0xec5(%rip),%xmm4
nopl   0x0(%rax,%rax,1)
movdqa %xmm0,%xmm5
paddd  %xmm1,%xmm5
cvtdq2ps %xmm0,%xmm6
cvtdq2ps %xmm5,%xmm5
movups %xmm6,-0x30(%rbx,%rax,4)
movups %xmm5,-0x20(%rbx,%rax,4)
movdqa %xmm0,%xmm5
paddd  %xmm2,%xmm5
movdqa %xmm0,%xmm6
paddd  %xmm3,%xmm6
cvtdq2ps %xmm5,%xmm5
cvtdq2ps %xmm6,%xmm6
movups %xmm5,-0x10(%rbx,%rax,4)
movups %xmm6,(%rbx,%rax,4)
paddd  %xmm4,%xmm0
add    $0x10,%rax
cmp    $0x100c,%rax
jne    1180 <main+0x40>
mov    %rbx,%rdi
call   1040 <reduce@plt>
lea    0xe7a(%rip),%rdi
call   1050 <printf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%f\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca float*
%7 = alloca i64
%8 = alloca i32
%9 = alloca float
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i64 4096, i64* %7
%10 = load i64, i64* %7
%11 = mul i64 4, %10
%12 = trunc i64 %11 to i32
%13 = call i64 @malloc(i32 %12)
%14 = inttoptr i64 %13 to float*
store float* %14, float** %6
store i32 0, i32* %8
br label %15
15: ; preds = %27, %2
%16 = load i32, i32* %8
%17 = load i64, i64* %7
%18 = trunc i64 %17 to i32
%19 = icmp slt i32 %16, %18
br i1 %19, label %20, label %30
20: ; preds = %15
%21 = load i32, i32* %8
%22 = sitofp i32 %21 to float
%23 = load float*, float** %6
%24 = load i32, i32* %8
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds float, float* %23, i64 %25
store float %22, float* %26
br label %27
27: ; preds = %20
%28 = load i32, i32* %8
%29 = add nsw i32 %28, 1
store i32 %29, i32* %8
br label %15
30: ; preds = %15
%31 = load float*, float** %6
%32 = call float @reduce(float* %31)
store float %32, float* %9
%33 = load float, float* %9
%34 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), float %33)
%35 = load float*, float** %6
%36 = call i32 @free(float* %35)
ret i32 0
}

LLVM IR (-O2):
@.str = [4 x i8] c"%f\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i64 @malloc(i32 16384)
%4 = inttoptr i64 %3 to float*
br label %5
5: ; preds = %5, %2
%6 = phi i64 [ 0, %2 ], [ %24, %5 ]
%7 = phi <4 x i32> [ <i32 0, i32 1, i32 2, i32 3>, %2 ], [ %25, %5 ]
%8 = add <4 x i32> %7, <i32 4, i32 4, i32 4, i32 4>
%9 = sitofp <4 x i32> %7 to <4 x float>
%10 = sitofp <4 x i32> %8 to <4 x float>
%11 = getelementptr inbounds float, float* %4, i64 %6
%12 = bitcast float* %11 to <4 x float>*
store <4 x float> %9, <4 x float>* %12
%13 = getelementptr inbounds float, float* %11, i64 4
%14 = bitcast float* %13 to <4 x float>*
store <4 x float> %10, <4 x float>* %14
%15 = or i64 %6, 8
%16 = add <4 x i32> %7, <i32 8, i32 8, i32 8, i32 8>
%17 = add <4 x i32> %7, <i32 12, i32 12, i32 12, i32 12>
%18 = sitofp <4 x i32> %16 to <4 x float>
%19 = sitofp <4 x i32> %17 to <4 x float>
%20 = getelementptr inbounds float, float* %4, i64 %15
%21 = bitcast float* %20 to <4 x float>*
store <4 x float> %18, <4 x float>* %21
%22 = getelementptr inbounds float, float* %20, i64 4
%23 = bitcast float* %22 to <4 x float>*
store <4 x float> %19, <4 x float>* %23
%24 = add nuw nsw i64 %6, 16
%25 = add <4 x i32> %7, <i32 16, i32 16, i32 16, i32 16>
%26 = icmp eq i64 %24, 4096
br i1 %26, label %27, label %5
27: ; preds = %5
%28 = tail call float @reduce(float* %4)
%29 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), float %28)
%30 = tail call i32 @free(float* %4)
ret i32 0
}