#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*/ memset(double *, int /*<<< orphan*/, int);
void matrix_sum(double y[], double **X, int n, int m) {
  int i, j;
  memset(y, 0, n * sizeof(double));
  for (i = 0; i < n; ++i) {
    for (j = 0; j < m; ++j) {
      y[j] += X[i][j];
    }
  }
}


x86 assembly (clang, -O0):
<matrix_sum>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
movslq -0x14(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edx
xor    %esi,%esi
call   1030 <memset@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11a9 <matrix_sum+0x99>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    1196 <matrix_sum+0x86>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x20(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x8(%rbp),%rax
movslq -0x20(%rbp),%rcx
addsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1155 <matrix_sum+0x45>
jmp    119b <matrix_sum+0x8b>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1142 <matrix_sum+0x32>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<matrix_sum>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %ecx,%ebp
mov    %edx,%r15d
mov    %rsi,%r14
mov    %rdi,%rbx
lea    0x0(,%r15,8),%edx
xor    %esi,%esi
call   1030 <memset@plt>
test   %r15d,%r15d
jle    1309 <matrix_sum+0x1f9>
mov    %r15d,%r12d
mov    %ebp,%ecx
lea    (%rbx,%rcx,8),%r10
mov    %ecx,%r15d
and    $0xfffffffc,%r15d
lea    -0x4(%r15),%r8
mov    %r8,%r11
shr    $0x2,%r11
add    $0x1,%r11
mov    %r11,%rax
and    $0xfffffffffffffffe,%rax
mov    %rax,(%rsp)
mov    %ecx,%r9d
and    $0x3,%r9d
xor    %edi,%edi
jmp    118d <matrix_sum+0x7d>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
add    $0x1,%rdi
cmp    %r12,%rdi
je     1309 <matrix_sum+0x1f9>
test   %ebp,%ebp
jle    1180 <matrix_sum+0x70>
mov    (%r14,%rdi,8),%rsi
cmp    $0x4,%ebp
jb     11b0 <matrix_sum+0xa0>
lea    (%rsi,%rcx,8),%rax
cmp    %rbx,%rax
jbe    1243 <matrix_sum+0x133>
cmp    %r10,%rsi
jae    1243 <matrix_sum+0x133>
xor    %eax,%eax
mov    %rax,%rdx
not    %rdx
add    %rcx,%rdx
test   %r9,%r9
je     11e9 <matrix_sum+0xd9>
mov    %r9,%r13
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movsd  (%rsi,%rax,8),%xmm0
addsd  (%rbx,%rax,8),%xmm0
movsd  %xmm0,(%rbx,%rax,8)
add    $0x1,%rax
add    $0xffffffffffffffff,%r13
jne    11d0 <matrix_sum+0xc0>
cmp    $0x3,%rdx
jb     1180 <matrix_sum+0x70>
nop
movsd  (%rsi,%rax,8),%xmm0
addsd  (%rbx,%rax,8),%xmm0
movsd  %xmm0,(%rbx,%rax,8)
movsd  0x8(%rsi,%rax,8),%xmm0
addsd  0x8(%rbx,%rax,8),%xmm0
movsd  %xmm0,0x8(%rbx,%rax,8)
movsd  0x10(%rsi,%rax,8),%xmm0
addsd  0x10(%rbx,%rax,8),%xmm0
movsd  %xmm0,0x10(%rbx,%rax,8)
movsd  0x18(%rsi,%rax,8),%xmm0
addsd  0x18(%rbx,%rax,8),%xmm0
movsd  %xmm0,0x18(%rbx,%rax,8)
add    $0x4,%rax
cmp    %rax,%rcx
jne    11f0 <matrix_sum+0xe0>
jmp    1180 <matrix_sum+0x70>
test   %r8,%r8
je     12ff <matrix_sum+0x1ef>
mov    (%rsp),%rdx
xor    %eax,%eax
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movupd (%rsi,%rax,8),%xmm0
movupd 0x10(%rsi,%rax,8),%xmm1
movupd (%rbx,%rax,8),%xmm2
addpd  %xmm0,%xmm2
movupd 0x10(%rbx,%rax,8),%xmm0
addpd  %xmm1,%xmm0
movupd 0x20(%rbx,%rax,8),%xmm1
movupd 0x30(%rbx,%rax,8),%xmm3
movupd %xmm2,(%rbx,%rax,8)
movupd %xmm0,0x10(%rbx,%rax,8)
movupd 0x20(%rsi,%rax,8),%xmm0
addpd  %xmm1,%xmm0
movupd 0x30(%rsi,%rax,8),%xmm1
addpd  %xmm3,%xmm1
movupd %xmm0,0x20(%rbx,%rax,8)
movupd %xmm1,0x30(%rbx,%rax,8)
add    $0x8,%rax
add    $0xfffffffffffffffe,%rdx
jne    1260 <matrix_sum+0x150>
test   $0x1,%r11b
je     12ee <matrix_sum+0x1de>
movupd (%rsi,%rax,8),%xmm0
movupd 0x10(%rsi,%rax,8),%xmm1
movupd (%rbx,%rax,8),%xmm2
addpd  %xmm0,%xmm2
movupd 0x10(%rbx,%rax,8),%xmm0
addpd  %xmm1,%xmm0
movupd %xmm2,(%rbx,%rax,8)
movupd %xmm0,0x10(%rbx,%rax,8)
mov    %r15,%rax
cmp    %rcx,%r15
je     1180 <matrix_sum+0x70>
jmp    11b2 <matrix_sum+0xa2>
xor    %eax,%eax
test   $0x1,%r11b
jne    12c5 <matrix_sum+0x1b5>
jmp    12ee <matrix_sum+0x1de>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define void @matrix_sum(double* %0, double** nocapture %1, i32 %2, i32 %3) {
%5 = shl i32 %2, 3
%6 = tail call i32 @memset(double* %0, i32 0, i32 %5)
%7 = icmp sgt i32 %2, 0
br i1 %7, label %8, label %144
8: ; preds = %4
%9 = icmp sgt i32 %3, 0
%10 = zext i32 %2 to i64
%11 = zext i32 %3 to i64
%12 = getelementptr double, double* %0, i64 %11
%13 = and i64 %11, 4294967292
%14 = add nsw i64 %13, -4
%15 = lshr exact i64 %14, 2
%16 = add nuw nsw i64 %15, 1
%17 = icmp ult i32 %3, 4
%18 = and i64 %11, 4294967292
%19 = and i64 %16, 1
%20 = icmp eq i64 %14, 0
%21 = and i64 %16, 9223372036854775806
%22 = icmp eq i64 %19, 0
%23 = icmp eq i64 %18, %11
%24 = and i64 %11, 3
%25 = icmp eq i64 %24, 0
br label %26
26: ; preds = %8, %141
%27 = phi i64 [ 0, %8 ], [ %142, %141 ]
br i1 %9, label %28, label %141
28: ; preds = %26
%29 = getelementptr inbounds double*, double** %1, i64 %27
%30 = load double*, double** %29
br i1 %17, label %96, label %31
31: ; preds = %28
%32 = getelementptr double, double* %30, i64 %11
%33 = icmp ugt double* %32, %0
%34 = icmp ult double* %30, %12
%35 = and i1 %33, %34
br i1 %35, label %96, label %36
36: ; preds = %31
br i1 %20, label %76, label %37
37: ; preds = %36, %37
%38 = phi i64 [ %73, %37 ], [ 0, %36 ]
%39 = phi i64 [ %74, %37 ], [ 0, %36 ]
%40 = getelementptr inbounds double, double* %30, i64 %38
%41 = bitcast double* %40 to <2 x double>*
%42 = load <2 x double>, <2 x double>* %41
%43 = getelementptr inbounds double, double* %40, i64 2
%44 = bitcast double* %43 to <2 x double>*
%45 = load <2 x double>, <2 x double>* %44
%46 = getelementptr inbounds double, double* %0, i64 %38
%47 = bitcast double* %46 to <2 x double>*
%48 = load <2 x double>, <2 x double>* %47
%49 = getelementptr inbounds double, double* %46, i64 2
%50 = bitcast double* %49 to <2 x double>*
%51 = load <2 x double>, <2 x double>* %50
%52 = fadd <2 x double> %42, %48
%53 = fadd <2 x double> %45, %51
%54 = bitcast double* %46 to <2 x double>*
store <2 x double> %52, <2 x double>* %54
%55 = bitcast double* %49 to <2 x double>*
store <2 x double> %53, <2 x double>* %55
%56 = or i64 %38, 4
%57 = getelementptr inbounds double, double* %30, i64 %56
%58 = bitcast double* %57 to <2 x double>*
%59 = load <2 x double>, <2 x double>* %58
%60 = getelementptr inbounds double, double* %57, i64 2
%61 = bitcast double* %60 to <2 x double>*
%62 = load <2 x double>, <2 x double>* %61
%63 = getelementptr inbounds double, double* %0, i64 %56
%64 = bitcast double* %63 to <2 x double>*
%65 = load <2 x double>, <2 x double>* %64
%66 = getelementptr inbounds double, double* %63, i64 2
%67 = bitcast double* %66 to <2 x double>*
%68 = load <2 x double>, <2 x double>* %67
%69 = fadd <2 x double> %59, %65
%70 = fadd <2 x double> %62, %68
%71 = bitcast double* %63 to <2 x double>*
store <2 x double> %69, <2 x double>* %71
%72 = bitcast double* %66 to <2 x double>*
store <2 x double> %70, <2 x double>* %72
%73 = add nuw i64 %38, 8
%74 = add i64 %39, 2
%75 = icmp eq i64 %74, %21
br i1 %75, label %76, label %37
76: ; preds = %37, %36
%77 = phi i64 [ 0, %36 ], [ %73, %37 ]
br i1 %22, label %95, label %78
78: ; preds = %76
%79 = getelementptr inbounds double, double* %30, i64 %77
%80 = bitcast double* %79 to <2 x double>*
%81 = load <2 x double>, <2 x double>* %80
%82 = getelementptr inbounds double, double* %79, i64 2
%83 = bitcast double* %82 to <2 x double>*
%84 = load <2 x double>, <2 x double>* %83
%85 = getelementptr inbounds double, double* %0, i64 %77
%86 = bitcast double* %85 to <2 x double>*
%87 = load <2 x double>, <2 x double>* %86
%88 = getelementptr inbounds double, double* %85, i64 2
%89 = bitcast double* %88 to <2 x double>*
%90 = load <2 x double>, <2 x double>* %89
%91 = fadd <2 x double> %81, %87
%92 = fadd <2 x double> %84, %90
%93 = bitcast double* %85 to <2 x double>*
store <2 x double> %91, <2 x double>* %93
%94 = bitcast double* %88 to <2 x double>*
store <2 x double> %92, <2 x double>* %94
br label %95
95: ; preds = %76, %78
br i1 %23, label %141, label %96
96: ; preds = %31, %28, %95
%97 = phi i64 [ 0, %31 ], [ 0, %28 ], [ %18, %95 ]
%98 = xor i64 %97, -1
%99 = add nsw i64 %98, %11
br i1 %25, label %111, label %100
100: ; preds = %96, %100
%101 = phi i64 [ %108, %100 ], [ %97, %96 ]
%102 = phi i64 [ %109, %100 ], [ 0, %96 ]
%103 = getelementptr inbounds double, double* %30, i64 %101
%104 = load double, double* %103
%105 = getelementptr inbounds double, double* %0, i64 %101
%106 = load double, double* %105
%107 = fadd double %104, %106
store double %107, double* %105
%108 = add nuw nsw i64 %101, 1
%109 = add i64 %102, 1
%110 = icmp eq i64 %109, %24
br i1 %110, label %111, label %100
111: ; preds = %100, %96
%112 = phi i64 [ %97, %96 ], [ %108, %100 ]
%113 = icmp ult i64 %99, 3
br i1 %113, label %141, label %114
114: ; preds = %111, %114
%115 = phi i64 [ %139, %114 ], [ %112, %111 ]
%116 = getelementptr inbounds double, double* %30, i64 %115
%117 = load double, double* %116
%118 = getelementptr inbounds double, double* %0, i64 %115
%119 = load double, double* %118
%120 = fadd double %117, %119
store double %120, double* %118
%121 = add nuw nsw i64 %115, 1
%122 = getelementptr inbounds double, double* %30, i64 %121
%123 = load double, double* %122
%124 = getelementptr inbounds double, double* %0, i64 %121
%125 = load double, double* %124
%126 = fadd double %123, %125
store double %126, double* %124
%127 = add nuw nsw i64 %115, 2
%128 = getelementptr inbounds double, double* %30, i64 %127
%129 = load double, double* %128
%130 = getelementptr inbounds double, double* %0, i64 %127
%131 = load double, double* %130
%132 = fadd double %129, %131
store double %132, double* %130
%133 = add nuw nsw i64 %115, 3
%134 = getelementptr inbounds double, double* %30, i64 %133
%135 = load double, double* %134
%136 = getelementptr inbounds double, double* %0, i64 %133
%137 = load double, double* %136
%138 = fadd double %135, %137
store double %138, double* %136
%139 = add nuw nsw i64 %115, 4
%140 = icmp eq i64 %139, %11
br i1 %140, label %141, label %114
141: ; preds = %111, %114, %95, %26
%142 = add nuw nsw i64 %27, 1
%143 = icmp eq i64 %142, %10
br i1 %143, label %144, label %26
144: ; preds = %141, %4
ret void
}