#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 **allocMem(int, int);
double getMatrixValue(double **, double **, int, int, int);
double **matrixMultiply(double **A, double **B, int aX, int aY, int bY) {
  double **C = allocMem(aX, bY);
  for (int i = 0; i < aX; i++)
    for (int j = 0; j < bY; j++) {
      C[i][j] = getMatrixValue(A, B, aY, i, j);
    }
  return C;
}


x86 assembly (clang, -O0):
<matrixMultiply>:
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    %r8d,-0x1c(%rbp)
mov    -0x14(%rbp),%edi
mov    -0x1c(%rbp),%esi
call   1030 <allocMem@plt>
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11bc <matrixMultiply+0x9c>
movl   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    11a9 <matrixMultiply+0x89>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%edx
mov    -0x2c(%rbp),%ecx
mov    -0x30(%rbp),%r8d
call   1040 <getMatrixValue@plt>
mov    -0x28(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x30(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    1163 <matrixMultiply+0x43>
jmp    11ae <matrixMultiply+0x8e>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1150 <matrixMultiply+0x30>
mov    -0x28(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<matrixMultiply>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %ecx,0x4(%rsp)
mov    %edx,%ebp
mov    %rsi,0x18(%rsp)
mov    %rdi,0x10(%rsp)
mov    %edx,%edi
mov    %r8d,(%rsp)
mov    %r8d,%esi
call   1030 <allocMem@plt>
test   %ebp,%ebp
jle    11ce <matrixMultiply+0xae>
mov    %ebp,%ecx
mov    %rcx,0x8(%rsp)
mov    (%rsp),%r12d
xor    %r15d,%r15d
mov    %rax,0x20(%rsp)
mov    0x4(%rsp),%r13d
mov    0x18(%rsp),%rbx
mov    0x10(%rsp),%rbp
jmp    118b <matrixMultiply+0x6b>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
add    $0x1,%r15
cmp    0x8(%rsp),%r15
je     11ce <matrixMultiply+0xae>
cmpl   $0x0,(%rsp)
jle    1180 <matrixMultiply+0x60>
xor    %r14d,%r14d
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %rbp,%rdi
mov    %rbx,%rsi
mov    %r13d,%edx
mov    %r15d,%ecx
mov    %r14d,%r8d
call   1040 <getMatrixValue@plt>
mov    0x20(%rsp),%rax
mov    (%rax,%r15,8),%rdx
movsd  %xmm0,(%rdx,%r14,8)
add    $0x1,%r14
cmp    %r14,%r12
jne    11a0 <matrixMultiply+0x80>
jmp    1180 <matrixMultiply+0x60>
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define double** @matrixMultiply(double** %0, double** %1, i32 %2, i32 %3, i32 %4) {
%6 = tail call double** @allocMem(i32 %2, i32 %4)
%7 = icmp sgt i32 %2, 0
br i1 %7, label %8, label %17
8: ; preds = %5
%9 = icmp sgt i32 %4, 0
%10 = zext i32 %2 to i64
%11 = zext i32 %4 to i64
br label %12
12: ; preds = %8, %18
%13 = phi i64 [ 0, %8 ], [ %19, %18 ]
br i1 %9, label %14, label %18
14: ; preds = %12
%15 = getelementptr inbounds double*, double** %6, i64 %13
%16 = trunc i64 %13 to i32
br label %21
17: ; preds = %18, %5
ret double** %6
18: ; preds = %21, %12
%19 = add nuw nsw i64 %13, 1
%20 = icmp eq i64 %19, %10
br i1 %20, label %17, label %12
21: ; preds = %14, %21
%22 = phi i64 [ 0, %14 ], [ %27, %21 ]
%23 = trunc i64 %22 to i32
%24 = tail call double @getMatrixValue(double** %0, double** %1, i32 %3, i32 %16, i32 %23)
%25 = load double*, double** %15
%26 = getelementptr inbounds double, double* %25, i64 %22
store double %24, double* %26
%27 = add nuw nsw i64 %22, 1
%28 = icmp eq i64 %27, %11
br i1 %28, label %18, label %21
}