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

; Function Attrs: inlinehint nounwind uwtable
declare hidden zeroext i1 @run_container_is_full(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 i32 @advanceUntil(ptr noundef, i32 noundef, i32 noundef, i16 noundef zeroext) #1

; Function Attrs: nounwind uwtable
define dso_local i32 @array_run_container_intersection_cardinality(ptr noundef %0, ptr noundef %1) #3 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca %struct.rle16_s, align 2
  %9 = alloca i32, align 4
  %10 = alloca i16, align 2
  %11 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  %12 = load ptr, ptr %5, align 8, !tbaa !5
  %13 = call zeroext i1 @run_container_is_full(ptr noundef %12)
  br i1 %13, label %14, label %18

14:                                               ; preds = %2
  %15 = load ptr, ptr %4, 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
  store i32 %17, ptr %3, align 4
  br label %103

18:                                               ; preds = %2
  %19 = load ptr, ptr %5, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.run_container_s, ptr %19, i32 0, i32 0
  %21 = load i32, ptr %20, align 8, !tbaa !12
  %22 = icmp eq i32 %21, 0
  br i1 %22, label %23, label %24

23:                                               ; preds = %18
  store i32 0, ptr %3, align 4
  br label %103

24:                                               ; preds = %18
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  store i32 0, ptr %6, align 4, !tbaa !14
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  store i32 0, ptr %7, align 4, !tbaa !14
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  %25 = load ptr, ptr %5, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.run_container_s, ptr %25, i32 0, i32 2
  %27 = load ptr, ptr %26, align 8, !tbaa !15
  %28 = load i32, ptr %6, align 4, !tbaa !14
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds %struct.rle16_s, ptr %27, i64 %29
  call void @llvm.memcpy.p0.p0.i64(ptr align 2 %8, ptr align 2 %30, i64 4, i1 false), !tbaa.struct !16
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  store i32 0, ptr %9, align 4, !tbaa !14
  br label %31

31:                                               ; preds = %99, %24
  %32 = load i32, ptr %7, align 4, !tbaa !14
  %33 = load ptr, ptr %4, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.array_container_s, ptr %33, i32 0, i32 0
  %35 = load i32, ptr %34, align 8, !tbaa !9
  %36 = icmp slt i32 %32, %35
  br i1 %36, label %37, label %100

37:                                               ; preds = %31
  call void @llvm.lifetime.start.p0(i64 2, ptr %10) #4
  %38 = load ptr, ptr %4, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.array_container_s, ptr %38, i32 0, i32 2
  %40 = load ptr, ptr %39, align 8, !tbaa !19
  %41 = load i32, ptr %7, align 4, !tbaa !14
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds i16, ptr %40, i64 %42
  %44 = load i16, ptr %43, align 2, !tbaa !17
  store i16 %44, ptr %10, align 2, !tbaa !17
  br label %45

45:                                               ; preds = %66, %37
  %46 = getelementptr inbounds %struct.rle16_s, ptr %8, i32 0, i32 0
  %47 = load i16, ptr %46, align 2, !tbaa !20
  %48 = zext i16 %47 to i32
  %49 = getelementptr inbounds %struct.rle16_s, ptr %8, i32 0, i32 1
  %50 = load i16, ptr %49, align 2, !tbaa !22
  %51 = zext i16 %50 to i32
  %52 = add nsw i32 %48, %51
  %53 = load i16, ptr %10, align 2, !tbaa !17
  %54 = zext i16 %53 to i32
  %55 = icmp slt i32 %52, %54
  br i1 %55, label %56, label %73

56:                                               ; preds = %45
  %57 = load i32, ptr %6, align 4, !tbaa !14
  %58 = add nsw i32 %57, 1
  store i32 %58, ptr %6, align 4, !tbaa !14
  %59 = load i32, ptr %6, align 4, !tbaa !14
  %60 = load ptr, ptr %5, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.run_container_s, ptr %60, i32 0, i32 0
  %62 = load i32, ptr %61, align 8, !tbaa !12
  %63 = icmp eq i32 %59, %62
  br i1 %63, label %64, label %66

64:                                               ; preds = %56
  %65 = load i32, ptr %9, align 4, !tbaa !14
  store i32 %65, ptr %3, align 4
  store i32 1, ptr %11, align 4
  br label %97

66:                                               ; preds = %56
  %67 = load ptr, ptr %5, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct.run_container_s, ptr %67, i32 0, i32 2
  %69 = load ptr, ptr %68, align 8, !tbaa !15
  %70 = load i32, ptr %6, align 4, !tbaa !14
  %71 = sext i32 %70 to i64
  %72 = getelementptr inbounds %struct.rle16_s, ptr %69, i64 %71
  call void @llvm.memcpy.p0.p0.i64(ptr align 2 %8, ptr align 2 %72, i64 4, i1 false), !tbaa.struct !16
  br label %45, !llvm.loop !23

73:                                               ; preds = %45
  %74 = getelementptr inbounds %struct.rle16_s, ptr %8, i32 0, i32 0
  %75 = load i16, ptr %74, align 2, !tbaa !20
  %76 = zext i16 %75 to i32
  %77 = load i16, ptr %10, align 2, !tbaa !17
  %78 = zext i16 %77 to i32
  %79 = icmp sgt i32 %76, %78
  br i1 %79, label %80, label %91

80:                                               ; preds = %73
  %81 = load ptr, ptr %4, align 8, !tbaa !5
  %82 = getelementptr inbounds %struct.array_container_s, ptr %81, i32 0, i32 2
  %83 = load ptr, ptr %82, align 8, !tbaa !19
  %84 = load i32, ptr %7, align 4, !tbaa !14
  %85 = load ptr, ptr %4, align 8, !tbaa !5
  %86 = getelementptr inbounds %struct.array_container_s, ptr %85, i32 0, i32 0
  %87 = load i32, ptr %86, align 8, !tbaa !9
  %88 = getelementptr inbounds %struct.rle16_s, ptr %8, i32 0, i32 0
  %89 = load i16, ptr %88, align 2, !tbaa !20
  %90 = call i32 @advanceUntil(ptr noundef %83, i32 noundef %84, i32 noundef %87, i16 noundef zeroext %89)
  store i32 %90, ptr %7, align 4, !tbaa !14
  br label %96

91:                                               ; preds = %73
  %92 = load i32, ptr %9, align 4, !tbaa !14
  %93 = add nsw i32 %92, 1
  store i32 %93, ptr %9, align 4, !tbaa !14
  %94 = load i32, ptr %7, align 4, !tbaa !14
  %95 = add nsw i32 %94, 1
  store i32 %95, ptr %7, align 4, !tbaa !14
  br label %96

96:                                               ; preds = %91, %80
  store i32 0, ptr %11, align 4
  br label %97

97:                                               ; preds = %96, %64
  call void @llvm.lifetime.end.p0(i64 2, ptr %10) #4
  %98 = load i32, ptr %11, align 4
  switch i32 %98, label %102 [
    i32 0, label %99
  ]

99:                                               ; preds = %97
  br label %31, !llvm.loop !25

100:                                              ; preds = %31
  %101 = load i32, ptr %9, align 4, !tbaa !14
  store i32 %101, ptr %3, align 4
  store i32 1, ptr %11, align 4
  br label %102

102:                                              ; preds = %100, %97
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  br label %103

103:                                              ; preds = %102, %23, %14
  %104 = load i32, ptr %3, align 4
  ret i32 %104
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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 }

!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 = !{!13, !11, i64 0}
!13 = !{!"run_container_s", !11, i64 0, !11, i64 4, !6, i64 8}
!14 = !{!11, !11, i64 0}
!15 = !{!13, !6, i64 8}
!16 = !{i64 0, i64 2, !17, i64 2, i64 2, !17}
!17 = !{!18, !18, i64 0}
!18 = !{!"short", !7, i64 0}
!19 = !{!10, !6, i64 8}
!20 = !{!21, !18, i64 0}
!21 = !{!"rle16_s", !18, i64 0, !18, i64 2}
!22 = !{!21, !18, i64 2}
!23 = distinct !{!23, !24}
!24 = !{!"llvm.loop.mustprogress"}
!25 = distinct !{!25, !24}


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

; Function Attrs: inlinehint nounwind uwtable
declare hidden zeroext i1 @run_container_is_full(ptr noundef) local_unnamed_addr #0

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @advanceUntil(ptr noundef, i32 noundef, i32 noundef, i16 noundef zeroext) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local i32 @array_run_container_intersection_cardinality(ptr nocapture noundef readonly %0, ptr noundef %1) local_unnamed_addr #1 {
  %3 = tail call zeroext i1 @run_container_is_full(ptr noundef %1)
  br i1 %3, label %4, label %6

4:                                                ; preds = %2
  %5 = load i32, ptr %0, align 8, !tbaa !5
  br label %.thread

6:                                                ; preds = %2
  %7 = load i32, ptr %1, align 8, !tbaa !11
  %8 = icmp eq i32 %7, 0
  br i1 %8, label %.thread, label %9

9:                                                ; preds = %6
  %10 = getelementptr inbounds i8, ptr %1, i64 8
  %11 = load i32, ptr %0, align 8, !tbaa !5
  %12 = icmp sgt i32 %11, 0
  br i1 %12, label %.lr.ph61, label %.thread

.lr.ph61:                                         ; preds = %9
  %13 = load ptr, ptr %10, align 8, !tbaa !13
  %.sroa.7.0..sroa_idx = getelementptr inbounds i8, ptr %13, i64 2
  %.sroa.7.0.copyload = load i16, ptr %.sroa.7.0..sroa_idx, align 2, !tbaa !14
  %.sroa.0.0.copyload = load i16, ptr %13, align 2, !tbaa !14
  %14 = getelementptr inbounds i8, ptr %0, i64 8
  br label %15

15:                                               ; preds = %.lr.ph61, %42
  %16 = phi i32 [ %11, %.lr.ph61 ], [ %43, %42 ]
  %.03059 = phi i32 [ 0, %.lr.ph61 ], [ %.232, %42 ]
  %.sroa.0.058 = phi i16 [ %.sroa.0.0.copyload, %.lr.ph61 ], [ %.sroa.0.1.lcssa, %42 ]
  %.sroa.7.057 = phi i16 [ %.sroa.7.0.copyload, %.lr.ph61 ], [ %.sroa.7.1.lcssa, %42 ]
  %.03356 = phi i32 [ 0, %.lr.ph61 ], [ %.235, %42 ]
  %.03655 = phi i32 [ 0, %.lr.ph61 ], [ %.137.lcssa, %42 ]
  %17 = load ptr, ptr %14, align 8, !tbaa !16
  %18 = sext i32 %.03356 to i64
  %19 = getelementptr inbounds i16, ptr %17, i64 %18
  %20 = load i16, ptr %19, align 2, !tbaa !14
  %21 = zext i16 %20 to i32
  %22 = zext i16 %.sroa.0.058 to i32
  %23 = zext i16 %.sroa.7.057 to i32
  %24 = add nuw nsw i32 %22, %23
  %.not51 = icmp ult i32 %24, %21
  br i1 %.not51, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %15
  %25 = load i32, ptr %1, align 8, !tbaa !11
  %26 = sext i32 %.03655 to i64
  br label %27

27:                                               ; preds = %.lr.ph, %30
  %indvars.iv = phi i64 [ %26, %.lr.ph ], [ %indvars.iv.next, %30 ]
  %indvars.iv.next = add nsw i64 %indvars.iv, 1
  %28 = trunc nsw i64 %indvars.iv.next to i32
  %29 = icmp eq i32 %25, %28
  br i1 %29, label %.thread, label %30

30:                                               ; preds = %27
  %31 = load ptr, ptr %10, align 8, !tbaa !13
  %32 = getelementptr inbounds %struct.rle16_s, ptr %31, i64 %indvars.iv.next
  %.sroa.0.0.copyload8 = load i16, ptr %32, align 2, !tbaa !14
  %.sroa.7.0..sroa_idx9 = getelementptr inbounds i8, ptr %32, i64 2
  %.sroa.7.0.copyload10 = load i16, ptr %.sroa.7.0..sroa_idx9, align 2, !tbaa !14
  %33 = zext i16 %.sroa.0.0.copyload8 to i32
  %34 = zext i16 %.sroa.7.0.copyload10 to i32
  %35 = add nuw nsw i32 %33, %34
  %.not = icmp ult i32 %35, %21
  br i1 %.not, label %27, label %._crit_edge, !llvm.loop !17

._crit_edge:                                      ; preds = %30, %15
  %.137.lcssa = phi i32 [ %.03655, %15 ], [ %28, %30 ]
  %.sroa.7.1.lcssa = phi i16 [ %.sroa.7.057, %15 ], [ %.sroa.7.0.copyload10, %30 ]
  %.sroa.0.1.lcssa = phi i16 [ %.sroa.0.058, %15 ], [ %.sroa.0.0.copyload8, %30 ]
  %36 = icmp ugt i16 %.sroa.0.1.lcssa, %20
  br i1 %36, label %37, label %39

37:                                               ; preds = %._crit_edge
  %38 = tail call i32 @advanceUntil(ptr noundef %17, i32 noundef %.03356, i32 noundef %16, i16 noundef zeroext %.sroa.0.1.lcssa)
  %.pre = load i32, ptr %0, align 8, !tbaa !5
  br label %42

39:                                               ; preds = %._crit_edge
  %40 = add nsw i32 %.03059, 1
  %41 = add nsw i32 %.03356, 1
  br label %42

42:                                               ; preds = %37, %39
  %43 = phi i32 [ %.pre, %37 ], [ %16, %39 ]
  %.235 = phi i32 [ %38, %37 ], [ %41, %39 ]
  %.232 = phi i32 [ %.03059, %37 ], [ %40, %39 ]
  %44 = icmp slt i32 %.235, %43
  br i1 %44, label %15, label %.thread

.thread:                                          ; preds = %42, %27, %9, %6, %4
  %.3 = phi i32 [ %5, %4 ], [ 0, %6 ], [ 0, %9 ], [ %.03059, %27 ], [ %.232, %42 ]
  ret i32 %.3
}

attributes #0 = { 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 #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" }

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


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