; LLVM IR from Simple-XX/SimpleKernel :: src/kernel/firstfit.ll (ZN8FIRSTFIT4freeEmm)

; 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.ALLOCATOR = type { ptr, ptr, i64, i64, i64, i64 }

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN8FIRSTFIT3clrEm(ptr noundef nonnull align 8 dereferenceable(4144), i64 noundef) #0 align 2

; 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 nounwind uwtable
define dso_local void @_ZN8FIRSTFIT4freeEmm(ptr noundef nonnull align 8 dereferenceable(4144) %0, i64 noundef %1, i64 noundef %2) unnamed_addr #0 align 2 {
  %4 = alloca ptr, align 8
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  %8 = alloca i64, 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
  %9 = load ptr, ptr %4, align 8
  %10 = load i64, ptr %5, align 8, !tbaa !9
  %11 = getelementptr inbounds %class.ALLOCATOR, ptr %9, i32 0, i32 2
  %12 = load i64, ptr %11, align 8, !tbaa !11
  %13 = icmp ult i64 %10, %12
  br i1 %13, label %23, label %14

14:                                               ; preds = %3
  %15 = load i64, ptr %5, align 8, !tbaa !9
  %16 = getelementptr inbounds %class.ALLOCATOR, ptr %9, i32 0, i32 2
  %17 = load i64, ptr %16, align 8, !tbaa !11
  %18 = getelementptr inbounds %class.ALLOCATOR, ptr %9, i32 0, i32 3
  %19 = load i64, ptr %18, align 8, !tbaa !13
  %20 = mul i64 %19, 4096
  %21 = add i64 %17, %20
  %22 = icmp uge i64 %15, %21
  br i1 %22, label %23, label %24

23:                                               ; preds = %14, %3
  br label %52

24:                                               ; preds = %14
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #2
  %25 = load i64, ptr %5, align 8, !tbaa !9
  %26 = getelementptr inbounds %class.ALLOCATOR, ptr %9, i32 0, i32 2
  %27 = load i64, ptr %26, align 8, !tbaa !11
  %28 = sub i64 %25, %27
  %29 = udiv i64 %28, 4096
  store i64 %29, ptr %7, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #2
  %30 = load i64, ptr %7, align 8, !tbaa !9
  store i64 %30, ptr %8, align 8, !tbaa !9
  br label %31

31:                                               ; preds = %40, %24
  %32 = load i64, ptr %8, align 8, !tbaa !9
  %33 = load i64, ptr %7, align 8, !tbaa !9
  %34 = load i64, ptr %6, align 8, !tbaa !9
  %35 = add i64 %33, %34
  %36 = icmp ult i64 %32, %35
  br i1 %36, label %38, label %37

37:                                               ; preds = %31
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #2
  br label %43

38:                                               ; preds = %31
  %39 = load i64, ptr %8, align 8, !tbaa !9
  call void @_ZN8FIRSTFIT3clrEm(ptr noundef nonnull align 8 dereferenceable(4144) %9, i64 noundef %39)
  br label %40

40:                                               ; preds = %38
  %41 = load i64, ptr %8, align 8, !tbaa !9
  %42 = add i64 %41, 1
  store i64 %42, ptr %8, align 8, !tbaa !9
  br label %31, !llvm.loop !14

43:                                               ; preds = %37
  %44 = load i64, ptr %6, align 8, !tbaa !9
  %45 = getelementptr inbounds %class.ALLOCATOR, ptr %9, i32 0, i32 4
  %46 = load i64, ptr %45, align 8, !tbaa !16
  %47 = add i64 %46, %44
  store i64 %47, ptr %45, align 8, !tbaa !16
  %48 = load i64, ptr %6, align 8, !tbaa !9
  %49 = getelementptr inbounds %class.ALLOCATOR, ptr %9, i32 0, i32 5
  %50 = load i64, ptr %49, align 8, !tbaa !17
  %51 = sub i64 %50, %48
  store i64 %51, ptr %49, align 8, !tbaa !17
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #2
  br label %52

52:                                               ; preds = %43, %23
  ret void
}

attributes #0 = { 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!12, !10, i64 16}
!12 = !{!"_ZTS9ALLOCATOR", !6, i64 8, !10, i64 16, !10, i64 24, !10, i64 32, !10, i64 40}
!13 = !{!12, !10, i64 24}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = !{!12, !10, i64 32}
!17 = !{!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"

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN8FIRSTFIT3clrEm(ptr noundef nonnull align 8 dereferenceable(4144), i64 noundef) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN8FIRSTFIT4freeEmm(ptr noundef nonnull align 8 dereferenceable(4144) %0, i64 noundef %1, i64 noundef %2) unnamed_addr #0 align 2 {
  %4 = getelementptr inbounds i8, ptr %0, i64 16
  %5 = load i64, ptr %4, align 8, !tbaa !5
  %6 = icmp ugt i64 %5, %1
  br i1 %6, label %24, label %7

7:                                                ; preds = %3
  %8 = getelementptr inbounds i8, ptr %0, i64 24
  %9 = load i64, ptr %8, align 8, !tbaa !11
  %10 = shl i64 %9, 12
  %11 = add i64 %10, %5
  %.not = icmp ugt i64 %11, %1
  br i1 %.not, label %12, label %24

12:                                               ; preds = %7
  %13 = sub i64 %1, %5
  %14 = lshr i64 %13, 12
  %15 = add i64 %14, %2
  %16 = icmp ult i64 %14, %15
  br i1 %16, label %.lr.ph, label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph, %12
  %17 = getelementptr inbounds i8, ptr %0, i64 32
  %18 = load i64, ptr %17, align 8, !tbaa !12
  %19 = add i64 %18, %2
  store i64 %19, ptr %17, align 8, !tbaa !12
  %20 = getelementptr inbounds i8, ptr %0, i64 40
  %21 = load i64, ptr %20, align 8, !tbaa !13
  %22 = sub i64 %21, %2
  store i64 %22, ptr %20, align 8, !tbaa !13
  br label %24

.lr.ph:                                           ; preds = %12, %.lr.ph
  %.013 = phi i64 [ %23, %.lr.ph ], [ %14, %12 ]
  tail call void @_ZN8FIRSTFIT3clrEm(ptr noundef nonnull align 8 dereferenceable(4144) %0, i64 noundef %.013)
  %23 = add i64 %.013, 1
  %exitcond.not = icmp eq i64 %23, %15
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph, !llvm.loop !14

24:                                               ; preds = %3, %7, %._crit_edge
  ret void
}

attributes #0 = { 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" }

!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 16}
!6 = !{!"_ZTS9ALLOCATOR", !7, i64 8, !10, i64 16, !10, i64 24, !10, i64 32, !10, i64 40}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"long", !8, i64 0}
!11 = !{!6, !10, i64 24}
!12 = !{!6, !10, i64 32}
!13 = !{!6, !10, i64 40}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass