; LLVM IR from jermp/2i_bench :: external/CRoaring/tests (toplevel_unit)

; 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.2 = external hidden unnamed_addr constant [88 x i8], align 1
@.str.115 = external hidden unnamed_addr constant [43 x i8], align 1
@.str.116 = external hidden unnamed_addr constant [32 x i8], align 1
@.str.118 = external hidden unnamed_addr constant [42 x i8], align 1

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

declare void @roaring_bitmap_free(ptr noundef) #1

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

declare void @_assert_true(i64 noundef, ptr noundef, ptr noundef, i32 noundef) #1

declare i64 @roaring_bitmap_get_cardinality(ptr noundef) #1

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

; Function Attrs: nounwind
declare void @free(ptr noundef) #3

declare void @roaring_bitmap_to_uint32_array(ptr noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
declare hidden i32 @array_equals(ptr noundef, i32 noundef, ptr noundef, i32 noundef) #4

declare zeroext i1 @roaring_bitmap_run_optimize(ptr noundef) #1

; Function Attrs: nounwind allocsize(0,1)
declare noalias ptr @calloc(i64 noundef, i64 noundef) #5

; Function Attrs: nounwind uwtable
declare hidden ptr @make_roaring_from_array(ptr noundef, i32 noundef) #4

declare zeroext i1 @roaring_bitmap_remove_run_compression(ptr noundef) #1

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

8:                                                ; preds = %24, %0
  %9 = load i32, ptr %3, align 4, !tbaa !5
  %10 = icmp ult i32 %9, 500
  br i1 %10, label %12, label %11

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

12:                                               ; preds = %8
  %13 = load i32, ptr %3, align 4, !tbaa !5
  %14 = icmp ne i32 %13, 300
  br i1 %14, label %15, label %23

15:                                               ; preds = %12
  %16 = load i32, ptr %3, align 4, !tbaa !5
  %17 = add i32 65536, %16
  %18 = load ptr, ptr %2, align 8, !tbaa !9
  %19 = load i32, ptr %1, align 4, !tbaa !5
  %20 = add nsw i32 %19, 1
  store i32 %20, ptr %1, align 4, !tbaa !5
  %21 = sext i32 %19 to i64
  %22 = getelementptr inbounds i32, ptr %18, i64 %21
  store i32 %17, ptr %22, align 4, !tbaa !5
  br label %23

23:                                               ; preds = %15, %12
  br label %24

24:                                               ; preds = %23
  %25 = load i32, ptr %3, align 4, !tbaa !5
  %26 = add i32 %25, 1
  store i32 %26, ptr %3, align 4, !tbaa !5
  br label %8, !llvm.loop !11

27:                                               ; preds = %11
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #6
  %28 = load ptr, ptr %2, align 8, !tbaa !9
  %29 = load i32, ptr %1, align 4, !tbaa !5
  %30 = call ptr @make_roaring_from_array(ptr noundef %28, i32 noundef %29)
  store ptr %30, ptr %4, align 8, !tbaa !9
  %31 = load ptr, ptr %4, align 8, !tbaa !9
  %32 = call zeroext i1 @roaring_bitmap_run_optimize(ptr noundef %31)
  %33 = zext i1 %32 to i64
  call void @_assert_true(i64 noundef %33, ptr noundef @.str.116, ptr noundef @.str.2, i32 noundef 2520)
  %34 = load ptr, ptr %4, align 8, !tbaa !9
  %35 = call zeroext i1 @roaring_bitmap_remove_run_compression(ptr noundef %34)
  %36 = zext i1 %35 to i64
  call void @_assert_true(i64 noundef %36, ptr noundef @.str.118, ptr noundef @.str.2, i32 noundef 2521)
  %37 = load ptr, ptr %4, align 8, !tbaa !9
  %38 = call zeroext i1 @roaring_bitmap_run_optimize(ptr noundef %37)
  %39 = zext i1 %38 to i64
  call void @_assert_true(i64 noundef %39, ptr noundef @.str.116, ptr noundef @.str.2, i32 noundef 2523)
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #6
  %40 = load ptr, ptr %4, align 8, !tbaa !9
  %41 = call i64 @roaring_bitmap_get_cardinality(ptr noundef %40)
  store i64 %41, ptr %5, align 8, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #6
  %42 = load i64, ptr %5, align 8, !tbaa !13
  %43 = mul i64 %42, 4
  %44 = call noalias ptr @malloc(i64 noundef %43) #8
  store ptr %44, ptr %6, align 8, !tbaa !9
  %45 = load ptr, ptr %4, align 8, !tbaa !9
  %46 = load ptr, ptr %6, align 8, !tbaa !9
  call void @roaring_bitmap_to_uint32_array(ptr noundef %45, ptr noundef %46)
  %47 = load ptr, ptr %6, align 8, !tbaa !9
  %48 = load i64, ptr %5, align 8, !tbaa !13
  %49 = trunc i64 %48 to i32
  %50 = load ptr, ptr %2, align 8, !tbaa !9
  %51 = load i32, ptr %1, align 4, !tbaa !5
  %52 = call i32 @array_equals(ptr noundef %47, i32 noundef %49, ptr noundef %50, i32 noundef %51)
  %53 = sext i32 %52 to i64
  call void @_assert_true(i64 noundef %53, ptr noundef @.str.115, ptr noundef @.str.2, i32 noundef 2529)
  %54 = load ptr, ptr %4, align 8, !tbaa !9
  call void @roaring_bitmap_free(ptr noundef %54)
  %55 = load ptr, ptr %6, align 8, !tbaa !9
  call void @free(ptr noundef %55) #6
  %56 = load ptr, ptr %2, align 8, !tbaa !9
  call void @free(ptr noundef %56) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %1) #6
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { "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 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 = { 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 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 #5 = { nounwind allocsize(0,1) "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 #6 = { nounwind }
attributes #7 = { nounwind allocsize(0,1) }
attributes #8 = { nounwind 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 = !{!14, !14, i64 0}
!14 = !{!"long", !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.2 = external hidden unnamed_addr constant [88 x i8], align 1
@.str.115 = external hidden unnamed_addr constant [43 x i8], align 1
@.str.116 = external hidden unnamed_addr constant [32 x i8], align 1
@.str.118 = external hidden unnamed_addr constant [42 x i8], align 1

declare void @roaring_bitmap_free(ptr noundef) local_unnamed_addr #0

declare void @_assert_true(i64 noundef, ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #0

declare i64 @roaring_bitmap_get_cardinality(ptr noundef) local_unnamed_addr #0

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

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

declare void @roaring_bitmap_to_uint32_array(ptr noundef, ptr noundef) local_unnamed_addr #0

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

declare zeroext i1 @roaring_bitmap_run_optimize(ptr noundef) local_unnamed_addr #0

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

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

declare zeroext i1 @roaring_bitmap_remove_run_compression(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @test_remove_run_to_array() local_unnamed_addr #3 {
  %1 = tail call noalias dereferenceable_or_null(400000) ptr @calloc(i64 noundef 100000, i64 noundef 4) #5
  br label %16

2:                                                ; preds = %22
  %3 = tail call ptr @make_roaring_from_array(ptr noundef %1, i32 noundef %24)
  %4 = tail call zeroext i1 @roaring_bitmap_run_optimize(ptr noundef %3) #6
  %5 = zext i1 %4 to i64
  tail call void @_assert_true(i64 noundef %5, ptr noundef nonnull @.str.116, ptr noundef nonnull @.str.2, i32 noundef 2520) #6
  %6 = tail call zeroext i1 @roaring_bitmap_remove_run_compression(ptr noundef %3) #6
  %7 = zext i1 %6 to i64
  tail call void @_assert_true(i64 noundef %7, ptr noundef nonnull @.str.118, ptr noundef nonnull @.str.2, i32 noundef 2521) #6
  %8 = tail call zeroext i1 @roaring_bitmap_run_optimize(ptr noundef %3) #6
  %9 = zext i1 %8 to i64
  tail call void @_assert_true(i64 noundef %9, ptr noundef nonnull @.str.116, ptr noundef nonnull @.str.2, i32 noundef 2523) #6
  %10 = tail call i64 @roaring_bitmap_get_cardinality(ptr noundef %3) #6
  %11 = shl i64 %10, 2
  %12 = tail call noalias ptr @malloc(i64 noundef %11) #7
  tail call void @roaring_bitmap_to_uint32_array(ptr noundef %3, ptr noundef %12) #6
  %13 = trunc i64 %10 to i32
  %14 = tail call i32 @array_equals(ptr noundef %12, i32 noundef %13, ptr noundef %1, i32 noundef %24)
  %15 = sext i32 %14 to i64
  tail call void @_assert_true(i64 noundef %15, ptr noundef nonnull @.str.115, ptr noundef nonnull @.str.2, i32 noundef 2529) #6
  tail call void @roaring_bitmap_free(ptr noundef %3) #6
  tail call void @free(ptr noundef %12) #6
  tail call void @free(ptr noundef %1) #6
  ret void

16:                                               ; preds = %22, %0
  %.023 = phi i32 [ 0, %0 ], [ %24, %22 ]
  %.02122 = phi i32 [ 0, %0 ], [ %27, %22 ]
  %.not = icmp eq i32 %.02122, 300
  br i1 %.not, label %22, label %17

17:                                               ; preds = %16
  %18 = or disjoint i32 %.02122, 65536
  %19 = add nsw i32 %.023, 1
  %20 = sext i32 %.023 to i64
  %21 = getelementptr inbounds i32, ptr %1, i64 %20
  store i32 %18, ptr %21, align 4, !tbaa !5
  br label %22

22:                                               ; preds = %17, %16
  %.1 = phi i32 [ %19, %17 ], [ %.023, %16 ]
  %23 = or i32 %.02122, 65537
  %24 = add nsw i32 %.1, 1
  %25 = sext i32 %.1 to i64
  %26 = getelementptr inbounds i32, ptr %1, i64 %25
  store i32 %23, ptr %26, align 4, !tbaa !5
  %27 = add nuw nsw i32 %.02122, 2
  %exitcond.not.1 = icmp eq i32 %27, 500
  br i1 %exitcond.not.1, label %2, label %16, !llvm.loop !9
}

attributes #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 = { 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 #2 = { 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 #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 = { mustprogress nofree nounwind willreturn allockind("alloc,zeroed") allocsize(0,1) 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 #5 = { nounwind allocsize(0,1) }
attributes #6 = { nounwind }
attributes #7 = { nounwind 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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LoopRotatePass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass