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

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

%class.HeapStack = type { i64, i64, i64, i64, i64, ptr, ptr }
%"struct.HeapStack::block_s" = type <{ ptr, i64, i8, [1 x i8] }>

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN9HeapStack7ReleaseEv(ptr noundef nonnull align 8 dereferenceable(56) %0) #0 align 2 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  %5 = load ptr, ptr %2, align 8
  %6 = getelementptr inbounds %class.HeapStack, ptr %5, i32 0, i32 5
  %7 = load ptr, ptr %6, align 8, !tbaa !9
  %8 = icmp ne ptr %7, null
  br i1 %8, label %9, label %39

9:                                                ; preds = %1
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #4
  %10 = getelementptr inbounds %class.HeapStack, ptr %5, i32 0, i32 5
  %11 = load ptr, ptr %10, align 8, !tbaa !9
  %12 = getelementptr inbounds %"struct.HeapStack::block_s", ptr %11, i32 0, i32 0
  %13 = load ptr, ptr %12, align 1, !tbaa !12
  store ptr %13, ptr %3, align 8, !tbaa !5
  br label %14

14:                                               ; preds = %36, %9
  %15 = load ptr, ptr %3, align 8, !tbaa !5
  %16 = icmp ne ptr %15, null
  br i1 %16, label %17, label %38

17:                                               ; preds = %14
  %18 = getelementptr inbounds %class.HeapStack, ptr %5, i32 0, i32 3
  %19 = load i64, ptr %18, align 8, !tbaa !15
  %20 = add nsw i64 %19, -1
  store i64 %20, ptr %18, align 8, !tbaa !15
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #4
  %21 = load ptr, ptr %3, align 8, !tbaa !5
  %22 = getelementptr inbounds %"struct.HeapStack::block_s", ptr %21, i32 0, i32 0
  %23 = load ptr, ptr %22, align 1, !tbaa !12
  store ptr %23, ptr %4, align 8, !tbaa !5
  %24 = load ptr, ptr %3, align 8, !tbaa !5
  %25 = getelementptr inbounds %"struct.HeapStack::block_s", ptr %24, i32 0, i32 2
  %26 = load i8, ptr %25, align 1, !tbaa !16, !range !17, !noundef !18
  %27 = trunc i8 %26 to i1
  br i1 %27, label %28, label %33

28:                                               ; preds = %17
  %29 = load ptr, ptr %3, align 8, !tbaa !5
  %30 = icmp eq ptr %29, null
  br i1 %30, label %32, label %31

31:                                               ; preds = %28
  call void @_ZdaPv(ptr noundef %29) #5
  br label %32

32:                                               ; preds = %31, %28
  br label %36

33:                                               ; preds = %17
  %34 = call noundef nonnull align 8 dereferenceable(33) ptr @_ZN18HeapStackBlockPool7getPoolEv()
  %35 = load ptr, ptr %3, align 8, !tbaa !5
  call void @_ZN18HeapStackBlockPool3PutEPv(ptr noundef nonnull align 8 dereferenceable(33) %34, ptr noundef %35)
  br label %36

36:                                               ; preds = %33, %32
  %37 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %37, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #4
  br label %14, !llvm.loop !19

38:                                               ; preds = %14
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #4
  br label %39

39:                                               ; preds = %38, %1
  %40 = getelementptr inbounds %class.HeapStack, ptr %5, i32 0, i32 5
  %41 = load ptr, ptr %40, align 8, !tbaa !9
  %42 = icmp ne ptr %41, null
  %43 = zext i1 %42 to i64
  %44 = select i1 %42, i32 1, i32 0
  %45 = sext i32 %44 to i64
  %46 = getelementptr inbounds %class.HeapStack, ptr %5, i32 0, i32 3
  store i64 %45, ptr %46, align 8, !tbaa !15
  %47 = getelementptr inbounds %class.HeapStack, ptr %5, i32 0, i32 4
  store i64 0, ptr %47, align 8, !tbaa !21
  %48 = getelementptr inbounds %class.HeapStack, ptr %5, i32 0, i32 5
  %49 = load ptr, ptr %48, align 8, !tbaa !9
  %50 = icmp ne ptr %49, null
  br i1 %50, label %54, label %51

51:                                               ; preds = %39
  %52 = getelementptr inbounds %class.HeapStack, ptr %5, i32 0, i32 5
  store ptr null, ptr %52, align 8, !tbaa !9
  %53 = getelementptr inbounds %class.HeapStack, ptr %5, i32 0, i32 6
  store ptr null, ptr %53, align 8, !tbaa !22
  br label %64

54:                                               ; preds = %39
  %55 = getelementptr inbounds %class.HeapStack, ptr %5, i32 0, i32 5
  %56 = load ptr, ptr %55, align 8, !tbaa !9
  %57 = getelementptr inbounds %"struct.HeapStack::block_s", ptr %56, i32 0, i32 1
  store i64 0, ptr %57, align 1, !tbaa !23
  %58 = getelementptr inbounds %class.HeapStack, ptr %5, i32 0, i32 5
  %59 = load ptr, ptr %58, align 8, !tbaa !9
  %60 = getelementptr inbounds %"struct.HeapStack::block_s", ptr %59, i32 0, i32 0
  store ptr null, ptr %60, align 1, !tbaa !12
  %61 = getelementptr inbounds %class.HeapStack, ptr %5, i32 0, i32 5
  %62 = load ptr, ptr %61, align 8, !tbaa !9
  %63 = getelementptr inbounds %class.HeapStack, ptr %5, i32 0, i32 6
  store ptr %62, ptr %63, align 8, !tbaa !22
  br label %64

64:                                               ; preds = %54, %51
  ret void
}

; Function Attrs: nobuiltin nounwind
declare void @_ZdaPv(ptr noundef) #1

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

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZN18HeapStackBlockPool3PutEPv(ptr noundef nonnull align 8 dereferenceable(33), ptr noundef) #2 align 2

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #3

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #3

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 = { nobuiltin nounwind "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 = { 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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { nounwind }
attributes #5 = { builtin 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 40}
!10 = !{!"_ZTS9HeapStack", !11, i64 0, !11, i64 8, !11, i64 16, !11, i64 24, !11, i64 32, !6, i64 40, !6, i64 48}
!11 = !{!"long", !7, i64 0}
!12 = !{!13, !6, i64 0}
!13 = !{!"_ZTSN9HeapStack7block_sE", !6, i64 0, !11, i64 8, !14, i64 16, !7, i64 17}
!14 = !{!"bool", !7, i64 0}
!15 = !{!10, !11, i64 24}
!16 = !{!13, !14, i64 16}
!17 = !{i8 0, i8 2}
!18 = !{}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}
!21 = !{!10, !11, i64 32}
!22 = !{!10, !6, i64 48}
!23 = !{!13, !11, i64 8}


; 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
define dso_local void @_ZN9HeapStack7ReleaseEv(ptr nocapture noundef nonnull align 8 dereferenceable(56) %0) local_unnamed_addr #0 align 2 {
  %2 = getelementptr inbounds i8, ptr %0, i64 40
  %3 = load ptr, ptr %2, align 8, !tbaa !5
  %.not = icmp eq ptr %3, null
  br i1 %.not, label %.thread, label %5

.thread:                                          ; preds = %1
  %4 = getelementptr inbounds i8, ptr %0, i64 24
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %4, i8 0, i64 16, i1 false)
  br label %22

5:                                                ; preds = %1
  %6 = load ptr, ptr %3, align 1, !tbaa !11
  %.not914 = icmp eq ptr %6, null
  %7 = getelementptr inbounds i8, ptr %0, i64 24
  br i1 %.not914, label %._crit_edge.thread, label %.lr.ph

._crit_edge.thread:                               ; preds = %5
  store i64 1, ptr %7, align 8, !tbaa !14
  %8 = getelementptr inbounds i8, ptr %0, i64 32
  store i64 0, ptr %8, align 8, !tbaa !15
  br label %23

.lr.ph:                                           ; preds = %5, %18
  %.015 = phi ptr [ %11, %18 ], [ %6, %5 ]
  %9 = load i64, ptr %7, align 8, !tbaa !14
  %10 = add nsw i64 %9, -1
  store i64 %10, ptr %7, align 8, !tbaa !14
  %11 = load ptr, ptr %.015, align 1, !tbaa !11
  %12 = getelementptr inbounds i8, ptr %.015, i64 16
  %13 = load i8, ptr %12, align 1, !tbaa !16, !range !17, !noundef !18
  %14 = trunc nuw i8 %13 to i1
  br i1 %14, label %15, label %16

15:                                               ; preds = %.lr.ph
  tail call void @_ZdaPv(ptr noundef nonnull %.015) #4
  br label %18

16:                                               ; preds = %.lr.ph
  %17 = tail call noundef nonnull align 8 dereferenceable(33) ptr @_ZN18HeapStackBlockPool7getPoolEv()
  tail call void @_ZN18HeapStackBlockPool3PutEPv(ptr noundef nonnull align 8 dereferenceable(33) %17, ptr noundef nonnull %.015)
  br label %18

18:                                               ; preds = %15, %16
  %.not9 = icmp eq ptr %11, null
  br i1 %.not9, label %._crit_edge, label %.lr.ph, !llvm.loop !19

._crit_edge:                                      ; preds = %18
  %.pr.pre = load ptr, ptr %2, align 8, !tbaa !5
  %.not10 = icmp ne ptr %.pr.pre, null
  %19 = zext i1 %.not10 to i64
  %20 = getelementptr inbounds i8, ptr %0, i64 24
  store i64 %19, ptr %20, align 8, !tbaa !14
  %21 = getelementptr inbounds i8, ptr %0, i64 32
  store i64 0, ptr %21, align 8, !tbaa !15
  %.not11 = icmp eq ptr %.pr.pre, null
  br i1 %.not11, label %22, label %23

22:                                               ; preds = %.thread, %._crit_edge
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %2, i8 0, i64 16, i1 false)
  br label %25

23:                                               ; preds = %._crit_edge.thread, %._crit_edge
  %.pr20 = phi ptr [ %3, %._crit_edge.thread ], [ %.pr.pre, %._crit_edge ]
  %24 = getelementptr inbounds i8, ptr %0, i64 48
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 1 dereferenceable(16) %.pr20, i8 0, i64 16, i1 false)
  store ptr %.pr20, ptr %24, align 8, !tbaa !21
  br label %25

25:                                               ; preds = %23, %22
  ret void
}

; Function Attrs: nobuiltin nounwind
declare void @_ZdaPv(ptr noundef) local_unnamed_addr #1

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

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #3

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 = { nobuiltin nounwind "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 = { 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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #4 = { builtin 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, !10, i64 40}
!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 = !{!12, !10, i64 0}
!12 = !{!"_ZTSN9HeapStack7block_sE", !10, i64 0, !7, i64 8, !13, i64 16, !8, i64 17}
!13 = !{!"bool", !8, i64 0}
!14 = !{!6, !7, i64 24}
!15 = !{!6, !7, i64 32}
!16 = !{!12, !13, i64 16}
!17 = !{i8 0, i8 2}
!18 = !{}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}
!21 = !{!6, !10, i64 48}


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