; LLVM IR from xiaoxianrouzhiyou/BBearEditor-2.0 :: Code/BBearEditor/Engine/Allocator/tlsf (tlsf)

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

@.str.2 = external hidden unnamed_addr constant [113 x i8], align 1
@.str.27 = external hidden unnamed_addr constant [43 x i8], align 1
@__PRETTY_FUNCTION__.tlsf_memalign = external hidden unnamed_addr constant [44 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: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #1

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

; Function Attrs: nounwind uwtable
declare hidden ptr @block_to_ptr(ptr noundef) #2

; Function Attrs: nounwind uwtable
declare hidden i64 @adjust_request_size(i64 noundef, i64 noundef) #2

; Function Attrs: nounwind uwtable
declare hidden ptr @block_locate_free(ptr noundef, i64 noundef) #2

; Function Attrs: nounwind uwtable
declare hidden ptr @block_prepare_used(ptr noundef, ptr noundef, i64 noundef) #2

; Function Attrs: nounwind uwtable
define dso_local ptr @tlsf_memalign(ptr noundef %0, i64 noundef %1, i64 noundef %2) #2 {
  %4 = alloca ptr, align 8
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i64, align 8
  %9 = alloca i64, align 8
  %10 = alloca i64, align 8
  %11 = alloca i64, align 8
  %12 = alloca ptr, align 8
  %13 = alloca ptr, align 8
  %14 = alloca ptr, align 8
  %15 = alloca i64, align 8
  %16 = alloca i64, align 8
  %17 = alloca i64, align 8
  %18 = alloca ptr, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i64 %1, ptr %5, align 8, !tbaa !9
  store i64 %2, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  %19 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %19, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  %20 = load i64, ptr %6, align 8, !tbaa !9
  %21 = call i64 @adjust_request_size(i64 noundef %20, i64 noundef 8)
  store i64 %21, ptr %8, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  store i64 32, ptr %9, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  %22 = load i64, ptr %8, align 8, !tbaa !9
  %23 = load i64, ptr %5, align 8, !tbaa !9
  %24 = add i64 %22, %23
  %25 = add i64 %24, 32
  %26 = load i64, ptr %5, align 8, !tbaa !9
  %27 = call i64 @adjust_request_size(i64 noundef %25, i64 noundef %26)
  store i64 %27, ptr %10, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #3
  %28 = load i64, ptr %5, align 8, !tbaa !9
  %29 = icmp ule i64 %28, 8
  br i1 %29, label %30, label %32

30:                                               ; preds = %3
  %31 = load i64, ptr %8, align 8, !tbaa !9
  br label %34

32:                                               ; preds = %3
  %33 = load i64, ptr %10, align 8, !tbaa !9
  br label %34

34:                                               ; preds = %32, %30
  %35 = phi i64 [ %31, %30 ], [ %33, %32 ]
  store i64 %35, ptr %11, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #3
  %36 = load ptr, ptr %7, align 8, !tbaa !5
  %37 = load i64, ptr %11, align 8, !tbaa !9
  %38 = call ptr @block_locate_free(ptr noundef %36, i64 noundef %37)
  store ptr %38, ptr %12, align 8, !tbaa !5
  %39 = load ptr, ptr %12, align 8, !tbaa !5
  %40 = icmp ne ptr %39, null
  br i1 %40, label %41, label %97

41:                                               ; preds = %34
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #3
  %42 = load ptr, ptr %12, align 8, !tbaa !5
  %43 = call ptr @block_to_ptr(ptr noundef %42)
  store ptr %43, ptr %13, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #3
  %44 = load ptr, ptr %13, align 8, !tbaa !5
  %45 = load i64, ptr %5, align 8, !tbaa !9
  %46 = call ptr @align_ptr(ptr noundef %44, i64 noundef %45)
  store ptr %46, ptr %14, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #3
  %47 = load ptr, ptr %14, align 8, !tbaa !5
  %48 = ptrtoint ptr %47 to i64
  %49 = load ptr, ptr %13, align 8, !tbaa !5
  %50 = ptrtoint ptr %49 to i64
  %51 = sub nsw i64 %48, %50
  store i64 %51, ptr %15, align 8, !tbaa !9
  %52 = load i64, ptr %15, align 8, !tbaa !9
  %53 = icmp ne i64 %52, 0
  br i1 %53, label %54, label %82

54:                                               ; preds = %41
  %55 = load i64, ptr %15, align 8, !tbaa !9
  %56 = icmp ult i64 %55, 32
  br i1 %56, label %57, label %82

57:                                               ; preds = %54
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #3
  %58 = load i64, ptr %15, align 8, !tbaa !9
  %59 = sub i64 32, %58
  store i64 %59, ptr %16, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %17) #3
  %60 = load i64, ptr %16, align 8, !tbaa !9
  %61 = load i64, ptr %5, align 8, !tbaa !9
  %62 = icmp ugt i64 %60, %61
  br i1 %62, label %63, label %65

63:                                               ; preds = %57
  %64 = load i64, ptr %16, align 8, !tbaa !9
  br label %67

65:                                               ; preds = %57
  %66 = load i64, ptr %5, align 8, !tbaa !9
  br label %67

67:                                               ; preds = %65, %63
  %68 = phi i64 [ %64, %63 ], [ %66, %65 ]
  store i64 %68, ptr %17, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %18) #3
  %69 = load ptr, ptr %14, align 8, !tbaa !5
  %70 = ptrtoint ptr %69 to i64
  %71 = load i64, ptr %17, align 8, !tbaa !9
  %72 = add i64 %70, %71
  %73 = inttoptr i64 %72 to ptr
  store ptr %73, ptr %18, align 8, !tbaa !5
  %74 = load ptr, ptr %18, align 8, !tbaa !5
  %75 = load i64, ptr %5, align 8, !tbaa !9
  %76 = call ptr @align_ptr(ptr noundef %74, i64 noundef %75)
  store ptr %76, ptr %14, align 8, !tbaa !5
  %77 = load ptr, ptr %14, align 8, !tbaa !5
  %78 = ptrtoint ptr %77 to i64
  %79 = load ptr, ptr %13, align 8, !tbaa !5
  %80 = ptrtoint ptr %79 to i64
  %81 = sub nsw i64 %78, %80
  store i64 %81, ptr %15, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %18) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %17) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #3
  br label %82

82:                                               ; preds = %67, %54, %41
  %83 = load i64, ptr %15, align 8, !tbaa !9
  %84 = icmp ne i64 %83, 0
  br i1 %84, label %85, label %96

85:                                               ; preds = %82
  %86 = load i64, ptr %15, align 8, !tbaa !9
  %87 = icmp uge i64 %86, 32
  br i1 %87, label %88, label %90

88:                                               ; preds = %85
  br i1 true, label %89, label %90

89:                                               ; preds = %88
  br label %91

90:                                               ; preds = %88, %85
  call void @__assert_fail(ptr noundef @.str.27, ptr noundef @.str.2, i32 noundef 957, ptr noundef @__PRETTY_FUNCTION__.tlsf_memalign) #4
  unreachable

91:                                               ; preds = %89
  %92 = load ptr, ptr %7, align 8, !tbaa !5
  %93 = load ptr, ptr %12, align 8, !tbaa !5
  %94 = load i64, ptr %15, align 8, !tbaa !9
  %95 = call ptr @block_trim_free_leading(ptr noundef %92, ptr noundef %93, i64 noundef %94)
  store ptr %95, ptr %12, align 8, !tbaa !5
  br label %96

96:                                               ; preds = %91, %82
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #3
  br label %97

97:                                               ; preds = %96, %34
  %98 = load ptr, ptr %7, align 8, !tbaa !5
  %99 = load ptr, ptr %12, align 8, !tbaa !5
  %100 = load i64, ptr %8, align 8, !tbaa !9
  %101 = call ptr @block_prepare_used(ptr noundef %98, ptr noundef %99, i64 noundef %100)
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  ret ptr %101
}

; Function Attrs: nounwind uwtable
declare hidden ptr @align_ptr(ptr noundef, i64 noundef) #2

; Function Attrs: nounwind uwtable
declare hidden ptr @block_trim_free_leading(ptr noundef, ptr noundef, i64 noundef) #2

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 = { 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 = { nounwind }
attributes #4 = { 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/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long", !7, i64 0}


; 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.2 = external hidden unnamed_addr constant [113 x i8], align 1
@.str.27 = external hidden unnamed_addr constant [43 x i8], align 1
@__PRETTY_FUNCTION__.tlsf_memalign = external hidden unnamed_addr constant [44 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: nounwind uwtable
declare hidden ptr @block_to_ptr(ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare hidden i64 @adjust_request_size(i64 noundef, i64 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare hidden ptr @block_locate_free(ptr noundef, i64 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare hidden ptr @block_prepare_used(ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local ptr @tlsf_memalign(ptr noundef %0, i64 noundef %1, i64 noundef %2) local_unnamed_addr #1 {
  %4 = tail call i64 @adjust_request_size(i64 noundef %2, i64 noundef 8)
  %5 = add i64 %1, 32
  %6 = add i64 %5, %4
  %7 = tail call i64 @adjust_request_size(i64 noundef %6, i64 noundef %1)
  %8 = icmp ult i64 %1, 9
  %9 = select i1 %8, i64 %4, i64 %7
  %10 = tail call ptr @block_locate_free(ptr noundef %0, i64 noundef %9)
  %.not = icmp eq ptr %10, null
  br i1 %.not, label %32, label %11

11:                                               ; preds = %3
  %12 = tail call ptr @block_to_ptr(ptr noundef nonnull %10)
  %13 = tail call ptr @align_ptr(ptr noundef %12, i64 noundef %1)
  %14 = ptrtoint ptr %13 to i64
  %15 = ptrtoint ptr %12 to i64
  %16 = sub nsw i64 %14, %15
  %17 = add i64 %16, -1
  %or.cond = icmp ult i64 %17, 31
  br i1 %or.cond, label %18, label %26

18:                                               ; preds = %11
  %19 = sub nuw nsw i64 32, %16
  %20 = tail call i64 @llvm.umax.i64(i64 %19, i64 %1)
  %21 = add i64 %20, %14
  %22 = inttoptr i64 %21 to ptr
  %23 = tail call ptr @align_ptr(ptr noundef %22, i64 noundef %1)
  %24 = ptrtoint ptr %23 to i64
  %25 = sub nsw i64 %24, %15
  br label %26

26:                                               ; preds = %18, %11
  %.037 = phi i64 [ %25, %18 ], [ %16, %11 ]
  %.not41 = icmp eq i64 %.037, 0
  br i1 %.not41, label %32, label %27

27:                                               ; preds = %26
  %28 = icmp ugt i64 %.037, 31
  br i1 %28, label %30, label %29

29:                                               ; preds = %27
  tail call void @__assert_fail(ptr noundef nonnull @.str.27, ptr noundef nonnull @.str.2, i32 noundef 957, ptr noundef nonnull @__PRETTY_FUNCTION__.tlsf_memalign) #3
  unreachable

30:                                               ; preds = %27
  %31 = tail call ptr @block_trim_free_leading(ptr noundef %0, ptr noundef nonnull %10, i64 noundef %.037)
  br label %32

32:                                               ; preds = %26, %30, %3
  %.1 = phi ptr [ null, %3 ], [ %31, %30 ], [ %10, %26 ]
  %33 = tail call ptr @block_prepare_used(ptr noundef %0, ptr noundef %.1, i64 noundef %4)
  ret ptr %33
}

; Function Attrs: nounwind uwtable
declare hidden ptr @align_ptr(ptr noundef, i64 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare hidden ptr @block_trim_free_leading(ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #1

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i64 @llvm.umax.i64(i64, i64) #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 = { 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 speculatable willreturn memory(none) }
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)"}


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