#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 */
float FLT_EPSILON;
float fabsf(float);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ matmul(float const *, float const *, float *);
int /*<<< orphan*/ matmul_ref(float const *, float const *, float *);
int /*<<< orphan*/ stderr;
int main(int argc, char **argv) {
  const float a[4 * 4] = {1.0f, 1.1f, 1.2f, 1.3f, 2.0f, 2.1f, 2.2f, 2.3f,
                          3.0f, 3.1f, 3.2f, 3.3f, 4.0f, 4.1f, 4.2f, 4.3f};
  const float b[4 * 4] = {1.0f,  2.0f,  3.0f,  4.0f,  5.0f,  6.0f,
                          7.0f,  8.0f,  9.0f,  10.0f, 11.0f, 12.0f,
                          13.0f, 14.0f, 15.0f, 16.0f};
  float c[4 * 4], c_ref[4 * 4];
  matmul(a, b, c);
  matmul_ref(a, b, c_ref);
  for (size_t i = 0; i < 4 * 4; i++) {
    const float error = fabsf(c[i] - c_ref[i]) / FLT_EPSILON;
    if (error >= 128.0f) {
      fprintf(stderr, "UNIT TEST FAILED\n");
      return 1;
    }
  }
  fprintf(stderr, "UNIT TEST PASSED\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x50(%rbp),%rdi
lea    0xebc(%rip),%rsi
mov    $0x40,%edx
call   1050 <memcpy@plt>
lea    -0x90(%rbp),%rdi
lea    0xee4(%rip),%rsi
mov    $0x40,%edx
call   1050 <memcpy@plt>
lea    -0x50(%rbp),%rdi
lea    -0x90(%rbp),%rsi
lea    -0xd0(%rbp),%rdx
call   1060 <matmul@plt>
lea    -0x50(%rbp),%rdi
lea    -0x90(%rbp),%rsi
lea    -0x110(%rbp),%rdx
call   1030 <matmul_ref@plt>
movq   $0x0,-0x118(%rbp)
cmpq   $0x10,-0x118(%rbp)
10
jae    1261 <main+0x121>
mov    -0x118(%rbp),%rax
movss  -0xd0(%rbp,%rax,4),%xmm0
ff ff
mov    -0x118(%rbp),%rax
subss  -0x110(%rbp,%rax,4),%xmm0
ff ff
movaps 0xe1c(%rip),%xmm1
pand   %xmm1,%xmm0
mov    0x2de1(%rip),%rax
divss  (%rax),%xmm0
movss  %xmm0,-0x11c(%rbp)
ff
movss  -0x11c(%rbp),%xmm0
ff
movss  0xde5(%rip),%xmm1
ucomiss %xmm1,%xmm0
jb     1245 <main+0x105>
mov    0x2dad(%rip),%rax
mov    (%rax),%edi
lea    0xe6c(%rip),%rsi
call   1040 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    127d <main+0x13d>
jmp    124a <main+0x10a>
mov    -0x118(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x118(%rbp)
jmp    11bf <main+0x7f>
mov    0x2d70(%rip),%rax
mov    (%rax),%edi
lea    0xe41(%rip),%rsi
call   1040 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x108,%rsp
movaps 0xf0f(%rip),%xmm0
movaps %xmm0,0x70(%rsp)
movaps 0xef3(%rip),%xmm0
movaps %xmm0,0x60(%rsp)
movaps 0xed7(%rip),%xmm0
movaps %xmm0,0x50(%rsp)
movaps 0xebb(%rip),%xmm0
movaps %xmm0,0x40(%rsp)
movaps 0xf1f(%rip),%xmm0
movaps %xmm0,0x30(%rsp)
movaps 0xf03(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movaps 0xee7(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movaps 0xecb(%rip),%xmm0
movaps %xmm0,(%rsp)
lea    0x40(%rsp),%rbx
mov    %rsp,%r14
lea    0xc0(%rsp),%rdx
mov    %rbx,%rdi
mov    %r14,%rsi
call   1050 <matmul@plt>
lea    0x80(%rsp),%rdx
mov    %rbx,%rdi
mov    %r14,%rsi
call   1030 <matmul_ref@plt>
mov    0x2e12(%rip),%rax
movss  (%rax),%xmm0
xor    %eax,%eax
movaps 0xe25(%rip),%xmm1
lea    0xebe(%rip),%rcx
movss  0xe26(%rip),%xmm2
lea    0xec1(%rip),%rsi
mov    $0x1,%ebx
cs nopw 0x0(%rax,%rax,1)
movss  0xc0(%rsp,%rax,4),%xmm3
subss  0x80(%rsp,%rax,4),%xmm3
andps  %xmm1,%xmm3
divss  %xmm0,%xmm3
ucomiss %xmm2,%xmm3
jae    124a <main+0x11a>
movss  0xc4(%rsp,%rax,4),%xmm3
subss  0x84(%rsp,%rax,4),%xmm3
andps  %xmm1,%xmm3
divss  %xmm0,%xmm3
ucomiss %xmm2,%xmm3
jae    124a <main+0x11a>
add    $0x2,%rax
cmp    $0x10,%rax
jne    1200 <main+0xd0>
xor    %ebx,%ebx
jmp    124d <main+0x11d>
mov    %rcx,%rsi
mov    0x2d84(%rip),%rax
mov    (%rax),%edi
call   1040 <fprintf@plt>
mov    %ebx,%eax
add    $0x108,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@__const.main.a = [16 x float] [float 1.000000e+00, float 0x3FF19999A0000000, float 0x3FF3333340000000, float 0x3FF4CCCCC0000000, float 2.000000e+00, float 0x4000CCCCC0000000, float 0x40019999A0000000, float 0x4002666660000000, float 3.000000e+00, float 0x4008CCCCC0000000, float 0x40099999A0000000, float 0x400A666660000000, float 4.000000e+00, float 0x4010666660000000, float 0x4010CCCCC0000000, float 0x4011333340000000]
@__const.main.b = [16 x float] [float 1.000000e+00, float 2.000000e+00, float 3.000000e+00, float 4.000000e+00, float 5.000000e+00, float 6.000000e+00, float 7.000000e+00, float 8.000000e+00, float 9.000000e+00, float 1.000000e+01, float 1.100000e+01, float 1.200000e+01, float 1.300000e+01, float 1.400000e+01, float 1.500000e+01, float 1.600000e+01]
@FLT_EPSILON = global float 0.000000e+00
@stderr = global i32 0
@.str = [18 x i8] c"UNIT TEST FAILED\0A\00"
@.str.1 = [18 x i8] c"UNIT TEST PASSED\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [16 x float]
%7 = alloca [16 x float]
%8 = alloca [16 x float]
%9 = alloca [16 x float]
%10 = alloca i64
%11 = alloca float
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = bitcast [16 x float]* %6 to i8*
%13 = bitcast [16 x float]* %7 to i8*
%14 = getelementptr inbounds [16 x float], [16 x float]* %6, i64 0, i64 0
%15 = getelementptr inbounds [16 x float], [16 x float]* %7, i64 0, i64 0
%16 = getelementptr inbounds [16 x float], [16 x float]* %8, i64 0, i64 0
%17 = call i32 @matmul(float* %14, float* %15, float* %16)
%18 = getelementptr inbounds [16 x float], [16 x float]* %6, i64 0, i64 0
%19 = getelementptr inbounds [16 x float], [16 x float]* %7, i64 0, i64 0
%20 = getelementptr inbounds [16 x float], [16 x float]* %9, i64 0, i64 0
%21 = call i32 @matmul_ref(float* %18, float* %19, float* %20)
store i64 0, i64* %10
br label %22
22: ; preds = %42, %2
%23 = load i64, i64* %10
%24 = icmp ult i64 %23, 16
br i1 %24, label %25, label %45
25: ; preds = %22
%26 = load i64, i64* %10
%27 = getelementptr inbounds [16 x float], [16 x float]* %8, i64 0, i64 %26
%28 = load float, float* %27
%29 = load i64, i64* %10
%30 = getelementptr inbounds [16 x float], [16 x float]* %9, i64 0, i64 %29
%31 = load float, float* %30
%32 = fsub float %28, %31
%33 = call float @llvm.fabs.f32(float %32)
%34 = load float, float* @FLT_EPSILON
%35 = fdiv float %33, %34
store float %35, float* %11
%36 = load float, float* %11
%37 = fcmp oge float %36, 1.280000e+02
br i1 %37, label %38, label %41
38: ; preds = %25
%39 = load i32, i32* @stderr
%40 = call i32 @fprintf(i32 %39, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %48
41: ; preds = %25
br label %42
42: ; preds = %41
%43 = load i64, i64* %10
%44 = add i64 %43, 1
store i64 %44, i64* %10
br label %22
45: ; preds = %22
%46 = load i32, i32* @stderr
%47 = call i32 @fprintf(i32 %46, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %3
br label %48
48: ; preds = %45, %38
%49 = load i32, i32* %3
ret i32 %49
}

LLVM IR (-O2):
@__const.main.a = [16 x float] [float 1.000000e+00, float 0x3FF19999A0000000, float 0x3FF3333340000000, float 0x3FF4CCCCC0000000, float 2.000000e+00, float 0x4000CCCCC0000000, float 0x40019999A0000000, float 0x4002666660000000, float 3.000000e+00, float 0x4008CCCCC0000000, float 0x40099999A0000000, float 0x400A666660000000, float 4.000000e+00, float 0x4010666660000000, float 0x4010CCCCC0000000, float 0x4011333340000000]
@__const.main.b = [16 x float] [float 1.000000e+00, float 2.000000e+00, float 3.000000e+00, float 4.000000e+00, float 5.000000e+00, float 6.000000e+00, float 7.000000e+00, float 8.000000e+00, float 9.000000e+00, float 1.000000e+01, float 1.100000e+01, float 1.200000e+01, float 1.300000e+01, float 1.400000e+01, float 1.500000e+01, float 1.600000e+01]
@FLT_EPSILON = global float 0.000000e+00
@stderr = global i32 0
@.str = [18 x i8] c"UNIT TEST FAILED\0A\00"
@.str.1 = [18 x i8] c"UNIT TEST PASSED\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [16 x float]
%4 = alloca [16 x float]
%5 = alloca [16 x float]
%6 = alloca [16 x float]
%7 = bitcast [16 x float]* %3 to i8*
%8 = bitcast [16 x float]* %4 to i8*
%9 = bitcast [16 x float]* %5 to i8*
%10 = bitcast [16 x float]* %6 to i8*
%11 = getelementptr inbounds [16 x float], [16 x float]* %3, i64 0, i64 0
%12 = getelementptr inbounds [16 x float], [16 x float]* %4, i64 0, i64 0
%13 = getelementptr inbounds [16 x float], [16 x float]* %5, i64 0, i64 0
%14 = call i32 @matmul(float* %11, float* %12, float* %13)
%15 = getelementptr inbounds [16 x float], [16 x float]* %6, i64 0, i64 0
%16 = call i32 @matmul_ref(float* %11, float* %12, float* %15)
%17 = load float, float* @FLT_EPSILON
br label %31
18: ; preds = %31
%19 = or i64 %32, 1
%20 = getelementptr inbounds [16 x float], [16 x float]* %5, i64 0, i64 %19
%21 = load float, float* %20
%22 = getelementptr inbounds [16 x float], [16 x float]* %6, i64 0, i64 %19
%23 = load float, float* %22
%24 = fsub float %21, %23
%25 = call float @llvm.fabs.f32(float %24)
%26 = fdiv float %25, %17
%27 = fcmp ult float %26, 1.280000e+02
br i1 %27, label %28, label %41
28: ; preds = %18
%29 = add nuw nsw i64 %32, 2
%30 = icmp eq i64 %29, 16
br i1 %30, label %41, label %31
31: ; preds = %28, %2
%32 = phi i64 [ 0, %2 ], [ %29, %28 ]
%33 = getelementptr inbounds [16 x float], [16 x float]* %5, i64 0, i64 %32
%34 = load float, float* %33
%35 = getelementptr inbounds [16 x float], [16 x float]* %6, i64 0, i64 %32
%36 = load float, float* %35
%37 = fsub float %34, %36
%38 = call float @llvm.fabs.f32(float %37)
%39 = fdiv float %38, %17
%40 = fcmp ult float %39, 1.280000e+02
br i1 %40, label %18, label %41
41: ; preds = %28, %18, %31
%42 = phi i8* [ getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), %31 ], [ getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), %18 ], [ getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), %28 ]
%43 = phi i32 [ 1, %31 ], [ 1, %18 ], [ 0, %28 ]
%44 = load i32, i32* @stderr
%45 = call i32 @fprintf(i32 %44, i8* %42)
ret i32 %43
}