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

; 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.17 = external hidden unnamed_addr constant [104 x i8], align 1
@.str.18 = external hidden unnamed_addr constant [9 x i8], align 1
@.str.19 = external hidden unnamed_addr constant [46 x i8], align 1
@_ZTISt9bad_alloc = external constant ptr
@.str.20 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.21 = external hidden unnamed_addr constant [56 x i8], align 1
@.str.22 = external hidden unnamed_addr constant [17 x i8], align 1
@.str.23 = external hidden unnamed_addr constant [37 x i8], align 1
@.str.24 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.25 = external hidden unnamed_addr constant [63 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 uwtable
define dso_local void @_Z24Test_NFS_Allocate_Throwsv() #1 personality ptr @__gxx_personality_v0 {
  %1 = alloca i64, align 8
  %2 = alloca i64, align 8
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i8, align 1
  %7 = alloca ptr, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %1) #5
  store i64 1024, ptr %1, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #5
  store i64 1024, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #5
  store ptr null, ptr %3, align 8, !tbaa !9
  %8 = invoke noundef ptr @_ZN3tbb8internal12NFS_AllocateEmmPv(i64 noundef 1024, i64 noundef 1024, ptr noundef null)
          to label %9 unwind label %10

9:                                                ; preds = %0
  store ptr %8, ptr %3, align 8, !tbaa !9
  br label %17

10:                                               ; preds = %0
  %11 = landingpad { ptr, i32 }
          catch ptr null
  %12 = extractvalue { ptr, i32 } %11, 0
  store ptr %12, ptr %4, align 8
  %13 = extractvalue { ptr, i32 } %11, 1
  store i32 %13, ptr %5, align 4
  br label %14

14:                                               ; preds = %10
  %15 = load ptr, ptr %4, align 8
  %16 = call ptr @__cxa_begin_catch(ptr %15) #5
  call void @__cxa_end_catch()
  br label %17

17:                                               ; preds = %14, %9
  %18 = load ptr, ptr %3, align 8, !tbaa !9
  %19 = icmp ne ptr %18, null
  br i1 %19, label %20, label %21

20:                                               ; preds = %17
  br label %22

21:                                               ; preds = %17
  call void @_Z11ReportErrorPKciS0_S0_(ptr noundef @.str.17, i32 noundef 47, ptr noundef @.str.18, ptr noundef @.str.19)
  br label %22

22:                                               ; preds = %21, %20
  call void @llvm.lifetime.start.p0(i64 1, ptr %6) #5
  store i8 0, ptr %6, align 1, !tbaa !11
  %23 = invoke noundef i64 @_ZN3tbb8internal15NFS_GetLineSizeEv()
          to label %24 unwind label %28

24:                                               ; preds = %22
  %25 = add i64 -1048577, %23
  %26 = invoke noundef ptr @_ZN3tbb8internal12NFS_AllocateEmmPv(i64 noundef 1, i64 noundef %25, ptr noundef null)
          to label %27 unwind label %28

27:                                               ; preds = %24
  br label %39

28:                                               ; preds = %24, %22
  %29 = landingpad { ptr, i32 }
          catch ptr @_ZTISt9bad_alloc
          catch ptr null
  %30 = extractvalue { ptr, i32 } %29, 0
  store ptr %30, ptr %4, align 8
  %31 = extractvalue { ptr, i32 } %29, 1
  store i32 %31, ptr %5, align 4
  br label %32

32:                                               ; preds = %28
  %33 = load i32, ptr %5, align 4
  %34 = call i32 @llvm.eh.typeid.for.p0(ptr @_ZTISt9bad_alloc) #5
  %35 = icmp eq i32 %33, %34
  br i1 %35, label %36, label %47

36:                                               ; preds = %32
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #5
  %37 = load ptr, ptr %4, align 8
  %38 = call ptr @__cxa_begin_catch(ptr %37) #5
  store ptr %38, ptr %7, align 8
  store i8 1, ptr %6, align 1, !tbaa !11
  call void @__cxa_end_catch()
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #5
  br label %39

39:                                               ; preds = %50, %36, %27
  %40 = load i8, ptr %6, align 1, !tbaa !11, !range !13, !noundef !14
  %41 = trunc i8 %40 to i1
  br i1 %41, label %42, label %43

42:                                               ; preds = %39
  br label %44

43:                                               ; preds = %39
  call void @_Z11ReportErrorPKciS0_S0_(ptr noundef @.str.17, i32 noundef 59, ptr noundef @.str.22, ptr noundef @.str.23)
  br label %44

44:                                               ; preds = %43, %42
  %45 = load ptr, ptr %3, align 8, !tbaa !9
  invoke void @_ZN3tbb8internal8NFS_FreeEPv(ptr noundef %45)
          to label %46 unwind label %56

46:                                               ; preds = %44
  br label %64

47:                                               ; preds = %32
  %48 = load ptr, ptr %4, align 8
  %49 = call ptr @__cxa_begin_catch(ptr %48) #5
  invoke void @_Z11ReportErrorPKciS0_S0_(ptr noundef @.str.17, i32 noundef 56, ptr noundef @.str.20, ptr noundef @.str.21)
          to label %50 unwind label %51

50:                                               ; preds = %47
  store i8 1, ptr %6, align 1, !tbaa !11
  call void @__cxa_end_catch()
  br label %39

51:                                               ; preds = %47
  %52 = landingpad { ptr, i32 }
          cleanup
  %53 = extractvalue { ptr, i32 } %52, 0
  store ptr %53, ptr %4, align 8
  %54 = extractvalue { ptr, i32 } %52, 1
  store i32 %54, ptr %5, align 4
  invoke void @__cxa_end_catch()
          to label %55 unwind label %76

55:                                               ; preds = %51
  br label %70

56:                                               ; preds = %44
  %57 = landingpad { ptr, i32 }
          catch ptr null
  %58 = extractvalue { ptr, i32 } %57, 0
  store ptr %58, ptr %4, align 8
  %59 = extractvalue { ptr, i32 } %57, 1
  store i32 %59, ptr %5, align 4
  br label %60

60:                                               ; preds = %56
  %61 = load ptr, ptr %4, align 8
  %62 = call ptr @__cxa_begin_catch(ptr %61) #5
  invoke void @_Z11ReportErrorPKciS0_S0_(ptr noundef @.str.17, i32 noundef 64, ptr noundef @.str.24, ptr noundef @.str.25)
          to label %63 unwind label %65

63:                                               ; preds = %60
  call void @__cxa_end_catch()
  br label %64

64:                                               ; preds = %63, %46
  call void @llvm.lifetime.end.p0(i64 1, ptr %6) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %1) #5
  ret void

65:                                               ; preds = %60
  %66 = landingpad { ptr, i32 }
          cleanup
  %67 = extractvalue { ptr, i32 } %66, 0
  store ptr %67, ptr %4, align 8
  %68 = extractvalue { ptr, i32 } %66, 1
  store i32 %68, ptr %5, align 4
  invoke void @__cxa_end_catch()
          to label %69 unwind label %76

69:                                               ; preds = %65
  br label %70

70:                                               ; preds = %69, %55
  call void @llvm.lifetime.end.p0(i64 1, ptr %6) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %1) #5
  br label %71

71:                                               ; preds = %70
  %72 = load ptr, ptr %4, align 8
  %73 = load i32, ptr %5, align 4
  %74 = insertvalue { ptr, i32 } poison, ptr %72, 0
  %75 = insertvalue { ptr, i32 } %74, i32 %73, 1
  resume { ptr, i32 } %75

76:                                               ; preds = %65, %51
  %77 = landingpad { ptr, i32 }
          catch ptr null
  %78 = extractvalue { ptr, i32 } %77, 0
  call void @__clang_call_terminate(ptr %78) #6
  unreachable
}

declare noundef ptr @_ZN3tbb8internal12NFS_AllocateEmmPv(i64 noundef, i64 noundef, ptr noundef) #2

declare i32 @__gxx_personality_v0(...)

declare ptr @__cxa_begin_catch(ptr)

declare void @__cxa_end_catch()

declare noundef i64 @_ZN3tbb8internal15NFS_GetLineSizeEv() #2

; Function Attrs: nounwind memory(none)
declare i32 @llvm.eh.typeid.for.p0(ptr) #3

; Function Attrs: noinline noreturn nounwind uwtable
declare hidden void @__clang_call_terminate(ptr noundef) #4

declare void @_ZN3tbb8internal8NFS_FreeEPv(ptr noundef) #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 = { "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 memory(none) }
attributes #4 = { noinline noreturn nounwind uwtable "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 #5 = { nounwind }
attributes #6 = { noreturn 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}
!11 = !{!12, !12, i64 0}
!12 = !{!"bool", !7, i64 0}
!13 = !{i8 0, i8 2}
!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.17 = external hidden unnamed_addr constant [104 x i8], align 1
@.str.18 = external hidden unnamed_addr constant [9 x i8], align 1
@.str.19 = external hidden unnamed_addr constant [46 x i8], align 1
@_ZTISt9bad_alloc = external constant ptr
@.str.20 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.21 = external hidden unnamed_addr constant [56 x i8], align 1
@.str.22 = external hidden unnamed_addr constant [17 x i8], align 1
@.str.23 = external hidden unnamed_addr constant [37 x i8], align 1
@.str.24 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.25 = external hidden unnamed_addr constant [63 x i8], align 1

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z11ReportErrorPKciS0_S0_(ptr noundef, i32 noundef, ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
define dso_local void @_Z24Test_NFS_Allocate_Throwsv() local_unnamed_addr #0 personality ptr @__gxx_personality_v0 {
  %1 = invoke noundef ptr @_ZN3tbb8internal12NFS_AllocateEmmPv(i64 noundef 1024, i64 noundef 1024, ptr noundef null)
          to label %5 unwind label %.thread

.thread:                                          ; preds = %0
  %2 = landingpad { ptr, i32 }
          catch ptr null
  %3 = extractvalue { ptr, i32 } %2, 0
  %4 = tail call ptr @__cxa_begin_catch(ptr %3) #4
  tail call void @__cxa_end_catch()
  br label %6

5:                                                ; preds = %0
  %.not = icmp eq ptr %1, null
  br i1 %.not, label %6, label %7

6:                                                ; preds = %.thread, %5
  tail call void @_Z11ReportErrorPKciS0_S0_(ptr noundef nonnull @.str.17, i32 noundef 47, ptr noundef nonnull @.str.18, ptr noundef nonnull @.str.19)
  br label %7

7:                                                ; preds = %5, %6
  %.015 = phi ptr [ %1, %5 ], [ null, %6 ]
  %8 = invoke noundef i64 @_ZN3tbb8internal15NFS_GetLineSizeEv()
          to label %9 unwind label %12

9:                                                ; preds = %7
  %10 = add i64 %8, -1048577
  %11 = invoke noundef ptr @_ZN3tbb8internal12NFS_AllocateEmmPv(i64 noundef 1, i64 noundef %10, ptr noundef null)
          to label %.critedge unwind label %12

12:                                               ; preds = %9, %7
  %13 = landingpad { ptr, i32 }
          catch ptr @_ZTISt9bad_alloc
          catch ptr null
  %14 = extractvalue { ptr, i32 } %13, 0
  %15 = extractvalue { ptr, i32 } %13, 1
  %16 = tail call i32 @llvm.eh.typeid.for.p0(ptr nonnull @_ZTISt9bad_alloc) #4
  %17 = icmp eq i32 %15, %16
  %18 = tail call ptr @__cxa_begin_catch(ptr %14) #4
  br i1 %17, label %19, label %21

19:                                               ; preds = %12
  tail call void @__cxa_end_catch()
  br label %20

.critedge:                                        ; preds = %9
  tail call void @_Z11ReportErrorPKciS0_S0_(ptr noundef nonnull @.str.17, i32 noundef 59, ptr noundef nonnull @.str.22, ptr noundef nonnull @.str.23)
  br label %20

20:                                               ; preds = %19, %22, %.critedge
  invoke void @_ZN3tbb8internal8NFS_FreeEPv(ptr noundef %.015)
          to label %30 unwind label %25

21:                                               ; preds = %12
  invoke void @_Z11ReportErrorPKciS0_S0_(ptr noundef nonnull @.str.17, i32 noundef 56, ptr noundef nonnull @.str.20, ptr noundef nonnull @.str.21)
          to label %22 unwind label %23

22:                                               ; preds = %21
  tail call void @__cxa_end_catch()
  br label %20

23:                                               ; preds = %21
  %24 = landingpad { ptr, i32 }
          cleanup
  invoke void @__cxa_end_catch()
          to label %33 unwind label %34

25:                                               ; preds = %20
  %26 = landingpad { ptr, i32 }
          catch ptr null
  %27 = extractvalue { ptr, i32 } %26, 0
  %28 = tail call ptr @__cxa_begin_catch(ptr %27) #4
  invoke void @_Z11ReportErrorPKciS0_S0_(ptr noundef nonnull @.str.17, i32 noundef 64, ptr noundef nonnull @.str.24, ptr noundef nonnull @.str.25)
          to label %29 unwind label %31

29:                                               ; preds = %25
  tail call void @__cxa_end_catch()
  br label %30

30:                                               ; preds = %20, %29
  ret void

31:                                               ; preds = %25
  %32 = landingpad { ptr, i32 }
          cleanup
  invoke void @__cxa_end_catch()
          to label %33 unwind label %34

33:                                               ; preds = %31, %23
  %.pn = phi { ptr, i32 } [ %32, %31 ], [ %24, %23 ]
  resume { ptr, i32 } %.pn

34:                                               ; preds = %31, %23
  %35 = landingpad { ptr, i32 }
          catch ptr null
  %36 = extractvalue { ptr, i32 } %35, 0
  tail call void @__clang_call_terminate(ptr %36) #5
  unreachable
}

declare noundef ptr @_ZN3tbb8internal12NFS_AllocateEmmPv(i64 noundef, i64 noundef, ptr noundef) local_unnamed_addr #1

declare i32 @__gxx_personality_v0(...)

declare ptr @__cxa_begin_catch(ptr) local_unnamed_addr

declare void @__cxa_end_catch() local_unnamed_addr

declare noundef i64 @_ZN3tbb8internal15NFS_GetLineSizeEv() local_unnamed_addr #1

; Function Attrs: nofree nosync nounwind memory(none)
declare i32 @llvm.eh.typeid.for.p0(ptr) #2

; Function Attrs: noinline noreturn nounwind uwtable
declare hidden void @__clang_call_terminate(ptr noundef) local_unnamed_addr #3

declare void @_ZN3tbb8internal8NFS_FreeEPv(ptr noundef) local_unnamed_addr #1

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 = { "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 = { nofree nosync nounwind memory(none) }
attributes #3 = { noinline noreturn nounwind uwtable "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 }
attributes #5 = { noreturn 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)"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,SROAPass,SimplifyCFGPass,TailCallElimPass