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

@GetAverageOfXYTangentialVelocity.x = external hidden global [3 x double], align 16
@GetAverageOfXYTangentialVelocity.v = external hidden global [3 x double], align 16
@GetAverageOfXYTangentialVelocity.ProjectedMagn = external hidden global double, align 8
@GetAverageOfXYTangentialVelocity.v_i_LAP = external hidden global [3 x double], align 16
@GetAverageOfXYTangentialVelocity.v_j_LAP = external hidden global [3 x double], align 16
@GetAverageOfXYTangentialVelocity.to_ref = 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

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

17:                                               ; preds = %37, %4
  %18 = load i32, ptr %9, align 4, !tbaa !9
  %19 = load ptr, ptr %6, 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 %40

23:                                               ; preds = %17
  %24 = load i32, ptr %9, align 4, !tbaa !9
  %25 = load i32, ptr %8, align 4, !tbaa !9
  %26 = icmp eq i32 %24, %25
  br i1 %26, label %27, label %28

27:                                               ; preds = %23
  br label %37

28:                                               ; preds = %23
  %29 = load ptr, ptr %6, align 8, !tbaa !5
  %30 = load i32, ptr %9, align 4, !tbaa !9
  call void @GetAgentsCoordinates(ptr noundef @GetAverageOfXYTangentialVelocity.x, ptr noundef %29, i32 noundef %30)
  %31 = load ptr, ptr %6, align 8, !tbaa !5
  %32 = load i32, ptr %9, align 4, !tbaa !9
  call void @GetAgentsVelocity(ptr noundef @GetAverageOfXYTangentialVelocity.v, ptr noundef %31, i32 noundef %32)
  %33 = load ptr, ptr %7, align 8, !tbaa !5
  call void @VectDifference(ptr noundef @GetAverageOfXYTangentialVelocity.to_ref, ptr noundef @GetAverageOfXYTangentialVelocity.x, ptr noundef %33)
  call void @RotateVectXY(ptr noundef @GetAverageOfXYTangentialVelocity.v_j_LAP, ptr noundef @GetAverageOfXYTangentialVelocity.to_ref, double noundef 0x3FF921FB54442D18)
  call void @UnitVect(ptr noundef @GetAverageOfXYTangentialVelocity.v_j_LAP, ptr noundef @GetAverageOfXYTangentialVelocity.v_j_LAP)
  %34 = call double @ScalarProduct(ptr noundef @GetAverageOfXYTangentialVelocity.v_j_LAP, ptr noundef @GetAverageOfXYTangentialVelocity.v, i32 noundef 2)
  %35 = load double, ptr @GetAverageOfXYTangentialVelocity.ProjectedMagn, align 8, !tbaa !11
  %36 = fadd double %35, %34
  store double %36, ptr @GetAverageOfXYTangentialVelocity.ProjectedMagn, align 8, !tbaa !11
  br label %37

37:                                               ; preds = %28, %27
  %38 = load i32, ptr %9, align 4, !tbaa !9
  %39 = add nsw i32 %38, 1
  store i32 %39, ptr %9, align 4, !tbaa !9
  br label %17, !llvm.loop !15

40:                                               ; preds = %17
  %41 = load ptr, ptr %5, align 8, !tbaa !5
  %42 = load double, ptr @GetAverageOfXYTangentialVelocity.v_i_LAP, align 16, !tbaa !11
  %43 = load double, ptr getelementptr inbounds ([3 x double], ptr @GetAverageOfXYTangentialVelocity.v_i_LAP, i64 0, i64 1), align 8, !tbaa !11
  call void @FillVect(ptr noundef %41, double noundef %42, double noundef %43, double noundef 0.000000e+00)
  %44 = load ptr, ptr %5, align 8, !tbaa !5
  %45 = load ptr, ptr %5, align 8, !tbaa !5
  %46 = load double, ptr @GetAverageOfXYTangentialVelocity.ProjectedMagn, align 8, !tbaa !11
  %47 = load ptr, ptr %6, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.phase_t, ptr %47, i32 0, i32 5
  %49 = load i32, ptr %48, align 4, !tbaa !13
  %50 = sitofp i32 %49 to double
  %51 = fdiv double %46, %50
  call void @MultiplicateWithScalar(ptr noundef %44, ptr noundef %45, double noundef %51, i32 noundef 2)
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  ret void
}

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

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"

@GetAverageOfXYTangentialVelocity.x = external hidden global [3 x double], align 16
@GetAverageOfXYTangentialVelocity.v = external hidden global [3 x double], align 16
@GetAverageOfXYTangentialVelocity.ProjectedMagn = external hidden local_unnamed_addr global double, align 8
@GetAverageOfXYTangentialVelocity.v_i_LAP = external hidden global [3 x double], align 16
@GetAverageOfXYTangentialVelocity.v_j_LAP = external hidden global [3 x double], align 16
@GetAverageOfXYTangentialVelocity.to_ref = 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

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

.lr.ph:                                           ; preds = %4, %15
  %9 = phi i32 [ %16, %15 ], [ %7, %4 ]
  %.019 = phi i32 [ %17, %15 ], [ 0, %4 ]
  %10 = icmp eq i32 %.019, %3
  br i1 %10, label %15, label %11

11:                                               ; preds = %.lr.ph
  tail call void @GetAgentsCoordinates(ptr noundef nonnull @GetAverageOfXYTangentialVelocity.x, ptr noundef nonnull %1, i32 noundef %.019)
  tail call void @GetAgentsVelocity(ptr noundef nonnull @GetAverageOfXYTangentialVelocity.v, ptr noundef nonnull %1, i32 noundef %.019)
  tail call void @VectDifference(ptr noundef nonnull @GetAverageOfXYTangentialVelocity.to_ref, ptr noundef nonnull @GetAverageOfXYTangentialVelocity.x, ptr noundef %2) #2
  tail call void @RotateVectXY(ptr noundef nonnull @GetAverageOfXYTangentialVelocity.v_j_LAP, ptr noundef nonnull @GetAverageOfXYTangentialVelocity.to_ref, double noundef 0x3FF921FB54442D18) #2
  tail call void @UnitVect(ptr noundef nonnull @GetAverageOfXYTangentialVelocity.v_j_LAP, ptr noundef nonnull @GetAverageOfXYTangentialVelocity.v_j_LAP) #2
  %12 = tail call double @ScalarProduct(ptr noundef nonnull @GetAverageOfXYTangentialVelocity.v_j_LAP, ptr noundef nonnull @GetAverageOfXYTangentialVelocity.v, i32 noundef 2) #2
  %13 = load double, ptr @GetAverageOfXYTangentialVelocity.ProjectedMagn, align 8, !tbaa !5
  %14 = fadd double %12, %13
  store double %14, ptr @GetAverageOfXYTangentialVelocity.ProjectedMagn, align 8, !tbaa !5
  %.pre = load i32, ptr %6, align 4, !tbaa !9
  br label %15

15:                                               ; preds = %.lr.ph, %11
  %16 = phi i32 [ %9, %.lr.ph ], [ %.pre, %11 ]
  %17 = add nuw nsw i32 %.019, 1
  %18 = icmp slt i32 %17, %16
  br i1 %18, label %.lr.ph, label %._crit_edge, !llvm.loop !13

._crit_edge:                                      ; preds = %15, %4
  %19 = load double, ptr @GetAverageOfXYTangentialVelocity.v_i_LAP, align 16, !tbaa !5
  %20 = load double, ptr getelementptr inbounds (i8, ptr @GetAverageOfXYTangentialVelocity.v_i_LAP, i64 8), align 8, !tbaa !5
  tail call void @FillVect(ptr noundef %0, double noundef %19, double noundef %20, double noundef 0.000000e+00) #2
  %21 = load double, ptr @GetAverageOfXYTangentialVelocity.ProjectedMagn, align 8, !tbaa !5
  %22 = load i32, ptr %6, align 4, !tbaa !9
  %23 = sitofp i32 %22 to double
  %24 = fdiv double %21, %23
  tail call void @MultiplicateWithScalar(ptr noundef %0, ptr noundef %0, double noundef %24, i32 noundef 2) #2
  ret void
}

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

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 = !{!"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"}


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