#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 */
struct timeval {
  scalar_t__ tv_usec;
  scalar_t__ tv_sec;
};

/* Variables and functions */
int /*<<< orphan*/ FloatComputeBound(float *, int const, float, float, float,
                                     float, float, int /*<<< orphan*/);
int /*<<< orphan*/ free(float *);
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/);
scalar_t__ malloc(size_t);
int /*<<< orphan*/ printf(char *, int const, double);
void run(const int M) {
  float *A_cpu;
  const int N = 576;
  const int K = M * N;
  size_t bytes = sizeof(float) * K;
  A_cpu = (float *)malloc(bytes);
  int i;
  for (i = 0; i < K; i++) {
    A_cpu[i] = (float)i / (float)(K - 1);
  }
  struct timeval startTime, endTime;
  gettimeofday(&startTime, 0);
  FloatComputeBound(A_cpu, M * N, 1.125f, 0.125f, 0.5f, 1.25f, 1.25f, 0);
  gettimeofday(&endTime, 0);
  double ms = (((double)endTime.tv_sec - (double)startTime.tv_sec) * 1000.0 +
               ((double)endTime.tv_usec - (double)startTime.tv_usec) / 1000.0);
  double s = ms / 1000.0;
  double GFLOPs = (2 * 0 + 2048 + 2048) / 1.0e6 * 1024 * K / 1.0e3;
  double GFLOPsPerSec = (GFLOPs / s);
  printf("%d\t\t%f\n", M, GFLOPsPerSec);
  free(A_cpu);
}


x86 assembly (clang, -O0):
<run>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x240,-0x14(%rbp)
imul   $0x240,-0x4(%rbp),%eax
mov    %eax,-0x18(%rbp)
movslq -0x18(%rbp),%rax
shl    $0x2,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1060 <malloc@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    11c6 <run+0x76>
cvtsi2ssl -0x24(%rbp),%xmm0
mov    -0x18(%rbp),%eax
sub    $0x1,%eax
cvtsi2ss %eax,%xmm1
divss  %xmm1,%xmm0
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
movss  %xmm0,(%rax,%rcx,4)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    118c <run+0x3c>
lea    -0x38(%rbp),%rdi
xor    %esi,%esi
call   1050 <gettimeofday@plt>
mov    -0x10(%rbp),%rdi
imul   $0x240,-0x4(%rbp),%esi
movss  0xe2c(%rip),%xmm0
movss  0xe28(%rip),%xmm1
movss  0xe24(%rip),%xmm2
movss  0xe20(%rip),%xmm4
xor    %edx,%edx
movaps %xmm4,%xmm3
call   1070 <FloatComputeBound@plt>
lea    -0x48(%rbp),%rdi
xor    %esi,%esi
call   1050 <gettimeofday@plt>
cvtsi2sdq -0x40(%rbp),%xmm0
cvtsi2sdq -0x30(%rbp),%xmm1
subsd  %xmm1,%xmm0
cvtsi2sdq -0x48(%rbp),%xmm1
cvtsi2sdq -0x38(%rbp),%xmm2
subsd  %xmm2,%xmm1
movsd  0xdc7(%rip),%xmm2
divsd  %xmm2,%xmm1
movsd  0xdbb(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x50(%rbp),%xmm0
movsd  0xda1(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x58(%rbp)
cvtsi2sdl -0x18(%rbp),%xmm1
movsd  0xd93(%rip),%xmm0
mulsd  %xmm1,%xmm0
movsd  0xd7f(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x60(%rbp)
movsd  -0x60(%rbp),%xmm0
divsd  -0x58(%rbp),%xmm0
movsd  %xmm0,-0x68(%rbp)
mov    -0x4(%rbp),%esi
movsd  -0x68(%rbp),%xmm0
lea    0xd78(%rip),%rdi
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<run>:
push   %rbp
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    %edi,%r14d
mov    %edi,%eax
shl    $0x6,%eax
lea    (%rax,%rax,8),%ebp
movslq %ebp,%rdi
shl    $0x2,%rdi
call   1060 <malloc@plt>
mov    %rax,%rbx
test   %r14d,%r14d
jle    1219 <run+0xc9>
lea    -0x1(%rbp),%eax
cvtsi2ss %eax,%xmm0
cmp    $0x2,%ebp
mov    $0x1,%eax
cmovge %ebp,%eax
cmp    $0x4,%eax
jae    1196 <run+0x46>
xor    %ecx,%ecx
jmp    1200 <run+0xb0>
mov    %eax,%ecx
and    $0x7fffffc0,%ecx
movaps %xmm0,%xmm1
shufps $0x0,%xmm0,%xmm1
lea    -0x4(%rcx),%rdx
shr    $0x2,%rdx
mov    %rbx,%rsi
add    $0x10,%rsi
add    $0x1,%rdx
movaps 0xe41(%rip),%xmm2
movdqa 0xe49(%rip),%xmm3
movdqa 0xe51(%rip),%xmm4
nop
cvtdq2ps %xmm2,%xmm5
divps  %xmm1,%xmm5
movups %xmm5,-0x10(%rsi)
movaps %xmm2,%xmm5
paddd  %xmm3,%xmm5
cvtdq2ps %xmm5,%xmm5
divps  %xmm1,%xmm5
movups %xmm5,(%rsi)
paddd  %xmm4,%xmm2
add    $0x20,%rsi
add    $0xfffffffffffffffe,%rdx
jne    11d0 <run+0x80>
cmp    %rax,%rcx
je     1219 <run+0xc9>
nopl   (%rax)
xorps  %xmm1,%xmm1
cvtsi2ss %ecx,%xmm1
divss  %xmm0,%xmm1
movss  %xmm1,(%rbx,%rcx,4)
add    $0x1,%rcx
cmp    %rcx,%rax
jne    1200 <run+0xb0>
lea    0x10(%rsp),%rdi
xor    %esi,%esi
call   1050 <gettimeofday@plt>
movss  0xe13(%rip),%xmm0
movss  0xe0f(%rip),%xmm1
movss  0xe0b(%rip),%xmm2
movss  0xe07(%rip),%xmm3
mov    %rbx,%rdi
mov    %ebp,%esi
movaps %xmm3,%xmm4
xor    %edx,%edx
call   1070 <FloatComputeBound@plt>
mov    %rsp,%rdi
xor    %esi,%esi
call   1050 <gettimeofday@plt>
xorps  %xmm1,%xmm1
cvtsi2sdq 0x8(%rsp),%xmm1
xorps  %xmm0,%xmm0
cvtsi2sdq 0x18(%rsp),%xmm0
subsd  %xmm0,%xmm1
xorps  %xmm2,%xmm2
cvtsi2sdq (%rsp),%xmm2
xorps  %xmm0,%xmm0
cvtsi2sdq 0x10(%rsp),%xmm0
subsd  %xmm0,%xmm2
movsd  0xdbb(%rip),%xmm0
divsd  %xmm0,%xmm2
mulsd  %xmm0,%xmm1
xorps  %xmm0,%xmm0
cvtsi2sd %ebp,%xmm0
addsd  %xmm2,%xmm1
mulsd  0xda8(%rip),%xmm0
unpcklpd %xmm1,%xmm0
divpd  0xd74(%rip),%xmm0
movapd %xmm0,%xmm1
unpckhpd %xmm0,%xmm1
divsd  %xmm1,%xmm0
lea    0xd91(%rip),%rdi
mov    %r14d,%esi
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.timeval = type { i64, i64 }
@.str = [8 x i8] c"%d\09\09%f\0A\00"
define void @run(i32 %0) {
%2 = alloca i32
%3 = alloca float*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i64
%7 = alloca i32
%8 = alloca %struct.timeval
%9 = alloca %struct.timeval
%10 = alloca double
%11 = alloca double
%12 = alloca double
%13 = alloca double
store i32 %0, i32* %2
store i32 576, i32* %4
%14 = load i32, i32* %2
%15 = mul nsw i32 %14, 576
store i32 %15, i32* %5
%16 = load i32, i32* %5
%17 = sext i32 %16 to i64
%18 = mul i64 4, %17
store i64 %18, i64* %6
%19 = load i64, i64* %6
%20 = call i64 @malloc(i64 %19)
%21 = inttoptr i64 %20 to float*
store float* %21, float** %3
store i32 0, i32* %7
br label %22
22: ; preds = %37, %1
%23 = load i32, i32* %7
%24 = load i32, i32* %5
%25 = icmp slt i32 %23, %24
br i1 %25, label %26, label %40
26: ; preds = %22
%27 = load i32, i32* %7
%28 = sitofp i32 %27 to float
%29 = load i32, i32* %5
%30 = sub nsw i32 %29, 1
%31 = sitofp i32 %30 to float
%32 = fdiv float %28, %31
%33 = load float*, float** %3
%34 = load i32, i32* %7
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds float, float* %33, i64 %35
store float %32, float* %36
br label %37
37: ; preds = %26
%38 = load i32, i32* %7
%39 = add nsw i32 %38, 1
store i32 %39, i32* %7
br label %22
40: ; preds = %22
%41 = call i32 @gettimeofday(%struct.timeval* %8, i32 0)
%42 = load float*, float** %3
%43 = load i32, i32* %2
%44 = mul nsw i32 %43, 576
%45 = call i32 @FloatComputeBound(float* %42, i32 %44, float 1.125000e+00, float 1.250000e-01, float 5.000000e-01, float 1.250000e+00, float 1.250000e+00, i32 0)
%46 = call i32 @gettimeofday(%struct.timeval* %9, i32 0)
%47 = getelementptr inbounds %struct.timeval, %struct.timeval* %9, i32 0, i32 1
%48 = load i64, i64* %47
%49 = sitofp i64 %48 to double
%50 = getelementptr inbounds %struct.timeval, %struct.timeval* %8, i32 0, i32 1
%51 = load i64, i64* %50
%52 = sitofp i64 %51 to double
%53 = fsub double %49, %52
%54 = getelementptr inbounds %struct.timeval, %struct.timeval* %9, i32 0, i32 0
%55 = load i64, i64* %54
%56 = sitofp i64 %55 to double
%57 = getelementptr inbounds %struct.timeval, %struct.timeval* %8, i32 0, i32 0
%58 = load i64, i64* %57
%59 = sitofp i64 %58 to double
%60 = fsub double %56, %59
%61 = fdiv double %60, 1.000000e+03
%62 = call double @llvm.fmuladd.f64(double %53, double 1.000000e+03, double %61)
store double %62, double* %10
%63 = load double, double* %10
%64 = fdiv double %63, 1.000000e+03
store double %64, double* %11
%65 = load i32, i32* %5
%66 = sitofp i32 %65 to double
%67 = fmul double 0x4010C6F7A0B5ED8D, %66
%68 = fdiv double %67, 1.000000e+03
store double %68, double* %12
%69 = load double, double* %12
%70 = load double, double* %11
%71 = fdiv double %69, %70
store double %71, double* %13
%72 = load i32, i32* %2
%73 = load double, double* %13
%74 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 %72, double %73)
%75 = load float*, float** %3
%76 = call i32 @free(float* %75)
ret void
}

LLVM IR (-O2):
%struct.timeval = type { i64, i64 }
@.str = [8 x i8] c"%d\09\09%f\0A\00"
define void @run(i32 %0) {
%2 = alloca %struct.timeval
%3 = alloca %struct.timeval
%4 = mul nsw i32 %0, 576
%5 = sext i32 %4 to i64
%6 = shl nsw i64 %5, 2
%7 = tail call i64 @malloc(i64 %6)
%8 = inttoptr i64 %7 to float*
%9 = icmp sgt i32 %0, 0
br i1 %9, label %10, label %53
10: ; preds = %1
%11 = add nsw i32 %4, -1
%12 = sitofp i32 %11 to float
%13 = call i32 @llvm.smax.i32(i32 %4, i32 1)
%14 = zext i32 %13 to i64
%15 = icmp ult i32 %13, 4
br i1 %15, label %43, label %16
16: ; preds = %10
%17 = and i64 %14, 2147483584
%18 = insertelement <4 x float> poison, float %12, i64 0
%19 = shufflevector <4 x float> %18, <4 x float> poison, <4 x i32> zeroinitializer
%20 = add nsw i64 %17, -4
%21 = lshr exact i64 %20, 2
br label %22
22: ; preds = %22, %16
%23 = phi i64 [ 0, %16 ], [ %36, %22 ]
%24 = phi <4 x i32> [ <i32 0, i32 1, i32 2, i32 3>, %16 ], [ %37, %22 ]
%25 = phi i64 [ 0, %16 ], [ %38, %22 ]
%26 = sitofp <4 x i32> %24 to <4 x float>
%27 = fdiv <4 x float> %26, %19
%28 = getelementptr inbounds float, float* %8, i64 %23
%29 = bitcast float* %28 to <4 x float>*
store <4 x float> %27, <4 x float>* %29
%30 = or i64 %23, 4
%31 = add <4 x i32> %24, <i32 4, i32 4, i32 4, i32 4>
%32 = sitofp <4 x i32> %31 to <4 x float>
%33 = fdiv <4 x float> %32, %19
%34 = getelementptr inbounds float, float* %8, i64 %30
%35 = bitcast float* %34 to <4 x float>*
store <4 x float> %33, <4 x float>* %35
%36 = add nuw i64 %23, 8
%37 = add <4 x i32> %24, <i32 8, i32 8, i32 8, i32 8>
%38 = add i64 %25, 2
%39 = or i64 %25, 1
%40 = icmp eq i64 %39, %21
br i1 %40, label %41, label %22
41: ; preds = %22
%42 = icmp eq i64 %17, %14
br i1 %42, label %53, label %43
43: ; preds = %10, %41
%44 = phi i64 [ 0, %10 ], [ %17, %41 ]
br label %45
45: ; preds = %43, %45
%46 = phi i64 [ %51, %45 ], [ %44, %43 ]
%47 = trunc i64 %46 to i32
%48 = sitofp i32 %47 to float
%49 = fdiv float %48, %12
%50 = getelementptr inbounds float, float* %8, i64 %46
store float %49, float* %50
%51 = add nuw nsw i64 %46, 1
%52 = icmp eq i64 %51, %14
br i1 %52, label %53, label %45
53: ; preds = %45, %41, %1
%54 = bitcast %struct.timeval* %2 to i8*
%55 = bitcast %struct.timeval* %3 to i8*
%56 = call i32 @gettimeofday(%struct.timeval* %2, i32 0)
%57 = call i32 @FloatComputeBound(float* %8, i32 %4, float 1.125000e+00, float 1.250000e-01, float 5.000000e-01, float 1.250000e+00, float 1.250000e+00, i32 0)
%58 = call i32 @gettimeofday(%struct.timeval* %3, i32 0)
%59 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 1
%60 = load i64, i64* %59
%61 = sitofp i64 %60 to double
%62 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 1
%63 = load i64, i64* %62
%64 = sitofp i64 %63 to double
%65 = fsub double %61, %64
%66 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 0
%67 = load i64, i64* %66
%68 = sitofp i64 %67 to double
%69 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 0
%70 = load i64, i64* %69
%71 = sitofp i64 %70 to double
%72 = fsub double %68, %71
%73 = fdiv double %72, 1.000000e+03
%74 = call double @llvm.fmuladd.f64(double %65, double 1.000000e+03, double %73)
%75 = sitofp i32 %4 to double
%76 = fmul double %75, 0x4010C6F7A0B5ED8D
%77 = insertelement <2 x double> poison, double %76, i64 0
%78 = insertelement <2 x double> %77, double %74, i64 1
%79 = fdiv <2 x double> %78, <double 1.000000e+03, double 1.000000e+03>
%80 = extractelement <2 x double> %79, i64 0
%81 = extractelement <2 x double> %79, i64 1
%82 = fdiv double %80, %81
%83 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 %0, double %82)
%84 = call i32 @free(float* %8)
ret void
}