; LLVM IR from ArefMq/SoccerBallDetection :: src/balldetector.ll (ZN7MVision12BallDetector20checkWhitePercentageEiii)

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

; 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: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZN7MVision12BallDetector20checkWhitePercentageEiii(ptr noundef nonnull align 8 dereferenceable(136) %0, i32 noundef %1, i32 noundef %2, i32 noundef %3) #1 align 2 {
  %5 = alloca i1, align 1
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  %15 = alloca ptr, align 8
  %16 = alloca i32, align 4
  %17 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store i32 %1, ptr %7, align 4, !tbaa !9
  store i32 %2, ptr %8, align 4, !tbaa !9
  store i32 %3, ptr %9, align 4, !tbaa !9
  %18 = load ptr, ptr %6, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  store i32 0, ptr %10, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  store i32 0, ptr %11, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #3
  store i32 0, ptr %12, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #3
  store i32 0, ptr %13, align 4, !tbaa !9
  br label %19

19:                                               ; preds = %81, %4
  %20 = load i32, ptr %13, align 4, !tbaa !9
  %21 = load i32, ptr %9, align 4, !tbaa !9
  %22 = icmp slt i32 %20, %21
  br i1 %22, label %24, label %23

23:                                               ; preds = %19
  store i32 2, ptr %14, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #3
  br label %84

24:                                               ; preds = %19
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %16) #3
  %25 = load i32, ptr %9, align 4, !tbaa !9
  %26 = load i32, ptr %9, align 4, !tbaa !9
  %27 = mul nsw i32 %25, %26
  %28 = load i32, ptr %13, align 4, !tbaa !9
  %29 = load i32, ptr %13, align 4, !tbaa !9
  %30 = mul nsw i32 %28, %29
  %31 = sub nsw i32 %27, %30
  %32 = call noundef double @_ZSt4sqrtIiEN9__gnu_cxx11__enable_ifIXsr12__is_integerIT_EE7__valueEdE6__typeES2_(i32 noundef %31)
  %33 = fptosi double %32 to i32
  store i32 %33, ptr %16, align 4, !tbaa !9
  store ptr %16, ptr %15, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %17) #3
  store i32 0, ptr %17, align 4, !tbaa !9
  br label %34

34:                                               ; preds = %77, %24
  %35 = load i32, ptr %17, align 4, !tbaa !9
  %36 = load ptr, ptr %15, align 8, !tbaa !5
  %37 = load i32, ptr %36, align 4, !tbaa !9
  %38 = icmp slt i32 %35, %37
  br i1 %38, label %40, label %39

39:                                               ; preds = %34
  store i32 5, ptr %14, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %17) #3
  br label %80

40:                                               ; preds = %34
  %41 = load i32, ptr %7, align 4, !tbaa !9
  %42 = load i32, ptr %13, align 4, !tbaa !9
  %43 = add nsw i32 %41, %42
  %44 = load i32, ptr %8, align 4, !tbaa !9
  %45 = load i32, ptr %17, align 4, !tbaa !9
  %46 = add nsw i32 %44, %45
  %47 = call noundef i32 @_ZN7MVision12BallDetector13searchedColorEiiRiS1_(ptr noundef nonnull align 8 dereferenceable(136) %18, i32 noundef %43, i32 noundef %46, ptr noundef nonnull align 4 dereferenceable(4) %10, ptr noundef nonnull align 4 dereferenceable(4) %11)
  %48 = load i32, ptr %12, align 4, !tbaa !9
  %49 = add nsw i32 %48, %47
  store i32 %49, ptr %12, align 4, !tbaa !9
  %50 = load i32, ptr %7, align 4, !tbaa !9
  %51 = load i32, ptr %13, align 4, !tbaa !9
  %52 = sub nsw i32 %50, %51
  %53 = load i32, ptr %8, align 4, !tbaa !9
  %54 = load i32, ptr %17, align 4, !tbaa !9
  %55 = add nsw i32 %53, %54
  %56 = call noundef i32 @_ZN7MVision12BallDetector13searchedColorEiiRiS1_(ptr noundef nonnull align 8 dereferenceable(136) %18, i32 noundef %52, i32 noundef %55, ptr noundef nonnull align 4 dereferenceable(4) %10, ptr noundef nonnull align 4 dereferenceable(4) %11)
  %57 = load i32, ptr %12, align 4, !tbaa !9
  %58 = add nsw i32 %57, %56
  store i32 %58, ptr %12, align 4, !tbaa !9
  %59 = load i32, ptr %7, align 4, !tbaa !9
  %60 = load i32, ptr %13, align 4, !tbaa !9
  %61 = add nsw i32 %59, %60
  %62 = load i32, ptr %8, align 4, !tbaa !9
  %63 = load i32, ptr %17, align 4, !tbaa !9
  %64 = sub nsw i32 %62, %63
  %65 = call noundef i32 @_ZN7MVision12BallDetector13searchedColorEiiRiS1_(ptr noundef nonnull align 8 dereferenceable(136) %18, i32 noundef %61, i32 noundef %64, ptr noundef nonnull align 4 dereferenceable(4) %10, ptr noundef nonnull align 4 dereferenceable(4) %11)
  %66 = load i32, ptr %12, align 4, !tbaa !9
  %67 = add nsw i32 %66, %65
  store i32 %67, ptr %12, align 4, !tbaa !9
  %68 = load i32, ptr %7, align 4, !tbaa !9
  %69 = load i32, ptr %13, align 4, !tbaa !9
  %70 = sub nsw i32 %68, %69
  %71 = load i32, ptr %8, align 4, !tbaa !9
  %72 = load i32, ptr %17, align 4, !tbaa !9
  %73 = sub nsw i32 %71, %72
  %74 = call noundef i32 @_ZN7MVision12BallDetector13searchedColorEiiRiS1_(ptr noundef nonnull align 8 dereferenceable(136) %18, i32 noundef %70, i32 noundef %73, ptr noundef nonnull align 4 dereferenceable(4) %10, ptr noundef nonnull align 4 dereferenceable(4) %11)
  %75 = load i32, ptr %12, align 4, !tbaa !9
  %76 = add nsw i32 %75, %74
  store i32 %76, ptr %12, align 4, !tbaa !9
  br label %77

77:                                               ; preds = %40
  %78 = load i32, ptr %17, align 4, !tbaa !9
  %79 = add nsw i32 %78, 1
  store i32 %79, ptr %17, align 4, !tbaa !9
  br label %34, !llvm.loop !11

80:                                               ; preds = %39
  call void @llvm.lifetime.end.p0(i64 4, ptr %16) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #3
  br label %81

81:                                               ; preds = %80
  %82 = load i32, ptr %13, align 4, !tbaa !9
  %83 = add nsw i32 %82, 1
  store i32 %83, ptr %13, align 4, !tbaa !9
  br label %19, !llvm.loop !13

84:                                               ; preds = %23
  %85 = load i32, ptr %12, align 4, !tbaa !9
  %86 = icmp eq i32 %85, 0
  br i1 %86, label %87, label %88

87:                                               ; preds = %84
  store i1 false, ptr %5, align 1
  store i32 1, ptr %14, align 4
  br label %106

88:                                               ; preds = %84
  %89 = load i32, ptr %10, align 4, !tbaa !9
  %90 = sitofp i32 %89 to float
  %91 = load i32, ptr %12, align 4, !tbaa !9
  %92 = sitofp i32 %91 to float
  %93 = fdiv float %90, %92
  %94 = fpext float %93 to double
  %95 = fcmp olt double %94, 5.000000e-02
  br i1 %95, label %104, label %96

96:                                               ; preds = %88
  %97 = load i32, ptr %11, align 4, !tbaa !9
  %98 = sitofp i32 %97 to float
  %99 = load i32, ptr %12, align 4, !tbaa !9
  %100 = sitofp i32 %99 to float
  %101 = fdiv float %98, %100
  %102 = fpext float %101 to double
  %103 = fcmp olt double %102, 0x3FE6666666666666
  br i1 %103, label %104, label %105

104:                                              ; preds = %96, %88
  store i1 false, ptr %5, align 1
  store i32 1, ptr %14, align 4
  br label %106

105:                                              ; preds = %96
  store i1 true, ptr %5, align 1
  store i32 1, ptr %14, align 4
  br label %106

106:                                              ; preds = %105, %104, %87
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  %107 = load i1, ptr %5, align 1
  ret i1 %107
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef double @_ZSt4sqrtIiEN9__gnu_cxx11__enable_ifIXsr12__is_integerIT_EE7__valueEdE6__typeES2_(i32 noundef) #2

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_ZN7MVision12BallDetector13searchedColorEiiRiS1_(ptr noundef nonnull align 8 dereferenceable(136), i32 noundef, i32 noundef, ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) #1 align 2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress 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 = { inlinehint mustprogress 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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}


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

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

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

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZN7MVision12BallDetector20checkWhitePercentageEiii(ptr noundef nonnull align 8 dereferenceable(136) %0, i32 noundef %1, i32 noundef %2, i32 noundef %3) local_unnamed_addr #1 align 2 {
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %5) #3
  store i32 0, ptr %5, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %6) #3
  store i32 0, ptr %6, align 4, !tbaa !5
  %7 = icmp sgt i32 %3, 0
  br i1 %7, label %.lr.ph43, label %._crit_edge44.thread

._crit_edge44:                                    ; preds = %._crit_edge
  %8 = icmp eq i32 %.1.lcssa, 0
  br i1 %8, label %._crit_edge44.thread, label %28

.lr.ph43:                                         ; preds = %4, %._crit_edge
  %.03541 = phi i32 [ %15, %._crit_edge ], [ 0, %4 ]
  %.03640 = phi i32 [ %.1.lcssa, %._crit_edge ], [ 0, %4 ]
  %add = add nuw nsw i32 %.03541, %3
  %sub = sub nsw i32 %3, %.03541
  %9 = mul nsw i32 %add, %sub
  %10 = call noundef double @_ZSt4sqrtIiEN9__gnu_cxx11__enable_ifIXsr12__is_integerIT_EE7__valueEdE6__typeES2_(i32 noundef %9)
  %11 = fptosi double %10 to i32
  %12 = icmp sgt i32 %11, 0
  br i1 %12, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %.lr.ph43
  %13 = add nsw i32 %.03541, %1
  %14 = sub nsw i32 %1, %.03541
  br label %16

._crit_edge:                                      ; preds = %16, %.lr.ph43
  %.1.lcssa = phi i32 [ %.03640, %.lr.ph43 ], [ %26, %16 ]
  %15 = add nuw nsw i32 %.03541, 1
  %exitcond46.not = icmp eq i32 %15, %3
  br i1 %exitcond46.not, label %._crit_edge44, label %.lr.ph43, !llvm.loop !9

16:                                               ; preds = %.lr.ph, %16
  %.039 = phi i32 [ 0, %.lr.ph ], [ %27, %16 ]
  %.138 = phi i32 [ %.03640, %.lr.ph ], [ %26, %16 ]
  %17 = add nsw i32 %.039, %2
  %18 = call noundef i32 @_ZN7MVision12BallDetector13searchedColorEiiRiS1_(ptr noundef nonnull align 8 dereferenceable(136) %0, i32 noundef %13, i32 noundef %17, ptr noundef nonnull align 4 dereferenceable(4) %5, ptr noundef nonnull align 4 dereferenceable(4) %6)
  %19 = add nsw i32 %18, %.138
  %20 = call noundef i32 @_ZN7MVision12BallDetector13searchedColorEiiRiS1_(ptr noundef nonnull align 8 dereferenceable(136) %0, i32 noundef %14, i32 noundef %17, ptr noundef nonnull align 4 dereferenceable(4) %5, ptr noundef nonnull align 4 dereferenceable(4) %6)
  %21 = add nsw i32 %19, %20
  %22 = sub nsw i32 %2, %.039
  %23 = call noundef i32 @_ZN7MVision12BallDetector13searchedColorEiiRiS1_(ptr noundef nonnull align 8 dereferenceable(136) %0, i32 noundef %13, i32 noundef %22, ptr noundef nonnull align 4 dereferenceable(4) %5, ptr noundef nonnull align 4 dereferenceable(4) %6)
  %24 = add nsw i32 %21, %23
  %25 = call noundef i32 @_ZN7MVision12BallDetector13searchedColorEiiRiS1_(ptr noundef nonnull align 8 dereferenceable(136) %0, i32 noundef %14, i32 noundef %22, ptr noundef nonnull align 4 dereferenceable(4) %5, ptr noundef nonnull align 4 dereferenceable(4) %6)
  %26 = add nsw i32 %24, %25
  %27 = add nuw nsw i32 %.039, 1
  %exitcond.not = icmp eq i32 %27, %11
  br i1 %exitcond.not, label %._crit_edge, label %16, !llvm.loop !11

28:                                               ; preds = %._crit_edge44
  %29 = load i32, ptr %5, align 4, !tbaa !5
  %30 = sitofp i32 %29 to float
  %31 = sitofp i32 %.1.lcssa to float
  %32 = fdiv float %30, %31
  %33 = fpext float %32 to double
  %34 = fcmp olt double %33, 5.000000e-02
  br i1 %34, label %._crit_edge44.thread, label %35

35:                                               ; preds = %28
  %36 = load i32, ptr %6, align 4, !tbaa !5
  %37 = sitofp i32 %36 to float
  %38 = fdiv float %37, %31
  %39 = fpext float %38 to double
  %40 = fcmp olt double %39, 0x3FE6666666666666
  br i1 %40, label %._crit_edge44.thread, label %41

41:                                               ; preds = %35
  br label %._crit_edge44.thread

._crit_edge44.thread:                             ; preds = %4, %28, %35, %._crit_edge44, %41
  %.034 = phi i1 [ true, %41 ], [ false, %._crit_edge44 ], [ false, %35 ], [ false, %28 ], [ false, %4 ]
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %6) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %5) #3
  ret i1 %.034
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef double @_ZSt4sqrtIiEN9__gnu_cxx11__enable_ifIXsr12__is_integerIT_EE7__valueEdE6__typeES2_(i32 noundef) local_unnamed_addr #2

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_ZN7MVision12BallDetector13searchedColorEiiRiS1_(ptr noundef nonnull align 8 dereferenceable(136), i32 noundef, i32 noundef, ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) local_unnamed_addr #1 align 2

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress 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 = { inlinehint mustprogress 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}


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