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

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

; 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 ptr @run_container_from_array(ptr noundef %0) #1 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %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 i16, align 2
  store ptr %0, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  %12 = load ptr, ptr %3, align 8, !tbaa !5
  %13 = call i32 @array_container_number_of_runs(ptr noundef %12)
  store i32 %13, ptr %4, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  %14 = load i32, ptr %4, align 4, !tbaa !9
  %15 = call ptr @run_container_create_given_capacity(i32 noundef %14)
  store ptr %15, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  store i32 -2, ptr %6, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  store i32 -1, ptr %7, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  %16 = load ptr, ptr %3, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.array_container_s, ptr %16, i32 0, i32 0
  %18 = load i32, ptr %17, align 8, !tbaa !11
  store i32 %18, ptr %8, align 4, !tbaa !9
  %19 = load i32, ptr %8, align 4, !tbaa !9
  %20 = icmp eq i32 %19, 0
  br i1 %20, label %21, label %23

21:                                               ; preds = %1
  %22 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %22, ptr %2, align 8
  store i32 1, ptr %9, align 4
  br label %69

23:                                               ; preds = %1
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  store i32 0, ptr %10, align 4, !tbaa !9
  br label %24

24:                                               ; preds = %61, %23
  %25 = load i32, ptr %10, align 4, !tbaa !9
  %26 = load i32, ptr %8, align 4, !tbaa !9
  %27 = icmp slt i32 %25, %26
  br i1 %27, label %29, label %28

28:                                               ; preds = %24
  store i32 2, ptr %9, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  br label %64

29:                                               ; preds = %24
  call void @llvm.lifetime.start.p0(i64 2, ptr %11) #3
  %30 = load ptr, ptr %3, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.array_container_s, ptr %30, i32 0, i32 2
  %32 = load ptr, ptr %31, align 8, !tbaa !13
  %33 = load i32, ptr %10, align 4, !tbaa !9
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds i16, ptr %32, i64 %34
  %36 = load i16, ptr %35, align 2, !tbaa !14
  store i16 %36, ptr %11, align 2, !tbaa !14
  %37 = load i16, ptr %11, align 2, !tbaa !14
  %38 = zext i16 %37 to i32
  %39 = load i32, ptr %6, align 4, !tbaa !9
  %40 = add nsw i32 %39, 1
  %41 = icmp ne i32 %38, %40
  br i1 %41, label %42, label %52

42:                                               ; preds = %29
  %43 = load i32, ptr %7, align 4, !tbaa !9
  %44 = icmp ne i32 %43, -1
  br i1 %44, label %45, label %49

45:                                               ; preds = %42
  %46 = load ptr, ptr %5, align 8, !tbaa !5
  %47 = load i32, ptr %7, align 4, !tbaa !9
  %48 = load i32, ptr %6, align 4, !tbaa !9
  call void @add_run(ptr noundef %46, i32 noundef %47, i32 noundef %48)
  br label %49

49:                                               ; preds = %45, %42
  %50 = load i16, ptr %11, align 2, !tbaa !14
  %51 = zext i16 %50 to i32
  store i32 %51, ptr %7, align 4, !tbaa !9
  br label %52

52:                                               ; preds = %49, %29
  %53 = load ptr, ptr %3, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.array_container_s, ptr %53, i32 0, i32 2
  %55 = load ptr, ptr %54, align 8, !tbaa !13
  %56 = load i32, ptr %10, align 4, !tbaa !9
  %57 = sext i32 %56 to i64
  %58 = getelementptr inbounds i16, ptr %55, i64 %57
  %59 = load i16, ptr %58, align 2, !tbaa !14
  %60 = zext i16 %59 to i32
  store i32 %60, ptr %6, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 2, ptr %11) #3
  br label %61

61:                                               ; preds = %52
  %62 = load i32, ptr %10, align 4, !tbaa !9
  %63 = add nsw i32 %62, 1
  store i32 %63, ptr %10, align 4, !tbaa !9
  br label %24, !llvm.loop !16

64:                                               ; preds = %28
  %65 = load ptr, ptr %5, align 8, !tbaa !5
  %66 = load i32, ptr %7, align 4, !tbaa !9
  %67 = load i32, ptr %6, align 4, !tbaa !9
  call void @add_run(ptr noundef %65, i32 noundef %66, i32 noundef %67)
  %68 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %68, ptr %2, align 8
  store i32 1, ptr %9, align 4
  br label %69

69:                                               ; preds = %64, %21
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  %70 = load ptr, ptr %2, align 8
  ret ptr %70
}

declare i32 @array_container_number_of_runs(ptr noundef) #2

declare ptr @run_container_create_given_capacity(i32 noundef) #2

; Function Attrs: nounwind uwtable
declare hidden void @add_run(ptr noundef, i32 noundef, i32 noundef) #1

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 = { "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 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 0}
!12 = !{!"array_container_s", !10, i64 0, !10, i64 4, !6, i64 8}
!13 = !{!12, !6, i64 8}
!14 = !{!15, !15, i64 0}
!15 = !{!"short", !7, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"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"

; Function Attrs: nounwind uwtable
define dso_local ptr @run_container_from_array(ptr noundef %0) local_unnamed_addr #0 {
  %2 = tail call i32 @array_container_number_of_runs(ptr noundef %0) #2
  %3 = tail call ptr @run_container_create_given_capacity(i32 noundef %2) #2
  %4 = load i32, ptr %0, align 8, !tbaa !5
  %5 = icmp eq i32 %4, 0
  br i1 %5, label %18, label %.preheader

.preheader:                                       ; preds = %1
  %6 = icmp sgt i32 %4, 0
  br i1 %6, label %.lr.ph, label %._crit_edge

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

._crit_edge:                                      ; preds = %16, %.preheader
  %.025.lcssa = phi i32 [ -1, %.preheader ], [ %.1, %16 ]
  %.024.lcssa = phi i32 [ -2, %.preheader ], [ %.pre-phi, %16 ]
  tail call void @add_run(ptr noundef %3, i32 noundef %.025.lcssa, i32 noundef %.024.lcssa)
  br label %18

8:                                                ; preds = %.lr.ph, %16
  %9 = phi ptr [ %.pre, %.lr.ph ], [ %17, %16 ]
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %16 ]
  %.02429 = phi i32 [ -2, %.lr.ph ], [ %.pre-phi, %16 ]
  %.02528 = phi i32 [ -1, %.lr.ph ], [ %.1, %16 ]
  %10 = getelementptr inbounds i16, ptr %9, i64 %indvars.iv
  %11 = load i16, ptr %10, align 2, !tbaa !12
  %12 = zext i16 %11 to i32
  %13 = add nsw i32 %.02429, 1
  %.not = icmp eq i32 %13, %12
  br i1 %.not, label %16, label %14

14:                                               ; preds = %8
  %.not27 = icmp eq i32 %.02528, -1
  br i1 %.not27, label %16, label %15

15:                                               ; preds = %14
  tail call void @add_run(ptr noundef %3, i32 noundef %.02528, i32 noundef %.02429)
  %.pre33 = load ptr, ptr %7, align 8, !tbaa !11
  %.phi.trans.insert = getelementptr inbounds i16, ptr %.pre33, i64 %indvars.iv
  %.pre34 = load i16, ptr %.phi.trans.insert, align 2, !tbaa !12
  %.pre35 = zext i16 %.pre34 to i32
  br label %16

16:                                               ; preds = %14, %15, %8
  %.pre-phi = phi i32 [ %12, %14 ], [ %.pre35, %15 ], [ %12, %8 ]
  %17 = phi ptr [ %9, %14 ], [ %.pre33, %15 ], [ %9, %8 ]
  %.1 = phi i32 [ %12, %14 ], [ %12, %15 ], [ %.02528, %8 ]
  %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 %._crit_edge, label %8, !llvm.loop !14

18:                                               ; preds = %1, %._crit_edge
  ret ptr %3
}

declare i32 @array_container_number_of_runs(ptr noundef) local_unnamed_addr #1

declare ptr @run_container_create_given_capacity(i32 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare hidden void @add_run(ptr noundef, i32 noundef, i32 noundef) local_unnamed_addr #0

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


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