; LLVM IR from IlyaGrebnov/libbsc :: libbsc/filters (detectors)

; 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: mustprogress uwtable
declare dso_local noundef i32 @_Z26bsc_detect_segments_serialP20BscSegmentationModelPKhi(ptr noalias noundef, ptr noalias noundef, i32 noundef) #0

; 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

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_Z29bsc_detect_segments_recursiveP20BscSegmentationModelS0_PKhiPiii(ptr noundef %0, ptr noundef %1, ptr noundef %2, i32 noundef %3, ptr noundef %4, i32 noundef %5, i32 noundef %6) #0 {
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca i32, align 4
  %13 = alloca ptr, align 8
  %14 = alloca i32, align 4
  %15 = alloca i32, align 4
  %16 = alloca i32, align 4
  %17 = alloca i32, align 4
  %18 = alloca i32, align 4
  %19 = alloca i32, align 4
  store ptr %0, ptr %9, align 8, !tbaa !5
  store ptr %1, ptr %10, align 8, !tbaa !5
  store ptr %2, ptr %11, align 8, !tbaa !5
  store i32 %3, ptr %12, align 4, !tbaa !9
  store ptr %4, ptr %13, align 8, !tbaa !5
  store i32 %5, ptr %14, align 4, !tbaa !9
  store i32 %6, ptr %15, align 4, !tbaa !9
  %20 = load i32, ptr %12, align 4, !tbaa !9
  %21 = icmp slt i32 %20, 24576
  br i1 %21, label %25, label %22

22:                                               ; preds = %7
  %23 = load i32, ptr %14, align 4, !tbaa !9
  %24 = icmp eq i32 %23, 1
  br i1 %24, label %25, label %29

25:                                               ; preds = %22, %7
  %26 = load i32, ptr %12, align 4, !tbaa !9
  %27 = load ptr, ptr %13, align 8, !tbaa !5
  %28 = getelementptr inbounds i32, ptr %27, i64 0
  store i32 %26, ptr %28, align 4, !tbaa !9
  store i32 1, ptr %8, align 4
  br label %86

29:                                               ; preds = %22
  call void @llvm.lifetime.start.p0(i64 4, ptr %16) #2
  %30 = load i32, ptr %12, align 4, !tbaa !9
  store i32 %30, ptr %16, align 4, !tbaa !9
  %31 = load ptr, ptr %9, align 8, !tbaa !5
  %32 = load ptr, ptr %11, align 8, !tbaa !5
  %33 = load i32, ptr %12, align 4, !tbaa !9
  %34 = call noundef i32 @_Z26bsc_detect_segments_serialP20BscSegmentationModelPKhi(ptr noundef %31, ptr noundef %32, i32 noundef %33)
  store i32 %34, ptr %16, align 4, !tbaa !9
  %35 = load i32, ptr %16, align 4, !tbaa !9
  %36 = load i32, ptr %12, align 4, !tbaa !9
  %37 = icmp eq i32 %35, %36
  br i1 %37, label %38, label %42

38:                                               ; preds = %29
  %39 = load i32, ptr %12, align 4, !tbaa !9
  %40 = load ptr, ptr %13, align 8, !tbaa !5
  %41 = getelementptr inbounds i32, ptr %40, i64 0
  store i32 %39, ptr %41, align 4, !tbaa !9
  store i32 1, ptr %8, align 4
  store i32 1, ptr %17, align 4
  br label %85

42:                                               ; preds = %29
  call void @llvm.lifetime.start.p0(i64 4, ptr %18) #2
  %43 = load ptr, ptr %9, align 8, !tbaa !5
  %44 = load ptr, ptr %10, align 8, !tbaa !5
  %45 = load ptr, ptr %11, align 8, !tbaa !5
  %46 = load i32, ptr %16, align 4, !tbaa !9
  %47 = load ptr, ptr %13, align 8, !tbaa !5
  %48 = load i32, ptr %14, align 4, !tbaa !9
  %49 = sub nsw i32 %48, 1
  %50 = load i32, ptr %15, align 4, !tbaa !9
  %51 = call noundef i32 @_Z29bsc_detect_segments_recursiveP20BscSegmentationModelS0_PKhiPiii(ptr noundef %43, ptr noundef %44, ptr noundef %45, i32 noundef %46, ptr noundef %47, i32 noundef %49, i32 noundef %50)
  store i32 %51, ptr %18, align 4, !tbaa !9
  %52 = load i32, ptr %18, align 4, !tbaa !9
  %53 = icmp slt i32 %52, 0
  br i1 %53, label %54, label %56

54:                                               ; preds = %42
  %55 = load i32, ptr %18, align 4, !tbaa !9
  store i32 %55, ptr %8, align 4
  store i32 1, ptr %17, align 4
  br label %84

56:                                               ; preds = %42
  call void @llvm.lifetime.start.p0(i64 4, ptr %19) #2
  %57 = load ptr, ptr %9, align 8, !tbaa !5
  %58 = load ptr, ptr %10, align 8, !tbaa !5
  %59 = load ptr, ptr %11, align 8, !tbaa !5
  %60 = load i32, ptr %16, align 4, !tbaa !9
  %61 = sext i32 %60 to i64
  %62 = getelementptr inbounds i8, ptr %59, i64 %61
  %63 = load i32, ptr %12, align 4, !tbaa !9
  %64 = load i32, ptr %16, align 4, !tbaa !9
  %65 = sub nsw i32 %63, %64
  %66 = load ptr, ptr %13, align 8, !tbaa !5
  %67 = load i32, ptr %18, align 4, !tbaa !9
  %68 = sext i32 %67 to i64
  %69 = getelementptr inbounds i32, ptr %66, i64 %68
  %70 = load i32, ptr %14, align 4, !tbaa !9
  %71 = load i32, ptr %18, align 4, !tbaa !9
  %72 = sub nsw i32 %70, %71
  %73 = load i32, ptr %15, align 4, !tbaa !9
  %74 = call noundef i32 @_Z29bsc_detect_segments_recursiveP20BscSegmentationModelS0_PKhiPiii(ptr noundef %57, ptr noundef %58, ptr noundef %62, i32 noundef %65, ptr noundef %69, i32 noundef %72, i32 noundef %73)
  store i32 %74, ptr %19, align 4, !tbaa !9
  %75 = load i32, ptr %19, align 4, !tbaa !9
  %76 = icmp slt i32 %75, 0
  br i1 %76, label %77, label %79

77:                                               ; preds = %56
  %78 = load i32, ptr %19, align 4, !tbaa !9
  store i32 %78, ptr %8, align 4
  store i32 1, ptr %17, align 4
  br label %83

79:                                               ; preds = %56
  %80 = load i32, ptr %18, align 4, !tbaa !9
  %81 = load i32, ptr %19, align 4, !tbaa !9
  %82 = add nsw i32 %80, %81
  store i32 %82, ptr %8, align 4
  store i32 1, ptr %17, align 4
  br label %83

83:                                               ; preds = %79, %77
  call void @llvm.lifetime.end.p0(i64 4, ptr %19) #2
  br label %84

84:                                               ; preds = %83, %54
  call void @llvm.lifetime.end.p0(i64 4, ptr %18) #2
  br label %85

85:                                               ; preds = %84, %38
  call void @llvm.lifetime.end.p0(i64 4, ptr %16) #2
  br label %86

86:                                               ; preds = %85, %25
  %87 = load i32, ptr %8, align 4
  ret i32 %87
}

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 = { 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}


; 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
declare dso_local noundef i32 @_Z26bsc_detect_segments_serialP20BscSegmentationModelPKhi(ptr noalias noundef, ptr noalias noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
define dso_local noundef range(i32 1, -2147483648) i32 @_Z29bsc_detect_segments_recursiveP20BscSegmentationModelS0_PKhiPiii(ptr noundef %0, ptr nocapture noundef readnone %1, ptr noundef %2, i32 noundef %3, ptr nocapture noundef writeonly %4, i32 noundef %5, i32 noundef %6) local_unnamed_addr #0 {
  %8 = icmp slt i32 %3, 24576
  %9 = icmp eq i32 %5, 1
  %or.cond54 = or i1 %8, %9
  br i1 %or.cond54, label %tailrecurse._crit_edge, label %.lr.ph

tailrecurse._crit_edge:                           ; preds = %tailrecurse, %7
  %accumulator.tr.lcssa = phi i32 [ 0, %7 ], [ %21, %tailrecurse ]
  %.tr46.lcssa = phi i32 [ %3, %7 ], [ %17, %tailrecurse ]
  %.tr47.lcssa = phi ptr [ %4, %7 ], [ %19, %tailrecurse ]
  store i32 %.tr46.lcssa, ptr %.tr47.lcssa, align 4, !tbaa !5
  br label %24

.lr.ph:                                           ; preds = %7, %tailrecurse
  %.tr4859 = phi i32 [ %20, %tailrecurse ], [ %5, %7 ]
  %.tr4758 = phi ptr [ %19, %tailrecurse ], [ %4, %7 ]
  %.tr4657 = phi i32 [ %17, %tailrecurse ], [ %3, %7 ]
  %.tr4556 = phi ptr [ %16, %tailrecurse ], [ %2, %7 ]
  %accumulator.tr55 = phi i32 [ %21, %tailrecurse ], [ 0, %7 ]
  %10 = tail call noundef i32 @_Z26bsc_detect_segments_serialP20BscSegmentationModelPKhi(ptr noundef %0, ptr noundef %.tr4556, i32 noundef %.tr4657)
  %11 = icmp eq i32 %10, %.tr4657
  br i1 %11, label %12, label %tailrecurse

12:                                               ; preds = %.lr.ph
  store i32 %.tr4657, ptr %.tr4758, align 4, !tbaa !5
  br label %24

tailrecurse:                                      ; preds = %.lr.ph
  %13 = add nsw i32 %.tr4859, -1
  %14 = tail call noundef i32 @_Z29bsc_detect_segments_recursiveP20BscSegmentationModelS0_PKhiPiii(ptr noundef %0, ptr noundef %1, ptr noundef %.tr4556, i32 noundef %10, ptr noundef %.tr4758, i32 noundef %13, i32 noundef %6)
  %15 = sext i32 %10 to i64
  %16 = getelementptr inbounds i8, ptr %.tr4556, i64 %15
  %17 = sub nsw i32 %.tr4657, %10
  %18 = zext nneg i32 %14 to i64
  %19 = getelementptr inbounds i32, ptr %.tr4758, i64 %18
  %20 = sub nsw i32 %.tr4859, %14
  %21 = add nuw nsw i32 %14, %accumulator.tr55
  %22 = icmp slt i32 %17, 24576
  %23 = icmp eq i32 %20, 1
  %or.cond = or i1 %22, %23
  br i1 %or.cond, label %tailrecurse._crit_edge, label %.lr.ph

24:                                               ; preds = %12, %tailrecurse._crit_edge
  %accumulator.tr53 = phi i32 [ %accumulator.tr55, %12 ], [ %accumulator.tr.lcssa, %tailrecurse._crit_edge ]
  %accumulator.ret.tr = add nuw nsw i32 %accumulator.tr53, 1
  ret i32 %accumulator.ret.tr
}

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

!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"}


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