; LLVM IR from ArefMq/SoccerBallDetection :: src/modules/coloranalyzer.ll (ZN7MVision13ColorAnalyzer17histogramAnalysisEv)

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

%"class.MVision::ColorAnalyzer" = type { %class.Debugable, ptr, i32, %"class.std::vector" }
%class.Debugable = type { ptr, ptr }
%"class.std::vector" = type { %"struct.std::_Vector_base" }
%"struct.std::_Vector_base" = type { %"struct.std::_Vector_base<int, std::allocator<int>>::_Vector_impl" }
%"struct.std::_Vector_base<int, std::allocator<int>>::_Vector_impl" = type { %"struct.std::_Vector_base<int, std::allocator<int>>::_Vector_impl_data" }
%"struct.std::_Vector_base<int, std::allocator<int>>::_Vector_impl_data" = type { ptr, ptr, ptr }
%"class.MVision::Image::Pixel" = type { i8, i8, i8 }

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN7MVision13ColorAnalyzer17histogramAnalysisEv(ptr noundef nonnull align 8 dereferenceable(56) %0) #0 align 2 {
  %2 = alloca ptr, align 8
  %3 = alloca [256 x i32], align 16
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i8, align 1
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  %11 = load ptr, ptr %2, align 8
  call void @llvm.lifetime.start.p0(i64 1024, ptr %3) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #4
  store i32 0, ptr %4, align 4, !tbaa !9
  br label %12

12:                                               ; preds = %20, %1
  %13 = load i32, ptr %4, align 4, !tbaa !9
  %14 = icmp slt i32 %13, 256
  br i1 %14, label %16, label %15

15:                                               ; preds = %12
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #4
  br label %23

16:                                               ; preds = %12
  %17 = load i32, ptr %4, align 4, !tbaa !9
  %18 = sext i32 %17 to i64
  %19 = getelementptr inbounds [256 x i32], ptr %3, i64 0, i64 %18
  store i32 0, ptr %19, align 4, !tbaa !9
  br label %20

20:                                               ; preds = %16
  %21 = load i32, ptr %4, align 4, !tbaa !9
  %22 = add nsw i32 %21, 1
  store i32 %22, ptr %4, align 4, !tbaa !9
  br label %12, !llvm.loop !11

23:                                               ; preds = %15
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  store i32 0, ptr %5, align 4, !tbaa !9
  br label %24

24:                                               ; preds = %55, %23
  %25 = load i32, ptr %5, align 4, !tbaa !9
  %26 = getelementptr inbounds %"class.MVision::ColorAnalyzer", ptr %11, i32 0, i32 1
  %27 = load ptr, ptr %26, align 8, !tbaa !13
  %28 = call noundef i32 @_ZNK7MVision5Image5widthEv(ptr noundef nonnull align 8 dereferenceable(24) %27)
  %29 = icmp ult i32 %25, %28
  br i1 %29, label %31, label %30

30:                                               ; preds = %24
  store i32 5, ptr %6, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  br label %58

31:                                               ; preds = %24
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  store i32 0, ptr %7, align 4, !tbaa !9
  br label %32

32:                                               ; preds = %51, %31
  %33 = load i32, ptr %7, align 4, !tbaa !9
  %34 = getelementptr inbounds %"class.MVision::ColorAnalyzer", ptr %11, i32 0, i32 1
  %35 = load ptr, ptr %34, align 8, !tbaa !13
  %36 = call noundef i32 @_ZNK7MVision5Image6heightEv(ptr noundef nonnull align 8 dereferenceable(24) %35)
  %37 = icmp ult i32 %33, %36
  br i1 %37, label %39, label %38

38:                                               ; preds = %32
  store i32 8, ptr %6, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  br label %54

39:                                               ; preds = %32
  %40 = getelementptr inbounds %"class.MVision::ColorAnalyzer", ptr %11, i32 0, i32 1
  %41 = load ptr, ptr %40, align 8, !tbaa !13
  %42 = load i32, ptr %5, align 4, !tbaa !9
  %43 = load i32, ptr %7, align 4, !tbaa !9
  %44 = call noundef nonnull align 1 dereferenceable(3) ptr @_ZNK7MVision5Image8getPixelEjj(ptr noundef nonnull align 8 dereferenceable(24) %41, i32 noundef %42, i32 noundef %43)
  %45 = getelementptr inbounds %"class.MVision::Image::Pixel", ptr %44, i32 0, i32 2
  %46 = load i8, ptr %45, align 1, !tbaa !20
  %47 = zext i8 %46 to i64
  %48 = getelementptr inbounds [256 x i32], ptr %3, i64 0, i64 %47
  %49 = load i32, ptr %48, align 4, !tbaa !9
  %50 = add nsw i32 %49, 1
  store i32 %50, ptr %48, align 4, !tbaa !9
  br label %51

51:                                               ; preds = %39
  %52 = load i32, ptr %7, align 4, !tbaa !9
  %53 = add i32 %52, 1
  store i32 %53, ptr %7, align 4, !tbaa !9
  br label %32, !llvm.loop !22

54:                                               ; preds = %38
  br label %55

55:                                               ; preds = %54
  %56 = load i32, ptr %5, align 4, !tbaa !9
  %57 = add i32 %56, 1
  store i32 %57, ptr %5, align 4, !tbaa !9
  br label %24, !llvm.loop !23

58:                                               ; preds = %30
  call void @llvm.lifetime.start.p0(i64 1, ptr %8) #4
  store i8 0, ptr %8, align 1, !tbaa !24
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  store i32 0, ptr %9, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #4
  store i32 0, ptr %10, align 4, !tbaa !9
  br label %59

59:                                               ; preds = %78, %58
  %60 = load i32, ptr %10, align 4, !tbaa !9
  %61 = icmp slt i32 %60, 127
  br i1 %61, label %63, label %62

62:                                               ; preds = %59
  store i32 11, ptr %6, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #4
  br label %81

63:                                               ; preds = %59
  %64 = load i32, ptr %10, align 4, !tbaa !9
  %65 = sext i32 %64 to i64
  %66 = getelementptr inbounds [256 x i32], ptr %3, i64 0, i64 %65
  %67 = load i32, ptr %66, align 4, !tbaa !9
  %68 = load i32, ptr %9, align 4, !tbaa !9
  %69 = icmp sgt i32 %67, %68
  br i1 %69, label %70, label %77

70:                                               ; preds = %63
  %71 = load i32, ptr %10, align 4, !tbaa !9
  %72 = sext i32 %71 to i64
  %73 = getelementptr inbounds [256 x i32], ptr %3, i64 0, i64 %72
  %74 = load i32, ptr %73, align 4, !tbaa !9
  store i32 %74, ptr %9, align 4, !tbaa !9
  %75 = load i32, ptr %10, align 4, !tbaa !9
  %76 = trunc i32 %75 to i8
  store i8 %76, ptr %8, align 1, !tbaa !24
  br label %77

77:                                               ; preds = %70, %63
  br label %78

78:                                               ; preds = %77
  %79 = load i32, ptr %10, align 4, !tbaa !9
  %80 = add nsw i32 %79, 1
  store i32 %80, ptr %10, align 4, !tbaa !9
  br label %59, !llvm.loop !25

81:                                               ; preds = %62
  %82 = load i8, ptr %8, align 1, !tbaa !24
  %83 = zext i8 %82 to i32
  %84 = getelementptr inbounds %"class.MVision::ColorAnalyzer", ptr %11, i32 0, i32 2
  store i32 %83, ptr %84, align 8, !tbaa !26
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 1, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 1024, ptr %3) #4
  ret void
}

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

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

declare noundef i32 @_ZNK7MVision5Image5widthEv(ptr noundef nonnull align 8 dereferenceable(24)) #2

declare noundef i32 @_ZNK7MVision5Image6heightEv(ptr noundef nonnull align 8 dereferenceable(24)) #2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 1 dereferenceable(3) ptr @_ZNK7MVision5Image8getPixelEjj(ptr noundef nonnull align 8 dereferenceable(24), i32 noundef, i32 noundef) #3 align 2

attributes #0 = { 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 #4 = { 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 = !{!14, !6, i64 16}
!14 = !{!"_ZTSN7MVision13ColorAnalyzerE", !15, i64 0, !6, i64 16, !10, i64 24, !16, i64 32}
!15 = !{!"_ZTS9Debugable", !6, i64 8}
!16 = !{!"_ZTSSt6vectorIiSaIiEE", !17, i64 0}
!17 = !{!"_ZTSSt12_Vector_baseIiSaIiEE", !18, i64 0}
!18 = !{!"_ZTSNSt12_Vector_baseIiSaIiEE12_Vector_implE", !19, i64 0}
!19 = !{!"_ZTSNSt12_Vector_baseIiSaIiEE17_Vector_impl_dataE", !6, i64 0, !6, i64 8, !6, i64 16}
!20 = !{!21, !7, i64 2}
!21 = !{!"_ZTSN7MVision5Image5PixelE", !7, i64 0, !7, i64 1, !7, i64 2}
!22 = distinct !{!22, !12}
!23 = distinct !{!23, !12}
!24 = !{!7, !7, i64 0}
!25 = distinct !{!25, !12}
!26 = !{!14, !10, i64 24}


; 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 uwtable
define dso_local void @_ZN7MVision13ColorAnalyzer17histogramAnalysisEv(ptr nocapture noundef nonnull align 8 dereferenceable(56) %0) local_unnamed_addr #0 align 2 {
.preheader25:
  %1 = alloca [256 x i32], align 16
  call void @llvm.lifetime.start.p0(i64 1024, ptr nonnull %1) #6
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(1024) %1, i8 0, i64 1024, i1 false), !tbaa !5
  %2 = getelementptr inbounds i8, ptr %0, i64 16
  %3 = load ptr, ptr %2, align 8, !tbaa !9
  %4 = tail call noundef i32 @_ZNK7MVision5Image5widthEv(ptr noundef nonnull align 8 dereferenceable(24) %3)
  %.not = icmp eq i32 %4, 0
  br i1 %.not, label %.preheader.preheader, label %.preheader24

.preheader.preheader:                             ; preds = %._crit_edge, %.preheader25
  br label %.preheader

.preheader24:                                     ; preds = %.preheader25, %._crit_edge
  %.02028 = phi i32 [ %7, %._crit_edge ], [ 0, %.preheader25 ]
  %5 = load ptr, ptr %2, align 8, !tbaa !9
  %6 = tail call noundef i32 @_ZNK7MVision5Image6heightEv(ptr noundef nonnull align 8 dereferenceable(24) %5)
  %.not32 = icmp eq i32 %6, 0
  br i1 %.not32, label %._crit_edge, label %.lr.ph

._crit_edge:                                      ; preds = %.lr.ph, %.preheader24
  %7 = add nuw i32 %.02028, 1
  %8 = load ptr, ptr %2, align 8, !tbaa !9
  %9 = tail call noundef i32 @_ZNK7MVision5Image5widthEv(ptr noundef nonnull align 8 dereferenceable(24) %8)
  %10 = icmp ult i32 %7, %9
  br i1 %10, label %.preheader24, label %.preheader.preheader, !llvm.loop !17

.lr.ph:                                           ; preds = %.preheader24, %.lr.ph
  %.01927 = phi i32 [ %19, %.lr.ph ], [ 0, %.preheader24 ]
  %11 = load ptr, ptr %2, align 8, !tbaa !9
  %12 = tail call noundef nonnull align 1 dereferenceable(3) ptr @_ZNK7MVision5Image8getPixelEjj(ptr noundef nonnull align 8 dereferenceable(24) %11, i32 noundef %.02028, i32 noundef %.01927)
  %13 = getelementptr inbounds i8, ptr %12, i64 2
  %14 = load i8, ptr %13, align 1, !tbaa !19
  %15 = zext i8 %14 to i64
  %16 = getelementptr inbounds [256 x i32], ptr %1, i64 0, i64 %15
  %17 = load i32, ptr %16, align 4, !tbaa !5
  %18 = add nsw i32 %17, 1
  store i32 %18, ptr %16, align 4, !tbaa !5
  %19 = add nuw i32 %.01927, 1
  %20 = load ptr, ptr %2, align 8, !tbaa !9
  %21 = tail call noundef i32 @_ZNK7MVision5Image6heightEv(ptr noundef nonnull align 8 dereferenceable(24) %20)
  %22 = icmp ult i32 %19, %21
  br i1 %22, label %.lr.ph, label %._crit_edge, !llvm.loop !21

23:                                               ; preds = %.preheader
  %24 = zext i8 %spec.select.2 to i32
  %25 = getelementptr inbounds i8, ptr %0, i64 24
  store i32 %24, ptr %25, align 8, !tbaa !22
  call void @llvm.lifetime.end.p0(i64 1024, ptr nonnull %1) #6
  ret void

.preheader:                                       ; preds = %.preheader.3, %.preheader.preheader
  %indvars.iv = phi i64 [ 0, %.preheader.preheader ], [ %indvars.iv.next.3, %.preheader.3 ]
  %.01630 = phi i32 [ 0, %.preheader.preheader ], [ %spec.select23.3, %.preheader.3 ]
  %.01729 = phi i8 [ 0, %.preheader.preheader ], [ %spec.select.3, %.preheader.3 ]
  %26 = getelementptr inbounds [256 x i32], ptr %1, i64 0, i64 %indvars.iv
  %27 = load i32, ptr %26, align 16, !tbaa !5
  %28 = icmp sgt i32 %27, %.01630
  %29 = trunc i64 %indvars.iv to i8
  %spec.select = select i1 %28, i8 %29, i8 %.01729
  %spec.select23 = tail call i32 @llvm.smax.i32(i32 %27, i32 %.01630)
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %30 = getelementptr inbounds [256 x i32], ptr %1, i64 0, i64 %indvars.iv.next
  %31 = load i32, ptr %30, align 4, !tbaa !5
  %32 = icmp sgt i32 %31, %spec.select23
  %33 = trunc i64 %indvars.iv.next to i8
  %spec.select.1 = select i1 %32, i8 %33, i8 %spec.select
  %spec.select23.1 = tail call i32 @llvm.smax.i32(i32 %31, i32 %spec.select23)
  %indvars.iv.next.1 = or disjoint i64 %indvars.iv, 2
  %34 = getelementptr inbounds [256 x i32], ptr %1, i64 0, i64 %indvars.iv.next.1
  %35 = load i32, ptr %34, align 8, !tbaa !5
  %36 = icmp sgt i32 %35, %spec.select23.1
  %37 = trunc i64 %indvars.iv.next.1 to i8
  %spec.select.2 = select i1 %36, i8 %37, i8 %spec.select.1
  %exitcond.not.2 = icmp eq i64 %indvars.iv, 124
  br i1 %exitcond.not.2, label %23, label %.preheader.3, !llvm.loop !23

.preheader.3:                                     ; preds = %.preheader
  %indvars.iv.next.2 = or disjoint i64 %indvars.iv, 3
  %spec.select23.2 = tail call i32 @llvm.smax.i32(i32 %35, i32 %spec.select23.1)
  %38 = getelementptr inbounds [256 x i32], ptr %1, i64 0, i64 %indvars.iv.next.2
  %39 = load i32, ptr %38, align 4, !tbaa !5
  %40 = icmp sgt i32 %39, %spec.select23.2
  %41 = trunc i64 %indvars.iv.next.2 to i8
  %spec.select.3 = select i1 %40, i8 %41, i8 %spec.select.2
  %spec.select23.3 = tail call i32 @llvm.smax.i32(i32 %39, i32 %spec.select23.2)
  %indvars.iv.next.3 = add nuw nsw i64 %indvars.iv, 4
  br label %.preheader
}

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

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

declare noundef i32 @_ZNK7MVision5Image5widthEv(ptr noundef nonnull align 8 dereferenceable(24)) local_unnamed_addr #2

declare noundef i32 @_ZNK7MVision5Image6heightEv(ptr noundef nonnull align 8 dereferenceable(24)) local_unnamed_addr #2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 1 dereferenceable(3) ptr @_ZNK7MVision5Image8getPixelEjj(ptr noundef nonnull align 8 dereferenceable(24), i32 noundef, i32 noundef) local_unnamed_addr #3 align 2

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.smax.i32(i32, i32) #4

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #5

attributes #0 = { 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 #1 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 #4 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #5 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #6 = { 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 = !{!10, !12, i64 16}
!10 = !{!"_ZTSN7MVision13ColorAnalyzerE", !11, i64 0, !12, i64 16, !6, i64 24, !13, i64 32}
!11 = !{!"_ZTS9Debugable", !12, i64 8}
!12 = !{!"any pointer", !7, i64 0}
!13 = !{!"_ZTSSt6vectorIiSaIiEE", !14, i64 0}
!14 = !{!"_ZTSSt12_Vector_baseIiSaIiEE", !15, i64 0}
!15 = !{!"_ZTSNSt12_Vector_baseIiSaIiEE12_Vector_implE", !16, i64 0}
!16 = !{!"_ZTSNSt12_Vector_baseIiSaIiEE17_Vector_impl_dataE", !12, i64 0, !12, i64 8, !12, i64 16}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}
!19 = !{!20, !7, i64 2}
!20 = !{!"_ZTSN7MVision5Image5PixelE", !7, i64 0, !7, i64 1, !7, i64 2}
!21 = distinct !{!21, !18}
!22 = !{!10, !6, i64 24}
!23 = distinct !{!23, !18}


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