; LLVM IR from Sopiro/Muli :: src/util/stack_allocator.ll (ZN4muli14StackAllocator8AllocateEi)

; 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.muli::StackAllocator" = type <{ %"class.muli::Allocator", [102400 x i8], i32, i32, i32, [4 x i8], [32 x %"struct.muli::StackAllocator::StackEntry"], i32, [4 x i8] }>
%"class.muli::Allocator" = type { ptr }
%"struct.muli::StackAllocator::StackEntry" = type { ptr, i32, i8 }

@.str.1 = external hidden unnamed_addr constant [74 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [65 x i8], align 1
@__PRETTY_FUNCTION__._ZN4muli14StackAllocator8AllocateEi = external hidden unnamed_addr constant [52 x i8], align 1

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #0

; Function Attrs: mustprogress uwtable
define dso_local noundef ptr @_ZN4muli14StackAllocator8AllocateEi(ptr noundef nonnull align 8 dereferenceable(102940) %0, i32 noundef %1) unnamed_addr #1 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !9
  %6 = load ptr, ptr %3, align 8
  %7 = getelementptr inbounds %"class.muli::StackAllocator", ptr %6, i32 0, i32 7
  %8 = load i32, ptr %7, align 8, !tbaa !11
  %9 = icmp slt i32 %8, 32
  br i1 %9, label %10, label %11

10:                                               ; preds = %2
  br label %11

11:                                               ; preds = %10, %2
  %12 = phi i1 [ false, %2 ], [ true, %10 ]
  br i1 %12, label %13, label %14

13:                                               ; preds = %11
  br label %16

14:                                               ; preds = %11
  call void @__assert_fail(ptr noundef @.str.3, ptr noundef @.str.1, i32 noundef 21, ptr noundef @__PRETTY_FUNCTION__._ZN4muli14StackAllocator8AllocateEi) #4
  unreachable

15:                                               ; No predecessors!
  br label %16

16:                                               ; preds = %15, %13
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #5
  %17 = getelementptr inbounds %"class.muli::StackAllocator", ptr %6, i32 0, i32 6
  %18 = getelementptr inbounds [32 x %"struct.muli::StackAllocator::StackEntry"], ptr %17, i64 0, i64 0
  %19 = getelementptr inbounds %"class.muli::StackAllocator", ptr %6, i32 0, i32 7
  %20 = load i32, ptr %19, align 8, !tbaa !11
  %21 = sext i32 %20 to i64
  %22 = getelementptr inbounds %"struct.muli::StackAllocator::StackEntry", ptr %18, i64 %21
  store ptr %22, ptr %5, align 8, !tbaa !5
  %23 = load i32, ptr %4, align 4, !tbaa !9
  %24 = load ptr, ptr %5, align 8, !tbaa !5
  %25 = getelementptr inbounds %"struct.muli::StackAllocator::StackEntry", ptr %24, i32 0, i32 1
  store i32 %23, ptr %25, align 8, !tbaa !14
  %26 = getelementptr inbounds %"class.muli::StackAllocator", ptr %6, i32 0, i32 2
  %27 = load i32, ptr %26, align 8, !tbaa !17
  %28 = load i32, ptr %4, align 4, !tbaa !9
  %29 = add nsw i32 %27, %28
  %30 = icmp sgt i32 %29, 102400
  br i1 %30, label %31, label %38

31:                                               ; preds = %16
  %32 = load i32, ptr %4, align 4, !tbaa !9
  %33 = call noundef ptr @_ZN4muli5AllocEi(i32 noundef %32)
  %34 = load ptr, ptr %5, align 8, !tbaa !5
  %35 = getelementptr inbounds %"struct.muli::StackAllocator::StackEntry", ptr %34, i32 0, i32 0
  store ptr %33, ptr %35, align 8, !tbaa !18
  %36 = load ptr, ptr %5, align 8, !tbaa !5
  %37 = getelementptr inbounds %"struct.muli::StackAllocator::StackEntry", ptr %36, i32 0, i32 2
  store i8 1, ptr %37, align 4, !tbaa !19
  br label %53

38:                                               ; preds = %16
  %39 = getelementptr inbounds %"class.muli::StackAllocator", ptr %6, i32 0, i32 1
  %40 = getelementptr inbounds [102400 x i8], ptr %39, i64 0, i64 0
  %41 = getelementptr inbounds %"class.muli::StackAllocator", ptr %6, i32 0, i32 2
  %42 = load i32, ptr %41, align 8, !tbaa !17
  %43 = sext i32 %42 to i64
  %44 = getelementptr inbounds i8, ptr %40, i64 %43
  %45 = load ptr, ptr %5, align 8, !tbaa !5
  %46 = getelementptr inbounds %"struct.muli::StackAllocator::StackEntry", ptr %45, i32 0, i32 0
  store ptr %44, ptr %46, align 8, !tbaa !18
  %47 = load ptr, ptr %5, align 8, !tbaa !5
  %48 = getelementptr inbounds %"struct.muli::StackAllocator::StackEntry", ptr %47, i32 0, i32 2
  store i8 0, ptr %48, align 4, !tbaa !19
  %49 = load i32, ptr %4, align 4, !tbaa !9
  %50 = getelementptr inbounds %"class.muli::StackAllocator", ptr %6, i32 0, i32 2
  %51 = load i32, ptr %50, align 8, !tbaa !17
  %52 = add nsw i32 %51, %49
  store i32 %52, ptr %50, align 8, !tbaa !17
  br label %53

53:                                               ; preds = %38, %31
  %54 = load i32, ptr %4, align 4, !tbaa !9
  %55 = getelementptr inbounds %"class.muli::StackAllocator", ptr %6, i32 0, i32 3
  %56 = load i32, ptr %55, align 4, !tbaa !20
  %57 = add nsw i32 %56, %54
  store i32 %57, ptr %55, align 4, !tbaa !20
  %58 = getelementptr inbounds %"class.muli::StackAllocator", ptr %6, i32 0, i32 3
  %59 = load i32, ptr %58, align 4, !tbaa !20
  %60 = getelementptr inbounds %"class.muli::StackAllocator", ptr %6, i32 0, i32 4
  %61 = load i32, ptr %60, align 8, !tbaa !21
  %62 = icmp sgt i32 %59, %61
  br i1 %62, label %63, label %67

63:                                               ; preds = %53
  %64 = getelementptr inbounds %"class.muli::StackAllocator", ptr %6, i32 0, i32 3
  %65 = load i32, ptr %64, align 4, !tbaa !20
  %66 = getelementptr inbounds %"class.muli::StackAllocator", ptr %6, i32 0, i32 4
  store i32 %65, ptr %66, align 8, !tbaa !21
  br label %67

67:                                               ; preds = %63, %53
  %68 = getelementptr inbounds %"class.muli::StackAllocator", ptr %6, i32 0, i32 7
  %69 = load i32, ptr %68, align 8, !tbaa !11
  %70 = add nsw i32 %69, 1
  store i32 %70, ptr %68, align 8, !tbaa !11
  %71 = load ptr, ptr %5, align 8, !tbaa !5
  %72 = getelementptr inbounds %"struct.muli::StackAllocator::StackEntry", ptr %71, i32 0, i32 0
  %73 = load ptr, ptr %72, align 8, !tbaa !18
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #5
  ret ptr %73
}

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZN4muli5AllocEi(i32 noundef) #3

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

attributes #0 = { noreturn 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 #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { inlinehint 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 #4 = { noreturn nounwind }
attributes #5 = { 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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 102936}
!12 = !{!"_ZTSN4muli14StackAllocatorE", !13, i64 0, !7, i64 8, !10, i64 102408, !10, i64 102412, !10, i64 102416, !7, i64 102424, !10, i64 102936}
!13 = !{!"_ZTSN4muli9AllocatorE"}
!14 = !{!15, !10, i64 8}
!15 = !{!"_ZTSN4muli14StackAllocator10StackEntryE", !6, i64 0, !10, i64 8, !16, i64 12}
!16 = !{!"bool", !7, i64 0}
!17 = !{!12, !10, i64 102408}
!18 = !{!15, !6, i64 0}
!19 = !{!15, !16, i64 12}
!20 = !{!12, !10, i64 102412}
!21 = !{!12, !10, i64 102416}


; 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.muli::StackAllocator::StackEntry" = type { ptr, i32, i8 }

@.str.1 = external hidden unnamed_addr constant [74 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [65 x i8], align 1
@__PRETTY_FUNCTION__._ZN4muli14StackAllocator8AllocateEi = external hidden unnamed_addr constant [52 x i8], align 1

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef ptr @_ZN4muli14StackAllocator8AllocateEi(ptr noundef nonnull align 8 dereferenceable(102940) %0, i32 noundef %1) unnamed_addr #1 align 2 {
  %3 = getelementptr inbounds i8, ptr %0, i64 102936
  %4 = load i32, ptr %3, align 8, !tbaa !5
  %5 = icmp slt i32 %4, 32
  br i1 %5, label %7, label %6

6:                                                ; preds = %2
  tail call void @__assert_fail(ptr noundef nonnull @.str.3, ptr noundef nonnull @.str.1, i32 noundef 21, ptr noundef nonnull @__PRETTY_FUNCTION__._ZN4muli14StackAllocator8AllocateEi) #3
  unreachable

7:                                                ; preds = %2
  %8 = getelementptr inbounds i8, ptr %0, i64 102424
  %9 = sext i32 %4 to i64
  %10 = getelementptr inbounds %"struct.muli::StackAllocator::StackEntry", ptr %8, i64 %9
  %11 = getelementptr inbounds i8, ptr %10, i64 8
  store i32 %1, ptr %11, align 8, !tbaa !11
  %12 = getelementptr inbounds i8, ptr %0, i64 102408
  %13 = load i32, ptr %12, align 8, !tbaa !15
  %14 = add nsw i32 %13, %1
  %15 = icmp sgt i32 %14, 102400
  br i1 %15, label %16, label %18

16:                                               ; preds = %7
  %17 = tail call noundef ptr @_ZN4muli5AllocEi(i32 noundef %1)
  br label %22

18:                                               ; preds = %7
  %19 = getelementptr inbounds i8, ptr %0, i64 8
  %20 = sext i32 %13 to i64
  %21 = getelementptr inbounds i8, ptr %19, i64 %20
  store i32 %14, ptr %12, align 8, !tbaa !15
  br label %22

22:                                               ; preds = %18, %16
  %23 = phi ptr [ %17, %16 ], [ %21, %18 ]
  %.sink = phi i8 [ 1, %16 ], [ 0, %18 ]
  store ptr %23, ptr %10, align 8
  %24 = getelementptr inbounds i8, ptr %10, i64 12
  store i8 %.sink, ptr %24, align 4
  %25 = getelementptr inbounds i8, ptr %0, i64 102412
  %26 = load i32, ptr %25, align 4, !tbaa !16
  %27 = add nsw i32 %26, %1
  store i32 %27, ptr %25, align 4, !tbaa !16
  %28 = getelementptr inbounds i8, ptr %0, i64 102416
  %29 = load i32, ptr %28, align 8, !tbaa !17
  %30 = icmp sgt i32 %27, %29
  br i1 %30, label %31, label %32

31:                                               ; preds = %22
  store i32 %27, ptr %28, align 8, !tbaa !17
  br label %32

32:                                               ; preds = %31, %22
  %33 = load i32, ptr %3, align 8, !tbaa !5
  %34 = add nsw i32 %33, 1
  store i32 %34, ptr %3, align 8, !tbaa !5
  ret ptr %23
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZN4muli5AllocEi(i32 noundef) local_unnamed_addr #2

attributes #0 = { noreturn 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 #1 = { 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 #2 = { inlinehint 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 = { 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, !10, i64 102936}
!6 = !{!"_ZTSN4muli14StackAllocatorE", !7, i64 0, !8, i64 8, !10, i64 102408, !10, i64 102412, !10, i64 102416, !8, i64 102424, !10, i64 102936}
!7 = !{!"_ZTSN4muli9AllocatorE"}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!12, !10, i64 8}
!12 = !{!"_ZTSN4muli14StackAllocator10StackEntryE", !13, i64 0, !10, i64 8, !14, i64 12}
!13 = !{!"any pointer", !8, i64 0}
!14 = !{!"bool", !8, i64 0}
!15 = !{!6, !10, i64 102408}
!16 = !{!6, !10, i64 102412}
!17 = !{!6, !10, i64 102416}


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