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

; 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.rml::MemPoolPolicy" = type { ptr, ptr, i64, i32, i32 }

@.str.20 = external hidden unnamed_addr constant [93 x i8], align 1
@_ZL9putMemAll = external hidden global i64, align 8
@_ZL9getMemAll = external hidden global i64, align 8
@.str.44 = external hidden unnamed_addr constant [11 x i8], align 1
@_ZL16getMemSuccessful = external hidden global i64, align 8
@.str.58 = external hidden unnamed_addr constant [25 x i8], align 1
@.str.59 = external hidden unnamed_addr constant [25 x i8], align 1
@.str.60 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.61 = external hidden unnamed_addr constant [27 x i8], align 1
@.str.62 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.63 = external hidden unnamed_addr constant [29 x i8], align 1
@.str.64 = external hidden unnamed_addr constant [79 x i8], align 1
@.str.65 = external hidden unnamed_addr constant [104 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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN3rml13MemPoolPolicyC2EPFPvlRmEPFilS1_mEmbb(ptr noundef nonnull align 8 dereferenceable(32), ptr noundef, ptr noundef, i64 noundef, i1 noundef zeroext, i1 noundef zeroext) unnamed_addr #2 align 2

declare noundef i32 @_ZN3rml14pool_create_v1ElPKNS_13MemPoolPolicyEPPNS_10MemoryPoolE(i64 noundef, ptr noundef, ptr noundef) #3

declare noundef ptr @_ZN3rml11pool_mallocEPNS_10MemoryPoolEm(ptr noundef, i64 noundef) #3

declare noundef zeroext i1 @_ZN3rml9pool_freeEPNS_10MemoryPoolEPv(ptr noundef, ptr noundef) #3

; Function Attrs: mustprogress nounwind uwtable
declare hidden noundef ptr @_ZL12getMemMalloclRm(i64 noundef, ptr noundef nonnull align 8 dereferenceable(8)) #2

; Function Attrs: mustprogress nounwind uwtable
declare hidden noundef i32 @_ZL10putMemFreelPvm(i64 noundef, ptr noundef, i64 noundef) #2

; Function Attrs: mustprogress uwtable
define dso_local noundef ptr @_Z16CreateUsablePoolm(i64 noundef %0) #1 {
  %2 = alloca ptr, align 8
  %3 = alloca i64, align 8
  %4 = alloca ptr, align 8
  %5 = alloca %"struct.rml::MemPoolPolicy", align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  store i64 %0, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #4
  call void @llvm.lifetime.start.p0(i64 32, ptr %5) #4
  call void @_ZN3rml13MemPoolPolicyC2EPFPvlRmEPFilS1_mEmbb(ptr noundef nonnull align 8 dereferenceable(32) %5, ptr noundef @_ZL12getMemMalloclRm, ptr noundef @_ZL10putMemFreelPvm, i64 noundef 0, i1 noundef zeroext false, i1 noundef zeroext false)
  store i64 0, ptr @_ZL16getMemSuccessful, align 8, !tbaa !5
  store i64 0, ptr @_ZL9getMemAll, align 8, !tbaa !5
  store i64 0, ptr @_ZL9putMemAll, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  %9 = call noundef i32 @_ZN3rml14pool_create_v1ElPKNS_13MemPoolPolicyEPPNS_10MemoryPoolE(i64 noundef 0, ptr noundef %5, ptr noundef %4)
  store i32 %9, ptr %6, align 4, !tbaa !9
  %10 = load i32, ptr %6, align 4, !tbaa !9
  %11 = icmp ne i32 %10, 0
  br i1 %11, label %12, label %21

12:                                               ; preds = %1
  %13 = load i64, ptr @_ZL9getMemAll, align 8, !tbaa !5
  %14 = icmp ne i64 %13, 0
  br i1 %14, label %19, label %15

15:                                               ; preds = %12
  %16 = load i64, ptr @_ZL9putMemAll, align 8, !tbaa !5
  %17 = icmp ne i64 %16, 0
  br i1 %17, label %19, label %18

18:                                               ; preds = %15
  br label %20

19:                                               ; preds = %15, %12
  call void @_Z11ReportErrorPKciS0_S0_(ptr noundef @.str.20, i32 noundef 628, ptr noundef @.str.58, ptr noundef @.str.59)
  br label %20

20:                                               ; preds = %19, %18
  store ptr null, ptr %2, align 8
  store i32 1, ptr %7, align 4
  br label %61

21:                                               ; preds = %1
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  %22 = load ptr, ptr %4, align 8, !tbaa !11
  %23 = load i64, ptr %3, align 8, !tbaa !5
  %24 = call noundef ptr @_ZN3rml11pool_mallocEPNS_10MemoryPoolEm(ptr noundef %22, i64 noundef %23)
  store ptr %24, ptr %8, align 8, !tbaa !11
  %25 = load i64, ptr @_ZL16getMemSuccessful, align 8, !tbaa !5
  %26 = icmp ne i64 %25, 0
  br i1 %26, label %33, label %27

27:                                               ; preds = %21
  %28 = load ptr, ptr %8, align 8, !tbaa !11
  %29 = icmp ne ptr %28, null
  br i1 %29, label %31, label %30

30:                                               ; preds = %27
  br label %32

31:                                               ; preds = %27
  call void @_Z11ReportErrorPKciS0_S0_(ptr noundef @.str.20, i32 noundef 634, ptr noundef @.str.60, ptr noundef @.str.61)
  br label %32

32:                                               ; preds = %31, %30
  store ptr null, ptr %2, align 8
  store i32 1, ptr %7, align 4
  br label %60

33:                                               ; preds = %21
  %34 = load ptr, ptr %8, align 8, !tbaa !11
  %35 = icmp ne ptr %34, null
  br i1 %35, label %36, label %37

36:                                               ; preds = %33
  br label %38

37:                                               ; preds = %33
  call void @_Z11ReportErrorPKciS0_S0_(ptr noundef @.str.20, i32 noundef 637, ptr noundef @.str.62, ptr noundef @.str.63)
  br label %38

38:                                               ; preds = %37, %36
  %39 = load i64, ptr @_ZL16getMemSuccessful, align 8, !tbaa !5
  %40 = icmp eq i64 %39, 1
  br i1 %40, label %48, label %41

41:                                               ; preds = %38
  %42 = load i64, ptr @_ZL16getMemSuccessful, align 8, !tbaa !5
  %43 = icmp eq i64 %42, 5
  br i1 %43, label %48, label %44

44:                                               ; preds = %41
  %45 = load i64, ptr @_ZL9getMemAll, align 8, !tbaa !5
  %46 = load i64, ptr @_ZL16getMemSuccessful, align 8, !tbaa !5
  %47 = icmp ugt i64 %45, %46
  br i1 %47, label %48, label %49

48:                                               ; preds = %44, %41, %38
  br label %50

49:                                               ; preds = %44
  call void @_Z11ReportErrorPKciS0_S0_(ptr noundef @.str.20, i32 noundef 639, ptr noundef @.str.64, ptr noundef @.str.65)
  br label %50

50:                                               ; preds = %49, %48
  %51 = load i64, ptr @_ZL9putMemAll, align 8, !tbaa !5
  %52 = icmp ne i64 %51, 0
  br i1 %52, label %54, label %53

53:                                               ; preds = %50
  br label %55

54:                                               ; preds = %50
  call void @_Z11ReportErrorPKciS0_S0_(ptr noundef @.str.20, i32 noundef 640, ptr noundef @.str.44, ptr noundef null)
  br label %55

55:                                               ; preds = %54, %53
  %56 = load ptr, ptr %4, align 8, !tbaa !11
  %57 = load ptr, ptr %8, align 8, !tbaa !11
  %58 = call noundef zeroext i1 @_ZN3rml9pool_freeEPNS_10MemoryPoolEPv(ptr noundef %56, ptr noundef %57)
  %59 = load ptr, ptr %4, align 8, !tbaa !11
  store ptr %59, ptr %2, align 8
  store i32 1, ptr %7, align 4
  br label %60

60:                                               ; preds = %55, %32
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  br label %61

61:                                               ; preds = %60, %20
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 32, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #4
  %62 = load ptr, ptr %2, align 8
  ret ptr %62
}

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 = { 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 = { "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 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"_ZTSN3rml12MemPoolErrorE", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"any pointer", !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"

%"struct.rml::MemPoolPolicy" = type { ptr, ptr, i64, i32, i32 }

@.str.20 = external hidden unnamed_addr constant [93 x i8], align 1
@_ZL9putMemAll = external hidden local_unnamed_addr global i64, align 8
@_ZL9getMemAll = external hidden local_unnamed_addr global i64, align 8
@.str.44 = external hidden unnamed_addr constant [11 x i8], align 1
@_ZL16getMemSuccessful = external hidden local_unnamed_addr global i64, align 8
@.str.58 = external hidden unnamed_addr constant [25 x i8], align 1
@.str.59 = external hidden unnamed_addr constant [25 x i8], align 1
@.str.60 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.61 = external hidden unnamed_addr constant [27 x i8], align 1
@.str.62 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.63 = external hidden unnamed_addr constant [29 x i8], align 1
@.str.64 = external hidden unnamed_addr constant [79 x i8], align 1
@.str.65 = external hidden unnamed_addr constant [104 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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN3rml13MemPoolPolicyC2EPFPvlRmEPFilS1_mEmbb(ptr noundef nonnull align 8 dereferenceable(32), ptr noundef, ptr noundef, i64 noundef, i1 noundef zeroext, i1 noundef zeroext) unnamed_addr #2 align 2

declare noundef i32 @_ZN3rml14pool_create_v1ElPKNS_13MemPoolPolicyEPPNS_10MemoryPoolE(i64 noundef, ptr noundef, ptr noundef) local_unnamed_addr #3

declare noundef ptr @_ZN3rml11pool_mallocEPNS_10MemoryPoolEm(ptr noundef, i64 noundef) local_unnamed_addr #3

declare noundef zeroext i1 @_ZN3rml9pool_freeEPNS_10MemoryPoolEPv(ptr noundef, ptr noundef) local_unnamed_addr #3

; Function Attrs: mustprogress nounwind uwtable
declare hidden noundef ptr @_ZL12getMemMalloclRm(i64 noundef, ptr noundef nonnull align 8 dereferenceable(8)) #2

; Function Attrs: mustprogress nounwind uwtable
declare hidden noundef i32 @_ZL10putMemFreelPvm(i64 noundef, ptr noundef, i64 noundef) #2

; Function Attrs: mustprogress uwtable
define dso_local noundef ptr @_Z16CreateUsablePoolm(i64 noundef %0) local_unnamed_addr #1 {
  %2 = alloca ptr, align 8
  %3 = alloca %"struct.rml::MemPoolPolicy", align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %2) #4
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %3) #4
  call void @_ZN3rml13MemPoolPolicyC2EPFPvlRmEPFilS1_mEmbb(ptr noundef nonnull align 8 dereferenceable(32) %3, ptr noundef nonnull @_ZL12getMemMalloclRm, ptr noundef nonnull @_ZL10putMemFreelPvm, i64 noundef 0, i1 noundef zeroext false, i1 noundef zeroext false)
  store i64 0, ptr @_ZL16getMemSuccessful, align 8, !tbaa !5
  store i64 0, ptr @_ZL9getMemAll, align 8, !tbaa !5
  store i64 0, ptr @_ZL9putMemAll, align 8, !tbaa !5
  %4 = call noundef i32 @_ZN3rml14pool_create_v1ElPKNS_13MemPoolPolicyEPPNS_10MemoryPoolE(i64 noundef 0, ptr noundef nonnull %3, ptr noundef nonnull %2)
  %.not = icmp eq i32 %4, 0
  br i1 %.not, label %11, label %5

5:                                                ; preds = %1
  %6 = load i64, ptr @_ZL9getMemAll, align 8, !tbaa !5
  %7 = icmp ne i64 %6, 0
  %8 = load i64, ptr @_ZL9putMemAll, align 8
  %9 = icmp ne i64 %8, 0
  %or.cond = select i1 %7, i1 true, i1 %9
  br i1 %or.cond, label %10, label %32

10:                                               ; preds = %5
  call void @_Z11ReportErrorPKciS0_S0_(ptr noundef nonnull @.str.20, i32 noundef 628, ptr noundef nonnull @.str.58, ptr noundef nonnull @.str.59)
  br label %32

11:                                               ; preds = %1
  %12 = load ptr, ptr %2, align 8, !tbaa !9
  %13 = call noundef ptr @_ZN3rml11pool_mallocEPNS_10MemoryPoolEm(ptr noundef %12, i64 noundef %0)
  %14 = load i64, ptr @_ZL16getMemSuccessful, align 8
  %.not9 = icmp eq i64 %14, 0
  %.not10 = icmp eq ptr %13, null
  br i1 %.not9, label %15, label %17

15:                                               ; preds = %11
  br i1 %.not10, label %32, label %16

16:                                               ; preds = %15
  call void @_Z11ReportErrorPKciS0_S0_(ptr noundef nonnull @.str.20, i32 noundef 634, ptr noundef nonnull @.str.60, ptr noundef nonnull @.str.61)
  br label %32

17:                                               ; preds = %11
  br i1 %.not10, label %18, label %19

18:                                               ; preds = %17
  call void @_Z11ReportErrorPKciS0_S0_(ptr noundef nonnull @.str.20, i32 noundef 637, ptr noundef nonnull @.str.62, ptr noundef nonnull @.str.63)
  %.pre = load i64, ptr @_ZL16getMemSuccessful, align 8
  br label %19

19:                                               ; preds = %17, %18
  %20 = phi i64 [ %14, %17 ], [ %.pre, %18 ]
  %21 = and i64 %20, -5
  %or.cond3 = icmp eq i64 %21, 1
  %22 = load i64, ptr @_ZL9getMemAll, align 8
  %23 = icmp ugt i64 %22, %20
  %or.cond14 = select i1 %or.cond3, i1 true, i1 %23
  br i1 %or.cond14, label %25, label %24

24:                                               ; preds = %19
  call void @_Z11ReportErrorPKciS0_S0_(ptr noundef nonnull @.str.20, i32 noundef 639, ptr noundef nonnull @.str.64, ptr noundef nonnull @.str.65)
  br label %25

25:                                               ; preds = %19, %24
  %26 = load i64, ptr @_ZL9putMemAll, align 8, !tbaa !5
  %.not12 = icmp eq i64 %26, 0
  br i1 %.not12, label %28, label %27

27:                                               ; preds = %25
  call void @_Z11ReportErrorPKciS0_S0_(ptr noundef nonnull @.str.20, i32 noundef 640, ptr noundef nonnull @.str.44, ptr noundef null)
  br label %28

28:                                               ; preds = %25, %27
  %29 = load ptr, ptr %2, align 8, !tbaa !9
  %30 = call noundef zeroext i1 @_ZN3rml9pool_freeEPNS_10MemoryPoolEPv(ptr noundef %29, ptr noundef %13)
  %31 = load ptr, ptr %2, align 8, !tbaa !9
  br label %32

32:                                               ; preds = %28, %15, %16, %10, %5
  %.1 = phi ptr [ null, %5 ], [ null, %10 ], [ %31, %28 ], [ null, %15 ], [ null, %16 ]
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %3) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #4
  ret ptr %.1
}

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 = { 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 = { "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 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,SROAPass,SimplifyCFGPass