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

@stderr = external global ptr, align 8
@.str.1 = external hidden unnamed_addr constant [42 x i8], align 1
@PlaceAgentsOnXYPlane.StepCount = external hidden global i32, align 4
@PlaceAgentsOnXYPlane.MaxStep = external hidden global i32, align 4
@PlaceAgentsOnXYPlane.IsArrangementCorrect = external hidden global i8, align 1
@PlaceAgentsOnXYPlane.AgentsCoordinates = external hidden global [3 x double], align 16
@PlaceAgentsOnXYPlane.TempCoord = 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 @InsertAgentsVelocity(ptr noundef, ptr noundef, i32 noundef) #1

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

; Function Attrs: nounwind uwtable
declare dso_local void @InsertAgentsCoordinates(ptr noundef, ptr noundef, i32 noundef) #1

; Function Attrs: noreturn nounwind
declare void @exit(i32 noundef) #2

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

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

declare void @FillVect(ptr noundef, double noundef, double noundef, double noundef) #3

declare double @VectAbsXY(ptr noundef) #3

declare double @randomizeDouble(double noundef, double noundef) #3

; Function Attrs: nounwind
declare i32 @fprintf(ptr noundef, ptr noundef, ...) #4

; Function Attrs: nounwind uwtable
define dso_local void @PlaceAgentsOnXYPlane(ptr noundef %0, double noundef %1, double noundef %2, double noundef %3, double noundef %4, double noundef %5, i32 noundef %6, i32 noundef %7, double noundef %8) #1 {
  %10 = alloca ptr, align 8
  %11 = alloca double, align 8
  %12 = alloca double, align 8
  %13 = alloca double, align 8
  %14 = alloca double, align 8
  %15 = alloca double, align 8
  %16 = alloca i32, align 4
  %17 = alloca i32, align 4
  %18 = alloca double, align 8
  %19 = alloca i32, align 4
  %20 = alloca i32, align 4
  store ptr %0, ptr %10, align 8, !tbaa !5
  store double %1, ptr %11, align 8, !tbaa !9
  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 i32 %6, ptr %16, align 4, !tbaa !11
  store i32 %7, ptr %17, align 4, !tbaa !11
  store double %8, ptr %18, align 8, !tbaa !9
  store i32 0, ptr @PlaceAgentsOnXYPlane.StepCount, align 4, !tbaa !11
  %21 = load ptr, ptr %10, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.phase_t, ptr %21, i32 0, i32 5
  %23 = load i32, ptr %22, align 4, !tbaa !13
  %24 = mul nsw i32 100, %23
  store i32 %24, ptr @PlaceAgentsOnXYPlane.MaxStep, align 4, !tbaa !11
  store i8 0, ptr @PlaceAgentsOnXYPlane.IsArrangementCorrect, align 1, !tbaa !15
  call void @NullVect(ptr noundef @PlaceAgentsOnXYPlane.AgentsCoordinates, i32 noundef 3)
  call void @llvm.lifetime.start.p0(i64 4, ptr %19) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %20) #5
  %25 = load i32, ptr %16, align 4, !tbaa !11
  store i32 %25, ptr %19, align 4, !tbaa !11
  br label %26

26:                                               ; preds = %93, %9
  %27 = load i32, ptr %19, align 4, !tbaa !11
  %28 = load i32, ptr %17, align 4, !tbaa !11
  %29 = icmp slt i32 %27, %28
  br i1 %29, label %30, label %96

30:                                               ; preds = %26
  br label %31

31:                                               ; preds = %87, %30
  %32 = load i8, ptr @PlaceAgentsOnXYPlane.IsArrangementCorrect, align 1, !tbaa !15, !range !17, !noundef !18
  %33 = trunc i8 %32 to i1
  %34 = zext i1 %33 to i32
  %35 = icmp eq i32 0, %34
  br i1 %35, label %36, label %88

36:                                               ; preds = %31
  store i8 1, ptr @PlaceAgentsOnXYPlane.IsArrangementCorrect, align 1, !tbaa !15
  %37 = load double, ptr %13, align 8, !tbaa !9
  %38 = load double, ptr %11, align 8, !tbaa !9
  %39 = fneg double %38
  %40 = fdiv double %39, 2.000000e+00
  %41 = load double, ptr %11, align 8, !tbaa !9
  %42 = fdiv double %41, 2.000000e+00
  %43 = call double @randomizeDouble(double noundef %40, double noundef %42)
  %44 = fadd double %37, %43
  %45 = load double, ptr %14, align 8, !tbaa !9
  %46 = load double, ptr %12, align 8, !tbaa !9
  %47 = fneg double %46
  %48 = fdiv double %47, 2.000000e+00
  %49 = load double, ptr %12, align 8, !tbaa !9
  %50 = fdiv double %49, 2.000000e+00
  %51 = call double @randomizeDouble(double noundef %48, double noundef %50)
  %52 = fadd double %45, %51
  %53 = load double, ptr %15, align 8, !tbaa !9
  call void @FillVect(ptr noundef @PlaceAgentsOnXYPlane.AgentsCoordinates, double noundef %44, double noundef %52, double noundef %53)
  store i32 0, ptr %20, align 4, !tbaa !11
  br label %54

54:                                               ; preds = %75, %36
  %55 = load i32, ptr %20, align 4, !tbaa !11
  %56 = load ptr, ptr %10, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.phase_t, ptr %56, i32 0, i32 5
  %58 = load i32, ptr %57, align 4, !tbaa !13
  %59 = icmp slt i32 %55, %58
  br i1 %59, label %60, label %78

60:                                               ; preds = %54
  %61 = load i32, ptr %19, align 4, !tbaa !11
  %62 = load i32, ptr %20, align 4, !tbaa !11
  %63 = icmp eq i32 %61, %62
  br i1 %63, label %64, label %67

64:                                               ; preds = %60
  %65 = load i32, ptr %17, align 4, !tbaa !11
  %66 = sub nsw i32 %65, 1
  store i32 %66, ptr %20, align 4, !tbaa !11
  br label %75

67:                                               ; preds = %60
  %68 = load ptr, ptr %10, align 8, !tbaa !5
  %69 = load i32, ptr %20, align 4, !tbaa !11
  call void @GetAgentsCoordinates(ptr noundef @PlaceAgentsOnXYPlane.TempCoord, ptr noundef %68, i32 noundef %69)
  call void @VectDifference(ptr noundef @PlaceAgentsOnXYPlane.TempCoord, ptr noundef @PlaceAgentsOnXYPlane.TempCoord, ptr noundef @PlaceAgentsOnXYPlane.AgentsCoordinates)
  %70 = call double @VectAbsXY(ptr noundef @PlaceAgentsOnXYPlane.TempCoord)
  %71 = load double, ptr %18, align 8, !tbaa !9
  %72 = fcmp ole double %70, %71
  br i1 %72, label %73, label %74

73:                                               ; preds = %67
  store i8 0, ptr @PlaceAgentsOnXYPlane.IsArrangementCorrect, align 1, !tbaa !15
  br label %74

74:                                               ; preds = %73, %67
  br label %75

75:                                               ; preds = %74, %64
  %76 = load i32, ptr %20, align 4, !tbaa !11
  %77 = add nsw i32 %76, 1
  store i32 %77, ptr %20, align 4, !tbaa !11
  br label %54, !llvm.loop !19

78:                                               ; preds = %54
  %79 = load i32, ptr @PlaceAgentsOnXYPlane.StepCount, align 4, !tbaa !11
  %80 = add nsw i32 %79, 1
  store i32 %80, ptr @PlaceAgentsOnXYPlane.StepCount, align 4, !tbaa !11
  %81 = load i32, ptr @PlaceAgentsOnXYPlane.StepCount, align 4, !tbaa !11
  %82 = load i32, ptr @PlaceAgentsOnXYPlane.MaxStep, align 4, !tbaa !11
  %83 = icmp sgt i32 %81, %82
  br i1 %83, label %84, label %87

84:                                               ; preds = %78
  %85 = load ptr, ptr @stderr, align 8, !tbaa !5
  %86 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %85, ptr noundef @.str.1) #5
  call void @exit(i32 noundef -1) #6
  unreachable

87:                                               ; preds = %78
  br label %31, !llvm.loop !21

88:                                               ; preds = %31
  %89 = load ptr, ptr %10, align 8, !tbaa !5
  %90 = load i32, ptr %19, align 4, !tbaa !11
  call void @InsertAgentsCoordinates(ptr noundef %89, ptr noundef @PlaceAgentsOnXYPlane.AgentsCoordinates, i32 noundef %90)
  call void @NullVect(ptr noundef @PlaceAgentsOnXYPlane.AgentsCoordinates, i32 noundef 3)
  %91 = load ptr, ptr %10, align 8, !tbaa !5
  %92 = load i32, ptr %19, align 4, !tbaa !11
  call void @InsertAgentsVelocity(ptr noundef %91, ptr noundef @PlaceAgentsOnXYPlane.AgentsCoordinates, i32 noundef %92)
  store i8 0, ptr @PlaceAgentsOnXYPlane.IsArrangementCorrect, align 1, !tbaa !15
  br label %93

93:                                               ; preds = %88
  %94 = load i32, ptr %19, align 4, !tbaa !11
  %95 = add nsw i32 %94, 1
  store i32 %95, ptr %19, align 4, !tbaa !11
  br label %26, !llvm.loop !22

96:                                               ; preds = %26
  call void @llvm.lifetime.end.p0(i64 4, ptr %20) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %19) #5
  ret void
}

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 = { noreturn nounwind "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 = { "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 #4 = { nounwind "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 #5 = { nounwind }
attributes #6 = { noreturn 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, !12, i64 36}
!14 = !{!"", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !12, i64 32, !12, i64 36}
!15 = !{!16, !16, i64 0}
!16 = !{!"_Bool", !7, i64 0}
!17 = !{i8 0, i8 2}
!18 = !{}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}
!21 = distinct !{!21, !20}
!22 = distinct !{!22, !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"

@stderr = external local_unnamed_addr global ptr, align 8
@.str.1 = external hidden unnamed_addr constant [42 x i8], align 1
@PlaceAgentsOnXYPlane.StepCount = external hidden local_unnamed_addr global i32, align 4
@PlaceAgentsOnXYPlane.MaxStep = external hidden local_unnamed_addr global i32, align 4
@PlaceAgentsOnXYPlane.IsArrangementCorrect = external hidden local_unnamed_addr global i8, align 1
@PlaceAgentsOnXYPlane.AgentsCoordinates = external hidden global [3 x double], align 16
@PlaceAgentsOnXYPlane.TempCoord = external hidden global [3 x double], align 16

; Function Attrs: nounwind uwtable
declare dso_local void @InsertAgentsVelocity(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

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

; Function Attrs: noreturn nounwind
declare void @exit(i32 noundef) local_unnamed_addr #1

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

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

declare void @FillVect(ptr noundef, double noundef, double noundef, double noundef) local_unnamed_addr #2

declare double @VectAbsXY(ptr noundef) local_unnamed_addr #2

declare double @randomizeDouble(double noundef, double noundef) local_unnamed_addr #2

; Function Attrs: nofree nounwind
declare noundef i32 @fprintf(ptr nocapture noundef, ptr nocapture noundef readonly, ...) local_unnamed_addr #3

; Function Attrs: nounwind uwtable
define dso_local void @PlaceAgentsOnXYPlane(ptr noundef %0, double noundef %1, double noundef %2, double noundef %3, double noundef %4, double noundef %5, i32 noundef %6, i32 noundef %7, double noundef %8) local_unnamed_addr #0 {
  store i32 0, ptr @PlaceAgentsOnXYPlane.StepCount, align 4, !tbaa !5
  %10 = getelementptr inbounds i8, ptr %0, i64 36
  %11 = load i32, ptr %10, align 4, !tbaa !9
  %12 = mul nsw i32 %11, 100
  store i32 %12, ptr @PlaceAgentsOnXYPlane.MaxStep, align 4, !tbaa !5
  store i8 0, ptr @PlaceAgentsOnXYPlane.IsArrangementCorrect, align 1, !tbaa !12
  tail call void @NullVect(ptr noundef nonnull @PlaceAgentsOnXYPlane.AgentsCoordinates, i32 noundef 3) #4
  %13 = icmp slt i32 %6, %7
  br i1 %13, label %.preheader.lr.ph, label %._crit_edge27

.preheader.lr.ph:                                 ; preds = %9
  %14 = fmul double %1, -5.000000e-01
  %15 = fmul double %1, 5.000000e-01
  %16 = fmul double %2, -5.000000e-01
  %17 = fmul double %2, 5.000000e-01
  %18 = add nsw i32 %7, -1
  br label %.preheader

.preheader:                                       ; preds = %.preheader.lr.ph, %44
  %.02426 = phi i32 [ %6, %.preheader.lr.ph ], [ %45, %44 ]
  br label %19

19:                                               ; preds = %.preheader, %._crit_edge
  %20 = load i8, ptr @PlaceAgentsOnXYPlane.IsArrangementCorrect, align 1, !tbaa !12, !range !14, !noundef !15
  %21 = icmp eq i8 %20, 0
  br i1 %21, label %22, label %44

22:                                               ; preds = %19
  store i8 1, ptr @PlaceAgentsOnXYPlane.IsArrangementCorrect, align 1, !tbaa !12
  %23 = tail call double @randomizeDouble(double noundef %14, double noundef %15) #4
  %24 = fadd double %23, %3
  %25 = tail call double @randomizeDouble(double noundef %16, double noundef %17) #4
  %26 = fadd double %25, %4
  tail call void @FillVect(ptr noundef nonnull @PlaceAgentsOnXYPlane.AgentsCoordinates, double noundef %24, double noundef %26, double noundef %5) #4
  %27 = load i32, ptr %10, align 4, !tbaa !9
  %28 = icmp sgt i32 %27, 0
  br i1 %28, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %22, %34
  %.025 = phi i32 [ %35, %34 ], [ 0, %22 ]
  %29 = icmp eq i32 %.02426, %.025
  br i1 %29, label %34, label %30

30:                                               ; preds = %.lr.ph
  tail call void @GetAgentsCoordinates(ptr noundef nonnull @PlaceAgentsOnXYPlane.TempCoord, ptr noundef nonnull %0, i32 noundef %.025)
  tail call void @VectDifference(ptr noundef nonnull @PlaceAgentsOnXYPlane.TempCoord, ptr noundef nonnull @PlaceAgentsOnXYPlane.TempCoord, ptr noundef nonnull @PlaceAgentsOnXYPlane.AgentsCoordinates) #4
  %31 = tail call double @VectAbsXY(ptr noundef nonnull @PlaceAgentsOnXYPlane.TempCoord) #4
  %32 = fcmp ugt double %31, %8
  br i1 %32, label %34, label %33

33:                                               ; preds = %30
  store i8 0, ptr @PlaceAgentsOnXYPlane.IsArrangementCorrect, align 1, !tbaa !12
  br label %34

34:                                               ; preds = %.lr.ph, %30, %33
  %.1 = phi i32 [ %.025, %33 ], [ %.025, %30 ], [ %18, %.lr.ph ]
  %35 = add nsw i32 %.1, 1
  %36 = load i32, ptr %10, align 4, !tbaa !9
  %37 = icmp slt i32 %35, %36
  br i1 %37, label %.lr.ph, label %._crit_edge, !llvm.loop !16

._crit_edge:                                      ; preds = %34, %22
  %38 = load i32, ptr @PlaceAgentsOnXYPlane.StepCount, align 4, !tbaa !5
  %39 = add nsw i32 %38, 1
  store i32 %39, ptr @PlaceAgentsOnXYPlane.StepCount, align 4, !tbaa !5
  %40 = load i32, ptr @PlaceAgentsOnXYPlane.MaxStep, align 4, !tbaa !5
  %.not = icmp slt i32 %38, %40
  br i1 %.not, label %19, label %41, !llvm.loop !18

41:                                               ; preds = %._crit_edge
  %42 = load ptr, ptr @stderr, align 8, !tbaa !19
  %43 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %42, ptr noundef nonnull @.str.1) #5
  tail call void @exit(i32 noundef -1) #6
  unreachable

44:                                               ; preds = %19
  tail call void @InsertAgentsCoordinates(ptr noundef %0, ptr noundef nonnull @PlaceAgentsOnXYPlane.AgentsCoordinates, i32 noundef %.02426)
  tail call void @NullVect(ptr noundef nonnull @PlaceAgentsOnXYPlane.AgentsCoordinates, i32 noundef 3) #4
  tail call void @InsertAgentsVelocity(ptr noundef %0, ptr noundef nonnull @PlaceAgentsOnXYPlane.AgentsCoordinates, i32 noundef %.02426)
  store i8 0, ptr @PlaceAgentsOnXYPlane.IsArrangementCorrect, align 1, !tbaa !12
  %45 = add i32 %.02426, 1
  %exitcond.not = icmp eq i32 %45, %7
  br i1 %exitcond.not, label %._crit_edge27, label %.preheader, !llvm.loop !20

._crit_edge27:                                    ; preds = %44, %9
  ret void
}

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 = { noreturn nounwind "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 = { nofree nounwind "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 #4 = { nounwind }
attributes #5 = { cold nounwind }
attributes #6 = { noreturn 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, !6, i64 36}
!10 = !{!"", !11, i64 0, !11, i64 8, !11, i64 16, !11, i64 24, !6, i64 32, !6, i64 36}
!11 = !{!"any pointer", !7, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"_Bool", !7, i64 0}
!14 = !{i8 0, i8 2}
!15 = !{}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}
!18 = distinct !{!18, !17}
!19 = !{!11, !11, i64 0}
!20 = distinct !{!20, !17}


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