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

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

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

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

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

declare double @VectAbs(ptr noundef) #0

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

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

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

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

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

31:                                               ; preds = %72, %8
  %32 = load i32, ptr %17, align 4, !tbaa !11
  %33 = load ptr, ptr %10, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.phase_t, ptr %33, i32 0, i32 5
  %35 = load i32, ptr %34, align 4, !tbaa !17
  %36 = icmp slt i32 %32, %35
  br i1 %36, label %37, label %75

37:                                               ; preds = %31
  %38 = load i32, ptr %17, align 4, !tbaa !11
  %39 = load i32, ptr %14, align 4, !tbaa !11
  %40 = icmp eq i32 %38, %39
  br i1 %40, label %41, label %42

41:                                               ; preds = %37
  br label %72

42:                                               ; preds = %37
  %43 = load ptr, ptr %10, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.phase_t, ptr %43, i32 0, i32 0
  %45 = load ptr, ptr %44, align 8, !tbaa !15
  %46 = load i32, ptr %17, align 4, !tbaa !11
  %47 = sext i32 %46 to i64
  %48 = getelementptr inbounds ptr, ptr %45, i64 %47
  %49 = load ptr, ptr %48, align 8, !tbaa !5
  store ptr %49, ptr %20, align 8, !tbaa !5
  %50 = load ptr, ptr %19, align 8, !tbaa !5
  %51 = load ptr, ptr %20, align 8, !tbaa !5
  call void @VectDifference(ptr noundef @RepulsionLin.DifferenceVector, ptr noundef %50, ptr noundef %51)
  %52 = load i32, ptr %15, align 4, !tbaa !11
  %53 = icmp eq i32 2, %52
  br i1 %53, label %54, label %55

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

55:                                               ; preds = %54, %42
  %56 = call double @VectAbs(ptr noundef @RepulsionLin.DifferenceVector)
  store double %56, ptr @RepulsionLin.DistanceFromNeighbour, align 8, !tbaa !9
  %57 = load double, ptr @RepulsionLin.DistanceFromNeighbour, align 8, !tbaa !9
  %58 = load double, ptr %13, align 8, !tbaa !9
  %59 = fcmp oge double %57, %58
  br i1 %59, label %60, label %61

60:                                               ; preds = %55
  br label %72

61:                                               ; preds = %55
  %62 = load i32, ptr %18, align 4, !tbaa !11
  %63 = add nsw i32 %62, 1
  store i32 %63, ptr %18, align 4, !tbaa !11
  call void @UnitVect(ptr noundef @RepulsionLin.DifferenceVector, ptr noundef @RepulsionLin.DifferenceVector)
  %64 = load double, ptr @RepulsionLin.DistanceFromNeighbour, align 8, !tbaa !9
  %65 = load double, ptr %12, align 8, !tbaa !9
  %66 = load double, ptr %11, align 8, !tbaa !9
  %67 = load double, ptr %13, align 8, !tbaa !9
  %68 = call double @SigmoidLin(double noundef %64, double noundef %65, double noundef %66, double noundef %67)
  %69 = load i32, ptr %15, align 4, !tbaa !11
  call void @MultiplicateWithScalar(ptr noundef @RepulsionLin.DifferenceVector, ptr noundef @RepulsionLin.DifferenceVector, double noundef %68, i32 noundef %69)
  %70 = load ptr, ptr %9, align 8, !tbaa !5
  %71 = load ptr, ptr %9, align 8, !tbaa !5
  call void @VectSum(ptr noundef %70, ptr noundef %71, ptr noundef @RepulsionLin.DifferenceVector)
  br label %72

72:                                               ; preds = %61, %60, %41
  %73 = load i32, ptr %17, align 4, !tbaa !11
  %74 = add nsw i32 %73, 1
  store i32 %74, ptr %17, align 4, !tbaa !11
  br label %31, !llvm.loop !18

75:                                               ; preds = %31
  %76 = load i8, ptr %16, align 1, !tbaa !13, !range !20, !noundef !21
  %77 = trunc i8 %76 to i1
  br i1 %77, label %78, label %93

78:                                               ; preds = %75
  %79 = load i32, ptr %18, align 4, !tbaa !11
  %80 = icmp sgt i32 %79, 1
  br i1 %80, label %81, label %93

81:                                               ; preds = %78
  call void @llvm.lifetime.start.p0(i64 8, ptr %21) #3
  %82 = load ptr, ptr %9, align 8, !tbaa !5
  %83 = call double @VectAbs(ptr noundef %82)
  %84 = load i32, ptr %18, align 4, !tbaa !11
  %85 = sitofp i32 %84 to double
  %86 = fdiv double %83, %85
  store double %86, ptr %21, align 8, !tbaa !9
  %87 = load ptr, ptr %9, align 8, !tbaa !5
  %88 = load ptr, ptr %9, align 8, !tbaa !5
  call void @UnitVect(ptr noundef %87, ptr noundef %88)
  %89 = load ptr, ptr %9, align 8, !tbaa !5
  %90 = load ptr, ptr %9, align 8, !tbaa !5
  %91 = load double, ptr %21, align 8, !tbaa !9
  %92 = load i32, ptr %15, align 4, !tbaa !11
  call void @MultiplicateWithScalar(ptr noundef %89, ptr noundef %90, double noundef %91, i32 noundef %92)
  call void @llvm.lifetime.end.p0(i64 8, ptr %21) #3
  br label %93

93:                                               ; preds = %81, %78, %75
  call void @llvm.lifetime.end.p0(i64 8, ptr %20) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %19) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %18) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %17) #3
  ret void
}

declare double @SigmoidLin(double noundef, double noundef, double noundef, double noundef) #0

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


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

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

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

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

declare double @VectAbs(ptr noundef) local_unnamed_addr #0

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

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

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

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

.lr.ph:                                           ; preds = %8
  %16 = icmp eq i32 %6, 2
  %17 = zext i32 %5 to i64
  br i1 %16, label %.lr.ph.split.us, label %.lr.ph.split

.lr.ph.split.us:                                  ; preds = %.lr.ph, %29
  %indvars.iv37 = phi i64 [ %indvars.iv.next38, %29 ], [ 0, %.lr.ph ]
  %.03133.us = phi i32 [ %.1.us, %29 ], [ 0, %.lr.ph ]
  %18 = icmp eq i64 %indvars.iv37, %17
  br i1 %18, label %29, label %19

19:                                               ; preds = %.lr.ph.split.us
  %20 = load ptr, ptr %1, align 8, !tbaa !5
  %21 = getelementptr inbounds ptr, ptr %20, i64 %indvars.iv37
  %22 = load ptr, ptr %21, align 8, !tbaa !11
  tail call void @VectDifference(ptr noundef nonnull @RepulsionLin.DifferenceVector, ptr noundef %12, ptr noundef %22) #2
  store double 0.000000e+00, ptr getelementptr inbounds (i8, ptr @RepulsionLin.DifferenceVector, i64 16), align 16, !tbaa !13
  %23 = tail call double @VectAbs(ptr noundef nonnull @RepulsionLin.DifferenceVector) #2
  store double %23, ptr @RepulsionLin.DistanceFromNeighbour, align 8, !tbaa !13
  %24 = fcmp ult double %23, %4
  br i1 %24, label %25, label %29

25:                                               ; preds = %19
  %26 = add nsw i32 %.03133.us, 1
  tail call void @UnitVect(ptr noundef nonnull @RepulsionLin.DifferenceVector, ptr noundef nonnull @RepulsionLin.DifferenceVector) #2
  %27 = load double, ptr @RepulsionLin.DistanceFromNeighbour, align 8, !tbaa !13
  %28 = tail call double @SigmoidLin(double noundef %27, double noundef %3, double noundef %2, double noundef %4) #2
  tail call void @MultiplicateWithScalar(ptr noundef nonnull @RepulsionLin.DifferenceVector, ptr noundef nonnull @RepulsionLin.DifferenceVector, double noundef %28, i32 noundef 2) #2
  tail call void @VectSum(ptr noundef %0, ptr noundef %0, ptr noundef nonnull @RepulsionLin.DifferenceVector) #2
  br label %29

29:                                               ; preds = %25, %19, %.lr.ph.split.us
  %.1.us = phi i32 [ %.03133.us, %.lr.ph.split.us ], [ %.03133.us, %19 ], [ %26, %25 ]
  %indvars.iv.next38 = add nuw nsw i64 %indvars.iv37, 1
  %30 = load i32, ptr %13, align 4, !tbaa !12
  %31 = sext i32 %30 to i64
  %32 = icmp slt i64 %indvars.iv.next38, %31
  br i1 %32, label %.lr.ph.split.us, label %._crit_edge, !llvm.loop !15

.lr.ph.split:                                     ; preds = %.lr.ph, %44
  %indvars.iv = phi i64 [ %indvars.iv.next, %44 ], [ 0, %.lr.ph ]
  %.03133 = phi i32 [ %.1, %44 ], [ 0, %.lr.ph ]
  %33 = icmp eq i64 %indvars.iv, %17
  br i1 %33, label %44, label %34

34:                                               ; preds = %.lr.ph.split
  %35 = load ptr, ptr %1, align 8, !tbaa !5
  %36 = getelementptr inbounds ptr, ptr %35, i64 %indvars.iv
  %37 = load ptr, ptr %36, align 8, !tbaa !11
  tail call void @VectDifference(ptr noundef nonnull @RepulsionLin.DifferenceVector, ptr noundef %12, ptr noundef %37) #2
  %38 = tail call double @VectAbs(ptr noundef nonnull @RepulsionLin.DifferenceVector) #2
  store double %38, ptr @RepulsionLin.DistanceFromNeighbour, align 8, !tbaa !13
  %39 = fcmp ult double %38, %4
  br i1 %39, label %40, label %44

40:                                               ; preds = %34
  %41 = add nsw i32 %.03133, 1
  tail call void @UnitVect(ptr noundef nonnull @RepulsionLin.DifferenceVector, ptr noundef nonnull @RepulsionLin.DifferenceVector) #2
  %42 = load double, ptr @RepulsionLin.DistanceFromNeighbour, align 8, !tbaa !13
  %43 = tail call double @SigmoidLin(double noundef %42, double noundef %3, double noundef %2, double noundef %4) #2
  tail call void @MultiplicateWithScalar(ptr noundef nonnull @RepulsionLin.DifferenceVector, ptr noundef nonnull @RepulsionLin.DifferenceVector, double noundef %43, i32 noundef %6) #2
  tail call void @VectSum(ptr noundef %0, ptr noundef %0, ptr noundef nonnull @RepulsionLin.DifferenceVector) #2
  br label %44

44:                                               ; preds = %34, %.lr.ph.split, %40
  %.1 = phi i32 [ %.03133, %.lr.ph.split ], [ %.03133, %34 ], [ %41, %40 ]
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %45 = load i32, ptr %13, align 4, !tbaa !12
  %46 = sext i32 %45 to i64
  %47 = icmp slt i64 %indvars.iv.next, %46
  br i1 %47, label %.lr.ph.split, label %._crit_edge, !llvm.loop !15

._crit_edge:                                      ; preds = %44, %29
  %.031.lcssa = phi i32 [ %.1.us, %29 ], [ %.1, %44 ]
  %48 = icmp sgt i32 %.031.lcssa, 1
  %or.cond = select i1 %7, i1 %48, i1 false
  br i1 %or.cond, label %49, label %._crit_edge.thread

49:                                               ; preds = %._crit_edge
  %50 = tail call double @VectAbs(ptr noundef %0) #2
  %51 = uitofp nneg i32 %.031.lcssa to double
  %52 = fdiv double %50, %51
  tail call void @UnitVect(ptr noundef %0, ptr noundef %0) #2
  tail call void @MultiplicateWithScalar(ptr noundef %0, ptr noundef %0, double noundef %52, i32 noundef %6) #2
  br label %._crit_edge.thread

._crit_edge.thread:                               ; preds = %8, %49, %._crit_edge
  ret void
}

declare double @SigmoidLin(double noundef, double noundef, double noundef, double noundef) local_unnamed_addr #0

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 = !{!14, !14, i64 0}
!14 = !{!"double", !8, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}


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