; 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

; Function Attrs: nounwind uwtable
define dso_local zeroext i1 @bitset_bitset_container_intersection(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 %32

15:                                               ; preds = %3
  %16 = call ptr @bitset_container_create()
  %17 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr %16, ptr %17, align 8, !tbaa !5
  %18 = load ptr, ptr %7, align 8, !tbaa !5
  %19 = load ptr, ptr %18, align 8, !tbaa !5
  %20 = icmp ne ptr %19, null
  br i1 %20, label %21, label %31

21:                                               ; preds = %15
  %22 = load ptr, ptr %5, align 8, !tbaa !5
  %23 = load ptr, ptr %6, align 8, !tbaa !5
  %24 = load ptr, ptr %7, align 8, !tbaa !5
  %25 = load ptr, ptr %24, align 8, !tbaa !5
  %26 = call i32 @bitset_container_and_nocard(ptr noundef %22, ptr noundef %23, ptr noundef %25)
  %27 = load i32, ptr %8, align 4, !tbaa !9
  %28 = load ptr, ptr %7, align 8, !tbaa !5
  %29 = load ptr, ptr %28, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.bitset_container_s, ptr %29, i32 0, i32 0
  store i32 %27, ptr %30, align 8, !tbaa !11
  br label %31

31:                                               ; preds = %21, %15
  store i1 true, ptr %4, align 1
  store i32 1, ptr %9, align 4
  br label %56

32:                                               ; preds = %3
  %33 = load i32, ptr %8, align 4, !tbaa !9
  %34 = call ptr @array_container_create_given_capacity(i32 noundef %33)
  %35 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr %34, ptr %35, align 8, !tbaa !5
  %36 = load ptr, ptr %7, align 8, !tbaa !5
  %37 = load ptr, ptr %36, align 8, !tbaa !5
  %38 = icmp ne ptr %37, null
  br i1 %38, label %39, label %55

39:                                               ; preds = %32
  %40 = load i32, ptr %8, align 4, !tbaa !9
  %41 = load ptr, ptr %7, align 8, !tbaa !5
  %42 = load ptr, ptr %41, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.array_container_s, ptr %42, i32 0, i32 0
  store i32 %40, ptr %43, align 8, !tbaa !13
  %44 = load ptr, ptr %5, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.bitset_container_s, ptr %44, i32 0, i32 1
  %46 = load ptr, ptr %45, align 8, !tbaa !15
  %47 = load ptr, ptr %6, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.bitset_container_s, ptr %47, i32 0, i32 1
  %49 = load ptr, ptr %48, align 8, !tbaa !15
  %50 = load ptr, ptr %7, align 8, !tbaa !5
  %51 = load ptr, ptr %50, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.array_container_s, ptr %51, i32 0, i32 2
  %53 = load ptr, ptr %52, align 8, !tbaa !16
  %54 = call i64 @bitset_extract_intersection_setbits_uint16(ptr noundef %46, ptr noundef %49, i64 noundef 1024, ptr noundef %53, i16 noundef zeroext 0)
  br label %55

55:                                               ; preds = %39, %32
  store i1 false, ptr %4, align 1
  store i32 1, ptr %9, align 4
  br label %56

56:                                               ; preds = %55, %31
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  %57 = load i1, ptr %4, align 1
  ret i1 %57
}

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

declare ptr @bitset_container_create() #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

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

; Function Attrs: nounwind uwtable
define dso_local noundef zeroext i1 @bitset_bitset_container_intersection(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 %11

6:                                                ; preds = %3
  %7 = tail call ptr @bitset_container_create() #2
  store ptr %7, ptr %2, align 8, !tbaa !5
  %.not21 = icmp eq ptr %7, null
  br i1 %.not21, label %21, label %8

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

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

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

21:                                               ; preds = %11, %13, %6, %8
  ret i1 %5
}

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

declare ptr @bitset_container_create() 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

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