; 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.117 = external hidden unnamed_addr constant [2 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

; Function Attrs: nounwind uwtable
define dso_local void @test_run_to_self() #4 {
  %1 = alloca i32, align 4
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca i8, align 1
  %6 = alloca i64, align 8
  %7 = 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
  %8 = call noalias ptr @calloc(i64 noundef 100000, i64 noundef 4) #7
  store ptr %8, 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 %9

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

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

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

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

24:                                               ; preds = %16, %13
  br label %25

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

28:                                               ; preds = %12
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #6
  %29 = load ptr, ptr %2, align 8, !tbaa !9
  %30 = load i32, ptr %1, align 4, !tbaa !5
  %31 = call ptr @make_roaring_from_array(ptr noundef %29, i32 noundef %30)
  store ptr %31, ptr %4, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 1, ptr %5) #6
  %32 = load ptr, ptr %4, align 8, !tbaa !9
  %33 = call zeroext i1 @roaring_bitmap_run_optimize(ptr noundef %32)
  %34 = zext i1 %33 to i8
  store i8 %34, ptr %5, align 1, !tbaa !13
  %35 = load ptr, ptr %4, align 8, !tbaa !9
  %36 = call zeroext i1 @roaring_bitmap_run_optimize(ptr noundef %35)
  %37 = zext i1 %36 to i8
  store i8 %37, ptr %5, align 1, !tbaa !13
  %38 = load i8, ptr %5, align 1, !tbaa !13, !range !15, !noundef !16
  %39 = trunc i8 %38 to i1
  %40 = zext i1 %39 to i64
  call void @_assert_true(i64 noundef %40, ptr noundef @.str.117, ptr noundef @.str.2, i32 noundef 2469)
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #6
  %41 = load ptr, ptr %4, align 8, !tbaa !9
  %42 = call i64 @roaring_bitmap_get_cardinality(ptr noundef %41)
  store i64 %42, ptr %6, align 8, !tbaa !17
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #6
  %43 = load i64, ptr %6, align 8, !tbaa !17
  %44 = mul i64 %43, 4
  %45 = call noalias ptr @malloc(i64 noundef %44) #8
  store ptr %45, ptr %7, align 8, !tbaa !9
  %46 = load ptr, ptr %4, align 8, !tbaa !9
  %47 = load ptr, ptr %7, align 8, !tbaa !9
  call void @roaring_bitmap_to_uint32_array(ptr noundef %46, ptr noundef %47)
  %48 = load ptr, ptr %7, align 8, !tbaa !9
  %49 = load i64, ptr %6, align 8, !tbaa !17
  %50 = trunc i64 %49 to i32
  %51 = load ptr, ptr %2, align 8, !tbaa !9
  %52 = load i32, ptr %1, align 4, !tbaa !5
  %53 = call i32 @array_equals(ptr noundef %48, i32 noundef %50, ptr noundef %51, i32 noundef %52)
  %54 = sext i32 %53 to i64
  call void @_assert_true(i64 noundef %54, ptr noundef @.str.115, ptr noundef @.str.2, i32 noundef 2475)
  %55 = load ptr, ptr %4, align 8, !tbaa !9
  call void @roaring_bitmap_free(ptr noundef %55)
  %56 = load ptr, ptr %7, align 8, !tbaa !9
  call void @free(ptr noundef %56) #6
  %57 = load ptr, ptr %2, align 8, !tbaa !9
  call void @free(ptr noundef %57) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #6
  call void @llvm.lifetime.end.p0(i64 1, 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 = !{!"_Bool", !7, i64 0}
!15 = !{i8 0, i8 2}
!16 = !{}
!17 = !{!18, !18, i64 0}
!18 = !{!"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.117 = external hidden unnamed_addr constant [2 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

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

2:                                                ; preds = %19
  %3 = tail call ptr @make_roaring_from_array(ptr noundef %1, i32 noundef %21)
  %4 = tail call zeroext i1 @roaring_bitmap_run_optimize(ptr noundef %3) #6
  %5 = tail call zeroext i1 @roaring_bitmap_run_optimize(ptr noundef %3) #6
  %6 = zext i1 %5 to i64
  tail call void @_assert_true(i64 noundef %6, ptr noundef nonnull @.str.117, ptr noundef nonnull @.str.2, i32 noundef 2469) #6
  %7 = tail call i64 @roaring_bitmap_get_cardinality(ptr noundef %3) #6
  %8 = shl i64 %7, 2
  %9 = tail call noalias ptr @malloc(i64 noundef %8) #7
  tail call void @roaring_bitmap_to_uint32_array(ptr noundef %3, ptr noundef %9) #6
  %10 = trunc i64 %7 to i32
  %11 = tail call i32 @array_equals(ptr noundef %9, i32 noundef %10, ptr noundef %1, i32 noundef %21)
  %12 = sext i32 %11 to i64
  tail call void @_assert_true(i64 noundef %12, ptr noundef nonnull @.str.115, ptr noundef nonnull @.str.2, i32 noundef 2475) #6
  tail call void @roaring_bitmap_free(ptr noundef %3) #6
  tail call void @free(ptr noundef %9) #6
  tail call void @free(ptr noundef %1) #6
  ret void

13:                                               ; preds = %19, %0
  %.023 = phi i32 [ 0, %0 ], [ %21, %19 ]
  %.02122 = phi i32 [ 0, %0 ], [ %24, %19 ]
  %.not = icmp eq i32 %.02122, 300
  br i1 %.not, label %19, label %14

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

19:                                               ; preds = %14, %13
  %.1 = phi i32 [ %16, %14 ], [ %.023, %13 ]
  %20 = or i32 %.02122, 65537
  %21 = add nsw i32 %.1, 1
  %22 = sext i32 %.1 to i64
  %23 = getelementptr inbounds i32, ptr %1, i64 %22
  store i32 %20, ptr %23, align 4, !tbaa !5
  %24 = add nuw nsw i32 %.02122, 2
  %exitcond.not.1 = icmp eq i32 %24, 50000
  br i1 %exitcond.not.1, label %2, label %13, !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: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LoopRotatePass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass