#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 dot(int, double *, int, double *, int);
void matmult_tn(int N, int M, int L, double *A, double *B, double *C) {
  int i, j;
  for (i = 0; i < N; i++) {
    for (j = 0; j < M; j++) {
      C[i + j * N] = dot(L, &A[i * L], 1, &B[j * L], 1);
    }
  }
}


x86 assembly (clang, -O0):
<matmult_tn>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    %rcx,-0x18(%rbp)
mov    %r8,-0x20(%rbp)
mov    %r9,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    11c5 <matmult_tn+0xb5>
movl   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11b2 <matmult_tn+0xa2>
mov    -0xc(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    -0x2c(%rbp),%eax
imul   -0xc(%rbp),%eax
cltq
shl    $0x3,%rax
add    %rax,%rsi
mov    -0x20(%rbp),%rcx
mov    -0x30(%rbp),%eax
imul   -0xc(%rbp),%eax
cltq
shl    $0x3,%rax
add    %rax,%rcx
mov    $0x1,%r8d
mov    %r8d,%edx
call   1030 <dot@plt>
mov    -0x28(%rbp),%rax
mov    -0x2c(%rbp),%ecx
mov    -0x30(%rbp),%edx
imul   -0x4(%rbp),%edx
add    %edx,%ecx
movslq %ecx,%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    1147 <matmult_tn+0x37>
jmp    11b7 <matmult_tn+0xa7>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1134 <matmult_tn+0x24>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<matmult_tn>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
mov    %r9,0x10(%rsp)
mov    %r8,0x30(%rsp)
mov    %rcx,0x28(%rsp)
mov    %esi,0x4(%rsp)
test   %edi,%edi
jle    11ee <matmult_tn+0xde>
mov    %edx,%r12d
movslq %edx,%rax
mov    %edi,%ecx
mov    0x4(%rsp),%esi
mov    %rsi,0x18(%rsp)
mov    %rcx,0x38(%rsp)
lea    0x0(,%rcx,8),%r15
mov    %rax,0x20(%rsp)
lea    0x0(,%rax,8),%rbx
xor    %eax,%eax
mov    %rax,0x8(%rsp)
jmp    118e <matmult_tn+0x7e>
nopl   (%rax)
mov    0x8(%rsp),%rcx
add    $0x1,%rcx
addq   $0x8,0x10(%rsp)
mov    %rcx,%rax
mov    %rcx,0x8(%rsp)
cmp    0x38(%rsp),%rcx
je     11ee <matmult_tn+0xde>
cmpl   $0x0,0x4(%rsp)
jle    1170 <matmult_tn+0x60>
mov    0x8(%rsp),%rax
imul   0x20(%rsp),%rax
mov    0x28(%rsp),%rcx
lea    (%rcx,%rax,8),%rax
mov    %rax,0x40(%rsp)
mov    0x18(%rsp),%r13
mov    0x30(%rsp),%r14
mov    0x10(%rsp),%rbp
nopl   (%rax)
mov    %r12d,%edi
mov    0x40(%rsp),%rsi
mov    $0x1,%edx
mov    %r14,%rcx
mov    $0x1,%r8d
call   1030 <dot@plt>
movsd  %xmm0,0x0(%rbp)
add    %r15,%rbp
add    %rbx,%r14
add    $0xffffffffffffffff,%r13
jne    11c0 <matmult_tn+0xb0>
jmp    1170 <matmult_tn+0x60>
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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