#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*/ dump(double *);
int /*<<< orphan*/ free(double *);
int /*<<< orphan*/ kernel(double *, double *);
scalar_t__ malloc(int);
int main(int argc, char *argv[]) {
  double *g1, *g2;
  size_t nelms = 32 * 32 * 32;
  g1 = (double *)malloc(sizeof(double) * nelms);
  g2 = (double *)malloc(sizeof(double) * nelms);
  int i;
  for (i = 0; i < (int)nelms; i++) {
    g1[i] = i;
    g2[i] = i;
  }
  kernel(g1, g2);
  dump(g2);
  free(g1);
  free(g2);
  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   $0x8000,-0x28(%rbp)
mov    -0x28(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x28(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
mov    -0x28(%rbp),%rcx
cmp    %ecx,%eax
jge    11cc <main+0x8c>
cvtsi2sdl -0x2c(%rbp),%xmm0
mov    -0x18(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
cvtsi2sdl -0x2c(%rbp),%xmm0
mov    -0x20(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    118b <main+0x4b>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1040 <kernel@plt>
mov    -0x20(%rbp),%rdi
call   1050 <dump@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    $0x40000,%edi
call   1060 <malloc@plt>
mov    %rax,%r14
mov    $0x40000,%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
add    $0x40000,%rax
cmp    %rax,%r14
jae    11e8 <main+0xa8>
mov    %r14,%rax
add    $0x40000,%rax
cmp    %rax,%rbx
jae    11e8 <main+0xa8>
xor    %eax,%eax
nopl   0x0(%rax)
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
movsd  %xmm0,(%r14,%rax,8)
movsd  %xmm0,(%rbx,%rax,8)
lea    0x1(%rax),%ecx
xorps  %xmm0,%xmm0
cvtsi2sd %ecx,%xmm0
movsd  %xmm0,0x8(%r14,%rax,8)
movsd  %xmm0,0x8(%rbx,%rax,8)
lea    0x2(%rax),%ecx
xorps  %xmm0,%xmm0
cvtsi2sd %ecx,%xmm0
movsd  %xmm0,0x10(%r14,%rax,8)
movsd  %xmm0,0x10(%rbx,%rax,8)
lea    0x3(%rax),%ecx
xorps  %xmm0,%xmm0
cvtsi2sd %ecx,%xmm0
movsd  %xmm0,0x18(%r14,%rax,8)
movsd  %xmm0,0x18(%rbx,%rax,8)
add    $0x4,%rax
cmp    $0x8000,%rax
jne    1180 <main+0x40>
jmp    1282 <main+0x142>
movdqa 0xe10(%rip),%xmm0
xor    %eax,%eax
movdqa 0xe16(%rip),%xmm1
movdqa 0xe1e(%rip),%xmm2
movdqa 0xe26(%rip),%xmm3
movdqa 0xe2e(%rip),%xmm4
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movdqa %xmm0,%xmm5
cvtdq2pd %xmm0,%xmm6
paddd  %xmm1,%xmm5
cvtdq2pd %xmm5,%xmm5
movups %xmm6,(%r14,%rax,8)
movups %xmm5,0x10(%r14,%rax,8)
movups %xmm6,(%rbx,%rax,8)
movdqa %xmm0,%xmm6
paddd  %xmm2,%xmm6
movdqa %xmm0,%xmm7
paddd  %xmm3,%xmm7
cvtdq2pd %xmm6,%xmm6
cvtdq2pd %xmm7,%xmm7
movups %xmm5,0x10(%rbx,%rax,8)
movups %xmm6,0x20(%r14,%rax,8)
movups %xmm7,0x30(%r14,%rax,8)
movups %xmm6,0x20(%rbx,%rax,8)
movups %xmm7,0x30(%rbx,%rax,8)
add    $0x8,%rax
paddd  %xmm4,%xmm0
cmp    $0x8000,%rax
jne    1220 <main+0xe0>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1040 <kernel@plt>
mov    %rbx,%rdi
call   1050 <dump@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca double*
%7 = alloca double*
%8 = alloca i64
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i64 32768, i64* %8
%10 = load i64, i64* %8
%11 = mul i64 8, %10
%12 = trunc i64 %11 to i32
%13 = call i64 @malloc(i32 %12)
%14 = inttoptr i64 %13 to double*
store double* %14, double** %6
%15 = load i64, i64* %8
%16 = mul i64 8, %15
%17 = trunc i64 %16 to i32
%18 = call i64 @malloc(i32 %17)
%19 = inttoptr i64 %18 to double*
store double* %19, double** %7
store i32 0, i32* %9
br label %20
20: ; preds = %38, %2
%21 = load i32, i32* %9
%22 = load i64, i64* %8
%23 = trunc i64 %22 to i32
%24 = icmp slt i32 %21, %23
br i1 %24, label %25, label %41
25: ; preds = %20
%26 = load i32, i32* %9
%27 = sitofp i32 %26 to double
%28 = load double*, double** %6
%29 = load i32, i32* %9
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds double, double* %28, i64 %30
store double %27, double* %31
%32 = load i32, i32* %9
%33 = sitofp i32 %32 to double
%34 = load double*, double** %7
%35 = load i32, i32* %9
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds double, double* %34, i64 %36
store double %33, double* %37
br label %38
38: ; preds = %25
%39 = load i32, i32* %9
%40 = add nsw i32 %39, 1
store i32 %40, i32* %9
br label %20
41: ; preds = %20
%42 = load double*, double** %6
%43 = load double*, double** %7
%44 = call i32 @kernel(double* %42, double* %43)
%45 = load double*, double** %7
%46 = call i32 @dump(double* %45)
%47 = load double*, double** %6
%48 = call i32 @free(double* %47)
%49 = load double*, double** %7
%50 = call i32 @free(double* %49)
ret i32 0
}

LLVM IR (-O2):
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i64 @malloc(i32 262144)
%4 = inttoptr i64 %3 to double*
%5 = tail call i64 @malloc(i32 262144)
%6 = inttoptr i64 %5 to double*
%7 = inttoptr i64 %5 to i8*
%8 = inttoptr i64 %3 to i8*
%9 = getelementptr double, double* %4, i64 32768
%10 = bitcast double* %9 to i8*
%11 = getelementptr double, double* %6, i64 32768
%12 = bitcast double* %11 to i8*
%13 = icmp ult i8* %8, %12
%14 = icmp ult i8* %7, %10
%15 = and i1 %13, %14
br i1 %15, label %46, label %16
16: ; preds = %2, %16
%17 = phi i64 [ %43, %16 ], [ 0, %2 ]
%18 = phi <2 x i32> [ %44, %16 ], [ <i32 0, i32 1>, %2 ]
%19 = add <2 x i32> %18, <i32 2, i32 2>
%20 = sitofp <2 x i32> %18 to <2 x double>
%21 = sitofp <2 x i32> %19 to <2 x double>
%22 = getelementptr inbounds double, double* %4, i64 %17
%23 = bitcast double* %22 to <2 x double>*
store <2 x double> %20, <2 x double>* %23
%24 = getelementptr inbounds double, double* %22, i64 2
%25 = bitcast double* %24 to <2 x double>*
store <2 x double> %21, <2 x double>* %25
%26 = getelementptr inbounds double, double* %6, i64 %17
%27 = bitcast double* %26 to <2 x double>*
store <2 x double> %20, <2 x double>* %27
%28 = getelementptr inbounds double, double* %26, i64 2
%29 = bitcast double* %28 to <2 x double>*
store <2 x double> %21, <2 x double>* %29
%30 = or i64 %17, 4
%31 = add <2 x i32> %18, <i32 4, i32 4>
%32 = add <2 x i32> %18, <i32 6, i32 6>
%33 = sitofp <2 x i32> %31 to <2 x double>
%34 = sitofp <2 x i32> %32 to <2 x double>
%35 = getelementptr inbounds double, double* %4, i64 %30
%36 = bitcast double* %35 to <2 x double>*
store <2 x double> %33, <2 x double>* %36
%37 = getelementptr inbounds double, double* %35, i64 2
%38 = bitcast double* %37 to <2 x double>*
store <2 x double> %34, <2 x double>* %38
%39 = getelementptr inbounds double, double* %6, i64 %30
%40 = bitcast double* %39 to <2 x double>*
store <2 x double> %33, <2 x double>* %40
%41 = getelementptr inbounds double, double* %39, i64 2
%42 = bitcast double* %41 to <2 x double>*
store <2 x double> %34, <2 x double>* %42
%43 = add nuw nsw i64 %17, 8
%44 = add <2 x i32> %18, <i32 8, i32 8>
%45 = icmp eq i64 %43, 32768
br i1 %45, label %69, label %16
46: ; preds = %2, %46
%47 = phi i64 [ %67, %46 ], [ 0, %2 ]
%48 = trunc i64 %47 to i32
%49 = sitofp i32 %48 to double
%50 = getelementptr inbounds double, double* %4, i64 %47
store double %49, double* %50
%51 = getelementptr inbounds double, double* %6, i64 %47
store double %49, double* %51
%52 = or i64 %47, 1
%53 = trunc i64 %52 to i32
%54 = sitofp i32 %53 to double
%55 = getelementptr inbounds double, double* %4, i64 %52
store double %54, double* %55
%56 = getelementptr inbounds double, double* %6, i64 %52
store double %54, double* %56
%57 = or i64 %47, 2
%58 = trunc i64 %57 to i32
%59 = sitofp i32 %58 to double
%60 = getelementptr inbounds double, double* %4, i64 %57
store double %59, double* %60
%61 = getelementptr inbounds double, double* %6, i64 %57
store double %59, double* %61
%62 = or i64 %47, 3
%63 = trunc i64 %62 to i32
%64 = sitofp i32 %63 to double
%65 = getelementptr inbounds double, double* %4, i64 %62
store double %64, double* %65
%66 = getelementptr inbounds double, double* %6, i64 %62
store double %64, double* %66
%67 = add nuw nsw i64 %47, 4
%68 = icmp eq i64 %67, 32768
br i1 %68, label %69, label %46
69: ; preds = %16, %46
%70 = tail call i32 @kernel(double* %4, double* %6)
%71 = tail call i32 @dump(double* %6)
%72 = tail call i32 @free(double* %4)
%73 = tail call i32 @free(double* %6)
ret i32 0
}