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

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

; Function Attrs: nounwind uwtable
declare hidden i32 @block_is_free(ptr noundef) #1

; Function Attrs: nounwind uwtable
declare hidden ptr @block_next(ptr noundef) #1

; Function Attrs: nounwind uwtable
declare hidden i64 @block_size(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
define dso_local void @tlsf_walk_pool(ptr noundef %0, ptr noundef %1, ptr noundef %2) #1 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store ptr %2, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #2
  %9 = load ptr, ptr %5, align 8, !tbaa !5
  %10 = icmp ne ptr %9, null
  br i1 %10, label %11, label %13

11:                                               ; preds = %3
  %12 = load ptr, ptr %5, align 8, !tbaa !5
  br label %14

13:                                               ; preds = %3
  br label %14

14:                                               ; preds = %13, %11
  %15 = phi ptr [ %12, %11 ], [ @default_walker, %13 ]
  store ptr %15, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #2
  %16 = load ptr, ptr %4, align 8, !tbaa !5
  %17 = call ptr @offset_to_block(ptr noundef %16, i64 noundef -8)
  store ptr %17, ptr %8, align 8, !tbaa !5
  br label %18

18:                                               ; preds = %28, %14
  %19 = load ptr, ptr %8, align 8, !tbaa !5
  %20 = icmp ne ptr %19, null
  br i1 %20, label %21, label %26

21:                                               ; preds = %18
  %22 = load ptr, ptr %8, align 8, !tbaa !5
  %23 = call i32 @block_is_last(ptr noundef %22)
  %24 = icmp ne i32 %23, 0
  %25 = xor i1 %24, true
  br label %26

26:                                               ; preds = %21, %18
  %27 = phi i1 [ false, %18 ], [ %25, %21 ]
  br i1 %27, label %28, label %42

28:                                               ; preds = %26
  %29 = load ptr, ptr %7, align 8, !tbaa !5
  %30 = load ptr, ptr %8, align 8, !tbaa !5
  %31 = call ptr @block_to_ptr(ptr noundef %30)
  %32 = load ptr, ptr %8, align 8, !tbaa !5
  %33 = call i64 @block_size(ptr noundef %32)
  %34 = load ptr, ptr %8, align 8, !tbaa !5
  %35 = call i32 @block_is_free(ptr noundef %34)
  %36 = icmp ne i32 %35, 0
  %37 = xor i1 %36, true
  %38 = zext i1 %37 to i32
  %39 = load ptr, ptr %6, align 8, !tbaa !5
  call void %29(ptr noundef %31, i64 noundef %33, i32 noundef %38, ptr noundef %39)
  %40 = load ptr, ptr %8, align 8, !tbaa !5
  %41 = call ptr @block_next(ptr noundef %40)
  store ptr %41, ptr %8, align 8, !tbaa !5
  br label %18, !llvm.loop !9

42:                                               ; preds = %26
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #2
  ret void
}

; Function Attrs: nounwind uwtable
declare hidden void @default_walker(ptr noundef, i64 noundef, i32 noundef, ptr noundef) #1

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

; Function Attrs: nounwind uwtable
declare hidden i32 @block_is_last(ptr noundef) #1

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


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

; Function Attrs: nounwind uwtable
declare hidden i32 @block_is_free(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare hidden ptr @block_next(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare hidden i64 @block_size(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @tlsf_walk_pool(ptr noundef %0, ptr noundef readonly %1, ptr noundef %2) local_unnamed_addr #0 {
  %.not = icmp eq ptr %1, null
  %4 = select i1 %.not, ptr @default_walker, ptr %1
  %5 = tail call ptr @offset_to_block(ptr noundef %0, i64 noundef -8)
  %.not1114 = icmp eq ptr %5, null
  br i1 %.not1114, label %.critedge, label %.lr.ph

.lr.ph:                                           ; preds = %3, %7
  %.015 = phi ptr [ %12, %7 ], [ %5, %3 ]
  %6 = tail call i32 @block_is_last(ptr noundef nonnull %.015)
  %.not12 = icmp eq i32 %6, 0
  br i1 %.not12, label %7, label %.critedge

7:                                                ; preds = %.lr.ph
  %8 = tail call ptr @block_to_ptr(ptr noundef nonnull %.015)
  %9 = tail call i64 @block_size(ptr noundef nonnull %.015)
  %10 = tail call i32 @block_is_free(ptr noundef nonnull %.015)
  %.not13 = icmp eq i32 %10, 0
  %11 = zext i1 %.not13 to i32
  tail call void %4(ptr noundef %8, i64 noundef %9, i32 noundef %11, ptr noundef %2) #1
  %12 = tail call ptr @block_next(ptr noundef nonnull %.015)
  %.not11 = icmp eq ptr %12, null
  br i1 %.not11, label %.critedge, label %.lr.ph, !llvm.loop !5

.critedge:                                        ; preds = %.lr.ph, %7, %3
  ret void
}

; Function Attrs: nounwind uwtable
declare hidden void @default_walker(ptr noundef, i64 noundef, i32 noundef, ptr noundef) local_unnamed_addr #0

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

; Function Attrs: nounwind uwtable
declare hidden i32 @block_is_last(ptr noundef) local_unnamed_addr #0

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

attributes #0 = { 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 #1 = { 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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass