; LLVM IR from facebook/redex :: libredex/ConcurrentContainers.ll (ZN7cc_impl36get_prime_number_greater_or_equal_toEm)

; 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.std::array" = type { [27 x i32] }

@_ZZN7cc_impl36get_prime_number_greater_or_equal_toEmE6primes = external hidden global %"struct.std::array", align 4

; 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: mustprogress nounwind uwtable
define dso_local noundef i64 @_ZN7cc_impl36get_prime_number_greater_or_equal_toEm(i64 noundef %0) #1 {
  %2 = alloca i64, align 8
  %3 = alloca i64, align 8
  %4 = alloca i64, align 8
  %5 = alloca i32, align 4
  store i64 %0, ptr %3, align 8, !tbaa !5
  %6 = load i64, ptr %3, align 8, !tbaa !5
  %7 = lshr i64 %6, 3
  store i64 %7, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  store i64 0, ptr %4, align 8, !tbaa !5
  br label %8

8:                                                ; preds = %12, %1
  %9 = load i64, ptr %3, align 8, !tbaa !5
  %10 = lshr i64 %9, 1
  store i64 %10, ptr %3, align 8, !tbaa !5
  %11 = icmp ne i64 %10, 0
  br i1 %11, label %12, label %15

12:                                               ; preds = %8
  %13 = load i64, ptr %4, align 8, !tbaa !5
  %14 = add i64 %13, 1
  store i64 %14, ptr %4, align 8, !tbaa !5
  br label %8, !llvm.loop !9

15:                                               ; preds = %8
  %16 = load i64, ptr %4, align 8, !tbaa !5
  %17 = call noundef i64 @_ZNKSt5arrayIjLm27EE4sizeEv(ptr noundef nonnull align 4 dereferenceable(108) @_ZZN7cc_impl36get_prime_number_greater_or_equal_toEmE6primes) #4
  %18 = icmp uge i64 %16, %17
  br i1 %18, label %19, label %24

19:                                               ; preds = %15
  %20 = load i64, ptr %4, align 8, !tbaa !5
  %21 = add i64 %20, 4
  %22 = shl i64 1, %21
  %23 = sub i64 %22, 1
  store i64 %23, ptr %2, align 8
  store i32 1, ptr %5, align 4
  br label %29

24:                                               ; preds = %15
  %25 = load i64, ptr %4, align 8, !tbaa !5
  %26 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt5arrayIjLm27EEixEm(ptr noundef nonnull align 4 dereferenceable(108) @_ZZN7cc_impl36get_prime_number_greater_or_equal_toEmE6primes, i64 noundef %25) #3
  %27 = load i32, ptr %26, align 4, !tbaa !11
  %28 = zext i32 %27 to i64
  store i64 %28, ptr %2, align 8
  store i32 1, ptr %5, align 4
  br label %29

29:                                               ; preds = %24, %19
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  %30 = load i64, ptr %2, align 8
  ret i64 %30
}

; Function Attrs: mustprogress nounwind willreturn memory(none) uwtable
declare dso_local noundef i64 @_ZNKSt5arrayIjLm27EE4sizeEv(ptr noundef nonnull align 4 dereferenceable(108)) #2 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt5arrayIjLm27EEixEm(ptr noundef nonnull align 4 dereferenceable(108), i64 noundef) #1 align 2

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

!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 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !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"

%"struct.std::array" = type { [27 x i32] }

@_ZZN7cc_impl36get_prime_number_greater_or_equal_toEmE6primes = external hidden global %"struct.std::array", align 4

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i64 @_ZN7cc_impl36get_prime_number_greater_or_equal_toEm(i64 noundef %0) local_unnamed_addr #0 {
  %.not11 = icmp ult i64 %0, 16
  br i1 %.not11, label %._crit_edge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %1
  %2 = lshr i64 %0, 3
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %.013 = phi i64 [ %4, %.lr.ph ], [ 0, %.lr.ph.preheader ]
  %.0712 = phi i64 [ %3, %.lr.ph ], [ %2, %.lr.ph.preheader ]
  %3 = lshr i64 %.0712, 1
  %4 = add nuw nsw i64 %.013, 1
  %.not = icmp ult i64 %.0712, 4
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !5

._crit_edge:                                      ; preds = %.lr.ph, %1
  %.0.lcssa = phi i64 [ 0, %1 ], [ %4, %.lr.ph ]
  %5 = tail call noundef i64 @_ZNKSt5arrayIjLm27EE4sizeEv(ptr noundef nonnull align 4 dereferenceable(108) @_ZZN7cc_impl36get_prime_number_greater_or_equal_toEmE6primes) #2
  %.not10 = icmp ult i64 %.0.lcssa, %5
  br i1 %.not10, label %9, label %6

6:                                                ; preds = %._crit_edge
  %7 = add i64 %.0.lcssa, 4
  %notmask = shl nsw i64 -1, %7
  %8 = xor i64 %notmask, -1
  br label %13

9:                                                ; preds = %._crit_edge
  %10 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt5arrayIjLm27EEixEm(ptr noundef nonnull align 4 dereferenceable(108) @_ZZN7cc_impl36get_prime_number_greater_or_equal_toEmE6primes, i64 noundef %.0.lcssa) #3
  %11 = load i32, ptr %10, align 4, !tbaa !7
  %12 = zext i32 %11 to i64
  br label %13

13:                                               ; preds = %9, %6
  %.08 = phi i64 [ %8, %6 ], [ %12, %9 ]
  ret i64 %.08
}

; Function Attrs: mustprogress nofree nosync nounwind willreturn memory(none) uwtable
declare dso_local noundef i64 @_ZNKSt5arrayIjLm27EE4sizeEv(ptr noundef nonnull align 4 dereferenceable(108)) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt5arrayIjLm27EEixEm(ptr noundef nonnull align 4 dereferenceable(108), i64 noundef) local_unnamed_addr #0 align 2

attributes #0 = { mustprogress 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 = { mustprogress nofree nosync nounwind willreturn memory(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" }
attributes #2 = { nounwind willreturn memory(none) }
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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}
!7 = !{!8, !8, i64 0}
!8 = !{!"int", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C++ TBAA"}


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