; LLVM IR from brewlin/garbage-collect :: mark-sweep-bitmap (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"

@.str = external hidden unnamed_addr constant [32 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [22 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local i32 @clear() #0

; 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: nounwind uwtable
define dso_local void @test_malloc_speed() #0 {
  %1 = alloca i64, align 8
  %2 = alloca i64, align 8
  %3 = alloca double, align 8
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %1) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #4
  %10 = call i64 @clock() #4
  store i64 %10, ptr %1, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #4
  store i32 0, ptr %4, align 4, !tbaa !9
  br label %11

11:                                               ; preds = %28, %0
  %12 = load i32, ptr %4, align 4, !tbaa !9
  %13 = icmp slt i32 %12, 100
  br i1 %13, label %15, label %14

14:                                               ; preds = %11
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #4
  br label %31

15:                                               ; preds = %11
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  %16 = call i32 @rand() #4
  %17 = srem i32 %16, 90
  store i32 %17, ptr %5, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  %18 = load i32, ptr %5, align 4, !tbaa !9
  %19 = sext i32 %18 to i64
  %20 = call ptr @gc_malloc(i64 noundef %19)
  store ptr %20, ptr %6, align 8, !tbaa !11
  %21 = load ptr, ptr %6, align 8, !tbaa !11
  %22 = icmp ne ptr %21, null
  br i1 %22, label %25, label %23

23:                                               ; preds = %15
  %24 = call i32 @clear()
  br label %27

25:                                               ; preds = %15
  %26 = load ptr, ptr %6, align 8, !tbaa !11
  call void @add_roots(ptr noundef %26)
  br label %27

27:                                               ; preds = %25, %23
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  br label %28

28:                                               ; preds = %27
  %29 = load i32, ptr %4, align 4, !tbaa !9
  %30 = add nsw i32 %29, 1
  store i32 %30, ptr %4, align 4, !tbaa !9
  br label %11, !llvm.loop !13

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

32:                                               ; preds = %47, %31
  %33 = load i32, ptr %7, align 4, !tbaa !9
  %34 = icmp slt i32 %33, 100
  br i1 %34, label %36, label %35

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

36:                                               ; preds = %32
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  %37 = call i32 @rand() #4
  %38 = srem i32 %37, 90
  store i32 %38, ptr %8, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  %39 = load i32, ptr %8, align 4, !tbaa !9
  %40 = sext i32 %39 to i64
  %41 = call ptr @gc_malloc(i64 noundef %40)
  store ptr %41, ptr %9, align 8, !tbaa !11
  %42 = load ptr, ptr %9, align 8, !tbaa !11
  %43 = icmp ne ptr %42, null
  br i1 %43, label %46, label %44

44:                                               ; preds = %36
  %45 = call i32 (ptr, ...) @printf(ptr noundef @.str)
  br label %46

46:                                               ; preds = %44, %36
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  br label %47

47:                                               ; preds = %46
  %48 = load i32, ptr %7, align 4, !tbaa !9
  %49 = add nsw i32 %48, 1
  store i32 %49, ptr %7, align 4, !tbaa !9
  br label %32, !llvm.loop !15

50:                                               ; preds = %35
  %51 = call i64 @clock() #4
  store i64 %51, ptr %2, align 8, !tbaa !5
  %52 = load i64, ptr %2, align 8, !tbaa !5
  %53 = load i64, ptr %1, align 8, !tbaa !5
  %54 = sub nsw i64 %52, %53
  %55 = sitofp i64 %54 to double
  %56 = fdiv double %55, 1.000000e+06
  store double %56, ptr %3, align 8, !tbaa !16
  %57 = load double, ptr %3, align 8, !tbaa !16
  %58 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, double noundef %57)
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %1) #4
  ret void
}

; Function Attrs: nounwind
declare i64 @clock() #2

; Function Attrs: nounwind
declare i32 @rand() #2

declare ptr @gc_malloc(i64 noundef) #3

declare void @add_roots(ptr noundef) #3

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

attributes #0 = { 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 = { 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 = { "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 = !{!"long", !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 = !{!"any pointer", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}
!16 = !{!17, !17, i64 0}
!17 = !{!"double", !7, i64 0}


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

; Function Attrs: nounwind uwtable
declare dso_local i32 @clear() local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @test_malloc_speed() local_unnamed_addr #0 {
  %1 = tail call i64 @clock() #4
  br label %2

2:                                                ; preds = %0, %10
  %.014 = phi i32 [ 0, %0 ], [ %11, %10 ]
  %3 = tail call i32 @rand() #4
  %4 = srem i32 %3, 90
  %5 = sext i32 %4 to i64
  %6 = tail call ptr @gc_malloc(i64 noundef %5) #4
  %.not13 = icmp eq ptr %6, null
  br i1 %.not13, label %7, label %9

7:                                                ; preds = %2
  %8 = tail call i32 @clear()
  br label %10

9:                                                ; preds = %2
  tail call void @add_roots(ptr noundef nonnull %6) #4
  br label %10

10:                                               ; preds = %9, %7
  %11 = add nuw nsw i32 %.014, 1
  %exitcond.not = icmp eq i32 %11, 100
  br i1 %exitcond.not, label %.preheader, label %2, !llvm.loop !5

12:                                               ; preds = %24
  %13 = tail call i64 @clock() #4
  %14 = sub nsw i64 %13, %1
  %15 = sitofp i64 %14 to double
  %16 = fdiv double %15, 1.000000e+06
  %17 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, double noundef %16)
  ret void

.preheader:                                       ; preds = %10, %24
  %.01115 = phi i32 [ %25, %24 ], [ 0, %10 ]
  %18 = tail call i32 @rand() #4
  %19 = srem i32 %18, 90
  %20 = sext i32 %19 to i64
  %21 = tail call ptr @gc_malloc(i64 noundef %20) #4
  %.not = icmp eq ptr %21, null
  br i1 %.not, label %22, label %24

22:                                               ; preds = %.preheader
  %23 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str)
  br label %24

24:                                               ; preds = %22, %.preheader
  %25 = add nuw nsw i32 %.01115, 1
  %exitcond16.not = icmp eq i32 %25, 100
  br i1 %exitcond16.not, label %12, label %.preheader, !llvm.loop !7
}

; Function Attrs: nounwind
declare i64 @clock() local_unnamed_addr #1

; Function Attrs: nounwind
declare i32 @rand() local_unnamed_addr #1

declare ptr @gc_malloc(i64 noundef) local_unnamed_addr #2

declare void @add_roots(ptr noundef) local_unnamed_addr #2

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #3

attributes #0 = { 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 = { 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 = { "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 = { nofree 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 = { 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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}
!7 = distinct !{!7, !6}


; Effective O3 passes: GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass