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

; 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.4 = external hidden unnamed_addr constant [15 x i8], align 1
@__PRETTY_FUNCTION__._ZN4muli14StackAllocator4FreeEPvi = external hidden unnamed_addr constant [55 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [17 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [20 x i8], align 1

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

; 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 @_ZN4muli14StackAllocator4FreeEPvi(ptr noundef nonnull align 8 dereferenceable(102940) %0, ptr noundef %1, i32 noundef %2) unnamed_addr #2 align 2 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store i32 %2, ptr %6, align 4, !tbaa !9
  %8 = load ptr, ptr %4, align 8
  %9 = getelementptr inbounds %"class.muli::StackAllocator", ptr %8, i32 0, i32 7
  %10 = load i32, ptr %9, align 8, !tbaa !11
  %11 = icmp sgt i32 %10, 0
  br i1 %11, label %12, label %13

12:                                               ; preds = %3
  br label %15

13:                                               ; preds = %3
  call void @__assert_fail(ptr noundef @.str.4, ptr noundef @.str.1, i32 noundef 52, ptr noundef @__PRETTY_FUNCTION__._ZN4muli14StackAllocator4FreeEPvi) #4
  unreachable

14:                                               ; No predecessors!
  br label %15

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

28:                                               ; preds = %15
  br label %31

29:                                               ; preds = %15
  call void @__assert_fail(ptr noundef @.str.5, ptr noundef @.str.1, i32 noundef 55, ptr noundef @__PRETTY_FUNCTION__._ZN4muli14StackAllocator4FreeEPvi) #4
  unreachable

30:                                               ; No predecessors!
  br label %31

31:                                               ; preds = %30, %28
  %32 = load ptr, ptr %7, align 8, !tbaa !5
  %33 = getelementptr inbounds %"struct.muli::StackAllocator::StackEntry", ptr %32, i32 0, i32 1
  %34 = load i32, ptr %33, align 8, !tbaa !17
  %35 = load i32, ptr %6, align 4, !tbaa !9
  %36 = icmp eq i32 %34, %35
  br i1 %36, label %37, label %38

37:                                               ; preds = %31
  br label %40

38:                                               ; preds = %31
  call void @__assert_fail(ptr noundef @.str.6, ptr noundef @.str.1, i32 noundef 56, ptr noundef @__PRETTY_FUNCTION__._ZN4muli14StackAllocator4FreeEPvi) #4
  unreachable

39:                                               ; No predecessors!
  br label %40

40:                                               ; preds = %39, %37
  %41 = load ptr, ptr %7, align 8, !tbaa !5
  %42 = getelementptr inbounds %"struct.muli::StackAllocator::StackEntry", ptr %41, i32 0, i32 2
  %43 = load i8, ptr %42, align 4, !tbaa !18, !range !19, !noundef !20
  %44 = trunc i8 %43 to i1
  br i1 %44, label %45, label %47

45:                                               ; preds = %40
  %46 = load ptr, ptr %5, align 8, !tbaa !5
  call void @_ZN4muli4FreeEPv(ptr noundef %46)
  br label %54

47:                                               ; preds = %40
  %48 = load ptr, ptr %7, align 8, !tbaa !5
  %49 = getelementptr inbounds %"struct.muli::StackAllocator::StackEntry", ptr %48, i32 0, i32 1
  %50 = load i32, ptr %49, align 8, !tbaa !17
  %51 = getelementptr inbounds %"class.muli::StackAllocator", ptr %8, i32 0, i32 2
  %52 = load i32, ptr %51, align 8, !tbaa !21
  %53 = sub nsw i32 %52, %50
  store i32 %53, ptr %51, align 8, !tbaa !21
  br label %54

54:                                               ; preds = %47, %45
  %55 = load ptr, ptr %7, align 8, !tbaa !5
  %56 = getelementptr inbounds %"struct.muli::StackAllocator::StackEntry", ptr %55, i32 0, i32 1
  %57 = load i32, ptr %56, align 8, !tbaa !17
  %58 = getelementptr inbounds %"class.muli::StackAllocator", ptr %8, i32 0, i32 3
  %59 = load i32, ptr %58, align 4, !tbaa !22
  %60 = sub nsw i32 %59, %57
  store i32 %60, ptr %58, align 4, !tbaa !22
  %61 = getelementptr inbounds %"class.muli::StackAllocator", ptr %8, i32 0, i32 7
  %62 = load i32, ptr %61, align 8, !tbaa !11
  %63 = add nsw i32 %62, -1
  store i32 %63, ptr %61, align 8, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #5
  ret void
}

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

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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 = { 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, !6, i64 0}
!15 = !{!"_ZTSN4muli14StackAllocator10StackEntryE", !6, i64 0, !10, i64 8, !16, i64 12}
!16 = !{!"bool", !7, i64 0}
!17 = !{!15, !10, i64 8}
!18 = !{!15, !16, i64 12}
!19 = !{i8 0, i8 2}
!20 = !{}
!21 = !{!12, !10, i64 102408}
!22 = !{!12, !10, i64 102412}


; 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.4 = external hidden unnamed_addr constant [15 x i8], align 1
@__PRETTY_FUNCTION__._ZN4muli14StackAllocator4FreeEPvi = external hidden unnamed_addr constant [55 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [17 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [20 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 void @_ZN4muli14StackAllocator4FreeEPvi(ptr nocapture noundef nonnull align 8 dereferenceable(102940) %0, ptr noundef %1, i32 noundef %2) unnamed_addr #1 align 2 {
  %4 = getelementptr inbounds i8, ptr %0, i64 102936
  %5 = load i32, ptr %4, align 8, !tbaa !5
  %6 = icmp sgt i32 %5, 0
  br i1 %6, label %8, label %7

7:                                                ; preds = %3
  tail call void @__assert_fail(ptr noundef nonnull @.str.4, ptr noundef nonnull @.str.1, i32 noundef 52, ptr noundef nonnull @__PRETTY_FUNCTION__._ZN4muli14StackAllocator4FreeEPvi) #3
  unreachable

8:                                                ; preds = %3
  %9 = getelementptr inbounds i8, ptr %0, i64 102424
  %10 = zext nneg i32 %5 to i64
  %11 = getelementptr inbounds %"struct.muli::StackAllocator::StackEntry", ptr %9, i64 %10
  %12 = getelementptr inbounds i8, ptr %11, i64 -16
  %13 = load ptr, ptr %12, align 8, !tbaa !11
  %14 = icmp eq ptr %13, %1
  br i1 %14, label %16, label %15

15:                                               ; preds = %8
  tail call void @__assert_fail(ptr noundef nonnull @.str.5, ptr noundef nonnull @.str.1, i32 noundef 55, ptr noundef nonnull @__PRETTY_FUNCTION__._ZN4muli14StackAllocator4FreeEPvi) #3
  unreachable

16:                                               ; preds = %8
  %17 = getelementptr inbounds i8, ptr %11, i64 -8
  %18 = load i32, ptr %17, align 8, !tbaa !15
  %19 = icmp eq i32 %18, %2
  br i1 %19, label %21, label %20

20:                                               ; preds = %16
  tail call void @__assert_fail(ptr noundef nonnull @.str.6, ptr noundef nonnull @.str.1, i32 noundef 56, ptr noundef nonnull @__PRETTY_FUNCTION__._ZN4muli14StackAllocator4FreeEPvi) #3
  unreachable

21:                                               ; preds = %16
  %22 = getelementptr inbounds i8, ptr %11, i64 -4
  %23 = load i8, ptr %22, align 4, !tbaa !16, !range !17, !noundef !18
  %24 = trunc nuw i8 %23 to i1
  br i1 %24, label %25, label %26

25:                                               ; preds = %21
  tail call void @_ZN4muli4FreeEPv(ptr noundef %1)
  %.pre = load i32, ptr %17, align 8, !tbaa !15
  %.pre10 = load i32, ptr %4, align 8, !tbaa !5
  br label %30

26:                                               ; preds = %21
  %27 = getelementptr inbounds i8, ptr %0, i64 102408
  %28 = load i32, ptr %27, align 8, !tbaa !19
  %29 = sub nsw i32 %28, %2
  store i32 %29, ptr %27, align 8, !tbaa !19
  br label %30

30:                                               ; preds = %26, %25
  %31 = phi i32 [ %5, %26 ], [ %.pre10, %25 ]
  %32 = phi i32 [ %2, %26 ], [ %.pre, %25 ]
  %33 = getelementptr inbounds i8, ptr %0, i64 102412
  %34 = load i32, ptr %33, align 4, !tbaa !20
  %35 = sub nsw i32 %34, %32
  store i32 %35, ptr %33, align 4, !tbaa !20
  %36 = add nsw i32 %31, -1
  store i32 %36, ptr %4, align 8, !tbaa !5
  ret void
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_ZN4muli4FreeEPv(ptr 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, !13, i64 0}
!12 = !{!"_ZTSN4muli14StackAllocator10StackEntryE", !13, i64 0, !10, i64 8, !14, i64 12}
!13 = !{!"any pointer", !8, i64 0}
!14 = !{!"bool", !8, i64 0}
!15 = !{!12, !10, i64 8}
!16 = !{!12, !14, i64 12}
!17 = !{i8 0, i8 2}
!18 = !{}
!19 = !{!6, !10, i64 102408}
!20 = !{!6, !10, i64 102412}


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