#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 */
struct tms {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ H2D(double *, double *, int, int);
double fabs(double);
int /*<<< orphan*/ horizontal_sum_cpu(double *, double *);
int /*<<< orphan*/ initialize_matrix(double *);
int /*<<< orphan*/ main_gpu(double *, double *, int, int);
double *matrix_alloc_cpu(int, int);
double *matrix_alloc_gpu(int, int);
int /*<<< orphan*/ printf(char *, ...);
int main() {
  double *a_cpu, *s_cpu, *s2_cpu;
  double *a_gpu, *s_gpu, max = -1.0, m;
  int i, j;
  struct tms buffer;
  a_cpu = matrix_alloc_cpu(400, 700);
  a_gpu = matrix_alloc_gpu(400, 700);
  s_cpu = matrix_alloc_cpu(400, 700);
  s2_cpu = matrix_alloc_cpu(400, 700);
  s_gpu = matrix_alloc_gpu(400, 700);
  initialize_matrix(a_cpu);
  horizontal_sum_cpu(a_cpu, s_cpu);
  H2D(a_gpu, a_cpu, 400, 700);
  main_gpu(s_gpu, a_gpu, 400, 700);
  for (j = 101; j < 101 + 5; j++) {
    for (i = 30; i < 30 + 5; i++) {
      printf("%.6g\t", s_cpu[i + j * 400]);
    }
    printf("\n");
  }
  printf("\n----\n\n");
  for (j = 101; j < 101 + 5; j++) {
    for (i = 30; i < 30 + 5; i++) {
      printf("%.6g\t", s2_cpu[i + j * 400]);
    }
    printf("\n");
  }
  for (j = 0; j < 700; j++) {
    for (i = 0; i < 400; i++) {
      m = fabs(s_cpu[i + j * 400] - s2_cpu[i + j * 400]);
      if (m > max)
        max = m;
    }
  }
  printf("Maximum difference = %g\n", max);
  if (max < 1e-11)
    printf("Test passed\n");
  else
    printf("Test failed\n");
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
movsd  0xe79(%rip),%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    $0x190,%edi
mov    $0x2bc,%esi
call   1090 <matrix_alloc_cpu@plt>
mov    %rax,-0x10(%rbp)
mov    $0x190,%edi
mov    $0x2bc,%esi
call   1060 <matrix_alloc_gpu@plt>
mov    %rax,-0x28(%rbp)
mov    $0x190,%edi
mov    $0x2bc,%esi
call   1090 <matrix_alloc_cpu@plt>
mov    %rax,-0x18(%rbp)
mov    $0x190,%edi
mov    $0x2bc,%esi
call   1090 <matrix_alloc_cpu@plt>
mov    %rax,-0x20(%rbp)
mov    $0x190,%edi
mov    $0x2bc,%esi
call   1060 <matrix_alloc_gpu@plt>
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
call   1080 <initialize_matrix@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <horizontal_sum_cpu@plt>
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    $0x190,%edx
mov    $0x2bc,%ecx
call   1070 <H2D@plt>
mov    -0x30(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    $0x190,%edx
mov    $0x2bc,%ecx
call   1040 <main_gpu@plt>
movl   $0x65,-0x48(%rbp)
cmpl   $0x6a,-0x48(%rbp)
jge    12a1 <main+0x131>
movl   $0x1e,-0x44(%rbp)
cmpl   $0x23,-0x44(%rbp)
jge    1285 <main+0x115>
mov    -0x18(%rbp),%rax
mov    -0x44(%rbp),%ecx
imul   $0x190,-0x48(%rbp),%edx
add    %edx,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
lea    0xdb0(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    1247 <main+0xd7>
lea    0xda0(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x48(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x48(%rbp)
jmp    1236 <main+0xc6>
lea    0xd7e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x65,-0x48(%rbp)
cmpl   $0x6a,-0x48(%rbp)
jge    1321 <main+0x1b1>
movl   $0x1e,-0x44(%rbp)
cmpl   $0x23,-0x44(%rbp)
jge    1305 <main+0x195>
mov    -0x20(%rbp),%rax
mov    -0x44(%rbp),%ecx
imul   $0x190,-0x48(%rbp),%edx
add    %edx,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
lea    0xd30(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    12c7 <main+0x157>
lea    0xd20(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x48(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x48(%rbp)
jmp    12b6 <main+0x146>
movl   $0x0,-0x48(%rbp)
cmpl   $0x2bc,-0x48(%rbp)
jge    13c9 <main+0x259>
movl   $0x0,-0x44(%rbp)
cmpl   $0x190,-0x44(%rbp)
jge    13b6 <main+0x246>
mov    -0x18(%rbp),%rax
mov    -0x44(%rbp),%ecx
imul   $0x190,-0x48(%rbp),%edx
add    %edx,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x20(%rbp),%rax
mov    -0x44(%rbp),%ecx
imul   $0x190,-0x48(%rbp),%edx
add    %edx,%ecx
movslq %ecx,%rcx
subsd  (%rax,%rcx,8),%xmm0
movaps 0xc90(%rip),%xmm1
pand   %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x40(%rbp),%xmm0
ucomisd -0x38(%rbp),%xmm0
jbe    13a3 <main+0x233>
movsd  -0x40(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
jmp    13a8 <main+0x238>
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    133c <main+0x1cc>
jmp    13bb <main+0x24b>
mov    -0x48(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x48(%rbp)
jmp    1328 <main+0x1b8>
movsd  -0x38(%rbp),%xmm0
lea    0xc59(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
movsd  0xc24(%rip),%xmm0
ucomisd -0x38(%rbp),%xmm0
jbe    1402 <main+0x292>
lea    0xc51(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1410 <main+0x2a0>
lea    0xc4b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    $0x190,%edi
mov    $0x2bc,%esi
call   10b0 <matrix_alloc_cpu@plt>
mov    %rax,%r12
mov    $0x190,%edi
mov    $0x2bc,%esi
call   1080 <matrix_alloc_gpu@plt>
mov    %rax,%r15
mov    $0x190,%edi
mov    $0x2bc,%esi
call   10b0 <matrix_alloc_cpu@plt>
mov    %rax,%r14
mov    $0x190,%edi
mov    $0x2bc,%esi
call   10b0 <matrix_alloc_cpu@plt>
mov    %rax,%rbx
mov    $0x190,%edi
mov    $0x2bc,%esi
call   1080 <matrix_alloc_gpu@plt>
mov    %rax,%r13
mov    %r12,%rdi
call   10a0 <initialize_matrix@plt>
mov    %r12,%rdi
mov    %r14,%rsi
call   1070 <horizontal_sum_cpu@plt>
mov    %r15,%rdi
mov    %r12,%rsi
mov    $0x190,%edx
mov    $0x2bc,%ecx
call   1090 <H2D@plt>
mov    %r13,%rdi
mov    %r15,%rsi
mov    $0x190,%edx
mov    $0x2bc,%ecx
call   1060 <main_gpu@plt>
movsd  0x4ef70(%r14),%xmm0
lea    0xddc(%rip),%r15
mov    %r15,%rdi
mov    $0x1,%al
call   1050 <printf@plt>
movsd  0x4ef78(%r14),%xmm0
mov    %r15,%rdi
mov    $0x1,%al
call   1050 <printf@plt>
movsd  0x4ef80(%r14),%xmm0
mov    %r15,%rdi
mov    $0x1,%al
call   1050 <printf@plt>
movsd  0x4ef88(%r14),%xmm0
mov    %r15,%rdi
mov    $0x1,%al
call   1050 <printf@plt>
movsd  0x4ef90(%r14),%xmm0
mov    %r15,%rdi
mov    $0x1,%al
call   1050 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
movsd  0x4fbf0(%r14),%xmm0
mov    %r15,%rdi
mov    $0x1,%al
call   1050 <printf@plt>
movsd  0x4fbf8(%r14),%xmm0
mov    %r15,%rdi
mov    $0x1,%al
call   1050 <printf@plt>
movsd  0x4fc00(%r14),%xmm0
mov    %r15,%rdi
mov    $0x1,%al
call   1050 <printf@plt>
movsd  0x4fc08(%r14),%xmm0
mov    %r15,%rdi
mov    $0x1,%al
call   1050 <printf@plt>
movsd  0x4fc10(%r14),%xmm0
mov    %r15,%rdi
mov    $0x1,%al
call   1050 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
movsd  0x50870(%r14),%xmm0
mov    %r15,%rdi
mov    $0x1,%al
call   1050 <printf@plt>
movsd  0x50878(%r14),%xmm0
mov    %r15,%rdi
mov    $0x1,%al
call   1050 <printf@plt>
movsd  0x50880(%r14),%xmm0
mov    %r15,%rdi
mov    $0x1,%al
call   1050 <printf@plt>
movsd  0x50888(%r14),%xmm0
mov    %r15,%rdi
mov    $0x1,%al
call   1050 <printf@plt>
movsd  0x50890(%r14),%xmm0
mov    %r15,%rdi
mov    $0x1,%al
call   1050 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
movsd  0x514f0(%r14),%xmm0
mov    %r15,%rdi
mov    $0x1,%al
call   1050 <printf@plt>
movsd  0x514f8(%r14),%xmm0
mov    %r15,%rdi
mov    $0x1,%al
call   1050 <printf@plt>
movsd  0x51500(%r14),%xmm0
mov    %r15,%rdi
mov    $0x1,%al
call   1050 <printf@plt>
movsd  0x51508(%r14),%xmm0
mov    %r15,%rdi
mov    $0x1,%al
call   1050 <printf@plt>
movsd  0x51510(%r14),%xmm0
mov    %r15,%rdi
mov    $0x1,%al
call   1050 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
movsd  0x52170(%r14),%xmm0
mov    %r15,%rdi
mov    $0x1,%al
call   1050 <printf@plt>
movsd  0x52178(%r14),%xmm0
mov    %r15,%rdi
mov    $0x1,%al
call   1050 <printf@plt>
movsd  0x52180(%r14),%xmm0
mov    %r15,%rdi
mov    $0x1,%al
call   1050 <printf@plt>
movsd  0x52188(%r14),%xmm0
mov    %r15,%rdi
mov    $0x1,%al
call   1050 <printf@plt>
movsd  0x52190(%r14),%xmm0
mov    %r15,%rdi
mov    $0x1,%al
call   1050 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
lea    0xbf0(%rip),%rdi
call   1040 <puts@plt>
movsd  0x4ef70(%rbx),%xmm0
mov    %r15,%rdi
mov    $0x1,%al
call   1050 <printf@plt>
movsd  0x4ef78(%rbx),%xmm0
mov    %r15,%rdi
mov    $0x1,%al
call   1050 <printf@plt>
movsd  0x4ef80(%rbx),%xmm0
mov    %r15,%rdi
mov    $0x1,%al
call   1050 <printf@plt>
movsd  0x4ef88(%rbx),%xmm0
mov    %r15,%rdi
mov    $0x1,%al
call   1050 <printf@plt>
movsd  0x4ef90(%rbx),%xmm0
mov    %r15,%rdi
mov    $0x1,%al
call   1050 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
movsd  0x4fbf0(%rbx),%xmm0
mov    %r15,%rdi
mov    $0x1,%al
call   1050 <printf@plt>
movsd  0x4fbf8(%rbx),%xmm0
mov    %r15,%rdi
mov    $0x1,%al
call   1050 <printf@plt>
movsd  0x4fc00(%rbx),%xmm0
mov    %r15,%rdi
mov    $0x1,%al
call   1050 <printf@plt>
movsd  0x4fc08(%rbx),%xmm0
mov    %r15,%rdi
mov    $0x1,%al
call   1050 <printf@plt>
movsd  0x4fc10(%rbx),%xmm0
mov    %r15,%rdi
mov    $0x1,%al
call   1050 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
movsd  0x50870(%rbx),%xmm0
mov    %r15,%rdi
mov    $0x1,%al
call   1050 <printf@plt>
movsd  0x50878(%rbx),%xmm0
mov    %r15,%rdi
mov    $0x1,%al
call   1050 <printf@plt>
movsd  0x50880(%rbx),%xmm0
mov    %r15,%rdi
mov    $0x1,%al
call   1050 <printf@plt>
movsd  0x50888(%rbx),%xmm0
mov    %r15,%rdi
mov    $0x1,%al
call   1050 <printf@plt>
movsd  0x50890(%rbx),%xmm0
mov    %r15,%rdi
mov    $0x1,%al
call   1050 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
movsd  0x514f0(%rbx),%xmm0
mov    %r15,%rdi
mov    $0x1,%al
call   1050 <printf@plt>
movsd  0x514f8(%rbx),%xmm0
mov    %r15,%rdi
mov    $0x1,%al
call   1050 <printf@plt>
movsd  0x51500(%rbx),%xmm0
mov    %r15,%rdi
mov    $0x1,%al
call   1050 <printf@plt>
movsd  0x51508(%rbx),%xmm0
mov    %r15,%rdi
mov    $0x1,%al
call   1050 <printf@plt>
movsd  0x51510(%rbx),%xmm0
mov    %r15,%rdi
mov    $0x1,%al
call   1050 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
movsd  0x52170(%rbx),%xmm0
mov    %r15,%rdi
mov    $0x1,%al
call   1050 <printf@plt>
movsd  0x52178(%rbx),%xmm0
mov    %r15,%rdi
mov    $0x1,%al
call   1050 <printf@plt>
movsd  0x52180(%rbx),%xmm0
mov    %r15,%rdi
mov    $0x1,%al
call   1050 <printf@plt>
movsd  0x52188(%rbx),%xmm0
mov    %r15,%rdi
mov    $0x1,%al
call   1050 <printf@plt>
movsd  0x52190(%rbx),%xmm0
mov    %r15,%rdi
mov    $0x1,%al
call   1050 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
add    $0x8,%rbx
add    $0x8,%r14
movsd  0x9a8(%rip),%xmm2
xor    %eax,%eax
movapd 0x9ae(%rip),%xmm0
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
xor    %ecx,%ecx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movsd  -0x8(%r14,%rcx,8),%xmm1
subsd  -0x8(%rbx,%rcx,8),%xmm1
andpd  %xmm0,%xmm1
maxsd  %xmm2,%xmm1
movsd  (%r14,%rcx,8),%xmm2
subsd  (%rbx,%rcx,8),%xmm2
andpd  %xmm0,%xmm2
maxsd  %xmm1,%xmm2
add    $0x2,%rcx
cmp    $0x190,%rcx
jne    1680 <main+0x4f0>
add    $0x1,%rax
add    $0xc80,%rbx
add    $0xc80,%r14
cmp    $0x2bc,%rax
jne    1670 <main+0x4e0>
lea    0x950(%rip),%rdi
movapd %xmm2,%xmm0
mov    $0x1,%al
movapd %xmm2,(%rsp)
call   1050 <printf@plt>
movsd  0x91a(%rip),%xmm0
ucomisd (%rsp),%xmm0
lea    0x958(%rip),%rax
lea    0x945(%rip),%rdi
cmova  %rax,%rdi
call   1040 <puts@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.tms = type { i32 }
@.str = [6 x i8] c"%.6g\09\00"
@.str.1 = [2 x i8] c"\0A\00"
@.str.2 = [8 x i8] c"\0A----\0A\0A\00"
@.str.3 = [25 x i8] c"Maximum difference = %g\0A\00"
@.str.4 = [13 x i8] c"Test passed\0A\00"
@.str.5 = [13 x i8] c"Test failed\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca double*
%3 = alloca double*
%4 = alloca double*
%5 = alloca double*
%6 = alloca double*
%7 = alloca double
%8 = alloca double
%9 = alloca i32
%10 = alloca i32
%11 = alloca %struct.tms
store i32 0, i32* %1
store double -1.000000e+00, double* %7
%12 = call double* @matrix_alloc_cpu(i32 400, i32 700)
store double* %12, double** %2
%13 = call double* @matrix_alloc_gpu(i32 400, i32 700)
store double* %13, double** %5
%14 = call double* @matrix_alloc_cpu(i32 400, i32 700)
store double* %14, double** %3
%15 = call double* @matrix_alloc_cpu(i32 400, i32 700)
store double* %15, double** %4
%16 = call double* @matrix_alloc_gpu(i32 400, i32 700)
store double* %16, double** %6
%17 = load double*, double** %2
%18 = call i32 @initialize_matrix(double* %17)
%19 = load double*, double** %2
%20 = load double*, double** %3
%21 = call i32 @horizontal_sum_cpu(double* %19, double* %20)
%22 = load double*, double** %5
%23 = load double*, double** %2
%24 = call i32 @H2D(double* %22, double* %23, i32 400, i32 700)
%25 = load double*, double** %6
%26 = load double*, double** %5
%27 = call i32 @main_gpu(double* %25, double* %26, i32 400, i32 700)
store i32 101, i32* %10
br label %28
28: ; preds = %50, %0
%29 = load i32, i32* %10
%30 = icmp slt i32 %29, 106
br i1 %30, label %31, label %53
31: ; preds = %28
store i32 30, i32* %9
br label %32
32: ; preds = %45, %31
%33 = load i32, i32* %9
%34 = icmp slt i32 %33, 35
br i1 %34, label %35, label %48
35: ; preds = %32
%36 = load double*, double** %3
%37 = load i32, i32* %9
%38 = load i32, i32* %10
%39 = mul nsw i32 %38, 400
%40 = add nsw i32 %37, %39
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds double, double* %36, i64 %41
%43 = load double, double* %42
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), double %43)
br label %45
45: ; preds = %35
%46 = load i32, i32* %9
%47 = add nsw i32 %46, 1
store i32 %47, i32* %9
br label %32
48: ; preds = %32
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %50
50: ; preds = %48
%51 = load i32, i32* %10
%52 = add nsw i32 %51, 1
store i32 %52, i32* %10
br label %28
53: ; preds = %28
%54 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
store i32 101, i32* %10
br label %55
55: ; preds = %77, %53
%56 = load i32, i32* %10
%57 = icmp slt i32 %56, 106
br i1 %57, label %58, label %80
58: ; preds = %55
store i32 30, i32* %9
br label %59
59: ; preds = %72, %58
%60 = load i32, i32* %9
%61 = icmp slt i32 %60, 35
br i1 %61, label %62, label %75
62: ; preds = %59
%63 = load double*, double** %4
%64 = load i32, i32* %9
%65 = load i32, i32* %10
%66 = mul nsw i32 %65, 400
%67 = add nsw i32 %64, %66
%68 = sext i32 %67 to i64
%69 = getelementptr inbounds double, double* %63, i64 %68
%70 = load double, double* %69
%71 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), double %70)
br label %72
72: ; preds = %62
%73 = load i32, i32* %9
%74 = add nsw i32 %73, 1
store i32 %74, i32* %9
br label %59
75: ; preds = %59
%76 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %77
77: ; preds = %75
%78 = load i32, i32* %10
%79 = add nsw i32 %78, 1
store i32 %79, i32* %10
br label %55
80: ; preds = %55
store i32 0, i32* %10
br label %81
81: ; preds = %117, %80
%82 = load i32, i32* %10
%83 = icmp slt i32 %82, 700
br i1 %83, label %84, label %120
84: ; preds = %81
store i32 0, i32* %9
br label %85
85: ; preds = %113, %84
%86 = load i32, i32* %9
%87 = icmp slt i32 %86, 400
br i1 %87, label %88, label %116
88: ; preds = %85
%89 = load double*, double** %3
%90 = load i32, i32* %9
%91 = load i32, i32* %10
%92 = mul nsw i32 %91, 400
%93 = add nsw i32 %90, %92
%94 = sext i32 %93 to i64
%95 = getelementptr inbounds double, double* %89, i64 %94
%96 = load double, double* %95
%97 = load double*, double** %4
%98 = load i32, i32* %9
%99 = load i32, i32* %10
%100 = mul nsw i32 %99, 400
%101 = add nsw i32 %98, %100
%102 = sext i32 %101 to i64
%103 = getelementptr inbounds double, double* %97, i64 %102
%104 = load double, double* %103
%105 = fsub double %96, %104
%106 = call double @llvm.fabs.f64(double %105)
store double %106, double* %8
%107 = load double, double* %8
%108 = load double, double* %7
%109 = fcmp ogt double %107, %108
br i1 %109, label %110, label %112
110: ; preds = %88
%111 = load double, double* %8
store double %111, double* %7
br label %112
112: ; preds = %110, %88
br label %113
113: ; preds = %112
%114 = load i32, i32* %9
%115 = add nsw i32 %114, 1
store i32 %115, i32* %9
br label %85
116: ; preds = %85
br label %117
117: ; preds = %116
%118 = load i32, i32* %10
%119 = add nsw i32 %118, 1
store i32 %119, i32* %10
br label %81
120: ; preds = %81
%121 = load double, double* %7
%122 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), double %121)
%123 = load double, double* %7
%124 = fcmp olt double %123, 0x3DA5FD7FE1796495
br i1 %124, label %125, label %127
125: ; preds = %120
%126 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0))
br label %129
127: ; preds = %120
%128 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0))
br label %129
129: ; preds = %127, %125
%130 = load i32, i32* %1
ret i32 %130
}

LLVM IR (-O2):
@.str = [6 x i8] c"%.6g\09\00"
@.str.3 = [25 x i8] c"Maximum difference = %g\0A\00"
@str = [7 x i8] c"\0A----\0A\00"
@str.6 = [12 x i8] c"Test failed\00"
@str.7 = [12 x i8] c"Test passed\00"
define i32 @main() {
%1 = tail call double* @matrix_alloc_cpu(i32 400, i32 700)
%2 = tail call double* @matrix_alloc_gpu(i32 400, i32 700)
%3 = tail call double* @matrix_alloc_cpu(i32 400, i32 700)
%4 = tail call double* @matrix_alloc_cpu(i32 400, i32 700)
%5 = tail call double* @matrix_alloc_gpu(i32 400, i32 700)
%6 = tail call i32 @initialize_matrix(double* %1)
%7 = tail call i32 @horizontal_sum_cpu(double* %1, double* %3)
%8 = tail call i32 @H2D(double* %2, double* %1, i32 400, i32 700)
%9 = tail call i32 @main_gpu(double* %5, double* %2, i32 400, i32 700)
%10 = getelementptr inbounds double, double* %3, i64 40430
%11 = load double, double* %10
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), double %11)
%13 = getelementptr inbounds double, double* %3, i64 40431
%14 = load double, double* %13
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), double %14)
%16 = getelementptr inbounds double, double* %3, i64 40432
%17 = load double, double* %16
%18 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), double %17)
%19 = getelementptr inbounds double, double* %3, i64 40433
%20 = load double, double* %19
%21 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), double %20)
%22 = getelementptr inbounds double, double* %3, i64 40434
%23 = load double, double* %22
%24 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), double %23)
%25 = tail call i32 @putchar(i32 10)
%26 = getelementptr inbounds double, double* %3, i64 40830
%27 = load double, double* %26
%28 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), double %27)
%29 = getelementptr inbounds double, double* %3, i64 40831
%30 = load double, double* %29
%31 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), double %30)
%32 = getelementptr inbounds double, double* %3, i64 40832
%33 = load double, double* %32
%34 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), double %33)
%35 = getelementptr inbounds double, double* %3, i64 40833
%36 = load double, double* %35
%37 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), double %36)
%38 = getelementptr inbounds double, double* %3, i64 40834
%39 = load double, double* %38
%40 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), double %39)
%41 = tail call i32 @putchar(i32 10)
%42 = getelementptr inbounds double, double* %3, i64 41230
%43 = load double, double* %42
%44 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), double %43)
%45 = getelementptr inbounds double, double* %3, i64 41231
%46 = load double, double* %45
%47 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), double %46)
%48 = getelementptr inbounds double, double* %3, i64 41232
%49 = load double, double* %48
%50 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), double %49)
%51 = getelementptr inbounds double, double* %3, i64 41233
%52 = load double, double* %51
%53 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), double %52)
%54 = getelementptr inbounds double, double* %3, i64 41234
%55 = load double, double* %54
%56 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), double %55)
%57 = tail call i32 @putchar(i32 10)
%58 = getelementptr inbounds double, double* %3, i64 41630
%59 = load double, double* %58
%60 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), double %59)
%61 = getelementptr inbounds double, double* %3, i64 41631
%62 = load double, double* %61
%63 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), double %62)
%64 = getelementptr inbounds double, double* %3, i64 41632
%65 = load double, double* %64
%66 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), double %65)
%67 = getelementptr inbounds double, double* %3, i64 41633
%68 = load double, double* %67
%69 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), double %68)
%70 = getelementptr inbounds double, double* %3, i64 41634
%71 = load double, double* %70
%72 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), double %71)
%73 = tail call i32 @putchar(i32 10)
%74 = getelementptr inbounds double, double* %3, i64 42030
%75 = load double, double* %74
%76 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), double %75)
%77 = getelementptr inbounds double, double* %3, i64 42031
%78 = load double, double* %77
%79 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), double %78)
%80 = getelementptr inbounds double, double* %3, i64 42032
%81 = load double, double* %80
%82 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), double %81)
%83 = getelementptr inbounds double, double* %3, i64 42033
%84 = load double, double* %83
%85 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), double %84)
%86 = getelementptr inbounds double, double* %3, i64 42034
%87 = load double, double* %86
%88 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), double %87)
%89 = tail call i32 @putchar(i32 10)
%90 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @str, i64 0, i64 0))
%91 = getelementptr inbounds double, double* %4, i64 40430
%92 = load double, double* %91
%93 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), double %92)
%94 = getelementptr inbounds double, double* %4, i64 40431
%95 = load double, double* %94
%96 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), double %95)
%97 = getelementptr inbounds double, double* %4, i64 40432
%98 = load double, double* %97
%99 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), double %98)
%100 = getelementptr inbounds double, double* %4, i64 40433
%101 = load double, double* %100
%102 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), double %101)
%103 = getelementptr inbounds double, double* %4, i64 40434
%104 = load double, double* %103
%105 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), double %104)
%106 = tail call i32 @putchar(i32 10)
%107 = getelementptr inbounds double, double* %4, i64 40830
%108 = load double, double* %107
%109 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), double %108)
%110 = getelementptr inbounds double, double* %4, i64 40831
%111 = load double, double* %110
%112 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), double %111)
%113 = getelementptr inbounds double, double* %4, i64 40832
%114 = load double, double* %113
%115 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), double %114)
%116 = getelementptr inbounds double, double* %4, i64 40833
%117 = load double, double* %116
%118 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), double %117)
%119 = getelementptr inbounds double, double* %4, i64 40834
%120 = load double, double* %119
%121 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), double %120)
%122 = tail call i32 @putchar(i32 10)
%123 = getelementptr inbounds double, double* %4, i64 41230
%124 = load double, double* %123
%125 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), double %124)
%126 = getelementptr inbounds double, double* %4, i64 41231
%127 = load double, double* %126
%128 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), double %127)
%129 = getelementptr inbounds double, double* %4, i64 41232
%130 = load double, double* %129
%131 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), double %130)
%132 = getelementptr inbounds double, double* %4, i64 41233
%133 = load double, double* %132
%134 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), double %133)
%135 = getelementptr inbounds double, double* %4, i64 41234
%136 = load double, double* %135
%137 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), double %136)
%138 = tail call i32 @putchar(i32 10)
%139 = getelementptr inbounds double, double* %4, i64 41630
%140 = load double, double* %139
%141 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), double %140)
%142 = getelementptr inbounds double, double* %4, i64 41631
%143 = load double, double* %142
%144 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), double %143)
%145 = getelementptr inbounds double, double* %4, i64 41632
%146 = load double, double* %145
%147 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), double %146)
%148 = getelementptr inbounds double, double* %4, i64 41633
%149 = load double, double* %148
%150 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), double %149)
%151 = getelementptr inbounds double, double* %4, i64 41634
%152 = load double, double* %151
%153 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), double %152)
%154 = tail call i32 @putchar(i32 10)
%155 = getelementptr inbounds double, double* %4, i64 42030
%156 = load double, double* %155
%157 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), double %156)
%158 = getelementptr inbounds double, double* %4, i64 42031
%159 = load double, double* %158
%160 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), double %159)
%161 = getelementptr inbounds double, double* %4, i64 42032
%162 = load double, double* %161
%163 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), double %162)
%164 = getelementptr inbounds double, double* %4, i64 42033
%165 = load double, double* %164
%166 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), double %165)
%167 = getelementptr inbounds double, double* %4, i64 42034
%168 = load double, double* %167
%169 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), double %168)
%170 = tail call i32 @putchar(i32 10)
br label %171
171: ; preds = %0, %199
%172 = phi i64 [ 0, %0 ], [ %200, %199 ]
%173 = phi double [ -1.000000e+00, %0 ], [ %196, %199 ]
%174 = mul nuw nsw i64 %172, 400
br label %175
175: ; preds = %175, %171
%176 = phi i64 [ 0, %171 ], [ %197, %175 ]
%177 = phi double [ %173, %171 ], [ %196, %175 ]
%178 = add nuw nsw i64 %176, %174
%179 = getelementptr inbounds double, double* %3, i64 %178
%180 = load double, double* %179
%181 = getelementptr inbounds double, double* %4, i64 %178
%182 = load double, double* %181
%183 = fsub double %180, %182
%184 = tail call double @llvm.fabs.f64(double %183)
%185 = fcmp ogt double %184, %177
%186 = select i1 %185, double %184, double %177
%187 = or i64 %176, 1
%188 = add nuw nsw i64 %187, %174
%189 = getelementptr inbounds double, double* %3, i64 %188
%190 = load double, double* %189
%191 = getelementptr inbounds double, double* %4, i64 %188
%192 = load double, double* %191
%193 = fsub double %190, %192
%194 = tail call double @llvm.fabs.f64(double %193)
%195 = fcmp ogt double %194, %186
%196 = select i1 %195, double %194, double %186
%197 = add nuw nsw i64 %176, 2
%198 = icmp eq i64 %197, 400
br i1 %198, label %199, label %175
199: ; preds = %175
%200 = add nuw nsw i64 %172, 1
%201 = icmp eq i64 %200, 700
br i1 %201, label %202, label %171
202: ; preds = %199
%203 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), double %196)
%204 = fcmp olt double %196, 0x3DA5FD7FE1796495
%205 = select i1 %204, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @str.7, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @str.6, i64 0, i64 0)
%206 = tail call i32 @puts(i8* dereferenceable(1) %205)
ret i32 0
}