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

@GetLocalAverageOfXYTangentialVelocity.n = external hidden global i32, align 4
@GetLocalAverageOfXYTangentialVelocity.x = external hidden global [3 x double], align 16
@GetLocalAverageOfXYTangentialVelocity.v = external hidden global [3 x double], align 16
@GetLocalAverageOfXYTangentialVelocity.ProjectedMagn = external hidden global double, align 8
@GetLocalAverageOfXYTangentialVelocity.v_i_LAP = external hidden global [3 x double], align 16
@GetLocalAverageOfXYTangentialVelocity.v_j_LAP = external hidden global [3 x double], align 16
@GetLocalAverageOfXYTangentialVelocity.to_ref = external hidden global [3 x double], align 16
@GetLocalAverageOfXYTangentialVelocity.x_neighbour = external hidden global [3 x double], align 16
@GetLocalAverageOfXYTangentialVelocity.DistanceVector = 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 uwtable
declare dso_local void @GetAgentsVelocity(ptr noundef, ptr noundef, i32 noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local void @GetAgentsCoordinates(ptr noundef, ptr noundef, i32 noundef) #1

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

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

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

declare void @RotateVectXY(ptr noundef, ptr noundef, double noundef) #2

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

declare double @ScalarProduct(ptr noundef, ptr noundef, i32 noundef) #2

declare void @FillVect(ptr noundef, double noundef, double noundef, double noundef) #2

; Function Attrs: nounwind uwtable
define dso_local void @GetLocalAverageOfXYTangentialVelocity(ptr noundef %0, ptr noundef %1, ptr noundef %2, i32 noundef %3, double noundef %4) #1 {
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca double, align 8
  %11 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store ptr %2, ptr %8, align 8, !tbaa !5
  store i32 %3, ptr %9, align 4, !tbaa !9
  store double %4, ptr %10, align 8, !tbaa !11
  %12 = load ptr, ptr %6, align 8, !tbaa !5
  call void @NullVect(ptr noundef %12, i32 noundef 3)
  store i32 1, ptr @GetLocalAverageOfXYTangentialVelocity.n, align 4, !tbaa !9
  %13 = load ptr, ptr %7, align 8, !tbaa !5
  %14 = load i32, ptr %9, align 4, !tbaa !9
  call void @GetAgentsCoordinates(ptr noundef @GetLocalAverageOfXYTangentialVelocity.x, ptr noundef %13, i32 noundef %14)
  %15 = load ptr, ptr %7, align 8, !tbaa !5
  %16 = load i32, ptr %9, align 4, !tbaa !9
  call void @GetAgentsVelocity(ptr noundef @GetLocalAverageOfXYTangentialVelocity.v, ptr noundef %15, i32 noundef %16)
  %17 = load ptr, ptr %8, align 8, !tbaa !5
  call void @VectDifference(ptr noundef @GetLocalAverageOfXYTangentialVelocity.to_ref, ptr noundef @GetLocalAverageOfXYTangentialVelocity.x, ptr noundef %17)
  call void @RotateVectXY(ptr noundef @GetLocalAverageOfXYTangentialVelocity.v_i_LAP, ptr noundef @GetLocalAverageOfXYTangentialVelocity.to_ref, double noundef 0x3FF921FB54442D18)
  call void @UnitVect(ptr noundef @GetLocalAverageOfXYTangentialVelocity.v_i_LAP, ptr noundef @GetLocalAverageOfXYTangentialVelocity.v_i_LAP)
  %18 = call double @ScalarProduct(ptr noundef @GetLocalAverageOfXYTangentialVelocity.v_i_LAP, ptr noundef @GetLocalAverageOfXYTangentialVelocity.v, i32 noundef 2)
  store double %18, ptr @GetLocalAverageOfXYTangentialVelocity.ProjectedMagn, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  store i32 0, ptr %11, align 4, !tbaa !9
  br label %19

19:                                               ; preds = %46, %5
  %20 = load i32, ptr %11, align 4, !tbaa !9
  %21 = load ptr, ptr %7, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.phase_t, ptr %21, i32 0, i32 5
  %23 = load i32, ptr %22, align 4, !tbaa !13
  %24 = icmp slt i32 %20, %23
  br i1 %24, label %25, label %49

25:                                               ; preds = %19
  %26 = load i32, ptr %11, align 4, !tbaa !9
  %27 = load i32, ptr %9, align 4, !tbaa !9
  %28 = icmp eq i32 %26, %27
  br i1 %28, label %29, label %30

29:                                               ; preds = %25
  br label %46

30:                                               ; preds = %25
  %31 = load ptr, ptr %7, align 8, !tbaa !5
  %32 = load i32, ptr %11, align 4, !tbaa !9
  call void @GetAgentsCoordinates(ptr noundef @GetLocalAverageOfXYTangentialVelocity.x_neighbour, ptr noundef %31, i32 noundef %32)
  call void @VectDifference(ptr noundef @GetLocalAverageOfXYTangentialVelocity.DistanceVector, ptr noundef @GetLocalAverageOfXYTangentialVelocity.x_neighbour, ptr noundef @GetLocalAverageOfXYTangentialVelocity.x)
  %33 = call double @VectAbsXY(ptr noundef @GetLocalAverageOfXYTangentialVelocity.DistanceVector)
  %34 = load double, ptr %10, align 8, !tbaa !11
  %35 = fcmp ole double %33, %34
  br i1 %35, label %36, label %45

36:                                               ; preds = %30
  %37 = load ptr, ptr %7, align 8, !tbaa !5
  %38 = load i32, ptr %11, align 4, !tbaa !9
  call void @GetAgentsVelocity(ptr noundef @GetLocalAverageOfXYTangentialVelocity.v, ptr noundef %37, i32 noundef %38)
  %39 = load ptr, ptr %8, align 8, !tbaa !5
  call void @VectDifference(ptr noundef @GetLocalAverageOfXYTangentialVelocity.to_ref, ptr noundef @GetLocalAverageOfXYTangentialVelocity.x_neighbour, ptr noundef %39)
  call void @RotateVectXY(ptr noundef @GetLocalAverageOfXYTangentialVelocity.v_j_LAP, ptr noundef @GetLocalAverageOfXYTangentialVelocity.to_ref, double noundef 0x3FF921FB54442D18)
  call void @UnitVect(ptr noundef @GetLocalAverageOfXYTangentialVelocity.v_j_LAP, ptr noundef @GetLocalAverageOfXYTangentialVelocity.v_j_LAP)
  %40 = call double @ScalarProduct(ptr noundef @GetLocalAverageOfXYTangentialVelocity.v_j_LAP, ptr noundef @GetLocalAverageOfXYTangentialVelocity.v, i32 noundef 2)
  %41 = load double, ptr @GetLocalAverageOfXYTangentialVelocity.ProjectedMagn, align 8, !tbaa !11
  %42 = fadd double %41, %40
  store double %42, ptr @GetLocalAverageOfXYTangentialVelocity.ProjectedMagn, align 8, !tbaa !11
  %43 = load i32, ptr @GetLocalAverageOfXYTangentialVelocity.n, align 4, !tbaa !9
  %44 = add nsw i32 %43, 1
  store i32 %44, ptr @GetLocalAverageOfXYTangentialVelocity.n, align 4, !tbaa !9
  br label %45

45:                                               ; preds = %36, %30
  br label %46

46:                                               ; preds = %45, %29
  %47 = load i32, ptr %11, align 4, !tbaa !9
  %48 = add nsw i32 %47, 1
  store i32 %48, ptr %11, align 4, !tbaa !9
  br label %19, !llvm.loop !15

49:                                               ; preds = %19
  %50 = load ptr, ptr %6, align 8, !tbaa !5
  %51 = load double, ptr @GetLocalAverageOfXYTangentialVelocity.v_i_LAP, align 16, !tbaa !11
  %52 = load double, ptr getelementptr inbounds ([3 x double], ptr @GetLocalAverageOfXYTangentialVelocity.v_i_LAP, i64 0, i64 1), align 8, !tbaa !11
  call void @FillVect(ptr noundef %50, double noundef %51, double noundef %52, double noundef 0.000000e+00)
  %53 = load ptr, ptr %6, align 8, !tbaa !5
  %54 = load ptr, ptr %6, align 8, !tbaa !5
  %55 = load double, ptr @GetLocalAverageOfXYTangentialVelocity.ProjectedMagn, align 8, !tbaa !11
  %56 = load i32, ptr @GetLocalAverageOfXYTangentialVelocity.n, align 4, !tbaa !9
  %57 = sitofp i32 %56 to double
  %58 = fdiv double %55, %57
  call void @MultiplicateWithScalar(ptr noundef %53, ptr noundef %54, double noundef %58, i32 noundef 2)
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  ret void
}

declare double @VectAbsXY(ptr noundef) #2

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 = { 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, !10, i64 36}
!14 = !{!"", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !10, i64 32, !10, i64 36}
!15 = distinct !{!15, !16}
!16 = !{!"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"

@GetLocalAverageOfXYTangentialVelocity.n = external hidden local_unnamed_addr global i32, align 4
@GetLocalAverageOfXYTangentialVelocity.x = external hidden global [3 x double], align 16
@GetLocalAverageOfXYTangentialVelocity.v = external hidden global [3 x double], align 16
@GetLocalAverageOfXYTangentialVelocity.ProjectedMagn = external hidden local_unnamed_addr global double, align 8
@GetLocalAverageOfXYTangentialVelocity.v_i_LAP = external hidden global [3 x double], align 16
@GetLocalAverageOfXYTangentialVelocity.v_j_LAP = external hidden global [3 x double], align 16
@GetLocalAverageOfXYTangentialVelocity.to_ref = external hidden global [3 x double], align 16
@GetLocalAverageOfXYTangentialVelocity.x_neighbour = external hidden global [3 x double], align 16
@GetLocalAverageOfXYTangentialVelocity.DistanceVector = external hidden global [3 x double], align 16

; Function Attrs: nounwind uwtable
declare dso_local void @GetAgentsVelocity(ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local void @GetAgentsCoordinates(ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #0

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

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

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

declare void @RotateVectXY(ptr noundef, ptr noundef, double noundef) local_unnamed_addr #1

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

declare double @ScalarProduct(ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #1

declare void @FillVect(ptr noundef, double noundef, double noundef, double noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local void @GetLocalAverageOfXYTangentialVelocity(ptr noundef %0, ptr noundef %1, ptr noundef %2, i32 noundef %3, double noundef %4) local_unnamed_addr #0 {
  tail call void @NullVect(ptr noundef %0, i32 noundef 3) #2
  store i32 1, ptr @GetLocalAverageOfXYTangentialVelocity.n, align 4, !tbaa !5
  tail call void @GetAgentsCoordinates(ptr noundef nonnull @GetLocalAverageOfXYTangentialVelocity.x, ptr noundef %1, i32 noundef %3)
  tail call void @GetAgentsVelocity(ptr noundef nonnull @GetLocalAverageOfXYTangentialVelocity.v, ptr noundef %1, i32 noundef %3)
  tail call void @VectDifference(ptr noundef nonnull @GetLocalAverageOfXYTangentialVelocity.to_ref, ptr noundef nonnull @GetLocalAverageOfXYTangentialVelocity.x, ptr noundef %2) #2
  tail call void @RotateVectXY(ptr noundef nonnull @GetLocalAverageOfXYTangentialVelocity.v_i_LAP, ptr noundef nonnull @GetLocalAverageOfXYTangentialVelocity.to_ref, double noundef 0x3FF921FB54442D18) #2
  tail call void @UnitVect(ptr noundef nonnull @GetLocalAverageOfXYTangentialVelocity.v_i_LAP, ptr noundef nonnull @GetLocalAverageOfXYTangentialVelocity.v_i_LAP) #2
  %6 = tail call double @ScalarProduct(ptr noundef nonnull @GetLocalAverageOfXYTangentialVelocity.v_i_LAP, ptr noundef nonnull @GetLocalAverageOfXYTangentialVelocity.v, i32 noundef 2) #2
  store double %6, ptr @GetLocalAverageOfXYTangentialVelocity.ProjectedMagn, align 8, !tbaa !9
  %7 = getelementptr inbounds i8, ptr %1, i64 36
  %8 = load i32, ptr %7, align 4, !tbaa !11
  %9 = icmp sgt i32 %8, 0
  br i1 %9, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %5, %20
  %.019 = phi i32 [ %21, %20 ], [ 0, %5 ]
  %10 = icmp eq i32 %.019, %3
  br i1 %10, label %20, label %11

11:                                               ; preds = %.lr.ph
  tail call void @GetAgentsCoordinates(ptr noundef nonnull @GetLocalAverageOfXYTangentialVelocity.x_neighbour, ptr noundef nonnull %1, i32 noundef %.019)
  tail call void @VectDifference(ptr noundef nonnull @GetLocalAverageOfXYTangentialVelocity.DistanceVector, ptr noundef nonnull @GetLocalAverageOfXYTangentialVelocity.x_neighbour, ptr noundef nonnull @GetLocalAverageOfXYTangentialVelocity.x) #2
  %12 = tail call double @VectAbsXY(ptr noundef nonnull @GetLocalAverageOfXYTangentialVelocity.DistanceVector) #2
  %13 = fcmp ugt double %12, %4
  br i1 %13, label %20, label %14

14:                                               ; preds = %11
  tail call void @GetAgentsVelocity(ptr noundef nonnull @GetLocalAverageOfXYTangentialVelocity.v, ptr noundef nonnull %1, i32 noundef %.019)
  tail call void @VectDifference(ptr noundef nonnull @GetLocalAverageOfXYTangentialVelocity.to_ref, ptr noundef nonnull @GetLocalAverageOfXYTangentialVelocity.x_neighbour, ptr noundef %2) #2
  tail call void @RotateVectXY(ptr noundef nonnull @GetLocalAverageOfXYTangentialVelocity.v_j_LAP, ptr noundef nonnull @GetLocalAverageOfXYTangentialVelocity.to_ref, double noundef 0x3FF921FB54442D18) #2
  tail call void @UnitVect(ptr noundef nonnull @GetLocalAverageOfXYTangentialVelocity.v_j_LAP, ptr noundef nonnull @GetLocalAverageOfXYTangentialVelocity.v_j_LAP) #2
  %15 = tail call double @ScalarProduct(ptr noundef nonnull @GetLocalAverageOfXYTangentialVelocity.v_j_LAP, ptr noundef nonnull @GetLocalAverageOfXYTangentialVelocity.v, i32 noundef 2) #2
  %16 = load double, ptr @GetLocalAverageOfXYTangentialVelocity.ProjectedMagn, align 8, !tbaa !9
  %17 = fadd double %15, %16
  store double %17, ptr @GetLocalAverageOfXYTangentialVelocity.ProjectedMagn, align 8, !tbaa !9
  %18 = load i32, ptr @GetLocalAverageOfXYTangentialVelocity.n, align 4, !tbaa !5
  %19 = add nsw i32 %18, 1
  store i32 %19, ptr @GetLocalAverageOfXYTangentialVelocity.n, align 4, !tbaa !5
  br label %20

20:                                               ; preds = %11, %14, %.lr.ph
  %21 = add nuw nsw i32 %.019, 1
  %22 = load i32, ptr %7, align 4, !tbaa !11
  %23 = icmp slt i32 %21, %22
  br i1 %23, label %.lr.ph, label %._crit_edge, !llvm.loop !14

._crit_edge:                                      ; preds = %20, %5
  %24 = load double, ptr @GetLocalAverageOfXYTangentialVelocity.v_i_LAP, align 16, !tbaa !9
  %25 = load double, ptr getelementptr inbounds (i8, ptr @GetLocalAverageOfXYTangentialVelocity.v_i_LAP, i64 8), align 8, !tbaa !9
  tail call void @FillVect(ptr noundef %0, double noundef %24, double noundef %25, double noundef 0.000000e+00) #2
  %26 = load double, ptr @GetLocalAverageOfXYTangentialVelocity.ProjectedMagn, align 8, !tbaa !9
  %27 = load i32, ptr @GetLocalAverageOfXYTangentialVelocity.n, align 4, !tbaa !5
  %28 = sitofp i32 %27 to double
  %29 = fdiv double %26, %28
  tail call void @MultiplicateWithScalar(ptr noundef %0, ptr noundef %0, double noundef %29, i32 noundef 2) #2
  ret void
}

declare double @VectAbsXY(ptr noundef) local_unnamed_addr #1

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 = { 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 = !{!"int", !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, !6, i64 36}
!12 = !{!"", !13, i64 0, !13, i64 8, !13, i64 16, !13, i64 24, !6, i64 32, !6, i64 36}
!13 = !{!"any pointer", !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass