#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 */
int /*<<< orphan*/ tensor_dot(double const *, double const *, unsigned int);
void tensor_mtxm(double *restrict C, unsigned int nc, const double *restrict A,
                 unsigned int na, const double *restrict B, unsigned int nb) {
  unsigned int i, j;
  for (j = 0; j < nb; ++j, B += na) {
    const double *restrict A_ = A;
    for (i = 0; i < nc; ++i, A_ += na)
      *C++ = tensor_dot(A_, B, na);
  }
}


x86 assembly (clang, -O0):
<tensor_mtxm>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9d,-0x2c(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x2c(%rbp),%eax
jae    11cc <tensor_mtxm+0xbc>
mov    -0x18(%rbp),%rax
mov    %rax,-0x40(%rbp)
movl   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%eax
cmp    -0xc(%rbp),%eax
jae    11a5 <tensor_mtxm+0x95>
mov    -0x40(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1030 <tensor_dot@plt>
cvtsi2sd %eax,%xmm0
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x8,%rcx
mov    %rcx,-0x8(%rbp)
movsd  %xmm0,(%rax)
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
mov    -0x1c(%rbp),%ecx
mov    -0x40(%rbp),%rax
mov    %ecx,%ecx
shl    $0x3,%rcx
add    %rcx,%rax
mov    %rax,-0x40(%rbp)
jmp    1150 <tensor_mtxm+0x40>
jmp    11aa <tensor_mtxm+0x9a>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
mov    -0x1c(%rbp),%ecx
mov    -0x28(%rbp),%rax
mov    %ecx,%ecx
shl    $0x3,%rcx
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
jmp    1135 <tensor_mtxm+0x25>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tensor_mtxm>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rdx,0x18(%rsp)
mov    %r9d,0x10(%rsp)
test   %r9d,%r9d
je     11a9 <tensor_mtxm+0x99>
mov    %r8,%rbx
mov    %ecx,%r13d
mov    %esi,%r12d
mov    %rdi,%rbp
mov    %ecx,%eax
mov    %rax,0x20(%rsp)
lea    0x0(,%rax,8),%r14
xor    %ecx,%ecx
mov    %esi,0xc(%rsp)
jmp    116b <tensor_mtxm+0x5b>
mov    0x14(%rsp),%ecx
add    $0x1,%ecx
mov    0x20(%rsp),%rax
lea    (%rbx,%rax,8),%rbx
cmp    0x10(%rsp),%ecx
mov    0xc(%rsp),%r12d
je     11a9 <tensor_mtxm+0x99>
test   %r12d,%r12d
mov    %ecx,0x14(%rsp)
je     1150 <tensor_mtxm+0x40>
mov    0x18(%rsp),%r15
nopl   0x0(%rax)
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %r13d,%edx
call   1030 <tensor_dot@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
movsd  %xmm0,0x0(%rbp)
add    $0x8,%rbp
add    %r14,%r15
add    $0xffffffff,%r12d
jne    1180 <tensor_mtxm+0x70>
jmp    1150 <tensor_mtxm+0x40>
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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