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

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

%"struct.SLAB::chunk_t" = type { i64, i64, ptr, ptr }
%"class.SLAB::slab_cache_t" = type <{ i64, %"struct.SLAB::chunk_t", %"struct.SLAB::chunk_t", %"struct.SLAB::chunk_t", i8, [7 x i8] }>

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

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

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN4SLAB12slab_cache_t5splitEPNS_7chunk_tEm(ptr noundef nonnull align 8 dereferenceable(105) %0, ptr noundef %1, i64 noundef %2) #1 align 2 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca i64, 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 i64 %2, ptr %6, align 8, !tbaa !9
  %9 = load ptr, ptr %4, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #2
  %10 = load ptr, ptr %5, align 8, !tbaa !5
  %11 = getelementptr inbounds %"struct.SLAB::chunk_t", ptr %10, i32 0, i32 1
  %12 = load i64, ptr %11, align 8, !tbaa !11
  store i64 %12, ptr %7, align 8, !tbaa !9
  %13 = load i64, ptr %6, align 8, !tbaa !9
  %14 = load ptr, ptr %5, align 8, !tbaa !5
  %15 = getelementptr inbounds %"struct.SLAB::chunk_t", ptr %14, i32 0, i32 1
  store i64 %13, ptr %15, align 8, !tbaa !11
  %16 = getelementptr inbounds %"class.SLAB::slab_cache_t", ptr %9, i32 0, i32 1
  %17 = load ptr, ptr %5, align 8, !tbaa !5
  call void @_ZN4SLAB12slab_cache_t4moveERNS_7chunk_tEPS1_(ptr noundef nonnull align 8 dereferenceable(105) %9, ptr noundef nonnull align 8 dereferenceable(32) %16, ptr noundef %17)
  %18 = load i64, ptr %7, align 8, !tbaa !9
  %19 = load i64, ptr %6, align 8, !tbaa !9
  %20 = add i64 %19, 32
  %21 = icmp ugt i64 %18, %20
  br i1 %21, label %22, label %56

22:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #2
  %23 = load ptr, ptr %5, align 8, !tbaa !5
  %24 = getelementptr inbounds %"struct.SLAB::chunk_t", ptr %23, i32 0, i32 0
  %25 = load i64, ptr %24, align 8, !tbaa !13
  %26 = add i64 %25, 32
  %27 = load i64, ptr %6, align 8, !tbaa !9
  %28 = add i64 %26, %27
  %29 = inttoptr i64 %28 to ptr
  store ptr %29, ptr %8, align 8, !tbaa !5
  %30 = load ptr, ptr %8, align 8, !tbaa !5
  %31 = ptrtoint ptr %30 to i64
  %32 = load ptr, ptr %8, align 8, !tbaa !5
  %33 = getelementptr inbounds %"struct.SLAB::chunk_t", ptr %32, i32 0, i32 0
  store i64 %31, ptr %33, align 8, !tbaa !13
  %34 = load i64, ptr %7, align 8, !tbaa !9
  %35 = load i64, ptr %6, align 8, !tbaa !9
  %36 = sub i64 %34, %35
  %37 = sub i64 %36, 32
  %38 = load ptr, ptr %8, align 8, !tbaa !5
  %39 = getelementptr inbounds %"struct.SLAB::chunk_t", ptr %38, i32 0, i32 1
  store i64 %37, ptr %39, align 8, !tbaa !11
  %40 = load ptr, ptr %8, align 8, !tbaa !5
  %41 = load ptr, ptr %8, align 8, !tbaa !5
  %42 = getelementptr inbounds %"struct.SLAB::chunk_t", ptr %41, i32 0, i32 2
  store ptr %40, ptr %42, align 8, !tbaa !14
  %43 = load ptr, ptr %8, align 8, !tbaa !5
  %44 = load ptr, ptr %8, align 8, !tbaa !5
  %45 = getelementptr inbounds %"struct.SLAB::chunk_t", ptr %44, i32 0, i32 3
  store ptr %43, ptr %45, align 8, !tbaa !15
  %46 = load ptr, ptr %8, align 8, !tbaa !5
  %47 = getelementptr inbounds %"struct.SLAB::chunk_t", ptr %46, i32 0, i32 1
  %48 = load i64, ptr %47, align 8, !tbaa !11
  %49 = getelementptr inbounds %"class.SLAB::slab_cache_t", ptr %9, i32 0, i32 0
  %50 = load i64, ptr %49, align 8, !tbaa !16
  %51 = icmp ugt i64 %48, %50
  br i1 %51, label %52, label %55

52:                                               ; preds = %22
  %53 = getelementptr inbounds %"class.SLAB::slab_cache_t", ptr %9, i32 0, i32 2
  %54 = load ptr, ptr %8, align 8, !tbaa !5
  call void @_ZN4SLAB7chunk_t9push_backEPS0_(ptr noundef nonnull align 8 dereferenceable(32) %53, ptr noundef %54)
  br label %55

55:                                               ; preds = %52, %22
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #2
  br label %56

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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 8}
!12 = !{!"_ZTSN4SLAB7chunk_tE", !10, i64 0, !10, i64 8, !6, i64 16, !6, i64 24}
!13 = !{!12, !10, i64 0}
!14 = !{!12, !6, i64 16}
!15 = !{!12, !6, i64 24}
!16 = !{!17, !10, i64 0}
!17 = !{!"_ZTSN4SLAB12slab_cache_tE", !10, i64 0, !12, i64 8, !12, i64 40, !12, i64 72, !18, i64 104}
!18 = !{!"bool", !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"

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN4SLAB7chunk_t9push_backEPS0_(ptr noundef nonnull align 8 dereferenceable(32), ptr noundef) 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 nounwind uwtable
define dso_local void @_ZN4SLAB12slab_cache_t5splitEPNS_7chunk_tEm(ptr noundef nonnull align 8 dereferenceable(105) %0, ptr noundef %1, i64 noundef %2) local_unnamed_addr #0 align 2 {
  %4 = getelementptr inbounds i8, ptr %1, i64 8
  %5 = load i64, ptr %4, align 8, !tbaa !5
  store i64 %2, ptr %4, align 8, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %0, i64 8
  tail call void @_ZN4SLAB12slab_cache_t4moveERNS_7chunk_tEPS1_(ptr noundef nonnull align 8 dereferenceable(105) %0, ptr noundef nonnull align 8 dereferenceable(32) %6, ptr noundef %1)
  %7 = add i64 %2, 32
  %8 = icmp ugt i64 %5, %7
  br i1 %8, label %9, label %22

9:                                                ; preds = %3
  %10 = load i64, ptr %1, align 8, !tbaa !11
  %11 = add i64 %7, %10
  %12 = inttoptr i64 %11 to ptr
  store i64 %11, ptr %12, align 8, !tbaa !11
  %13 = sub i64 %5, %2
  %14 = add i64 %13, -32
  %15 = getelementptr inbounds i8, ptr %12, i64 8
  store i64 %14, ptr %15, align 8, !tbaa !5
  %16 = getelementptr inbounds i8, ptr %12, i64 16
  store ptr %12, ptr %16, align 8, !tbaa !12
  %17 = getelementptr inbounds i8, ptr %12, i64 24
  store ptr %12, ptr %17, align 8, !tbaa !13
  %18 = load i64, ptr %0, align 8, !tbaa !14
  %19 = icmp ugt i64 %14, %18
  br i1 %19, label %20, label %22

20:                                               ; preds = %9
  %21 = getelementptr inbounds i8, ptr %0, i64 40
  tail call void @_ZN4SLAB7chunk_t9push_backEPS0_(ptr noundef nonnull align 8 dereferenceable(32) %21, ptr noundef nonnull %12)
  br label %22

22:                                               ; preds = %9, %20, %3
  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, !7, i64 8}
!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, !10, i64 16}
!13 = !{!6, !10, i64 24}
!14 = !{!15, !7, i64 0}
!15 = !{!"_ZTSN4SLAB12slab_cache_tE", !7, i64 0, !6, i64 8, !6, i64 40, !6, i64 72, !16, i64 104}
!16 = !{!"bool", !8, i64 0}


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