; 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"

@StatOfAcceleration.accLength = external hidden global double, align 8
@StatOfAcceleration.StatAcc = external hidden global [4 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

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

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

; Function Attrs: nounwind uwtable
define dso_local ptr @StatOfAcceleration(ptr noundef %0, double noundef %1) #3 {
  %3 = alloca ptr, align 8
  %4 = alloca double, align 8
  %5 = alloca i32, align 4
  %6 = alloca double, align 8
  %7 = alloca double, align 8
  %8 = alloca double, align 8
  %9 = alloca double, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store double %1, ptr %4, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  store double 0.000000e+00, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  store double 0.000000e+00, ptr %7, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  store double 2.000000e+222, ptr %8, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  store double 0.000000e+00, ptr %9, align 8, !tbaa !9
  store i32 0, ptr %5, align 4, !tbaa !11
  br label %10

10:                                               ; preds = %40, %2
  %11 = load i32, ptr %5, align 4, !tbaa !11
  %12 = sitofp i32 %11 to double
  %13 = load double, ptr %4, align 8, !tbaa !9
  %14 = fcmp olt double %12, %13
  br i1 %14, label %15, label %43

15:                                               ; preds = %10
  %16 = load ptr, ptr %3, align 8, !tbaa !5
  %17 = load i32, ptr %5, align 4, !tbaa !11
  %18 = sext i32 %17 to i64
  %19 = getelementptr inbounds double, ptr %16, i64 %18
  %20 = load double, ptr %19, align 8, !tbaa !9
  store double %20, ptr @StatOfAcceleration.accLength, align 8, !tbaa !9
  %21 = load double, ptr @StatOfAcceleration.accLength, align 8, !tbaa !9
  %22 = load double, ptr %6, align 8, !tbaa !9
  %23 = fadd double %22, %21
  store double %23, ptr %6, align 8, !tbaa !9
  %24 = load double, ptr @StatOfAcceleration.accLength, align 8, !tbaa !9
  %25 = load double, ptr @StatOfAcceleration.accLength, align 8, !tbaa !9
  %26 = load double, ptr %7, align 8, !tbaa !9
  %27 = call double @llvm.fmuladd.f64(double %24, double %25, double %26)
  store double %27, ptr %7, align 8, !tbaa !9
  %28 = load double, ptr @StatOfAcceleration.accLength, align 8, !tbaa !9
  %29 = load double, ptr %9, align 8, !tbaa !9
  %30 = fcmp ogt double %28, %29
  br i1 %30, label %31, label %33

31:                                               ; preds = %15
  %32 = load double, ptr @StatOfAcceleration.accLength, align 8, !tbaa !9
  store double %32, ptr %9, align 8, !tbaa !9
  br label %33

33:                                               ; preds = %31, %15
  %34 = load double, ptr @StatOfAcceleration.accLength, align 8, !tbaa !9
  %35 = load double, ptr %8, align 8, !tbaa !9
  %36 = fcmp olt double %34, %35
  br i1 %36, label %37, label %39

37:                                               ; preds = %33
  %38 = load double, ptr @StatOfAcceleration.accLength, align 8, !tbaa !9
  store double %38, ptr %8, align 8, !tbaa !9
  br label %39

39:                                               ; preds = %37, %33
  br label %40

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

43:                                               ; preds = %10
  %44 = load double, ptr %4, align 8, !tbaa !9
  %45 = load double, ptr %6, align 8, !tbaa !9
  %46 = fdiv double %45, %44
  store double %46, ptr %6, align 8, !tbaa !9
  %47 = load double, ptr %4, align 8, !tbaa !9
  %48 = load double, ptr %7, align 8, !tbaa !9
  %49 = fdiv double %48, %47
  store double %49, ptr %7, align 8, !tbaa !9
  %50 = load double, ptr %6, align 8, !tbaa !9
  %51 = load double, ptr %6, align 8, !tbaa !9
  %52 = load double, ptr %7, align 8, !tbaa !9
  %53 = fneg double %50
  %54 = call double @llvm.fmuladd.f64(double %53, double %51, double %52)
  store double %54, ptr %7, align 8, !tbaa !9
  %55 = load double, ptr %7, align 8, !tbaa !9
  %56 = fcmp olt double %55, 0.000000e+00
  br i1 %56, label %57, label %58

57:                                               ; preds = %43
  store double 0.000000e+00, ptr %7, align 8, !tbaa !9
  br label %58

58:                                               ; preds = %57, %43
  %59 = load double, ptr %6, align 8, !tbaa !9
  store double %59, ptr @StatOfAcceleration.StatAcc, align 16, !tbaa !9
  %60 = load double, ptr %7, align 8, !tbaa !9
  %61 = call double @sqrt(double noundef %60) #4
  store double %61, ptr getelementptr inbounds ([4 x double], ptr @StatOfAcceleration.StatAcc, i64 0, i64 1), align 8, !tbaa !9
  %62 = load double, ptr %8, align 8, !tbaa !9
  store double %62, ptr getelementptr inbounds ([4 x double], ptr @StatOfAcceleration.StatAcc, i64 0, i64 2), align 16, !tbaa !9
  %63 = load double, ptr %9, align 8, !tbaa !9
  store double %63, ptr getelementptr inbounds ([4 x double], ptr @StatOfAcceleration.StatAcc, i64 0, i64 3), align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  ret ptr @StatOfAcceleration.StatAcc
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #2 = { 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 #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 = !{!"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 = distinct !{!13, !14}
!14 = !{!"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"

@StatOfAcceleration.accLength = external hidden local_unnamed_addr global double, align 8
@StatOfAcceleration.StatAcc = external hidden global [4 x double], align 16

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

; Function Attrs: nofree norecurse nosync nounwind memory(write, argmem: read, inaccessiblemem: none) uwtable
define dso_local noundef nonnull ptr @StatOfAcceleration(ptr nocapture noundef readonly %0, double noundef %1) local_unnamed_addr #1 {
  %3 = fcmp ogt double %1, 0.000000e+00
  br i1 %3, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %2, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 0, %2 ]
  %.034 = phi double [ %.1, %.lr.ph ], [ 0.000000e+00, %2 ]
  %.02033 = phi double [ %.121, %.lr.ph ], [ 2.000000e+222, %2 ]
  %.02232 = phi double [ %7, %.lr.ph ], [ 0.000000e+00, %2 ]
  %.02431 = phi double [ %6, %.lr.ph ], [ 0.000000e+00, %2 ]
  %4 = getelementptr inbounds double, ptr %0, i64 %indvars.iv
  %5 = load double, ptr %4, align 8, !tbaa !5
  store double %5, ptr @StatOfAcceleration.accLength, align 8, !tbaa !5
  %6 = fadd double %.02431, %5
  %7 = tail call double @llvm.fmuladd.f64(double %5, double %5, double %.02232)
  %8 = fcmp ogt double %5, %.034
  %.1 = select i1 %8, double %5, double %.034
  %9 = fcmp olt double %5, %.02033
  %.121 = select i1 %9, double %5, double %.02033
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %10 = trunc nuw nsw i64 %indvars.iv.next to i32
  %11 = uitofp nneg i32 %10 to double
  %12 = fcmp olt double %11, %1
  br i1 %12, label %.lr.ph, label %._crit_edge, !llvm.loop !9

._crit_edge:                                      ; preds = %.lr.ph, %2
  %.024.lcssa = phi double [ 0.000000e+00, %2 ], [ %6, %.lr.ph ]
  %.022.lcssa = phi double [ 0.000000e+00, %2 ], [ %7, %.lr.ph ]
  %.020.lcssa = phi double [ 2.000000e+222, %2 ], [ %.121, %.lr.ph ]
  %.0.lcssa = phi double [ 0.000000e+00, %2 ], [ %.1, %.lr.ph ]
  %13 = fdiv double %.024.lcssa, %1
  %14 = fdiv double %.022.lcssa, %1
  %15 = fneg double %13
  %16 = tail call double @llvm.fmuladd.f64(double %15, double %13, double %14)
  %17 = fcmp olt double %16, 0.000000e+00
  %.123 = select i1 %17, double 0.000000e+00, double %16
  store double %13, ptr @StatOfAcceleration.StatAcc, align 16, !tbaa !5
  %sqrt = tail call double @llvm.sqrt.f64(double %.123)
  store double %sqrt, ptr getelementptr inbounds (i8, ptr @StatOfAcceleration.StatAcc, i64 8), align 8, !tbaa !5
  store double %.020.lcssa, ptr getelementptr inbounds (i8, ptr @StatOfAcceleration.StatAcc, i64 16), align 16, !tbaa !5
  store double %.0.lcssa, ptr getelementptr inbounds (i8, ptr @StatOfAcceleration.StatAcc, i64 24), align 8, !tbaa !5
  ret ptr @StatOfAcceleration.StatAcc
}

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

attributes #0 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #1 = { nofree norecurse nosync nounwind memory(write, argmem: read, inaccessiblemem: none) 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 #2 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }

!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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


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