; LLVM IR from Sopiro/Muli :: src/util/linear_allocator.ll (ZN4muli15LinearAllocator4FreeEPvi)

; 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::LinearAllocator" = type { %"class.muli::Allocator", ptr, i32, i32, ptr, i32, i32, i32, i32 }
%"class.muli::Allocator" = type { ptr }
%"struct.muli::LinearAllocator::MemoryEntry" = type { ptr, i32, i8 }

@.str.1 = external hidden unnamed_addr constant [75 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [15 x i8], align 1
@__PRETTY_FUNCTION__._ZN4muli15LinearAllocator4FreeEPvi = external hidden unnamed_addr constant [56 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [17 x i8], align 1
@.str.4 = 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: inlinehint mustprogress nounwind uwtable
declare dso_local void @_ZN4muli4FreeEPv(ptr noundef) #1

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

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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN4muli15LinearAllocator4FreeEPvi(ptr noundef nonnull align 8 dereferenceable(48) %0, ptr noundef %1, i32 noundef %2) unnamed_addr #3 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::LinearAllocator", ptr %8, i32 0, i32 2
  %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.2, ptr noundef @.str.1, i32 noundef 69, ptr noundef @__PRETTY_FUNCTION__._ZN4muli15LinearAllocator4FreeEPvi) #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::LinearAllocator", ptr %8, i32 0, i32 1
  %17 = load ptr, ptr %16, align 8, !tbaa !14
  %18 = getelementptr inbounds %"class.muli::LinearAllocator", ptr %8, i32 0, i32 2
  %19 = load i32, ptr %18, align 8, !tbaa !11
  %20 = sub nsw i32 %19, 1
  %21 = sext i32 %20 to i64
  %22 = getelementptr inbounds %"struct.muli::LinearAllocator::MemoryEntry", ptr %17, i64 %21
  store ptr %22, ptr %7, align 8, !tbaa !5
  %23 = load ptr, ptr %7, align 8, !tbaa !5
  %24 = getelementptr inbounds %"struct.muli::LinearAllocator::MemoryEntry", ptr %23, i32 0, i32 0
  %25 = load ptr, ptr %24, align 8, !tbaa !15
  %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.3, ptr noundef @.str.1, i32 noundef 72, ptr noundef @__PRETTY_FUNCTION__._ZN4muli15LinearAllocator4FreeEPvi) #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::LinearAllocator::MemoryEntry", ptr %32, i32 0, i32 1
  %34 = load i32, ptr %33, align 8, !tbaa !18
  %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.4, ptr noundef @.str.1, i32 noundef 73, ptr noundef @__PRETTY_FUNCTION__._ZN4muli15LinearAllocator4FreeEPvi) #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::LinearAllocator::MemoryEntry", ptr %41, i32 0, i32 2
  %43 = load i8, ptr %42, align 4, !tbaa !19, !range !20, !noundef !21
  %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::LinearAllocator::MemoryEntry", ptr %48, i32 0, i32 1
  %50 = load i32, ptr %49, align 8, !tbaa !18
  %51 = getelementptr inbounds %"class.muli::LinearAllocator", ptr %8, i32 0, i32 6
  %52 = load i32, ptr %51, align 4, !tbaa !22
  %53 = sub nsw i32 %52, %50
  store i32 %53, ptr %51, align 4, !tbaa !22
  br label %54

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

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 = { 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 #2 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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 #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 16}
!12 = !{!"_ZTSN4muli15LinearAllocatorE", !13, i64 0, !6, i64 8, !10, i64 16, !10, i64 20, !6, i64 24, !10, i64 32, !10, i64 36, !10, i64 40, !10, i64 44}
!13 = !{!"_ZTSN4muli9AllocatorE"}
!14 = !{!12, !6, i64 8}
!15 = !{!16, !6, i64 0}
!16 = !{!"_ZTSN4muli15LinearAllocator11MemoryEntryE", !6, i64 0, !10, i64 8, !17, i64 12}
!17 = !{!"bool", !7, i64 0}
!18 = !{!16, !10, i64 8}
!19 = !{!16, !17, i64 12}
!20 = !{i8 0, i8 2}
!21 = !{}
!22 = !{!12, !10, i64 36}
!23 = !{!12, !10, 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"

%"struct.muli::LinearAllocator::MemoryEntry" = type { ptr, i32, i8 }

@.str.1 = external hidden unnamed_addr constant [75 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [15 x i8], align 1
@__PRETTY_FUNCTION__._ZN4muli15LinearAllocator4FreeEPvi = external hidden unnamed_addr constant [56 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [17 x i8], align 1
@.str.4 = 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: inlinehint mustprogress nounwind uwtable
declare dso_local void @_ZN4muli4FreeEPv(ptr noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN4muli15LinearAllocator4FreeEPvi(ptr nocapture noundef nonnull align 8 dereferenceable(48) %0, ptr noundef %1, i32 noundef %2) unnamed_addr #2 align 2 {
  %4 = getelementptr inbounds i8, ptr %0, i64 16
  %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.2, ptr noundef nonnull @.str.1, i32 noundef 69, ptr noundef nonnull @__PRETTY_FUNCTION__._ZN4muli15LinearAllocator4FreeEPvi) #3
  unreachable

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

16:                                               ; preds = %8
  tail call void @__assert_fail(ptr noundef nonnull @.str.3, ptr noundef nonnull @.str.1, i32 noundef 72, ptr noundef nonnull @__PRETTY_FUNCTION__._ZN4muli15LinearAllocator4FreeEPvi) #3
  unreachable

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

21:                                               ; preds = %17
  tail call void @__assert_fail(ptr noundef nonnull @.str.4, ptr noundef nonnull @.str.1, i32 noundef 73, ptr noundef nonnull @__PRETTY_FUNCTION__._ZN4muli15LinearAllocator4FreeEPvi) #3
  unreachable

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

26:                                               ; preds = %22
  tail call void @_ZN4muli4FreeEPv(ptr noundef %1)
  %.pre = load i32, ptr %18, align 8, !tbaa !16
  %.pre10 = load i32, ptr %4, align 8, !tbaa !5
  br label %31

27:                                               ; preds = %22
  %28 = getelementptr inbounds i8, ptr %0, i64 36
  %29 = load i32, ptr %28, align 4, !tbaa !20
  %30 = sub nsw i32 %29, %2
  store i32 %30, ptr %28, align 4, !tbaa !20
  br label %31

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

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 = { 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 #2 = { 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, !11, i64 16}
!6 = !{!"_ZTSN4muli15LinearAllocatorE", !7, i64 0, !8, i64 8, !11, i64 16, !11, i64 20, !8, i64 24, !11, i64 32, !11, i64 36, !11, i64 40, !11, i64 44}
!7 = !{!"_ZTSN4muli9AllocatorE"}
!8 = !{!"any pointer", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C++ TBAA"}
!11 = !{!"int", !9, i64 0}
!12 = !{!6, !8, i64 8}
!13 = !{!14, !8, i64 0}
!14 = !{!"_ZTSN4muli15LinearAllocator11MemoryEntryE", !8, i64 0, !11, i64 8, !15, i64 12}
!15 = !{!"bool", !9, i64 0}
!16 = !{!14, !11, i64 8}
!17 = !{!14, !15, i64 12}
!18 = !{i8 0, i8 2}
!19 = !{}
!20 = !{!6, !11, i64 36}
!21 = !{!6, !11, i64 40}


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