#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(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], N, &B[j * L], 1);
  }
}


x86 assembly (clang, -O0):
<matmult>:
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    11c0 <matmult+0xb0>
movl   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11ad <matmult+0x9d>
mov    -0xc(%rbp),%edi
mov    -0x18(%rbp),%rsi
movslq -0x2c(%rbp),%rax
shl    $0x3,%rax
add    %rax,%rsi
mov    -0x4(%rbp),%edx
mov    -0x20(%rbp),%rcx
mov    -0x30(%rbp),%eax
imul   -0xc(%rbp),%eax
cltq
shl    $0x3,%rax
add    %rax,%rcx
mov    $0x1,%r8d
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+0x37>
jmp    11b2 <matmult+0xa2>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1134 <matmult+0x24>
add    $0x30,%rsp
pop    %rbp
ret

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

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

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