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

15:                                               ; preds = %70, %2
  %16 = load i32, ptr %8, align 4, !tbaa !11
  %17 = load ptr, ptr %4, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.run_container_s, ptr %17, i32 0, i32 0
  %19 = load i32, ptr %18, align 8, !tbaa !13
  %20 = icmp slt i32 %16, %19
  br i1 %20, label %22, label %21

21:                                               ; preds = %15
  store i32 2, ptr %9, align 4
  br label %73

22:                                               ; preds = %15
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #2
  %23 = load ptr, ptr %4, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.run_container_s, ptr %23, i32 0, i32 2
  %25 = load ptr, ptr %24, align 8, !tbaa !15
  %26 = load i32, ptr %8, align 4, !tbaa !11
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds %struct.rle16_s, ptr %25, i64 %27
  %29 = getelementptr inbounds %struct.rle16_s, ptr %28, i32 0, i32 0
  %30 = load i16, ptr %29, align 2, !tbaa !16
  %31 = zext i16 %30 to i32
  store i32 %31, ptr %10, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #2
  %32 = load ptr, ptr %4, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.run_container_s, ptr %32, i32 0, i32 2
  %34 = load ptr, ptr %33, align 8, !tbaa !15
  %35 = load i32, ptr %8, align 4, !tbaa !11
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds %struct.rle16_s, ptr %34, i64 %36
  %38 = getelementptr inbounds %struct.rle16_s, ptr %37, i32 0, i32 1
  %39 = load i16, ptr %38, align 2, !tbaa !18
  %40 = zext i16 %39 to i32
  store i32 %40, ptr %11, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #2
  %41 = load i32, ptr %11, align 4, !tbaa !11
  %42 = load i32, ptr %10, align 4, !tbaa !11
  %43 = add i32 %41, %42
  store i32 %43, ptr %12, align 4, !tbaa !11
  %44 = load i16, ptr %5, align 2, !tbaa !9
  %45 = zext i16 %44 to i32
  %46 = load i32, ptr %12, align 4, !tbaa !11
  %47 = icmp ule i32 %45, %46
  br i1 %47, label %48, label %61

48:                                               ; preds = %22
  %49 = load i16, ptr %5, align 2, !tbaa !9
  %50 = zext i16 %49 to i32
  %51 = load i32, ptr %10, align 4, !tbaa !11
  %52 = icmp ult i32 %50, %51
  br i1 %52, label %53, label %54

53:                                               ; preds = %48
  store i32 2, ptr %9, align 4
  br label %67

54:                                               ; preds = %48
  %55 = load i32, ptr %6, align 4, !tbaa !11
  %56 = load i32, ptr %7, align 4, !tbaa !11
  %57 = load i32, ptr %10, align 4, !tbaa !11
  %58 = sub i32 %56, %57
  %59 = add i32 %55, %58
  %60 = add i32 %59, 1
  store i32 %60, ptr %3, align 4
  store i32 1, ptr %9, align 4
  br label %67

61:                                               ; preds = %22
  %62 = load i32, ptr %11, align 4, !tbaa !11
  %63 = add i32 %62, 1
  %64 = load i32, ptr %6, align 4, !tbaa !11
  %65 = add i32 %64, %63
  store i32 %65, ptr %6, align 4, !tbaa !11
  br label %66

66:                                               ; preds = %61
  store i32 0, ptr %9, align 4
  br label %67

67:                                               ; preds = %66, %54, %53
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #2
  %68 = load i32, ptr %9, align 4
  switch i32 %68, label %73 [
    i32 0, label %69
  ]

69:                                               ; preds = %67
  br label %70

70:                                               ; preds = %69
  %71 = load i32, ptr %8, align 4, !tbaa !11
  %72 = add nsw i32 %71, 1
  store i32 %72, ptr %8, align 4, !tbaa !11
  br label %15, !llvm.loop !19

73:                                               ; preds = %67, %21
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  %74 = load i32, ptr %9, align 4
  switch i32 %74, label %77 [
    i32 2, label %75
  ]

75:                                               ; preds = %73
  %76 = load i32, ptr %6, align 4, !tbaa !11
  store i32 %76, ptr %3, align 4
  store i32 1, ptr %9, align 4
  br label %77

77:                                               ; preds = %75, %73
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  %78 = load i32, ptr %3, align 4
  ret i32 %78
}

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 = !{!"short", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !12, i64 0}
!14 = !{!"run_container_s", !12, i64 0, !12, i64 4, !6, i64 8}
!15 = !{!14, !6, i64 8}
!16 = !{!17, !10, i64 0}
!17 = !{!"rle16_s", !10, i64 0, !10, i64 2}
!18 = !{!17, !10, i64 2}
!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, inaccessiblemem: none) uwtable
define dso_local i32 @run_container_rank(ptr nocapture noundef readonly %0, i16 noundef zeroext %1) local_unnamed_addr #0 {
  %3 = zext i16 %1 to i32
  %4 = load i32, ptr %0, align 8, !tbaa !5
  %5 = icmp sgt i32 %4, 0
  br i1 %5, label %.lr.ph, label %.thread34

.lr.ph:                                           ; preds = %2
  %6 = getelementptr inbounds i8, ptr %0, i64 8
  %7 = load ptr, ptr %6, align 8, !tbaa !11
  %wide.trip.count = zext nneg i32 %4 to i64
  br label %8

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

16:                                               ; preds = %8
  %17 = icmp ugt i16 %10, %1
  br i1 %17, label %.thread34, label %21

18:                                               ; preds = %8
  %19 = add i32 %.02347, 1
  %20 = add i32 %19, %14
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %.thread34, label %8, !llvm.loop !16

21:                                               ; preds = %16
  %22 = add nuw nsw i32 %3, 1
  %23 = add i32 %22, %.02347
  %24 = sub i32 %23, %11
  br label %.thread34

.thread34:                                        ; preds = %18, %2, %16, %21
  %25 = phi i32 [ %24, %21 ], [ %.02347, %16 ], [ 0, %2 ], [ %20, %18 ]
  ret i32 %25
}

attributes #0 = { nofree norecurse nosync nounwind memory(read, 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 = !{!13, !14, i64 0}
!13 = !{!"rle16_s", !14, i64 0, !14, i64 2}
!14 = !{!"short", !8, i64 0}
!15 = !{!13, !14, i64 2}
!16 = distinct !{!16, !17}
!17 = !{!"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