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

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

@.str = external hidden unnamed_addr constant [30 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [76 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [14 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [15 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

; Function Attrs: mustprogress uwtable
define dso_local noundef nonnull align 8 dereferenceable(32) ptr @_ZNK4SLAB7chunk_tixEm(ptr noundef nonnull align 8 dereferenceable(32) %0, i64 noundef %1) #2 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca i64, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i64, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i64 %1, ptr %4, align 8, !tbaa !9
  %8 = load ptr, ptr %3, align 8
  %9 = load i64, ptr %4, align 8, !tbaa !9
  %10 = call noundef i64 @_ZNK4SLAB7chunk_t4sizeEv(ptr noundef nonnull align 8 dereferenceable(32) %8)
  %11 = icmp ult i64 %9, %10
  br i1 %11, label %12, label %13

12:                                               ; preds = %2
  br label %15

13:                                               ; preds = %2
  %14 = call i32 (ptr, ...) @err(ptr noundef @.str, ptr noundef @.str.1, i32 noundef 58, ptr noundef @.str.2)
  br label %15

15:                                               ; preds = %13, %12
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  store ptr null, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  store ptr %8, ptr %6, align 8, !tbaa !5
  br label %16

16:                                               ; preds = %33, %15
  %17 = load ptr, ptr %6, align 8, !tbaa !5
  %18 = getelementptr inbounds %"struct.SLAB::chunk_t", ptr %17, i32 0, i32 3
  %19 = load ptr, ptr %18, align 8, !tbaa !11
  %20 = icmp ne ptr %19, %8
  br i1 %20, label %21, label %37

21:                                               ; preds = %16
  %22 = load ptr, ptr %6, align 8, !tbaa !5
  %23 = getelementptr inbounds %"struct.SLAB::chunk_t", ptr %22, i32 0, i32 0
  %24 = load i64, ptr %23, align 8, !tbaa !13
  %25 = icmp eq i64 %24, 52685
  br i1 %25, label %26, label %33

26:                                               ; preds = %21
  %27 = load ptr, ptr %6, align 8, !tbaa !5
  %28 = getelementptr inbounds %"struct.SLAB::chunk_t", ptr %27, i32 0, i32 1
  %29 = load i64, ptr %28, align 8, !tbaa !14
  %30 = icmp eq i64 %29, 52685
  br i1 %30, label %31, label %33

31:                                               ; preds = %26
  %32 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %32, ptr %5, align 8, !tbaa !5
  br label %37

33:                                               ; preds = %26, %21
  %34 = load ptr, ptr %6, align 8, !tbaa !5
  %35 = getelementptr inbounds %"struct.SLAB::chunk_t", ptr %34, i32 0, i32 3
  %36 = load ptr, ptr %35, align 8, !tbaa !11
  store ptr %36, ptr %6, align 8, !tbaa !5
  br label %16, !llvm.loop !15

37:                                               ; preds = %31, %16
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  store i64 0, ptr %7, align 8, !tbaa !9
  br label %38

38:                                               ; preds = %47, %37
  %39 = load i64, ptr %7, align 8, !tbaa !9
  %40 = load i64, ptr %4, align 8, !tbaa !9
  %41 = icmp ult i64 %39, %40
  br i1 %41, label %43, label %42

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

43:                                               ; preds = %38
  %44 = load ptr, ptr %5, align 8, !tbaa !5
  %45 = getelementptr inbounds %"struct.SLAB::chunk_t", ptr %44, i32 0, i32 3
  %46 = load ptr, ptr %45, align 8, !tbaa !11
  store ptr %46, ptr %5, align 8, !tbaa !5
  br label %47

47:                                               ; preds = %43
  %48 = load i64, ptr %7, align 8, !tbaa !9
  %49 = add i64 %48, 1
  store i64 %49, ptr %7, align 8, !tbaa !9
  br label %38, !llvm.loop !17

50:                                               ; preds = %42
  %51 = load ptr, ptr %5, align 8, !tbaa !5
  %52 = icmp ne ptr %51, null
  br i1 %52, label %53, label %54

53:                                               ; preds = %50
  br label %56

54:                                               ; preds = %50
  %55 = call i32 (ptr, ...) @err(ptr noundef @.str, ptr noundef @.str.1, i32 noundef 74, ptr noundef @.str.3)
  br label %56

56:                                               ; preds = %54, %53
  %57 = load ptr, ptr %5, 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
  ret ptr %57
}

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

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 = { "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 24}
!12 = !{!"_ZTSN4SLAB7chunk_tE", !10, i64 0, !10, i64 8, !6, i64 16, !6, i64 24}
!13 = !{!12, !10, i64 0}
!14 = !{!12, !10, i64 8}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = distinct !{!17, !16}


; 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.2 = external hidden unnamed_addr constant [14 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [15 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

; Function Attrs: mustprogress uwtable
define dso_local noundef nonnull align 8 dereferenceable(32) ptr @_ZNK4SLAB7chunk_tixEm(ptr noundef nonnull align 8 dereferenceable(32) %0, i64 noundef %1) local_unnamed_addr #1 align 2 {
  %3 = tail call noundef i64 @_ZNK4SLAB7chunk_t4sizeEv(ptr noundef nonnull align 8 dereferenceable(32) %0)
  %4 = icmp ugt i64 %3, %1
  br i1 %4, label %7, label %5

5:                                                ; preds = %2
  %6 = tail call i32 (ptr, ...) @err(ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 58, ptr noundef nonnull @.str.2)
  br label %7

7:                                                ; preds = %2, %5
  %8 = getelementptr inbounds i8, ptr %0, i64 24
  %9 = load ptr, ptr %8, align 8, !tbaa !5
  %.not15 = icmp eq ptr %9, %0
  br i1 %.not15, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %7, %17
  %10 = phi ptr [ %19, %17 ], [ %9, %7 ]
  %.01216 = phi ptr [ %10, %17 ], [ %0, %7 ]
  %11 = load i64, ptr %.01216, align 8, !tbaa !11
  %12 = icmp eq i64 %11, 52685
  br i1 %12, label %13, label %17

13:                                               ; preds = %.lr.ph
  %14 = getelementptr inbounds i8, ptr %.01216, i64 8
  %15 = load i64, ptr %14, align 8, !tbaa !12
  %16 = icmp eq i64 %15, 52685
  br i1 %16, label %._crit_edge, label %17

17:                                               ; preds = %13, %.lr.ph
  %18 = getelementptr inbounds i8, ptr %10, i64 24
  %19 = load ptr, ptr %18, align 8, !tbaa !5
  %.not = icmp eq ptr %19, %0
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !13

._crit_edge:                                      ; preds = %17, %13, %7
  %.013 = phi ptr [ null, %7 ], [ %.01216, %13 ], [ null, %17 ]
  %.not25 = icmp eq i64 %1, 0
  br i1 %.not25, label %._crit_edge23, label %.lr.ph22.preheader

.lr.ph22.preheader:                               ; preds = %._crit_edge
  %xtraiter = and i64 %1, 7
  %20 = icmp ult i64 %1, 8
  br i1 %20, label %._crit_edge23.loopexit.unr-lcssa, label %.lr.ph22.preheader.new

.lr.ph22.preheader.new:                           ; preds = %.lr.ph22.preheader
  %unroll_iter = and i64 %1, -8
  br label %.lr.ph22

._crit_edge23.loopexit.unr-lcssa:                 ; preds = %.lr.ph22, %.lr.ph22.preheader
  %.lcssa.ph = phi ptr [ poison, %.lr.ph22.preheader ], [ %38, %.lr.ph22 ]
  %.119.unr = phi ptr [ %.013, %.lr.ph22.preheader ], [ %38, %.lr.ph22 ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge23, label %.lr.ph22.epil

.lr.ph22.epil:                                    ; preds = %._crit_edge23.loopexit.unr-lcssa, %.lr.ph22.epil
  %.119.epil = phi ptr [ %22, %.lr.ph22.epil ], [ %.119.unr, %._crit_edge23.loopexit.unr-lcssa ]
  %epil.iter = phi i64 [ %epil.iter.next, %.lr.ph22.epil ], [ 0, %._crit_edge23.loopexit.unr-lcssa ]
  %21 = getelementptr inbounds i8, ptr %.119.epil, i64 24
  %22 = load ptr, ptr %21, align 8, !tbaa !5
  %epil.iter.next = add i64 %epil.iter, 1
  %epil.iter.cmp.not = icmp eq i64 %epil.iter.next, %xtraiter
  br i1 %epil.iter.cmp.not, label %._crit_edge23, label %.lr.ph22.epil, !llvm.loop !15

._crit_edge23:                                    ; preds = %._crit_edge23.loopexit.unr-lcssa, %.lr.ph22.epil, %._crit_edge
  %.1.lcssa = phi ptr [ %.013, %._crit_edge ], [ %.lcssa.ph, %._crit_edge23.loopexit.unr-lcssa ], [ %22, %.lr.ph22.epil ]
  %.not14 = icmp eq ptr %.1.lcssa, null
  br i1 %.not14, label %39, label %41

.lr.ph22:                                         ; preds = %.lr.ph22, %.lr.ph22.preheader.new
  %.119 = phi ptr [ %.013, %.lr.ph22.preheader.new ], [ %38, %.lr.ph22 ]
  %niter = phi i64 [ 0, %.lr.ph22.preheader.new ], [ %niter.next.7, %.lr.ph22 ]
  %23 = getelementptr inbounds i8, ptr %.119, i64 24
  %24 = load ptr, ptr %23, align 8, !tbaa !5
  %25 = getelementptr inbounds i8, ptr %24, i64 24
  %26 = load ptr, ptr %25, align 8, !tbaa !5
  %27 = getelementptr inbounds i8, ptr %26, i64 24
  %28 = load ptr, ptr %27, align 8, !tbaa !5
  %29 = getelementptr inbounds i8, ptr %28, i64 24
  %30 = load ptr, ptr %29, align 8, !tbaa !5
  %31 = getelementptr inbounds i8, ptr %30, i64 24
  %32 = load ptr, ptr %31, align 8, !tbaa !5
  %33 = getelementptr inbounds i8, ptr %32, i64 24
  %34 = load ptr, ptr %33, align 8, !tbaa !5
  %35 = getelementptr inbounds i8, ptr %34, i64 24
  %36 = load ptr, ptr %35, align 8, !tbaa !5
  %37 = getelementptr inbounds i8, ptr %36, i64 24
  %38 = load ptr, ptr %37, align 8, !tbaa !5
  %niter.next.7 = add i64 %niter, 8
  %niter.ncmp.7 = icmp eq i64 %niter.next.7, %unroll_iter
  br i1 %niter.ncmp.7, label %._crit_edge23.loopexit.unr-lcssa, label %.lr.ph22, !llvm.loop !17

39:                                               ; preds = %._crit_edge23
  %40 = tail call i32 (ptr, ...) @err(ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 74, ptr noundef nonnull @.str.3)
  br label %41

41:                                               ; preds = %._crit_edge23, %39
  ret ptr %.1.lcssa
}

declare i32 @err(ptr noundef, ...) local_unnamed_addr #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 = { 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 #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" }

!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 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.unroll.disable"}
!17 = distinct !{!17, !14}


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