#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 */
double *calloc(int, int);
int add(double *A, double *B, int rows, int cols, double **sum) {
  *sum = calloc(rows * cols, sizeof(double));
  for (int i = 0; i < rows; i++) {
    for (int j = 0; j < cols; j++) {
      (*sum)[i * cols + j] = A[i * cols + j] + B[i * cols + j];
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<add>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    %r8,-0x20(%rbp)
mov    -0x14(%rbp),%edi
imul   -0x18(%rbp),%edi
mov    $0x8,%esi
call   1030 <calloc@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11d1 <add+0xc1>
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    11be <add+0xae>
mov    -0x8(%rbp),%rax
mov    -0x24(%rbp),%ecx
imul   -0x18(%rbp),%ecx
add    -0x28(%rbp),%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x10(%rbp),%rax
mov    -0x24(%rbp),%ecx
imul   -0x18(%rbp),%ecx
add    -0x28(%rbp),%ecx
movslq %ecx,%rcx
addsd  (%rax,%rcx,8),%xmm0
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
mov    -0x24(%rbp),%ecx
imul   -0x18(%rbp),%ecx
add    -0x28(%rbp),%ecx
movslq %ecx,%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    115f <add+0x4f>
jmp    11c3 <add+0xb3>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    114c <add+0x3c>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<add>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %r8,%rbx
mov    %ecx,%r12d
mov    %edx,%ebp
mov    %rsi,0x10(%rsp)
mov    %rdi,0x8(%rsp)
mov    %ecx,%edi
imul   %edx,%edi
mov    $0x8,%esi
call   1030 <calloc@plt>
mov    %rax,(%rsp)
mov    %rax,(%rbx)
test   %ebp,%ebp
jle    131f <add+0x20f>
movslq %r12d,%rdx
mov    %ebp,%r13d
mov    %edx,%esi
mov    %esi,%r11d
and    $0xfffffffc,%r11d
lea    -0x4(%r11),%rax
mov    %rax,0x30(%rsp)
mov    %rax,%rcx
shr    $0x2,%rcx
add    $0x1,%rcx
mov    %rcx,%rax
mov    %rcx,0x28(%rsp)
and    $0xfffffffffffffffe,%rcx
mov    %rcx,0x20(%rsp)
mov    (%rsp),%rax
mov    %rax,%rcx
add    $0x30,%rcx
mov    %rdx,0x18(%rsp)
lea    0x0(,%rdx,8),%rbp
mov    0x10(%rsp),%r14
lea    0x30(%r14),%rdi
mov    0x8(%rsp),%r15
lea    0x30(%r15),%rdx
xor    %r8d,%r8d
jmp    11df <add+0xcf>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
add    $0x1,%r8
add    %rbp,%rcx
add    %rbp,%rdi
add    %rbp,%rdx
add    %rbp,%r15
add    %rbp,%r14
add    %rbp,%rax
cmp    %r13,%r8
je     131f <add+0x20f>
test   %r12d,%r12d
jle    11c0 <add+0xb0>
cmp    $0x4,%r12d
jae    1200 <add+0xf0>
xor    %ebx,%ebx
jmp    12f0 <add+0x1e0>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
cmpq   $0x0,0x30(%rsp)
je     130f <add+0x1ff>
mov    0x20(%rsp),%r9
xor    %r10d,%r10d
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movupd -0x30(%rdx,%r10,8),%xmm0
movupd -0x20(%rdx,%r10,8),%xmm1
movupd -0x30(%rdi,%r10,8),%xmm2
addpd  %xmm0,%xmm2
movupd -0x20(%rdi,%r10,8),%xmm0
addpd  %xmm1,%xmm0
movupd %xmm2,-0x30(%rcx,%r10,8)
movupd %xmm0,-0x20(%rcx,%r10,8)
movupd -0x10(%rdx,%r10,8),%xmm0
movupd (%rdx,%r10,8),%xmm1
movupd -0x10(%rdi,%r10,8),%xmm2
addpd  %xmm0,%xmm2
movupd (%rdi,%r10,8),%xmm0
addpd  %xmm1,%xmm0
movupd %xmm2,-0x10(%rcx,%r10,8)
movupd %xmm0,(%rcx,%r10,8)
add    $0x8,%r10
add    $0xfffffffffffffffe,%r9
jne    1220 <add+0x110>
testb  $0x1,0x28(%rsp)
je     12db <add+0x1cb>
mov    %r8,%rbx
imul   0x18(%rsp),%rbx
add    %rbx,%r10
mov    0x8(%rsp),%rbx
movupd (%rbx,%r10,8),%xmm0
movupd 0x10(%rbx,%r10,8),%xmm1
mov    0x10(%rsp),%rbx
movupd (%rbx,%r10,8),%xmm2
addpd  %xmm0,%xmm2
movupd 0x10(%rbx,%r10,8),%xmm0
addpd  %xmm1,%xmm0
mov    (%rsp),%rbx
movupd %xmm2,(%rbx,%r10,8)
movupd %xmm0,0x10(%rbx,%r10,8)
mov    %r11,%rbx
cmp    %rsi,%r11
je     11c0 <add+0xb0>
nopw   0x0(%rax,%rax,1)
movsd  (%r15,%rbx,8),%xmm0
addsd  (%r14,%rbx,8),%xmm0
movsd  %xmm0,(%rax,%rbx,8)
add    $0x1,%rbx
cmp    %rbx,%rsi
jne    12f0 <add+0x1e0>
jmp    11c0 <add+0xb0>
xor    %r10d,%r10d
testb  $0x1,0x28(%rsp)
jne    1292 <add+0x182>
jmp    12db <add+0x1cb>
xor    %eax,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @add(double* nocapture %0, double* nocapture %1, i32 %2, i32 %3, double** nocapture %4) {
%6 = mul nsw i32 %3, %2
%7 = tail call double* @calloc(i32 %6, i32 8)
store double* %7, double** %4
%8 = icmp sgt i32 %2, 0
br i1 %8, label %9, label %100
9: ; preds = %5
%10 = icmp sgt i32 %3, 0
%11 = sext i32 %3 to i64
%12 = zext i32 %2 to i64
%13 = zext i32 %3 to i64
%14 = and i64 %13, 4294967292
%15 = add nsw i64 %14, -4
%16 = lshr exact i64 %15, 2
%17 = add nuw nsw i64 %16, 1
%18 = icmp ult i32 %3, 4
%19 = and i64 %13, 4294967292
%20 = and i64 %17, 1
%21 = icmp eq i64 %15, 0
%22 = and i64 %17, 9223372036854775806
%23 = icmp eq i64 %20, 0
%24 = icmp eq i64 %19, %13
br label %25
25: ; preds = %9, %101
%26 = phi i64 [ 0, %9 ], [ %102, %101 ]
br i1 %10, label %27, label %101
27: ; preds = %25
%28 = mul nsw i64 %26, %11
br i1 %18, label %98, label %29
29: ; preds = %27
br i1 %21, label %75, label %30
30: ; preds = %29, %30
%31 = phi i64 [ %72, %30 ], [ 0, %29 ]
%32 = phi i64 [ %73, %30 ], [ 0, %29 ]
%33 = add nsw i64 %31, %28
%34 = getelementptr inbounds double, double* %0, i64 %33
%35 = bitcast double* %34 to <2 x double>*
%36 = load <2 x double>, <2 x double>* %35
%37 = getelementptr inbounds double, double* %34, i64 2
%38 = bitcast double* %37 to <2 x double>*
%39 = load <2 x double>, <2 x double>* %38
%40 = getelementptr inbounds double, double* %1, i64 %33
%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 = fadd <2 x double> %36, %42
%47 = fadd <2 x double> %39, %45
%48 = getelementptr inbounds double, double* %7, i64 %33
%49 = bitcast double* %48 to <2 x double>*
store <2 x double> %46, <2 x double>* %49
%50 = getelementptr inbounds double, double* %48, i64 2
%51 = bitcast double* %50 to <2 x double>*
store <2 x double> %47, <2 x double>* %51
%52 = or i64 %31, 4
%53 = add nsw i64 %52, %28
%54 = getelementptr inbounds double, double* %0, i64 %53
%55 = bitcast double* %54 to <2 x double>*
%56 = load <2 x double>, <2 x double>* %55
%57 = getelementptr inbounds double, double* %54, i64 2
%58 = bitcast double* %57 to <2 x double>*
%59 = load <2 x double>, <2 x double>* %58
%60 = getelementptr inbounds double, double* %1, i64 %53
%61 = bitcast double* %60 to <2 x double>*
%62 = load <2 x double>, <2 x double>* %61
%63 = getelementptr inbounds double, double* %60, i64 2
%64 = bitcast double* %63 to <2 x double>*
%65 = load <2 x double>, <2 x double>* %64
%66 = fadd <2 x double> %56, %62
%67 = fadd <2 x double> %59, %65
%68 = getelementptr inbounds double, double* %7, i64 %53
%69 = bitcast double* %68 to <2 x double>*
store <2 x double> %66, <2 x double>* %69
%70 = getelementptr inbounds double, double* %68, i64 2
%71 = bitcast double* %70 to <2 x double>*
store <2 x double> %67, <2 x double>* %71
%72 = add nuw i64 %31, 8
%73 = add i64 %32, 2
%74 = icmp eq i64 %73, %22
br i1 %74, label %75, label %30
75: ; preds = %30, %29
%76 = phi i64 [ 0, %29 ], [ %72, %30 ]
br i1 %23, label %97, label %77
77: ; preds = %75
%78 = add nsw i64 %76, %28
%79 = getelementptr inbounds double, double* %0, i64 %78
%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* %1, i64 %78
%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 = getelementptr inbounds double, double* %7, i64 %78
%94 = bitcast double* %93 to <2 x double>*
store <2 x double> %91, <2 x double>* %94
%95 = getelementptr inbounds double, double* %93, i64 2
%96 = bitcast double* %95 to <2 x double>*
store <2 x double> %92, <2 x double>* %96
br label %97
97: ; preds = %75, %77
br i1 %24, label %101, label %98
98: ; preds = %27, %97
%99 = phi i64 [ 0, %27 ], [ %19, %97 ]
br label %104
100: ; preds = %101, %5
ret i32 0
101: ; preds = %104, %97, %25
%102 = add nuw nsw i64 %26, 1
%103 = icmp eq i64 %102, %12
br i1 %103, label %100, label %25
104: ; preds = %98, %104
%105 = phi i64 [ %113, %104 ], [ %99, %98 ]
%106 = add nsw i64 %105, %28
%107 = getelementptr inbounds double, double* %0, i64 %106
%108 = load double, double* %107
%109 = getelementptr inbounds double, double* %1, i64 %106
%110 = load double, double* %109
%111 = fadd double %108, %110
%112 = getelementptr inbounds double, double* %7, i64 %106
store double %111, double* %112
%113 = add nuw nsw i64 %105, 1
%114 = icmp eq i64 %113, %13
br i1 %114, label %101, label %104
}