; LLVM IR from flingengine/FlingEngine :: FlingEngine/Utils/src/FreeList.ll (ZN5Fling8FreeListC2EPvS1_mmm)

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

%union.anon = type { ptr }
%"class.Fling::FreeList" = type { ptr }

@.str = external hidden unnamed_addr constant [15 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [92 x i8], align 1
@__PRETTY_FUNCTION__._ZN5Fling8FreeListC2EPvS1_mmm = external hidden unnamed_addr constant [66 x i8], align 1

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN5Fling8FreeListC2EPvS1_mmm(ptr noundef nonnull align 8 dereferenceable(8) %0, ptr noundef %1, ptr noundef %2, i64 noundef %3, i64 noundef %4, i64 noundef %5) unnamed_addr #0 align 2 {
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i64, align 8
  %11 = alloca i64, align 8
  %12 = alloca i64, align 8
  %13 = alloca %union.anon, align 8
  %14 = alloca ptr, align 8
  %15 = alloca i64, align 8
  %16 = alloca i64, align 8
  %17 = alloca i64, align 8
  store ptr %0, ptr %7, align 8, !tbaa !5
  store ptr %1, ptr %8, align 8, !tbaa !5
  store ptr %2, ptr %9, align 8, !tbaa !5
  store i64 %3, ptr %10, align 8, !tbaa !9
  store i64 %4, ptr %11, align 8, !tbaa !9
  store i64 %5, ptr %12, align 8, !tbaa !9
  %18 = load ptr, ptr %7, align 8
  %19 = getelementptr inbounds %"class.Fling::FreeList", ptr %18, i32 0, i32 0
  store ptr null, ptr %19, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #3
  %20 = load ptr, ptr %8, align 8, !tbaa !5
  store ptr %20, ptr %13, align 8, !tbaa !13
  %21 = load ptr, ptr %13, align 8, !tbaa !13
  %22 = getelementptr inbounds %"class.Fling::FreeList", ptr %18, i32 0, i32 0
  store ptr %21, ptr %22, align 8, !tbaa !11
  %23 = load i64, ptr %10, align 8, !tbaa !9
  %24 = load ptr, ptr %13, align 8, !tbaa !13
  %25 = getelementptr inbounds i8, ptr %24, i64 %23
  store ptr %25, ptr %13, align 8, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #3
  %26 = getelementptr inbounds %"class.Fling::FreeList", ptr %18, i32 0, i32 0
  %27 = load ptr, ptr %26, align 8, !tbaa !11
  store ptr %27, ptr %14, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #3
  %28 = load ptr, ptr %9, align 8, !tbaa !5
  %29 = load ptr, ptr %8, align 8, !tbaa !5
  %30 = ptrtoint ptr %28 to i64
  %31 = ptrtoint ptr %29 to i64
  %32 = sub i64 %30, %31
  store i64 %32, ptr %15, align 8, !tbaa !9
  %33 = load i64, ptr %15, align 8, !tbaa !9
  %34 = icmp sgt i64 %33, 0
  br i1 %34, label %35, label %36

35:                                               ; preds = %6
  br label %38

36:                                               ; preds = %6
  call void @__assert_fail(ptr noundef @.str, ptr noundef @.str.1, i32 noundef 25, ptr noundef @__PRETTY_FUNCTION__._ZN5Fling8FreeListC2EPvS1_mmm) #4
  unreachable

37:                                               ; No predecessors!
  br label %38

38:                                               ; preds = %37, %35
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #3
  %39 = load i64, ptr %15, align 8, !tbaa !9
  %40 = load i64, ptr %10, align 8, !tbaa !9
  %41 = udiv i64 %39, %40
  store i64 %41, ptr %16, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %17) #3
  store i64 1, ptr %17, align 8, !tbaa !9
  br label %42

42:                                               ; preds = %55, %38
  %43 = load i64, ptr %17, align 8, !tbaa !9
  %44 = load i64, ptr %16, align 8, !tbaa !9
  %45 = icmp ult i64 %43, %44
  br i1 %45, label %47, label %46

46:                                               ; preds = %42
  call void @llvm.lifetime.end.p0(i64 8, ptr %17) #3
  br label %58

47:                                               ; preds = %42
  %48 = load ptr, ptr %13, align 8, !tbaa !13
  %49 = load ptr, ptr %14, align 8, !tbaa !5
  %50 = getelementptr inbounds %"class.Fling::FreeList", ptr %49, i32 0, i32 0
  store ptr %48, ptr %50, align 8, !tbaa !11
  %51 = load ptr, ptr %13, align 8, !tbaa !13
  store ptr %51, ptr %14, align 8, !tbaa !5
  %52 = load i64, ptr %10, align 8, !tbaa !9
  %53 = load ptr, ptr %13, align 8, !tbaa !13
  %54 = getelementptr inbounds i8, ptr %53, i64 %52
  store ptr %54, ptr %13, align 8, !tbaa !13
  br label %55

55:                                               ; preds = %47
  %56 = load i64, ptr %17, align 8, !tbaa !9
  %57 = add i64 %56, 1
  store i64 %57, ptr %17, align 8, !tbaa !9
  br label %42, !llvm.loop !14

58:                                               ; preds = %46
  %59 = load ptr, ptr %14, align 8, !tbaa !5
  %60 = getelementptr inbounds %"class.Fling::FreeList", ptr %59, i32 0, i32 0
  store ptr null, ptr %60, align 8, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #3
  ret void
}

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

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #2

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { noreturn nounwind "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 }
attributes #4 = { noreturn 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 0}
!12 = !{!"_ZTSN5Fling8FreeListE", !6, i64 0}
!13 = !{!7, !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}


; 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 [15 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [92 x i8], align 1
@__PRETTY_FUNCTION__._ZN5Fling8FreeListC2EPvS1_mmm = external hidden unnamed_addr constant [66 x i8], align 1

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN5Fling8FreeListC2EPvS1_mmm(ptr nocapture noundef nonnull writeonly align 8 dereferenceable(8) %0, ptr noundef %1, ptr noundef %2, i64 noundef %3, i64 noundef %4, i64 noundef %5) unnamed_addr #0 align 2 {
  store ptr %1, ptr %0, align 8, !tbaa !5
  %7 = ptrtoint ptr %2 to i64
  %8 = ptrtoint ptr %1 to i64
  %9 = sub i64 %7, %8
  %10 = icmp sgt i64 %9, 0
  br i1 %10, label %12, label %11

11:                                               ; preds = %6
  tail call void @__assert_fail(ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 25, ptr noundef nonnull @__PRETTY_FUNCTION__._ZN5Fling8FreeListC2EPvS1_mmm) #2
  unreachable

12:                                               ; preds = %6
  %13 = udiv i64 %9, %3
  %14 = icmp ugt i64 %13, 1
  br i1 %14, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %12
  %15 = add nsw i64 %13, -1
  %16 = add nsw i64 %13, -2
  %xtraiter = and i64 %15, 7
  %17 = icmp ult i64 %16, 7
  br i1 %17, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph.preheader.new

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

._crit_edge.loopexit.unr-lcssa:                   ; preds = %.lr.ph, %.lr.ph.preheader
  %.sroa.0.0.lcssa.ph = phi ptr [ poison, %.lr.ph.preheader ], [ %.sroa.0.0.7, %.lr.ph ]
  %.01719.unr = phi ptr [ %1, %.lr.ph.preheader ], [ %.sroa.0.0.7, %.lr.ph ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge, label %.lr.ph.epil

.lr.ph.epil:                                      ; preds = %._crit_edge.loopexit.unr-lcssa, %.lr.ph.epil
  %.01719.epil = phi ptr [ %.sroa.0.0.epil, %.lr.ph.epil ], [ %.01719.unr, %._crit_edge.loopexit.unr-lcssa ]
  %epil.iter = phi i64 [ %epil.iter.next, %.lr.ph.epil ], [ 0, %._crit_edge.loopexit.unr-lcssa ]
  %.sroa.0.0.epil = getelementptr inbounds i8, ptr %.01719.epil, i64 %3
  store ptr %.sroa.0.0.epil, ptr %.01719.epil, 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_edge, label %.lr.ph.epil, !llvm.loop !10

._crit_edge:                                      ; preds = %._crit_edge.loopexit.unr-lcssa, %.lr.ph.epil, %12
  %.017.lcssa = phi ptr [ %1, %12 ], [ %.sroa.0.0.lcssa.ph, %._crit_edge.loopexit.unr-lcssa ], [ %.sroa.0.0.epil, %.lr.ph.epil ]
  store ptr null, ptr %.017.lcssa, align 8, !tbaa !5
  ret void

.lr.ph:                                           ; preds = %.lr.ph, %.lr.ph.preheader.new
  %.01719 = phi ptr [ %1, %.lr.ph.preheader.new ], [ %.sroa.0.0.7, %.lr.ph ]
  %niter = phi i64 [ 0, %.lr.ph.preheader.new ], [ %niter.next.7, %.lr.ph ]
  %.sroa.0.0 = getelementptr inbounds i8, ptr %.01719, i64 %3
  store ptr %.sroa.0.0, ptr %.01719, align 8, !tbaa !5
  %.sroa.0.0.1 = getelementptr inbounds i8, ptr %.sroa.0.0, i64 %3
  store ptr %.sroa.0.0.1, ptr %.sroa.0.0, align 8, !tbaa !5
  %.sroa.0.0.2 = getelementptr inbounds i8, ptr %.sroa.0.0.1, i64 %3
  store ptr %.sroa.0.0.2, ptr %.sroa.0.0.1, align 8, !tbaa !5
  %.sroa.0.0.3 = getelementptr inbounds i8, ptr %.sroa.0.0.2, i64 %3
  store ptr %.sroa.0.0.3, ptr %.sroa.0.0.2, align 8, !tbaa !5
  %.sroa.0.0.4 = getelementptr inbounds i8, ptr %.sroa.0.0.3, i64 %3
  store ptr %.sroa.0.0.4, ptr %.sroa.0.0.3, align 8, !tbaa !5
  %.sroa.0.0.5 = getelementptr inbounds i8, ptr %.sroa.0.0.4, i64 %3
  store ptr %.sroa.0.0.5, ptr %.sroa.0.0.4, align 8, !tbaa !5
  %.sroa.0.0.6 = getelementptr inbounds i8, ptr %.sroa.0.0.5, i64 %3
  store ptr %.sroa.0.0.6, ptr %.sroa.0.0.5, align 8, !tbaa !5
  %.sroa.0.0.7 = getelementptr inbounds i8, ptr %.sroa.0.0.6, i64 %3
  store ptr %.sroa.0.0.7, ptr %.sroa.0.0.6, align 8, !tbaa !5
  %niter.next.7 = add i64 %niter, 8
  %niter.ncmp.7.not = icmp eq i64 %niter.next.7, %unroll_iter
  br i1 %niter.ncmp.7.not, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph, !llvm.loop !12
}

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr 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 = { noreturn nounwind "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 = { noreturn 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, !7, i64 0}
!6 = !{!"_ZTSN5Fling8FreeListE", !7, i64 0}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.unroll.disable"}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}


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