; LLVM IR from csviragh/robotsim :: src (stat)

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

@RatioOfDangerousSituations.x_j = external hidden global [3 x double], align 16
@RatioOfDangerousSituations.NumberOfCollisions = external hidden global i32, align 4

; 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

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

declare double @VectAbs(ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local double @RatioOfDangerousSituations(ptr noundef %0, double noundef %1) #2 {
  %3 = alloca ptr, align 8
  %4 = alloca double, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store double %1, ptr %4, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  store i32 0, ptr @RatioOfDangerousSituations.NumberOfCollisions, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  store i32 0, ptr %6, align 4, !tbaa !11
  br label %8

8:                                                ; preds = %41, %2
  %9 = load i32, ptr %6, align 4, !tbaa !11
  %10 = load ptr, ptr %3, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct.phase_t, ptr %10, i32 0, i32 5
  %12 = load i32, ptr %11, align 4, !tbaa !13
  %13 = icmp slt i32 %9, %12
  br i1 %13, label %14, label %44

14:                                               ; preds = %8
  %15 = load ptr, ptr %3, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.phase_t, ptr %15, i32 0, i32 0
  %17 = load ptr, ptr %16, align 8, !tbaa !15
  %18 = load i32, ptr %6, align 4, !tbaa !11
  %19 = sext i32 %18 to i64
  %20 = getelementptr inbounds ptr, ptr %17, i64 %19
  %21 = load ptr, ptr %20, align 8, !tbaa !5
  store ptr %21, ptr %5, align 8, !tbaa !5
  store i32 0, ptr %7, align 4, !tbaa !11
  br label %22

22:                                               ; preds = %37, %14
  %23 = load i32, ptr %7, align 4, !tbaa !11
  %24 = load i32, ptr %6, align 4, !tbaa !11
  %25 = icmp slt i32 %23, %24
  br i1 %25, label %26, label %40

26:                                               ; preds = %22
  %27 = load ptr, ptr %3, align 8, !tbaa !5
  %28 = load i32, ptr %7, align 4, !tbaa !11
  call void @GetAgentsCoordinates(ptr noundef @RatioOfDangerousSituations.x_j, ptr noundef %27, i32 noundef %28)
  %29 = load ptr, ptr %5, align 8, !tbaa !5
  call void @VectDifference(ptr noundef @RatioOfDangerousSituations.x_j, ptr noundef @RatioOfDangerousSituations.x_j, ptr noundef %29)
  %30 = call double @VectAbs(ptr noundef @RatioOfDangerousSituations.x_j)
  %31 = load double, ptr %4, align 8, !tbaa !9
  %32 = fcmp ole double %30, %31
  br i1 %32, label %33, label %36

33:                                               ; preds = %26
  %34 = load i32, ptr @RatioOfDangerousSituations.NumberOfCollisions, align 4, !tbaa !11
  %35 = add nsw i32 %34, 1
  store i32 %35, ptr @RatioOfDangerousSituations.NumberOfCollisions, align 4, !tbaa !11
  br label %36

36:                                               ; preds = %33, %26
  br label %37

37:                                               ; preds = %36
  %38 = load i32, ptr %7, align 4, !tbaa !11
  %39 = add nsw i32 %38, 1
  store i32 %39, ptr %7, align 4, !tbaa !11
  br label %22, !llvm.loop !16

40:                                               ; preds = %22
  br label %41

41:                                               ; preds = %40
  %42 = load i32, ptr %6, align 4, !tbaa !11
  %43 = add nsw i32 %42, 1
  store i32 %43, ptr %6, align 4, !tbaa !11
  br label %8, !llvm.loop !18

44:                                               ; preds = %8
  %45 = load i32, ptr @RatioOfDangerousSituations.NumberOfCollisions, align 4, !tbaa !11
  %46 = sitofp i32 %45 to double
  %47 = fmul double %46, 2.000000e+00
  %48 = load ptr, ptr %3, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.phase_t, ptr %48, i32 0, i32 5
  %50 = load i32, ptr %49, align 4, !tbaa !13
  %51 = load ptr, ptr %3, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.phase_t, ptr %51, i32 0, i32 5
  %53 = load i32, ptr %52, align 4, !tbaa !13
  %54 = sub nsw i32 %53, 1
  %55 = mul nsw i32 %50, %54
  %56 = sitofp i32 %55 to double
  %57 = fdiv double %47, %56
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  ret double %57
}

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

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


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

@RatioOfDangerousSituations.x_j = external hidden global [3 x double], align 16
@RatioOfDangerousSituations.NumberOfCollisions = external hidden local_unnamed_addr global i32, align 4

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

declare double @VectAbs(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local double @RatioOfDangerousSituations(ptr noundef %0, double noundef %1) local_unnamed_addr #1 {
  store i32 0, ptr @RatioOfDangerousSituations.NumberOfCollisions, align 4, !tbaa !5
  %3 = getelementptr inbounds i8, ptr %0, i64 36
  %4 = load i32, ptr %3, align 4, !tbaa !9
  %5 = icmp sgt i32 %4, 0
  br i1 %5, label %.lr.ph18, label %._crit_edge19

.lr.ph18:                                         ; preds = %2, %._crit_edge
  %6 = phi i32 [ %18, %._crit_edge ], [ %4, %2 ]
  %indvars.iv = phi i64 [ %indvars.iv.next, %._crit_edge ], [ 0, %2 ]
  %7 = load ptr, ptr %0, align 8, !tbaa !12
  %8 = getelementptr inbounds ptr, ptr %7, i64 %indvars.iv
  %9 = load ptr, ptr %8, align 8, !tbaa !13
  %.not = icmp eq i64 %indvars.iv, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph18, %15
  %.015 = phi i32 [ %16, %15 ], [ 0, %.lr.ph18 ]
  tail call void @GetAgentsCoordinates(ptr noundef nonnull @RatioOfDangerousSituations.x_j, ptr noundef nonnull %0, i32 noundef %.015) #2
  tail call void @VectDifference(ptr noundef nonnull @RatioOfDangerousSituations.x_j, ptr noundef nonnull @RatioOfDangerousSituations.x_j, ptr noundef %9) #2
  %10 = tail call double @VectAbs(ptr noundef nonnull @RatioOfDangerousSituations.x_j) #2
  %11 = fcmp ugt double %10, %1
  br i1 %11, label %15, label %12

12:                                               ; preds = %.lr.ph
  %13 = load i32, ptr @RatioOfDangerousSituations.NumberOfCollisions, align 4, !tbaa !5
  %14 = add nsw i32 %13, 1
  store i32 %14, ptr @RatioOfDangerousSituations.NumberOfCollisions, align 4, !tbaa !5
  br label %15

15:                                               ; preds = %.lr.ph, %12
  %16 = add nuw nsw i32 %.015, 1
  %17 = zext nneg i32 %16 to i64
  %exitcond.not = icmp eq i64 %indvars.iv, %17
  br i1 %exitcond.not, label %._crit_edge.loopexit, label %.lr.ph, !llvm.loop !14

._crit_edge.loopexit:                             ; preds = %15
  %.pre = load i32, ptr %3, align 4, !tbaa !9
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %.lr.ph18
  %18 = phi i32 [ %.pre, %._crit_edge.loopexit ], [ %6, %.lr.ph18 ]
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %19 = sext i32 %18 to i64
  %20 = icmp slt i64 %indvars.iv.next, %19
  br i1 %20, label %.lr.ph18, label %._crit_edge19.loopexit, !llvm.loop !16

._crit_edge19.loopexit:                           ; preds = %._crit_edge
  %.pre22 = load i32, ptr @RatioOfDangerousSituations.NumberOfCollisions, align 4, !tbaa !5
  %21 = sitofp i32 %.pre22 to double
  %22 = fmul double %21, 2.000000e+00
  br label %._crit_edge19

._crit_edge19:                                    ; preds = %._crit_edge19.loopexit, %2
  %23 = phi double [ 0.000000e+00, %2 ], [ %22, %._crit_edge19.loopexit ]
  %.lcssa = phi i32 [ %4, %2 ], [ %18, %._crit_edge19.loopexit ]
  %24 = add nsw i32 %.lcssa, -1
  %25 = mul nsw i32 %24, %.lcssa
  %26 = sitofp i32 %25 to double
  %27 = fdiv double %23, %26
  ret double %27
}

declare void @GetAgentsCoordinates(ptr noundef, ptr noundef, i32 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, !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 = !{!10, !11, i64 0}
!13 = !{!11, !11, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = distinct !{!16, !15}


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