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

; 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.SLAB::slab_cache_t" = type <{ i64, %"struct.SLAB::chunk_t", %"struct.SLAB::chunk_t", %"struct.SLAB::chunk_t", i8, [7 x i8] }>
%"struct.SLAB::chunk_t" = type { i64, i64, ptr, ptr }

@.str = external hidden unnamed_addr constant [30 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [76 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [51 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [17 x i8], align 1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZNK4SLAB7chunk_t4sizeEv(ptr noundef nonnull align 8 dereferenceable(32)) #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

declare i32 @err(ptr noundef, ...) #2

declare noundef nonnull align 8 dereferenceable(72) ptr @_ZN3PMM12get_instanceEv() #2

declare noundef nonnull align 1 dereferenceable(1) ptr @_ZN3VMM12get_instanceEv() #2

declare noundef ptr @_ZN3VMM7get_pgdEv(ptr noundef nonnull align 1 dereferenceable(1)) #2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN4SLAB12slab_cache_t8free_pmmEv(ptr noundef nonnull align 8 dereferenceable(105) %0) #3 align 2 {
  %2 = alloca ptr, align 8
  %3 = alloca i64, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  %8 = load ptr, ptr %2, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #4
  store i64 0, ptr %3, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #4
  %9 = getelementptr inbounds %"class.SLAB::slab_cache_t", ptr %8, i32 0, i32 3
  %10 = getelementptr inbounds %"struct.SLAB::chunk_t", ptr %9, i32 0, i32 3
  %11 = load ptr, ptr %10, align 8, !tbaa !11
  store ptr %11, ptr %4, align 8, !tbaa !5
  br label %12

12:                                               ; preds = %73, %1
  %13 = load ptr, ptr %4, align 8, !tbaa !5
  %14 = getelementptr inbounds %"class.SLAB::slab_cache_t", ptr %8, i32 0, i32 3
  %15 = icmp ne ptr %13, %14
  br i1 %15, label %16, label %75

16:                                               ; preds = %12
  %17 = load ptr, ptr %4, align 8, !tbaa !5
  %18 = getelementptr inbounds %"struct.SLAB::chunk_t", ptr %17, i32 0, i32 1
  %19 = load i64, ptr %18, align 8, !tbaa !15
  %20 = add i64 %19, 32
  %21 = udiv i64 %20, 4096
  store i64 %21, ptr %3, align 8, !tbaa !9
  %22 = load ptr, ptr %4, align 8, !tbaa !5
  %23 = getelementptr inbounds %"struct.SLAB::chunk_t", ptr %22, i32 0, i32 1
  %24 = load i64, ptr %23, align 8, !tbaa !15
  %25 = add i64 %24, 32
  %26 = urem i64 %25, 4096
  %27 = icmp eq i64 %26, 0
  br i1 %27, label %28, label %29

28:                                               ; preds = %16
  br label %31

29:                                               ; preds = %16
  %30 = call i32 (ptr, ...) @err(ptr noundef @.str, ptr noundef @.str.1, i32 noundef 163, ptr noundef @.str.5)
  br label %31

31:                                               ; preds = %29, %28
  %32 = call noundef nonnull align 8 dereferenceable(72) ptr @_ZN3PMM12get_instanceEv()
  %33 = load ptr, ptr %4, align 8, !tbaa !5
  %34 = getelementptr inbounds %"struct.SLAB::chunk_t", ptr %33, i32 0, i32 0
  %35 = load i64, ptr %34, align 8, !tbaa !16
  %36 = load i64, ptr %3, align 8, !tbaa !9
  call void @_ZN3PMM10free_pagesEmm(ptr noundef nonnull align 8 dereferenceable(72) %32, i64 noundef %35, i64 noundef %36)
  %37 = load ptr, ptr %4, align 8, !tbaa !5
  %38 = getelementptr inbounds %"struct.SLAB::chunk_t", ptr %37, i32 0, i32 3
  %39 = load ptr, ptr %38, align 8, !tbaa !17
  %40 = load ptr, ptr %4, align 8, !tbaa !5
  %41 = getelementptr inbounds %"struct.SLAB::chunk_t", ptr %40, i32 0, i32 2
  %42 = load ptr, ptr %41, align 8, !tbaa !18
  %43 = getelementptr inbounds %"struct.SLAB::chunk_t", ptr %42, i32 0, i32 3
  store ptr %39, ptr %43, align 8, !tbaa !17
  %44 = load ptr, ptr %4, align 8, !tbaa !5
  %45 = getelementptr inbounds %"struct.SLAB::chunk_t", ptr %44, i32 0, i32 2
  %46 = load ptr, ptr %45, align 8, !tbaa !18
  %47 = load ptr, ptr %4, align 8, !tbaa !5
  %48 = getelementptr inbounds %"struct.SLAB::chunk_t", ptr %47, i32 0, i32 3
  %49 = load ptr, ptr %48, align 8, !tbaa !17
  %50 = getelementptr inbounds %"struct.SLAB::chunk_t", ptr %49, i32 0, i32 2
  store ptr %46, ptr %50, align 8, !tbaa !18
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  %51 = load ptr, ptr %4, align 8, !tbaa !5
  %52 = getelementptr inbounds %"struct.SLAB::chunk_t", ptr %51, i32 0, i32 3
  %53 = load ptr, ptr %52, align 8, !tbaa !17
  store ptr %53, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  store i64 0, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  store i64 0, ptr %7, align 8, !tbaa !9
  br label %54

54:                                               ; preds = %70, %31
  %55 = load i64, ptr %7, align 8, !tbaa !9
  %56 = load i64, ptr %3, align 8, !tbaa !9
  %57 = icmp ult i64 %55, %56
  br i1 %57, label %59, label %58

58:                                               ; preds = %54
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  br label %73

59:                                               ; preds = %54
  %60 = load ptr, ptr %4, align 8, !tbaa !5
  %61 = getelementptr inbounds %"struct.SLAB::chunk_t", ptr %60, i32 0, i32 0
  %62 = load i64, ptr %61, align 8, !tbaa !16
  %63 = load i64, ptr %7, align 8, !tbaa !9
  %64 = mul i64 %63, 4096
  %65 = add i64 %62, %64
  store i64 %65, ptr %6, align 8, !tbaa !9
  %66 = call noundef nonnull align 1 dereferenceable(1) ptr @_ZN3VMM12get_instanceEv()
  %67 = call noundef nonnull align 1 dereferenceable(1) ptr @_ZN3VMM12get_instanceEv()
  %68 = call noundef ptr @_ZN3VMM7get_pgdEv(ptr noundef nonnull align 1 dereferenceable(1) %67)
  %69 = load i64, ptr %6, align 8, !tbaa !9
  call void @_ZN3VMM6unmmapEPmm(ptr noundef nonnull align 1 dereferenceable(1) %66, ptr noundef %68, i64 noundef %69)
  br label %70

70:                                               ; preds = %59
  %71 = load i64, ptr %7, align 8, !tbaa !9
  %72 = add i64 %71, 1
  store i64 %72, ptr %7, align 8, !tbaa !9
  br label %54, !llvm.loop !19

73:                                               ; preds = %58
  %74 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %74, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  br label %12, !llvm.loop !21

75:                                               ; preds = %12
  %76 = getelementptr inbounds %"class.SLAB::slab_cache_t", ptr %8, i32 0, i32 3
  %77 = call noundef i64 @_ZNK4SLAB7chunk_t4sizeEv(ptr noundef nonnull align 8 dereferenceable(32) %76)
  %78 = icmp eq i64 %77, 0
  br i1 %78, label %79, label %80

79:                                               ; preds = %75
  br label %82

80:                                               ; preds = %75
  %81 = call i32 (ptr, ...) @err(ptr noundef @.str, ptr noundef @.str.1, i32 noundef 181, ptr noundef @.str.6)
  br label %82

82:                                               ; preds = %80, %79
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #4
  ret void
}

declare void @_ZN3PMM10free_pagesEmm(ptr noundef nonnull align 8 dereferenceable(72), i64 noundef, i64 noundef) #2

declare void @_ZN3VMM6unmmapEPmm(ptr noundef nonnull align 1 dereferenceable(1), ptr noundef, i64 noundef) #2

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 = { "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 = { 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 = { 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, !6, i64 96}
!12 = !{!"_ZTSN4SLAB12slab_cache_tE", !10, i64 0, !13, i64 8, !13, i64 40, !13, i64 72, !14, i64 104}
!13 = !{!"_ZTSN4SLAB7chunk_tE", !10, i64 0, !10, i64 8, !6, i64 16, !6, i64 24}
!14 = !{!"bool", !7, i64 0}
!15 = !{!13, !10, i64 8}
!16 = !{!13, !10, i64 0}
!17 = !{!13, !6, i64 24}
!18 = !{!13, !6, i64 16}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}
!21 = distinct !{!21, !20}


; 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 = external hidden unnamed_addr constant [30 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [76 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [51 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [17 x i8], align 1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZNK4SLAB7chunk_t4sizeEv(ptr noundef nonnull align 8 dereferenceable(32)) local_unnamed_addr #0 align 2

declare i32 @err(ptr noundef, ...) local_unnamed_addr #1

declare noundef nonnull align 8 dereferenceable(72) ptr @_ZN3PMM12get_instanceEv() local_unnamed_addr #1

declare noundef nonnull align 1 dereferenceable(1) ptr @_ZN3VMM12get_instanceEv() local_unnamed_addr #1

declare noundef ptr @_ZN3VMM7get_pgdEv(ptr noundef nonnull align 1 dereferenceable(1)) local_unnamed_addr #1

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN4SLAB12slab_cache_t8free_pmmEv(ptr noundef nonnull align 8 dereferenceable(105) %0) local_unnamed_addr #2 align 2 {
  %2 = getelementptr inbounds i8, ptr %0, i64 72
  %3 = getelementptr inbounds i8, ptr %0, i64 96
  %4 = load ptr, ptr %3, align 8, !tbaa !5
  %.not20 = icmp eq ptr %4, %2
  br i1 %.not20, label %._crit_edge, label %.lr.ph22

.loopexit:                                        ; preds = %.lr.ph, %13
  %.not = icmp eq ptr %17, %2
  br i1 %.not, label %._crit_edge, label %.lr.ph22, !llvm.loop !13

.lr.ph22:                                         ; preds = %1, %.loopexit
  %.01721 = phi ptr [ %17, %.loopexit ], [ %4, %1 ]
  %5 = getelementptr inbounds i8, ptr %.01721, i64 8
  %6 = load i64, ptr %5, align 8, !tbaa !15
  %7 = add i64 %6, 32
  %8 = lshr i64 %7, 12
  %9 = and i64 %7, 4095
  %10 = icmp eq i64 %9, 0
  br i1 %10, label %13, label %11

11:                                               ; preds = %.lr.ph22
  %12 = tail call i32 (ptr, ...) @err(ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 163, ptr noundef nonnull @.str.5)
  br label %13

13:                                               ; preds = %.lr.ph22, %11
  %14 = tail call noundef nonnull align 8 dereferenceable(72) ptr @_ZN3PMM12get_instanceEv()
  %15 = load i64, ptr %.01721, align 8, !tbaa !16
  tail call void @_ZN3PMM10free_pagesEmm(ptr noundef nonnull align 8 dereferenceable(72) %14, i64 noundef %15, i64 noundef %8)
  %16 = getelementptr inbounds i8, ptr %.01721, i64 24
  %17 = load ptr, ptr %16, align 8, !tbaa !17
  %18 = getelementptr inbounds i8, ptr %.01721, i64 16
  %19 = load ptr, ptr %18, align 8, !tbaa !18
  %20 = getelementptr inbounds i8, ptr %19, i64 24
  store ptr %17, ptr %20, align 8, !tbaa !17
  %21 = getelementptr inbounds i8, ptr %17, i64 16
  store ptr %19, ptr %21, align 8, !tbaa !18
  %.not23 = icmp ult i64 %7, 4096
  br i1 %.not23, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %13, %.lr.ph
  %.019 = phi i64 [ %28, %.lr.ph ], [ 0, %13 ]
  %22 = load i64, ptr %.01721, align 8, !tbaa !16
  %23 = shl nuw i64 %.019, 12
  %24 = add i64 %22, %23
  %25 = tail call noundef nonnull align 1 dereferenceable(1) ptr @_ZN3VMM12get_instanceEv()
  %26 = tail call noundef nonnull align 1 dereferenceable(1) ptr @_ZN3VMM12get_instanceEv()
  %27 = tail call noundef ptr @_ZN3VMM7get_pgdEv(ptr noundef nonnull align 1 dereferenceable(1) %26)
  tail call void @_ZN3VMM6unmmapEPmm(ptr noundef nonnull align 1 dereferenceable(1) %25, ptr noundef %27, i64 noundef %24)
  %28 = add nuw nsw i64 %.019, 1
  %exitcond.not = icmp eq i64 %28, %8
  br i1 %exitcond.not, label %.loopexit, label %.lr.ph, !llvm.loop !19

._crit_edge:                                      ; preds = %.loopexit, %1
  %29 = tail call noundef i64 @_ZNK4SLAB7chunk_t4sizeEv(ptr noundef nonnull align 8 dereferenceable(32) %2)
  %30 = icmp eq i64 %29, 0
  br i1 %30, label %33, label %31

31:                                               ; preds = %._crit_edge
  %32 = tail call i32 (ptr, ...) @err(ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 181, ptr noundef nonnull @.str.6)
  br label %33

33:                                               ; preds = %._crit_edge, %31
  ret void
}

declare void @_ZN3PMM10free_pagesEmm(ptr noundef nonnull align 8 dereferenceable(72), i64 noundef, i64 noundef) local_unnamed_addr #1

declare void @_ZN3VMM6unmmapEPmm(ptr noundef nonnull align 1 dereferenceable(1), ptr noundef, i64 noundef) local_unnamed_addr #1

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

!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 96}
!6 = !{!"_ZTSN4SLAB12slab_cache_tE", !7, i64 0, !10, i64 8, !10, i64 40, !10, i64 72, !12, i64 104}
!7 = !{!"long", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"_ZTSN4SLAB7chunk_tE", !7, i64 0, !7, i64 8, !11, i64 16, !11, i64 24}
!11 = !{!"any pointer", !8, i64 0}
!12 = !{!"bool", !8, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = !{!10, !7, i64 8}
!16 = !{!10, !7, i64 0}
!17 = !{!10, !11, i64 24}
!18 = !{!10, !11, i64 16}
!19 = distinct !{!19, !14}


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