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

@debug_flag = external dso_local global i32, align 4
@verbose_flag = external dso_local global i32, align 4
@num_workers = external dso_local global i32, align 4
@run_time = external dso_local global double, align 8
@object_size = external dso_local global i32, align 4
@batches = external dso_local global ptr, align 8
@counters = external dso_local global ptr, align 8
@thread_ids = external dso_local global ptr, align 8
@.str.16 = external hidden unnamed_addr constant [9 x i8], align 1
@optarg = external global ptr, align 8

; 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: allocsize(0)
declare ptr @malloc(i64 noundef) #1

declare void @free(ptr noundef) #2

; Function Attrs: nounwind uwtable
declare dso_local i32 @run_memory_free_test() #3

; Function Attrs: nounwind uwtable
declare dso_local void @usage(ptr noundef) #3

; Function Attrs: nounwind uwtable
define dso_local i32 @main(i32 noundef %0, ptr noundef %1) #3 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  store i32 0, ptr %3, align 4
  store i32 %0, ptr %4, align 4, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #5
  br label %9

9:                                                ; preds = %33, %2
  %10 = load i32, ptr %4, align 4, !tbaa !5
  %11 = load ptr, ptr %5, align 8, !tbaa !9
  %12 = call i32 @getopt(i32 noundef %10, ptr noundef %11, ptr noundef @.str.16) #5
  store i32 %12, ptr %6, align 4, !tbaa !5
  %13 = icmp ne i32 %12, -1
  br i1 %13, label %14, label %34

14:                                               ; preds = %9
  %15 = load i32, ptr %6, align 4, !tbaa !5
  switch i32 %15, label %29 [
    i32 119, label %16
    i32 116, label %19
    i32 100, label %22
    i32 115, label %23
    i32 118, label %26
  ]

16:                                               ; preds = %14
  %17 = load ptr, ptr @optarg, align 8, !tbaa !9
  %18 = call i32 @atoi(ptr noundef %17)
  store i32 %18, ptr @num_workers, align 4, !tbaa !5
  br label %33

19:                                               ; preds = %14
  %20 = load ptr, ptr @optarg, align 8, !tbaa !9
  %21 = call double @atof(ptr noundef %20)
  store double %21, ptr @run_time, align 8, !tbaa !11
  br label %33

22:                                               ; preds = %14
  store i32 1, ptr @debug_flag, align 4, !tbaa !5
  br label %33

23:                                               ; preds = %14
  %24 = load ptr, ptr @optarg, align 8, !tbaa !9
  %25 = call i32 @atoi(ptr noundef %24)
  store i32 %25, ptr @object_size, align 4, !tbaa !5
  br label %33

26:                                               ; preds = %14
  %27 = load i32, ptr @verbose_flag, align 4, !tbaa !5
  %28 = add nsw i32 %27, 1
  store i32 %28, ptr @verbose_flag, align 4, !tbaa !5
  br label %33

29:                                               ; preds = %14
  %30 = load ptr, ptr %5, align 8, !tbaa !9
  %31 = getelementptr inbounds ptr, ptr %30, i64 0
  %32 = load ptr, ptr %31, align 8, !tbaa !9
  call void @usage(ptr noundef %32)
  br label %33

33:                                               ; preds = %29, %26, %23, %22, %19, %16
  br label %9, !llvm.loop !13

34:                                               ; preds = %9
  %35 = load i32, ptr @num_workers, align 4, !tbaa !5
  %36 = sext i32 %35 to i64
  %37 = mul i64 8, %36
  %38 = mul i64 %37, 2
  %39 = call ptr @malloc(i64 noundef %38) #6
  store ptr %39, ptr @thread_ids, align 8, !tbaa !9
  %40 = load i32, ptr @num_workers, align 4, !tbaa !5
  %41 = sext i32 %40 to i64
  %42 = mul i64 64, %41
  %43 = call ptr @malloc(i64 noundef %42) #6
  store ptr %43, ptr @counters, align 8, !tbaa !9
  %44 = call i32 @run_memory_free_test()
  br label %45

45:                                               ; preds = %67, %34
  %46 = load ptr, ptr @batches, align 8, !tbaa !9
  %47 = icmp ne ptr %46, null
  br i1 %47, label %48, label %69

48:                                               ; preds = %45
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #5
  %49 = load ptr, ptr @batches, align 8, !tbaa !9
  store ptr %49, ptr %7, align 8, !tbaa !9
  %50 = load ptr, ptr %7, align 8, !tbaa !9
  %51 = getelementptr inbounds %struct.batch, ptr %50, i32 0, i32 0
  %52 = load ptr, ptr %51, align 8, !tbaa !15
  store ptr %52, ptr @batches, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #5
  store i32 0, ptr %8, align 4, !tbaa !5
  br label %53

53:                                               ; preds = %64, %48
  %54 = load i32, ptr %8, align 4, !tbaa !5
  %55 = icmp slt i32 %54, 4096
  br i1 %55, label %57, label %56

56:                                               ; preds = %53
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #5
  br label %67

57:                                               ; preds = %53
  %58 = load ptr, ptr %7, align 8, !tbaa !9
  %59 = getelementptr inbounds %struct.batch, ptr %58, i32 0, i32 1
  %60 = load i32, ptr %8, align 4, !tbaa !5
  %61 = sext i32 %60 to i64
  %62 = getelementptr inbounds [4096 x ptr], ptr %59, i64 0, i64 %61
  %63 = load ptr, ptr %62, align 8, !tbaa !9
  call void @free(ptr noundef %63)
  br label %64

64:                                               ; preds = %57
  %65 = load i32, ptr %8, align 4, !tbaa !5
  %66 = add nsw i32 %65, 1
  store i32 %66, ptr %8, align 4, !tbaa !5
  br label %53, !llvm.loop !17

67:                                               ; preds = %56
  %68 = load ptr, ptr %7, align 8, !tbaa !9
  call void @free(ptr noundef %68)
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #5
  br label %45, !llvm.loop !18

69:                                               ; preds = %45
  %70 = load ptr, ptr @thread_ids, align 8, !tbaa !9
  call void @free(ptr noundef %70)
  %71 = load ptr, ptr @counters, align 8, !tbaa !9
  call void @free(ptr noundef %71)
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #5
  ret i32 0
}

; Function Attrs: nounwind
declare i32 @getopt(i32 noundef, ptr noundef, ptr noundef) #4

declare i32 @atoi(ptr noundef) #2

declare double @atof(ptr noundef) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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" }
attributes #3 = { 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 #4 = { 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 #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 = !{!12, !12, i64 0}
!12 = !{!"double", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = !{!16, !10, i64 0}
!16 = !{!"batch", !10, i64 0, !7, i64 8}
!17 = distinct !{!17, !14}
!18 = distinct !{!18, !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"

@debug_flag = external dso_local local_unnamed_addr global i32, align 4
@verbose_flag = external dso_local local_unnamed_addr global i32, align 4
@num_workers = external dso_local local_unnamed_addr global i32, align 4
@run_time = external dso_local local_unnamed_addr global double, align 8
@object_size = external dso_local local_unnamed_addr global i32, align 4
@batches = external dso_local local_unnamed_addr global ptr, align 8
@counters = external dso_local local_unnamed_addr global ptr, align 8
@thread_ids = external dso_local local_unnamed_addr global ptr, align 8
@.str.16 = external hidden unnamed_addr constant [9 x i8], align 1
@optarg = external local_unnamed_addr global ptr, align 8

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

; Function Attrs: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local i32 @run_memory_free_test() local_unnamed_addr #2

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

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @main(i32 noundef %0, ptr noundef %1) local_unnamed_addr #2 {
  br label %3

3:                                                ; preds = %.backedge, %2
  %4 = tail call i32 @getopt(i32 noundef %0, ptr noundef %1, ptr noundef nonnull @.str.16) #5
  switch i32 %4, label %18 [
    i32 -1, label %20
    i32 119, label %5
    i32 116, label %8
    i32 100, label %11
    i32 115, label %12
    i32 118, label %15
  ]

5:                                                ; preds = %3
  %6 = load ptr, ptr @optarg, align 8, !tbaa !5
  %7 = tail call i32 @atoi(ptr nocapture noundef %6)
  store i32 %7, ptr @num_workers, align 4, !tbaa !9
  br label %.backedge

8:                                                ; preds = %3
  %9 = load ptr, ptr @optarg, align 8, !tbaa !5
  %10 = tail call double @atof(ptr noundef %9)
  store double %10, ptr @run_time, align 8, !tbaa !11
  br label %.backedge

11:                                               ; preds = %3
  store i32 1, ptr @debug_flag, align 4, !tbaa !9
  br label %.backedge

12:                                               ; preds = %3
  %13 = load ptr, ptr @optarg, align 8, !tbaa !5
  %14 = tail call i32 @atoi(ptr nocapture noundef %13)
  store i32 %14, ptr @object_size, align 4, !tbaa !9
  br label %.backedge

15:                                               ; preds = %3
  %16 = load i32, ptr @verbose_flag, align 4, !tbaa !9
  %17 = add nsw i32 %16, 1
  store i32 %17, ptr @verbose_flag, align 4, !tbaa !9
  br label %.backedge

18:                                               ; preds = %3
  %19 = load ptr, ptr %1, align 8, !tbaa !5
  tail call void @usage(ptr noundef %19)
  br label %.backedge

.backedge:                                        ; preds = %18, %15, %12, %11, %8, %5
  br label %3, !llvm.loop !13

20:                                               ; preds = %3
  %21 = load i32, ptr @num_workers, align 4, !tbaa !9
  %22 = sext i32 %21 to i64
  %23 = shl nsw i64 %22, 4
  %24 = tail call ptr @malloc(i64 noundef %23) #6
  store ptr %24, ptr @thread_ids, align 8, !tbaa !5
  %25 = shl nsw i64 %22, 6
  %26 = tail call ptr @malloc(i64 noundef %25) #6
  store ptr %26, ptr @counters, align 8, !tbaa !5
  %27 = tail call i32 @run_memory_free_test()
  %28 = load ptr, ptr @batches, align 8, !tbaa !5
  %.not1113 = icmp eq ptr %28, null
  br i1 %.not1113, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %20, %32
  %29 = phi ptr [ %33, %32 ], [ %28, %20 ]
  %30 = load ptr, ptr %29, align 8, !tbaa !15
  store ptr %30, ptr @batches, align 8, !tbaa !5
  %31 = getelementptr inbounds i8, ptr %29, i64 8
  br label %34

32:                                               ; preds = %34
  tail call void @free(ptr noundef nonnull %29)
  %33 = load ptr, ptr @batches, align 8, !tbaa !5
  %.not11 = icmp eq ptr %33, null
  br i1 %.not11, label %._crit_edge, label %.lr.ph, !llvm.loop !17

34:                                               ; preds = %.lr.ph, %34
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %34 ]
  %35 = getelementptr inbounds [4096 x ptr], ptr %31, i64 0, i64 %indvars.iv
  %36 = load ptr, ptr %35, align 8, !tbaa !5
  tail call void @free(ptr noundef %36)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, 4096
  br i1 %exitcond.not, label %32, label %34, !llvm.loop !18

._crit_edge:                                      ; preds = %32, %20
  %37 = load ptr, ptr @thread_ids, align 8, !tbaa !5
  tail call void @free(ptr noundef %37)
  %38 = load ptr, ptr @counters, align 8, !tbaa !5
  tail call void @free(ptr noundef %38)
  ret i32 0
}

; Function Attrs: nounwind
declare i32 @getopt(i32 noundef, ptr noundef, ptr noundef) local_unnamed_addr #3

; Function Attrs: mustprogress nofree nounwind willreturn memory(read)
declare i32 @atoi(ptr nocapture noundef) local_unnamed_addr #4

; Function Attrs: mustprogress nofree nounwind willreturn memory(read)
declare double @atof(ptr nocapture noundef) local_unnamed_addr #4

attributes #0 = { 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 #1 = { mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, 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 #2 = { 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 #3 = { 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 #4 = { mustprogress nofree nounwind willreturn memory(read) "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 #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 = !{!"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 = !{!"double", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = !{!16, !6, i64 0}
!16 = !{!"batch", !6, i64 0, !7, i64 8}
!17 = distinct !{!17, !14}
!18 = distinct !{!18, !14}


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