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

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

@FrictionLinSqrt.DifferenceVector = external hidden global [3 x double], align 16
@FrictionLinSqrt.DistanceFromNeighbour = external hidden global double, align 8
@FrictionLinSqrt.VelDiff = external hidden global double, align 8
@FrictionLinSqrt.MaxVelDiff = external hidden global double, align 8

; Function Attrs: nounwind uwtable
define dso_local void @FrictionLinSqrt(ptr noundef %0, ptr noundef %1, double noundef %2, double noundef %3, double noundef %4, double noundef %5, double noundef %6, i32 noundef %7, i32 noundef %8) #0 {
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca double, align 8
  %13 = alloca double, align 8
  %14 = alloca double, align 8
  %15 = alloca double, align 8
  %16 = alloca double, align 8
  %17 = alloca i32, align 4
  %18 = alloca i32, align 4
  %19 = alloca i32, align 4
  %20 = alloca i32, align 4
  %21 = alloca ptr, align 8
  %22 = alloca ptr, align 8
  %23 = alloca ptr, align 8
  %24 = alloca ptr, align 8
  store ptr %0, ptr %10, align 8, !tbaa !5
  store ptr %1, ptr %11, align 8, !tbaa !5
  store double %2, ptr %12, align 8, !tbaa !9
  store double %3, ptr %13, align 8, !tbaa !9
  store double %4, ptr %14, align 8, !tbaa !9
  store double %5, ptr %15, align 8, !tbaa !9
  store double %6, ptr %16, align 8, !tbaa !9
  store i32 %7, ptr %17, align 4, !tbaa !11
  store i32 %8, ptr %18, align 4, !tbaa !11
  %25 = load ptr, ptr %10, align 8, !tbaa !5
  call void @NullVect(ptr noundef %25, i32 noundef 3)
  call void @llvm.lifetime.start.p0(i64 4, ptr %19) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %20) #3
  store i32 0, ptr %20, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %21) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %22) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %23) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %24) #3
  %26 = load ptr, ptr %11, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.phase_t, ptr %26, i32 0, i32 0
  %28 = load ptr, ptr %27, align 8, !tbaa !13
  %29 = load i32, ptr %17, align 4, !tbaa !11
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds ptr, ptr %28, i64 %30
  %32 = load ptr, ptr %31, align 8, !tbaa !5
  store ptr %32, ptr %21, align 8, !tbaa !5
  %33 = load ptr, ptr %11, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.phase_t, ptr %33, i32 0, i32 1
  %35 = load ptr, ptr %34, align 8, !tbaa !15
  %36 = load i32, ptr %17, align 4, !tbaa !11
  %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 %22, align 8, !tbaa !5
  store i32 0, ptr %19, align 4, !tbaa !11
  br label %40

40:                                               ; preds = %108, %9
  %41 = load i32, ptr %19, align 4, !tbaa !11
  %42 = load ptr, ptr %11, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.phase_t, ptr %42, i32 0, i32 5
  %44 = load i32, ptr %43, align 4, !tbaa !16
  %45 = icmp slt i32 %41, %44
  br i1 %45, label %46, label %111

46:                                               ; preds = %40
  %47 = load i32, ptr %19, align 4, !tbaa !11
  %48 = load i32, ptr %17, align 4, !tbaa !11
  %49 = icmp eq i32 %47, %48
  br i1 %49, label %50, label %51

50:                                               ; preds = %46
  br label %108

51:                                               ; preds = %46
  %52 = load ptr, ptr %11, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.phase_t, ptr %52, i32 0, i32 0
  %54 = load ptr, ptr %53, align 8, !tbaa !13
  %55 = load i32, ptr %19, align 4, !tbaa !11
  %56 = sext i32 %55 to i64
  %57 = getelementptr inbounds ptr, ptr %54, i64 %56
  %58 = load ptr, ptr %57, align 8, !tbaa !5
  store ptr %58, ptr %23, align 8, !tbaa !5
  call void @NullVect(ptr noundef @FrictionLinSqrt.DifferenceVector, i32 noundef 3)
  %59 = load ptr, ptr %23, align 8, !tbaa !5
  %60 = load ptr, ptr %21, align 8, !tbaa !5
  call void @VectDifference(ptr noundef @FrictionLinSqrt.DifferenceVector, ptr noundef %59, ptr noundef %60)
  %61 = call double @VectAbs(ptr noundef @FrictionLinSqrt.DifferenceVector)
  store double %61, ptr @FrictionLinSqrt.DistanceFromNeighbour, align 8, !tbaa !9
  %62 = load ptr, ptr %11, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.phase_t, ptr %62, i32 0, i32 1
  %64 = load ptr, ptr %63, align 8, !tbaa !15
  %65 = load i32, ptr %19, align 4, !tbaa !11
  %66 = sext i32 %65 to i64
  %67 = getelementptr inbounds ptr, ptr %64, i64 %66
  %68 = load ptr, ptr %67, align 8, !tbaa !5
  store ptr %68, ptr %24, align 8, !tbaa !5
  %69 = load ptr, ptr %24, align 8, !tbaa !5
  %70 = load ptr, ptr %22, align 8, !tbaa !5
  call void @VectDifference(ptr noundef @FrictionLinSqrt.DifferenceVector, ptr noundef %69, ptr noundef %70)
  %71 = load i32, ptr %18, align 4, !tbaa !11
  %72 = icmp eq i32 2, %71
  br i1 %72, label %73, label %74

73:                                               ; preds = %51
  store double 0.000000e+00, ptr getelementptr inbounds ([3 x double], ptr @FrictionLinSqrt.DifferenceVector, i64 0, i64 2), align 16, !tbaa !9
  br label %74

74:                                               ; preds = %73, %51
  %75 = call double @VectAbs(ptr noundef @FrictionLinSqrt.DifferenceVector)
  store double %75, ptr @FrictionLinSqrt.VelDiff, align 8, !tbaa !9
  call void @UnitVect(ptr noundef @FrictionLinSqrt.DifferenceVector, ptr noundef @FrictionLinSqrt.DifferenceVector)
  %76 = load double, ptr %13, align 8, !tbaa !9
  %77 = load double, ptr @FrictionLinSqrt.DistanceFromNeighbour, align 8, !tbaa !9
  %78 = load double, ptr %15, align 8, !tbaa !9
  %79 = load double, ptr %14, align 8, !tbaa !9
  %80 = load double, ptr @FrictionLinSqrt.VelDiff, align 8, !tbaa !9
  %81 = load double, ptr %16, align 8, !tbaa !9
  %82 = call double @VelDecayLinSqrt(double noundef %77, double noundef %78, double noundef %79, double noundef %80, double noundef %81)
  %83 = fcmp ogt double %76, %82
  br i1 %83, label %84, label %86

84:                                               ; preds = %74
  %85 = load double, ptr %13, align 8, !tbaa !9
  br label %93

86:                                               ; preds = %74
  %87 = load double, ptr @FrictionLinSqrt.DistanceFromNeighbour, align 8, !tbaa !9
  %88 = load double, ptr %15, align 8, !tbaa !9
  %89 = load double, ptr %14, align 8, !tbaa !9
  %90 = load double, ptr @FrictionLinSqrt.VelDiff, align 8, !tbaa !9
  %91 = load double, ptr %16, align 8, !tbaa !9
  %92 = call double @VelDecayLinSqrt(double noundef %87, double noundef %88, double noundef %89, double noundef %90, double noundef %91)
  br label %93

93:                                               ; preds = %86, %84
  %94 = phi double [ %85, %84 ], [ %92, %86 ]
  store double %94, ptr @FrictionLinSqrt.MaxVelDiff, align 8, !tbaa !9
  %95 = load double, ptr @FrictionLinSqrt.VelDiff, align 8, !tbaa !9
  %96 = load double, ptr @FrictionLinSqrt.MaxVelDiff, align 8, !tbaa !9
  %97 = fcmp ogt double %95, %96
  br i1 %97, label %98, label %107

98:                                               ; preds = %93
  %99 = load double, ptr %12, align 8, !tbaa !9
  %100 = load double, ptr @FrictionLinSqrt.VelDiff, align 8, !tbaa !9
  %101 = load double, ptr @FrictionLinSqrt.MaxVelDiff, align 8, !tbaa !9
  %102 = fsub double %100, %101
  %103 = fmul double %99, %102
  %104 = load i32, ptr %18, align 4, !tbaa !11
  call void @MultiplicateWithScalar(ptr noundef @FrictionLinSqrt.DifferenceVector, ptr noundef @FrictionLinSqrt.DifferenceVector, double noundef %103, i32 noundef %104)
  %105 = load ptr, ptr %10, align 8, !tbaa !5
  %106 = load ptr, ptr %10, align 8, !tbaa !5
  call void @VectSum(ptr noundef %105, ptr noundef %106, ptr noundef @FrictionLinSqrt.DifferenceVector)
  br label %107

107:                                              ; preds = %98, %93
  br label %108

108:                                              ; preds = %107, %50
  %109 = load i32, ptr %19, align 4, !tbaa !11
  %110 = add nsw i32 %109, 1
  store i32 %110, ptr %19, align 4, !tbaa !11
  br label %40, !llvm.loop !17

111:                                              ; preds = %40
  call void @llvm.lifetime.end.p0(i64 8, ptr %24) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %23) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %22) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %21) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %20) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %19) #3
  ret void
}

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

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #2

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

declare double @VectAbs(ptr noundef) #1

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

declare double @VelDecayLinSqrt(double noundef, double noundef, double noundef, double noundef, double noundef) #1

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

declare void @VectSum(ptr noundef, ptr noundef, ptr noundef) #1

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #2

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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = !{!"double", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !6, i64 0}
!14 = !{!"", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !12, i64 32, !12, i64 36}
!15 = !{!14, !6, i64 8}
!16 = !{!14, !12, i64 36}
!17 = distinct !{!17, !18}
!18 = !{!"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"

@FrictionLinSqrt.DifferenceVector = external hidden global [3 x double], align 16
@FrictionLinSqrt.DistanceFromNeighbour = external hidden local_unnamed_addr global double, align 8
@FrictionLinSqrt.VelDiff = external hidden local_unnamed_addr global double, align 8
@FrictionLinSqrt.MaxVelDiff = external hidden local_unnamed_addr global double, align 8

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

.lr.ph:                                           ; preds = %9
  %21 = icmp eq i32 %8, 2
  %22 = zext i32 %7 to i64
  br label %23

23:                                               ; preds = %.lr.ph, %51
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %51 ]
  %24 = icmp eq i64 %indvars.iv, %22
  br i1 %24, label %51, label %25

25:                                               ; preds = %23
  %26 = load ptr, ptr %1, align 8, !tbaa !5
  %27 = getelementptr inbounds ptr, ptr %26, i64 %indvars.iv
  %28 = load ptr, ptr %27, align 8, !tbaa !11
  tail call void @NullVect(ptr noundef nonnull @FrictionLinSqrt.DifferenceVector, i32 noundef 3) #2
  tail call void @VectDifference(ptr noundef nonnull @FrictionLinSqrt.DifferenceVector, ptr noundef %28, ptr noundef %13) #2
  %29 = tail call double @VectAbs(ptr noundef nonnull @FrictionLinSqrt.DifferenceVector) #2
  store double %29, ptr @FrictionLinSqrt.DistanceFromNeighbour, align 8, !tbaa !14
  %30 = load ptr, ptr %14, align 8, !tbaa !12
  %31 = getelementptr inbounds ptr, ptr %30, i64 %indvars.iv
  %32 = load ptr, ptr %31, align 8, !tbaa !11
  tail call void @VectDifference(ptr noundef nonnull @FrictionLinSqrt.DifferenceVector, ptr noundef %32, ptr noundef %17) #2
  br i1 %21, label %33, label %34

33:                                               ; preds = %25
  store double 0.000000e+00, ptr getelementptr inbounds (i8, ptr @FrictionLinSqrt.DifferenceVector, i64 16), align 16, !tbaa !14
  br label %34

34:                                               ; preds = %33, %25
  %35 = tail call double @VectAbs(ptr noundef nonnull @FrictionLinSqrt.DifferenceVector) #2
  store double %35, ptr @FrictionLinSqrt.VelDiff, align 8, !tbaa !14
  tail call void @UnitVect(ptr noundef nonnull @FrictionLinSqrt.DifferenceVector, ptr noundef nonnull @FrictionLinSqrt.DifferenceVector) #2
  %36 = load double, ptr @FrictionLinSqrt.DistanceFromNeighbour, align 8, !tbaa !14
  %37 = load double, ptr @FrictionLinSqrt.VelDiff, align 8, !tbaa !14
  %38 = tail call double @VelDecayLinSqrt(double noundef %36, double noundef %5, double noundef %4, double noundef %37, double noundef %6) #2
  %39 = fcmp olt double %38, %3
  br i1 %39, label %44, label %40

40:                                               ; preds = %34
  %41 = load double, ptr @FrictionLinSqrt.DistanceFromNeighbour, align 8, !tbaa !14
  %42 = load double, ptr @FrictionLinSqrt.VelDiff, align 8, !tbaa !14
  %43 = tail call double @VelDecayLinSqrt(double noundef %41, double noundef %5, double noundef %4, double noundef %42, double noundef %6) #2
  br label %44

44:                                               ; preds = %34, %40
  %45 = phi double [ %43, %40 ], [ %3, %34 ]
  store double %45, ptr @FrictionLinSqrt.MaxVelDiff, align 8, !tbaa !14
  %46 = load double, ptr @FrictionLinSqrt.VelDiff, align 8, !tbaa !14
  %47 = fcmp ogt double %46, %45
  br i1 %47, label %48, label %51

48:                                               ; preds = %44
  %49 = fsub double %46, %45
  %50 = fmul double %49, %2
  tail call void @MultiplicateWithScalar(ptr noundef nonnull @FrictionLinSqrt.DifferenceVector, ptr noundef nonnull @FrictionLinSqrt.DifferenceVector, double noundef %50, i32 noundef %8) #2
  tail call void @VectSum(ptr noundef %0, ptr noundef %0, ptr noundef nonnull @FrictionLinSqrt.DifferenceVector) #2
  br label %51

51:                                               ; preds = %44, %48, %23
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %52 = load i32, ptr %18, align 4, !tbaa !13
  %53 = sext i32 %52 to i64
  %54 = icmp slt i64 %indvars.iv.next, %53
  br i1 %54, label %23, label %._crit_edge, !llvm.loop !16

._crit_edge:                                      ; preds = %51, %9
  ret void
}

declare void @NullVect(ptr 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 @UnitVect(ptr noundef, ptr noundef) local_unnamed_addr #1

declare double @VelDecayLinSqrt(double noundef, double noundef, double noundef, double noundef, double noundef) local_unnamed_addr #1

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

declare void @VectSum(ptr noundef, ptr noundef, 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, !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, !7, i64 8}
!13 = !{!6, !10, i64 36}
!14 = !{!15, !15, i64 0}
!15 = !{!"double", !8, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}


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