#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*/ AddOnGpu(float *, float *, float *, int, int);
int /*<<< orphan*/ Init(float *, int, int);
float fabs(float);
int /*<<< orphan*/ free(float *);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *);
int main() {
  int i = 0, error = 0, nx = 200, ny = 100;
  float diff;
  float *mat_in1 = (float *)malloc(nx * ny * sizeof(float));
  float *mat_in2 = (float *)malloc(nx * ny * sizeof(float));
  float *mat_out = (float *)malloc(nx * ny * sizeof(float));
  Init(mat_in1, nx, ny);
  Init(mat_in2, nx, ny);
  AddOnGpu(mat_out, mat_in1, mat_in2, nx, ny);
  for (i = 0; i < nx * ny; i++) {
    diff = mat_out[i] - (mat_in1[i] + mat_in2[i]);
    if (fabs(diff) > 0.0000001f) {
      error = 1;
    }
  }
  if (error) {
    printf("FAILED\n");
  } else {
    printf("PASSED\n");
  }
  free(mat_in1);
  free(mat_in2);
  free(mat_out);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0xc8,-0x10(%rbp)
movl   $0x64,-0x14(%rbp)
mov    -0x10(%rbp),%eax
imul   -0x14(%rbp),%eax
cltq
shl    $0x2,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%eax
imul   -0x14(%rbp),%eax
cltq
shl    $0x2,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%eax
imul   -0x14(%rbp),%eax
cltq
shl    $0x2,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%esi
mov    -0x14(%rbp),%edx
call   1080 <Init@plt>
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%esi
mov    -0x14(%rbp),%edx
call   1080 <Init@plt>
mov    -0x30(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x28(%rbp),%rdx
mov    -0x10(%rbp),%ecx
mov    -0x14(%rbp),%r8d
call   1070 <AddOnGpu@plt>
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    -0x10(%rbp),%ecx
imul   -0x14(%rbp),%ecx
cmp    %ecx,%eax
jge    1287 <main+0x127>
mov    -0x30(%rbp),%rax
movslq -0x8(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm0
mov    -0x20(%rbp),%rax
movslq -0x8(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm1
mov    -0x28(%rbp),%rax
movslq -0x8(%rbp),%rcx
addss  (%rax,%rcx,4),%xmm1
subss  %xmm1,%xmm0
movss  %xmm0,-0x18(%rbp)
movss  -0x18(%rbp),%xmm0
call   1050 <fabs@plt>
movss  0xd9c(%rip),%xmm1
ucomiss %xmm1,%xmm0
jbe    1274 <main+0x114>
movl   $0x1,-0xc(%rbp)
jmp    1279 <main+0x119>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1210 <main+0xb0>
cmpl   $0x0,-0xc(%rbp)
je     12a2 <main+0x142>
lea    0xd6c(%rip),%rdi
call   1040 <printf@plt>
jmp    12ae <main+0x14e>
lea    0xd63(%rip),%rdi
call   1040 <printf@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
mov    $0x13880,%edi
call   1050 <malloc@plt>
mov    %rax,%r14
mov    $0x13880,%edi
call   1050 <malloc@plt>
mov    %rax,%r15
mov    $0x13880,%edi
call   1050 <malloc@plt>
mov    %rax,%rbx
mov    %r14,%rdi
mov    $0xc8,%esi
mov    $0x64,%edx
call   1070 <Init@plt>
mov    %r15,%rdi
mov    $0xc8,%esi
mov    $0x64,%edx
call   1070 <Init@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
mov    $0xc8,%ecx
mov    $0x64,%r8d
call   1060 <AddOnGpu@plt>
xorps  %xmm0,%xmm0
mov    $0x4,%eax
movaps 0xe37(%rip),%xmm8
movaps 0xe40(%rip),%xmm3
xorps  %xmm1,%xmm1
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movups -0x10(%rbx,%rax,4),%xmm4
movups (%rbx,%rax,4),%xmm5
movups -0x10(%r14,%rax,4),%xmm6
movups (%r14,%rax,4),%xmm7
movups -0x10(%r15,%rax,4),%xmm2
addps  %xmm6,%xmm2
subps  %xmm2,%xmm4
movups (%r15,%rax,4),%xmm2
addps  %xmm7,%xmm2
subps  %xmm2,%xmm5
andps  %xmm8,%xmm4
andps  %xmm8,%xmm5
movaps %xmm3,%xmm2
cmpltps %xmm4,%xmm2
movaps %xmm3,%xmm4
cmpltps %xmm5,%xmm4
movaps %xmm2,%xmm5
andnps %xmm0,%xmm5
movaps %xmm5,%xmm0
psubd  %xmm2,%xmm0
movaps %xmm4,%xmm2
andnps %xmm1,%xmm2
movaps %xmm2,%xmm1
psubd  %xmm4,%xmm1
add    $0x8,%rax
cmp    $0x4e24,%rax
jne    11e0 <main+0x90>
xorps  %xmm2,%xmm2
movaps %xmm0,%xmm3
pcmpeqd %xmm2,%xmm3
andps  %xmm3,%xmm1
andnps %xmm0,%xmm3
orps   %xmm1,%xmm3
pcmpeqd %xmm2,%xmm3
movmskps %xmm3,%eax
cmp    $0xf,%eax
lea    0xdb5(%rip),%rax
lea    0xdb5(%rip),%rdi
cmove  %rax,%rdi
call   1040 <puts@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    %r15,%rdi
call   1030 <free@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [8 x i8] c"FAILED\0A\00"
@.str.1 = [8 x i8] c"PASSED\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca float
%7 = alloca float*
%8 = alloca float*
%9 = alloca float*
store i32 0, i32* %1
store i32 0, i32* %2
store i32 0, i32* %3
store i32 200, i32* %4
store i32 100, i32* %5
%10 = load i32, i32* %4
%11 = load i32, i32* %5
%12 = mul nsw i32 %10, %11
%13 = sext i32 %12 to i64
%14 = mul i64 %13, 4
%15 = trunc i64 %14 to i32
%16 = call i64 @malloc(i32 %15)
%17 = inttoptr i64 %16 to float*
store float* %17, float** %7
%18 = load i32, i32* %4
%19 = load i32, i32* %5
%20 = mul nsw i32 %18, %19
%21 = sext i32 %20 to i64
%22 = mul i64 %21, 4
%23 = trunc i64 %22 to i32
%24 = call i64 @malloc(i32 %23)
%25 = inttoptr i64 %24 to float*
store float* %25, float** %8
%26 = load i32, i32* %4
%27 = load i32, i32* %5
%28 = mul nsw i32 %26, %27
%29 = sext i32 %28 to i64
%30 = mul i64 %29, 4
%31 = trunc i64 %30 to i32
%32 = call i64 @malloc(i32 %31)
%33 = inttoptr i64 %32 to float*
store float* %33, float** %9
%34 = load float*, float** %7
%35 = load i32, i32* %4
%36 = load i32, i32* %5
%37 = call i32 @Init(float* %34, i32 %35, i32 %36)
%38 = load float*, float** %8
%39 = load i32, i32* %4
%40 = load i32, i32* %5
%41 = call i32 @Init(float* %38, i32 %39, i32 %40)
%42 = load float*, float** %9
%43 = load float*, float** %7
%44 = load float*, float** %8
%45 = load i32, i32* %4
%46 = load i32, i32* %5
%47 = call i32 @AddOnGpu(float* %42, float* %43, float* %44, i32 %45, i32 %46)
store i32 0, i32* %2
br label %48
48: ; preds = %77, %0
%49 = load i32, i32* %2
%50 = load i32, i32* %4
%51 = load i32, i32* %5
%52 = mul nsw i32 %50, %51
%53 = icmp slt i32 %49, %52
br i1 %53, label %54, label %80
54: ; preds = %48
%55 = load float*, float** %9
%56 = load i32, i32* %2
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds float, float* %55, i64 %57
%59 = load float, float* %58
%60 = load float*, float** %7
%61 = load i32, i32* %2
%62 = sext i32 %61 to i64
%63 = getelementptr inbounds float, float* %60, i64 %62
%64 = load float, float* %63
%65 = load float*, float** %8
%66 = load i32, i32* %2
%67 = sext i32 %66 to i64
%68 = getelementptr inbounds float, float* %65, i64 %67
%69 = load float, float* %68
%70 = fadd float %64, %69
%71 = fsub float %59, %70
store float %71, float* %6
%72 = load float, float* %6
%73 = call float @fabs(float %72)
%74 = fcmp ogt float %73, 0x3E7AD7F2A0000000
br i1 %74, label %75, label %76
75: ; preds = %54
store i32 1, i32* %3
br label %76
76: ; preds = %75, %54
br label %77
77: ; preds = %76
%78 = load i32, i32* %2
%79 = add nsw i32 %78, 1
store i32 %79, i32* %2
br label %48
80: ; preds = %48
%81 = load i32, i32* %3
%82 = icmp ne i32 %81, 0
br i1 %82, label %83, label %85
83: ; preds = %80
%84 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
br label %87
85: ; preds = %80
%86 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
br label %87
87: ; preds = %85, %83
%88 = load float*, float** %7
%89 = call i32 @free(float* %88)
%90 = load float*, float** %8
%91 = call i32 @free(float* %90)
%92 = load float*, float** %9
%93 = call i32 @free(float* %92)
%94 = load i32, i32* %1
ret i32 %94
}

LLVM IR (-O2):
@str = [7 x i8] c"PASSED\00"
@str.2 = [7 x i8] c"FAILED\00"
define i32 @main() {
%1 = tail call i64 @malloc(i32 80000)
%2 = inttoptr i64 %1 to float*
%3 = tail call i64 @malloc(i32 80000)
%4 = inttoptr i64 %3 to float*
%5 = tail call i64 @malloc(i32 80000)
%6 = inttoptr i64 %5 to float*
%7 = tail call i32 @Init(float* %2, i32 200, i32 100)
%8 = tail call i32 @Init(float* %4, i32 200, i32 100)
%9 = tail call i32 @AddOnGpu(float* %6, float* %2, float* %4, i32 200, i32 100)
br label %10
10: ; preds = %10, %0
%11 = phi i64 [ 0, %0 ], [ %42, %10 ]
%12 = phi <4 x i32> [ zeroinitializer, %0 ], [ %40, %10 ]
%13 = phi <4 x i32> [ zeroinitializer, %0 ], [ %41, %10 ]
%14 = getelementptr inbounds float, float* %6, i64 %11
%15 = bitcast float* %14 to <4 x float>*
%16 = load <4 x float>, <4 x float>* %15
%17 = getelementptr inbounds float, float* %14, i64 4
%18 = bitcast float* %17 to <4 x float>*
%19 = load <4 x float>, <4 x float>* %18
%20 = getelementptr inbounds float, float* %2, i64 %11
%21 = bitcast float* %20 to <4 x float>*
%22 = load <4 x float>, <4 x float>* %21
%23 = getelementptr inbounds float, float* %20, i64 4
%24 = bitcast float* %23 to <4 x float>*
%25 = load <4 x float>, <4 x float>* %24
%26 = getelementptr inbounds float, float* %4, i64 %11
%27 = bitcast float* %26 to <4 x float>*
%28 = load <4 x float>, <4 x float>* %27
%29 = getelementptr inbounds float, float* %26, i64 4
%30 = bitcast float* %29 to <4 x float>*
%31 = load <4 x float>, <4 x float>* %30
%32 = fadd <4 x float> %22, %28
%33 = fadd <4 x float> %25, %31
%34 = fsub <4 x float> %16, %32
%35 = fsub <4 x float> %19, %33
%36 = call <4 x float> @llvm.fabs.v4f32(<4 x float> %34)
%37 = call <4 x float> @llvm.fabs.v4f32(<4 x float> %35)
%38 = fcmp ogt <4 x float> %36, <float 0x3E7AD7F2A0000000, float 0x3E7AD7F2A0000000, float 0x3E7AD7F2A0000000, float 0x3E7AD7F2A0000000>
%39 = fcmp ogt <4 x float> %37, <float 0x3E7AD7F2A0000000, float 0x3E7AD7F2A0000000, float 0x3E7AD7F2A0000000, float 0x3E7AD7F2A0000000>
%40 = select <4 x i1> %38, <4 x i32> <i32 1, i32 1, i32 1, i32 1>, <4 x i32> %12
%41 = select <4 x i1> %39, <4 x i32> <i32 1, i32 1, i32 1, i32 1>, <4 x i32> %13
%42 = add nuw i64 %11, 8
%43 = icmp eq i64 %42, 20000
br i1 %43, label %44, label %10
44: ; preds = %10
%45 = icmp eq <4 x i32> %40, zeroinitializer
%46 = select <4 x i1> %45, <4 x i32> %41, <4 x i32> %40
%47 = icmp ne <4 x i32> %46, zeroinitializer
%48 = bitcast <4 x i1> %47 to i4
%49 = icmp eq i4 %48, 0
%50 = select i1 %49, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @str, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @str.2, i64 0, i64 0)
%51 = tail call i32 @puts(i8* dereferenceable(1) %50)
%52 = tail call i32 @free(float* %2)
%53 = tail call i32 @free(float* %4)
%54 = tail call i32 @free(float* %6)
ret i32 0
}