; LLVM IR from Sopiro/Muli :: src/util/block_allocator.ll (ZN4muli14BlockAllocator4FreeEPvi)

; 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::BlockAllocator" = type { %"class.muli::Allocator", i32, i32, [128 x i32], ptr, [128 x ptr] }
%"class.muli::Allocator" = type { ptr }
%"struct.muli::Block" = type { ptr }

@.str.1 = external hidden unnamed_addr constant [74 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [40 x i8], align 1
@__PRETTY_FUNCTION__._ZN4muli14BlockAllocator4FreeEPvi = external hidden unnamed_addr constant [55 x i8], align 1

; 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: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #1

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN4muli14BlockAllocator4FreeEPvi(ptr noundef nonnull align 8 dereferenceable(1560) %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 i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = 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
  %11 = load ptr, ptr %4, align 8
  %12 = load i32, ptr %6, align 4, !tbaa !9
  %13 = icmp eq i32 %12, 0
  br i1 %13, label %14, label %15

14:                                               ; preds = %3
  br label %64

15:                                               ; preds = %3
  %16 = load i32, ptr %6, align 4, !tbaa !9
  %17 = icmp sgt i32 %16, 1024
  br i1 %17, label %18, label %20

18:                                               ; preds = %15
  %19 = load ptr, ptr %5, align 8, !tbaa !5
  call void @_ZN4muli4FreeEPv(ptr noundef %19)
  br label %64

20:                                               ; preds = %15
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  %21 = load i32, ptr %6, align 4, !tbaa !9
  store i32 %21, ptr %7, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  %22 = load i32, ptr %6, align 4, !tbaa !9
  %23 = sdiv i32 %22, 8
  store i32 %23, ptr %8, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  %24 = load i32, ptr %6, align 4, !tbaa !9
  %25 = srem i32 %24, 8
  store i32 %25, ptr %9, align 4, !tbaa !9
  %26 = load i32, ptr %9, align 4, !tbaa !9
  %27 = icmp ne i32 %26, 0
  br i1 %27, label %28, label %33

28:                                               ; preds = %20
  %29 = load i32, ptr %9, align 4, !tbaa !9
  %30 = sub nsw i32 8, %29
  %31 = load i32, ptr %7, align 4, !tbaa !9
  %32 = add nsw i32 %31, %30
  store i32 %32, ptr %7, align 4, !tbaa !9
  br label %36

33:                                               ; preds = %20
  %34 = load i32, ptr %8, align 4, !tbaa !9
  %35 = add nsw i32 %34, -1
  store i32 %35, ptr %8, align 4, !tbaa !9
  br label %36

36:                                               ; preds = %33, %28
  %37 = load i32, ptr %8, align 4, !tbaa !9
  %38 = icmp sle i32 0, %37
  br i1 %38, label %39, label %42

39:                                               ; preds = %36
  %40 = load i32, ptr %8, align 4, !tbaa !9
  %41 = icmp sle i32 %40, 128
  br label %42

42:                                               ; preds = %39, %36
  %43 = phi i1 [ false, %36 ], [ %41, %39 ]
  br i1 %43, label %44, label %45

44:                                               ; preds = %42
  br label %47

45:                                               ; preds = %42
  call void @__assert_fail(ptr noundef @.str.2, ptr noundef @.str.1, i32 noundef 114, ptr noundef @__PRETTY_FUNCTION__._ZN4muli14BlockAllocator4FreeEPvi) #5
  unreachable

46:                                               ; No predecessors!
  br label %47

47:                                               ; preds = %46, %44
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  %48 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %48, ptr %10, align 8, !tbaa !5
  %49 = getelementptr inbounds %"class.muli::BlockAllocator", ptr %11, i32 0, i32 5
  %50 = load i32, ptr %8, align 4, !tbaa !9
  %51 = sext i32 %50 to i64
  %52 = getelementptr inbounds [128 x ptr], ptr %49, i64 0, i64 %51
  %53 = load ptr, ptr %52, align 8, !tbaa !5
  %54 = load ptr, ptr %10, align 8, !tbaa !5
  %55 = getelementptr inbounds %"struct.muli::Block", ptr %54, i32 0, i32 0
  store ptr %53, ptr %55, align 8, !tbaa !11
  %56 = load ptr, ptr %10, align 8, !tbaa !5
  %57 = getelementptr inbounds %"class.muli::BlockAllocator", ptr %11, i32 0, i32 5
  %58 = load i32, ptr %8, align 4, !tbaa !9
  %59 = sext i32 %58 to i64
  %60 = getelementptr inbounds [128 x ptr], ptr %57, i64 0, i64 %59
  store ptr %56, ptr %60, align 8, !tbaa !5
  %61 = getelementptr inbounds %"class.muli::BlockAllocator", ptr %11, i32 0, i32 1
  %62 = load i32, ptr %61, align 8, !tbaa !13
  %63 = add nsw i32 %62, -1
  store i32 %63, ptr %61, align 8, !tbaa !13
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  br label %64

64:                                               ; preds = %47, %18, %14
  ret void
}

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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 = { nounwind }
attributes #5 = { 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, !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, !6, i64 0}
!12 = !{!"_ZTSN4muli5BlockE", !6, i64 0}
!13 = !{!14, !10, i64 8}
!14 = !{!"_ZTSN4muli14BlockAllocatorE", !15, i64 0, !10, i64 8, !10, i64 12, !7, i64 16, !6, i64 528, !7, i64 536}
!15 = !{!"_ZTSN4muli9AllocatorE"}


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

@.str.1 = external hidden unnamed_addr constant [74 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [40 x i8], align 1
@__PRETTY_FUNCTION__._ZN4muli14BlockAllocator4FreeEPvi = external hidden unnamed_addr constant [55 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 @_ZN4muli14BlockAllocator4FreeEPvi(ptr nocapture noundef nonnull align 8 dereferenceable(1560) %0, ptr noundef %1, i32 noundef %2) unnamed_addr #1 align 2 {
  %4 = icmp eq i32 %2, 0
  br i1 %4, label %22, label %5

5:                                                ; preds = %3
  %6 = icmp sgt i32 %2, 1024
  br i1 %6, label %7, label %8

7:                                                ; preds = %5
  tail call void @_ZN4muli4FreeEPv(ptr noundef %1)
  br label %22

8:                                                ; preds = %5
  %9 = sdiv i32 %2, 8
  %10 = and i32 %2, 7
  %.not = icmp eq i32 %10, 0
  %11 = sext i1 %.not to i32
  %.0 = add nsw i32 %9, %11
  %12 = icmp ult i32 %.0, 129
  br i1 %12, label %14, label %13

13:                                               ; preds = %8
  tail call void @__assert_fail(ptr noundef nonnull @.str.2, ptr noundef nonnull @.str.1, i32 noundef 114, ptr noundef nonnull @__PRETTY_FUNCTION__._ZN4muli14BlockAllocator4FreeEPvi) #3
  unreachable

14:                                               ; preds = %8
  %15 = getelementptr inbounds i8, ptr %0, i64 536
  %16 = zext nneg i32 %.0 to i64
  %17 = getelementptr inbounds [128 x ptr], ptr %15, i64 0, i64 %16
  %18 = load ptr, ptr %17, align 8, !tbaa !5
  store ptr %18, ptr %1, align 8, !tbaa !9
  store ptr %1, ptr %17, align 8, !tbaa !5
  %19 = getelementptr inbounds i8, ptr %0, i64 8
  %20 = load i32, ptr %19, align 8, !tbaa !11
  %21 = add nsw i32 %20, -1
  store i32 %21, ptr %19, align 8, !tbaa !11
  br label %22

22:                                               ; preds = %3, %14, %7
  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, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !6, i64 0}
!10 = !{!"_ZTSN4muli5BlockE", !6, i64 0}
!11 = !{!12, !14, i64 8}
!12 = !{!"_ZTSN4muli14BlockAllocatorE", !13, i64 0, !14, i64 8, !14, i64 12, !7, i64 16, !6, i64 528, !7, i64 536}
!13 = !{!"_ZTSN4muli9AllocatorE"}
!14 = !{!"int", !7, i64 0}


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