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

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

; 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 i32 @advanceUntil(ptr noundef, i32 noundef, i32 noundef, i16 noundef zeroext) #1

; Function Attrs: nounwind uwtable
define dso_local zeroext i1 @intersect_skewed_uint16_nonempty(ptr noundef %0, i64 noundef %1, ptr noundef %2, i64 noundef %3) #2 {
  %5 = alloca i1, align 1
  %6 = alloca ptr, align 8
  %7 = alloca i64, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i64, align 8
  %10 = alloca i64, align 8
  %11 = alloca i64, align 8
  %12 = alloca i32, align 4
  %13 = alloca i16, align 2
  %14 = alloca i16, align 2
  store ptr %0, ptr %6, align 8, !tbaa !5
  store i64 %1, ptr %7, align 8, !tbaa !9
  store ptr %2, ptr %8, align 8, !tbaa !5
  store i64 %3, ptr %9, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  store i64 0, ptr %10, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #3
  store i64 0, ptr %11, align 8, !tbaa !9
  %15 = load i64, ptr %7, align 8, !tbaa !9
  %16 = icmp eq i64 0, %15
  br i1 %16, label %17, label %18

17:                                               ; preds = %4
  store i1 false, ptr %5, align 1
  store i32 1, ptr %12, align 4
  br label %75

18:                                               ; preds = %4
  call void @llvm.lifetime.start.p0(i64 2, ptr %13) #3
  %19 = load ptr, ptr %8, align 8, !tbaa !5
  %20 = load i64, ptr %10, align 8, !tbaa !9
  %21 = getelementptr inbounds i16, ptr %19, i64 %20
  %22 = load i16, ptr %21, align 2, !tbaa !11
  store i16 %22, ptr %13, align 2, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 2, ptr %14) #3
  %23 = load ptr, ptr %6, align 8, !tbaa !5
  %24 = load i64, ptr %11, align 8, !tbaa !9
  %25 = getelementptr inbounds i16, ptr %23, i64 %24
  %26 = load i16, ptr %25, align 2, !tbaa !11
  store i16 %26, ptr %14, align 2, !tbaa !11
  br label %27

27:                                               ; preds = %72, %18
  br label %28

28:                                               ; preds = %27
  %29 = load i16, ptr %13, align 2, !tbaa !11
  %30 = zext i16 %29 to i32
  %31 = load i16, ptr %14, align 2, !tbaa !11
  %32 = zext i16 %31 to i32
  %33 = icmp slt i32 %30, %32
  br i1 %33, label %34, label %52

34:                                               ; preds = %28
  %35 = load ptr, ptr %8, align 8, !tbaa !5
  %36 = load i64, ptr %10, align 8, !tbaa !9
  %37 = trunc i64 %36 to i32
  %38 = load i64, ptr %9, align 8, !tbaa !9
  %39 = trunc i64 %38 to i32
  %40 = load i16, ptr %14, align 2, !tbaa !11
  %41 = call i32 @advanceUntil(ptr noundef %35, i32 noundef %37, i32 noundef %39, i16 noundef zeroext %40)
  %42 = sext i32 %41 to i64
  store i64 %42, ptr %10, align 8, !tbaa !9
  %43 = load i64, ptr %10, align 8, !tbaa !9
  %44 = load i64, ptr %9, align 8, !tbaa !9
  %45 = icmp eq i64 %43, %44
  br i1 %45, label %46, label %47

46:                                               ; preds = %34
  br label %73

47:                                               ; preds = %34
  %48 = load ptr, ptr %8, align 8, !tbaa !5
  %49 = load i64, ptr %10, align 8, !tbaa !9
  %50 = getelementptr inbounds i16, ptr %48, i64 %49
  %51 = load i16, ptr %50, align 2, !tbaa !11
  store i16 %51, ptr %13, align 2, !tbaa !11
  br label %72

52:                                               ; preds = %28
  %53 = load i16, ptr %14, align 2, !tbaa !11
  %54 = zext i16 %53 to i32
  %55 = load i16, ptr %13, align 2, !tbaa !11
  %56 = zext i16 %55 to i32
  %57 = icmp slt i32 %54, %56
  br i1 %57, label %58, label %70

58:                                               ; preds = %52
  %59 = load i64, ptr %11, align 8, !tbaa !9
  %60 = add i64 %59, 1
  store i64 %60, ptr %11, align 8, !tbaa !9
  %61 = load i64, ptr %11, align 8, !tbaa !9
  %62 = load i64, ptr %7, align 8, !tbaa !9
  %63 = icmp eq i64 %61, %62
  br i1 %63, label %64, label %65

64:                                               ; preds = %58
  br label %73

65:                                               ; preds = %58
  %66 = load ptr, ptr %6, align 8, !tbaa !5
  %67 = load i64, ptr %11, align 8, !tbaa !9
  %68 = getelementptr inbounds i16, ptr %66, i64 %67
  %69 = load i16, ptr %68, align 2, !tbaa !11
  store i16 %69, ptr %14, align 2, !tbaa !11
  br label %71

70:                                               ; preds = %52
  store i1 true, ptr %5, align 1
  store i32 1, ptr %12, align 4
  br label %74

71:                                               ; preds = %65
  br label %72

72:                                               ; preds = %71, %47
  br label %27

73:                                               ; preds = %64, %46
  store i1 false, ptr %5, align 1
  store i32 1, ptr %12, align 4
  br label %74

74:                                               ; preds = %73, %70
  call void @llvm.lifetime.end.p0(i64 2, ptr %14) #3
  call void @llvm.lifetime.end.p0(i64 2, ptr %13) #3
  br label %75

75:                                               ; preds = %74, %17
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  %76 = load i1, ptr %5, align 1
  ret i1 %76
}

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 = { 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 = !{!"long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"short", !7, 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"

; 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 noundef zeroext i1 @intersect_skewed_uint16_nonempty(ptr nocapture noundef readonly %0, i64 noundef %1, ptr noundef %2, i64 noundef %3) local_unnamed_addr #1 {
  %5 = icmp eq i64 %1, 0
  br i1 %5, label %.loopexit, label %6

6:                                                ; preds = %4
  %7 = load i16, ptr %0, align 2, !tbaa !5
  %8 = trunc i64 %3 to i32
  br label %.outer

.outer:                                           ; preds = %15, %6
  %.026.ph = phi i32 [ %12, %15 ], [ 0, %6 ]
  %.024.ph = phi i64 [ %.024, %15 ], [ 0, %6 ]
  %.022.ph.in = phi ptr [ %16, %15 ], [ %2, %6 ]
  %.0.ph = phi i16 [ %.0, %15 ], [ %7, %6 ]
  %.022.ph = load i16, ptr %.022.ph.in, align 2, !tbaa !5
  br label %9

9:                                                ; preds = %.outer, %22
  %.024 = phi i64 [ %20, %22 ], [ %.024.ph, %.outer ]
  %.0 = phi i16 [ %24, %22 ], [ %.0.ph, %.outer ]
  %10 = icmp ult i16 %.022.ph, %.0
  br i1 %10, label %11, label %17

11:                                               ; preds = %9
  %12 = tail call i32 @advanceUntil(ptr noundef nonnull %2, i32 noundef %.026.ph, i32 noundef %8, i16 noundef zeroext %.0)
  %13 = sext i32 %12 to i64
  %14 = icmp eq i64 %13, %3
  br i1 %14, label %.loopexit, label %15

15:                                               ; preds = %11
  %16 = getelementptr inbounds i16, ptr %2, i64 %13
  br label %.outer

17:                                               ; preds = %9
  %18 = icmp uge i16 %.0, %.022.ph
  br i1 %18, label %.loopexit, label %19

19:                                               ; preds = %17
  %20 = add i64 %.024, 1
  %21 = icmp eq i64 %20, %1
  br i1 %21, label %.loopexit, label %22

22:                                               ; preds = %19
  %23 = getelementptr inbounds i16, ptr %0, i64 %20
  %24 = load i16, ptr %23, align 2, !tbaa !5
  br label %9

.loopexit:                                        ; preds = %17, %19, %11, %4
  %.129 = phi i1 [ false, %4 ], [ %18, %17 ], [ %18, %19 ], [ false, %11 ]
  ret i1 %.129
}

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, !6, i64 0}
!6 = !{!"short", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}


; Effective O3 passes: AggressiveInstCombinePass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass