; 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_setbits_uint16(ptr noundef %0, i64 noundef %1, ptr noundef %2, i16 noundef zeroext %3) #2 {
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i16, align 2
  %9 = alloca i32, align 4
  %10 = alloca i64, align 8
  %11 = alloca i64, align 8
  %12 = alloca i64, align 8
  %13 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i64 %1, ptr %6, align 8, !tbaa !9
  store ptr %2, ptr %7, align 8, !tbaa !5
  store i16 %3, ptr %8, align 2, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  store i32 0, ptr %9, align 4, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  store i64 0, ptr %10, align 8, !tbaa !9
  br label %14

14:                                               ; preds = %54, %4
  %15 = load i64, ptr %10, align 8, !tbaa !9
  %16 = load i64, ptr %6, align 8, !tbaa !9
  %17 = icmp ult i64 %15, %16
  br i1 %17, label %19, label %18

18:                                               ; preds = %14
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  br label %57

19:                                               ; preds = %14
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #3
  %20 = load ptr, ptr %5, align 8, !tbaa !5
  %21 = load i64, ptr %10, align 8, !tbaa !9
  %22 = getelementptr inbounds i64, ptr %20, i64 %21
  %23 = load i64, ptr %22, align 8, !tbaa !9
  store i64 %23, ptr %11, align 8, !tbaa !9
  br label %24

24:                                               ; preds = %27, %19
  %25 = load i64, ptr %11, align 8, !tbaa !9
  %26 = icmp ne i64 %25, 0
  br i1 %26, label %27, label %49

27:                                               ; preds = %24
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #3
  %28 = load i64, ptr %11, align 8, !tbaa !9
  %29 = load i64, ptr %11, align 8, !tbaa !9
  %30 = xor i64 %29, -1
  %31 = add i64 %30, 1
  %32 = and i64 %28, %31
  store i64 %32, ptr %12, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #3
  %33 = load i64, ptr %11, align 8, !tbaa !9
  %34 = call i64 @llvm.cttz.i64(i64 %33, i1 true)
  %35 = trunc i64 %34 to i32
  store i32 %35, ptr %13, align 4, !tbaa !13
  %36 = load i32, ptr %13, align 4, !tbaa !13
  %37 = load i16, ptr %8, align 2, !tbaa !11
  %38 = zext i16 %37 to i32
  %39 = add nsw i32 %36, %38
  %40 = trunc i32 %39 to i16
  %41 = load ptr, ptr %7, align 8, !tbaa !5
  %42 = load i32, ptr %9, align 4, !tbaa !13
  %43 = add nsw i32 %42, 1
  store i32 %43, ptr %9, align 4, !tbaa !13
  %44 = sext i32 %42 to i64
  %45 = getelementptr inbounds i16, ptr %41, i64 %44
  store i16 %40, ptr %45, align 2, !tbaa !11
  %46 = load i64, ptr %12, align 8, !tbaa !9
  %47 = load i64, ptr %11, align 8, !tbaa !9
  %48 = xor i64 %47, %46
  store i64 %48, ptr %11, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #3
  br label %24, !llvm.loop !15

49:                                               ; preds = %24
  %50 = load i16, ptr %8, align 2, !tbaa !11
  %51 = zext i16 %50 to i32
  %52 = add nsw i32 %51, 64
  %53 = trunc i32 %52 to i16
  store i16 %53, ptr %8, align 2, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  br label %54

54:                                               ; preds = %49
  %55 = load i64, ptr %10, align 8, !tbaa !9
  %56 = add i64 %55, 1
  store i64 %56, ptr %10, align 8, !tbaa !9
  br label %14, !llvm.loop !17

57:                                               ; preds = %18
  %58 = load i32, ptr %9, align 4, !tbaa !13
  %59 = sext i32 %58 to i64
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  ret i64 %59
}

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_setbits_uint16(ptr nocapture noundef readonly %0, i64 noundef %1, ptr nocapture noundef writeonly %2, i16 noundef zeroext %3) local_unnamed_addr #1 {
  %.not29 = icmp eq i64 %1, 0
  br i1 %.not29, label %._crit_edge27, label %.lr.ph26

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

._crit_edge27:                                    ; preds = %._crit_edge27.loopexit, %4
  %.016.lcssa = phi i64 [ 0, %4 ], [ %5, %._crit_edge27.loopexit ]
  ret i64 %.016.lcssa

.lr.ph26:                                         ; preds = %4, %._crit_edge
  %.024 = phi i16 [ %16, %._crit_edge ], [ %3, %4 ]
  %.01623 = phi i32 [ %.1.lcssa, %._crit_edge ], [ 0, %4 ]
  %.01822 = phi i64 [ %17, %._crit_edge ], [ 0, %4 ]
  %6 = getelementptr inbounds i64, ptr %0, i64 %.01822
  %7 = load i64, ptr %6, align 8, !tbaa !5
  %.not19 = icmp eq i64 %7, 0
  br i1 %.not19, label %._crit_edge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %.lr.ph26
  %8 = sext i32 %.01623 to i64
  br label %.lr.ph

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

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

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %.lr.ph26
  %.1.lcssa = phi i32 [ %.01623, %.lr.ph26 ], [ %15, %._crit_edge.loopexit ]
  %16 = add i16 %.024, 64
  %17 = add nuw i64 %.01822, 1
  %exitcond.not = icmp eq i64 %17, %1
  br i1 %exitcond.not, label %._crit_edge27.loopexit, label %.lr.ph26, !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