; LLVM IR from csviragh/robotsim :: src/utilities (dynamics_utils)

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

@GetLocalAverageOfXYVelocity.CacheDifferenceVector = external hidden global [3 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
declare double @pow(double noundef, double noundef) #1

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

declare double @VectAbs(ptr noundef) #2

; Function Attrs: nounwind uwtable
define dso_local void @GetLocalAverageOfXYVelocity(ptr noundef %0, ptr noundef %1, i32 noundef %2, double noundef %3) #3 {
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca double, align 8
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca ptr, align 8
  %13 = alloca ptr, align 8
  %14 = alloca ptr, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store i32 %2, ptr %7, align 4, !tbaa !9
  store double %3, ptr %8, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  store i32 0, ptr %9, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #4
  %15 = load ptr, ptr %6, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.phase_t, ptr %15, i32 0, i32 0
  %17 = load ptr, ptr %16, align 8, !tbaa !13
  %18 = load i32, ptr %7, align 4, !tbaa !9
  %19 = sext i32 %18 to i64
  %20 = getelementptr inbounds ptr, ptr %17, i64 %19
  %21 = load ptr, ptr %20, align 8, !tbaa !5
  store ptr %21, ptr %14, align 8, !tbaa !5
  store i32 0, ptr %11, align 4, !tbaa !9
  br label %22

22:                                               ; preds = %76, %4
  %23 = load i32, ptr %11, align 4, !tbaa !9
  %24 = load ptr, ptr %6, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.phase_t, ptr %24, i32 0, i32 5
  %26 = load i32, ptr %25, align 4, !tbaa !15
  %27 = icmp slt i32 %23, %26
  br i1 %27, label %28, label %79

28:                                               ; preds = %22
  %29 = load i32, ptr %11, align 4, !tbaa !9
  %30 = load i32, ptr %7, align 4, !tbaa !9
  %31 = icmp ne i32 %29, %30
  br i1 %31, label %32, label %75

32:                                               ; preds = %28
  %33 = load ptr, ptr %6, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.phase_t, ptr %33, i32 0, i32 1
  %35 = load ptr, ptr %34, align 8, !tbaa !16
  %36 = load i32, ptr %11, align 4, !tbaa !9
  %37 = sext i32 %36 to i64
  %38 = getelementptr inbounds ptr, ptr %35, i64 %37
  %39 = load ptr, ptr %38, align 8, !tbaa !5
  store ptr %39, ptr %12, align 8, !tbaa !5
  %40 = load ptr, ptr %6, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.phase_t, ptr %40, i32 0, i32 0
  %42 = load ptr, ptr %41, align 8, !tbaa !13
  %43 = load i32, ptr %11, align 4, !tbaa !9
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds ptr, ptr %42, i64 %44
  %46 = load ptr, ptr %45, align 8, !tbaa !5
  store ptr %46, ptr %13, align 8, !tbaa !5
  %47 = load ptr, ptr %14, align 8, !tbaa !5
  %48 = load ptr, ptr %13, align 8, !tbaa !5
  call void @VectDifference(ptr noundef @GetLocalAverageOfXYVelocity.CacheDifferenceVector, ptr noundef %47, ptr noundef %48)
  %49 = call double @VectAbs(ptr noundef @GetLocalAverageOfXYVelocity.CacheDifferenceVector)
  %50 = load double, ptr %8, align 8, !tbaa !11
  %51 = fcmp ole double %49, %50
  br i1 %51, label %52, label %74

52:                                               ; preds = %32
  store i32 0, ptr %10, align 4, !tbaa !9
  br label %53

53:                                               ; preds = %68, %52
  %54 = load i32, ptr %10, align 4, !tbaa !9
  %55 = icmp slt i32 %54, 2
  br i1 %55, label %56, label %71

56:                                               ; preds = %53
  %57 = load ptr, ptr %12, align 8, !tbaa !5
  %58 = load i32, ptr %10, align 4, !tbaa !9
  %59 = sext i32 %58 to i64
  %60 = getelementptr inbounds double, ptr %57, i64 %59
  %61 = load double, ptr %60, align 8, !tbaa !11
  %62 = load ptr, ptr %5, align 8, !tbaa !5
  %63 = load i32, ptr %10, align 4, !tbaa !9
  %64 = sext i32 %63 to i64
  %65 = getelementptr inbounds double, ptr %62, i64 %64
  %66 = load double, ptr %65, align 8, !tbaa !11
  %67 = fadd double %66, %61
  store double %67, ptr %65, align 8, !tbaa !11
  br label %68

68:                                               ; preds = %56
  %69 = load i32, ptr %10, align 4, !tbaa !9
  %70 = add nsw i32 %69, 1
  store i32 %70, ptr %10, align 4, !tbaa !9
  br label %53, !llvm.loop !17

71:                                               ; preds = %53
  %72 = load i32, ptr %9, align 4, !tbaa !9
  %73 = add nsw i32 %72, 1
  store i32 %73, ptr %9, align 4, !tbaa !9
  br label %74

74:                                               ; preds = %71, %32
  br label %75

75:                                               ; preds = %74, %28
  br label %76

76:                                               ; preds = %75
  %77 = load i32, ptr %11, align 4, !tbaa !9
  %78 = add nsw i32 %77, 1
  store i32 %78, ptr %11, align 4, !tbaa !9
  br label %22, !llvm.loop !19

79:                                               ; preds = %22
  %80 = load ptr, ptr %6, align 8, !tbaa !5
  %81 = getelementptr inbounds %struct.phase_t, ptr %80, i32 0, i32 1
  %82 = load ptr, ptr %81, align 8, !tbaa !16
  %83 = load i32, ptr %7, align 4, !tbaa !9
  %84 = sext i32 %83 to i64
  %85 = getelementptr inbounds ptr, ptr %82, i64 %84
  %86 = load ptr, ptr %85, align 8, !tbaa !5
  store ptr %86, ptr %12, align 8, !tbaa !5
  store i32 0, ptr %10, align 4, !tbaa !9
  br label %87

87:                                               ; preds = %102, %79
  %88 = load i32, ptr %10, align 4, !tbaa !9
  %89 = icmp slt i32 %88, 2
  br i1 %89, label %90, label %105

90:                                               ; preds = %87
  %91 = load ptr, ptr %12, align 8, !tbaa !5
  %92 = load i32, ptr %10, align 4, !tbaa !9
  %93 = sext i32 %92 to i64
  %94 = getelementptr inbounds double, ptr %91, i64 %93
  %95 = load double, ptr %94, align 8, !tbaa !11
  %96 = load ptr, ptr %5, align 8, !tbaa !5
  %97 = load i32, ptr %10, align 4, !tbaa !9
  %98 = sext i32 %97 to i64
  %99 = getelementptr inbounds double, ptr %96, i64 %98
  %100 = load double, ptr %99, align 8, !tbaa !11
  %101 = fadd double %100, %95
  store double %101, ptr %99, align 8, !tbaa !11
  br label %102

102:                                              ; preds = %90
  %103 = load i32, ptr %10, align 4, !tbaa !9
  %104 = add nsw i32 %103, 1
  store i32 %104, ptr %10, align 4, !tbaa !9
  br label %87, !llvm.loop !20

105:                                              ; preds = %87
  %106 = load i32, ptr %9, align 4, !tbaa !9
  %107 = add nsw i32 %106, 1
  store i32 %107, ptr %9, align 4, !tbaa !9
  store i32 0, ptr %10, align 4, !tbaa !9
  br label %108

108:                                              ; preds = %125, %105
  %109 = load i32, ptr %10, align 4, !tbaa !9
  %110 = icmp slt i32 %109, 2
  br i1 %110, label %111, label %128

111:                                              ; preds = %108
  %112 = load ptr, ptr %5, align 8, !tbaa !5
  %113 = load i32, ptr %10, align 4, !tbaa !9
  %114 = sext i32 %113 to i64
  %115 = getelementptr inbounds double, ptr %112, i64 %114
  %116 = load double, ptr %115, align 8, !tbaa !11
  %117 = load i32, ptr %9, align 4, !tbaa !9
  %118 = sitofp i32 %117 to double
  %119 = call double @pow(double noundef %118, double noundef -1.000000e+00) #4
  %120 = fmul double %116, %119
  %121 = load ptr, ptr %5, align 8, !tbaa !5
  %122 = load i32, ptr %10, align 4, !tbaa !9
  %123 = sext i32 %122 to i64
  %124 = getelementptr inbounds double, ptr %121, i64 %123
  store double %120, ptr %124, align 8, !tbaa !11
  br label %125

125:                                              ; preds = %111
  %126 = load i32, ptr %10, align 4, !tbaa !9
  %127 = add nsw i32 %126, 1
  store i32 %127, ptr %10, align 4, !tbaa !9
  br label %108, !llvm.loop !21

128:                                              ; preds = %108
  %129 = load ptr, ptr %5, align 8, !tbaa !5
  %130 = getelementptr inbounds double, ptr %129, i64 2
  store double 0.000000e+00, ptr %130, align 8, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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 = { 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 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"double", !7, i64 0}
!13 = !{!14, !6, i64 0}
!14 = !{!"", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !10, i64 32, !10, i64 36}
!15 = !{!14, !10, i64 36}
!16 = !{!14, !6, i64 8}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}
!19 = distinct !{!19, !18}
!20 = distinct !{!20, !18}
!21 = distinct !{!21, !18}


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

@GetLocalAverageOfXYVelocity.CacheDifferenceVector = external hidden global [3 x double], align 16

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

declare double @VectAbs(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @GetLocalAverageOfXYVelocity(ptr nocapture noundef %0, ptr nocapture noundef readonly %1, i32 noundef %2, double noundef %3) local_unnamed_addr #1 {
  %5 = load ptr, ptr %1, align 8, !tbaa !5
  %6 = sext i32 %2 to i64
  %7 = getelementptr inbounds ptr, ptr %5, i64 %6
  %8 = load ptr, ptr %7, align 8, !tbaa !11
  %9 = getelementptr inbounds i8, ptr %1, i64 36
  %10 = load i32, ptr %9, align 4, !tbaa !12
  %11 = icmp sgt i32 %10, 0
  br i1 %11, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %4
  %12 = getelementptr inbounds i8, ptr %1, i64 8
  %13 = zext i32 %2 to i64
  %14 = getelementptr inbounds i8, ptr %0, i64 8
  br label %15

15:                                               ; preds = %.lr.ph, %33
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %33 ]
  %.042 = phi i32 [ 0, %.lr.ph ], [ %.1, %33 ]
  %.not = icmp eq i64 %indvars.iv, %13
  br i1 %.not, label %33, label %16

16:                                               ; preds = %15
  %17 = load ptr, ptr %12, align 8, !tbaa !13
  %18 = getelementptr inbounds ptr, ptr %17, i64 %indvars.iv
  %19 = load ptr, ptr %18, align 8, !tbaa !11
  %20 = load ptr, ptr %1, align 8, !tbaa !5
  %21 = getelementptr inbounds ptr, ptr %20, i64 %indvars.iv
  %22 = load ptr, ptr %21, align 8, !tbaa !11
  tail call void @VectDifference(ptr noundef nonnull @GetLocalAverageOfXYVelocity.CacheDifferenceVector, ptr noundef %8, ptr noundef %22) #2
  %23 = tail call double @VectAbs(ptr noundef nonnull @GetLocalAverageOfXYVelocity.CacheDifferenceVector) #2
  %24 = fcmp ugt double %23, %3
  br i1 %24, label %33, label %.preheader.preheader

.preheader.preheader:                             ; preds = %16
  %25 = load double, ptr %19, align 8, !tbaa !14
  %26 = load double, ptr %0, align 8, !tbaa !14
  %27 = fadd double %25, %26
  store double %27, ptr %0, align 8, !tbaa !14
  %28 = getelementptr inbounds i8, ptr %19, i64 8
  %29 = load double, ptr %28, align 8, !tbaa !14
  %30 = load double, ptr %14, align 8, !tbaa !14
  %31 = fadd double %29, %30
  store double %31, ptr %14, align 8, !tbaa !14
  %32 = add nsw i32 %.042, 1
  br label %33

33:                                               ; preds = %15, %.preheader.preheader, %16
  %.1 = phi i32 [ %32, %.preheader.preheader ], [ %.042, %16 ], [ %.042, %15 ]
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %34 = load i32, ptr %9, align 4, !tbaa !12
  %35 = sext i32 %34 to i64
  %36 = icmp slt i64 %indvars.iv.next, %35
  br i1 %36, label %15, label %._crit_edge.loopexit, !llvm.loop !16

._crit_edge.loopexit:                             ; preds = %33
  %37 = add nsw i32 %.1, 1
  %38 = sitofp i32 %37 to double
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %4
  %.0.lcssa = phi double [ 1.000000e+00, %4 ], [ %38, %._crit_edge.loopexit ]
  %39 = getelementptr inbounds i8, ptr %1, i64 8
  %40 = load ptr, ptr %39, align 8, !tbaa !13
  %41 = getelementptr inbounds ptr, ptr %40, i64 %6
  %42 = load ptr, ptr %41, align 8, !tbaa !11
  %43 = load double, ptr %42, align 8, !tbaa !14
  %44 = load double, ptr %0, align 8, !tbaa !14
  %45 = getelementptr inbounds i8, ptr %42, i64 8
  %46 = getelementptr inbounds i8, ptr %0, i64 8
  %47 = load double, ptr %46, align 8, !tbaa !14
  %reciprocal = fdiv double 1.000000e+00, %.0.lcssa
  %48 = fadd double %43, %44
  store double %48, ptr %0, align 8, !tbaa !14
  %49 = load double, ptr %45, align 8, !tbaa !14
  %50 = fadd double %49, %47
  %51 = insertelement <2 x double> poison, double %reciprocal, i64 0
  %52 = shufflevector <2 x double> %51, <2 x double> poison, <2 x i32> zeroinitializer
  %53 = insertelement <2 x double> poison, double %48, i64 0
  %54 = insertelement <2 x double> %53, double %50, i64 1
  %55 = fmul <2 x double> %52, %54
  store <2 x double> %55, ptr %0, align 8, !tbaa !14
  %56 = getelementptr inbounds i8, ptr %0, i64 16
  store double 0.000000e+00, ptr %56, align 8, !tbaa !14
  ret void
}

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 = { 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 = { 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, !7, i64 0}
!6 = !{!"", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !10, i64 32, !10, i64 36}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!7, !7, i64 0}
!12 = !{!6, !10, i64 36}
!13 = !{!6, !7, i64 8}
!14 = !{!15, !15, i64 0}
!15 = !{!"double", !8, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}


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