#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_outer(double *, double *, double *, int, int);
int /*<<< orphan*/ matprod_trans1_sub(double *, double *, double *, int, int,
                                      int, double *);
int /*<<< orphan*/ matprod_vec_mat(double *, double *, double *, int, int);
int /*<<< orphan*/ set_to_zeros(double *, size_t);
void matprod_trans1(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 (n <= 1) {
    if (n == 1) {
      matprod_vec_mat(x, y, z, k, m);
    }
    return;
  }
  if (m <= 1) {
    if (m == 1) {
      matprod_vec_mat(y, x, z, k, n);
    }
    return;
  }
  if (k <= 1) {
    if (k == 1) {
      matprod_outer(x, y, z, n, m);
    } else {
      set_to_zeros(z, (size_t)n * m);
    }
    return;
  }
  double *sym = x == y && n == m && (n > 8 || k > 8) ? z : 0;
  matprod_trans1_sub(x, y, z, n, k, m, sym);
}


x86 assembly (clang, -O0):
<matprod_trans1>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%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   1050 <assert@plt>
mov    -0x10(%rbp),%rax
and    $0x0,%rax
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0x18(%rbp),%rax
and    $0x0,%rax
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <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,-0x1c(%rbp)
jg     1203 <matprod_trans1+0xb3>
cmpl   $0x1,-0x1c(%rbp)
jne    11fe <matprod_trans1+0xae>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%ecx
mov    -0x24(%rbp),%r8d
call   1040 <matprod_vec_mat@plt>
jmp    12f1 <matprod_trans1+0x1a1>
cmpl   $0x1,-0x24(%rbp)
jg     1234 <matprod_trans1+0xe4>
cmpl   $0x1,-0x24(%rbp)
jne    122f <matprod_trans1+0xdf>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%ecx
mov    -0x1c(%rbp),%r8d
call   1040 <matprod_vec_mat@plt>
jmp    12f1 <matprod_trans1+0x1a1>
cmpl   $0x1,-0x20(%rbp)
jg     127f <matprod_trans1+0x12f>
cmpl   $0x1,-0x20(%rbp)
jne    1265 <matprod_trans1+0x115>
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    127a <matprod_trans1+0x12a>
mov    -0x18(%rbp),%rdi
movslq -0x1c(%rbp),%rsi
movslq -0x24(%rbp),%rax
imul   %rax,%rsi
call   1060 <set_to_zeros@plt>
jmp    12f1 <matprod_trans1+0x1a1>
mov    -0x8(%rbp),%rax
cmp    -0x10(%rbp),%rax
jne    12ba <matprod_trans1+0x16a>
mov    -0x1c(%rbp),%eax
cmp    -0x24(%rbp),%eax
jne    12ba <matprod_trans1+0x16a>
cmpl   $0x8,-0x1c(%rbp)
jg     12ad <matprod_trans1+0x15d>
cmpl   $0x8,-0x20(%rbp)
jle    12ba <matprod_trans1+0x16a>
mov    -0x18(%rbp),%rax
mov    %rax,-0x38(%rbp)
jmp    12c5 <matprod_trans1+0x175>
xor    %eax,%eax
mov    %rax,-0x38(%rbp)
jmp    12c5 <matprod_trans1+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    -0x30(%rbp),%rax
mov    %rax,(%rsp)
call   1070 <matprod_trans1_sub@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<matprod_trans1>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r9d,%ebp
mov    %r8d,%r15d
mov    %ecx,%ebx
mov    %rdx,%r14
mov    %rsi,%r12
mov    %rdi,%r13
mov    $0x1,%edi
call   1050 <assert@plt>
mov    $0x1,%edi
call   1050 <assert@plt>
mov    $0x1,%edi
call   1050 <assert@plt>
cmp    $0x1,%ebx
jg     11a6 <matprod_trans1+0x56>
jne    1239 <matprod_trans1+0xe9>
mov    %r13,%rdi
mov    %r12,%rsi
mov    %r14,%rdx
mov    %r15d,%ecx
mov    %ebp,%r8d
jmp    11c0 <matprod_trans1+0x70>
cmp    $0x1,%ebp
jg     11d3 <matprod_trans1+0x83>
jne    1239 <matprod_trans1+0xe9>
mov    %r12,%rdi
mov    %r13,%rsi
mov    %r14,%rdx
mov    %r15d,%ecx
mov    %ebx,%r8d
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <matprod_vec_mat@plt>
cmp    $0x1,%r15d
jg     11fc <matprod_trans1+0xac>
jne    1248 <matprod_trans1+0xf8>
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    1030 <matprod_outer@plt>
xor    %eax,%eax
cmp    %ebp,%ebx
mov    $0x0,%ecx
cmove  %r14,%rcx
cmp    %r12,%r13
cmovne %rax,%rcx
cmp    $0x9,%r15d
cmovae %rcx,%rax
cmp    $0x9,%ebx
cmovae %rcx,%rax
mov    %rax,(%rsp)
mov    %r13,%rdi
mov    %r12,%rsi
mov    %r14,%rdx
mov    %ebx,%ecx
mov    %r15d,%r8d
mov    %ebp,%r9d
call   1070 <matprod_trans1_sub@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %ebx,%eax
mov    %ebp,%esi
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>

LLVM IR (-O0):
define void @matprod_trans1(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* %10
%36 = icmp sle i32 %35, 1
br i1 %36, label %37, label %48
37: ; preds = %6
%38 = load i32, i32* %10
%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* %11
%45 = load i32, i32* %12
%46 = call i32 @matprod_vec_mat(double* %41, double* %42, double* %43, i32 %44, i32 %45)
br label %47
47: ; preds = %40, %37
br label %111
48: ; preds = %6
%49 = load i32, i32* %12
%50 = icmp sle i32 %49, 1
br i1 %50, label %51, label %62
51: ; preds = %48
%52 = load i32, i32* %12
%53 = icmp eq i32 %52, 1
br i1 %53, label %54, label %61
54: ; preds = %51
%55 = load double*, double** %8
%56 = load double*, double** %7
%57 = load double*, double** %9
%58 = load i32, i32* %11
%59 = load i32, i32* %10
%60 = call i32 @matprod_vec_mat(double* %55, double* %56, double* %57, i32 %58, i32 %59)
br label %61
61: ; preds = %54, %51
br label %111
62: ; preds = %48
%63 = load i32, i32* %11
%64 = icmp sle i32 %63, 1
br i1 %64, label %65, label %84
65: ; preds = %62
%66 = load i32, i32* %11
%67 = icmp eq i32 %66, 1
br i1 %67, label %68, label %75
68: ; preds = %65
%69 = load double*, double** %7
%70 = load double*, double** %8
%71 = load double*, double** %9
%72 = load i32, i32* %10
%73 = load i32, i32* %12
%74 = call i32 @matprod_outer(double* %69, double* %70, double* %71, i32 %72, i32 %73)
br label %83
75: ; preds = %65
%76 = load double*, double** %9
%77 = load i32, i32* %10
%78 = sext i32 %77 to i64
%79 = load i32, i32* %12
%80 = sext i32 %79 to i64
%81 = mul i64 %78, %80
%82 = call i32 @set_to_zeros(double* %76, i64 %81)
br label %83
83: ; preds = %75, %68
br label %111
84: ; preds = %62
%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 double*, double** %13
%110 = call i32 @matprod_trans1_sub(double* %103, double* %104, double* %105, i32 %106, i32 %107, i32 %108, double* %109)
br label %111
111: ; preds = %101, %83, %61, %47
ret void
}

LLVM IR (-O2):
define void @matprod_trans1(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 %3, 2
br i1 %10, label %11, label %15
11: ; preds = %6
%12 = icmp eq i32 %3, 1
br i1 %12, label %13, label %42
13: ; preds = %11
%14 = tail call i32 @matprod_vec_mat(double* %0, double* %1, double* %2, i32 %4, i32 %5)
br label %42
15: ; preds = %6
%16 = icmp slt i32 %5, 2
br i1 %16, label %17, label %21
17: ; preds = %15
%18 = icmp eq i32 %5, 1
br i1 %18, label %19, label %42
19: ; preds = %17
%20 = tail call i32 @matprod_vec_mat(double* %1, double* %0, double* %2, i32 %4, i32 %3)
br label %42
21: ; preds = %15
%22 = icmp slt i32 %4, 2
br i1 %22, label %23, label %32
23: ; preds = %21
%24 = icmp eq i32 %4, 1
br i1 %24, label %25, label %27
25: ; preds = %23
%26 = tail call i32 @matprod_outer(double* %0, double* %1, double* %2, i32 %3, i32 %5)
br label %42
27: ; preds = %23
%28 = zext i32 %3 to i64
%29 = zext i32 %5 to i64
%30 = mul nuw nsw i64 %29, %28
%31 = tail call i32 @set_to_zeros(double* %2, i64 %30)
br label %42
32: ; preds = %21
%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_trans1_sub(double* %0, double* %1, double* %2, i32 %3, i32 %4, i32 %5, double* %40)
br label %42
42: ; preds = %25, %27, %17, %19, %11, %13, %32
ret void
}