; LLVM IR from daanx/mimalloc-bench :: bench/xmalloc-test (xmalloc-test)

; 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.lran2_st = type { i64, i64, [97 x i64] }
%struct.batch = type { ptr, [4096 x ptr] }

@object_size = external dso_local global i32, align 4
@done_flag = external dso_local global i32, align 4
@possible_sizes = external hidden constant [17 x i64], align 16

; 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: nounwind uwtable
declare dso_local void @enqueue_batch(ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local ptr @mem_allocator(ptr noundef %0) #1 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  %4 = alloca %struct.lran2_st, align 8
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i64, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #4
  %9 = load ptr, ptr %2, align 8, !tbaa !5
  %10 = load i32, ptr %9, align 4, !tbaa !9
  store i32 %10, ptr %3, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 792, ptr %4) #4
  %11 = load i32, ptr %3, align 4, !tbaa !9
  %12 = sext i32 %11 to i64
  call void @lran2_init(ptr noundef %4, i64 noundef %12)
  br label %13

13:                                               ; preds = %63, %1
  %14 = load atomic volatile i32, ptr @done_flag acquire, align 4
  store i32 %14, ptr %5, align 4
  %15 = load i32, ptr %5, align 4, !tbaa !9
  %16 = icmp ne i32 %15, 0
  %17 = xor i1 %16, true
  br i1 %17, label %18, label %65

18:                                               ; preds = %13
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  %19 = call ptr @malloc(i64 noundef 32776) #5
  store ptr %19, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  store i32 0, ptr %7, align 4, !tbaa !9
  br label %20

20:                                               ; preds = %60, %18
  %21 = load i32, ptr %7, align 4, !tbaa !9
  %22 = icmp slt i32 %21, 4096
  br i1 %22, label %24, label %23

23:                                               ; preds = %20
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  br label %63

24:                                               ; preds = %20
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  %25 = load i32, ptr @object_size, align 4, !tbaa !9
  %26 = icmp sgt i32 %25, 0
  br i1 %26, label %27, label %30

27:                                               ; preds = %24
  %28 = load i32, ptr @object_size, align 4, !tbaa !9
  %29 = sext i32 %28 to i64
  br label %35

30:                                               ; preds = %24
  %31 = call i64 @lran2(ptr noundef %4)
  %32 = srem i64 %31, 17
  %33 = getelementptr inbounds [17 x i64], ptr @possible_sizes, i64 0, i64 %32
  %34 = load i64, ptr %33, align 8, !tbaa !11
  br label %35

35:                                               ; preds = %30, %27
  %36 = phi i64 [ %29, %27 ], [ %34, %30 ]
  store i64 %36, ptr %8, align 8, !tbaa !11
  %37 = load i64, ptr %8, align 8, !tbaa !11
  %38 = call ptr @malloc(i64 noundef %37) #5
  %39 = load ptr, ptr %6, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.batch, ptr %39, i32 0, i32 1
  %41 = load i32, ptr %7, align 4, !tbaa !9
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds [4096 x ptr], ptr %40, i64 0, i64 %42
  store ptr %38, ptr %43, align 8, !tbaa !5
  %44 = load ptr, ptr %6, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.batch, ptr %44, i32 0, i32 1
  %46 = load i32, ptr %7, align 4, !tbaa !9
  %47 = sext i32 %46 to i64
  %48 = getelementptr inbounds [4096 x ptr], ptr %45, i64 0, i64 %47
  %49 = load ptr, ptr %48, align 8, !tbaa !5
  %50 = load i32, ptr %7, align 4, !tbaa !9
  %51 = srem i32 %50, 256
  %52 = trunc i32 %51 to i8
  %53 = load i64, ptr %8, align 8, !tbaa !11
  %54 = icmp ugt i64 %53, 128
  br i1 %54, label %55, label %56

55:                                               ; preds = %35
  br label %58

56:                                               ; preds = %35
  %57 = load i64, ptr %8, align 8, !tbaa !11
  br label %58

58:                                               ; preds = %56, %55
  %59 = phi i64 [ 128, %55 ], [ %57, %56 ]
  call void @llvm.memset.p0.i64(ptr align 1 %49, i8 %52, i64 %59, i1 false)
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  br label %60

60:                                               ; preds = %58
  %61 = load i32, ptr %7, align 4, !tbaa !9
  %62 = add nsw i32 %61, 1
  store i32 %62, ptr %7, align 4, !tbaa !9
  br label %20, !llvm.loop !13

63:                                               ; preds = %23
  %64 = load ptr, ptr %6, align 8, !tbaa !5
  call void @enqueue_batch(ptr noundef %64)
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  br label %13, !llvm.loop !15

65:                                               ; preds = %13
  call void @llvm.lifetime.end.p0(i64 792, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #4
  ret ptr null
}

; Function Attrs: nounwind uwtable
declare hidden void @lran2_init(ptr noundef, i64 noundef) #1

; Function Attrs: allocsize(0)
declare ptr @malloc(i64 noundef) #2

; Function Attrs: nounwind uwtable
declare hidden i64 @lran2(ptr noundef) #1

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #3

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 = { allocsize(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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #4 = { nounwind }
attributes #5 = { allocsize(0) }

!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/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}


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

%struct.lran2_st = type { i64, i64, [97 x i64] }

@object_size = external dso_local local_unnamed_addr global i32, align 4
@done_flag = external dso_local global i32, align 4
@possible_sizes = external hidden local_unnamed_addr constant [17 x i64], align 16

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

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

; Function Attrs: nounwind uwtable
declare dso_local void @enqueue_batch(ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local noalias noundef ptr @mem_allocator(ptr nocapture noundef readonly %0) local_unnamed_addr #1 {
  %2 = alloca %struct.lran2_st, align 8
  %3 = load i32, ptr %0, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 792, ptr nonnull %2) #5
  %4 = sext i32 %3 to i64
  call void @lran2_init(ptr noundef nonnull %2, i64 noundef %4)
  %5 = load atomic volatile i32, ptr @done_flag acquire, align 4
  %.not17 = icmp eq i32 %5, 0
  br i1 %.not17, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %1, %.split16.us
  %6 = call dereferenceable_or_null(32776) ptr @malloc(i64 noundef 32776) #6
  %7 = getelementptr inbounds i8, ptr %6, i64 8
  %8 = load i32, ptr @object_size, align 4, !tbaa !5
  %9 = icmp sgt i32 %8, 0
  br i1 %9, label %.split.us, label %.split

.split.us:                                        ; preds = %.lr.ph
  %10 = zext nneg i32 %8 to i64
  %11 = call i64 @llvm.umin.i64(i64 %10, i64 128)
  br label %12

12:                                               ; preds = %12, %.split.us
  %indvars.iv20 = phi i64 [ %indvars.iv.next21, %12 ], [ 0, %.split.us ]
  %13 = call ptr @malloc(i64 noundef %10) #6
  %14 = getelementptr inbounds [4096 x ptr], ptr %7, i64 0, i64 %indvars.iv20
  store ptr %13, ptr %14, align 8, !tbaa !9
  %15 = trunc i64 %indvars.iv20 to i8
  call void @llvm.memset.p0.i64(ptr align 1 %13, i8 %15, i64 %11, i1 false)
  %indvars.iv.next21 = add nuw nsw i64 %indvars.iv20, 1
  %exitcond23.not = icmp eq i64 %indvars.iv.next21, 4096
  br i1 %exitcond23.not, label %.split16.us, label %12, !llvm.loop !11

.split16.us:                                      ; preds = %26, %12
  call void @enqueue_batch(ptr noundef nonnull %6)
  %16 = load atomic volatile i32, ptr @done_flag acquire, align 4
  %.not = icmp eq i32 %16, 0
  br i1 %.not, label %.lr.ph, label %._crit_edge, !llvm.loop !13

.split:                                           ; preds = %.lr.ph, %26
  %17 = phi i32 [ %27, %26 ], [ %8, %.lr.ph ]
  %indvars.iv = phi i64 [ %indvars.iv.next, %26 ], [ 0, %.lr.ph ]
  %18 = icmp sgt i32 %17, 0
  br i1 %18, label %19, label %21

19:                                               ; preds = %.split
  %20 = zext nneg i32 %17 to i64
  br label %26

21:                                               ; preds = %.split
  %22 = call i64 @lran2(ptr noundef nonnull %2)
  %23 = srem i64 %22, 17
  %24 = getelementptr inbounds [17 x i64], ptr @possible_sizes, i64 0, i64 %23
  %25 = load i64, ptr %24, align 8, !tbaa !14
  %.pre = load i32, ptr @object_size, align 4, !tbaa !5
  br label %26

26:                                               ; preds = %21, %19
  %27 = phi i32 [ %17, %19 ], [ %.pre, %21 ]
  %28 = phi i64 [ %20, %19 ], [ %25, %21 ]
  %29 = call ptr @malloc(i64 noundef %28) #6
  %30 = getelementptr inbounds [4096 x ptr], ptr %7, i64 0, i64 %indvars.iv
  store ptr %29, ptr %30, align 8, !tbaa !9
  %31 = trunc i64 %indvars.iv to i8
  %32 = call i64 @llvm.umin.i64(i64 %28, i64 128)
  call void @llvm.memset.p0.i64(ptr align 1 %29, i8 %31, i64 %32, i1 false)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, 4096
  br i1 %exitcond.not, label %.split16.us, label %.split, !llvm.loop !16

._crit_edge:                                      ; preds = %.split16.us, %1
  call void @llvm.lifetime.end.p0(i64 792, ptr nonnull %2) #5
  ret ptr null
}

; Function Attrs: nounwind uwtable
declare hidden void @lran2_init(ptr noundef, i64 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
declare hidden i64 @lran2(ptr noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #3

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i64 @llvm.umin.i64(i64, i64) #4

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 = { mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" "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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #4 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #5 = { nounwind }
attributes #6 = { allocsize(0) }

!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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}
!14 = !{!15, !15, i64 0}
!15 = !{!"long", !7, i64 0}
!16 = distinct !{!16, !12, !17}
!17 = !{!"llvm.loop.unswitch.partial.disable"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopInstSimplifyPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimpleLoopUnswitchPass,SimplifyCFGPass