#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 *alloc_array(int, int);
size_t map(int, int, int, char);
double *mm(double *A, int arows, int acols, char transA, double *B, int brows,
           int bcols, char transB) {
  double *C = alloc_array(arows, bcols);
  double sum;
  int i;
  int j;
  int k;
  for (i = 0; i < arows; i++) {
    for (j = 0; j < brows; j++) {
      sum = 0;
      for (k = 0; k < bcols; k++) {
        sum = sum + A[map(i, k, acols, transA)] * B[map(k, j, bcols, transB)];
      }
      C[map(i, j, bcols, 'n')] = sum;
    }
  }
  return C;
}


x86 assembly (clang, -O0):
<mm>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %cl,%al
mov    0x18(%rbp),%cl
mov    0x10(%rbp),%ecx
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %al,-0x11(%rbp)
mov    %r8,-0x20(%rbp)
mov    %r9d,-0x24(%rbp)
mov    -0xc(%rbp),%edi
mov    0x10(%rbp),%esi
call   1030 <alloc_array@plt>
mov    %rax,-0x30(%rbp)
movl   $0x0,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    126f <mm+0x14f>
movl   $0x0,-0x40(%rbp)
mov    -0x40(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    125c <mm+0x13c>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x38(%rbp)
movl   $0x0,-0x44(%rbp)
mov    -0x44(%rbp),%eax
cmp    0x10(%rbp),%eax
jge    1218 <mm+0xf8>
movsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x58(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x68(%rbp)
mov    -0x3c(%rbp),%edi
mov    -0x44(%rbp),%esi
mov    -0x10(%rbp),%edx
movsbl -0x11(%rbp),%ecx
call   1040 <map@plt>
mov    %rax,%rcx
mov    -0x68(%rbp),%rax
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x60(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x44(%rbp),%edi
mov    -0x40(%rbp),%esi
mov    0x10(%rbp),%edx
movsbl 0x18(%rbp),%ecx
call   1040 <map@plt>
movsd  -0x60(%rbp),%xmm0
movsd  -0x58(%rbp),%xmm1
mov    %rax,%rcx
mov    -0x50(%rbp),%rax
movsd  (%rax,%rcx,8),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    118c <mm+0x6c>
movsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x78(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x70(%rbp)
mov    -0x3c(%rbp),%edi
mov    -0x40(%rbp),%esi
mov    0x10(%rbp),%edx
mov    $0x6e,%ecx
call   1040 <map@plt>
movsd  -0x78(%rbp),%xmm0
mov    %rax,%rcx
mov    -0x70(%rbp),%rax
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x40(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x40(%rbp)
jmp    1171 <mm+0x51>
jmp    1261 <mm+0x141>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    115e <mm+0x3e>
mov    -0x30(%rbp),%rax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mm>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
mov    %r9d,0xc(%rsp)
mov    %r8,0x38(%rsp)
mov    %ecx,%r15d
mov    %edx,%ebp
mov    %esi,%ebx
mov    %rdi,0x30(%rsp)
mov    0x80(%rsp),%r12d
mov    %esi,%edi
mov    %r12d,%esi
call   1030 <alloc_array@plt>
mov    %rax,0x28(%rsp)
mov    %ebx,0x18(%rsp)
test   %ebx,%ebx
jle    1258 <mm+0x138>
xor    %r13d,%r13d
movsbl %r15b,%edx
movsbl 0x88(%rsp),%ecx
mov    %ebp,0x24(%rsp)
mov    %edx,0x20(%rsp)
mov    %ecx,0x1c(%rsp)
mov    0x38(%rsp),%rbp
mov    0x30(%rsp),%r14
jmp    119f <mm+0x7f>
xchg   %ax,%ax
add    $0x1,%r13d
cmp    0x18(%rsp),%r13d
je     1258 <mm+0x138>
cmpl   $0x0,0xc(%rsp)
jle    1190 <mm+0x70>
xor    %r15d,%r15d
jmp    11e4 <mm+0xc4>
nopl   0x0(%rax,%rax,1)
movsd  %xmm0,0x10(%rsp)
mov    %r13d,%edi
mov    %r15d,%esi
mov    %r12d,%edx
mov    $0x6e,%ecx
call   1040 <map@plt>
mov    0x28(%rsp),%rcx
movsd  0x10(%rsp),%xmm0
movsd  %xmm0,(%rcx,%rax,8)
add    $0x1,%r15d
cmp    0xc(%rsp),%r15d
je     1190 <mm+0x70>
xorpd  %xmm0,%xmm0
test   %r12d,%r12d
jle    11b0 <mm+0x90>
movsd  %xmm0,0x10(%rsp)
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r13d,%edi
mov    %ebx,%esi
mov    0x24(%rsp),%edx
mov    0x20(%rsp),%ecx
call   1040 <map@plt>
movsd  (%r14,%rax,8),%xmm0
movsd  %xmm0,0x40(%rsp)
mov    %ebx,%edi
mov    %r15d,%esi
mov    %r12d,%edx
mov    0x1c(%rsp),%ecx
call   1040 <map@plt>
movsd  0x40(%rsp),%xmm1
mulsd  0x0(%rbp,%rax,8),%xmm1
movsd  0x10(%rsp),%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,0x10(%rsp)
add    $0x1,%ebx
cmp    %ebx,%r12d
jne    1200 <mm+0xe0>
jmp    11b6 <mm+0x96>
mov    0x28(%rsp),%rax
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define double* @mm(double* %0, i32 %1, i32 %2, i8 signext %3, double* %4, i32 %5, i32 %6, i8 signext %7) {
%9 = alloca double*
%10 = alloca i32
%11 = alloca i32
%12 = alloca i8
%13 = alloca double*
%14 = alloca i32
%15 = alloca i32
%16 = alloca i8
%17 = alloca double*
%18 = alloca double
%19 = alloca i32
%20 = alloca i32
%21 = alloca i32
store double* %0, double** %9
store i32 %1, i32* %10
store i32 %2, i32* %11
store i8 %3, i8* %12
store double* %4, double** %13
store i32 %5, i32* %14
store i32 %6, i32* %15
store i8 %7, i8* %16
%22 = load i32, i32* %10
%23 = load i32, i32* %15
%24 = call double* @alloc_array(i32 %22, i32 %23)
store double* %24, double** %17
store i32 0, i32* %19
br label %25
25: ; preds = %73, %8
%26 = load i32, i32* %19
%27 = load i32, i32* %10
%28 = icmp slt i32 %26, %27
br i1 %28, label %29, label %76
29: ; preds = %25
store i32 0, i32* %20
br label %30
30: ; preds = %69, %29
%31 = load i32, i32* %20
%32 = load i32, i32* %14
%33 = icmp slt i32 %31, %32
br i1 %33, label %34, label %72
34: ; preds = %30
store double 0.000000e+00, double* %18
store i32 0, i32* %21
br label %35
35: ; preds = %58, %34
%36 = load i32, i32* %21
%37 = load i32, i32* %15
%38 = icmp slt i32 %36, %37
br i1 %38, label %39, label %61
39: ; preds = %35
%40 = load double, double* %18
%41 = load double*, double** %9
%42 = load i32, i32* %19
%43 = load i32, i32* %21
%44 = load i32, i32* %11
%45 = load i8, i8* %12
%46 = call i64 @map(i32 %42, i32 %43, i32 %44, i8 signext %45)
%47 = getelementptr inbounds double, double* %41, i64 %46
%48 = load double, double* %47
%49 = load double*, double** %13
%50 = load i32, i32* %21
%51 = load i32, i32* %20
%52 = load i32, i32* %15
%53 = load i8, i8* %16
%54 = call i64 @map(i32 %50, i32 %51, i32 %52, i8 signext %53)
%55 = getelementptr inbounds double, double* %49, i64 %54
%56 = load double, double* %55
%57 = call double @llvm.fmuladd.f64(double %48, double %56, double %40)
store double %57, double* %18
br label %58
58: ; preds = %39
%59 = load i32, i32* %21
%60 = add nsw i32 %59, 1
store i32 %60, i32* %21
br label %35
61: ; preds = %35
%62 = load double, double* %18
%63 = load double*, double** %17
%64 = load i32, i32* %19
%65 = load i32, i32* %20
%66 = load i32, i32* %15
%67 = call i64 @map(i32 %64, i32 %65, i32 %66, i8 signext 110)
%68 = getelementptr inbounds double, double* %63, i64 %67
store double %62, double* %68
br label %69
69: ; preds = %61
%70 = load i32, i32* %20
%71 = add nsw i32 %70, 1
store i32 %71, i32* %20
br label %30
72: ; preds = %30
br label %73
73: ; preds = %72
%74 = load i32, i32* %19
%75 = add nsw i32 %74, 1
store i32 %75, i32* %19
br label %25
76: ; preds = %25
%77 = load double*, double** %17
ret double* %77
}

LLVM IR (-O2):
define double* @mm(double* nocapture %0, i32 %1, i32 %2, i8 signext %3, double* nocapture %4, i32 %5, i32 %6, i8 signext %7) {
%9 = tail call double* @alloc_array(i32 %1, i32 %6)
%10 = icmp sgt i32 %1, 0
br i1 %10, label %11, label %39
11: ; preds = %8
%12 = icmp sgt i32 %5, 0
%13 = icmp sgt i32 %6, 0
br label %14
14: ; preds = %11, %36
%15 = phi i32 [ 0, %11 ], [ %37, %36 ]
br i1 %12, label %16, label %36
16: ; preds = %14, %30
%17 = phi i32 [ %34, %30 ], [ 0, %14 ]
br i1 %13, label %18, label %30
18: ; preds = %16, %18
%19 = phi i32 [ %28, %18 ], [ 0, %16 ]
%20 = phi double [ %27, %18 ], [ 0.000000e+00, %16 ]
%21 = tail call i64 @map(i32 %15, i32 %19, i32 %2, i8 signext %3)
%22 = getelementptr inbounds double, double* %0, i64 %21
%23 = load double, double* %22
%24 = tail call i64 @map(i32 %19, i32 %17, i32 %6, i8 signext %7)
%25 = getelementptr inbounds double, double* %4, i64 %24
%26 = load double, double* %25
%27 = tail call double @llvm.fmuladd.f64(double %23, double %26, double %20)
%28 = add nuw nsw i32 %19, 1
%29 = icmp eq i32 %28, %6
br i1 %29, label %30, label %18
30: ; preds = %18, %16
%31 = phi double [ 0.000000e+00, %16 ], [ %27, %18 ]
%32 = tail call i64 @map(i32 %15, i32 %17, i32 %6, i8 signext 110)
%33 = getelementptr inbounds double, double* %9, i64 %32
store double %31, double* %33
%34 = add nuw nsw i32 %17, 1
%35 = icmp eq i32 %34, %5
br i1 %35, label %36, label %16
36: ; preds = %30, %14
%37 = add nuw nsw i32 %15, 1
%38 = icmp eq i32 %37, %1
br i1 %38, label %39, label %14
39: ; preds = %36, %8
ret double* %9
}