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

; 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

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

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

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

16:                                               ; preds = %61, %5
  %17 = load i64, ptr %12, align 8, !tbaa !9
  %18 = load i64, ptr %8, align 8, !tbaa !9
  %19 = icmp ult i64 %17, %18
  br i1 %19, label %21, label %20

20:                                               ; preds = %16
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #3
  br label %64

21:                                               ; preds = %16
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #3
  %22 = load ptr, ptr %6, align 8, !tbaa !5
  %23 = load i64, ptr %12, align 8, !tbaa !9
  %24 = getelementptr inbounds i64, ptr %22, i64 %23
  %25 = load i64, ptr %24, align 8, !tbaa !9
  %26 = load ptr, ptr %7, align 8, !tbaa !5
  %27 = load i64, ptr %12, align 8, !tbaa !9
  %28 = getelementptr inbounds i64, ptr %26, i64 %27
  %29 = load i64, ptr %28, align 8, !tbaa !9
  %30 = and i64 %25, %29
  store i64 %30, ptr %13, align 8, !tbaa !9
  br label %31

31:                                               ; preds = %34, %21
  %32 = load i64, ptr %13, align 8, !tbaa !9
  %33 = icmp ne i64 %32, 0
  br i1 %33, label %34, label %56

34:                                               ; preds = %31
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #3
  %35 = load i64, ptr %13, align 8, !tbaa !9
  %36 = load i64, ptr %13, align 8, !tbaa !9
  %37 = xor i64 %36, -1
  %38 = add i64 %37, 1
  %39 = and i64 %35, %38
  store i64 %39, ptr %14, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #3
  %40 = load i64, ptr %13, align 8, !tbaa !9
  %41 = call i64 @llvm.cttz.i64(i64 %40, i1 true)
  %42 = trunc i64 %41 to i32
  store i32 %42, ptr %15, align 4, !tbaa !13
  %43 = load i32, ptr %15, align 4, !tbaa !13
  %44 = load i16, ptr %10, align 2, !tbaa !11
  %45 = zext i16 %44 to i32
  %46 = add nsw i32 %43, %45
  %47 = trunc i32 %46 to i16
  %48 = load ptr, ptr %9, align 8, !tbaa !5
  %49 = load i32, ptr %11, align 4, !tbaa !13
  %50 = add nsw i32 %49, 1
  store i32 %50, ptr %11, align 4, !tbaa !13
  %51 = sext i32 %49 to i64
  %52 = getelementptr inbounds i16, ptr %48, i64 %51
  store i16 %47, ptr %52, align 2, !tbaa !11
  %53 = load i64, ptr %14, align 8, !tbaa !9
  %54 = load i64, ptr %13, align 8, !tbaa !9
  %55 = xor i64 %54, %53
  store i64 %55, ptr %13, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #3
  br label %31, !llvm.loop !15

56:                                               ; preds = %31
  %57 = load i16, ptr %10, align 2, !tbaa !11
  %58 = zext i16 %57 to i32
  %59 = add nsw i32 %58, 64
  %60 = trunc i32 %59 to i16
  store i16 %60, ptr %10, align 2, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #3
  br label %61

61:                                               ; preds = %56
  %62 = load i64, ptr %12, align 8, !tbaa !9
  %63 = add i64 %62, 1
  store i64 %63, ptr %12, align 8, !tbaa !9
  br label %16, !llvm.loop !17

64:                                               ; preds = %20
  %65 = load i32, ptr %11, align 4, !tbaa !13
  %66 = sext i32 %65 to i64
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  ret i64 %66
}

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 = !{!"long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"short", !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"int", !7, i64 0}
!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: nofree norecurse nosync nounwind memory(argmem: readwrite) uwtable
define dso_local range(i64 -2147483648, 2147483648) i64 @bitset_extract_intersection_setbits_uint16(ptr noalias nocapture noundef readonly %0, ptr noalias nocapture noundef readonly %1, i64 noundef %2, ptr nocapture noundef writeonly %3, i16 noundef zeroext %4) local_unnamed_addr #1 {
  %.not31 = icmp eq i64 %2, 0
  br i1 %.not31, label %._crit_edge29, label %.lr.ph28

._crit_edge29.loopexit:                           ; preds = %._crit_edge
  %6 = sext i32 %.1.lcssa to i64
  br label %._crit_edge29

._crit_edge29:                                    ; preds = %._crit_edge29.loopexit, %5
  %.018.lcssa = phi i64 [ 0, %5 ], [ %6, %._crit_edge29.loopexit ]
  ret i64 %.018.lcssa

.lr.ph28:                                         ; preds = %5, %._crit_edge
  %.026 = phi i16 [ %20, %._crit_edge ], [ %4, %5 ]
  %.01825 = phi i32 [ %.1.lcssa, %._crit_edge ], [ 0, %5 ]
  %.02024 = phi i64 [ %21, %._crit_edge ], [ 0, %5 ]
  %7 = getelementptr inbounds i64, ptr %0, i64 %.02024
  %8 = load i64, ptr %7, align 8, !tbaa !5
  %9 = getelementptr inbounds i64, ptr %1, i64 %.02024
  %10 = load i64, ptr %9, align 8, !tbaa !5
  %11 = and i64 %10, %8
  %.not21 = icmp eq i64 %11, 0
  br i1 %.not21, label %._crit_edge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %.lr.ph28
  %12 = sext i32 %.01825 to i64
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %indvars.iv = phi i64 [ %12, %.lr.ph.preheader ], [ %indvars.iv.next, %.lr.ph ]
  %.01922 = phi i64 [ %11, %.lr.ph.preheader ], [ %18, %.lr.ph ]
  %13 = tail call range(i64 0, 65) i64 @llvm.cttz.i64(i64 %.01922, i1 true)
  %14 = trunc nuw nsw i64 %13 to i16
  %15 = add i16 %.026, %14
  %indvars.iv.next = add nsw i64 %indvars.iv, 1
  %16 = getelementptr inbounds i16, ptr %3, i64 %indvars.iv
  store i16 %15, ptr %16, align 2, !tbaa !9
  %17 = add i64 %.01922, -1
  %18 = and i64 %17, %.01922
  %.not = icmp eq i64 %18, 0
  br i1 %.not, label %._crit_edge.loopexit, label %.lr.ph, !llvm.loop !11

._crit_edge.loopexit:                             ; preds = %.lr.ph
  %19 = trunc nsw i64 %indvars.iv.next to i32
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %.lr.ph28
  %.1.lcssa = phi i32 [ %.01825, %.lr.ph28 ], [ %19, %._crit_edge.loopexit ]
  %20 = add i16 %.026, 64
  %21 = add nuw i64 %.02024, 1
  %exitcond.not = icmp eq i64 %21, %2
  br i1 %exitcond.not, label %._crit_edge29.loopexit, label %.lr.ph28, !llvm.loop !13
}

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

!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 = !{!"short", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}


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