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

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

; 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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN4SLAB12slab_cache_t4moveERNS_7chunk_tEPS1_(ptr noundef nonnull align 8 dereferenceable(105), ptr noundef nonnull align 8 dereferenceable(32), ptr noundef) #0 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN4SLAB12slab_cache_t8free_pmmEv(ptr noundef nonnull align 8 dereferenceable(105)) #2 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN4SLAB12slab_cache_t5mergeEv(ptr noundef nonnull align 8 dereferenceable(105) %0) #2 align 2 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  %5 = load ptr, ptr %2, align 8
  %6 = getelementptr inbounds %"class.SLAB::slab_cache_t", ptr %5, i32 0, i32 2
  %7 = call noundef i64 @_ZNK4SLAB7chunk_t4sizeEv(ptr noundef nonnull align 8 dereferenceable(32) %6)
  %8 = icmp ult i64 %7, 2
  br i1 %8, label %9, label %10

9:                                                ; preds = %1
  br label %100

10:                                               ; preds = %1
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #3
  %11 = getelementptr inbounds %"class.SLAB::slab_cache_t", ptr %5, i32 0, i32 2
  %12 = getelementptr inbounds %"struct.SLAB::chunk_t", ptr %11, i32 0, i32 3
  %13 = load ptr, ptr %12, align 8, !tbaa !9
  store ptr %13, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  %14 = load ptr, ptr %3, align 8, !tbaa !5
  %15 = getelementptr inbounds %"struct.SLAB::chunk_t", ptr %14, i32 0, i32 3
  %16 = load ptr, ptr %15, align 8, !tbaa !14
  store ptr %16, ptr %4, align 8, !tbaa !5
  br label %17

17:                                               ; preds = %69, %10
  %18 = load ptr, ptr %3, align 8, !tbaa !5
  %19 = getelementptr inbounds %"class.SLAB::slab_cache_t", ptr %5, i32 0, i32 2
  %20 = icmp ne ptr %18, %19
  br i1 %20, label %21, label %73

21:                                               ; preds = %17
  br label %22

22:                                               ; preds = %65, %21
  %23 = load ptr, ptr %3, align 8, !tbaa !5
  %24 = load ptr, ptr %4, align 8, !tbaa !5
  %25 = icmp ne ptr %23, %24
  br i1 %25, label %26, label %69

26:                                               ; preds = %22
  %27 = load ptr, ptr %3, align 8, !tbaa !5
  %28 = getelementptr inbounds %"struct.SLAB::chunk_t", ptr %27, i32 0, i32 0
  %29 = load i64, ptr %28, align 8, !tbaa !15
  %30 = add i64 %29, 32
  %31 = load ptr, ptr %3, align 8, !tbaa !5
  %32 = getelementptr inbounds %"struct.SLAB::chunk_t", ptr %31, i32 0, i32 1
  %33 = load i64, ptr %32, align 8, !tbaa !16
  %34 = add i64 %30, %33
  %35 = load ptr, ptr %4, align 8, !tbaa !5
  %36 = getelementptr inbounds %"struct.SLAB::chunk_t", ptr %35, i32 0, i32 0
  %37 = load i64, ptr %36, align 8, !tbaa !15
  %38 = icmp eq i64 %34, %37
  br i1 %38, label %39, label %65

39:                                               ; preds = %26
  %40 = load ptr, ptr %3, align 8, !tbaa !5
  %41 = getelementptr inbounds %"struct.SLAB::chunk_t", ptr %40, i32 0, i32 1
  %42 = load i64, ptr %41, align 8, !tbaa !16
  %43 = add i64 %42, 32
  store i64 %43, ptr %41, align 8, !tbaa !16
  %44 = load ptr, ptr %4, align 8, !tbaa !5
  %45 = getelementptr inbounds %"struct.SLAB::chunk_t", ptr %44, i32 0, i32 1
  %46 = load i64, ptr %45, align 8, !tbaa !16
  %47 = load ptr, ptr %3, align 8, !tbaa !5
  %48 = getelementptr inbounds %"struct.SLAB::chunk_t", ptr %47, i32 0, i32 1
  %49 = load i64, ptr %48, align 8, !tbaa !16
  %50 = add i64 %49, %46
  store i64 %50, ptr %48, align 8, !tbaa !16
  %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 !14
  %54 = load ptr, ptr %4, align 8, !tbaa !5
  %55 = getelementptr inbounds %"struct.SLAB::chunk_t", ptr %54, i32 0, i32 2
  %56 = load ptr, ptr %55, align 8, !tbaa !17
  %57 = getelementptr inbounds %"struct.SLAB::chunk_t", ptr %56, i32 0, i32 3
  store ptr %53, ptr %57, align 8, !tbaa !14
  %58 = load ptr, ptr %4, align 8, !tbaa !5
  %59 = getelementptr inbounds %"struct.SLAB::chunk_t", ptr %58, i32 0, i32 2
  %60 = load ptr, ptr %59, align 8, !tbaa !17
  %61 = load ptr, ptr %4, align 8, !tbaa !5
  %62 = getelementptr inbounds %"struct.SLAB::chunk_t", ptr %61, i32 0, i32 3
  %63 = load ptr, ptr %62, align 8, !tbaa !14
  %64 = getelementptr inbounds %"struct.SLAB::chunk_t", ptr %63, i32 0, i32 2
  store ptr %60, ptr %64, align 8, !tbaa !17
  br label %69

65:                                               ; preds = %26
  %66 = load ptr, ptr %4, align 8, !tbaa !5
  %67 = getelementptr inbounds %"struct.SLAB::chunk_t", ptr %66, i32 0, i32 3
  %68 = load ptr, ptr %67, align 8, !tbaa !14
  store ptr %68, ptr %4, align 8, !tbaa !5
  br label %22, !llvm.loop !18

69:                                               ; preds = %39, %22
  %70 = load ptr, ptr %3, align 8, !tbaa !5
  %71 = getelementptr inbounds %"struct.SLAB::chunk_t", ptr %70, i32 0, i32 3
  %72 = load ptr, ptr %71, align 8, !tbaa !14
  store ptr %72, ptr %3, align 8, !tbaa !5
  br label %17, !llvm.loop !20

73:                                               ; preds = %17
  %74 = getelementptr inbounds %"class.SLAB::slab_cache_t", ptr %5, i32 0, i32 2
  %75 = getelementptr inbounds %"struct.SLAB::chunk_t", ptr %74, i32 0, i32 3
  %76 = load ptr, ptr %75, align 8, !tbaa !9
  store ptr %76, ptr %4, align 8, !tbaa !5
  br label %77

77:                                               ; preds = %98, %73
  %78 = load ptr, ptr %4, align 8, !tbaa !5
  %79 = getelementptr inbounds %"class.SLAB::slab_cache_t", ptr %5, i32 0, i32 2
  %80 = icmp ne ptr %78, %79
  br i1 %80, label %81, label %99

81:                                               ; preds = %77
  %82 = load ptr, ptr %4, align 8, !tbaa !5
  %83 = getelementptr inbounds %"struct.SLAB::chunk_t", ptr %82, i32 0, i32 1
  %84 = load i64, ptr %83, align 8, !tbaa !16
  %85 = add i64 %84, 32
  %86 = urem i64 %85, 4096
  %87 = icmp eq i64 %86, 0
  br i1 %87, label %88, label %94

88:                                               ; preds = %81
  %89 = getelementptr inbounds %"class.SLAB::slab_cache_t", ptr %5, i32 0, i32 3
  %90 = load ptr, ptr %4, align 8, !tbaa !5
  call void @_ZN4SLAB12slab_cache_t4moveERNS_7chunk_tEPS1_(ptr noundef nonnull align 8 dereferenceable(105) %5, ptr noundef nonnull align 8 dereferenceable(32) %89, ptr noundef %90)
  %91 = getelementptr inbounds %"class.SLAB::slab_cache_t", ptr %5, i32 0, i32 2
  %92 = getelementptr inbounds %"struct.SLAB::chunk_t", ptr %91, i32 0, i32 3
  %93 = load ptr, ptr %92, align 8, !tbaa !9
  store ptr %93, ptr %4, align 8, !tbaa !5
  br label %98

94:                                               ; preds = %81
  %95 = load ptr, ptr %4, align 8, !tbaa !5
  %96 = getelementptr inbounds %"struct.SLAB::chunk_t", ptr %95, i32 0, i32 3
  %97 = load ptr, ptr %96, align 8, !tbaa !14
  store ptr %97, ptr %4, align 8, !tbaa !5
  br label %98

98:                                               ; preds = %94, %88
  br label %77, !llvm.loop !21

99:                                               ; preds = %77
  call void @_ZN4SLAB12slab_cache_t8free_pmmEv(ptr noundef nonnull align 8 dereferenceable(105) %5)
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  br label %100

100:                                              ; preds = %99, %9
  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 = { 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 = { 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 64}
!10 = !{!"_ZTSN4SLAB12slab_cache_tE", !11, i64 0, !12, i64 8, !12, i64 40, !12, i64 72, !13, i64 104}
!11 = !{!"long", !7, i64 0}
!12 = !{!"_ZTSN4SLAB7chunk_tE", !11, i64 0, !11, i64 8, !6, i64 16, !6, i64 24}
!13 = !{!"bool", !7, i64 0}
!14 = !{!12, !6, i64 24}
!15 = !{!12, !11, i64 0}
!16 = !{!12, !11, i64 8}
!17 = !{!12, !6, i64 16}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}
!20 = distinct !{!20, !19}
!21 = distinct !{!21, !19}


; 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 noundef i64 @_ZNK4SLAB7chunk_t4sizeEv(ptr noundef nonnull align 8 dereferenceable(32)) local_unnamed_addr #0 align 2

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN4SLAB12slab_cache_t8free_pmmEv(ptr noundef nonnull align 8 dereferenceable(105)) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN4SLAB12slab_cache_t5mergeEv(ptr noundef nonnull align 8 dereferenceable(105) %0) local_unnamed_addr #1 align 2 {
  %2 = getelementptr inbounds i8, ptr %0, i64 40
  %3 = tail call noundef i64 @_ZNK4SLAB7chunk_t4sizeEv(ptr noundef nonnull align 8 dereferenceable(32) %2)
  %4 = icmp ult i64 %3, 2
  br i1 %4, label %44, label %5

5:                                                ; preds = %1
  %6 = getelementptr inbounds i8, ptr %0, i64 64
  %7 = load ptr, ptr %6, align 8, !tbaa !5
  %.not31 = icmp eq ptr %7, %2
  br i1 %.not31, label %.preheader, label %.preheader25.preheader

.preheader25.preheader:                           ; preds = %5
  %8 = getelementptr inbounds i8, ptr %7, i64 24
  %9 = load ptr, ptr %8, align 8, !tbaa !5
  br label %.preheader25

.preheader25:                                     ; preds = %.preheader25.preheader, %.loopexit
  %.034 = phi ptr [ %.127, %.loopexit ], [ %9, %.preheader25.preheader ]
  %.02132 = phi ptr [ %33, %.loopexit ], [ %7, %.preheader25.preheader ]
  %.not2429 = icmp eq ptr %.02132, %.034
  br i1 %.not2429, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %.preheader25
  %10 = load i64, ptr %.02132, align 8, !tbaa !11
  %11 = getelementptr inbounds i8, ptr %.02132, i64 8
  %12 = load i64, ptr %11, align 8, !tbaa !12
  %13 = add i64 %12, 32
  %14 = add i64 %13, %10
  br label %16

.preheader.loopexit:                              ; preds = %.loopexit
  %.235.pre = load ptr, ptr %6, align 8, !tbaa !5
  br label %.preheader

.preheader:                                       ; preds = %.preheader.loopexit, %5
  %.235 = phi ptr [ %.235.pre, %.preheader.loopexit ], [ %7, %5 ]
  %.not2336 = icmp eq ptr %.235, %2
  br i1 %.not2336, label %._crit_edge, label %.lr.ph38

.lr.ph38:                                         ; preds = %.preheader
  %15 = getelementptr inbounds i8, ptr %0, i64 72
  br label %34

16:                                               ; preds = %.lr.ph, %29
  %.130 = phi ptr [ %.034, %.lr.ph ], [ %31, %29 ]
  %17 = load i64, ptr %.130, align 8, !tbaa !11
  %18 = icmp eq i64 %14, %17
  br i1 %18, label %19, label %29

19:                                               ; preds = %16
  store i64 %13, ptr %11, align 8, !tbaa !12
  %20 = getelementptr inbounds i8, ptr %.130, i64 8
  %21 = load i64, ptr %20, align 8, !tbaa !12
  %22 = add i64 %21, %13
  store i64 %22, ptr %11, align 8, !tbaa !12
  %23 = getelementptr inbounds i8, ptr %.130, i64 24
  %24 = load ptr, ptr %23, align 8, !tbaa !5
  %25 = getelementptr inbounds i8, ptr %.130, i64 16
  %26 = load ptr, ptr %25, align 8, !tbaa !13
  %27 = getelementptr inbounds i8, ptr %26, i64 24
  store ptr %24, ptr %27, align 8, !tbaa !5
  %28 = getelementptr inbounds i8, ptr %24, i64 16
  store ptr %26, ptr %28, align 8, !tbaa !13
  br label %.loopexit

29:                                               ; preds = %16
  %30 = getelementptr inbounds i8, ptr %.130, i64 24
  %31 = load ptr, ptr %30, align 8, !tbaa !5
  %.not24 = icmp eq ptr %.02132, %31
  br i1 %.not24, label %.loopexit, label %16, !llvm.loop !14

.loopexit:                                        ; preds = %29, %.preheader25, %19
  %.127 = phi ptr [ %.130, %19 ], [ %.034, %.preheader25 ], [ %31, %29 ]
  %32 = getelementptr inbounds i8, ptr %.02132, i64 24
  %33 = load ptr, ptr %32, align 8, !tbaa !5
  %.not = icmp eq ptr %33, %2
  br i1 %.not, label %.preheader.loopexit, label %.preheader25, !llvm.loop !16

34:                                               ; preds = %.lr.ph38, %43
  %.237 = phi ptr [ %.235, %.lr.ph38 ], [ %.2, %43 ]
  %35 = getelementptr inbounds i8, ptr %.237, i64 8
  %36 = load i64, ptr %35, align 8, !tbaa !12
  %37 = add i64 %36, 32
  %38 = and i64 %37, 4095
  %39 = icmp eq i64 %38, 0
  br i1 %39, label %40, label %41

40:                                               ; preds = %34
  tail call void @_ZN4SLAB12slab_cache_t4moveERNS_7chunk_tEPS1_(ptr noundef nonnull align 8 dereferenceable(105) %0, ptr noundef nonnull align 8 dereferenceable(32) %15, ptr noundef nonnull %.237)
  br label %43

41:                                               ; preds = %34
  %42 = getelementptr inbounds i8, ptr %.237, i64 24
  br label %43

43:                                               ; preds = %41, %40
  %.3.in = phi ptr [ %6, %40 ], [ %42, %41 ]
  %.2 = load ptr, ptr %.3.in, align 8, !tbaa !5
  %.not23 = icmp eq ptr %.2, %2
  br i1 %.not23, label %._crit_edge, label %34, !llvm.loop !17

._crit_edge:                                      ; preds = %43, %.preheader
  tail call void @_ZN4SLAB12slab_cache_t8free_pmmEv(ptr noundef nonnull align 8 dereferenceable(105) %0)
  br label %44

44:                                               ; preds = %1, %._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" }
attributes #1 = { 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, !10, i64 24}
!6 = !{!"_ZTSN4SLAB7chunk_tE", !7, i64 0, !7, i64 8, !10, i64 16, !10, i64 24}
!7 = !{!"long", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!6, !7, i64 0}
!12 = !{!6, !7, i64 8}
!13 = !{!6, !10, i64 16}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = distinct !{!16, !15}
!17 = distinct !{!17, !15}


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