; 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
@StatOfDistanceBetweenUnits.Dist_1_2 = external hidden global double, align 8
@StatOfDistanceBetweenUnits.CoordDiff = external hidden global [3 x double], align 16
@StatOfDistanceBetweenUnits.StatData = 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: nounwind uwtable
define dso_local ptr @StatOfDistanceBetweenUnits(ptr noundef %0) #1 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = 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 4, ptr %4) #5
  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
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #5
  store i32 0, ptr %3, align 4, !tbaa !11
  br label %7

7:                                                ; preds = %64, %1
  %8 = load i32, ptr %3, align 4, !tbaa !11
  %9 = load ptr, ptr %2, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct.phase_t, ptr %9, i32 0, i32 5
  %11 = load i32, ptr %10, align 4, !tbaa !13
  %12 = sub nsw i32 %11, 1
  %13 = icmp slt i32 %8, %12
  br i1 %13, label %14, label %67

14:                                               ; preds = %7
  %15 = load i32, ptr %3, align 4, !tbaa !11
  %16 = add nsw i32 %15, 1
  store i32 %16, ptr %4, align 4, !tbaa !11
  br label %17

17:                                               ; preds = %60, %14
  %18 = load i32, ptr %4, align 4, !tbaa !11
  %19 = load ptr, ptr %2, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.phase_t, ptr %19, i32 0, i32 5
  %21 = load i32, ptr %20, align 4, !tbaa !13
  %22 = icmp slt i32 %18, %21
  br i1 %22, label %23, label %63

23:                                               ; preds = %17
  %24 = load ptr, ptr %2, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.phase_t, ptr %24, i32 0, i32 0
  %26 = load ptr, ptr %25, align 8, !tbaa !15
  %27 = load i32, ptr %3, align 4, !tbaa !11
  %28 = sext i32 %27 to i64
  %29 = getelementptr inbounds ptr, ptr %26, i64 %28
  %30 = load ptr, ptr %29, align 8, !tbaa !5
  store ptr %30, ptr %5, align 8, !tbaa !5
  %31 = load ptr, ptr %2, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.phase_t, ptr %31, i32 0, i32 0
  %33 = load ptr, ptr %32, align 8, !tbaa !15
  %34 = load i32, ptr %4, align 4, !tbaa !11
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds ptr, ptr %33, i64 %35
  %37 = load ptr, ptr %36, align 8, !tbaa !5
  store ptr %37, ptr %6, align 8, !tbaa !5
  %38 = load ptr, ptr %5, align 8, !tbaa !5
  %39 = load ptr, ptr %6, align 8, !tbaa !5
  call void @VectDifference(ptr noundef @StatOfDistanceBetweenUnits.CoordDiff, ptr noundef %38, ptr noundef %39)
  %40 = call double @VectAbs(ptr noundef @StatOfDistanceBetweenUnits.CoordDiff)
  store double %40, ptr @StatOfDistanceBetweenUnits.Dist_1_2, align 8, !tbaa !9
  %41 = load double, ptr @StatOfDistanceBetweenUnits.Dist_1_2, align 8, !tbaa !9
  %42 = load double, ptr @Max, align 8, !tbaa !9
  %43 = fcmp ogt double %41, %42
  br i1 %43, label %44, label %46

44:                                               ; preds = %23
  %45 = load double, ptr @StatOfDistanceBetweenUnits.Dist_1_2, align 8, !tbaa !9
  store double %45, ptr @Max, align 8, !tbaa !9
  br label %46

46:                                               ; preds = %44, %23
  %47 = load double, ptr @StatOfDistanceBetweenUnits.Dist_1_2, align 8, !tbaa !9
  %48 = load double, ptr @Min, align 8, !tbaa !9
  %49 = fcmp olt double %47, %48
  br i1 %49, label %50, label %52

50:                                               ; preds = %46
  %51 = load double, ptr @StatOfDistanceBetweenUnits.Dist_1_2, align 8, !tbaa !9
  store double %51, ptr @Min, align 8, !tbaa !9
  br label %52

52:                                               ; preds = %50, %46
  %53 = load double, ptr @StatOfDistanceBetweenUnits.Dist_1_2, align 8, !tbaa !9
  %54 = load double, ptr @Avg, align 8, !tbaa !9
  %55 = fadd double %54, %53
  store double %55, ptr @Avg, align 8, !tbaa !9
  %56 = load double, ptr @StatOfDistanceBetweenUnits.Dist_1_2, align 8, !tbaa !9
  %57 = load double, ptr @StatOfDistanceBetweenUnits.Dist_1_2, align 8, !tbaa !9
  %58 = load double, ptr @StDev, align 8, !tbaa !9
  %59 = call double @llvm.fmuladd.f64(double %56, double %57, double %58)
  store double %59, ptr @StDev, align 8, !tbaa !9
  br label %60

60:                                               ; preds = %52
  %61 = load i32, ptr %4, align 4, !tbaa !11
  %62 = add nsw i32 %61, 1
  store i32 %62, ptr %4, align 4, !tbaa !11
  br label %17, !llvm.loop !16

63:                                               ; preds = %17
  br label %64

64:                                               ; preds = %63
  %65 = load i32, ptr %3, align 4, !tbaa !11
  %66 = add nsw i32 %65, 1
  store i32 %66, ptr %3, align 4, !tbaa !11
  br label %7, !llvm.loop !18

67:                                               ; preds = %7
  %68 = load ptr, ptr %2, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct.phase_t, ptr %68, i32 0, i32 5
  %70 = load i32, ptr %69, align 4, !tbaa !13
  %71 = load ptr, ptr %2, align 8, !tbaa !5
  %72 = getelementptr inbounds %struct.phase_t, ptr %71, i32 0, i32 5
  %73 = load i32, ptr %72, align 4, !tbaa !13
  %74 = sub nsw i32 %73, 1
  %75 = mul nsw i32 %70, %74
  %76 = sitofp i32 %75 to double
  %77 = fdiv double 2.000000e+00, %76
  %78 = load double, ptr @Avg, align 8, !tbaa !9
  %79 = fmul double %78, %77
  store double %79, ptr @Avg, align 8, !tbaa !9
  %80 = load ptr, ptr %2, align 8, !tbaa !5
  %81 = getelementptr inbounds %struct.phase_t, ptr %80, i32 0, i32 5
  %82 = load i32, ptr %81, align 4, !tbaa !13
  %83 = load ptr, ptr %2, align 8, !tbaa !5
  %84 = getelementptr inbounds %struct.phase_t, ptr %83, i32 0, i32 5
  %85 = load i32, ptr %84, align 4, !tbaa !13
  %86 = sub nsw i32 %85, 1
  %87 = mul nsw i32 %82, %86
  %88 = sitofp i32 %87 to double
  %89 = fdiv double 2.000000e+00, %88
  %90 = load double, ptr @StDev, align 8, !tbaa !9
  %91 = fmul double %90, %89
  store double %91, ptr @StDev, align 8, !tbaa !9
  %92 = load double, ptr @Avg, align 8, !tbaa !9
  %93 = load double, ptr @Avg, align 8, !tbaa !9
  %94 = load double, ptr @StDev, align 8, !tbaa !9
  %95 = fneg double %92
  %96 = call double @llvm.fmuladd.f64(double %95, double %93, double %94)
  store double %96, ptr @StDev, align 8, !tbaa !9
  %97 = load double, ptr @StDev, align 8, !tbaa !9
  %98 = fcmp olt double %97, 0.000000e+00
  br i1 %98, label %99, label %100

99:                                               ; preds = %67
  store double 0.000000e+00, ptr @StDev, align 8, !tbaa !9
  br label %100

100:                                              ; preds = %99, %67
  %101 = load double, ptr @Avg, align 8, !tbaa !9
  store double %101, ptr @StatOfDistanceBetweenUnits.StatData, align 16, !tbaa !9
  %102 = load double, ptr @StDev, align 8, !tbaa !9
  %103 = call double @sqrt(double noundef %102) #5
  store double %103, ptr getelementptr inbounds ([4 x double], ptr @StatOfDistanceBetweenUnits.StatData, i64 0, i64 1), align 8, !tbaa !9
  %104 = load double, ptr @Min, align 8, !tbaa !9
  store double %104, ptr getelementptr inbounds ([4 x double], ptr @StatOfDistanceBetweenUnits.StatData, i64 0, i64 2), align 16, !tbaa !9
  %105 = load double, ptr @Max, align 8, !tbaa !9
  store double %105, ptr getelementptr inbounds ([4 x double], ptr @StatOfDistanceBetweenUnits.StatData, i64 0, i64 3), align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #5
  ret ptr @StatOfDistanceBetweenUnits.StatData
}

declare void @VectDifference(ptr noundef, ptr noundef, ptr noundef) #2

declare double @VectAbs(ptr noundef) #2

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

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { "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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #4 = { 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 #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 0}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}
!18 = distinct !{!18, !17}


; 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
@StatOfDistanceBetweenUnits.Dist_1_2 = external hidden local_unnamed_addr global double, align 8
@StatOfDistanceBetweenUnits.CoordDiff = external hidden global [3 x double], align 16
@StatOfDistanceBetweenUnits.StatData = external hidden global [4 x double], align 16

; Function Attrs: nounwind uwtable
define dso_local noundef nonnull ptr @StatOfDistanceBetweenUnits(ptr nocapture noundef readonly %0) local_unnamed_addr #0 {
  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
  %2 = getelementptr inbounds i8, ptr %0, i64 36
  %3 = load i32, ptr %2, align 4, !tbaa !9
  %4 = add nsw i32 %3, -1
  %5 = icmp sgt i32 %3, 1
  br i1 %5, label %.lr.ph23, label %._crit_edge

.loopexit:                                        ; preds = %35, %.lr.ph23
  %6 = phi double [ %14, %.lr.ph23 ], [ %31, %35 ]
  %7 = phi double [ %15, %.lr.ph23 ], [ %36, %35 ]
  %8 = phi double [ %16, %.lr.ph23 ], [ %40, %35 ]
  %9 = phi double [ %17, %.lr.ph23 ], [ %38, %35 ]
  %10 = phi i32 [ %18, %.lr.ph23 ], [ %41, %35 ]
  %11 = add nsw i32 %10, -1
  %12 = sext i32 %11 to i64
  %13 = icmp slt i64 %indvars.iv.next31, %12
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  br i1 %13, label %.lr.ph23, label %._crit_edge, !llvm.loop !13

.lr.ph23:                                         ; preds = %1, %.loopexit
  %14 = phi double [ %6, %.loopexit ], [ 0.000000e+00, %1 ]
  %15 = phi double [ %7, %.loopexit ], [ 2.000000e+222, %1 ]
  %16 = phi double [ %8, %.loopexit ], [ 0.000000e+00, %1 ]
  %17 = phi double [ %9, %.loopexit ], [ 0.000000e+00, %1 ]
  %18 = phi i32 [ %10, %.loopexit ], [ %3, %1 ]
  %indvars.iv30 = phi i64 [ %indvars.iv.next31, %.loopexit ], [ 0, %1 ]
  %indvars.iv = phi i64 [ %indvars.iv.next, %.loopexit ], [ 1, %1 ]
  %indvars.iv.next31 = add nuw nsw i64 %indvars.iv30, 1
  %19 = sext i32 %18 to i64
  %20 = icmp slt i64 %indvars.iv.next31, %19
  br i1 %20, label %.lr.ph, label %.loopexit

.lr.ph:                                           ; preds = %.lr.ph23, %35
  %indvars.iv27 = phi i64 [ %indvars.iv.next28, %35 ], [ %indvars.iv, %.lr.ph23 ]
  %21 = load ptr, ptr %0, align 8, !tbaa !15
  %22 = getelementptr inbounds ptr, ptr %21, i64 %indvars.iv30
  %23 = load ptr, ptr %22, align 8, !tbaa !16
  %24 = getelementptr inbounds ptr, ptr %21, i64 %indvars.iv27
  %25 = load ptr, ptr %24, align 8, !tbaa !16
  tail call void @VectDifference(ptr noundef nonnull @StatOfDistanceBetweenUnits.CoordDiff, ptr noundef %23, ptr noundef %25) #4
  %26 = tail call double @VectAbs(ptr noundef nonnull @StatOfDistanceBetweenUnits.CoordDiff) #4
  store double %26, ptr @StatOfDistanceBetweenUnits.Dist_1_2, align 8, !tbaa !5
  %27 = load double, ptr @Max, align 8, !tbaa !5
  %28 = fcmp ogt double %26, %27
  br i1 %28, label %29, label %30

29:                                               ; preds = %.lr.ph
  store double %26, ptr @Max, align 8, !tbaa !5
  br label %30

30:                                               ; preds = %29, %.lr.ph
  %31 = phi double [ %26, %29 ], [ %27, %.lr.ph ]
  %32 = load double, ptr @Min, align 8, !tbaa !5
  %33 = fcmp olt double %26, %32
  br i1 %33, label %34, label %35

34:                                               ; preds = %30
  store double %26, ptr @Min, align 8, !tbaa !5
  br label %35

35:                                               ; preds = %34, %30
  %36 = phi double [ %26, %34 ], [ %32, %30 ]
  %37 = load double, ptr @Avg, align 8, !tbaa !5
  %38 = fadd double %26, %37
  store double %38, ptr @Avg, align 8, !tbaa !5
  %39 = load double, ptr @StDev, align 8, !tbaa !5
  %40 = tail call double @llvm.fmuladd.f64(double %26, double %26, double %39)
  store double %40, ptr @StDev, align 8, !tbaa !5
  %indvars.iv.next28 = add nuw nsw i64 %indvars.iv27, 1
  %41 = load i32, ptr %2, align 4, !tbaa !9
  %42 = trunc nuw i64 %indvars.iv.next28 to i32
  %43 = icmp sgt i32 %41, %42
  br i1 %43, label %.lr.ph, label %.loopexit, !llvm.loop !17

._crit_edge:                                      ; preds = %.loopexit, %1
  %44 = phi double [ 0.000000e+00, %1 ], [ %6, %.loopexit ]
  %45 = phi double [ 2.000000e+222, %1 ], [ %7, %.loopexit ]
  %46 = phi double [ 0.000000e+00, %1 ], [ %8, %.loopexit ]
  %47 = phi double [ 0.000000e+00, %1 ], [ %9, %.loopexit ]
  %.lcssa20 = phi i32 [ %3, %1 ], [ %10, %.loopexit ]
  %.lcssa = phi i32 [ %4, %1 ], [ %11, %.loopexit ]
  %48 = mul nsw i32 %.lcssa, %.lcssa20
  %49 = sitofp i32 %48 to double
  %50 = fdiv double 2.000000e+00, %49
  %51 = fmul double %50, %47
  store double %51, ptr @Avg, align 8, !tbaa !5
  %52 = fmul double %50, %46
  %53 = fneg double %51
  %54 = tail call double @llvm.fmuladd.f64(double %53, double %51, double %52)
  %55 = fcmp olt double %54, 0.000000e+00
  %storemerge = select i1 %55, double 0.000000e+00, double %54
  store double %storemerge, ptr @StDev, align 8, !tbaa !5
  store double %51, ptr @StatOfDistanceBetweenUnits.StatData, align 16, !tbaa !5
  %sqrt = tail call double @llvm.sqrt.f64(double %storemerge)
  store double %sqrt, ptr getelementptr inbounds (i8, ptr @StatOfDistanceBetweenUnits.StatData, i64 8), align 8, !tbaa !5
  store double %45, ptr getelementptr inbounds (i8, ptr @StatOfDistanceBetweenUnits.StatData, i64 16), align 16, !tbaa !5
  store double %44, ptr getelementptr inbounds (i8, ptr @StatOfDistanceBetweenUnits.StatData, i64 24), align 8, !tbaa !5
  ret ptr @StatOfDistanceBetweenUnits.StatData
}

declare void @VectDifference(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #1

declare double @VectAbs(ptr noundef) local_unnamed_addr #1

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

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

attributes #0 = { 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 #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 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #3 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = !{!10, !11, i64 0}
!16 = !{!11, !11, i64 0}
!17 = distinct !{!17, !14}


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