; LLVM IR from facebook/redex :: service/regalloc/VirtualRegistersFile.ll (ZN8regalloc20VirtualRegistersFile8alloc_atEtm)

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

%"class.boost::dynamic_bitset<>::reference" = type { ptr, i64 }
%"class.regalloc::VirtualRegistersFile" = type { %"class.boost::dynamic_bitset" }
%"class.boost::dynamic_bitset" = type { %"class.std::vector", i64 }
%"class.std::vector" = type { %"struct.std::_Vector_base" }
%"struct.std::_Vector_base" = type { %"struct.std::_Vector_base<unsigned long, std::allocator<unsigned long>>::_Vector_impl" }
%"struct.std::_Vector_base<unsigned long, std::allocator<unsigned long>>::_Vector_impl" = type { %"struct.std::_Vector_base<unsigned long, std::allocator<unsigned long>>::_Vector_impl_data" }
%"struct.std::_Vector_base<unsigned long, std::allocator<unsigned long>>::_Vector_impl_data" = type { ptr, ptr, ptr }

@.str = external hidden unnamed_addr constant [25 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [90 x i8], align 1
@__PRETTY_FUNCTION__._ZN8regalloc20VirtualRegistersFile8alloc_atEtm = external hidden unnamed_addr constant [62 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [2 x i8], align 1

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: mustprogress uwtable
declare dso_local { ptr, i64 } @_ZN5boost14dynamic_bitsetImSaImEEixEm(ptr noundef nonnull align 8 dereferenceable(32), i64 noundef) #1 align 2

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN8regalloc20VirtualRegistersFile8alloc_atEtm(ptr noundef nonnull align 8 dereferenceable(32) %0, i16 noundef zeroext %1, i64 noundef %2) #1 align 2 {
  %4 = alloca ptr, align 8
  %5 = alloca i16, align 2
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  %8 = alloca i64, align 8
  %9 = alloca i64, align 8
  %10 = alloca %"class.boost::dynamic_bitset<>::reference", align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i16 %1, ptr %5, align 2, !tbaa !9
  store i64 %2, ptr %6, align 8, !tbaa !11
  %11 = load ptr, ptr %4, align 8
  %12 = getelementptr inbounds %"class.regalloc::VirtualRegistersFile", ptr %11, i32 0, i32 0
  %13 = call noundef i64 @_ZNK5boost14dynamic_bitsetImSaImEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(32) %12) #4
  %14 = load i16, ptr %5, align 2, !tbaa !9
  %15 = zext i16 %14 to i64
  %16 = load i64, ptr %6, align 8, !tbaa !11
  %17 = add i64 %15, %16
  %18 = icmp ult i64 %13, %17
  br i1 %18, label %19, label %36

19:                                               ; preds = %3
  %20 = getelementptr inbounds %"class.regalloc::VirtualRegistersFile", ptr %11, i32 0, i32 0
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  %21 = getelementptr inbounds %"class.regalloc::VirtualRegistersFile", ptr %11, i32 0, i32 0
  %22 = call noundef i64 @_ZNK5boost14dynamic_bitsetImSaImEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(32) %21) #4
  store i64 %22, ptr %7, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  %23 = load i16, ptr %5, align 2, !tbaa !9
  %24 = zext i16 %23 to i64
  %25 = load i64, ptr %6, align 8, !tbaa !11
  %26 = add i64 %24, %25
  store i64 %26, ptr %8, align 8, !tbaa !11
  %27 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3maxImERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8) %7, ptr noundef nonnull align 8 dereferenceable(8) %8)
  %28 = load i64, ptr %27, align 8, !tbaa !11
  call void @_ZN5boost14dynamic_bitsetImSaImEE6resizeEmb(ptr noundef nonnull align 8 dereferenceable(32) %20, i64 noundef %28, i1 noundef zeroext true)
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  %29 = getelementptr inbounds %"class.regalloc::VirtualRegistersFile", ptr %11, i32 0, i32 0
  %30 = call noundef i64 @_ZNK5boost14dynamic_bitsetImSaImEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(32) %29) #4
  %31 = icmp ule i64 %30, 65535
  br i1 %31, label %32, label %33

32:                                               ; preds = %19
  br label %35

33:                                               ; preds = %19
  call void (ptr, ptr, i32, ptr, i32, ptr, ...) @_Z11assert_failPKcS0_jS0_10RedexErrorS0_z(ptr noundef @.str, ptr noundef @.str.1, i32 noundef 52, ptr noundef @__PRETTY_FUNCTION__._ZN8regalloc20VirtualRegistersFile8alloc_atEtm, i32 noundef 2, ptr noundef @.str.2) #5
  unreachable

34:                                               ; No predecessors!
  br label %35

35:                                               ; preds = %34, %32
  br label %36

36:                                               ; preds = %35, %3
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  store i64 0, ptr %9, align 8, !tbaa !11
  br label %37

37:                                               ; preds = %54, %36
  %38 = load i64, ptr %9, align 8, !tbaa !11
  %39 = load i64, ptr %6, align 8, !tbaa !11
  %40 = icmp ult i64 %38, %39
  br i1 %40, label %42, label %41

41:                                               ; preds = %37
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  br label %57

42:                                               ; preds = %37
  call void @llvm.lifetime.start.p0(i64 16, ptr %10) #4
  %43 = getelementptr inbounds %"class.regalloc::VirtualRegistersFile", ptr %11, i32 0, i32 0
  %44 = load i16, ptr %5, align 2, !tbaa !9
  %45 = zext i16 %44 to i64
  %46 = load i64, ptr %9, align 8, !tbaa !11
  %47 = add i64 %45, %46
  %48 = call { ptr, i64 } @_ZN5boost14dynamic_bitsetImSaImEEixEm(ptr noundef nonnull align 8 dereferenceable(32) %43, i64 noundef %47)
  %49 = getelementptr inbounds { ptr, i64 }, ptr %10, i32 0, i32 0
  %50 = extractvalue { ptr, i64 } %48, 0
  store ptr %50, ptr %49, align 8
  %51 = getelementptr inbounds { ptr, i64 }, ptr %10, i32 0, i32 1
  %52 = extractvalue { ptr, i64 } %48, 1
  store i64 %52, ptr %51, align 8
  %53 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZN5boost14dynamic_bitsetImSaImEE9referenceaSEb(ptr noundef nonnull align 8 dereferenceable(16) %10, i1 noundef zeroext false)
  call void @llvm.lifetime.end.p0(i64 16, ptr %10) #4
  br label %54

54:                                               ; preds = %42
  %55 = load i64, ptr %9, align 8, !tbaa !11
  %56 = add i64 %55, 1
  store i64 %56, ptr %9, align 8, !tbaa !11
  br label %37, !llvm.loop !13

57:                                               ; preds = %41
  ret void
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZNK5boost14dynamic_bitsetImSaImEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(32)) #2 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN5boost14dynamic_bitsetImSaImEE6resizeEmb(ptr noundef nonnull align 8 dereferenceable(32), i64 noundef, i1 noundef zeroext) #1 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3maxImERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef nonnull align 8 dereferenceable(8)) #2

; Function Attrs: noreturn
declare void @_Z11assert_failPKcS0_jS0_10RedexErrorS0_z(ptr noundef, ptr noundef, i32 noundef, ptr noundef, i32 noundef, ptr noundef, ...) #3

; Function Attrs: mustprogress uwtable
declare dso_local noundef nonnull align 8 dereferenceable(16) ptr @_ZN5boost14dynamic_bitsetImSaImEE9referenceaSEb(ptr noundef nonnull align 8 dereferenceable(16), i1 noundef zeroext) #1 align 2

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

!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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"short", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"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"

%"class.boost::dynamic_bitset<>::reference" = type { ptr, i64 }

@.str = external hidden unnamed_addr constant [25 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [90 x i8], align 1
@__PRETTY_FUNCTION__._ZN8regalloc20VirtualRegistersFile8alloc_atEtm = external hidden unnamed_addr constant [62 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [2 x i8], align 1

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: mustprogress uwtable
declare dso_local { ptr, i64 } @_ZN5boost14dynamic_bitsetImSaImEEixEm(ptr noundef nonnull align 8 dereferenceable(32), i64 noundef) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN8regalloc20VirtualRegistersFile8alloc_atEtm(ptr noundef nonnull align 8 dereferenceable(32) %0, i16 noundef zeroext %1, i64 noundef %2) local_unnamed_addr #1 align 2 {
  %4 = alloca i64, align 8
  %5 = alloca i64, align 8
  %6 = alloca %"class.boost::dynamic_bitset<>::reference", align 8
  %7 = tail call noundef i64 @_ZNK5boost14dynamic_bitsetImSaImEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(32) %0) #4
  %8 = zext i16 %1 to i64
  %9 = add i64 %8, %2
  %10 = icmp ult i64 %7, %9
  br i1 %10, label %11, label %18

11:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %4) #4
  %12 = tail call noundef i64 @_ZNK5boost14dynamic_bitsetImSaImEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(32) %0) #4
  store i64 %12, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %5) #4
  store i64 %9, ptr %5, align 8, !tbaa !5
  %13 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3maxImERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8) %4, ptr noundef nonnull align 8 dereferenceable(8) %5)
  %14 = load i64, ptr %13, align 8, !tbaa !5
  call void @_ZN5boost14dynamic_bitsetImSaImEE6resizeEmb(ptr noundef nonnull align 8 dereferenceable(32) %0, i64 noundef %14, i1 noundef zeroext true)
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %5) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #4
  %15 = call noundef i64 @_ZNK5boost14dynamic_bitsetImSaImEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(32) %0) #4
  %16 = icmp ult i64 %15, 65536
  br i1 %16, label %18, label %17

17:                                               ; preds = %11
  call void (ptr, ptr, i32, ptr, i32, ptr, ...) @_Z11assert_failPKcS0_jS0_10RedexErrorS0_z(ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 52, ptr noundef nonnull @__PRETTY_FUNCTION__._ZN8regalloc20VirtualRegistersFile8alloc_atEtm, i32 noundef 2, ptr noundef nonnull @.str.2) #5
  unreachable

18:                                               ; preds = %11, %3
  %.not = icmp eq i64 %2, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %18
  %19 = getelementptr inbounds i8, ptr %6, i64 8
  br label %20

._crit_edge:                                      ; preds = %20, %18
  ret void

20:                                               ; preds = %.lr.ph, %20
  %.010 = phi i64 [ 0, %.lr.ph ], [ %26, %20 ]
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %6) #4
  %21 = add i64 %.010, %8
  %22 = call { ptr, i64 } @_ZN5boost14dynamic_bitsetImSaImEEixEm(ptr noundef nonnull align 8 dereferenceable(32) %0, i64 noundef %21)
  %23 = extractvalue { ptr, i64 } %22, 0
  store ptr %23, ptr %6, align 8
  %24 = extractvalue { ptr, i64 } %22, 1
  store i64 %24, ptr %19, align 8
  %25 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZN5boost14dynamic_bitsetImSaImEE9referenceaSEb(ptr noundef nonnull align 8 dereferenceable(16) %6, i1 noundef zeroext false)
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %6) #4
  %26 = add nuw i64 %.010, 1
  %exitcond.not = icmp eq i64 %26, %2
  br i1 %exitcond.not, label %._crit_edge, label %20, !llvm.loop !9
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZNK5boost14dynamic_bitsetImSaImEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(32)) local_unnamed_addr #2 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN5boost14dynamic_bitsetImSaImEE6resizeEmb(ptr noundef nonnull align 8 dereferenceable(32), i64 noundef, i1 noundef zeroext) local_unnamed_addr #1 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3maxImERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef nonnull align 8 dereferenceable(8)) local_unnamed_addr #2

; Function Attrs: noreturn
declare void @_Z11assert_failPKcS0_jS0_10RedexErrorS0_z(ptr noundef, ptr noundef, i32 noundef, ptr noundef, i32 noundef, ptr noundef, ...) local_unnamed_addr #3

; Function Attrs: mustprogress uwtable
declare dso_local noundef nonnull align 8 dereferenceable(16) ptr @_ZN5boost14dynamic_bitsetImSaImEE9referenceaSEb(ptr noundef nonnull align 8 dereferenceable(16), i1 noundef zeroext) local_unnamed_addr #1 align 2

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

!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"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass