; 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 @bitset_container_create() #1

declare void @bitset_container_copy(ptr noundef, ptr noundef) #1

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_andnot(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 ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca %struct.rle16_s, align 2
  %11 = alloca i32, align 4
  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
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #5
  %12 = call ptr @bitset_container_create()
  store ptr %12, ptr %8, align 8, !tbaa !5
  %13 = load ptr, ptr %5, align 8, !tbaa !5
  %14 = load ptr, ptr %8, align 8, !tbaa !5
  call void @bitset_container_copy(ptr noundef %13, ptr noundef %14)
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #5
  store i32 0, ptr %9, align 4, !tbaa !9
  br label %15

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

21:                                               ; preds = %15
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #5
  br label %46

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

43:                                               ; preds = %22
  %44 = load i32, ptr %9, align 4, !tbaa !9
  %45 = add nsw i32 %44, 1
  store i32 %45, ptr %9, align 4, !tbaa !9
  br label %15, !llvm.loop !22

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

55:                                               ; preds = %46
  %56 = load ptr, ptr %8, align 8, !tbaa !5
  %57 = call ptr @array_container_from_bitset(ptr noundef %56)
  %58 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr %57, ptr %58, align 8, !tbaa !5
  %59 = load ptr, ptr %8, align 8, !tbaa !5
  call void @bitset_container_free(ptr noundef %59)
  store i1 false, ptr %4, align 1
  store i32 1, ptr %11, align 4
  br label %63

60:                                               ; preds = %46
  %61 = load ptr, ptr %8, align 8, !tbaa !5
  %62 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr %61, ptr %62, align 8, !tbaa !5
  store i1 true, ptr %4, align 1
  store i32 1, ptr %11, align 4
  br label %63

63:                                               ; preds = %60, %55
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #5
  %64 = load i1, ptr %4, align 1
  ret i1 %64
}

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 @bitset_container_create() local_unnamed_addr #0

declare void @bitset_container_copy(ptr noundef, ptr noundef) local_unnamed_addr #0

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_andnot(ptr noundef %0, ptr nocapture noundef readonly %1, ptr nocapture noundef writeonly %2) local_unnamed_addr #2 {
  %4 = tail call ptr @bitset_container_create() #3
  tail call void @bitset_container_copy(ptr noundef %0, ptr noundef %4) #3
  %5 = load i32, ptr %1, align 8, !tbaa !5
  %6 = icmp sgt i32 %5, 0
  br i1 %6, label %.lr.ph, label %._crit_edge

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

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

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

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

24:                                               ; preds = %._crit_edge
  store ptr %4, ptr %2, align 8, !tbaa !19
  br label %25

25:                                               ; preds = %24, %22
  ret i1 %10
}

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


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