; LLVM IR from opset/openset :: lib/heapstack/heapstack.ll (ZN9HeapStack8newBlockEv)

; 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.HeapStack::block_s" = type <{ ptr, i64, i8, [1 x i8] }>
%class.HeapStack = type { i64, i64, i64, i64, i64, ptr, ptr }

; Function Attrs: mustprogress uwtable
declare dso_local noundef nonnull align 8 dereferenceable(33) ptr @_ZN18HeapStackBlockPool7getPoolEv() #0 align 2

; 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 void @_ZN9HeapStack8newBlockEv(ptr noundef nonnull align 8 dereferenceable(56) %0) #0 align 2 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  %4 = load ptr, ptr %2, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #3
  %5 = call noundef nonnull align 8 dereferenceable(33) ptr @_ZN18HeapStackBlockPool7getPoolEv()
  %6 = call noundef ptr @_ZN18HeapStackBlockPool3GetEv(ptr noundef nonnull align 8 dereferenceable(33) %5)
  store ptr %6, ptr %3, align 8, !tbaa !5
  %7 = load ptr, ptr %3, align 8, !tbaa !5
  %8 = getelementptr inbounds %"struct.HeapStack::block_s", ptr %7, i32 0, i32 0
  store ptr null, ptr %8, align 1, !tbaa !9
  %9 = load ptr, ptr %3, align 8, !tbaa !5
  %10 = getelementptr inbounds %"struct.HeapStack::block_s", ptr %9, i32 0, i32 1
  store i64 0, ptr %10, align 1, !tbaa !13
  %11 = load ptr, ptr %3, align 8, !tbaa !5
  %12 = getelementptr inbounds %"struct.HeapStack::block_s", ptr %11, i32 0, i32 2
  store i8 0, ptr %12, align 1, !tbaa !14
  %13 = getelementptr inbounds %class.HeapStack, ptr %4, i32 0, i32 3
  %14 = load i64, ptr %13, align 8, !tbaa !15
  %15 = add nsw i64 %14, 1
  store i64 %15, ptr %13, align 8, !tbaa !15
  %16 = getelementptr inbounds %class.HeapStack, ptr %4, i32 0, i32 6
  %17 = load ptr, ptr %16, align 8, !tbaa !17
  %18 = icmp ne ptr %17, null
  br i1 %18, label %19, label %24

19:                                               ; preds = %1
  %20 = load ptr, ptr %3, align 8, !tbaa !5
  %21 = getelementptr inbounds %class.HeapStack, ptr %4, i32 0, i32 6
  %22 = load ptr, ptr %21, align 8, !tbaa !17
  %23 = getelementptr inbounds %"struct.HeapStack::block_s", ptr %22, i32 0, i32 0
  store ptr %20, ptr %23, align 1, !tbaa !9
  br label %24

24:                                               ; preds = %19, %1
  %25 = getelementptr inbounds %class.HeapStack, ptr %4, i32 0, i32 5
  %26 = load ptr, ptr %25, align 8, !tbaa !18
  %27 = icmp ne ptr %26, null
  br i1 %27, label %31, label %28

28:                                               ; preds = %24
  %29 = load ptr, ptr %3, align 8, !tbaa !5
  %30 = getelementptr inbounds %class.HeapStack, ptr %4, i32 0, i32 5
  store ptr %29, ptr %30, align 8, !tbaa !18
  br label %31

31:                                               ; preds = %28, %24
  %32 = load ptr, ptr %3, align 8, !tbaa !5
  %33 = getelementptr inbounds %class.HeapStack, ptr %4, i32 0, i32 6
  store ptr %32, ptr %33, align 8, !tbaa !17
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  ret void
}

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef ptr @_ZN18HeapStackBlockPool3GetEv(ptr noundef nonnull align 8 dereferenceable(33)) #2 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 = { inlinehint 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 #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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !6, i64 0}
!10 = !{!"_ZTSN9HeapStack7block_sE", !6, i64 0, !11, i64 8, !12, i64 16, !7, i64 17}
!11 = !{!"long", !7, i64 0}
!12 = !{!"bool", !7, i64 0}
!13 = !{!10, !11, i64 8}
!14 = !{!10, !12, i64 16}
!15 = !{!16, !11, i64 24}
!16 = !{!"_ZTS9HeapStack", !11, i64 0, !11, i64 8, !11, i64 16, !11, i64 24, !11, i64 32, !6, i64 40, !6, i64 48}
!17 = !{!16, !6, i64 48}
!18 = !{!16, !6, i64 40}


; 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 nonnull align 8 dereferenceable(33) ptr @_ZN18HeapStackBlockPool7getPoolEv() local_unnamed_addr #0 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN9HeapStack8newBlockEv(ptr nocapture noundef nonnull align 8 dereferenceable(56) %0) local_unnamed_addr #0 align 2 {
  %2 = tail call noundef nonnull align 8 dereferenceable(33) ptr @_ZN18HeapStackBlockPool7getPoolEv()
  %3 = tail call noundef ptr @_ZN18HeapStackBlockPool3GetEv(ptr noundef nonnull align 8 dereferenceable(33) %2)
  %4 = getelementptr inbounds i8, ptr %0, i64 24
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 1 dereferenceable(17) %3, i8 0, i64 17, i1 false)
  %5 = load i64, ptr %4, align 8, !tbaa !5
  %6 = add nsw i64 %5, 1
  store i64 %6, ptr %4, align 8, !tbaa !5
  %7 = getelementptr inbounds i8, ptr %0, i64 48
  %8 = load ptr, ptr %7, align 8, !tbaa !11
  %.not = icmp eq ptr %8, null
  br i1 %.not, label %10, label %9

9:                                                ; preds = %1
  store ptr %3, ptr %8, align 1, !tbaa !12
  br label %10

10:                                               ; preds = %9, %1
  %11 = getelementptr inbounds i8, ptr %0, i64 40
  %12 = load ptr, ptr %11, align 8, !tbaa !15
  %.not7 = icmp eq ptr %12, null
  br i1 %.not7, label %13, label %14

13:                                               ; preds = %10
  store ptr %3, ptr %11, align 8, !tbaa !15
  br label %14

14:                                               ; preds = %13, %10
  store ptr %3, ptr %7, align 8, !tbaa !11
  ret void
}

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef ptr @_ZN18HeapStackBlockPool3GetEv(ptr noundef nonnull align 8 dereferenceable(33)) local_unnamed_addr #1 align 2

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #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 = { inlinehint 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 = { nocallback nofree nounwind willreturn memory(argmem: write) }

!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, !7, i64 24}
!6 = !{!"_ZTS9HeapStack", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !7, i64 32, !10, i64 40, !10, i64 48}
!7 = !{!"long", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!6, !10, i64 48}
!12 = !{!13, !10, i64 0}
!13 = !{!"_ZTSN9HeapStack7block_sE", !10, i64 0, !7, i64 8, !14, i64 16, !8, i64 17}
!14 = !{!"bool", !8, i64 0}
!15 = !{!6, !10, i64 40}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,MemCpyOptPass,PostOrderFunctionAttrsPass,SROAPass,TailCallElimPass