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

; 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.array_container_s = type { i32, i32, ptr }
%struct.bitset_container_s = type { i32, ptr }

declare i64 @bitset_set_list_withcard(ptr noundef, i64 noundef, ptr noundef, i64 noundef) #0

declare void @bitset_set_list(ptr noundef, ptr noundef, i64 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: nounwind uwtable
define dso_local zeroext i1 @array_array_container_union(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
  %10 = alloca i8, align 1
  %11 = alloca ptr, align 8
  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
  %12 = load ptr, ptr %5, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.array_container_s, ptr %12, i32 0, i32 0
  %14 = load i32, ptr %13, align 8, !tbaa !9
  %15 = load ptr, ptr %6, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.array_container_s, ptr %15, i32 0, i32 0
  %17 = load i32, ptr %16, align 8, !tbaa !9
  %18 = add nsw i32 %14, %17
  store i32 %18, ptr %8, align 4, !tbaa !12
  %19 = load i32, ptr %8, align 4, !tbaa !12
  %20 = icmp sle i32 %19, 4096
  br i1 %20, label %21, label %35

21:                                               ; preds = %3
  %22 = load i32, ptr %8, align 4, !tbaa !12
  %23 = call ptr @array_container_create_given_capacity(i32 noundef %22)
  %24 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr %23, ptr %24, align 8, !tbaa !5
  %25 = load ptr, ptr %7, align 8, !tbaa !5
  %26 = load ptr, ptr %25, align 8, !tbaa !5
  %27 = icmp ne ptr %26, null
  br i1 %27, label %28, label %33

28:                                               ; preds = %21
  %29 = load ptr, ptr %5, align 8, !tbaa !5
  %30 = load ptr, ptr %6, align 8, !tbaa !5
  %31 = load ptr, ptr %7, align 8, !tbaa !5
  %32 = load ptr, ptr %31, align 8, !tbaa !5
  call void @array_container_union(ptr noundef %29, ptr noundef %30, ptr noundef %32)
  br label %34

33:                                               ; preds = %21
  store i1 true, ptr %4, align 1
  store i32 1, ptr %9, align 4
  br label %85

34:                                               ; preds = %28
  store i1 false, ptr %4, align 1
  store i32 1, ptr %9, align 4
  br label %85

35:                                               ; preds = %3
  %36 = call ptr @bitset_container_create()
  %37 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr %36, ptr %37, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 1, ptr %10) #3
  store i8 1, ptr %10, align 1, !tbaa !13
  %38 = load ptr, ptr %7, align 8, !tbaa !5
  %39 = load ptr, ptr %38, align 8, !tbaa !5
  %40 = icmp ne ptr %39, null
  br i1 %40, label %41, label %82

41:                                               ; preds = %35
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #3
  %42 = load ptr, ptr %7, align 8, !tbaa !5
  %43 = load ptr, ptr %42, align 8, !tbaa !5
  store ptr %43, ptr %11, align 8, !tbaa !5
  %44 = load ptr, ptr %11, 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 %5, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.array_container_s, ptr %47, i32 0, i32 2
  %49 = load ptr, ptr %48, align 8, !tbaa !17
  %50 = load ptr, ptr %5, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.array_container_s, ptr %50, i32 0, i32 0
  %52 = load i32, ptr %51, align 8, !tbaa !9
  %53 = sext i32 %52 to i64
  call void @bitset_set_list(ptr noundef %46, ptr noundef %49, i64 noundef %53)
  %54 = load ptr, ptr %11, 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 !15
  %57 = load ptr, ptr %5, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.array_container_s, ptr %57, i32 0, i32 0
  %59 = load i32, ptr %58, align 8, !tbaa !9
  %60 = sext i32 %59 to i64
  %61 = load ptr, ptr %6, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.array_container_s, ptr %61, i32 0, i32 2
  %63 = load ptr, ptr %62, align 8, !tbaa !17
  %64 = load ptr, ptr %6, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.array_container_s, ptr %64, i32 0, i32 0
  %66 = load i32, ptr %65, align 8, !tbaa !9
  %67 = sext i32 %66 to i64
  %68 = call i64 @bitset_set_list_withcard(ptr noundef %56, i64 noundef %60, ptr noundef %63, i64 noundef %67)
  %69 = trunc i64 %68 to i32
  %70 = load ptr, ptr %11, align 8, !tbaa !5
  %71 = getelementptr inbounds %struct.bitset_container_s, ptr %70, i32 0, i32 0
  store i32 %69, ptr %71, align 8, !tbaa !18
  %72 = load ptr, ptr %11, align 8, !tbaa !5
  %73 = getelementptr inbounds %struct.bitset_container_s, ptr %72, i32 0, i32 0
  %74 = load i32, ptr %73, align 8, !tbaa !18
  %75 = icmp sle i32 %74, 4096
  br i1 %75, label %76, label %81

76:                                               ; preds = %41
  %77 = load ptr, ptr %11, align 8, !tbaa !5
  %78 = call ptr @array_container_from_bitset(ptr noundef %77)
  %79 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr %78, ptr %79, align 8, !tbaa !5
  %80 = load ptr, ptr %11, align 8, !tbaa !5
  call void @bitset_container_free(ptr noundef %80)
  store i8 0, ptr %10, align 1, !tbaa !13
  br label %81

81:                                               ; preds = %76, %41
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  br label %82

82:                                               ; preds = %81, %35
  %83 = load i8, ptr %10, align 1, !tbaa !13, !range !19, !noundef !20
  %84 = trunc i8 %83 to i1
  store i1 %84, ptr %4, align 1
  store i32 1, ptr %9, align 4
  call void @llvm.lifetime.end.p0(i64 1, ptr %10) #3
  br label %85

85:                                               ; preds = %82, %34, %33
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  %86 = load i1, ptr %4, align 1
  ret i1 %86
}

declare ptr @array_container_create_given_capacity(i32 noundef) #0

declare void @array_container_union(ptr noundef, ptr noundef, ptr noundef) #0

declare ptr @bitset_container_create() #0

declare ptr @array_container_from_bitset(ptr noundef) #0

declare void @bitset_container_free(ptr noundef) #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = !{!"array_container_s", !11, i64 0, !11, i64 4, !6, i64 8}
!11 = !{!"int", !7, i64 0}
!12 = !{!11, !11, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"_Bool", !7, i64 0}
!15 = !{!16, !6, i64 8}
!16 = !{!"bitset_container_s", !11, i64 0, !6, i64 8}
!17 = !{!10, !6, i64 8}
!18 = !{!16, !11, i64 0}
!19 = !{i8 0, i8 2}
!20 = !{}


; 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 i64 @bitset_set_list_withcard(ptr noundef, i64 noundef, ptr noundef, i64 noundef) local_unnamed_addr #0

declare void @bitset_set_list(ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local noundef zeroext i1 @array_array_container_union(ptr noundef %0, ptr noundef %1, ptr nocapture noundef writeonly %2) local_unnamed_addr #1 {
  %4 = load i32, ptr %0, align 8, !tbaa !5
  %5 = load i32, ptr %1, align 8, !tbaa !5
  %6 = add nsw i32 %5, %4
  %7 = icmp slt i32 %6, 4097
  br i1 %7, label %8, label %11

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

10:                                               ; preds = %8
  tail call void @array_container_union(ptr noundef nonnull %0, ptr noundef nonnull %1, ptr noundef nonnull %9) #2
  br label %32

11:                                               ; preds = %3
  %12 = tail call ptr @bitset_container_create() #2
  store ptr %12, ptr %2, align 8, !tbaa !11
  %.not = icmp eq ptr %12, null
  br i1 %.not, label %32, label %13

13:                                               ; preds = %11
  %14 = getelementptr inbounds i8, ptr %12, i64 8
  %15 = load ptr, ptr %14, align 8, !tbaa !12
  %16 = getelementptr inbounds i8, ptr %0, i64 8
  %17 = load ptr, ptr %16, align 8, !tbaa !14
  %18 = load i32, ptr %0, align 8, !tbaa !5
  %19 = sext i32 %18 to i64
  tail call void @bitset_set_list(ptr noundef %15, ptr noundef %17, i64 noundef %19) #2
  %20 = load ptr, ptr %14, align 8, !tbaa !12
  %21 = load i32, ptr %0, align 8, !tbaa !5
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds i8, ptr %1, i64 8
  %24 = load ptr, ptr %23, align 8, !tbaa !14
  %25 = load i32, ptr %1, align 8, !tbaa !5
  %26 = sext i32 %25 to i64
  %27 = tail call i64 @bitset_set_list_withcard(ptr noundef %20, i64 noundef %22, ptr noundef %24, i64 noundef %26) #2
  %28 = trunc i64 %27 to i32
  store i32 %28, ptr %12, align 8, !tbaa !15
  %29 = icmp sgt i32 %28, 4096
  br i1 %29, label %32, label %30

30:                                               ; preds = %13
  %31 = tail call ptr @array_container_from_bitset(ptr noundef nonnull %12) #2
  store ptr %31, ptr %2, align 8, !tbaa !11
  tail call void @bitset_container_free(ptr noundef nonnull %12) #2
  br label %32

32:                                               ; preds = %11, %30, %13, %8, %10
  %.0 = phi i1 [ false, %10 ], [ true, %8 ], [ true, %11 ], [ false, %30 ], [ true, %13 ]
  ret i1 %.0
}

declare ptr @array_container_create_given_capacity(i32 noundef) local_unnamed_addr #0

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

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

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


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