#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 */
double *allocMat(int const);
int /*<<< orphan*/ clearMat(int const, double *);
double diffMat(int const, double *, double const *);
double getTime();
int /*<<< orphan*/ printf(char *, double);
double checkMulMatFunc(void (*func)(const int matsize, const double *mata,
                                    const double *matb, double *matc),
                       const int matsize, const double *mata,
                       const double *matb, const double *matc) {
  double start, end;
  double *tmp_matc;
  double calcerror;
  double time;
  tmp_matc = allocMat(matsize);
  clearMat(matsize, tmp_matc);
  start = getTime();
  func(matsize, mata, matb, tmp_matc);
  end = getTime();
  time = end - start;
  printf("Time=%f sec , ", time);
  calcerror = diffMat(matsize, tmp_matc, matc);
  if (calcerror > 0.00001) {
    printf("\tWrong Calculation! (error=%.10f)\n", calcerror);
  } else {
    printf("\tOK (error =%.10f)\n", calcerror);
  }
  return (time);
}


x86 assembly (clang, -O0):
<checkMulMatFunc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    -0xc(%rbp),%edi
call   1060 <allocMat@plt>
mov    %rax,-0x40(%rbp)
mov    -0xc(%rbp),%edi
mov    -0x40(%rbp),%rsi
call   1070 <clearMat@plt>
mov    $0x0,%al
call   1040 <getTime@plt>
movsd  %xmm0,-0x30(%rbp)
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    -0x40(%rbp),%rcx
call   *%rax
mov    $0x0,%al
call   1040 <getTime@plt>
movsd  %xmm0,-0x38(%rbp)
movsd  -0x38(%rbp),%xmm0
subsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x50(%rbp),%xmm0
lea    0xe3d(%rip),%rdi
call   1050 <printf@plt>
mov    -0xc(%rbp),%edi
mov    -0x40(%rbp),%rsi
mov    -0x28(%rbp),%rdx
call   1030 <diffMat@plt>
movsd  %xmm0,-0x48(%rbp)
movsd  -0x48(%rbp),%xmm0
movsd  0xe0e(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    1212 <checkMulMatFunc+0xc2>
movsd  -0x48(%rbp),%xmm0
lea    0xe0f(%rip),%rdi
call   1050 <printf@plt>
jmp    1223 <checkMulMatFunc+0xd3>
movsd  -0x48(%rbp),%xmm0
lea    0xe1c(%rip),%rdi
call   1050 <printf@plt>
movsd  -0x50(%rbp),%xmm0
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<checkMulMatFunc>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r8,%r14
mov    %rcx,%r15
mov    %rdx,%r12
mov    %esi,%ebp
mov    %rdi,%r13
mov    %esi,%edi
call   1060 <allocMat@plt>
mov    %rax,%rbx
mov    %ebp,%edi
mov    %rax,%rsi
call   1070 <clearMat@plt>
xor    %eax,%eax
call   1040 <getTime@plt>
movsd  %xmm0,(%rsp)
mov    %ebp,%edi
mov    %r12,%rsi
mov    %r15,%rdx
mov    %rbx,%rcx
call   *%r13
xor    %eax,%eax
call   1040 <getTime@plt>
subsd  (%rsp),%xmm0
movsd  %xmm0,(%rsp)
lea    0xe59(%rip),%rdi
call   1050 <printf@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r14,%rdx
call   1030 <diffMat@plt>
ucomisd 0xe37(%rip),%xmm0
lea    0xe47(%rip),%rax
lea    0xe63(%rip),%rdi
cmova  %rax,%rdi
call   1050 <printf@plt>
movsd  (%rsp),%xmm0
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [15 x i8] c"Time=%f sec , \00"
@.str.1 = [35 x i8] c"\09Wrong Calculation! (error=%.10f)\0A\00"
@.str.2 = [20 x i8] c"\09OK (error =%.10f)\0A\00"
define double @checkMulMatFunc(void (i32, double*, double*, double*)* %0, i32 %1, double* %2, double* %3, double* %4) {
%6 = alloca void (i32, double*, double*, double*)*
%7 = alloca i32
%8 = alloca double*
%9 = alloca double*
%10 = alloca double*
%11 = alloca double
%12 = alloca double
%13 = alloca double*
%14 = alloca double
%15 = alloca double
store void (i32, double*, double*, double*)* %0, void (i32, double*, double*, double*)** %6
store i32 %1, i32* %7
store double* %2, double** %8
store double* %3, double** %9
store double* %4, double** %10
%16 = load i32, i32* %7
%17 = call double* @allocMat(i32 %16)
store double* %17, double** %13
%18 = load i32, i32* %7
%19 = load double*, double** %13
%20 = call i32 @clearMat(i32 %18, double* %19)
%21 = call double (...) @getTime()
store double %21, double* %11
%22 = load void (i32, double*, double*, double*)*, void (i32, double*, double*, double*)** %6
%23 = load i32, i32* %7
%24 = load double*, double** %8
%25 = load double*, double** %9
%26 = load double*, double** %13
%27 = call double (...) @getTime()
store double %27, double* %12
%28 = load double, double* %12
%29 = load double, double* %11
%30 = fsub double %28, %29
store double %30, double* %15
%31 = load double, double* %15
%32 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), double %31)
%33 = load i32, i32* %7
%34 = load double*, double** %13
%35 = load double*, double** %10
%36 = call double @diffMat(i32 %33, double* %34, double* %35)
store double %36, double* %14
%37 = load double, double* %14
%38 = fcmp ogt double %37, 1.000000e-05
br i1 %38, label %39, label %42
39: ; preds = %5
%40 = load double, double* %14
%41 = call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0), double %40)
br label %45
42: ; preds = %5
%43 = load double, double* %14
%44 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), double %43)
br label %45
45: ; preds = %42, %39
%46 = load double, double* %15
ret double %46
}

LLVM IR (-O2):
@.str = [15 x i8] c"Time=%f sec , \00"
@.str.1 = [35 x i8] c"\09Wrong Calculation! (error=%.10f)\0A\00"
@.str.2 = [20 x i8] c"\09OK (error =%.10f)\0A\00"
define double @checkMulMatFunc(void (i32, double*, double*, double*)* nocapture %0, i32 %1, double* %2, double* %3, double* %4) {
%6 = tail call double* @allocMat(i32 %1)
%7 = tail call i32 @clearMat(i32 %1, double* %6)
%8 = tail call double (...) @getTime()
tail call void %0(i32 %1, double* %2, double* %3, double* %6)
%9 = tail call double (...) @getTime()
%10 = fsub double %9, %8
%11 = tail call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), double %10)
%12 = tail call double @diffMat(i32 %1, double* %6, double* %4)
%13 = fcmp ogt double %12, 1.000000e-05
%14 = select i1 %13, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0)
%15 = tail call i32 @printf(i8* %14, double %12)
ret double %10
}