; 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"

; 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 ptr @roaring_bitmap_create() #1

declare void @roaring_bitmap_add(ptr noundef, i32 noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local void @convert_all_containers(ptr noundef, i8 noundef zeroext) #2

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

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

; Function Attrs: nounwind uwtable
declare dso_local void @read_compare(ptr noundef, ptr noundef, i32 noundef, i32 noundef) #2

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

8:                                                ; preds = %20, %1
  %9 = load i32, ptr %6, align 4, !tbaa !10
  %10 = load i32, ptr %4, align 4, !tbaa !10
  %11 = icmp ult i32 %9, %10
  br i1 %11, label %13, label %12

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

13:                                               ; preds = %8
  %14 = load ptr, ptr %5, align 8, !tbaa !8
  %15 = load ptr, ptr %3, align 8, !tbaa !8
  %16 = load i32, ptr %6, align 4, !tbaa !10
  %17 = zext i32 %16 to i64
  %18 = getelementptr inbounds i32, ptr %15, i64 %17
  %19 = load i32, ptr %18, align 4, !tbaa !10
  call void @roaring_bitmap_add(ptr noundef %14, i32 noundef %19)
  br label %20

20:                                               ; preds = %13
  %21 = load i32, ptr %6, align 4, !tbaa !10
  %22 = add i32 %21, 1
  store i32 %22, ptr %6, align 4, !tbaa !10
  br label %8, !llvm.loop !12

23:                                               ; preds = %12
  %24 = load i8, ptr %2, align 1, !tbaa !5
  %25 = zext i8 %24 to i32
  %26 = icmp ne i32 %25, 255
  br i1 %26, label %27, label %30

27:                                               ; preds = %23
  %28 = load ptr, ptr %5, align 8, !tbaa !8
  %29 = load i8, ptr %2, align 1, !tbaa !5
  call void @convert_all_containers(ptr noundef %28, i8 noundef zeroext %29)
  br label %30

30:                                               ; preds = %27, %23
  %31 = load ptr, ptr %5, align 8, !tbaa !8
  %32 = load ptr, ptr %3, align 8, !tbaa !8
  %33 = load i32, ptr %4, align 4, !tbaa !10
  call void @read_compare(ptr noundef %31, ptr noundef %32, i32 noundef %33, i32 noundef 1)
  %34 = load ptr, ptr %5, align 8, !tbaa !8
  %35 = load ptr, ptr %3, align 8, !tbaa !8
  %36 = load i32, ptr %4, align 4, !tbaa !10
  call void @read_compare(ptr noundef %34, ptr noundef %35, i32 noundef %36, i32 noundef 2)
  %37 = load ptr, ptr %5, align 8, !tbaa !8
  %38 = load ptr, ptr %3, align 8, !tbaa !8
  %39 = load i32, ptr %4, align 4, !tbaa !10
  call void @read_compare(ptr noundef %37, ptr noundef %38, i32 noundef %39, i32 noundef 7)
  %40 = load ptr, ptr %5, align 8, !tbaa !8
  %41 = load ptr, ptr %3, align 8, !tbaa !8
  %42 = load i32, ptr %4, align 4, !tbaa !10
  %43 = load i32, ptr %4, align 4, !tbaa !10
  %44 = sub i32 %43, 1
  call void @read_compare(ptr noundef %40, ptr noundef %41, i32 noundef %42, i32 noundef %44)
  %45 = load ptr, ptr %5, align 8, !tbaa !8
  %46 = load ptr, ptr %3, align 8, !tbaa !8
  %47 = load i32, ptr %4, align 4, !tbaa !10
  %48 = load i32, ptr %4, align 4, !tbaa !10
  call void @read_compare(ptr noundef %45, ptr noundef %46, i32 noundef %47, i32 noundef %48)
  %49 = load ptr, ptr %5, align 8, !tbaa !8
  %50 = load ptr, ptr %3, align 8, !tbaa !8
  %51 = load i32, ptr %4, align 4, !tbaa !10
  call void @read_compare(ptr noundef %49, ptr noundef %50, i32 noundef %51, i32 noundef -1)
  %52 = load ptr, ptr %5, align 8, !tbaa !8
  call void @roaring_bitmap_free(ptr noundef %52)
  %53 = load ptr, ptr %3, align 8, !tbaa !8
  call void @free(ptr noundef %53) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #4
  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 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 = { 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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = !{!9, !9, i64 0}
!9 = !{!"any pointer", !6, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"int", !6, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}


; 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"

; Function Attrs: mustprogress 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) local_unnamed_addr #1

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

declare ptr @roaring_bitmap_create() local_unnamed_addr #1

declare void @roaring_bitmap_add(ptr noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local void @convert_all_containers(ptr noundef, i8 noundef zeroext) local_unnamed_addr #2

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

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

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

; Function Attrs: nounwind uwtable
define dso_local void @test_read_uint32_iterator(i8 noundef zeroext %0) local_unnamed_addr #2 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %2) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %3) #4
  call void @test_iterator_generate_data(ptr noundef nonnull %2, ptr noundef nonnull %3)
  %4 = call ptr @roaring_bitmap_create() #4
  %5 = load i32, ptr %3, align 4, !tbaa !5
  %.not14 = icmp eq i32 %5, 0
  br i1 %.not14, label %._crit_edge, label %.lr.ph

._crit_edge:                                      ; preds = %.lr.ph, %1
  %6 = phi i32 [ 0, %1 ], [ %10, %.lr.ph ]
  %.not = icmp eq i8 %0, -1
  br i1 %.not, label %14, label %13

.lr.ph:                                           ; preds = %1, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 0, %1 ]
  %7 = load ptr, ptr %2, align 8, !tbaa !9
  %8 = getelementptr inbounds i32, ptr %7, i64 %indvars.iv
  %9 = load i32, ptr %8, align 4, !tbaa !5
  call void @roaring_bitmap_add(ptr noundef %4, i32 noundef %9) #4
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %10 = load i32, ptr %3, align 4, !tbaa !5
  %11 = zext i32 %10 to i64
  %12 = icmp ult i64 %indvars.iv.next, %11
  br i1 %12, label %.lr.ph, label %._crit_edge, !llvm.loop !11

13:                                               ; preds = %._crit_edge
  call void @convert_all_containers(ptr noundef %4, i8 noundef zeroext %0)
  %.pre = load i32, ptr %3, align 4, !tbaa !5
  br label %14

14:                                               ; preds = %13, %._crit_edge
  %15 = phi i32 [ %.pre, %13 ], [ %6, %._crit_edge ]
  %16 = load ptr, ptr %2, align 8, !tbaa !9
  call void @read_compare(ptr noundef %4, ptr noundef %16, i32 noundef %15, i32 noundef 1)
  %17 = load ptr, ptr %2, align 8, !tbaa !9
  %18 = load i32, ptr %3, align 4, !tbaa !5
  call void @read_compare(ptr noundef %4, ptr noundef %17, i32 noundef %18, i32 noundef 2)
  %19 = load ptr, ptr %2, align 8, !tbaa !9
  %20 = load i32, ptr %3, align 4, !tbaa !5
  call void @read_compare(ptr noundef %4, ptr noundef %19, i32 noundef %20, i32 noundef 7)
  %21 = load ptr, ptr %2, align 8, !tbaa !9
  %22 = load i32, ptr %3, align 4, !tbaa !5
  %23 = add i32 %22, -1
  call void @read_compare(ptr noundef %4, ptr noundef %21, i32 noundef %22, i32 noundef %23)
  %24 = load ptr, ptr %2, align 8, !tbaa !9
  %25 = load i32, ptr %3, align 4, !tbaa !5
  call void @read_compare(ptr noundef %4, ptr noundef %24, i32 noundef %25, i32 noundef %25)
  %26 = load ptr, ptr %2, align 8, !tbaa !9
  %27 = load i32, ptr %3, align 4, !tbaa !5
  call void @read_compare(ptr noundef %4, ptr noundef %26, i32 noundef %27, i32 noundef -1)
  call void @roaring_bitmap_free(ptr noundef %4) #4
  %28 = load ptr, ptr %2, align 8, !tbaa !9
  call void @free(ptr noundef %28) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %3) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #4
  ret void
}

attributes #0 = { mustprogress 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 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 = { 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 #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 = !{!"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"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass