; LLVM IR from facebook/redex :: libresource/VectorImpl.ll (ZN7android10VectorImpl6resizeEm)

; 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.android::VectorImpl" = type { ptr, ptr, i64, i32, i64 }

; 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 uwtable
declare dso_local noundef i64 @_ZN7android10VectorImpl8insertAtEmm(ptr noundef nonnull align 8 dereferenceable(40), i64 noundef, i64 noundef) #1 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef i64 @_ZN7android10VectorImpl13removeItemsAtEmm(ptr noundef nonnull align 8 dereferenceable(40), i64 noundef, i64 noundef) #1 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef i64 @_ZN7android10VectorImpl6resizeEm(ptr noundef nonnull align 8 dereferenceable(40) %0, i64 noundef %1) #1 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca i64, align 8
  %5 = alloca i64, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i64 %1, ptr %4, align 8, !tbaa !9
  %6 = load ptr, ptr %3, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #2
  store i64 0, ptr %5, align 8, !tbaa !9
  %7 = load i64, ptr %4, align 8, !tbaa !9
  %8 = getelementptr inbounds %"class.android::VectorImpl", ptr %6, i32 0, i32 2
  %9 = load i64, ptr %8, align 8, !tbaa !11
  %10 = icmp ugt i64 %7, %9
  br i1 %10, label %11, label %19

11:                                               ; preds = %2
  %12 = getelementptr inbounds %"class.android::VectorImpl", ptr %6, i32 0, i32 2
  %13 = load i64, ptr %12, align 8, !tbaa !11
  %14 = load i64, ptr %4, align 8, !tbaa !9
  %15 = getelementptr inbounds %"class.android::VectorImpl", ptr %6, i32 0, i32 2
  %16 = load i64, ptr %15, align 8, !tbaa !11
  %17 = sub i64 %14, %16
  %18 = call noundef i64 @_ZN7android10VectorImpl8insertAtEmm(ptr noundef nonnull align 8 dereferenceable(40) %6, i64 noundef %13, i64 noundef %17)
  store i64 %18, ptr %5, align 8, !tbaa !9
  br label %32

19:                                               ; preds = %2
  %20 = load i64, ptr %4, align 8, !tbaa !9
  %21 = getelementptr inbounds %"class.android::VectorImpl", ptr %6, i32 0, i32 2
  %22 = load i64, ptr %21, align 8, !tbaa !11
  %23 = icmp ult i64 %20, %22
  br i1 %23, label %24, label %31

24:                                               ; preds = %19
  %25 = load i64, ptr %4, align 8, !tbaa !9
  %26 = getelementptr inbounds %"class.android::VectorImpl", ptr %6, i32 0, i32 2
  %27 = load i64, ptr %26, align 8, !tbaa !11
  %28 = load i64, ptr %4, align 8, !tbaa !9
  %29 = sub i64 %27, %28
  %30 = call noundef i64 @_ZN7android10VectorImpl13removeItemsAtEmm(ptr noundef nonnull align 8 dereferenceable(40) %6, i64 noundef %25, i64 noundef %29)
  store i64 %30, ptr %5, align 8, !tbaa !9
  br label %31

31:                                               ; preds = %24, %19
  br label %32

32:                                               ; preds = %31, %11
  %33 = load i64, ptr %5, align 8, !tbaa !9
  %34 = icmp slt i64 %33, 0
  br i1 %34, label %35, label %37

35:                                               ; preds = %32
  %36 = load i64, ptr %5, align 8, !tbaa !9
  br label %39

37:                                               ; preds = %32
  %38 = load i64, ptr %4, align 8, !tbaa !9
  br label %39

39:                                               ; preds = %37, %35
  %40 = phi i64 [ %36, %35 ], [ %38, %37 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #2
  ret i64 %40
}

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 = { 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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!12, !10, i64 16}
!12 = !{!"_ZTSN7android10VectorImplE", !6, i64 8, !10, i64 16, !13, i64 24, !10, i64 32}
!13 = !{!"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"

; Function Attrs: mustprogress uwtable
declare dso_local noundef i64 @_ZN7android10VectorImpl8insertAtEmm(ptr noundef nonnull align 8 dereferenceable(40), i64 noundef, i64 noundef) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef i64 @_ZN7android10VectorImpl13removeItemsAtEmm(ptr noundef nonnull align 8 dereferenceable(40), i64 noundef, i64 noundef) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef i64 @_ZN7android10VectorImpl6resizeEm(ptr noundef nonnull align 8 dereferenceable(40) %0, i64 noundef %1) local_unnamed_addr #0 align 2 {
  %3 = getelementptr inbounds i8, ptr %0, i64 16
  %4 = load i64, ptr %3, align 8, !tbaa !5
  %5 = icmp ult i64 %4, %1
  br i1 %5, label %6, label %9

6:                                                ; preds = %2
  %7 = sub i64 %1, %4
  %8 = tail call noundef i64 @_ZN7android10VectorImpl8insertAtEmm(ptr noundef nonnull align 8 dereferenceable(40) %0, i64 noundef %4, i64 noundef %7)
  br label %14

9:                                                ; preds = %2
  %10 = icmp ugt i64 %4, %1
  br i1 %10, label %11, label %.thread

11:                                               ; preds = %9
  %12 = sub i64 %4, %1
  %13 = tail call noundef i64 @_ZN7android10VectorImpl13removeItemsAtEmm(ptr noundef nonnull align 8 dereferenceable(40) %0, i64 noundef %1, i64 noundef %12)
  br label %14

14:                                               ; preds = %11, %6
  %.0 = phi i64 [ %8, %6 ], [ %13, %11 ]
  %15 = icmp slt i64 %.0, 0
  %spec.select = select i1 %15, i64 %.0, i64 %1
  br label %.thread

.thread:                                          ; preds = %14, %9
  %16 = phi i64 [ %1, %9 ], [ %spec.select, %14 ]
  ret i64 %16
}

attributes #0 = { 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" }

!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, !10, i64 16}
!6 = !{!"_ZTSN7android10VectorImplE", !7, i64 8, !10, i64 16, !11, i64 24, !10, i64 32}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"long", !8, i64 0}
!11 = !{!"int", !8, i64 0}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,SROAPass,SimplifyCFGPass,TailCallElimPass