#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(float *);
int /*<<< orphan*/ free(float *);
int /*<<< orphan*/ kernel(float *, float *, int, int, int);
scalar_t__ malloc(int);
int main(int argc, char *argv[]) {
  float *g1, *g2;
  size_t nelms = 8 * 8 * 8;
  g1 = (float *)malloc(sizeof(float) * nelms);
  g2 = (float *)malloc(sizeof(float) * nelms);
  int i;
  for (i = 0; i < nelms; i++) {
    g1[i] = i;
  }
  int nx = 8, ny = 8, nz = 8;
  for (i = 0; i < 1; ++i) {
    kernel(g1, g2, nx, ny, nz);
    float *t = g1;
    g1 = g2;
    g2 = t;
  }
  dump(g1);
  free(g1);
  free(g2);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x200,-0x28(%rbp)
mov    -0x28(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x28(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x2c(%rbp)
movslq -0x2c(%rbp),%rax
cmp    -0x28(%rbp),%rax
jae    11b9 <main+0x79>
cvtsi2ssl -0x2c(%rbp),%xmm0
mov    -0x18(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movss  %xmm0,(%rax,%rcx,4)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    118b <main+0x4b>
movl   $0x8,-0x30(%rbp)
movl   $0x8,-0x34(%rbp)
movl   $0x8,-0x38(%rbp)
movl   $0x0,-0x2c(%rbp)
cmpl   $0x1,-0x2c(%rbp)
jge    121c <main+0xdc>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x30(%rbp),%edx
mov    -0x34(%rbp),%ecx
mov    -0x38(%rbp),%r8d
call   1040 <kernel@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x40(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    11d5 <main+0x95>
mov    -0x18(%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    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    $0x800,%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
mov    $0x800,%edi
call   1060 <malloc@plt>
mov    %rax,%r14
movdqa 0xe9a(%rip),%xmm0
mov    $0xc,%eax
movdqa 0xe9d(%rip),%xmm1
movdqa 0xea5(%rip),%xmm2
movdqa 0xead(%rip),%xmm3
movdqa 0xeb5(%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    $0x20c,%rax
jne    1190 <main+0x50>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x8,%edx
mov    $0x8,%ecx
mov    $0x8,%r8d
call   1040 <kernel@plt>
mov    %r14,%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 float*
%7 = alloca float*
%8 = alloca i64
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca float*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i64 512, i64* %8
%14 = load i64, i64* %8
%15 = mul i64 4, %14
%16 = trunc i64 %15 to i32
%17 = call i64 @malloc(i32 %16)
%18 = inttoptr i64 %17 to float*
store float* %18, float** %6
%19 = load i64, i64* %8
%20 = mul i64 4, %19
%21 = trunc i64 %20 to i32
%22 = call i64 @malloc(i32 %21)
%23 = inttoptr i64 %22 to float*
store float* %23, float** %7
store i32 0, i32* %9
br label %24
24: ; preds = %36, %2
%25 = load i32, i32* %9
%26 = sext i32 %25 to i64
%27 = load i64, i64* %8
%28 = icmp ult i64 %26, %27
br i1 %28, label %29, label %39
29: ; preds = %24
%30 = load i32, i32* %9
%31 = sitofp i32 %30 to float
%32 = load float*, float** %6
%33 = load i32, i32* %9
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds float, float* %32, i64 %34
store float %31, float* %35
br label %36
36: ; preds = %29
%37 = load i32, i32* %9
%38 = add nsw i32 %37, 1
store i32 %38, i32* %9
br label %24
39: ; preds = %24
store i32 8, i32* %10
store i32 8, i32* %11
store i32 8, i32* %12
store i32 0, i32* %9
br label %40
40: ; preds = %53, %39
%41 = load i32, i32* %9
%42 = icmp slt i32 %41, 1
br i1 %42, label %43, label %56
43: ; preds = %40
%44 = load float*, float** %6
%45 = load float*, float** %7
%46 = load i32, i32* %10
%47 = load i32, i32* %11
%48 = load i32, i32* %12
%49 = call i32 @kernel(float* %44, float* %45, i32 %46, i32 %47, i32 %48)
%50 = load float*, float** %6
store float* %50, float** %13
%51 = load float*, float** %7
store float* %51, float** %6
%52 = load float*, float** %13
store float* %52, float** %7
br label %53
53: ; preds = %43
%54 = load i32, i32* %9
%55 = add nsw i32 %54, 1
store i32 %55, i32* %9
br label %40
56: ; preds = %40
%57 = load float*, float** %6
%58 = call i32 @dump(float* %57)
%59 = load float*, float** %6
%60 = call i32 @free(float* %59)
%61 = load float*, float** %7
%62 = call i32 @free(float* %61)
ret i32 0
}

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