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

; 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.rle16_s = type { i16, i16 }
%struct.run_container_s = type { i32, i32, ptr }
%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

declare ptr @array_container_from_bitset(ptr noundef) #1

declare void @bitset_container_free(ptr noundef) #1

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #2

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @bitset_reset_range(ptr noundef, i32 noundef, i32 noundef) #3

declare i32 @bitset_container_compute_cardinality(ptr noundef) #1

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

12:                                               ; preds = %40, %3
  %13 = load i32, ptr %8, align 4, !tbaa !9
  %14 = load ptr, ptr %6, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.run_container_s, ptr %14, i32 0, i32 0
  %16 = load i32, ptr %15, align 8, !tbaa !11
  %17 = icmp slt i32 %13, %16
  br i1 %17, label %19, label %18

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

19:                                               ; preds = %12
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #5
  %20 = load ptr, ptr %6, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.run_container_s, ptr %20, i32 0, i32 2
  %22 = load ptr, ptr %21, align 8, !tbaa !13
  %23 = load i32, ptr %8, align 4, !tbaa !9
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds %struct.rle16_s, ptr %22, i64 %24
  call void @llvm.memcpy.p0.p0.i64(ptr align 2 %9, ptr align 2 %25, i64 4, i1 false), !tbaa.struct !14
  %26 = load ptr, ptr %5, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.bitset_container_s, ptr %26, i32 0, i32 1
  %28 = load ptr, ptr %27, align 8, !tbaa !17
  %29 = getelementptr inbounds %struct.rle16_s, ptr %9, i32 0, i32 0
  %30 = load i16, ptr %29, align 2, !tbaa !19
  %31 = zext i16 %30 to i32
  %32 = getelementptr inbounds %struct.rle16_s, ptr %9, i32 0, i32 0
  %33 = load i16, ptr %32, align 2, !tbaa !19
  %34 = zext i16 %33 to i32
  %35 = getelementptr inbounds %struct.rle16_s, ptr %9, i32 0, i32 1
  %36 = load i16, ptr %35, align 2, !tbaa !21
  %37 = zext i16 %36 to i32
  %38 = add nsw i32 %34, %37
  %39 = add i32 %38, 1
  call void @bitset_reset_range(ptr noundef %28, i32 noundef %31, i32 noundef %39)
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #5
  br label %40

40:                                               ; preds = %19
  %41 = load i32, ptr %8, align 4, !tbaa !9
  %42 = add nsw i32 %41, 1
  store i32 %42, ptr %8, align 4, !tbaa !9
  br label %12, !llvm.loop !22

43:                                               ; preds = %18
  %44 = load ptr, ptr %5, align 8, !tbaa !5
  %45 = call i32 @bitset_container_compute_cardinality(ptr noundef %44)
  %46 = load ptr, ptr %5, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.bitset_container_s, ptr %46, i32 0, i32 0
  store i32 %45, ptr %47, align 8, !tbaa !24
  %48 = load ptr, ptr %5, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.bitset_container_s, ptr %48, i32 0, i32 0
  %50 = load i32, ptr %49, align 8, !tbaa !24
  %51 = icmp sle i32 %50, 4096
  br i1 %51, label %52, label %57

52:                                               ; preds = %43
  %53 = load ptr, ptr %5, align 8, !tbaa !5
  %54 = call ptr @array_container_from_bitset(ptr noundef %53)
  %55 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr %54, ptr %55, align 8, !tbaa !5
  %56 = load ptr, ptr %5, align 8, !tbaa !5
  call void @bitset_container_free(ptr noundef %56)
  store i1 false, ptr %4, align 1
  br label %58

57:                                               ; preds = %43
  store i1 true, ptr %4, align 1
  br label %58

58:                                               ; preds = %57, %52
  %59 = load i1, ptr %4, align 1
  ret i1 %59
}

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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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 #4 = { 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 #5 = { 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, !10, i64 0}
!12 = !{!"run_container_s", !10, i64 0, !10, i64 4, !6, i64 8}
!13 = !{!12, !6, i64 8}
!14 = !{i64 0, i64 2, !15, i64 2, i64 2, !15}
!15 = !{!16, !16, i64 0}
!16 = !{!"short", !7, i64 0}
!17 = !{!18, !6, i64 8}
!18 = !{!"bitset_container_s", !10, i64 0, !6, i64 8}
!19 = !{!20, !16, i64 0}
!20 = !{!"rle16_s", !16, i64 0, !16, i64 2}
!21 = !{!20, !16, i64 2}
!22 = distinct !{!22, !23}
!23 = !{!"llvm.loop.mustprogress"}
!24 = !{!18, !10, i64 0}


; 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.rle16_s = type { i16, i16 }

declare ptr @array_container_from_bitset(ptr noundef) local_unnamed_addr #0

declare void @bitset_container_free(ptr noundef) local_unnamed_addr #0

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @bitset_reset_range(ptr noundef, i32 noundef, i32 noundef) local_unnamed_addr #1

declare i32 @bitset_container_compute_cardinality(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local noundef zeroext i1 @bitset_run_container_iandnot(ptr noundef %0, ptr nocapture noundef readonly %1, ptr nocapture noundef writeonly %2) local_unnamed_addr #2 {
  store ptr %0, ptr %2, align 8, !tbaa !5
  %4 = load i32, ptr %1, align 8, !tbaa !9
  %5 = icmp sgt i32 %4, 0
  br i1 %5, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %3
  %6 = getelementptr inbounds i8, ptr %1, i64 8
  %7 = getelementptr inbounds i8, ptr %0, i64 8
  br label %10

._crit_edge:                                      ; preds = %10, %3
  %8 = tail call i32 @bitset_container_compute_cardinality(ptr noundef %0) #3
  store i32 %8, ptr %0, align 8, !tbaa !12
  %9 = icmp sgt i32 %8, 4096
  br i1 %9, label %23, label %21

10:                                               ; preds = %.lr.ph, %10
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %10 ]
  %11 = load ptr, ptr %6, align 8, !tbaa !14
  %12 = getelementptr inbounds %struct.rle16_s, ptr %11, i64 %indvars.iv
  %.sroa.0.0.copyload = load i16, ptr %12, align 2, !tbaa !15
  %.sroa.5.0..sroa_idx = getelementptr inbounds i8, ptr %12, i64 2
  %.sroa.5.0.copyload = load i16, ptr %.sroa.5.0..sroa_idx, align 2, !tbaa !15
  %13 = load ptr, ptr %7, align 8, !tbaa !17
  %14 = zext i16 %.sroa.0.0.copyload to i32
  %15 = zext i16 %.sroa.5.0.copyload to i32
  %16 = add nuw nsw i32 %14, 1
  %17 = add nuw nsw i32 %16, %15
  tail call void @bitset_reset_range(ptr noundef %13, i32 noundef %14, i32 noundef %17)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %18 = load i32, ptr %1, align 8, !tbaa !9
  %19 = sext i32 %18 to i64
  %20 = icmp slt i64 %indvars.iv.next, %19
  br i1 %20, label %10, label %._crit_edge, !llvm.loop !18

21:                                               ; preds = %._crit_edge
  %22 = tail call ptr @array_container_from_bitset(ptr noundef nonnull %0) #3
  store ptr %22, ptr %2, align 8, !tbaa !5
  tail call void @bitset_container_free(ptr noundef nonnull %0) #3
  br label %23

23:                                               ; preds = %._crit_edge, %21
  ret i1 %9
}

attributes #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 = { 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 #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, !11, i64 0}
!10 = !{!"run_container_s", !11, i64 0, !11, i64 4, !6, i64 8}
!11 = !{!"int", !7, i64 0}
!12 = !{!13, !11, i64 0}
!13 = !{!"bitset_container_s", !11, i64 0, !6, i64 8}
!14 = !{!10, !6, i64 8}
!15 = !{!16, !16, i64 0}
!16 = !{!"short", !7, i64 0}
!17 = !{!13, !6, i64 8}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}


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