#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 */
typedef scalar_t__ z;
typedef scalar_t__ y;
typedef scalar_t__ x;

/* Variables and functions */
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ matprod_mat_vec(double *, double *, double *, int, int);
int /*<<< orphan*/ matprod_outer(double *, double *, double *, int, int);
int /*<<< orphan*/ matprod_trans2_sub(double *, double *, double *, int, int,
                                      int, int, double *);
int /*<<< orphan*/ set_to_zeros(double *, size_t);
void matprod_trans2(double *restrict x, double *restrict y, double *restrict z,
                    int n, int k, int m) {
  assert(((uintptr_t)(x) & (1 - 1)) == 0);
  assert(((uintptr_t)(y) & (1 - 1)) == 0);
  assert(((uintptr_t)(z) & (1 - 1)) == 0);
  x = (x);
  y = (y);
  z = (z);
  if (k <= 1) {
    if (k == 1) {
      matprod_outer(x, y, z, n, m);
    } else {
      set_to_zeros(z, (size_t)n * m);
    }
    return;
  }
  if (n <= 1) {
    if (n == 1) {
      matprod_mat_vec(y, x, z, m, k);
    }
    return;
  }
  if (m <= 1) {
    if (m == 1) {
      matprod_mat_vec(x, y, z, n, k);
    }
    return;
  }
  double *sym = x == y && n == m && (n > 8 || k > 8) ? z : 0;
  matprod_trans2_sub(x, y, z, n, k, m, m, sym);
}


x86 assembly (clang, -O0):
<matprod_trans2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8d,-0x20(%rbp)
mov    %r9d,-0x24(%rbp)
mov    -0x8(%rbp),%rax
and    $0x0,%rax
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x10(%rbp),%rax
and    $0x0,%rax
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x18(%rbp),%rax
and    $0x0,%rax
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x8(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x18(%rbp)
cmpl   $0x1,-0x20(%rbp)
jg     121d <matprod_trans2+0xcd>
cmpl   $0x1,-0x20(%rbp)
jne    1203 <matprod_trans2+0xb3>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x1c(%rbp),%ecx
mov    -0x24(%rbp),%r8d
call   1030 <matprod_outer@plt>
jmp    1218 <matprod_trans2+0xc8>
mov    -0x18(%rbp),%rdi
movslq -0x1c(%rbp),%rsi
movslq -0x24(%rbp),%rax
imul   %rax,%rsi
call   1060 <set_to_zeros@plt>
jmp    12fa <matprod_trans2+0x1aa>
cmpl   $0x1,-0x1c(%rbp)
jg     124e <matprod_trans2+0xfe>
cmpl   $0x1,-0x1c(%rbp)
jne    1249 <matprod_trans2+0xf9>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x24(%rbp),%ecx
mov    -0x20(%rbp),%r8d
call   1070 <matprod_mat_vec@plt>
jmp    12fa <matprod_trans2+0x1aa>
cmpl   $0x1,-0x24(%rbp)
jg     127f <matprod_trans2+0x12f>
cmpl   $0x1,-0x24(%rbp)
jne    127a <matprod_trans2+0x12a>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x1c(%rbp),%ecx
mov    -0x20(%rbp),%r8d
call   1070 <matprod_mat_vec@plt>
jmp    12fa <matprod_trans2+0x1aa>
mov    -0x8(%rbp),%rax
cmp    -0x10(%rbp),%rax
jne    12ba <matprod_trans2+0x16a>
mov    -0x1c(%rbp),%eax
cmp    -0x24(%rbp),%eax
jne    12ba <matprod_trans2+0x16a>
cmpl   $0x8,-0x1c(%rbp)
jg     12ad <matprod_trans2+0x15d>
cmpl   $0x8,-0x20(%rbp)
jle    12ba <matprod_trans2+0x16a>
mov    -0x18(%rbp),%rax
mov    %rax,-0x38(%rbp)
jmp    12c5 <matprod_trans2+0x175>
xor    %eax,%eax
mov    %rax,-0x38(%rbp)
jmp    12c5 <matprod_trans2+0x175>
mov    -0x38(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x1c(%rbp),%ecx
mov    -0x20(%rbp),%r8d
mov    -0x24(%rbp),%r9d
mov    -0x24(%rbp),%r10d
mov    -0x30(%rbp),%rax
mov    %r10d,(%rsp)
mov    %rax,0x8(%rsp)
call   1050 <matprod_trans2_sub@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<matprod_trans2>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r9d,%r15d
mov    %r8d,%ebp
mov    %ecx,%ebx
mov    %rdx,%r14
mov    %rsi,%r12
mov    %rdi,%r13
mov    $0x1,%edi
call   1040 <assert@plt>
mov    $0x1,%edi
call   1040 <assert@plt>
mov    $0x1,%edi
call   1040 <assert@plt>
cmp    $0x1,%ebp
jg     11b2 <matprod_trans2+0x62>
jne    11c7 <matprod_trans2+0x77>
mov    %r13,%rdi
mov    %r12,%rsi
mov    %r14,%rdx
mov    %ebx,%ecx
mov    %r15d,%r8d
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <matprod_outer@plt>
cmp    $0x1,%ebx
jg     11e7 <matprod_trans2+0x97>
jne    1210 <matprod_trans2+0xc0>
mov    %r12,%rdi
mov    %r13,%rsi
mov    %r14,%rdx
mov    %r15d,%ecx
jmp    11fa <matprod_trans2+0xaa>
movslq %ebx,%rax
movslq %r15d,%rsi
imul   %rax,%rsi
mov    %r14,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1060 <set_to_zeros@plt>
cmp    $0x1,%r15d
jg     1216 <matprod_trans2+0xc6>
jne    1210 <matprod_trans2+0xc0>
mov    %r13,%rdi
mov    %r12,%rsi
mov    %r14,%rdx
mov    %ebx,%ecx
mov    %ebp,%r8d
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1070 <matprod_mat_vec@plt>
add    $0x8,%rsp
jmp    1256 <matprod_trans2+0x106>
xor    %eax,%eax
cmp    %r15d,%ebx
mov    $0x0,%ecx
cmove  %r14,%rcx
cmp    %r12,%r13
cmovne %rax,%rcx
cmp    $0x9,%ebp
cmovae %rcx,%rax
cmp    $0x9,%ebx
cmovae %rcx,%rax
mov    %r13,%rdi
mov    %r12,%rsi
mov    %r14,%rdx
mov    %ebx,%ecx
mov    %ebp,%r8d
mov    %r15d,%r9d
push   %rax
push   %r15
call   1050 <matprod_trans2_sub@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @matprod_trans2(double* noalias %0, double* noalias %1, double* noalias %2, i32 %3, i32 %4, i32 %5) {
%7 = alloca double*
%8 = alloca double*
%9 = alloca double*
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca double*
store double* %0, double** %7
store double* %1, double** %8
store double* %2, double** %9
store i32 %3, i32* %10
store i32 %4, i32* %11
store i32 %5, i32* %12
%14 = load double*, double** %7
%15 = ptrtoint double* %14 to i64
%16 = and i64 %15, 0
%17 = icmp eq i64 %16, 0
%18 = zext i1 %17 to i32
%19 = call i32 @assert(i32 %18)
%20 = load double*, double** %8
%21 = ptrtoint double* %20 to i64
%22 = and i64 %21, 0
%23 = icmp eq i64 %22, 0
%24 = zext i1 %23 to i32
%25 = call i32 @assert(i32 %24)
%26 = load double*, double** %9
%27 = ptrtoint double* %26 to i64
%28 = and i64 %27, 0
%29 = icmp eq i64 %28, 0
%30 = zext i1 %29 to i32
%31 = call i32 @assert(i32 %30)
%32 = load double*, double** %7
store double* %32, double** %7
%33 = load double*, double** %8
store double* %33, double** %8
%34 = load double*, double** %9
store double* %34, double** %9
%35 = load i32, i32* %11
%36 = icmp sle i32 %35, 1
br i1 %36, label %37, label %56
37: ; preds = %6
%38 = load i32, i32* %11
%39 = icmp eq i32 %38, 1
br i1 %39, label %40, label %47
40: ; preds = %37
%41 = load double*, double** %7
%42 = load double*, double** %8
%43 = load double*, double** %9
%44 = load i32, i32* %10
%45 = load i32, i32* %12
%46 = call i32 @matprod_outer(double* %41, double* %42, double* %43, i32 %44, i32 %45)
br label %55
47: ; preds = %37
%48 = load double*, double** %9
%49 = load i32, i32* %10
%50 = sext i32 %49 to i64
%51 = load i32, i32* %12
%52 = sext i32 %51 to i64
%53 = mul i64 %50, %52
%54 = call i32 @set_to_zeros(double* %48, i64 %53)
br label %55
55: ; preds = %47, %40
br label %112
56: ; preds = %6
%57 = load i32, i32* %10
%58 = icmp sle i32 %57, 1
br i1 %58, label %59, label %70
59: ; preds = %56
%60 = load i32, i32* %10
%61 = icmp eq i32 %60, 1
br i1 %61, label %62, label %69
62: ; preds = %59
%63 = load double*, double** %8
%64 = load double*, double** %7
%65 = load double*, double** %9
%66 = load i32, i32* %12
%67 = load i32, i32* %11
%68 = call i32 @matprod_mat_vec(double* %63, double* %64, double* %65, i32 %66, i32 %67)
br label %69
69: ; preds = %62, %59
br label %112
70: ; preds = %56
%71 = load i32, i32* %12
%72 = icmp sle i32 %71, 1
br i1 %72, label %73, label %84
73: ; preds = %70
%74 = load i32, i32* %12
%75 = icmp eq i32 %74, 1
br i1 %75, label %76, label %83
76: ; preds = %73
%77 = load double*, double** %7
%78 = load double*, double** %8
%79 = load double*, double** %9
%80 = load i32, i32* %10
%81 = load i32, i32* %11
%82 = call i32 @matprod_mat_vec(double* %77, double* %78, double* %79, i32 %80, i32 %81)
br label %83
83: ; preds = %76, %73
br label %112
84: ; preds = %70
%85 = load double*, double** %7
%86 = load double*, double** %8
%87 = icmp eq double* %85, %86
br i1 %87, label %88, label %100
88: ; preds = %84
%89 = load i32, i32* %10
%90 = load i32, i32* %12
%91 = icmp eq i32 %89, %90
br i1 %91, label %92, label %100
92: ; preds = %88
%93 = load i32, i32* %10
%94 = icmp sgt i32 %93, 8
br i1 %94, label %98, label %95
95: ; preds = %92
%96 = load i32, i32* %11
%97 = icmp sgt i32 %96, 8
br i1 %97, label %98, label %100
98: ; preds = %95, %92
%99 = load double*, double** %9
br label %101
100: ; preds = %95, %88, %84
br label %101
101: ; preds = %100, %98
%102 = phi double* [ %99, %98 ], [ null, %100 ]
store double* %102, double** %13
%103 = load double*, double** %7
%104 = load double*, double** %8
%105 = load double*, double** %9
%106 = load i32, i32* %10
%107 = load i32, i32* %11
%108 = load i32, i32* %12
%109 = load i32, i32* %12
%110 = load double*, double** %13
%111 = call i32 @matprod_trans2_sub(double* %103, double* %104, double* %105, i32 %106, i32 %107, i32 %108, i32 %109, double* %110)
br label %112
112: ; preds = %101, %83, %69, %55
ret void
}

LLVM IR (-O2):
define void @matprod_trans2(double* noalias %0, double* noalias %1, double* noalias %2, i32 %3, i32 %4, i32 %5) {
%7 = tail call i32 @assert(i32 1)
%8 = tail call i32 @assert(i32 1)
%9 = tail call i32 @assert(i32 1)
%10 = icmp slt i32 %4, 2
br i1 %10, label %11, label %20
11: ; preds = %6
%12 = icmp eq i32 %4, 1
br i1 %12, label %13, label %15
13: ; preds = %11
%14 = tail call i32 @matprod_outer(double* %0, double* %1, double* %2, i32 %3, i32 %5)
br label %42
15: ; preds = %11
%16 = sext i32 %3 to i64
%17 = sext i32 %5 to i64
%18 = mul nsw i64 %17, %16
%19 = tail call i32 @set_to_zeros(double* %2, i64 %18)
br label %42
20: ; preds = %6
%21 = icmp slt i32 %3, 2
br i1 %21, label %22, label %26
22: ; preds = %20
%23 = icmp eq i32 %3, 1
br i1 %23, label %24, label %42
24: ; preds = %22
%25 = tail call i32 @matprod_mat_vec(double* %1, double* %0, double* %2, i32 %5, i32 %4)
br label %42
26: ; preds = %20
%27 = icmp slt i32 %5, 2
br i1 %27, label %28, label %32
28: ; preds = %26
%29 = icmp eq i32 %5, 1
br i1 %29, label %30, label %42
30: ; preds = %28
%31 = tail call i32 @matprod_mat_vec(double* %0, double* %1, double* %2, i32 %3, i32 %4)
br label %42
32: ; preds = %26
%33 = icmp eq double* %0, %1
%34 = icmp eq i32 %3, %5
%35 = and i1 %33, %34
%36 = icmp ugt i32 %3, 8
%37 = icmp ugt i32 %4, 8
%38 = or i1 %36, %37
%39 = and i1 %38, %35
%40 = select i1 %39, double* %2, double* null
%41 = tail call i32 @matprod_trans2_sub(double* %0, double* %1, double* %2, i32 %3, i32 %4, i32 %5, i32 %5, double* %40)
br label %42
42: ; preds = %28, %30, %22, %24, %13, %15, %32
ret void
}