; 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

; 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_array_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 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, 2
  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 = xor i1 %32, true
  %34 = zext i1 %33 to i32
  %35 = sext i32 %34 to i64
  call void @_assert_true(i64 noundef %35, ptr noundef @.str.116, ptr noundef @.str.2, i32 noundef 2393)
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #6
  %36 = load ptr, ptr %4, align 8, !tbaa !9
  %37 = call i64 @roaring_bitmap_get_cardinality(ptr noundef %36)
  store i64 %37, ptr %5, align 8, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #6
  %38 = load i64, ptr %5, align 8, !tbaa !13
  %39 = mul i64 %38, 4
  %40 = call noalias ptr @malloc(i64 noundef %39) #8
  store ptr %40, ptr %6, align 8, !tbaa !9
  %41 = load ptr, ptr %4, align 8, !tbaa !9
  %42 = load ptr, ptr %6, align 8, !tbaa !9
  call void @roaring_bitmap_to_uint32_array(ptr noundef %41, ptr noundef %42)
  %43 = load ptr, ptr %6, align 8, !tbaa !9
  %44 = load i64, ptr %5, align 8, !tbaa !13
  %45 = trunc i64 %44 to i32
  %46 = load ptr, ptr %2, align 8, !tbaa !9
  %47 = load i32, ptr %1, align 4, !tbaa !5
  %48 = call i32 @array_equals(ptr noundef %43, i32 noundef %45, ptr noundef %46, i32 noundef %47)
  %49 = sext i32 %48 to i64
  call void @_assert_true(i64 noundef %49, ptr noundef @.str.115, ptr noundef @.str.2, i32 noundef 2399)
  %50 = load ptr, ptr %4, align 8, !tbaa !9
  call void @roaring_bitmap_free(ptr noundef %50)
  %51 = load ptr, ptr %6, align 8, !tbaa !9
  call void @free(ptr noundef %51) #6
  %52 = load ptr, ptr %2, align 8, !tbaa !9
  call void @free(ptr noundef %52) #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

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_array_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 %22)
  %4 = tail call zeroext i1 @roaring_bitmap_run_optimize(ptr noundef %3) #6
  %5 = xor i1 %4, true
  %6 = zext i1 %5 to i64
  tail call void @_assert_true(i64 noundef %6, ptr noundef nonnull @.str.116, ptr noundef nonnull @.str.2, i32 noundef 2393) #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 %22)
  %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 2399) #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
  %.021 = phi i32 [ 0, %0 ], [ %22, %19 ]
  %.01920 = phi i32 [ 0, %0 ], [ %25, %19 ]
  %.not = icmp eq i32 %.01920, 300
  br i1 %.not, label %19, label %14

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

19:                                               ; preds = %13, %14
  %.1 = phi i32 [ %16, %14 ], [ %.021, %13 ]
  %20 = or disjoint i32 %.01920, 2
  %21 = or i32 %.01920, 65538
  %22 = add nsw i32 %.1, 1
  %23 = sext i32 %.1 to i64
  %24 = getelementptr inbounds i32, ptr %1, i64 %23
  store i32 %21, ptr %24, align 4, !tbaa !5
  %25 = add nuw nsw i32 %.01920, 4
  %26 = icmp ult i32 %20, 498
  br i1 %26, label %13, label %2, !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,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LoopRotatePass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass