; LLVM IR from csviragh/robotsim :: src (stat)

; Unoptimized IR (clang -disable-llvm-passes):
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

%struct.phase_t = type { ptr, ptr, ptr, ptr, i32, i32 }

@Avg = external hidden global double, align 8
@StDev = external hidden global double, align 8
@Min = external hidden global double, align 8
@Max = external hidden global double, align 8
@StatOfVelocity.AvgVelocity = external hidden global [3 x double], align 16
@StatOfVelocity.velLength = external hidden global double, align 8
@StatOfVelocity.StatVel = external hidden global [8 x double], align 16

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

declare double @VectAbs(ptr noundef) #1

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #2

; Function Attrs: nounwind
declare double @sqrt(double noundef) #3

; Function Attrs: nounwind uwtable
define dso_local ptr @StatOfVelocity(ptr noundef %0) #4 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #5
  call void @NullVect(ptr noundef @StatOfVelocity.AvgVelocity, i32 noundef 3)
  store double 0.000000e+00, ptr @Avg, align 8, !tbaa !9
  store double 0.000000e+00, ptr @StDev, align 8, !tbaa !9
  store double 2.000000e+222, ptr @Min, align 8, !tbaa !9
  store double 0.000000e+00, ptr @Max, align 8, !tbaa !9
  store double 0.000000e+00, ptr @StatOfVelocity.velLength, align 8, !tbaa !9
  store i32 0, ptr %3, align 4, !tbaa !11
  br label %5

5:                                                ; preds = %41, %1
  %6 = load i32, ptr %3, align 4, !tbaa !11
  %7 = load ptr, ptr %2, align 8, !tbaa !5
  %8 = getelementptr inbounds %struct.phase_t, ptr %7, i32 0, i32 5
  %9 = load i32, ptr %8, align 4, !tbaa !13
  %10 = icmp slt i32 %6, %9
  br i1 %10, label %11, label %44

11:                                               ; preds = %5
  %12 = load ptr, ptr %2, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.phase_t, ptr %12, i32 0, i32 1
  %14 = load ptr, ptr %13, align 8, !tbaa !15
  %15 = load i32, ptr %3, align 4, !tbaa !11
  %16 = sext i32 %15 to i64
  %17 = getelementptr inbounds ptr, ptr %14, i64 %16
  %18 = load ptr, ptr %17, align 8, !tbaa !5
  store ptr %18, ptr %4, align 8, !tbaa !5
  %19 = load ptr, ptr %4, align 8, !tbaa !5
  call void @VectSum(ptr noundef @StatOfVelocity.AvgVelocity, ptr noundef @StatOfVelocity.AvgVelocity, ptr noundef %19)
  %20 = load ptr, ptr %4, align 8, !tbaa !5
  %21 = call double @VectAbs(ptr noundef %20)
  store double %21, ptr @StatOfVelocity.velLength, align 8, !tbaa !9
  %22 = load double, ptr @StatOfVelocity.velLength, align 8, !tbaa !9
  %23 = load double, ptr @Avg, align 8, !tbaa !9
  %24 = fadd double %23, %22
  store double %24, ptr @Avg, align 8, !tbaa !9
  %25 = load double, ptr @StatOfVelocity.velLength, align 8, !tbaa !9
  %26 = load double, ptr @StatOfVelocity.velLength, align 8, !tbaa !9
  %27 = load double, ptr @StDev, align 8, !tbaa !9
  %28 = call double @llvm.fmuladd.f64(double %25, double %26, double %27)
  store double %28, ptr @StDev, align 8, !tbaa !9
  %29 = load double, ptr @StatOfVelocity.velLength, align 8, !tbaa !9
  %30 = load double, ptr @Max, align 8, !tbaa !9
  %31 = fcmp ogt double %29, %30
  br i1 %31, label %32, label %34

32:                                               ; preds = %11
  %33 = load double, ptr @StatOfVelocity.velLength, align 8, !tbaa !9
  store double %33, ptr @Max, align 8, !tbaa !9
  br label %34

34:                                               ; preds = %32, %11
  %35 = load double, ptr @StatOfVelocity.velLength, align 8, !tbaa !9
  %36 = load double, ptr @Min, align 8, !tbaa !9
  %37 = fcmp olt double %35, %36
  br i1 %37, label %38, label %40

38:                                               ; preds = %34
  %39 = load double, ptr @StatOfVelocity.velLength, align 8, !tbaa !9
  store double %39, ptr @Min, align 8, !tbaa !9
  br label %40

40:                                               ; preds = %38, %34
  br label %41

41:                                               ; preds = %40
  %42 = load i32, ptr %3, align 4, !tbaa !11
  %43 = add nsw i32 %42, 1
  store i32 %43, ptr %3, align 4, !tbaa !11
  br label %5, !llvm.loop !16

44:                                               ; preds = %5
  %45 = load ptr, ptr %2, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.phase_t, ptr %45, i32 0, i32 5
  %47 = load i32, ptr %46, align 4, !tbaa !13
  %48 = sitofp i32 %47 to double
  %49 = load double, ptr @Avg, align 8, !tbaa !9
  %50 = fdiv double %49, %48
  store double %50, ptr @Avg, align 8, !tbaa !9
  %51 = load ptr, ptr %2, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.phase_t, ptr %51, i32 0, i32 5
  %53 = load i32, ptr %52, align 4, !tbaa !13
  %54 = sitofp i32 %53 to double
  %55 = load double, ptr @StDev, align 8, !tbaa !9
  %56 = fdiv double %55, %54
  store double %56, ptr @StDev, align 8, !tbaa !9
  %57 = load double, ptr @Avg, align 8, !tbaa !9
  %58 = load double, ptr @Avg, align 8, !tbaa !9
  %59 = load double, ptr @StDev, align 8, !tbaa !9
  %60 = fneg double %57
  %61 = call double @llvm.fmuladd.f64(double %60, double %58, double %59)
  store double %61, ptr @StDev, align 8, !tbaa !9
  %62 = load double, ptr @StDev, align 8, !tbaa !9
  %63 = fcmp olt double %62, 0.000000e+00
  br i1 %63, label %64, label %65

64:                                               ; preds = %44
  store double 0.000000e+00, ptr @StDev, align 8, !tbaa !9
  br label %65

65:                                               ; preds = %64, %44
  %66 = load ptr, ptr %2, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.phase_t, ptr %66, i32 0, i32 5
  %68 = load i32, ptr %67, align 4, !tbaa !13
  %69 = sitofp i32 %68 to double
  %70 = fdiv double 1.000000e+00, %69
  call void @MultiplicateWithScalar(ptr noundef @StatOfVelocity.AvgVelocity, ptr noundef @StatOfVelocity.AvgVelocity, double noundef %70, i32 noundef 3)
  %71 = load double, ptr @Avg, align 8, !tbaa !9
  store double %71, ptr @StatOfVelocity.StatVel, align 16, !tbaa !9
  %72 = load double, ptr @StDev, align 8, !tbaa !9
  %73 = call double @sqrt(double noundef %72) #5
  store double %73, ptr getelementptr inbounds ([8 x double], ptr @StatOfVelocity.StatVel, i64 0, i64 1), align 8, !tbaa !9
  %74 = load double, ptr @Min, align 8, !tbaa !9
  store double %74, ptr getelementptr inbounds ([8 x double], ptr @StatOfVelocity.StatVel, i64 0, i64 2), align 16, !tbaa !9
  %75 = load double, ptr @Max, align 8, !tbaa !9
  store double %75, ptr getelementptr inbounds ([8 x double], ptr @StatOfVelocity.StatVel, i64 0, i64 3), align 8, !tbaa !9
  %76 = call double @VectAbs(ptr noundef @StatOfVelocity.AvgVelocity)
  store double %76, ptr getelementptr inbounds ([8 x double], ptr @StatOfVelocity.StatVel, i64 0, i64 4), align 16, !tbaa !9
  %77 = load double, ptr @StatOfVelocity.AvgVelocity, align 16, !tbaa !9
  store double %77, ptr getelementptr inbounds ([8 x double], ptr @StatOfVelocity.StatVel, i64 0, i64 5), align 8, !tbaa !9
  %78 = load double, ptr getelementptr inbounds ([3 x double], ptr @StatOfVelocity.AvgVelocity, i64 0, i64 1), align 8, !tbaa !9
  store double %78, ptr getelementptr inbounds ([8 x double], ptr @StatOfVelocity.StatVel, i64 0, i64 6), align 16, !tbaa !9
  %79 = load double, ptr getelementptr inbounds ([3 x double], ptr @StatOfVelocity.AvgVelocity, i64 0, i64 2), align 16, !tbaa !9
  store double %79, ptr getelementptr inbounds ([8 x double], ptr @StatOfVelocity.StatVel, i64 0, i64 7), align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #5
  ret ptr @StatOfVelocity.StatVel
}

declare void @NullVect(ptr noundef, i32 noundef) #1

declare void @VectSum(ptr noundef, ptr noundef, ptr noundef) #1

declare void @MultiplicateWithScalar(ptr noundef, ptr noundef, double noundef, i32 noundef) #1

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #2 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #3 = { nounwind "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #4 = { nounwind uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #5 = { nounwind }

!llvm.module.flags = !{!0, !1, !2, !3}
!llvm.ident = !{!4}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 2}
!4 = !{!"clang version 19.1.0 (git@github.com:llvm/llvm-project.git a4bf6cd7cfb1a1421ba92bca9d017b49936c55e4)"}
!5 = !{!6, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"double", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !12, i64 36}
!14 = !{!"", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !12, i64 32, !12, i64 36}
!15 = !{!14, !6, i64 8}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}


; Optimized IR (opt -passes='default<O3>'):
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

@Avg = external hidden local_unnamed_addr global double, align 8
@StDev = external hidden local_unnamed_addr global double, align 8
@Min = external hidden local_unnamed_addr global double, align 8
@Max = external hidden local_unnamed_addr global double, align 8
@StatOfVelocity.AvgVelocity = external hidden global [3 x double], align 16
@StatOfVelocity.velLength = external hidden local_unnamed_addr global double, align 8
@StatOfVelocity.StatVel = external hidden global [8 x double], align 16

declare double @VectAbs(ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #1

; Function Attrs: mustprogress nofree nounwind willreturn memory(write)
declare double @sqrt(double noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
define dso_local noundef nonnull ptr @StatOfVelocity(ptr nocapture noundef readonly %0) local_unnamed_addr #3 {
  tail call void @NullVect(ptr noundef nonnull @StatOfVelocity.AvgVelocity, i32 noundef 3) #4
  store double 0.000000e+00, ptr @Avg, align 8, !tbaa !5
  store double 0.000000e+00, ptr @StDev, align 8, !tbaa !5
  store double 2.000000e+222, ptr @Min, align 8, !tbaa !5
  store double 0.000000e+00, ptr @Max, align 8, !tbaa !5
  store double 0.000000e+00, ptr @StatOfVelocity.velLength, align 8, !tbaa !5
  %2 = getelementptr inbounds i8, ptr %0, i64 36
  %3 = load i32, ptr %2, align 4, !tbaa !9
  %4 = icmp sgt i32 %3, 0
  br i1 %4, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %1
  %5 = getelementptr inbounds i8, ptr %0, i64 8
  br label %6

6:                                                ; preds = %.lr.ph, %22
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %22 ]
  %7 = load ptr, ptr %5, align 8, !tbaa !13
  %8 = getelementptr inbounds ptr, ptr %7, i64 %indvars.iv
  %9 = load ptr, ptr %8, align 8, !tbaa !14
  tail call void @VectSum(ptr noundef nonnull @StatOfVelocity.AvgVelocity, ptr noundef nonnull @StatOfVelocity.AvgVelocity, ptr noundef %9) #4
  %10 = tail call double @VectAbs(ptr noundef %9) #4
  store double %10, ptr @StatOfVelocity.velLength, align 8, !tbaa !5
  %11 = load double, ptr @Avg, align 8, !tbaa !5
  %12 = fadd double %10, %11
  store double %12, ptr @Avg, align 8, !tbaa !5
  %13 = load double, ptr @StDev, align 8, !tbaa !5
  %14 = tail call double @llvm.fmuladd.f64(double %10, double %10, double %13)
  store double %14, ptr @StDev, align 8, !tbaa !5
  %15 = load double, ptr @Max, align 8, !tbaa !5
  %16 = fcmp ogt double %10, %15
  br i1 %16, label %17, label %18

17:                                               ; preds = %6
  store double %10, ptr @Max, align 8, !tbaa !5
  br label %18

18:                                               ; preds = %17, %6
  %19 = load double, ptr @Min, align 8, !tbaa !5
  %20 = fcmp olt double %10, %19
  br i1 %20, label %21, label %22

21:                                               ; preds = %18
  store double %10, ptr @Min, align 8, !tbaa !5
  br label %22

22:                                               ; preds = %18, %21
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %23 = load i32, ptr %2, align 4, !tbaa !9
  %24 = sext i32 %23 to i64
  %25 = icmp slt i64 %indvars.iv.next, %24
  br i1 %25, label %6, label %._crit_edge, !llvm.loop !15

._crit_edge:                                      ; preds = %22, %1
  %26 = phi double [ 0.000000e+00, %1 ], [ %14, %22 ]
  %27 = phi double [ 0.000000e+00, %1 ], [ %12, %22 ]
  %.lcssa = phi i32 [ %3, %1 ], [ %23, %22 ]
  %28 = sitofp i32 %.lcssa to double
  %29 = fdiv double %27, %28
  store double %29, ptr @Avg, align 8, !tbaa !5
  %30 = fdiv double %26, %28
  %31 = fneg double %29
  %32 = tail call double @llvm.fmuladd.f64(double %31, double %29, double %30)
  %33 = fcmp olt double %32, 0.000000e+00
  %storemerge = select i1 %33, double 0.000000e+00, double %32
  store double %storemerge, ptr @StDev, align 8, !tbaa !5
  %34 = fdiv double 1.000000e+00, %28
  tail call void @MultiplicateWithScalar(ptr noundef nonnull @StatOfVelocity.AvgVelocity, ptr noundef nonnull @StatOfVelocity.AvgVelocity, double noundef %34, i32 noundef 3) #4
  %35 = load double, ptr @Avg, align 8, !tbaa !5
  store double %35, ptr @StatOfVelocity.StatVel, align 16, !tbaa !5
  %36 = load double, ptr @StDev, align 8, !tbaa !5
  %37 = tail call double @sqrt(double noundef %36) #4
  store double %37, ptr getelementptr inbounds (i8, ptr @StatOfVelocity.StatVel, i64 8), align 8, !tbaa !5
  %38 = load double, ptr @Min, align 8, !tbaa !5
  store double %38, ptr getelementptr inbounds (i8, ptr @StatOfVelocity.StatVel, i64 16), align 16, !tbaa !5
  %39 = load double, ptr @Max, align 8, !tbaa !5
  store double %39, ptr getelementptr inbounds (i8, ptr @StatOfVelocity.StatVel, i64 24), align 8, !tbaa !5
  %40 = tail call double @VectAbs(ptr noundef nonnull @StatOfVelocity.AvgVelocity) #4
  store double %40, ptr getelementptr inbounds (i8, ptr @StatOfVelocity.StatVel, i64 32), align 16, !tbaa !5
  %41 = load <2 x double>, ptr @StatOfVelocity.AvgVelocity, align 16, !tbaa !5
  store <2 x double> %41, ptr getelementptr inbounds (i8, ptr @StatOfVelocity.StatVel, i64 40), align 8, !tbaa !5
  %42 = load double, ptr getelementptr inbounds (i8, ptr @StatOfVelocity.AvgVelocity, i64 16), align 16, !tbaa !5
  store double %42, ptr getelementptr inbounds (i8, ptr @StatOfVelocity.StatVel, i64 56), align 8, !tbaa !5
  ret ptr @StatOfVelocity.StatVel
}

declare void @NullVect(ptr noundef, i32 noundef) local_unnamed_addr #0

declare void @VectSum(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #0

declare void @MultiplicateWithScalar(ptr noundef, ptr noundef, double noundef, i32 noundef) local_unnamed_addr #0

attributes #0 = { "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #1 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #2 = { mustprogress nofree nounwind willreturn memory(write) "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #3 = { nounwind uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #4 = { nounwind }

!llvm.module.flags = !{!0, !1, !2, !3}
!llvm.ident = !{!4}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 2}
!4 = !{!"clang version 19.1.0 (git@github.com:llvm/llvm-project.git a4bf6cd7cfb1a1421ba92bca9d017b49936c55e4)"}
!5 = !{!6, !6, i64 0}
!6 = !{!"double", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !12, i64 36}
!10 = !{!"", !11, i64 0, !11, i64 8, !11, i64 16, !11, i64 24, !12, i64 32, !12, i64 36}
!11 = !{!"any pointer", !7, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!10, !11, i64 8}
!14 = !{!11, !11, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SLPVectorizerPass,SROAPass,SimplifyCFGPass,TailCallElimPass