; LLVM IR from jermp/2i_bench :: external/CRoaring/src/containers (bitset)

; 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.bitset_container_s = type { i32, ptr }

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

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

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i64 @llvm.cttz.i64(i64, i1 immarg) #1

; Function Attrs: nounwind uwtable
define dso_local zeroext i1 @bitset_container_iterate64(ptr noundef %0, i32 noundef %1, ptr noundef %2, i64 noundef %3, ptr noundef %4) #2 {
  %6 = alloca i1, align 1
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca i64, align 8
  %11 = alloca ptr, align 8
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  %14 = alloca i64, align 8
  %15 = alloca i64, align 8
  %16 = alloca i32, align 4
  store ptr %0, ptr %7, align 8, !tbaa !5
  store i32 %1, ptr %8, align 4, !tbaa !9
  store ptr %2, ptr %9, align 8, !tbaa !5
  store i64 %3, ptr %10, align 8, !tbaa !11
  store ptr %4, ptr %11, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #3
  store i32 0, ptr %12, align 4, !tbaa !9
  br label %17

17:                                               ; preds = %64, %5
  %18 = load i32, ptr %12, align 4, !tbaa !9
  %19 = icmp slt i32 %18, 1024
  br i1 %19, label %21, label %20

20:                                               ; preds = %17
  store i32 2, ptr %13, align 4
  br label %67

21:                                               ; preds = %17
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #3
  %22 = load ptr, ptr %7, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.bitset_container_s, ptr %22, i32 0, i32 1
  %24 = load ptr, ptr %23, align 8, !tbaa !13
  %25 = load i32, ptr %12, align 4, !tbaa !9
  %26 = sext i32 %25 to i64
  %27 = getelementptr inbounds i64, ptr %24, i64 %26
  %28 = load i64, ptr %27, align 8, !tbaa !11
  store i64 %28, ptr %14, align 8, !tbaa !11
  br label %29

29:                                               ; preds = %57, %21
  %30 = load i64, ptr %14, align 8, !tbaa !11
  %31 = icmp ne i64 %30, 0
  br i1 %31, label %32, label %58

32:                                               ; preds = %29
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #3
  %33 = load i64, ptr %14, align 8, !tbaa !11
  %34 = load i64, ptr %14, align 8, !tbaa !11
  %35 = xor i64 %34, -1
  %36 = add i64 %35, 1
  %37 = and i64 %33, %36
  store i64 %37, ptr %15, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %16) #3
  %38 = load i64, ptr %14, align 8, !tbaa !11
  %39 = call i64 @llvm.cttz.i64(i64 %38, i1 true)
  %40 = trunc i64 %39 to i32
  store i32 %40, ptr %16, align 4, !tbaa !9
  %41 = load ptr, ptr %9, align 8, !tbaa !5
  %42 = load i64, ptr %10, align 8, !tbaa !11
  %43 = load i32, ptr %16, align 4, !tbaa !9
  %44 = load i32, ptr %8, align 4, !tbaa !9
  %45 = add i32 %43, %44
  %46 = zext i32 %45 to i64
  %47 = or i64 %42, %46
  %48 = load ptr, ptr %11, align 8, !tbaa !5
  %49 = call zeroext i1 %41(i64 noundef %47, ptr noundef %48)
  br i1 %49, label %51, label %50

50:                                               ; preds = %32
  store i1 false, ptr %6, align 1
  store i32 1, ptr %13, align 4
  br label %55

51:                                               ; preds = %32
  %52 = load i64, ptr %15, align 8, !tbaa !11
  %53 = load i64, ptr %14, align 8, !tbaa !11
  %54 = xor i64 %53, %52
  store i64 %54, ptr %14, align 8, !tbaa !11
  store i32 0, ptr %13, align 4
  br label %55

55:                                               ; preds = %51, %50
  call void @llvm.lifetime.end.p0(i64 4, ptr %16) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #3
  %56 = load i32, ptr %13, align 4
  switch i32 %56, label %61 [
    i32 0, label %57
  ]

57:                                               ; preds = %55
  br label %29, !llvm.loop !15

58:                                               ; preds = %29
  %59 = load i32, ptr %8, align 4, !tbaa !9
  %60 = add i32 %59, 64
  store i32 %60, ptr %8, align 4, !tbaa !9
  store i32 0, ptr %13, align 4
  br label %61

61:                                               ; preds = %58, %55
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #3
  %62 = load i32, ptr %13, align 4
  switch i32 %62, label %67 [
    i32 0, label %63
  ]

63:                                               ; preds = %61
  br label %64

64:                                               ; preds = %63
  %65 = load i32, ptr %12, align 4, !tbaa !9
  %66 = add nsw i32 %65, 1
  store i32 %66, ptr %12, align 4, !tbaa !9
  br label %17, !llvm.loop !17

67:                                               ; preds = %61, %20
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #3
  %68 = load i32, ptr %13, align 4
  switch i32 %68, label %72 [
    i32 2, label %69
    i32 1, label %70
  ]

69:                                               ; preds = %67
  store i1 true, ptr %6, align 1
  br label %70

70:                                               ; preds = %69, %67
  %71 = load i1, ptr %6, align 1
  ret i1 %71

72:                                               ; preds = %67
  unreachable
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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 }

!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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!14, !6, i64 8}
!14 = !{!"bitset_container_s", !10, i64 0, !6, i64 8}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = distinct !{!17, !16}


; 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 speculatable willreturn memory(none)
declare i64 @llvm.cttz.i64(i64, i1 immarg) #0

; Function Attrs: nounwind uwtable
define dso_local zeroext i1 @bitset_container_iterate64(ptr nocapture noundef readonly %0, i32 noundef %1, ptr nocapture noundef readonly %2, i64 noundef %3, ptr noundef %4) local_unnamed_addr #1 {
  %6 = getelementptr inbounds i8, ptr %0, i64 8
  br label %7

7:                                                ; preds = %5, %22
  %indvars.iv = phi i64 [ 0, %5 ], [ %indvars.iv.next, %22 ]
  %8 = phi i1 [ false, %5 ], [ %24, %22 ]
  %.02033 = phi i32 [ %1, %5 ], [ %23, %22 ]
  %9 = load ptr, ptr %6, align 8, !tbaa !5
  %10 = getelementptr inbounds i64, ptr %9, i64 %indvars.iv
  %11 = load i64, ptr %10, align 8, !tbaa !11
  br label %12

12:                                               ; preds = %13, %7
  %.022 = phi i64 [ %11, %7 ], [ %21, %13 ]
  %.not = icmp eq i64 %.022, 0
  br i1 %.not, label %22, label %13

13:                                               ; preds = %12
  %14 = tail call range(i64 0, 65) i64 @llvm.cttz.i64(i64 %.022, i1 true)
  %15 = trunc nuw nsw i64 %14 to i32
  %16 = add i32 %.02033, %15
  %17 = zext i32 %16 to i64
  %18 = or i64 %17, %3
  %19 = tail call zeroext i1 %2(i64 noundef %18, ptr noundef %4) #2
  %20 = add i64 %.022, -1
  %21 = and i64 %20, %.022
  br i1 %19, label %12, label %.loopexit, !llvm.loop !13

22:                                               ; preds = %12
  %23 = add i32 %.02033, 64
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %24 = icmp ugt i64 %indvars.iv, 1022
  %exitcond = icmp eq i64 %indvars.iv.next, 1024
  br i1 %exitcond, label %.loopexit, label %7, !llvm.loop !15

.loopexit:                                        ; preds = %22, %13
  %25 = phi i1 [ %8, %13 ], [ %24, %22 ]
  ret i1 %25
}

attributes #0 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #1 = { 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 #2 = { 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, !10, i64 8}
!6 = !{!"bitset_container_s", !7, i64 0, !10, i64 8}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long", !8, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}


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