#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*/ assert(int);
int /*<<< orphan*/ fail(char *, int, int);
int /*<<< orphan*/ matrix_product_clean(float *, int *, int *, float *, int,
                                        int, float *, int, int);
int matrix_product(float *ab, float *a, float *b, int na, int nb) {
  int a_nrows, a_ncols, b_nrows, b_ncols;
  if (na == 4 && nb == 4) {
    a_nrows = a_ncols = b_nrows = b_ncols = 2;
  } else if (na == 9 && nb == 9) {
    a_nrows = a_ncols = b_nrows = b_ncols = 3;
  } else if (na == 16 && nb == 16) {
    a_nrows = a_ncols = b_nrows = b_ncols = 4;
  } else if (na == 9 && nb == 3) {
    a_nrows = a_ncols = b_nrows = 3;
    b_ncols = 1;
  } else if (na == 4 && nb == 2) {
    a_nrows = a_ncols = b_nrows = 2;
    b_ncols = 1;
  } else if (na == 1 && nb == 1) {
    a_nrows = a_ncols = b_nrows = b_ncols = 1;
  } else if (na == 6 && nb == 2) {
    ab[0] = a[0] * b[0] + a[1] * b[1] + a[2];
    ab[1] = a[3] * b[0] + a[4] * b[1] + a[5];
    return 2;
  } else
    fail("bad matrix product (%d %d)", na, nb);
  assert(a_ncols == b_nrows);
  int ab_nrows, ab_ncols;
  matrix_product_clean(ab, &ab_nrows, &ab_ncols, a, a_nrows, a_ncols, b,
                       b_nrows, b_ncols);
  return ab_nrows * ab_ncols;
}


x86 assembly (clang, -O0):
<matrix_product>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
mov    %r8d,-0x28(%rbp)
cmpl   $0x4,-0x24(%rbp)
jne    1180 <matrix_product+0x50>
cmpl   $0x4,-0x28(%rbp)
jne    1180 <matrix_product+0x50>
movl   $0x2,-0x38(%rbp)
movl   $0x2,-0x34(%rbp)
movl   $0x2,-0x30(%rbp)
movl   $0x2,-0x2c(%rbp)
jmp    1351 <matrix_product+0x221>
cmpl   $0x9,-0x24(%rbp)
jne    11b5 <matrix_product+0x85>
cmpl   $0x9,-0x28(%rbp)
jne    11b5 <matrix_product+0x85>
movl   $0x3,-0x38(%rbp)
movl   $0x3,-0x34(%rbp)
movl   $0x3,-0x30(%rbp)
movl   $0x3,-0x2c(%rbp)
jmp    134c <matrix_product+0x21c>
cmpl   $0x10,-0x24(%rbp)
jne    11ea <matrix_product+0xba>
cmpl   $0x10,-0x28(%rbp)
jne    11ea <matrix_product+0xba>
movl   $0x4,-0x38(%rbp)
movl   $0x4,-0x34(%rbp)
movl   $0x4,-0x30(%rbp)
movl   $0x4,-0x2c(%rbp)
jmp    1347 <matrix_product+0x217>
cmpl   $0x9,-0x24(%rbp)
jne    121f <matrix_product+0xef>
cmpl   $0x3,-0x28(%rbp)
jne    121f <matrix_product+0xef>
movl   $0x3,-0x34(%rbp)
movl   $0x3,-0x30(%rbp)
movl   $0x3,-0x2c(%rbp)
movl   $0x1,-0x38(%rbp)
jmp    1342 <matrix_product+0x212>
cmpl   $0x4,-0x24(%rbp)
jne    1254 <matrix_product+0x124>
cmpl   $0x2,-0x28(%rbp)
jne    1254 <matrix_product+0x124>
movl   $0x2,-0x34(%rbp)
movl   $0x2,-0x30(%rbp)
movl   $0x2,-0x2c(%rbp)
movl   $0x1,-0x38(%rbp)
jmp    133d <matrix_product+0x20d>
cmpl   $0x1,-0x24(%rbp)
jne    1289 <matrix_product+0x159>
cmpl   $0x1,-0x28(%rbp)
jne    1289 <matrix_product+0x159>
movl   $0x1,-0x38(%rbp)
movl   $0x1,-0x34(%rbp)
movl   $0x1,-0x30(%rbp)
movl   $0x1,-0x2c(%rbp)
jmp    1338 <matrix_product+0x208>
cmpl   $0x6,-0x24(%rbp)
jne    1321 <matrix_product+0x1f1>
cmpl   $0x2,-0x28(%rbp)
jne    1321 <matrix_product+0x1f1>
mov    -0x18(%rbp),%rax
movss  (%rax),%xmm0
mov    -0x20(%rbp),%rax
movss  (%rax),%xmm2
mov    -0x18(%rbp),%rax
movss  0x4(%rax),%xmm1
mov    -0x20(%rbp),%rax
mulss  0x4(%rax),%xmm1
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
mov    -0x18(%rbp),%rax
addss  0x8(%rax),%xmm0
mov    -0x10(%rbp),%rax
movss  %xmm0,(%rax)
mov    -0x18(%rbp),%rax
movss  0xc(%rax),%xmm0
mov    -0x20(%rbp),%rax
movss  (%rax),%xmm2
mov    -0x18(%rbp),%rax
movss  0x10(%rax),%xmm1
mov    -0x20(%rbp),%rax
mulss  0x4(%rax),%xmm1
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
mov    -0x18(%rbp),%rax
addss  0x14(%rax),%xmm0
mov    -0x10(%rbp),%rax
movss  %xmm0,0x4(%rax)
movl   $0x2,-0x4(%rbp)
jmp    13a3 <matrix_product+0x273>
mov    -0x24(%rbp),%esi
mov    -0x28(%rbp),%edx
lea    0xcd2(%rip),%rdi
call   1030 <fail@plt>
jmp    1338 <matrix_product+0x208>
jmp    133d <matrix_product+0x20d>
jmp    1342 <matrix_product+0x212>
jmp    1347 <matrix_product+0x217>
jmp    134c <matrix_product+0x21c>
jmp    1351 <matrix_product+0x221>
mov    -0x30(%rbp),%eax
cmp    -0x34(%rbp),%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    -0x2c(%rbp),%r8d
mov    -0x30(%rbp),%r9d
mov    -0x20(%rbp),%r11
mov    -0x34(%rbp),%r10d
mov    -0x38(%rbp),%eax
lea    -0x3c(%rbp),%rsi
lea    -0x40(%rbp),%rdx
mov    %r11,(%rsp)
mov    %r10d,0x8(%rsp)
mov    %eax,0x10(%rsp)
call   1040 <matrix_product_clean@plt>
mov    -0x3c(%rbp),%eax
imul   -0x40(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<matrix_product>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%r12
mov    $0x2,%ebx
cmp    $0x4,%ecx
jne    1161 <matrix_product+0x31>
cmp    $0x4,%r8d
jne    1161 <matrix_product+0x31>
mov    $0x2,%r13d
jmp    124c <matrix_product+0x11c>
cmp    $0x9,%ecx
jne    117c <matrix_product+0x4c>
cmp    $0x9,%r8d
jne    117c <matrix_product+0x4c>
mov    $0x3,%ebx
mov    $0x3,%r13d
jmp    124c <matrix_product+0x11c>
cmp    $0x10,%ecx
jne    1196 <matrix_product+0x66>
mov    $0x4,%ebx
mov    $0x4,%r13d
cmp    $0x10,%r8d
je     124c <matrix_product+0x11c>
mov    $0x1,%r13d
cmp    $0x9,%ecx
jne    11b1 <matrix_product+0x81>
cmp    $0x3,%r8d
jne    11b1 <matrix_product+0x81>
mov    $0x3,%ebx
jmp    124c <matrix_product+0x11c>
cmp    $0x4,%ecx
jne    11c5 <matrix_product+0x95>
mov    $0x2,%ebx
cmp    $0x2,%r8d
je     124c <matrix_product+0x11c>
cmp    $0x1,%ecx
jne    11db <matrix_product+0xab>
mov    $0x1,%ebx
mov    $0x1,%r13d
cmp    $0x1,%r8d
je     124c <matrix_product+0x11c>
cmp    $0x6,%ecx
jne    123b <matrix_product+0x10b>
cmp    $0x2,%r8d
jne    123b <matrix_product+0x10b>
movss  (%r15),%xmm0
movss  0x4(%r15),%xmm1
mulss  0x4(%r14),%xmm1
mulss  (%r14),%xmm0
addss  %xmm1,%xmm0
addss  0x8(%r15),%xmm0
movss  %xmm0,(%r12)
movss  0x10(%r15),%xmm0
mulss  0x4(%r14),%xmm0
movss  0xc(%r15),%xmm1
mulss  (%r14),%xmm1
addss  %xmm0,%xmm1
addss  0x14(%r15),%xmm1
movss  %xmm1,0x4(%r12)
mov    $0x2,%eax
jmp    1287 <matrix_product+0x157>
lea    0xdbe(%rip),%rdi
mov    %ecx,%esi
mov    %r8d,%edx
call   1030 <fail@plt>
mov    $0x1,%edi
call   1050 <assert@plt>
sub    $0x8,%rsp
lea    0x14(%rsp),%rsi
lea    0x10(%rsp),%rdx
mov    %r12,%rdi
mov    %r15,%rcx
mov    %ebx,%r8d
mov    %ebx,%r9d
push   %r13
push   %rbx
push   %r14
call   1040 <matrix_product_clean@plt>
add    $0x20,%rsp
mov    0x8(%rsp),%eax
imul   0xc(%rsp),%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [27 x i8] c"bad matrix product (%d %d)\00"
define i32 @matrix_product(float* %0, float* %1, float* %2, i32 %3, i32 %4) {
%6 = alloca i32
%7 = alloca float*
%8 = alloca float*
%9 = alloca float*
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
store float* %0, float** %7
store float* %1, float** %8
store float* %2, float** %9
store i32 %3, i32* %10
store i32 %4, i32* %11
%18 = load i32, i32* %10
%19 = icmp eq i32 %18, 4
br i1 %19, label %20, label %24
20: ; preds = %5
%21 = load i32, i32* %11
%22 = icmp eq i32 %21, 4
br i1 %22, label %23, label %24
23: ; preds = %20
store i32 2, i32* %15
store i32 2, i32* %14
store i32 2, i32* %13
store i32 2, i32* %12
br label %116
24: ; preds = %20, %5
%25 = load i32, i32* %10
%26 = icmp eq i32 %25, 9
br i1 %26, label %27, label %31
27: ; preds = %24
%28 = load i32, i32* %11
%29 = icmp eq i32 %28, 9
br i1 %29, label %30, label %31
30: ; preds = %27
store i32 3, i32* %15
store i32 3, i32* %14
store i32 3, i32* %13
store i32 3, i32* %12
br label %115
31: ; preds = %27, %24
%32 = load i32, i32* %10
%33 = icmp eq i32 %32, 16
br i1 %33, label %34, label %38
34: ; preds = %31
%35 = load i32, i32* %11
%36 = icmp eq i32 %35, 16
br i1 %36, label %37, label %38
37: ; preds = %34
store i32 4, i32* %15
store i32 4, i32* %14
store i32 4, i32* %13
store i32 4, i32* %12
br label %114
38: ; preds = %34, %31
%39 = load i32, i32* %10
%40 = icmp eq i32 %39, 9
br i1 %40, label %41, label %45
41: ; preds = %38
%42 = load i32, i32* %11
%43 = icmp eq i32 %42, 3
br i1 %43, label %44, label %45
44: ; preds = %41
store i32 3, i32* %14
store i32 3, i32* %13
store i32 3, i32* %12
store i32 1, i32* %15
br label %113
45: ; preds = %41, %38
%46 = load i32, i32* %10
%47 = icmp eq i32 %46, 4
br i1 %47, label %48, label %52
48: ; preds = %45
%49 = load i32, i32* %11
%50 = icmp eq i32 %49, 2
br i1 %50, label %51, label %52
51: ; preds = %48
store i32 2, i32* %14
store i32 2, i32* %13
store i32 2, i32* %12
store i32 1, i32* %15
br label %112
52: ; preds = %48, %45
%53 = load i32, i32* %10
%54 = icmp eq i32 %53, 1
br i1 %54, label %55, label %59
55: ; preds = %52
%56 = load i32, i32* %11
%57 = icmp eq i32 %56, 1
br i1 %57, label %58, label %59
58: ; preds = %55
store i32 1, i32* %15
store i32 1, i32* %14
store i32 1, i32* %13
store i32 1, i32* %12
br label %111
59: ; preds = %55, %52
%60 = load i32, i32* %10
%61 = icmp eq i32 %60, 6
br i1 %61, label %62, label %106
62: ; preds = %59
%63 = load i32, i32* %11
%64 = icmp eq i32 %63, 2
br i1 %64, label %65, label %106
65: ; preds = %62
%66 = load float*, float** %8
%67 = getelementptr inbounds float, float* %66, i64 0
%68 = load float, float* %67
%69 = load float*, float** %9
%70 = getelementptr inbounds float, float* %69, i64 0
%71 = load float, float* %70
%72 = load float*, float** %8
%73 = getelementptr inbounds float, float* %72, i64 1
%74 = load float, float* %73
%75 = load float*, float** %9
%76 = getelementptr inbounds float, float* %75, i64 1
%77 = load float, float* %76
%78 = fmul float %74, %77
%79 = call float @llvm.fmuladd.f32(float %68, float %71, float %78)
%80 = load float*, float** %8
%81 = getelementptr inbounds float, float* %80, i64 2
%82 = load float, float* %81
%83 = fadd float %79, %82
%84 = load float*, float** %7
%85 = getelementptr inbounds float, float* %84, i64 0
store float %83, float* %85
%86 = load float*, float** %8
%87 = getelementptr inbounds float, float* %86, i64 3
%88 = load float, float* %87
%89 = load float*, float** %9
%90 = getelementptr inbounds float, float* %89, i64 0
%91 = load float, float* %90
%92 = load float*, float** %8
%93 = getelementptr inbounds float, float* %92, i64 4
%94 = load float, float* %93
%95 = load float*, float** %9
%96 = getelementptr inbounds float, float* %95, i64 1
%97 = load float, float* %96
%98 = fmul float %94, %97
%99 = call float @llvm.fmuladd.f32(float %88, float %91, float %98)
%100 = load float*, float** %8
%101 = getelementptr inbounds float, float* %100, i64 5
%102 = load float, float* %101
%103 = fadd float %99, %102
%104 = load float*, float** %7
%105 = getelementptr inbounds float, float* %104, i64 1
store float %103, float* %105
store i32 2, i32* %6
br label %133
106: ; preds = %62, %59
%107 = load i32, i32* %10
%108 = load i32, i32* %11
%109 = call i32 @fail(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i32 %107, i32 %108)
br label %110
110: ; preds = %106
br label %111
111: ; preds = %110, %58
br label %112
112: ; preds = %111, %51
br label %113
113: ; preds = %112, %44
br label %114
114: ; preds = %113, %37
br label %115
115: ; preds = %114, %30
br label %116
116: ; preds = %115, %23
%117 = load i32, i32* %13
%118 = load i32, i32* %14
%119 = icmp eq i32 %117, %118
%120 = zext i1 %119 to i32
%121 = call i32 @assert(i32 %120)
%122 = load float*, float** %7
%123 = load float*, float** %8
%124 = load i32, i32* %12
%125 = load i32, i32* %13
%126 = load float*, float** %9
%127 = load i32, i32* %14
%128 = load i32, i32* %15
%129 = call i32 @matrix_product_clean(float* %122, i32* %16, i32* %17, float* %123, i32 %124, i32 %125, float* %126, i32 %127, i32 %128)
%130 = load i32, i32* %16
%131 = load i32, i32* %17
%132 = mul nsw i32 %130, %131
store i32 %132, i32* %6
br label %133
133: ; preds = %116, %65
%134 = load i32, i32* %6
ret i32 %134
}

LLVM IR (-O2):
@.str = [27 x i8] c"bad matrix product (%d %d)\00"
define i32 @matrix_product(float* %0, float* %1, float* %2, i32 %3, i32 %4) {
%6 = alloca i32
%7 = alloca i32
%8 = icmp eq i32 %3, 4
%9 = icmp eq i32 %4, 4
%10 = and i1 %8, %9
br i1 %10, label %58, label %11
11: ; preds = %5
%12 = icmp eq i32 %3, 9
%13 = icmp eq i32 %4, 9
%14 = and i1 %12, %13
br i1 %14, label %58, label %15
15: ; preds = %11
%16 = icmp eq i32 %3, 16
%17 = icmp eq i32 %4, 16
%18 = and i1 %16, %17
br i1 %18, label %58, label %19
19: ; preds = %15
%20 = icmp eq i32 %4, 3
%21 = and i1 %12, %20
br i1 %21, label %58, label %22
22: ; preds = %19
%23 = icmp eq i32 %4, 2
%24 = and i1 %8, %23
br i1 %24, label %58, label %25
25: ; preds = %22
%26 = icmp eq i32 %3, 1
%27 = icmp eq i32 %4, 1
%28 = and i1 %26, %27
br i1 %28, label %58, label %29
29: ; preds = %25
%30 = icmp eq i32 %3, 6
%31 = and i1 %30, %23
br i1 %31, label %32, label %56
32: ; preds = %29
%33 = load float, float* %1
%34 = load float, float* %2
%35 = getelementptr inbounds float, float* %1, i64 1
%36 = load float, float* %35
%37 = getelementptr inbounds float, float* %2, i64 1
%38 = load float, float* %37
%39 = fmul float %36, %38
%40 = tail call float @llvm.fmuladd.f32(float %33, float %34, float %39)
%41 = getelementptr inbounds float, float* %1, i64 2
%42 = load float, float* %41
%43 = fadd float %42, %40
store float %43, float* %0
%44 = getelementptr inbounds float, float* %1, i64 3
%45 = load float, float* %44
%46 = load float, float* %2
%47 = getelementptr inbounds float, float* %1, i64 4
%48 = load float, float* %47
%49 = load float, float* %37
%50 = fmul float %48, %49
%51 = tail call float @llvm.fmuladd.f32(float %45, float %46, float %50)
%52 = getelementptr inbounds float, float* %1, i64 5
%53 = load float, float* %52
%54 = fadd float %53, %51
%55 = getelementptr inbounds float, float* %0, i64 1
store float %54, float* %55
br label %68
56: ; preds = %29
%57 = tail call i32 @fail(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i32 %3, i32 %4)
br label %58
58: ; preds = %25, %22, %19, %15, %11, %5, %56
%59 = phi i32 [ undef, %56 ], [ 2, %5 ], [ 3, %11 ], [ 4, %15 ], [ 3, %19 ], [ 2, %22 ], [ 1, %25 ]
%60 = phi i32 [ undef, %56 ], [ 2, %5 ], [ 3, %11 ], [ 4, %15 ], [ 1, %19 ], [ 1, %22 ], [ 1, %25 ]
%61 = tail call i32 @assert(i32 1)
%62 = bitcast i32* %6 to i8*
%63 = bitcast i32* %7 to i8*
%64 = call i32 @matrix_product_clean(float* %0, i32* %6, i32* %7, float* %1, i32 %59, i32 %59, float* %2, i32 %59, i32 %60)
%65 = load i32, i32* %6
%66 = load i32, i32* %7
%67 = mul nsw i32 %66, %65
br label %68
68: ; preds = %58, %32
%69 = phi i32 [ %67, %58 ], [ 2, %32 ]
ret i32 %69
}