; LLVM IR from Sopiro/Muli :: src/util/block_allocator.ll (ZN4muli14BlockAllocator5ClearEi)

; 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.muli::BlockAllocator" = type { %"class.muli::Allocator", i32, i32, [128 x i32], ptr, [128 x ptr] }
%"class.muli::Allocator" = type { ptr }

; 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 uwtable
define dso_local void @_ZN4muli14BlockAllocator5ClearEi(ptr noundef nonnull align 8 dereferenceable(1560) %0, i32 noundef %1) #1 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !9
  %6 = load ptr, ptr %3, align 8
  %7 = load ptr, ptr %6, align 8, !tbaa !11
  %8 = getelementptr inbounds ptr, ptr %7, i64 4
  %9 = load ptr, ptr %8, align 8
  call void %9(ptr noundef nonnull align 8 dereferenceable(1560) %6)
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #2
  store i32 0, ptr %5, align 4, !tbaa !9
  br label %10

10:                                               ; preds = %20, %2
  %11 = load i32, ptr %5, align 4, !tbaa !9
  %12 = icmp slt i32 %11, 128
  br i1 %12, label %14, label %13

13:                                               ; preds = %10
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  br label %23

14:                                               ; preds = %10
  %15 = load i32, ptr %4, align 4, !tbaa !9
  %16 = getelementptr inbounds %"class.muli::BlockAllocator", ptr %6, i32 0, i32 3
  %17 = load i32, ptr %5, align 4, !tbaa !9
  %18 = sext i32 %17 to i64
  %19 = getelementptr inbounds [128 x i32], ptr %16, i64 0, i64 %18
  store i32 %15, ptr %19, align 4, !tbaa !9
  br label %20

20:                                               ; preds = %14
  %21 = load i32, ptr %5, align 4, !tbaa !9
  %22 = add nsw i32 %21, 1
  store i32 %22, ptr %5, align 4, !tbaa !9
  br label %10, !llvm.loop !13

23:                                               ; preds = %13
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"vtable pointer", !8, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"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"

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN4muli14BlockAllocator5ClearEi(ptr noundef nonnull align 8 dereferenceable(1560) %0, i32 noundef %1) local_unnamed_addr #0 align 2 {
vector.ph:
  %2 = load ptr, ptr %0, align 8, !tbaa !5
  %3 = getelementptr inbounds i8, ptr %2, i64 32
  %4 = load ptr, ptr %3, align 8
  tail call void %4(ptr noundef nonnull align 8 dereferenceable(1560) %0)
  %broadcast.splatinsert = insertelement <4 x i32> poison, i32 %1, i64 0
  %broadcast.splat = shufflevector <4 x i32> %broadcast.splatinsert, <4 x i32> poison, <4 x i32> zeroinitializer
  %5 = getelementptr inbounds i8, ptr %0, i64 16
  %6 = getelementptr inbounds i8, ptr %0, i64 32
  store <4 x i32> %broadcast.splat, ptr %5, align 8, !tbaa !8
  store <4 x i32> %broadcast.splat, ptr %6, align 8, !tbaa !8
  %7 = getelementptr inbounds i8, ptr %0, i64 48
  %8 = getelementptr inbounds i8, ptr %0, i64 64
  store <4 x i32> %broadcast.splat, ptr %7, align 8, !tbaa !8
  store <4 x i32> %broadcast.splat, ptr %8, align 8, !tbaa !8
  %9 = getelementptr inbounds i8, ptr %0, i64 80
  %10 = getelementptr inbounds i8, ptr %0, i64 96
  store <4 x i32> %broadcast.splat, ptr %9, align 8, !tbaa !8
  store <4 x i32> %broadcast.splat, ptr %10, align 8, !tbaa !8
  %11 = getelementptr inbounds i8, ptr %0, i64 112
  %12 = getelementptr inbounds i8, ptr %0, i64 128
  store <4 x i32> %broadcast.splat, ptr %11, align 8, !tbaa !8
  store <4 x i32> %broadcast.splat, ptr %12, align 8, !tbaa !8
  %13 = getelementptr inbounds i8, ptr %0, i64 144
  %14 = getelementptr inbounds i8, ptr %0, i64 160
  store <4 x i32> %broadcast.splat, ptr %13, align 8, !tbaa !8
  store <4 x i32> %broadcast.splat, ptr %14, align 8, !tbaa !8
  %15 = getelementptr inbounds i8, ptr %0, i64 176
  %16 = getelementptr inbounds i8, ptr %0, i64 192
  store <4 x i32> %broadcast.splat, ptr %15, align 8, !tbaa !8
  store <4 x i32> %broadcast.splat, ptr %16, align 8, !tbaa !8
  %17 = getelementptr inbounds i8, ptr %0, i64 208
  %18 = getelementptr inbounds i8, ptr %0, i64 224
  store <4 x i32> %broadcast.splat, ptr %17, align 8, !tbaa !8
  store <4 x i32> %broadcast.splat, ptr %18, align 8, !tbaa !8
  %19 = getelementptr inbounds i8, ptr %0, i64 240
  %20 = getelementptr inbounds i8, ptr %0, i64 256
  store <4 x i32> %broadcast.splat, ptr %19, align 8, !tbaa !8
  store <4 x i32> %broadcast.splat, ptr %20, align 8, !tbaa !8
  %21 = getelementptr inbounds i8, ptr %0, i64 272
  %22 = getelementptr inbounds i8, ptr %0, i64 288
  store <4 x i32> %broadcast.splat, ptr %21, align 8, !tbaa !8
  store <4 x i32> %broadcast.splat, ptr %22, align 8, !tbaa !8
  %23 = getelementptr inbounds i8, ptr %0, i64 304
  %24 = getelementptr inbounds i8, ptr %0, i64 320
  store <4 x i32> %broadcast.splat, ptr %23, align 8, !tbaa !8
  store <4 x i32> %broadcast.splat, ptr %24, align 8, !tbaa !8
  %25 = getelementptr inbounds i8, ptr %0, i64 336
  %26 = getelementptr inbounds i8, ptr %0, i64 352
  store <4 x i32> %broadcast.splat, ptr %25, align 8, !tbaa !8
  store <4 x i32> %broadcast.splat, ptr %26, align 8, !tbaa !8
  %27 = getelementptr inbounds i8, ptr %0, i64 368
  %28 = getelementptr inbounds i8, ptr %0, i64 384
  store <4 x i32> %broadcast.splat, ptr %27, align 8, !tbaa !8
  store <4 x i32> %broadcast.splat, ptr %28, align 8, !tbaa !8
  %29 = getelementptr inbounds i8, ptr %0, i64 400
  %30 = getelementptr inbounds i8, ptr %0, i64 416
  store <4 x i32> %broadcast.splat, ptr %29, align 8, !tbaa !8
  store <4 x i32> %broadcast.splat, ptr %30, align 8, !tbaa !8
  %31 = getelementptr inbounds i8, ptr %0, i64 432
  %32 = getelementptr inbounds i8, ptr %0, i64 448
  store <4 x i32> %broadcast.splat, ptr %31, align 8, !tbaa !8
  store <4 x i32> %broadcast.splat, ptr %32, align 8, !tbaa !8
  %33 = getelementptr inbounds i8, ptr %0, i64 464
  %34 = getelementptr inbounds i8, ptr %0, i64 480
  store <4 x i32> %broadcast.splat, ptr %33, align 8, !tbaa !8
  store <4 x i32> %broadcast.splat, ptr %34, align 8, !tbaa !8
  %35 = getelementptr inbounds i8, ptr %0, i64 496
  %36 = getelementptr inbounds i8, ptr %0, i64 512
  store <4 x i32> %broadcast.splat, ptr %35, align 8, !tbaa !8
  store <4 x i32> %broadcast.splat, ptr %36, align 8, !tbaa !8
  ret void
}

attributes #0 = { 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, !6, i64 0}
!6 = !{!"vtable pointer", !7, i64 0}
!7 = !{!"Simple C++ TBAA"}
!8 = !{!9, !9, i64 0}
!9 = !{!"int", !10, i64 0}
!10 = !{!"omnipotent char", !7, i64 0}


; Effective O3 passes: GlobalOptPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,LICMPass,LoopLoadEliminationPass,LoopRotatePass,LoopUnrollPass,LoopVectorizePass,SROAPass,SimplifyCFGPass,TailCallElimPass