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

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

24:                                               ; preds = %2
  %25 = load ptr, ptr %5, align 8, !tbaa !5
  %26 = getelementptr inbounds %class.HeapStack, ptr %6, i32 0, i32 6
  %27 = load ptr, ptr %26, align 8, !tbaa !19
  %28 = getelementptr inbounds %"struct.HeapStack::block_s", ptr %27, i32 0, i32 0
  store ptr %25, ptr %28, align 1, !tbaa !13
  br label %29

29:                                               ; preds = %24, %2
  %30 = getelementptr inbounds %class.HeapStack, ptr %6, i32 0, i32 5
  %31 = load ptr, ptr %30, align 8, !tbaa !20
  %32 = icmp ne ptr %31, null
  br i1 %32, label %36, label %33

33:                                               ; preds = %29
  %34 = load ptr, ptr %5, align 8, !tbaa !5
  %35 = getelementptr inbounds %class.HeapStack, ptr %6, i32 0, i32 5
  store ptr %34, ptr %35, align 8, !tbaa !20
  br label %36

36:                                               ; preds = %33, %29
  %37 = load ptr, ptr %5, align 8, !tbaa !5
  %38 = getelementptr inbounds %class.HeapStack, ptr %6, i32 0, i32 6
  store ptr %37, ptr %38, align 8, !tbaa !19
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  ret void
}

; Function Attrs: nobuiltin allocsize(0)
declare noundef nonnull ptr @_Znam(i64 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 = { nobuiltin allocsize(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 }
attributes #4 = { builtin allocsize(0) }

!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, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!12, !10, i64 0}
!12 = !{!"_ZTS9HeapStack", !10, i64 0, !10, i64 8, !10, i64 16, !10, i64 24, !10, i64 32, !6, i64 40, !6, i64 48}
!13 = !{!14, !6, i64 0}
!14 = !{!"_ZTSN9HeapStack7block_sE", !6, i64 0, !10, i64 8, !15, i64 16, !7, i64 17}
!15 = !{!"bool", !7, i64 0}
!16 = !{!14, !10, i64 8}
!17 = !{!14, !15, i64 16}
!18 = !{!12, !10, i64 24}
!19 = !{!12, !6, i64 48}
!20 = !{!12, !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
define dso_local void @_ZN9HeapStack17newNonpooledBlockEl(ptr nocapture noundef nonnull align 8 dereferenceable(56) %0, i64 noundef %1) local_unnamed_addr #0 align 2 {
  %3 = load i64, ptr %0, align 8, !tbaa !5
  %4 = add nsw i64 %3, %1
  %5 = tail call noalias noundef nonnull ptr @_Znam(i64 noundef %4) #3
  %6 = getelementptr inbounds i8, ptr %5, i64 16
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 1 dereferenceable(16) %5, i8 0, i64 16, i1 false)
  store i8 1, ptr %6, align 1, !tbaa !11
  %7 = getelementptr inbounds i8, ptr %0, i64 24
  %8 = load i64, ptr %7, align 8, !tbaa !14
  %9 = add nsw i64 %8, 1
  store i64 %9, ptr %7, align 8, !tbaa !14
  %10 = getelementptr inbounds i8, ptr %0, i64 48
  %11 = load ptr, ptr %10, align 8, !tbaa !15
  %.not = icmp eq ptr %11, null
  br i1 %.not, label %13, label %12

12:                                               ; preds = %2
  store ptr %5, ptr %11, align 1, !tbaa !16
  br label %13

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

16:                                               ; preds = %13
  store ptr %5, ptr %14, align 8, !tbaa !17
  br label %17

17:                                               ; preds = %16, %13
  store ptr %5, ptr %10, align 8, !tbaa !15
  ret void
}

; Function Attrs: nobuiltin allocsize(0)
declare noundef nonnull ptr @_Znam(i64 noundef) local_unnamed_addr #1

; 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 = { nobuiltin allocsize(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) }
attributes #3 = { builtin allocsize(0) }

!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 0}
!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, !13, i64 16}
!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, !10, i64 48}
!16 = !{!12, !10, i64 0}
!17 = !{!6, !10, i64 40}


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