; LLVM IR from stan-dev/math :: lib/tbb_2020.3/src/test/test_malloc_pools.ll (Z14CheckPoolLeaksm)

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

@.str.20 = external hidden unnamed_addr constant [93 x i8], align 1
@.str.23 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.66 = external hidden unnamed_addr constant [30 x i8], align 1
@.str.67 = external hidden unnamed_addr constant [66 x i8], align 1
@.str.68 = external hidden unnamed_addr constant [35 x i8], align 1
@.str.69 = external hidden unnamed_addr constant [48 x i8], align 1

; 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
declare dso_local void @_Z11ReportErrorPKciS0_S0_(ptr noundef, i32 noundef, ptr noundef, ptr noundef) #1

declare noundef zeroext i1 @_ZN3rml12pool_destroyEPNS_10MemoryPoolE(ptr noundef) #2

; Function Attrs: mustprogress uwtable
declare dso_local noundef ptr @_Z16CreateUsablePoolm(i64 noundef) #1

; Function Attrs: mustprogress uwtable
define dso_local void @_Z14CheckPoolLeaksm(i64 noundef %0) #1 {
  %2 = alloca i64, align 8
  %3 = alloca i64, align 8
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca [16000 x ptr], align 16
  %7 = alloca i64, align 8
  %8 = alloca i64, align 8
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca ptr, align 8
  %13 = alloca i64, align 8
  %14 = alloca i8, align 1
  store i64 %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #3
  store i64 16000, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  store i32 20, ptr %4, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  store i32 3, ptr %5, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 128000, ptr %6) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  store i64 16000, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  store i32 0, ptr %9, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  store i32 0, ptr %10, align 4, !tbaa !9
  br label %15

15:                                               ; preds = %80, %1
  %16 = load i32, ptr %10, align 4, !tbaa !9
  %17 = icmp slt i32 %16, 20
  br i1 %17, label %18, label %21

18:                                               ; preds = %15
  %19 = load i32, ptr %9, align 4, !tbaa !9
  %20 = icmp slt i32 %19, 3
  br label %21

21:                                               ; preds = %18, %15
  %22 = phi i1 [ false, %15 ], [ %20, %18 ]
  br i1 %22, label %24, label %23

23:                                               ; preds = %21
  store i32 2, ptr %11, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  br label %83

24:                                               ; preds = %21
  store i64 0, ptr %7, align 8, !tbaa !5
  br label %25

25:                                               ; preds = %41, %24
  %26 = load i64, ptr %7, align 8, !tbaa !5
  %27 = load i64, ptr %8, align 8, !tbaa !5
  %28 = icmp ult i64 %26, %27
  br i1 %28, label %29, label %44

29:                                               ; preds = %25
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #3
  %30 = call noundef ptr @_Z16CreateUsablePoolm(i64 noundef 1024)
  store ptr %30, ptr %12, align 8, !tbaa !11
  %31 = load ptr, ptr %12, align 8, !tbaa !11
  %32 = icmp ne ptr %31, null
  br i1 %32, label %34, label %33

33:                                               ; preds = %29
  store i32 5, ptr %11, align 4
  br label %38

34:                                               ; preds = %29
  %35 = load ptr, ptr %12, align 8, !tbaa !11
  %36 = load i64, ptr %7, align 8, !tbaa !5
  %37 = getelementptr inbounds [16000 x ptr], ptr %6, i64 0, i64 %36
  store ptr %35, ptr %37, align 8, !tbaa !11
  store i32 0, ptr %11, align 4
  br label %38

38:                                               ; preds = %34, %33
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #3
  %39 = load i32, ptr %11, align 4
  switch i32 %39, label %89 [
    i32 0, label %40
    i32 5, label %44
  ]

40:                                               ; preds = %38
  br label %41

41:                                               ; preds = %40
  %42 = load i64, ptr %7, align 8, !tbaa !5
  %43 = add i64 %42, 1
  store i64 %43, ptr %7, align 8, !tbaa !5
  br label %25, !llvm.loop !13

44:                                               ; preds = %38, %25
  %45 = load i64, ptr %7, align 8, !tbaa !5
  %46 = load i64, ptr %2, align 8, !tbaa !5
  %47 = icmp uge i64 %45, %46
  br i1 %47, label %48, label %49

48:                                               ; preds = %44
  br label %50

49:                                               ; preds = %44
  call void @_Z11ReportErrorPKciS0_S0_(ptr noundef @.str.20, i32 noundef 664, ptr noundef @.str.66, ptr noundef @.str.67)
  br label %50

50:                                               ; preds = %49, %48
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #3
  store i64 0, ptr %13, align 8, !tbaa !5
  br label %51

51:                                               ; preds = %67, %50
  %52 = load i64, ptr %13, align 8, !tbaa !5
  %53 = load i64, ptr %7, align 8, !tbaa !5
  %54 = icmp ult i64 %52, %53
  br i1 %54, label %56, label %55

55:                                               ; preds = %51
  store i32 8, ptr %11, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #3
  br label %70

56:                                               ; preds = %51
  call void @llvm.lifetime.start.p0(i64 1, ptr %14) #3
  %57 = load i64, ptr %13, align 8, !tbaa !5
  %58 = getelementptr inbounds [16000 x ptr], ptr %6, i64 0, i64 %57
  %59 = load ptr, ptr %58, align 8, !tbaa !11
  %60 = call noundef zeroext i1 @_ZN3rml12pool_destroyEPNS_10MemoryPoolE(ptr noundef %59)
  %61 = zext i1 %60 to i8
  store i8 %61, ptr %14, align 1, !tbaa !15
  %62 = load i8, ptr %14, align 1, !tbaa !15, !range !17, !noundef !18
  %63 = trunc i8 %62 to i1
  br i1 %63, label %64, label %65

64:                                               ; preds = %56
  br label %66

65:                                               ; preds = %56
  call void @_Z11ReportErrorPKciS0_S0_(ptr noundef @.str.20, i32 noundef 667, ptr noundef @.str.23, ptr noundef null)
  br label %66

66:                                               ; preds = %65, %64
  call void @llvm.lifetime.end.p0(i64 1, ptr %14) #3
  br label %67

67:                                               ; preds = %66
  %68 = load i64, ptr %13, align 8, !tbaa !5
  %69 = add i64 %68, 1
  store i64 %69, ptr %13, align 8, !tbaa !5
  br label %51, !llvm.loop !19

70:                                               ; preds = %55
  %71 = load i64, ptr %7, align 8, !tbaa !5
  %72 = load i64, ptr %8, align 8, !tbaa !5
  %73 = icmp ult i64 %71, %72
  br i1 %73, label %74, label %76

74:                                               ; preds = %70
  %75 = load i64, ptr %7, align 8, !tbaa !5
  store i64 %75, ptr %8, align 8, !tbaa !5
  store i32 0, ptr %9, align 4, !tbaa !9
  br label %79

76:                                               ; preds = %70
  %77 = load i32, ptr %9, align 4, !tbaa !9
  %78 = add nsw i32 %77, 1
  store i32 %78, ptr %9, align 4, !tbaa !9
  br label %79

79:                                               ; preds = %76, %74
  br label %80

80:                                               ; preds = %79
  %81 = load i32, ptr %10, align 4, !tbaa !9
  %82 = add nsw i32 %81, 1
  store i32 %82, ptr %10, align 4, !tbaa !9
  br label %15, !llvm.loop !20

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

86:                                               ; preds = %83
  br label %88

87:                                               ; preds = %83
  call void @_Z11ReportErrorPKciS0_S0_(ptr noundef @.str.20, i32 noundef 675, ptr noundef @.str.68, ptr noundef @.str.69)
  br label %88

88:                                               ; preds = %87, %86
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 128000, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  ret void

89:                                               ; preds = %38
  unreachable
}

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 = { "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 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"any pointer", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = !{!16, !16, i64 0}
!16 = !{!"bool", !7, i64 0}
!17 = !{i8 0, i8 2}
!18 = !{}
!19 = distinct !{!19, !14}
!20 = distinct !{!20, !14}


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

@.str.20 = external hidden unnamed_addr constant [93 x i8], align 1
@.str.23 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.66 = external hidden unnamed_addr constant [30 x i8], align 1
@.str.67 = external hidden unnamed_addr constant [66 x i8], align 1
@.str.68 = external hidden unnamed_addr constant [35 x i8], align 1
@.str.69 = external hidden unnamed_addr constant [48 x i8], align 1

; 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
declare dso_local void @_Z11ReportErrorPKciS0_S0_(ptr noundef, i32 noundef, ptr noundef, ptr noundef) local_unnamed_addr #1

declare noundef zeroext i1 @_ZN3rml12pool_destroyEPNS_10MemoryPoolE(ptr noundef) local_unnamed_addr #2

; Function Attrs: mustprogress uwtable
declare dso_local noundef ptr @_Z16CreateUsablePoolm(i64 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress uwtable
define dso_local void @_Z14CheckPoolLeaksm(i64 noundef %0) local_unnamed_addr #1 {
  %2 = alloca [16000 x ptr], align 16
  call void @llvm.lifetime.start.p0(i64 128000, ptr nonnull %2) #4
  br label %.preheader

.preheader:                                       ; preds = %1, %._crit_edge39
  %.02242 = phi i64 [ 16000, %1 ], [ %.1, %._crit_edge39 ]
  %.02441 = phi i32 [ 0, %1 ], [ %14, %._crit_edge39 ]
  %.02540 = phi i32 [ 0, %1 ], [ %.126, %._crit_edge39 ]
  %.not45 = icmp eq i64 %.02242, 0
  br i1 %.not45, label %._crit_edge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %.preheader
  %3 = tail call noundef ptr @_Z16CreateUsablePoolm(i64 noundef 1024)
  %.not46 = icmp eq ptr %3, null
  br i1 %.not46, label %._crit_edge, label %.lr.ph48

4:                                                ; preds = %._crit_edge39
  %5 = icmp eq i32 %.126, 3
  br i1 %5, label %25, label %24

.lr.ph:                                           ; preds = %.lr.ph48
  %6 = tail call noundef ptr @_Z16CreateUsablePoolm(i64 noundef 1024)
  %.not = icmp eq ptr %6, null
  br i1 %.not, label %._crit_edge.loopexit, label %.lr.ph48, !llvm.loop !5

.lr.ph48:                                         ; preds = %.lr.ph.preheader, %.lr.ph
  %7 = phi ptr [ %6, %.lr.ph ], [ %3, %.lr.ph.preheader ]
  %.03147 = phi i64 [ %9, %.lr.ph ], [ 0, %.lr.ph.preheader ]
  %8 = getelementptr inbounds [16000 x ptr], ptr %2, i64 0, i64 %.03147
  store ptr %7, ptr %8, align 8, !tbaa !7
  %9 = add nuw i64 %.03147, 1
  %exitcond.not = icmp eq i64 %9, %.02242
  br i1 %exitcond.not, label %._crit_edge.loopexit, label %.lr.ph, !llvm.loop !5

._crit_edge.loopexit:                             ; preds = %.lr.ph48, %.lr.ph
  %.0.lcssa.ph = phi i64 [ %.02242, %.lr.ph48 ], [ %9, %.lr.ph ]
  %10 = icmp ult i64 %9, %.02242
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %.lr.ph.preheader, %.preheader
  %.0.lcssa = phi i64 [ 0, %.preheader ], [ 0, %.lr.ph.preheader ], [ %.0.lcssa.ph, %._crit_edge.loopexit ]
  %.lcssa = phi i1 [ false, %.preheader ], [ true, %.lr.ph.preheader ], [ %10, %._crit_edge.loopexit ]
  %.not28 = icmp ult i64 %.0.lcssa, %0
  br i1 %.not28, label %11, label %12

11:                                               ; preds = %._crit_edge
  tail call void @_Z11ReportErrorPKciS0_S0_(ptr noundef nonnull @.str.20, i32 noundef 664, ptr noundef nonnull @.str.66, ptr noundef nonnull @.str.67)
  br label %12

12:                                               ; preds = %._crit_edge, %11
  %.not43 = icmp eq i64 %.0.lcssa, 0
  br i1 %.not43, label %._crit_edge39, label %.lr.ph38

._crit_edge39:                                    ; preds = %22, %12
  %13 = add nsw i32 %.02540, 1
  %.126 = select i1 %.lcssa, i32 0, i32 %13
  %.1 = tail call i64 @llvm.umin.i64(i64 %.0.lcssa, i64 %.02242)
  %14 = add nuw nsw i32 %.02441, 1
  %15 = icmp ult i32 %.02441, 19
  %16 = icmp slt i32 %.126, 3
  %17 = select i1 %15, i1 %16, i1 false
  br i1 %17, label %.preheader, label %4, !llvm.loop !11

.lr.ph38:                                         ; preds = %12, %22
  %.02136 = phi i64 [ %23, %22 ], [ 0, %12 ]
  %18 = getelementptr inbounds [16000 x ptr], ptr %2, i64 0, i64 %.02136
  %19 = load ptr, ptr %18, align 8, !tbaa !7
  %20 = tail call noundef zeroext i1 @_ZN3rml12pool_destroyEPNS_10MemoryPoolE(ptr noundef %19)
  br i1 %20, label %22, label %21

21:                                               ; preds = %.lr.ph38
  tail call void @_Z11ReportErrorPKciS0_S0_(ptr noundef nonnull @.str.20, i32 noundef 667, ptr noundef nonnull @.str.23, ptr noundef null)
  br label %22

22:                                               ; preds = %.lr.ph38, %21
  %23 = add nuw i64 %.02136, 1
  %exitcond44.not = icmp eq i64 %23, %.0.lcssa
  br i1 %exitcond44.not, label %._crit_edge39, label %.lr.ph38, !llvm.loop !12

24:                                               ; preds = %4
  tail call void @_Z11ReportErrorPKciS0_S0_(ptr noundef nonnull @.str.20, i32 noundef 675, ptr noundef nonnull @.str.68, ptr noundef nonnull @.str.69)
  br label %25

25:                                               ; preds = %4, %24
  call void @llvm.lifetime.end.p0(i64 128000, ptr nonnull %2) #4
  ret void
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i64 @llvm.umin.i64(i64, i64) #3

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 = { "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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}
!7 = !{!8, !8, i64 0}
!8 = !{!"any pointer", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C++ TBAA"}
!11 = distinct !{!11, !6}
!12 = distinct !{!12, !6}


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