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

@HowManyCollisions.Collisions = external hidden global i32, align 4
@HowManyCollisions.ithAgentsCoordinates = external hidden global [3 x double], align 16
@HowManyCollisions.jthAgentsCoordinates = external hidden global [3 x double], align 16
@HowManyCollisions.RelativeCoordinates = external hidden global [3 x double], align 16
@HowManyCollisions.PreviousSituation = external hidden global i8, align 1

; 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 @GetAgentsCoordinates(ptr noundef, ptr noundef, i32 noundef) #1

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

declare double @VectAbs(ptr noundef) #2

; Function Attrs: nounwind uwtable
define dso_local i32 @HowManyCollisions(ptr noundef %0, ptr noundef %1, i1 noundef zeroext %2, double noundef %3) #1 {
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i8, align 1
  %8 = alloca double, align 8
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  %11 = zext i1 %2 to i8
  store i8 %11, ptr %7, align 1, !tbaa !9
  store double %3, ptr %8, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  store i32 0, ptr @HowManyCollisions.Collisions, align 4, !tbaa !13
  store i8 0, ptr @HowManyCollisions.PreviousSituation, align 1, !tbaa !9
  %12 = load i8, ptr %7, align 1, !tbaa !9, !range !15, !noundef !16
  %13 = trunc i8 %12 to i1
  %14 = zext i1 %13 to i32
  %15 = icmp eq i32 %14, 1
  br i1 %15, label %16, label %88

16:                                               ; preds = %4
  store i32 0, ptr %10, align 4, !tbaa !13
  br label %17

17:                                               ; preds = %84, %16
  %18 = load i32, ptr %10, align 4, !tbaa !13
  %19 = load ptr, ptr %5, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.phase_t, ptr %19, i32 0, i32 5
  %21 = load i32, ptr %20, align 4, !tbaa !17
  %22 = icmp slt i32 %18, %21
  br i1 %22, label %23, label %87

23:                                               ; preds = %17
  %24 = load ptr, ptr %6, align 8, !tbaa !5
  %25 = load i32, ptr %10, align 4, !tbaa !13
  %26 = sext i32 %25 to i64
  %27 = getelementptr inbounds i8, ptr %24, i64 %26
  %28 = load i8, ptr %27, align 1, !tbaa !9, !range !15, !noundef !16
  %29 = trunc i8 %28 to i1
  %30 = zext i1 %29 to i8
  store i8 %30, ptr @HowManyCollisions.PreviousSituation, align 1, !tbaa !9
  %31 = load ptr, ptr %6, align 8, !tbaa !5
  %32 = load i32, ptr %10, align 4, !tbaa !13
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds i8, ptr %31, i64 %33
  store i8 0, ptr %34, align 1, !tbaa !9
  store i32 0, ptr %9, align 4, !tbaa !13
  br label %35

35:                                               ; preds = %62, %23
  %36 = load i32, ptr %9, align 4, !tbaa !13
  %37 = load i32, ptr %10, align 4, !tbaa !13
  %38 = icmp slt i32 %36, %37
  br i1 %38, label %39, label %65

39:                                               ; preds = %35
  %40 = load i32, ptr %9, align 4, !tbaa !13
  %41 = load i32, ptr %10, align 4, !tbaa !13
  %42 = icmp ne i32 %40, %41
  br i1 %42, label %43, label %61

43:                                               ; preds = %39
  %44 = load ptr, ptr %5, align 8, !tbaa !5
  %45 = load i32, ptr %9, align 4, !tbaa !13
  call void @GetAgentsCoordinates(ptr noundef @HowManyCollisions.ithAgentsCoordinates, ptr noundef %44, i32 noundef %45)
  %46 = load ptr, ptr %5, align 8, !tbaa !5
  %47 = load i32, ptr %10, align 4, !tbaa !13
  call void @GetAgentsCoordinates(ptr noundef @HowManyCollisions.jthAgentsCoordinates, ptr noundef %46, i32 noundef %47)
  call void @VectDifference(ptr noundef @HowManyCollisions.RelativeCoordinates, ptr noundef @HowManyCollisions.ithAgentsCoordinates, ptr noundef @HowManyCollisions.jthAgentsCoordinates)
  %48 = call double @VectAbs(ptr noundef @HowManyCollisions.RelativeCoordinates)
  %49 = load double, ptr %8, align 8, !tbaa !11
  %50 = fcmp ole double %48, %49
  br i1 %50, label %51, label %60

51:                                               ; preds = %43
  %52 = load ptr, ptr %6, align 8, !tbaa !5
  %53 = load i32, ptr %10, align 4, !tbaa !13
  %54 = sext i32 %53 to i64
  %55 = getelementptr inbounds i8, ptr %52, i64 %54
  store i8 1, ptr %55, align 1, !tbaa !9
  %56 = load ptr, ptr %6, align 8, !tbaa !5
  %57 = load i32, ptr %9, align 4, !tbaa !13
  %58 = sext i32 %57 to i64
  %59 = getelementptr inbounds i8, ptr %56, i64 %58
  store i8 1, ptr %59, align 1, !tbaa !9
  br label %60

60:                                               ; preds = %51, %43
  br label %61

61:                                               ; preds = %60, %39
  br label %62

62:                                               ; preds = %61
  %63 = load i32, ptr %9, align 4, !tbaa !13
  %64 = add nsw i32 %63, 1
  store i32 %64, ptr %9, align 4, !tbaa !13
  br label %35, !llvm.loop !19

65:                                               ; preds = %35
  %66 = load i8, ptr @HowManyCollisions.PreviousSituation, align 1, !tbaa !9, !range !15, !noundef !16
  %67 = trunc i8 %66 to i1
  %68 = zext i1 %67 to i32
  %69 = icmp eq i32 %68, 0
  br i1 %69, label %70, label %79

70:                                               ; preds = %65
  %71 = load ptr, ptr %6, align 8, !tbaa !5
  %72 = load i32, ptr %10, align 4, !tbaa !13
  %73 = sext i32 %72 to i64
  %74 = getelementptr inbounds i8, ptr %71, i64 %73
  %75 = load i8, ptr %74, align 1, !tbaa !9, !range !15, !noundef !16
  %76 = trunc i8 %75 to i1
  %77 = zext i1 %76 to i32
  %78 = icmp eq i32 %77, 1
  br label %79

79:                                               ; preds = %70, %65
  %80 = phi i1 [ false, %65 ], [ %78, %70 ]
  %81 = zext i1 %80 to i32
  %82 = load i32, ptr @HowManyCollisions.Collisions, align 4, !tbaa !13
  %83 = add nsw i32 %82, %81
  store i32 %83, ptr @HowManyCollisions.Collisions, align 4, !tbaa !13
  br label %84

84:                                               ; preds = %79
  %85 = load i32, ptr %10, align 4, !tbaa !13
  %86 = add nsw i32 %85, 1
  store i32 %86, ptr %10, align 4, !tbaa !13
  br label %17, !llvm.loop !21

87:                                               ; preds = %17
  br label %88

88:                                               ; preds = %87, %4
  %89 = load i32, ptr @HowManyCollisions.Collisions, align 4, !tbaa !13
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  ret i32 %89
}

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 = !{!"_Bool", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"double", !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"int", !7, i64 0}
!15 = !{i8 0, i8 2}
!16 = !{}
!17 = !{!18, !14, i64 36}
!18 = !{!"", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !14, i64 32, !14, i64 36}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}
!21 = distinct !{!21, !20}


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

@HowManyCollisions.Collisions = external hidden local_unnamed_addr global i32, align 4
@HowManyCollisions.ithAgentsCoordinates = external hidden global [3 x double], align 16
@HowManyCollisions.jthAgentsCoordinates = external hidden global [3 x double], align 16
@HowManyCollisions.RelativeCoordinates = external hidden global [3 x double], align 16
@HowManyCollisions.PreviousSituation = external hidden local_unnamed_addr global i8, align 1

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

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

declare double @VectAbs(ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local i32 @HowManyCollisions(ptr noundef %0, ptr nocapture noundef %1, i1 noundef zeroext %2, double noundef %3) local_unnamed_addr #0 {
  store i32 0, ptr @HowManyCollisions.Collisions, align 4, !tbaa !5
  store i8 0, ptr @HowManyCollisions.PreviousSituation, align 1, !tbaa !9
  br i1 %2, label %.preheader, label %.loopexit

.preheader:                                       ; preds = %4
  %5 = getelementptr inbounds i8, ptr %0, i64 36
  %6 = load i32, ptr %5, align 4, !tbaa !11
  %7 = icmp sgt i32 %6, 0
  br i1 %7, label %.lr.ph26, label %.loopexit

.lr.ph26:                                         ; preds = %.preheader, %22
  %indvars.iv28 = phi i64 [ %indvars.iv.next29, %22 ], [ 0, %.preheader ]
  %8 = getelementptr inbounds i8, ptr %1, i64 %indvars.iv28
  %9 = load i8, ptr %8, align 1, !tbaa !9, !range !14, !noundef !15
  store i8 %9, ptr @HowManyCollisions.PreviousSituation, align 1, !tbaa !9
  store i8 0, ptr %8, align 1, !tbaa !9
  %.not = icmp eq i64 %indvars.iv28, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %.lr.ph26
  %10 = trunc nuw nsw i64 %indvars.iv28 to i32
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %16
  %indvars.iv = phi i64 [ 0, %.lr.ph.preheader ], [ %indvars.iv.next, %16 ]
  %11 = trunc nuw nsw i64 %indvars.iv to i32
  tail call void @GetAgentsCoordinates(ptr noundef nonnull @HowManyCollisions.ithAgentsCoordinates, ptr noundef %0, i32 noundef %11)
  tail call void @GetAgentsCoordinates(ptr noundef nonnull @HowManyCollisions.jthAgentsCoordinates, ptr noundef %0, i32 noundef %10)
  tail call void @VectDifference(ptr noundef nonnull @HowManyCollisions.RelativeCoordinates, ptr noundef nonnull @HowManyCollisions.ithAgentsCoordinates, ptr noundef nonnull @HowManyCollisions.jthAgentsCoordinates) #2
  %12 = tail call double @VectAbs(ptr noundef nonnull @HowManyCollisions.RelativeCoordinates) #2
  %13 = fcmp ugt double %12, %3
  br i1 %13, label %16, label %14

14:                                               ; preds = %.lr.ph
  store i8 1, ptr %8, align 1, !tbaa !9
  %15 = getelementptr inbounds i8, ptr %1, i64 %indvars.iv
  store i8 1, ptr %15, align 1, !tbaa !9
  br label %16

16:                                               ; preds = %14, %.lr.ph
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %indvars.iv28
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph, !llvm.loop !16

._crit_edge:                                      ; preds = %16, %.lr.ph26
  %17 = load i8, ptr @HowManyCollisions.PreviousSituation, align 1, !tbaa !9, !range !14, !noundef !15
  %18 = icmp eq i8 %17, 0
  br i1 %18, label %19, label %22

19:                                               ; preds = %._crit_edge
  %20 = load i8, ptr %8, align 1, !tbaa !9, !range !14, !noundef !15
  %21 = zext nneg i8 %20 to i32
  br label %22

22:                                               ; preds = %19, %._crit_edge
  %23 = phi i32 [ 0, %._crit_edge ], [ %21, %19 ]
  %24 = load i32, ptr @HowManyCollisions.Collisions, align 4, !tbaa !5
  %25 = add nsw i32 %24, %23
  store i32 %25, ptr @HowManyCollisions.Collisions, align 4, !tbaa !5
  %indvars.iv.next29 = add nuw nsw i64 %indvars.iv28, 1
  %26 = load i32, ptr %5, align 4, !tbaa !11
  %27 = sext i32 %26 to i64
  %28 = icmp slt i64 %indvars.iv.next29, %27
  br i1 %28, label %.lr.ph26, label %.loopexit, !llvm.loop !18

.loopexit:                                        ; preds = %22, %.preheader, %4
  %29 = phi i32 [ 0, %.preheader ], [ 0, %4 ], [ %25, %22 ]
  ret i32 %29
}

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 = !{!"_Bool", !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 = !{i8 0, i8 2}
!15 = !{}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}
!18 = distinct !{!18, !17}


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