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

@.str.4 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [90 x i8], align 1
@__PRETTY_FUNCTION__.bitset_container_select = external hidden unnamed_addr constant [92 x i8], align 1

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @bitset_container_cardinality(ptr noundef) #0

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

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @hamming(i64 noundef) #0

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

; Function Attrs: nounwind uwtable
define dso_local zeroext i1 @bitset_container_select(ptr noundef %0, ptr noundef %1, i32 noundef %2, ptr noundef %3) #3 {
  %5 = alloca i1, align 1
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca ptr, align 8
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  %15 = alloca i64, align 8
  %16 = alloca i16, align 2
  %17 = alloca i64, align 8
  %18 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store i32 %2, ptr %8, align 4, !tbaa !9
  store ptr %3, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #5
  %19 = load ptr, ptr %6, align 8, !tbaa !5
  %20 = call i32 @bitset_container_cardinality(ptr noundef %19)
  store i32 %20, ptr %10, align 4, !tbaa !9
  %21 = load i32, ptr %8, align 4, !tbaa !9
  %22 = load ptr, ptr %7, align 8, !tbaa !5
  %23 = load i32, ptr %22, align 4, !tbaa !9
  %24 = load i32, ptr %10, align 4, !tbaa !9
  %25 = add i32 %23, %24
  %26 = icmp uge i32 %21, %25
  br i1 %26, label %27, label %32

27:                                               ; preds = %4
  %28 = load i32, ptr %10, align 4, !tbaa !9
  %29 = load ptr, ptr %7, align 8, !tbaa !5
  %30 = load i32, ptr %29, align 4, !tbaa !9
  %31 = add i32 %30, %28
  store i32 %31, ptr %29, align 4, !tbaa !9
  store i1 false, ptr %5, align 1
  store i32 1, ptr %11, align 4
  br label %113

32:                                               ; preds = %4
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #5
  %33 = load ptr, ptr %6, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.bitset_container_s, ptr %33, i32 0, i32 1
  %35 = load ptr, ptr %34, align 8, !tbaa !11
  store ptr %35, ptr %12, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #5
  store i32 0, ptr %14, align 4, !tbaa !9
  br label %36

36:                                               ; preds = %106, %32
  %37 = load i32, ptr %14, align 4, !tbaa !9
  %38 = icmp slt i32 %37, 1024
  br i1 %38, label %40, label %39

39:                                               ; preds = %36
  store i32 2, ptr %11, align 4
  br label %109

40:                                               ; preds = %36
  %41 = load ptr, ptr %12, align 8, !tbaa !5
  %42 = load i32, ptr %14, align 4, !tbaa !9
  %43 = sext i32 %42 to i64
  %44 = getelementptr inbounds i64, ptr %41, i64 %43
  %45 = load i64, ptr %44, align 8, !tbaa !13
  %46 = call i32 @hamming(i64 noundef %45)
  store i32 %46, ptr %13, align 4, !tbaa !9
  %47 = load i32, ptr %8, align 4, !tbaa !9
  %48 = load ptr, ptr %7, align 8, !tbaa !5
  %49 = load i32, ptr %48, align 4, !tbaa !9
  %50 = load i32, ptr %13, align 4, !tbaa !9
  %51 = add i32 %49, %50
  %52 = icmp ule i32 %47, %51
  br i1 %52, label %53, label %100

53:                                               ; preds = %40
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #5
  %54 = load ptr, ptr %6, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.bitset_container_s, ptr %54, i32 0, i32 1
  %56 = load ptr, ptr %55, align 8, !tbaa !11
  %57 = load i32, ptr %14, align 4, !tbaa !9
  %58 = sext i32 %57 to i64
  %59 = getelementptr inbounds i64, ptr %56, i64 %58
  %60 = load i64, ptr %59, align 8, !tbaa !13
  store i64 %60, ptr %15, align 8, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 2, ptr %16) #5
  %61 = load i32, ptr %14, align 4, !tbaa !9
  %62 = mul nsw i32 %61, 64
  %63 = trunc i32 %62 to i16
  store i16 %63, ptr %16, align 2, !tbaa !15
  br label %64

64:                                               ; preds = %95, %53
  %65 = load i64, ptr %15, align 8, !tbaa !13
  %66 = icmp ne i64 %65, 0
  br i1 %66, label %67, label %96

67:                                               ; preds = %64
  call void @llvm.lifetime.start.p0(i64 8, ptr %17) #5
  %68 = load i64, ptr %15, align 8, !tbaa !13
  %69 = load i64, ptr %15, align 8, !tbaa !13
  %70 = xor i64 %69, -1
  %71 = add i64 %70, 1
  %72 = and i64 %68, %71
  store i64 %72, ptr %17, align 8, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 4, ptr %18) #5
  %73 = load i64, ptr %15, align 8, !tbaa !13
  %74 = call i64 @llvm.cttz.i64(i64 %73, i1 true)
  %75 = trunc i64 %74 to i32
  store i32 %75, ptr %18, align 4, !tbaa !9
  %76 = load ptr, ptr %7, align 8, !tbaa !5
  %77 = load i32, ptr %76, align 4, !tbaa !9
  %78 = load i32, ptr %8, align 4, !tbaa !9
  %79 = icmp eq i32 %77, %78
  br i1 %79, label %80, label %86

80:                                               ; preds = %67
  %81 = load i32, ptr %18, align 4, !tbaa !9
  %82 = load i16, ptr %16, align 2, !tbaa !15
  %83 = zext i16 %82 to i32
  %84 = add nsw i32 %81, %83
  %85 = load ptr, ptr %9, align 8, !tbaa !5
  store i32 %84, ptr %85, align 4, !tbaa !9
  store i1 true, ptr %5, align 1
  store i32 1, ptr %11, align 4
  br label %93

86:                                               ; preds = %67
  %87 = load i64, ptr %17, align 8, !tbaa !13
  %88 = load i64, ptr %15, align 8, !tbaa !13
  %89 = xor i64 %88, %87
  store i64 %89, ptr %15, align 8, !tbaa !13
  %90 = load ptr, ptr %7, align 8, !tbaa !5
  %91 = load i32, ptr %90, align 4, !tbaa !9
  %92 = add i32 %91, 1
  store i32 %92, ptr %90, align 4, !tbaa !9
  store i32 0, ptr %11, align 4
  br label %93

93:                                               ; preds = %86, %80
  call void @llvm.lifetime.end.p0(i64 4, ptr %18) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %17) #5
  %94 = load i32, ptr %11, align 4
  switch i32 %94, label %97 [
    i32 0, label %95
  ]

95:                                               ; preds = %93
  br label %64, !llvm.loop !17

96:                                               ; preds = %64
  store i32 0, ptr %11, align 4
  br label %97

97:                                               ; preds = %96, %93
  call void @llvm.lifetime.end.p0(i64 2, ptr %16) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #5
  %98 = load i32, ptr %11, align 4
  switch i32 %98, label %109 [
    i32 0, label %99
  ]

99:                                               ; preds = %97
  br label %105

100:                                              ; preds = %40
  %101 = load i32, ptr %13, align 4, !tbaa !9
  %102 = load ptr, ptr %7, align 8, !tbaa !5
  %103 = load i32, ptr %102, align 4, !tbaa !9
  %104 = add i32 %103, %101
  store i32 %104, ptr %102, align 4, !tbaa !9
  br label %105

105:                                              ; preds = %100, %99
  br label %106

106:                                              ; preds = %105
  %107 = load i32, ptr %14, align 4, !tbaa !9
  %108 = add nsw i32 %107, 1
  store i32 %108, ptr %14, align 4, !tbaa !9
  br label %36, !llvm.loop !19

109:                                              ; preds = %97, %39
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #5
  %110 = load i32, ptr %11, align 4
  switch i32 %110, label %112 [
    i32 2, label %111
  ]

111:                                              ; preds = %109
  call void @__assert_fail(ptr noundef @.str.4, ptr noundef @.str.5, i32 noundef 661, ptr noundef @__PRETTY_FUNCTION__.bitset_container_select) #6
  unreachable

112:                                              ; preds = %109
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #5
  br label %113

113:                                              ; preds = %112, %27
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #5
  %114 = load i1, ptr %5, align 1
  ret i1 %114
}

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

attributes #0 = { inlinehint 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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 = { 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 #5 = { nounwind }
attributes #6 = { 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 = !{!"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, !6, i64 8}
!12 = !{!"bitset_container_s", !10, i64 0, !6, i64 8}
!13 = !{!14, !14, i64 0}
!14 = !{!"long", !7, i64 0}
!15 = !{!16, !16, i64 0}
!16 = !{!"short", !7, i64 0}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}
!19 = distinct !{!19, !18}


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

@.str.4 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [90 x i8], align 1
@__PRETTY_FUNCTION__.bitset_container_select = external hidden unnamed_addr constant [92 x i8], align 1

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @bitset_container_cardinality(ptr noundef) local_unnamed_addr #0

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @hamming(i64 noundef) local_unnamed_addr #0

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

; Function Attrs: nounwind uwtable
define dso_local noundef zeroext i1 @bitset_container_select(ptr noundef %0, ptr nocapture noundef %1, i32 noundef %2, ptr nocapture noundef writeonly %3) local_unnamed_addr #2 {
  %5 = tail call i32 @bitset_container_cardinality(ptr noundef %0)
  %6 = load i32, ptr %1, align 4, !tbaa !5
  %7 = add i32 %6, %5
  %.not = icmp ugt i32 %7, %2
  br i1 %.not, label %9, label %8

8:                                                ; preds = %4
  store i32 %7, ptr %1, align 4, !tbaa !5
  br label %34

9:                                                ; preds = %4
  %10 = getelementptr inbounds i8, ptr %0, i64 8
  %11 = load ptr, ptr %10, align 8, !tbaa !9
  br label %12

12:                                               ; preds = %9, %.critedge
  %indvars.iv = phi i64 [ 0, %9 ], [ %indvars.iv.next, %.critedge ]
  %13 = getelementptr inbounds i64, ptr %11, i64 %indvars.iv
  %14 = load i64, ptr %13, align 8, !tbaa !12
  %15 = tail call i32 @hamming(i64 noundef %14)
  %16 = load i32, ptr %1, align 4, !tbaa !5
  %17 = add i32 %16, %15
  %.not46 = icmp ult i32 %17, %2
  br i1 %.not46, label %27, label %18

18:                                               ; preds = %12
  %19 = load ptr, ptr %10, align 8, !tbaa !9
  %20 = getelementptr inbounds i64, ptr %19, i64 %indvars.iv
  %21 = load i64, ptr %20, align 8, !tbaa !12
  %.not4753 = icmp eq i64 %21, 0
  br i1 %.not4753, label %.critedge, label %.lr.ph

.lr.ph:                                           ; preds = %18, %23
  %22 = phi i32 [ %26, %23 ], [ %16, %18 ]
  %.04054 = phi i64 [ %25, %23 ], [ %21, %18 ]
  %.not48 = icmp eq i32 %22, %2
  br i1 %.not48, label %28, label %23

23:                                               ; preds = %.lr.ph
  %24 = add i64 %.04054, -1
  %25 = and i64 %24, %.04054
  %26 = add i32 %22, 1
  store i32 %26, ptr %1, align 4, !tbaa !5
  %.not47 = icmp eq i64 %25, 0
  br i1 %.not47, label %.critedge, label %.lr.ph

27:                                               ; preds = %12
  store i32 %17, ptr %1, align 4, !tbaa !5
  br label %.critedge

.critedge:                                        ; preds = %23, %18, %27
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond = icmp eq i64 %indvars.iv.next, 1024
  br i1 %exitcond, label %.critedge50, label %12, !llvm.loop !14

28:                                               ; preds = %.lr.ph
  %29 = trunc nuw nsw i64 %indvars.iv to i32
  %30 = shl nuw nsw i32 %29, 6
  %31 = tail call range(i64 0, 65) i64 @llvm.cttz.i64(i64 %.04054, i1 true)
  %32 = trunc nuw nsw i64 %31 to i32
  %33 = or disjoint i32 %30, %32
  store i32 %33, ptr %3, align 4, !tbaa !5
  br label %34

.critedge50:                                      ; preds = %.critedge
  tail call void @__assert_fail(ptr noundef nonnull @.str.4, ptr noundef nonnull @.str.5, i32 noundef 661, ptr noundef nonnull @__PRETTY_FUNCTION__.bitset_container_select) #4
  unreachable

34:                                               ; preds = %28, %8
  ret i1 %.not
}

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

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


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