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

@GetLocalAverageOfTangentialVelocity.n = external hidden global i32, align 4
@GetLocalAverageOfTangentialVelocity.x = external hidden global [3 x double], align 16
@GetLocalAverageOfTangentialVelocity.v = external hidden global [3 x double], align 16
@GetLocalAverageOfTangentialVelocity.ProjectedMagn = external hidden global double, align 8
@GetLocalAverageOfTangentialVelocity.v_i_LAP = external hidden global [3 x double], align 16
@GetLocalAverageOfTangentialVelocity.v_j_LAP = external hidden global [3 x double], align 16
@GetLocalAverageOfTangentialVelocity.to_ref = external hidden global [3 x double], align 16
@GetLocalAverageOfTangentialVelocity.x_neighbour = external hidden global [3 x double], align 16
@GetLocalAverageOfTangentialVelocity.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 double @VectAbs(ptr noundef) #2

declare void @NullVect(ptr noundef, i32 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 @GetLocalAverageOfTangentialVelocity(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3, i32 noundef %4, double noundef %5) #1 {
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  %12 = alloca double, align 8
  %13 = alloca i32, align 4
  store ptr %0, ptr %7, align 8, !tbaa !5
  store ptr %1, ptr %8, align 8, !tbaa !5
  store ptr %2, ptr %9, align 8, !tbaa !5
  store ptr %3, ptr %10, align 8, !tbaa !5
  store i32 %4, ptr %11, align 4, !tbaa !9
  store double %5, ptr %12, align 8, !tbaa !11
  %14 = load ptr, ptr %7, align 8, !tbaa !5
  call void @NullVect(ptr noundef %14, i32 noundef 3)
  store i32 1, ptr @GetLocalAverageOfTangentialVelocity.n, align 4, !tbaa !9
  %15 = load ptr, ptr %8, align 8, !tbaa !5
  %16 = load i32, ptr %11, align 4, !tbaa !9
  call void @GetAgentsCoordinates(ptr noundef @GetLocalAverageOfTangentialVelocity.x, ptr noundef %15, i32 noundef %16)
  %17 = load ptr, ptr %8, align 8, !tbaa !5
  %18 = load i32, ptr %11, align 4, !tbaa !9
  call void @GetAgentsVelocity(ptr noundef @GetLocalAverageOfTangentialVelocity.v, ptr noundef %17, i32 noundef %18)
  %19 = load ptr, ptr %9, align 8, !tbaa !5
  call void @VectDifference(ptr noundef @GetLocalAverageOfTangentialVelocity.to_ref, ptr noundef @GetLocalAverageOfTangentialVelocity.x, ptr noundef %19)
  %20 = load ptr, ptr %10, align 8, !tbaa !5
  call void @RotateVectAroundSpecificAxis(ptr noundef @GetLocalAverageOfTangentialVelocity.v_i_LAP, ptr noundef @GetLocalAverageOfTangentialVelocity.to_ref, ptr noundef %20, double noundef 0x3FF921FB54442D18)
  call void @UnitVect(ptr noundef @GetLocalAverageOfTangentialVelocity.v_i_LAP, ptr noundef @GetLocalAverageOfTangentialVelocity.v_i_LAP)
  %21 = call double @ScalarProduct(ptr noundef @GetLocalAverageOfTangentialVelocity.v_i_LAP, ptr noundef @GetLocalAverageOfTangentialVelocity.v, i32 noundef 3)
  store double %21, ptr @GetLocalAverageOfTangentialVelocity.ProjectedMagn, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #3
  store i32 0, ptr %13, align 4, !tbaa !9
  br label %22

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

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

32:                                               ; preds = %28
  br label %50

33:                                               ; preds = %28
  %34 = load ptr, ptr %8, align 8, !tbaa !5
  %35 = load i32, ptr %13, align 4, !tbaa !9
  call void @GetAgentsCoordinates(ptr noundef @GetLocalAverageOfTangentialVelocity.x_neighbour, ptr noundef %34, i32 noundef %35)
  call void @VectDifference(ptr noundef @GetLocalAverageOfTangentialVelocity.DistanceVector, ptr noundef @GetLocalAverageOfTangentialVelocity.x_neighbour, ptr noundef @GetLocalAverageOfTangentialVelocity.x)
  %36 = call double @VectAbs(ptr noundef @GetLocalAverageOfTangentialVelocity.DistanceVector)
  %37 = load double, ptr %12, align 8, !tbaa !11
  %38 = fcmp ole double %36, %37
  br i1 %38, label %39, label %49

39:                                               ; preds = %33
  %40 = load ptr, ptr %8, align 8, !tbaa !5
  %41 = load i32, ptr %13, align 4, !tbaa !9
  call void @GetAgentsVelocity(ptr noundef @GetLocalAverageOfTangentialVelocity.v, ptr noundef %40, i32 noundef %41)
  %42 = load ptr, ptr %9, align 8, !tbaa !5
  call void @VectDifference(ptr noundef @GetLocalAverageOfTangentialVelocity.to_ref, ptr noundef @GetLocalAverageOfTangentialVelocity.x_neighbour, ptr noundef %42)
  %43 = load ptr, ptr %10, align 8, !tbaa !5
  call void @RotateVectAroundSpecificAxis(ptr noundef @GetLocalAverageOfTangentialVelocity.v_j_LAP, ptr noundef @GetLocalAverageOfTangentialVelocity.to_ref, ptr noundef %43, double noundef 0x3FF921FB54442D18)
  call void @UnitVect(ptr noundef @GetLocalAverageOfTangentialVelocity.v_j_LAP, ptr noundef @GetLocalAverageOfTangentialVelocity.v_j_LAP)
  %44 = call double @ScalarProduct(ptr noundef @GetLocalAverageOfTangentialVelocity.v_j_LAP, ptr noundef @GetLocalAverageOfTangentialVelocity.v, i32 noundef 3)
  %45 = load double, ptr @GetLocalAverageOfTangentialVelocity.ProjectedMagn, align 8, !tbaa !11
  %46 = fadd double %45, %44
  store double %46, ptr @GetLocalAverageOfTangentialVelocity.ProjectedMagn, align 8, !tbaa !11
  %47 = load i32, ptr @GetLocalAverageOfTangentialVelocity.n, align 4, !tbaa !9
  %48 = add nsw i32 %47, 1
  store i32 %48, ptr @GetLocalAverageOfTangentialVelocity.n, align 4, !tbaa !9
  br label %49

49:                                               ; preds = %39, %33
  br label %50

50:                                               ; preds = %49, %32
  %51 = load i32, ptr %13, align 4, !tbaa !9
  %52 = add nsw i32 %51, 1
  store i32 %52, ptr %13, align 4, !tbaa !9
  br label %22, !llvm.loop !15

53:                                               ; preds = %22
  %54 = load ptr, ptr %7, align 8, !tbaa !5
  %55 = load double, ptr @GetLocalAverageOfTangentialVelocity.v_i_LAP, align 16, !tbaa !11
  %56 = load double, ptr getelementptr inbounds ([3 x double], ptr @GetLocalAverageOfTangentialVelocity.v_i_LAP, i64 0, i64 1), align 8, !tbaa !11
  %57 = load double, ptr getelementptr inbounds ([3 x double], ptr @GetLocalAverageOfTangentialVelocity.v_i_LAP, i64 0, i64 2), align 16, !tbaa !11
  call void @FillVect(ptr noundef %54, double noundef %55, double noundef %56, double noundef %57)
  %58 = load ptr, ptr %7, align 8, !tbaa !5
  %59 = load ptr, ptr %7, align 8, !tbaa !5
  %60 = load double, ptr @GetLocalAverageOfTangentialVelocity.ProjectedMagn, align 8, !tbaa !11
  %61 = load i32, ptr @GetLocalAverageOfTangentialVelocity.n, align 4, !tbaa !9
  %62 = sitofp i32 %61 to double
  %63 = fdiv double %60, %62
  call void @MultiplicateWithScalar(ptr noundef %58, ptr noundef %59, double noundef %63, i32 noundef 3)
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #3
  ret void
}

declare void @RotateVectAroundSpecificAxis(ptr noundef, ptr noundef, ptr noundef, double 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"

@GetLocalAverageOfTangentialVelocity.n = external hidden local_unnamed_addr global i32, align 4
@GetLocalAverageOfTangentialVelocity.x = external hidden global [3 x double], align 16
@GetLocalAverageOfTangentialVelocity.v = external hidden global [3 x double], align 16
@GetLocalAverageOfTangentialVelocity.ProjectedMagn = external hidden local_unnamed_addr global double, align 8
@GetLocalAverageOfTangentialVelocity.v_i_LAP = external hidden global [3 x double], align 16
@GetLocalAverageOfTangentialVelocity.v_j_LAP = external hidden global [3 x double], align 16
@GetLocalAverageOfTangentialVelocity.to_ref = external hidden global [3 x double], align 16
@GetLocalAverageOfTangentialVelocity.x_neighbour = external hidden global [3 x double], align 16
@GetLocalAverageOfTangentialVelocity.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 double @VectAbs(ptr noundef) local_unnamed_addr #1

declare void @NullVect(ptr noundef, i32 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 @GetLocalAverageOfTangentialVelocity(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3, i32 noundef %4, double noundef %5) local_unnamed_addr #0 {
  tail call void @NullVect(ptr noundef %0, i32 noundef 3) #2
  store i32 1, ptr @GetLocalAverageOfTangentialVelocity.n, align 4, !tbaa !5
  tail call void @GetAgentsCoordinates(ptr noundef nonnull @GetLocalAverageOfTangentialVelocity.x, ptr noundef %1, i32 noundef %4)
  tail call void @GetAgentsVelocity(ptr noundef nonnull @GetLocalAverageOfTangentialVelocity.v, ptr noundef %1, i32 noundef %4)
  tail call void @VectDifference(ptr noundef nonnull @GetLocalAverageOfTangentialVelocity.to_ref, ptr noundef nonnull @GetLocalAverageOfTangentialVelocity.x, ptr noundef %2) #2
  tail call void @RotateVectAroundSpecificAxis(ptr noundef nonnull @GetLocalAverageOfTangentialVelocity.v_i_LAP, ptr noundef nonnull @GetLocalAverageOfTangentialVelocity.to_ref, ptr noundef %3, double noundef 0x3FF921FB54442D18) #2
  tail call void @UnitVect(ptr noundef nonnull @GetLocalAverageOfTangentialVelocity.v_i_LAP, ptr noundef nonnull @GetLocalAverageOfTangentialVelocity.v_i_LAP) #2
  %7 = tail call double @ScalarProduct(ptr noundef nonnull @GetLocalAverageOfTangentialVelocity.v_i_LAP, ptr noundef nonnull @GetLocalAverageOfTangentialVelocity.v, i32 noundef 3) #2
  store double %7, ptr @GetLocalAverageOfTangentialVelocity.ProjectedMagn, align 8, !tbaa !9
  %8 = getelementptr inbounds i8, ptr %1, i64 36
  %9 = load i32, ptr %8, align 4, !tbaa !11
  %10 = icmp sgt i32 %9, 0
  br i1 %10, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %6, %21
  %.021 = phi i32 [ %22, %21 ], [ 0, %6 ]
  %11 = icmp eq i32 %.021, %4
  br i1 %11, label %21, label %12

12:                                               ; preds = %.lr.ph
  tail call void @GetAgentsCoordinates(ptr noundef nonnull @GetLocalAverageOfTangentialVelocity.x_neighbour, ptr noundef nonnull %1, i32 noundef %.021)
  tail call void @VectDifference(ptr noundef nonnull @GetLocalAverageOfTangentialVelocity.DistanceVector, ptr noundef nonnull @GetLocalAverageOfTangentialVelocity.x_neighbour, ptr noundef nonnull @GetLocalAverageOfTangentialVelocity.x) #2
  %13 = tail call double @VectAbs(ptr noundef nonnull @GetLocalAverageOfTangentialVelocity.DistanceVector) #2
  %14 = fcmp ugt double %13, %5
  br i1 %14, label %21, label %15

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

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

._crit_edge:                                      ; preds = %21, %6
  %25 = load double, ptr @GetLocalAverageOfTangentialVelocity.v_i_LAP, align 16, !tbaa !9
  %26 = load double, ptr getelementptr inbounds (i8, ptr @GetLocalAverageOfTangentialVelocity.v_i_LAP, i64 8), align 8, !tbaa !9
  %27 = load double, ptr getelementptr inbounds (i8, ptr @GetLocalAverageOfTangentialVelocity.v_i_LAP, i64 16), align 16, !tbaa !9
  tail call void @FillVect(ptr noundef %0, double noundef %25, double noundef %26, double noundef %27) #2
  %28 = load double, ptr @GetLocalAverageOfTangentialVelocity.ProjectedMagn, align 8, !tbaa !9
  %29 = load i32, ptr @GetLocalAverageOfTangentialVelocity.n, align 4, !tbaa !5
  %30 = sitofp i32 %29 to double
  %31 = fdiv double %28, %30
  tail call void @MultiplicateWithScalar(ptr noundef %0, ptr noundef %0, double noundef %31, i32 noundef 3) #2
  ret void
}

declare void @RotateVectAroundSpecificAxis(ptr noundef, ptr noundef, ptr noundef, double 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