#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_n2(double *, double *, double *, int);
int /*<<< orphan*/ matprod_outer_n3(double *, double *, double *, int);
int /*<<< orphan*/ matprod_outer_n4(double *, double *, double *, int);
int /*<<< orphan*/ matprod_outer_sub(double *, double *, double *, int, int,
                                     int);
int /*<<< orphan*/ matprod_scalar_vec(double, double *, double *, int);
void matprod_outer(double *restrict x, double *restrict y, double *restrict z,
                   int n, 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 (m <= 1) {
    if (m == 1) {
      matprod_scalar_vec(y[0], x, z, n);
    }
    return;
  }
  if (n <= 4) {
    if (n == 4) {
      matprod_outer_n4(x, y, z, m);
    } else if (n == 3) {
      matprod_outer_n3(x, y, z, m);
    } else if (n == 2) {
      matprod_outer_n2(x, y, z, m);
    } else if (n == 1) {
      matprod_scalar_vec(x[0], y, z, m);
    }
    return;
  }
  int rows = n;
  while (rows > 2 * (2048 - 128)) {
    matprod_outer_sub(x, y, z, n, m, (2048 - 128));
    x += (2048 - 128);
    z += (2048 - 128);
    rows -= (2048 - 128);
  }
  if (rows > (2048 - 128)) {
    int nr = (((rows + 3) >> 1) & ~3);
    matprod_outer_sub(x, y, z, n, m, nr);
    x += nr;
    z += nr;
    rows -= nr;
  }
  matprod_outer_sub(x, y, z, n, m, rows);
}


x86 assembly (clang, -O0):
<matprod_outer>:
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    -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,-0x20(%rbp)
jg     120f <matprod_outer+0xaf>
cmpl   $0x1,-0x20(%rbp)
jne    120a <matprod_outer+0xaa>
mov    -0x10(%rbp),%rax
movsd  (%rax),%xmm0
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1080 <matprod_scalar_vec@plt>
jmp    139e <matprod_outer+0x23e>
cmpl   $0x4,-0x1c(%rbp)
jg     12b8 <matprod_outer+0x158>
cmpl   $0x4,-0x1c(%rbp)
jne    123c <matprod_outer+0xdc>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%ecx
call   1060 <matprod_outer_n4@plt>
jmp    12b3 <matprod_outer+0x153>
cmpl   $0x3,-0x1c(%rbp)
jne    125f <matprod_outer+0xff>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%ecx
call   1030 <matprod_outer_n3@plt>
jmp    12ae <matprod_outer+0x14e>
cmpl   $0x2,-0x1c(%rbp)
jne    1282 <matprod_outer+0x122>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%ecx
call   1070 <matprod_outer_n2@plt>
jmp    12a9 <matprod_outer+0x149>
cmpl   $0x1,-0x1c(%rbp)
jne    12a4 <matprod_outer+0x144>
mov    -0x8(%rbp),%rax
movsd  (%rax),%xmm0
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%edx
call   1080 <matprod_scalar_vec@plt>
jmp    12a9 <matprod_outer+0x149>
jmp    12ae <matprod_outer+0x14e>
jmp    12b3 <matprod_outer+0x153>
jmp    139e <matprod_outer+0x23e>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x24(%rbp)
cmpl   $0xf00,-0x24(%rbp)
jle    1315 <matprod_outer+0x1b5>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x1c(%rbp),%ecx
mov    -0x20(%rbp),%r8d
mov    $0x780,%r9d
call   1040 <matprod_outer_sub@plt>
mov    -0x8(%rbp),%rax
add    $0x3c00,%rax
mov    %rax,-0x8(%rbp)
mov    -0x18(%rbp),%rax
add    $0x3c00,%rax
mov    %rax,-0x18(%rbp)
mov    -0x24(%rbp),%eax
sub    $0x780,%eax
mov    %eax,-0x24(%rbp)
jmp    12be <matprod_outer+0x15e>
cmpl   $0x780,-0x24(%rbp)
jle    1382 <matprod_outer+0x222>
mov    -0x24(%rbp),%eax
add    $0x3,%eax
sar    $0x1,%eax
and    $0xfffffffc,%eax
mov    %eax,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x1c(%rbp),%ecx
mov    -0x20(%rbp),%r8d
mov    -0x28(%rbp),%r9d
call   1040 <matprod_outer_sub@plt>
mov    -0x28(%rbp),%ecx
mov    -0x8(%rbp),%rax
movslq %ecx,%rcx
shl    $0x3,%rcx
add    %rcx,%rax
mov    %rax,-0x8(%rbp)
mov    -0x28(%rbp),%ecx
mov    -0x18(%rbp),%rax
movslq %ecx,%rcx
shl    $0x3,%rcx
add    %rcx,%rax
mov    %rax,-0x18(%rbp)
mov    -0x28(%rbp),%ecx
mov    -0x24(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x24(%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
call   1040 <matprod_outer_sub@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<matprod_outer>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r8d,%r12d
mov    %ecx,%r14d
mov    %rdx,%rbx
mov    %rsi,%r15
mov    %rdi,%rbp
mov    $0x1,%edi
call   1050 <assert@plt>
mov    $0x1,%edi
call   1050 <assert@plt>
mov    $0x1,%edi
call   1050 <assert@plt>
cmp    $0x1,%r12d
jg     11c1 <matprod_outer+0x61>
jne    11f1 <matprod_outer+0x91>
movsd  (%r15),%xmm0
mov    %rbp,%rdi
mov    %rbx,%rsi
mov    %r14d,%edx
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1080 <matprod_scalar_vec@plt>
cmp    $0x5,%r14d
jge    1200 <matprod_outer+0xa0>
add    $0xffffffff,%r14d
cmp    $0x3,%r14d
ja     11f1 <matprod_outer+0x91>
lea    0xe28(%rip),%rax
movslq (%rax,%r14,4),%rcx
add    %rax,%rcx
jmp    *%rcx
movsd  0x0(%rbp),%xmm0
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %r12d,%edx
jmp    11ae <matprod_outer+0x4e>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
cmp    $0xf01,%r14d
mov    %r12d,0x4(%rsp)
jb     1260 <matprod_outer+0x100>
mov    %r14d,%r12d
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %rbp,%rdi
mov    %r15,%rsi
mov    %rbx,%rdx
mov    %r14d,%ecx
mov    0x4(%rsp),%r8d
mov    $0x780,%r9d
call   1040 <matprod_outer_sub@plt>
add    $0x3c00,%rbp
add    $0x3c00,%rbx
lea    -0x780(%r12),%r13d
ff
cmp    $0x1680,%r12d
mov    %r13d,%r12d
ja     1220 <matprod_outer+0xc0>
jmp    126f <matprod_outer+0x10f>
mov    %r14d,%r13d
mov    %r14d,%r9d
cmp    $0x781,%r14d
jb     12a2 <matprod_outer+0x142>
lea    0x3(%r13),%r12d
shr    %r12d
and    $0xfffffffc,%r12d
mov    %rbp,%rdi
mov    %r15,%rsi
mov    %rbx,%rdx
mov    %r14d,%ecx
mov    0x4(%rsp),%r8d
mov    %r12d,%r9d
call   1040 <matprod_outer_sub@plt>
lea    0x0(%rbp,%r12,8),%rbp
lea    (%rbx,%r12,8),%rbx
sub    %r12d,%r13d
mov    %r13d,%r9d
mov    %rbp,%rdi
mov    %r15,%rsi
mov    %rbx,%rdx
mov    %r14d,%ecx
mov    0x4(%rsp),%r8d
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <matprod_outer_sub@plt>
mov    %rbp,%rdi
mov    %r15,%rsi
mov    %rbx,%rdx
mov    %r12d,%ecx
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1070 <matprod_outer_n2@plt>
mov    %rbp,%rdi
mov    %r15,%rsi
mov    %rbx,%rdx
mov    %r12d,%ecx
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <matprod_outer_n3@plt>
mov    %rbp,%rdi
mov    %r15,%rsi
mov    %rbx,%rdx
mov    %r12d,%ecx
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1060 <matprod_outer_n4@plt>

LLVM IR (-O0):
define void @matprod_outer(double* noalias %0, double* noalias %1, double* noalias %2, i32 %3, i32 %4) {
%6 = alloca double*
%7 = alloca double*
%8 = alloca double*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
store double* %0, double** %6
store double* %1, double** %7
store double* %2, double** %8
store i32 %3, i32* %9
store i32 %4, i32* %10
%13 = load double*, double** %6
%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** %7
%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** %8
%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** %6
store double* %31, double** %6
%32 = load double*, double** %7
store double* %32, double** %7
%33 = load double*, double** %8
store double* %33, double** %8
%34 = load i32, i32* %10
%35 = icmp sle i32 %34, 1
br i1 %35, label %36, label %48
36: ; preds = %5
%37 = load i32, i32* %10
%38 = icmp eq i32 %37, 1
br i1 %38, label %39, label %47
39: ; preds = %36
%40 = load double*, double** %7
%41 = getelementptr inbounds double, double* %40, i64 0
%42 = load double, double* %41
%43 = load double*, double** %6
%44 = load double*, double** %8
%45 = load i32, i32* %9
%46 = call i32 @matprod_scalar_vec(double %42, double* %43, double* %44, i32 %45)
br label %47
47: ; preds = %39, %36
br label %145
48: ; preds = %5
%49 = load i32, i32* %9
%50 = icmp sle i32 %49, 4
br i1 %50, label %51, label %93
51: ; preds = %48
%52 = load i32, i32* %9
%53 = icmp eq i32 %52, 4
br i1 %53, label %54, label %60
54: ; preds = %51
%55 = load double*, double** %6
%56 = load double*, double** %7
%57 = load double*, double** %8
%58 = load i32, i32* %10
%59 = call i32 @matprod_outer_n4(double* %55, double* %56, double* %57, i32 %58)
br label %92
60: ; preds = %51
%61 = load i32, i32* %9
%62 = icmp eq i32 %61, 3
br i1 %62, label %63, label %69
63: ; preds = %60
%64 = load double*, double** %6
%65 = load double*, double** %7
%66 = load double*, double** %8
%67 = load i32, i32* %10
%68 = call i32 @matprod_outer_n3(double* %64, double* %65, double* %66, i32 %67)
br label %91
69: ; preds = %60
%70 = load i32, i32* %9
%71 = icmp eq i32 %70, 2
br i1 %71, label %72, label %78
72: ; preds = %69
%73 = load double*, double** %6
%74 = load double*, double** %7
%75 = load double*, double** %8
%76 = load i32, i32* %10
%77 = call i32 @matprod_outer_n2(double* %73, double* %74, double* %75, i32 %76)
br label %90
78: ; preds = %69
%79 = load i32, i32* %9
%80 = icmp eq i32 %79, 1
br i1 %80, label %81, label %89
81: ; preds = %78
%82 = load double*, double** %6
%83 = getelementptr inbounds double, double* %82, i64 0
%84 = load double, double* %83
%85 = load double*, double** %7
%86 = load double*, double** %8
%87 = load i32, i32* %10
%88 = call i32 @matprod_scalar_vec(double %84, double* %85, double* %86, i32 %87)
br label %89
89: ; preds = %81, %78
br label %90
90: ; preds = %89, %72
br label %91
91: ; preds = %90, %63
br label %92
92: ; preds = %91, %54
br label %145
93: ; preds = %48
%94 = load i32, i32* %9
store i32 %94, i32* %11
br label %95
95: ; preds = %98, %93
%96 = load i32, i32* %11
%97 = icmp sgt i32 %96, 3840
br i1 %97, label %98, label %111
98: ; preds = %95
%99 = load double*, double** %6
%100 = load double*, double** %7
%101 = load double*, double** %8
%102 = load i32, i32* %9
%103 = load i32, i32* %10
%104 = call i32 @matprod_outer_sub(double* %99, double* %100, double* %101, i32 %102, i32 %103, i32 1920)
%105 = load double*, double** %6
%106 = getelementptr inbounds double, double* %105, i64 1920
store double* %106, double** %6
%107 = load double*, double** %8
%108 = getelementptr inbounds double, double* %107, i64 1920
store double* %108, double** %8
%109 = load i32, i32* %11
%110 = sub nsw i32 %109, 1920
store i32 %110, i32* %11
br label %95
111: ; preds = %95
%112 = load i32, i32* %11
%113 = icmp sgt i32 %112, 1920
br i1 %113, label %114, label %137
114: ; preds = %111
%115 = load i32, i32* %11
%116 = add nsw i32 %115, 3
%117 = ashr i32 %116, 1
%118 = and i32 %117, -4
store i32 %118, i32* %12
%119 = load double*, double** %6
%120 = load double*, double** %7
%121 = load double*, double** %8
%122 = load i32, i32* %9
%123 = load i32, i32* %10
%124 = load i32, i32* %12
%125 = call i32 @matprod_outer_sub(double* %119, double* %120, double* %121, i32 %122, i32 %123, i32 %124)
%126 = load i32, i32* %12
%127 = load double*, double** %6
%128 = sext i32 %126 to i64
%129 = getelementptr inbounds double, double* %127, i64 %128
store double* %129, double** %6
%130 = load i32, i32* %12
%131 = load double*, double** %8
%132 = sext i32 %130 to i64
%133 = getelementptr inbounds double, double* %131, i64 %132
store double* %133, double** %8
%134 = load i32, i32* %12
%135 = load i32, i32* %11
%136 = sub nsw i32 %135, %134
store i32 %136, i32* %11
br label %137
137: ; preds = %114, %111
%138 = load double*, double** %6
%139 = load double*, double** %7
%140 = load double*, double** %8
%141 = load i32, i32* %9
%142 = load i32, i32* %10
%143 = load i32, i32* %11
%144 = call i32 @matprod_outer_sub(double* %138, double* %139, double* %140, i32 %141, i32 %142, i32 %143)
br label %145
145: ; preds = %137, %92, %47
ret void
}

LLVM IR (-O2):
define void @matprod_outer(double* noalias %0, double* noalias %1, double* noalias %2, i32 %3, i32 %4) {
%6 = tail call i32 @assert(i32 1)
%7 = tail call i32 @assert(i32 1)
%8 = tail call i32 @assert(i32 1)
%9 = icmp slt i32 %4, 2
br i1 %9, label %10, label %15
10: ; preds = %5
%11 = icmp eq i32 %4, 1
br i1 %11, label %12, label %57
12: ; preds = %10
%13 = load double, double* %1
%14 = tail call i32 @matprod_scalar_vec(double %13, double* %0, double* %2, i32 %3)
br label %57
15: ; preds = %5
%16 = icmp slt i32 %3, 5
br i1 %16, label %19, label %17
17: ; preds = %15
%18 = icmp ugt i32 %3, 3840
br i1 %18, label %29, label %38
19: ; preds = %15
switch i32 %3, label %57 [
i32 4, label %20
i32 3, label %22
i32 2, label %24
i32 1, label %26
]
20: ; preds = %19
%21 = tail call i32 @matprod_outer_n4(double* %0, double* %1, double* %2, i32 %4)
br label %57
22: ; preds = %19
%23 = tail call i32 @matprod_outer_n3(double* %0, double* %1, double* %2, i32 %4)
br label %57
24: ; preds = %19
%25 = tail call i32 @matprod_outer_n2(double* %0, double* %1, double* %2, i32 %4)
br label %57
26: ; preds = %19
%27 = load double, double* %0
%28 = tail call i32 @matprod_scalar_vec(double %27, double* %1, double* %2, i32 %4)
br label %57
29: ; preds = %17, %29
%30 = phi double* [ %34, %29 ], [ %0, %17 ]
%31 = phi i32 [ %36, %29 ], [ %3, %17 ]
%32 = phi double* [ %35, %29 ], [ %2, %17 ]
%33 = tail call i32 @matprod_outer_sub(double* %30, double* %1, double* %32, i32 %3, i32 %4, i32 1920)
%34 = getelementptr inbounds double, double* %30, i64 1920
%35 = getelementptr inbounds double, double* %32, i64 1920
%36 = add nsw i32 %31, -1920
%37 = icmp ugt i32 %31, 5760
br i1 %37, label %29, label %40
38: ; preds = %17
%39 = icmp ugt i32 %3, 1920
br i1 %39, label %40, label %52
40: ; preds = %29, %38
%41 = phi double* [ %0, %38 ], [ %34, %29 ]
%42 = phi i32 [ %3, %38 ], [ %36, %29 ]
%43 = phi double* [ %2, %38 ], [ %35, %29 ]
%44 = add nuw nsw i32 %42, 3
%45 = lshr i32 %44, 1
%46 = and i32 %45, 2147483644
%47 = tail call i32 @matprod_outer_sub(double* %41, double* %1, double* %43, i32 %3, i32 %4, i32 %46)
%48 = zext i32 %46 to i64
%49 = getelementptr inbounds double, double* %41, i64 %48
%50 = getelementptr inbounds double, double* %43, i64 %48
%51 = sub nuw nsw i32 %42, %46
br label %52
52: ; preds = %40, %38
%53 = phi double* [ %50, %40 ], [ %2, %38 ]
%54 = phi i32 [ %51, %40 ], [ %3, %38 ]
%55 = phi double* [ %49, %40 ], [ %0, %38 ]
%56 = tail call i32 @matprod_outer_sub(double* %55, double* %1, double* %53, i32 %3, i32 %4, i32 %54)
br label %57
57: ; preds = %19, %20, %24, %26, %22, %10, %12, %52
ret void
}