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

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

; 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: nounwind uwtable
define dso_local zeroext i1 @run_container_select(ptr noundef %0, ptr noundef %1, i32 noundef %2, ptr noundef %3) #1 {
  %5 = alloca i1, align 1
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i16, align 2
  %13 = alloca i16, align 2
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store i32 %2, ptr %8, align 4, !tbaa !9
  store ptr %3, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #2
  store i32 0, ptr %10, align 4, !tbaa !9
  br label %14

14:                                               ; preds = %65, %4
  %15 = load i32, ptr %10, align 4, !tbaa !9
  %16 = load ptr, ptr %6, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.run_container_s, ptr %16, i32 0, i32 0
  %18 = load i32, ptr %17, align 8, !tbaa !11
  %19 = icmp slt i32 %15, %18
  br i1 %19, label %21, label %20

20:                                               ; preds = %14
  store i32 2, ptr %11, align 4
  br label %68

21:                                               ; preds = %14
  call void @llvm.lifetime.start.p0(i64 2, ptr %12) #2
  %22 = load ptr, ptr %6, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.run_container_s, ptr %22, i32 0, i32 2
  %24 = load ptr, ptr %23, align 8, !tbaa !13
  %25 = load i32, ptr %10, align 4, !tbaa !9
  %26 = sext i32 %25 to i64
  %27 = getelementptr inbounds %struct.rle16_s, ptr %24, i64 %26
  %28 = getelementptr inbounds %struct.rle16_s, ptr %27, i32 0, i32 1
  %29 = load i16, ptr %28, align 2, !tbaa !14
  store i16 %29, ptr %12, align 2, !tbaa !17
  %30 = load i32, ptr %8, align 4, !tbaa !9
  %31 = load ptr, ptr %7, align 8, !tbaa !5
  %32 = load i32, ptr %31, align 4, !tbaa !9
  %33 = load i16, ptr %12, align 2, !tbaa !17
  %34 = zext i16 %33 to i32
  %35 = add i32 %32, %34
  %36 = icmp ule i32 %30, %35
  br i1 %36, label %37, label %54

37:                                               ; preds = %21
  call void @llvm.lifetime.start.p0(i64 2, ptr %13) #2
  %38 = load ptr, ptr %6, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.run_container_s, ptr %38, i32 0, i32 2
  %40 = load ptr, ptr %39, align 8, !tbaa !13
  %41 = load i32, ptr %10, align 4, !tbaa !9
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds %struct.rle16_s, ptr %40, i64 %42
  %44 = getelementptr inbounds %struct.rle16_s, ptr %43, i32 0, i32 0
  %45 = load i16, ptr %44, align 2, !tbaa !18
  store i16 %45, ptr %13, align 2, !tbaa !17
  %46 = load i16, ptr %13, align 2, !tbaa !17
  %47 = zext i16 %46 to i32
  %48 = load i32, ptr %8, align 4, !tbaa !9
  %49 = add i32 %47, %48
  %50 = load ptr, ptr %7, align 8, !tbaa !5
  %51 = load i32, ptr %50, align 4, !tbaa !9
  %52 = sub i32 %49, %51
  %53 = load ptr, ptr %9, align 8, !tbaa !5
  store i32 %52, ptr %53, align 4, !tbaa !9
  store i1 true, ptr %5, align 1
  store i32 1, ptr %11, align 4
  call void @llvm.lifetime.end.p0(i64 2, ptr %13) #2
  br label %62

54:                                               ; preds = %21
  %55 = load i16, ptr %12, align 2, !tbaa !17
  %56 = zext i16 %55 to i32
  %57 = add nsw i32 %56, 1
  %58 = load ptr, ptr %7, align 8, !tbaa !5
  %59 = load i32, ptr %58, align 4, !tbaa !9
  %60 = add i32 %59, %57
  store i32 %60, ptr %58, align 4, !tbaa !9
  br label %61

61:                                               ; preds = %54
  store i32 0, ptr %11, align 4
  br label %62

62:                                               ; preds = %61, %37
  call void @llvm.lifetime.end.p0(i64 2, ptr %12) #2
  %63 = load i32, ptr %11, align 4
  switch i32 %63, label %68 [
    i32 0, label %64
  ]

64:                                               ; preds = %62
  br label %65

65:                                               ; preds = %64
  %66 = load i32, ptr %10, align 4, !tbaa !9
  %67 = add nsw i32 %66, 1
  store i32 %67, ptr %10, align 4, !tbaa !9
  br label %14, !llvm.loop !19

68:                                               ; preds = %62, %20
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #2
  %69 = load i32, ptr %11, align 4
  switch i32 %69, label %73 [
    i32 2, label %70
    i32 1, label %71
  ]

70:                                               ; preds = %68
  store i1 false, ptr %5, align 1
  br label %71

71:                                               ; preds = %70, %68
  %72 = load i1, ptr %5, align 1
  ret i1 %72

73:                                               ; preds = %68
  unreachable
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 0}
!12 = !{!"run_container_s", !10, i64 0, !10, i64 4, !6, i64 8}
!13 = !{!12, !6, i64 8}
!14 = !{!15, !16, i64 2}
!15 = !{!"rle16_s", !16, i64 0, !16, i64 2}
!16 = !{!"short", !7, i64 0}
!17 = !{!16, !16, i64 0}
!18 = !{!15, !16, i64 0}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}


; 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: nofree norecurse nosync nounwind memory(read, argmem: readwrite, inaccessiblemem: none) uwtable
define dso_local noundef zeroext i1 @run_container_select(ptr nocapture noundef readonly %0, ptr nocapture noundef %1, i32 noundef %2, ptr nocapture noundef writeonly %3) local_unnamed_addr #0 {
  %5 = load i32, ptr %0, align 8, !tbaa !5
  %.not2226 = icmp sgt i32 %5, 0
  br i1 %.not2226, label %.lr.ph, label %.loopexit

.lr.ph:                                           ; preds = %4
  %6 = getelementptr inbounds i8, ptr %0, i64 8
  %7 = load ptr, ptr %6, align 8, !tbaa !11
  %.pre = load i32, ptr %1, align 4, !tbaa !12
  br label %8

8:                                                ; preds = %.lr.ph, %20
  %9 = phi i32 [ %.pre, %.lr.ph ], [ %21, %20 ]
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %20 ]
  %10 = getelementptr inbounds %struct.rle16_s, ptr %7, i64 %indvars.iv
  %11 = getelementptr inbounds i8, ptr %10, i64 2
  %12 = load i16, ptr %11, align 2, !tbaa !13
  %13 = zext i16 %12 to i32
  %14 = add i32 %9, %13
  %.not = icmp ult i32 %14, %2
  br i1 %.not, label %20, label %15

15:                                               ; preds = %8
  %16 = load i16, ptr %10, align 2, !tbaa !16
  %17 = zext i16 %16 to i32
  %18 = sub i32 %2, %9
  %19 = add i32 %18, %17
  store i32 %19, ptr %3, align 4, !tbaa !12
  br label %.loopexit

20:                                               ; preds = %8
  %21 = add nuw i32 %14, 1
  store i32 %21, ptr %1, align 4, !tbaa !12
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %22 = load i32, ptr %0, align 8, !tbaa !5
  %23 = sext i32 %22 to i64
  %.not22 = icmp slt i64 %indvars.iv.next, %23
  br i1 %.not22, label %8, label %.loopexit, !llvm.loop !17

.loopexit:                                        ; preds = %20, %4, %15
  %.not2224 = phi i1 [ true, %15 ], [ false, %4 ], [ false, %20 ]
  ret i1 %.not2224
}

attributes #0 = { nofree norecurse nosync nounwind memory(read, argmem: readwrite, inaccessiblemem: none) 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 = !{!"run_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 = !{!6, !10, i64 8}
!12 = !{!7, !7, i64 0}
!13 = !{!14, !15, i64 2}
!14 = !{!"rle16_s", !15, i64 0, !15, i64 2}
!15 = !{!"short", !8, i64 0}
!16 = !{!14, !15, i64 0}
!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,ReassociatePass,SROAPass,SimplifyCFGPass