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

; 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 }
%struct.array_container_s = type { i32, 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_create_given_capacity(i32 noundef) #1

declare i32 @bitset_container_and_justcard(ptr noundef, ptr noundef) #1

declare i32 @bitset_container_and_nocard(ptr noundef, ptr noundef, ptr noundef) #1

declare i64 @bitset_extract_intersection_setbits_uint16(ptr noundef, ptr noundef, i64 noundef, ptr noundef, i16 noundef zeroext) #1

; Function Attrs: nounwind uwtable
define dso_local zeroext i1 @bitset_bitset_container_intersection_inplace(ptr noundef %0, ptr noundef %1, ptr noundef %2) #2 {
  %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 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 4, ptr %8) #3
  %10 = load ptr, ptr %5, align 8, !tbaa !5
  %11 = load ptr, ptr %6, align 8, !tbaa !5
  %12 = call i32 @bitset_container_and_justcard(ptr noundef %10, ptr noundef %11)
  store i32 %12, ptr %8, align 4, !tbaa !9
  %13 = load i32, ptr %8, align 4, !tbaa !9
  %14 = icmp sgt i32 %13, 4096
  br i1 %14, label %15, label %26

15:                                               ; preds = %3
  %16 = load ptr, ptr %5, align 8, !tbaa !5
  %17 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr %16, ptr %17, align 8, !tbaa !5
  %18 = load ptr, ptr %5, align 8, !tbaa !5
  %19 = load ptr, ptr %6, align 8, !tbaa !5
  %20 = load ptr, ptr %5, align 8, !tbaa !5
  %21 = call i32 @bitset_container_and_nocard(ptr noundef %18, ptr noundef %19, ptr noundef %20)
  %22 = load i32, ptr %8, align 4, !tbaa !9
  %23 = load ptr, ptr %7, align 8, !tbaa !5
  %24 = load ptr, ptr %23, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.bitset_container_s, ptr %24, i32 0, i32 0
  store i32 %22, ptr %25, align 8, !tbaa !11
  store i1 true, ptr %4, align 1
  store i32 1, ptr %9, align 4
  br label %50

26:                                               ; preds = %3
  %27 = load i32, ptr %8, align 4, !tbaa !9
  %28 = call ptr @array_container_create_given_capacity(i32 noundef %27)
  %29 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr %28, ptr %29, align 8, !tbaa !5
  %30 = load ptr, ptr %7, align 8, !tbaa !5
  %31 = load ptr, ptr %30, align 8, !tbaa !5
  %32 = icmp ne ptr %31, null
  br i1 %32, label %33, label %49

33:                                               ; preds = %26
  %34 = load i32, ptr %8, align 4, !tbaa !9
  %35 = load ptr, ptr %7, align 8, !tbaa !5
  %36 = load ptr, ptr %35, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.array_container_s, ptr %36, i32 0, i32 0
  store i32 %34, ptr %37, align 8, !tbaa !13
  %38 = load ptr, ptr %5, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.bitset_container_s, ptr %38, i32 0, i32 1
  %40 = load ptr, ptr %39, align 8, !tbaa !15
  %41 = load ptr, ptr %6, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.bitset_container_s, ptr %41, i32 0, i32 1
  %43 = load ptr, ptr %42, align 8, !tbaa !15
  %44 = load ptr, ptr %7, align 8, !tbaa !5
  %45 = load ptr, ptr %44, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.array_container_s, ptr %45, i32 0, i32 2
  %47 = load ptr, ptr %46, align 8, !tbaa !16
  %48 = call i64 @bitset_extract_intersection_setbits_uint16(ptr noundef %40, ptr noundef %43, i64 noundef 1024, ptr noundef %47, i16 noundef zeroext 0)
  br label %49

49:                                               ; preds = %33, %26
  store i1 false, ptr %4, align 1
  store i32 1, ptr %9, align 4
  br label %50

50:                                               ; preds = %49, %15
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  %51 = load i1, ptr %4, align 1
  ret i1 %51
}

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 = { 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 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 0}
!12 = !{!"bitset_container_s", !10, i64 0, !6, i64 8}
!13 = !{!14, !10, i64 0}
!14 = !{!"array_container_s", !10, i64 0, !10, i64 4, !6, i64 8}
!15 = !{!12, !6, i64 8}
!16 = !{!14, !6, i64 8}


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

declare ptr @array_container_create_given_capacity(i32 noundef) local_unnamed_addr #0

declare i32 @bitset_container_and_justcard(ptr noundef, ptr noundef) local_unnamed_addr #0

declare i32 @bitset_container_and_nocard(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #0

declare i64 @bitset_extract_intersection_setbits_uint16(ptr noundef, ptr noundef, i64 noundef, ptr noundef, i16 noundef zeroext) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local noundef zeroext i1 @bitset_bitset_container_intersection_inplace(ptr noundef %0, ptr noundef %1, ptr nocapture noundef %2) local_unnamed_addr #1 {
  %4 = tail call i32 @bitset_container_and_justcard(ptr noundef %0, ptr noundef %1) #2
  %5 = icmp sgt i32 %4, 4096
  br i1 %5, label %6, label %9

6:                                                ; preds = %3
  store ptr %0, ptr %2, align 8, !tbaa !5
  %7 = tail call i32 @bitset_container_and_nocard(ptr noundef %0, ptr noundef %1, ptr noundef %0) #2
  %8 = load ptr, ptr %2, align 8, !tbaa !5
  store i32 %4, ptr %8, align 8, !tbaa !9
  br label %19

9:                                                ; preds = %3
  %10 = tail call ptr @array_container_create_given_capacity(i32 noundef %4) #2
  store ptr %10, ptr %2, align 8, !tbaa !5
  %.not = icmp eq ptr %10, null
  br i1 %.not, label %19, label %11

11:                                               ; preds = %9
  store i32 %4, ptr %10, align 8, !tbaa !12
  %12 = getelementptr inbounds i8, ptr %0, i64 8
  %13 = load ptr, ptr %12, align 8, !tbaa !14
  %14 = getelementptr inbounds i8, ptr %1, i64 8
  %15 = load ptr, ptr %14, align 8, !tbaa !14
  %16 = getelementptr inbounds i8, ptr %10, i64 8
  %17 = load ptr, ptr %16, align 8, !tbaa !15
  %18 = tail call i64 @bitset_extract_intersection_setbits_uint16(ptr noundef %13, ptr noundef %15, i64 noundef 1024, ptr noundef %17, i16 noundef zeroext 0) #2
  br label %19

19:                                               ; preds = %9, %11, %6
  ret i1 %5
}

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 = { 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 }

!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 = !{!"bitset_container_s", !11, i64 0, !6, i64 8}
!11 = !{!"int", !7, i64 0}
!12 = !{!13, !11, i64 0}
!13 = !{!"array_container_s", !11, i64 0, !11, i64 4, !6, i64 8}
!14 = !{!10, !6, i64 8}
!15 = !{!13, !6, i64 8}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass