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

%struct.roaring_uint32_iterator_s = type { ptr, i32, i32, i32, i32, i8, ptr, i8, i32 }

@.str.2 = external hidden unnamed_addr constant [88 x i8], align 1
@.str.38 = external hidden unnamed_addr constant [11 x i8], align 1
@.str.39 = external hidden unnamed_addr constant [40 x i8], align 1
@.str.40 = external hidden unnamed_addr constant [44 x i8], align 1
@__PRETTY_FUNCTION__.check_iterate_to_beginning = external hidden unnamed_addr constant [34 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 ptr @roaring_bitmap_create() #1

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

declare i64 @roaring_bitmap_get_cardinality(ptr noundef) #1

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #2

declare void @roaring_bitmap_flip_inplace(ptr noundef, i64 noundef, i64 noundef) #1

; Function Attrs: nounwind uwtable
define dso_local void @check_iterate_to_beginning() #3 {
  %1 = alloca i64, align 8
  %2 = alloca i64, align 8
  %3 = alloca ptr, align 8
  %4 = alloca %struct.roaring_uint32_iterator_s, align 8
  %5 = alloca i64, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %1) #4
  store i64 4294967296, ptr %1, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #4
  store i64 0, ptr %2, align 8, !tbaa !5
  br label %6

6:                                                ; preds = %49, %0
  %7 = load i64, ptr %2, align 8, !tbaa !5
  %8 = icmp ult i64 %7, 1024
  br i1 %8, label %10, label %9

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

10:                                               ; preds = %6
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #4
  %11 = call ptr @roaring_bitmap_create()
  store ptr %11, ptr %3, align 8, !tbaa !9
  %12 = load ptr, ptr %3, align 8, !tbaa !9
  %13 = load i64, ptr %1, align 8, !tbaa !5
  %14 = load i64, ptr %2, align 8, !tbaa !5
  %15 = sub i64 %13, %14
  %16 = load i64, ptr %1, align 8, !tbaa !5
  call void @roaring_bitmap_flip_inplace(ptr noundef %12, i64 noundef %15, i64 noundef %16)
  call void @llvm.lifetime.start.p0(i64 48, ptr %4) #4
  %17 = load ptr, ptr %3, align 8, !tbaa !9
  call void @roaring_init_iterator_last(ptr noundef %17, ptr noundef %4)
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  store i64 0, ptr %5, align 8, !tbaa !5
  br label %18

18:                                               ; preds = %34, %10
  %19 = getelementptr inbounds %struct.roaring_uint32_iterator_s, ptr %4, i32 0, i32 5
  %20 = load i8, ptr %19, align 8, !tbaa !11, !range !15, !noundef !16
  %21 = trunc i8 %20 to i1
  br i1 %21, label %22, label %36

22:                                               ; preds = %18
  %23 = load i64, ptr %5, align 8, !tbaa !5
  %24 = add i64 %23, 1
  store i64 %24, ptr %5, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.roaring_uint32_iterator_s, ptr %4, i32 0, i32 4
  %26 = load i32, ptr %25, align 4, !tbaa !17
  %27 = zext i32 %26 to i64
  %28 = load i64, ptr %5, align 8, !tbaa !5
  %29 = add i64 %27, %28
  %30 = load i64, ptr %1, align 8, !tbaa !5
  %31 = icmp eq i64 %29, %30
  br i1 %31, label %32, label %33

32:                                               ; preds = %22
  br label %34

33:                                               ; preds = %22
  call void @__assert_fail(ptr noundef @.str.40, ptr noundef @.str.2, i32 noundef 387, ptr noundef @__PRETTY_FUNCTION__.check_iterate_to_beginning) #5
  unreachable

34:                                               ; preds = %32
  %35 = call zeroext i1 @roaring_previous_uint32_iterator(ptr noundef %4)
  br label %18, !llvm.loop !18

36:                                               ; preds = %18
  %37 = load i64, ptr %5, align 8, !tbaa !5
  %38 = load i64, ptr %2, align 8, !tbaa !5
  %39 = icmp eq i64 %37, %38
  %40 = zext i1 %39 to i32
  %41 = sext i32 %40 to i64
  call void @_assert_true(i64 noundef %41, ptr noundef @.str.38, ptr noundef @.str.2, i32 noundef 390)
  %42 = load ptr, ptr %3, align 8, !tbaa !9
  %43 = call i64 @roaring_bitmap_get_cardinality(ptr noundef %42)
  %44 = load i64, ptr %2, align 8, !tbaa !5
  %45 = icmp eq i64 %43, %44
  %46 = zext i1 %45 to i32
  %47 = sext i32 %46 to i64
  call void @_assert_true(i64 noundef %47, ptr noundef @.str.39, ptr noundef @.str.2, i32 noundef 391)
  %48 = load ptr, ptr %3, align 8, !tbaa !9
  call void @roaring_bitmap_free(ptr noundef %48)
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 48, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #4
  br label %49

49:                                               ; preds = %36
  %50 = load i64, ptr %2, align 8, !tbaa !5
  %51 = add i64 %50, 1
  store i64 %51, ptr %2, align 8, !tbaa !5
  br label %6, !llvm.loop !20

52:                                               ; preds = %9
  call void @llvm.lifetime.end.p0(i64 8, ptr %1) #4
  ret void
}

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

declare zeroext i1 @roaring_previous_uint32_iterator(ptr noundef) #1

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 = { noreturn 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 = { 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 = { nounwind }
attributes #5 = { noreturn 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 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !14, i64 24}
!12 = !{!"roaring_uint32_iterator_s", !10, i64 0, !13, i64 8, !13, i64 12, !13, i64 16, !13, i64 20, !14, i64 24, !10, i64 32, !7, i64 40, !13, i64 44}
!13 = !{!"int", !7, i64 0}
!14 = !{!"_Bool", !7, i64 0}
!15 = !{i8 0, i8 2}
!16 = !{}
!17 = !{!12, !13, i64 20}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}
!20 = distinct !{!20, !19}


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

%struct.roaring_uint32_iterator_s = type { ptr, i32, i32, i32, i32, i8, ptr, i8, i32 }

@.str.2 = external hidden unnamed_addr constant [88 x i8], align 1
@.str.38 = external hidden unnamed_addr constant [11 x i8], align 1
@.str.39 = external hidden unnamed_addr constant [40 x i8], align 1
@.str.40 = external hidden unnamed_addr constant [44 x i8], align 1
@__PRETTY_FUNCTION__.check_iterate_to_beginning = external hidden unnamed_addr constant [34 x i8], align 1

; 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 @_assert_true(i64 noundef, ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #1

declare i64 @roaring_bitmap_get_cardinality(ptr noundef) local_unnamed_addr #1

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #2

declare void @roaring_bitmap_flip_inplace(ptr noundef, i64 noundef, i64 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local void @check_iterate_to_beginning() local_unnamed_addr #3 {
  %1 = alloca %struct.roaring_uint32_iterator_s, align 8
  %2 = getelementptr inbounds i8, ptr %1, i64 24
  %3 = getelementptr inbounds i8, ptr %1, i64 20
  br label %5

4:                                                ; preds = %._crit_edge
  ret void

5:                                                ; preds = %0, %._crit_edge
  %.01417 = phi i64 [ 0, %0 ], [ %25, %._crit_edge ]
  %6 = call ptr @roaring_bitmap_create() #4
  %7 = sub nuw nsw i64 4294967296, %.01417
  call void @roaring_bitmap_flip_inplace(ptr noundef %6, i64 noundef %7, i64 noundef 4294967296) #4
  call void @llvm.lifetime.start.p0(i64 48, ptr nonnull %1) #4
  call void @roaring_init_iterator_last(ptr noundef %6, ptr noundef nonnull %1) #4
  %8 = load i8, ptr %2, align 8, !tbaa !5, !range !12, !noundef !13
  %9 = trunc nuw i8 %8 to i1
  br i1 %9, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %5, %16
  %.016 = phi i64 [ %10, %16 ], [ 0, %5 ]
  %10 = add i64 %.016, 1
  %11 = load i32, ptr %3, align 4, !tbaa !14
  %12 = zext i32 %11 to i64
  %13 = add i64 %10, %12
  %14 = icmp eq i64 %13, 4294967296
  br i1 %14, label %16, label %15

15:                                               ; preds = %.lr.ph
  call void @__assert_fail(ptr noundef nonnull @.str.40, ptr noundef nonnull @.str.2, i32 noundef 387, ptr noundef nonnull @__PRETTY_FUNCTION__.check_iterate_to_beginning) #5
  unreachable

16:                                               ; preds = %.lr.ph
  %17 = call zeroext i1 @roaring_previous_uint32_iterator(ptr noundef nonnull %1) #4
  %18 = load i8, ptr %2, align 8, !tbaa !5, !range !12, !noundef !13
  %19 = trunc nuw i8 %18 to i1
  br i1 %19, label %.lr.ph, label %._crit_edge, !llvm.loop !15

._crit_edge:                                      ; preds = %16, %5
  %.0.lcssa = phi i64 [ 0, %5 ], [ %10, %16 ]
  %20 = icmp eq i64 %.0.lcssa, %.01417
  %21 = zext i1 %20 to i64
  call void @_assert_true(i64 noundef %21, ptr noundef nonnull @.str.38, ptr noundef nonnull @.str.2, i32 noundef 390) #4
  %22 = call i64 @roaring_bitmap_get_cardinality(ptr noundef %6) #4
  %23 = icmp eq i64 %22, %.01417
  %24 = zext i1 %23 to i64
  call void @_assert_true(i64 noundef %24, ptr noundef nonnull @.str.39, ptr noundef nonnull @.str.2, i32 noundef 391) #4
  call void @roaring_bitmap_free(ptr noundef %6) #4
  call void @llvm.lifetime.end.p0(i64 48, ptr nonnull %1) #4
  %25 = add nuw nsw i64 %.01417, 1
  %exitcond.not = icmp eq i64 %25, 1024
  br i1 %exitcond.not, label %4, label %5, !llvm.loop !17
}

declare void @roaring_init_iterator_last(ptr noundef, ptr noundef) local_unnamed_addr #1

declare zeroext i1 @roaring_previous_uint32_iterator(ptr noundef) local_unnamed_addr #1

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 = { noreturn 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 = { 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 = { nounwind }
attributes #5 = { noreturn 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, !11, i64 24}
!6 = !{!"roaring_uint32_iterator_s", !7, i64 0, !10, i64 8, !10, i64 12, !10, i64 16, !10, i64 20, !11, i64 24, !7, i64 32, !8, i64 40, !10, i64 44}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"_Bool", !8, i64 0}
!12 = !{i8 0, i8 2}
!13 = !{}
!14 = !{!6, !10, i64 20}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = distinct !{!17, !16}


; Effective O3 passes: GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass