#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_trans12_sub(double *, double *, double *, int, int,
                                       int, int);
int /*<<< orphan*/ matprod_vec_mat(double *, double *, double *, int, int);
int /*<<< orphan*/ set_to_zeros(double *, size_t);
void matprod_trans12(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_vec_mat(y, x, z, k, n);
    }
    return;
  }
  matprod_trans12_sub(x, y, z, n, k, m, m);
}


x86 assembly (clang, -O0):
<matprod_trans12>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%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   1060 <assert@plt>
mov    -0x10(%rbp),%rax
and    $0x0,%rax
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
mov    -0x18(%rbp),%rax
and    $0x0,%rax
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <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     122d <matprod_trans12+0xcd>
cmpl   $0x1,-0x20(%rbp)
jne    1213 <matprod_trans12+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    1228 <matprod_trans12+0xc8>
mov    -0x18(%rbp),%rdi
movslq -0x1c(%rbp),%rsi
movslq -0x24(%rbp),%rax
imul   %rax,%rsi
call   1070 <set_to_zeros@plt>
jmp    12b1 <matprod_trans12+0x151>
cmpl   $0x1,-0x1c(%rbp)
jg     125e <matprod_trans12+0xfe>
cmpl   $0x1,-0x1c(%rbp)
jne    1259 <matprod_trans12+0xf9>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x24(%rbp),%ecx
mov    -0x20(%rbp),%r8d
call   1080 <matprod_mat_vec@plt>
jmp    12b1 <matprod_trans12+0x151>
cmpl   $0x1,-0x24(%rbp)
jg     128f <matprod_trans12+0x12f>
cmpl   $0x1,-0x24(%rbp)
jne    128a <matprod_trans12+0x12a>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%ecx
mov    -0x1c(%rbp),%r8d
call   1050 <matprod_vec_mat@plt>
jmp    12b1 <matprod_trans12+0x151>
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),%eax
mov    %eax,(%rsp)
call   1040 <matprod_trans12_sub@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<matprod_trans12>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r9d,%r15d
mov    %r8d,%ebx
mov    %ecx,%ebp
mov    %rdx,%r14
mov    %rsi,%r12
mov    %rdi,%r13
mov    $0x1,%edi
call   1060 <assert@plt>
mov    $0x1,%edi
call   1060 <assert@plt>
mov    $0x1,%edi
call   1060 <assert@plt>
cmp    $0x1,%ebx
jg     11c2 <matprod_trans12+0x62>
jne    11ef <matprod_trans12+0x8f>
mov    %r13,%rdi
mov    %r12,%rsi
mov    %r14,%rdx
mov    %ebp,%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,%ebp
jg     120f <matprod_trans12+0xaf>
jne    1252 <matprod_trans12+0xf2>
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    1080 <matprod_mat_vec@plt>
movslq %ebp,%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    1070 <set_to_zeros@plt>
cmp    $0x1,%r15d
jg     1238 <matprod_trans12+0xd8>
jne    1252 <matprod_trans12+0xf2>
mov    %r12,%rdi
mov    %r13,%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    1050 <matprod_vec_mat@plt>
mov    %r15d,(%rsp)
mov    %r13,%rdi
mov    %r12,%rsi
mov    %r14,%rdx
mov    %ebp,%ecx
mov    %ebx,%r8d
mov    %r15d,%r9d
call   1040 <matprod_trans12_sub@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @matprod_trans12(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
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
%13 = load double*, double** %7
%14 = ptrtoint double* %13 to i64
%15 = and i64 %14, 0
%16 = icmp eq i64 %15, 0
%17 = zext i1 %16 to i32
%18 = call i32 @assert(i32 %17)
%19 = load double*, double** %8
%20 = ptrtoint double* %19 to i64
%21 = and i64 %20, 0
%22 = icmp eq i64 %21, 0
%23 = zext i1 %22 to i32
%24 = call i32 @assert(i32 %23)
%25 = load double*, double** %9
%26 = ptrtoint double* %25 to i64
%27 = and i64 %26, 0
%28 = icmp eq i64 %27, 0
%29 = zext i1 %28 to i32
%30 = call i32 @assert(i32 %29)
%31 = load double*, double** %7
store double* %31, double** %7
%32 = load double*, double** %8
store double* %32, double** %8
%33 = load double*, double** %9
store double* %33, double** %9
%34 = load i32, i32* %11
%35 = icmp sle i32 %34, 1
br i1 %35, label %36, label %55
36: ; preds = %6
%37 = load i32, i32* %11
%38 = icmp eq i32 %37, 1
br i1 %38, label %39, label %46
39: ; preds = %36
%40 = load double*, double** %7
%41 = load double*, double** %8
%42 = load double*, double** %9
%43 = load i32, i32* %10
%44 = load i32, i32* %12
%45 = call i32 @matprod_outer(double* %40, double* %41, double* %42, i32 %43, i32 %44)
br label %54
46: ; preds = %36
%47 = load double*, double** %9
%48 = load i32, i32* %10
%49 = sext i32 %48 to i64
%50 = load i32, i32* %12
%51 = sext i32 %50 to i64
%52 = mul i64 %49, %51
%53 = call i32 @set_to_zeros(double* %47, i64 %52)
br label %54
54: ; preds = %46, %39
br label %92
55: ; preds = %6
%56 = load i32, i32* %10
%57 = icmp sle i32 %56, 1
br i1 %57, label %58, label %69
58: ; preds = %55
%59 = load i32, i32* %10
%60 = icmp eq i32 %59, 1
br i1 %60, label %61, label %68
61: ; preds = %58
%62 = load double*, double** %8
%63 = load double*, double** %7
%64 = load double*, double** %9
%65 = load i32, i32* %12
%66 = load i32, i32* %11
%67 = call i32 @matprod_mat_vec(double* %62, double* %63, double* %64, i32 %65, i32 %66)
br label %68
68: ; preds = %61, %58
br label %92
69: ; preds = %55
%70 = load i32, i32* %12
%71 = icmp sle i32 %70, 1
br i1 %71, label %72, label %83
72: ; preds = %69
%73 = load i32, i32* %12
%74 = icmp eq i32 %73, 1
br i1 %74, label %75, label %82
75: ; preds = %72
%76 = load double*, double** %8
%77 = load double*, double** %7
%78 = load double*, double** %9
%79 = load i32, i32* %11
%80 = load i32, i32* %10
%81 = call i32 @matprod_vec_mat(double* %76, double* %77, double* %78, i32 %79, i32 %80)
br label %82
82: ; preds = %75, %72
br label %92
83: ; preds = %69
%84 = load double*, double** %7
%85 = load double*, double** %8
%86 = load double*, double** %9
%87 = load i32, i32* %10
%88 = load i32, i32* %11
%89 = load i32, i32* %12
%90 = load i32, i32* %12
%91 = call i32 @matprod_trans12_sub(double* %84, double* %85, double* %86, i32 %87, i32 %88, i32 %89, i32 %90)
br label %92
92: ; preds = %83, %82, %68, %54
ret void
}

LLVM IR (-O2):
define void @matprod_trans12(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 %34
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 %34
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 %34
24: ; preds = %22
%25 = tail call i32 @matprod_mat_vec(double* %1, double* %0, double* %2, i32 %5, i32 %4)
br label %34
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 %34
30: ; preds = %28
%31 = tail call i32 @matprod_vec_mat(double* %1, double* %0, double* %2, i32 %4, i32 %3)
br label %34
32: ; preds = %26
%33 = tail call i32 @matprod_trans12_sub(double* %0, double* %1, double* %2, i32 %3, i32 %4, i32 %5, i32 %5)
br label %34
34: ; preds = %28, %30, %22, %24, %13, %15, %32
ret void
}