; LLVM IR from niessner/Matterport :: code/gaps/pkgs/RNBasics/RNQueue.ll (ZN8RNVQueue6ResizeEi)

; 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.RNVQueue = type { %class.RNVArray, i32, i32 }
%class.RNVArray = type { ptr, i32, i32 }

@.str = external hidden unnamed_addr constant [41 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [43 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [89 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: 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 @_ZN8RNVQueue6ResizeEi(ptr noundef nonnull align 8 dereferenceable(24) %0, i32 noundef %1) #1 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %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
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !9
  %11 = load ptr, ptr %3, align 8
  %12 = load i32, ptr %4, align 4, !tbaa !9
  %13 = call noundef i32 @_ZNK8RNVQueue10NAllocatedEv(ptr noundef nonnull align 8 dereferenceable(24) %11)
  %14 = icmp sgt i32 %12, %13
  br i1 %14, label %15, label %87

15:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #5
  %16 = call noundef i32 @_ZNK8RNVQueue10NAllocatedEv(ptr noundef nonnull align 8 dereferenceable(24) %11)
  store i32 %16, ptr %5, align 4, !tbaa !9
  %17 = getelementptr inbounds %class.RNVQueue, ptr %11, i32 0, i32 0
  %18 = call noundef i32 @_ZNK8RNVArray10NAllocatedEv(ptr noundef nonnull align 8 dereferenceable(16) %17)
  %19 = getelementptr inbounds %class.RNVQueue, ptr %11, i32 0, i32 0
  %20 = call noundef i32 @_ZNK8RNVArray8NEntriesEv(ptr noundef nonnull align 8 dereferenceable(16) %19)
  %21 = icmp eq i32 %18, %20
  br i1 %21, label %23, label %22

22:                                               ; preds = %15
  call void (ptr, ...) @_Z7RNAbortPKcz(ptr noundef @.str, ptr noundef @.str.1, i32 noundef 213, ptr noundef @.str.2)
  br label %23

23:                                               ; preds = %22, %15
  %24 = getelementptr inbounds %class.RNVQueue, ptr %11, i32 0, i32 0
  %25 = load i32, ptr %4, align 4, !tbaa !9
  call void @_ZN8RNVArray6ResizeEi(ptr noundef nonnull align 8 dereferenceable(16) %24, i32 noundef %25)
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #5
  %26 = getelementptr inbounds %class.RNVQueue, ptr %11, i32 0, i32 0
  %27 = call noundef i32 @_ZNK8RNVArray10NAllocatedEv(ptr noundef nonnull align 8 dereferenceable(16) %26)
  store i32 %27, ptr %6, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #5
  store i32 0, ptr %7, align 4, !tbaa !9
  br label %28

28:                                               ; preds = %38, %23
  %29 = load i32, ptr %7, align 4, !tbaa !9
  %30 = load i32, ptr %6, align 4, !tbaa !9
  %31 = load i32, ptr %5, align 4, !tbaa !9
  %32 = sub nsw i32 %30, %31
  %33 = icmp slt i32 %29, %32
  br i1 %33, label %35, label %34

34:                                               ; preds = %28
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #5
  br label %41

35:                                               ; preds = %28
  %36 = getelementptr inbounds %class.RNVQueue, ptr %11, i32 0, i32 0
  %37 = call noundef ptr @_ZN8RNVArray6InsertEPv(ptr noundef nonnull align 8 dereferenceable(16) %36, ptr noundef null)
  br label %38

38:                                               ; preds = %35
  %39 = load i32, ptr %7, align 4, !tbaa !9
  %40 = add nsw i32 %39, 1
  store i32 %40, ptr %7, align 4, !tbaa !9
  br label %28, !llvm.loop !11

41:                                               ; preds = %34
  %42 = getelementptr inbounds %class.RNVQueue, ptr %11, i32 0, i32 0
  %43 = call noundef i32 @_ZNK8RNVArray10NAllocatedEv(ptr noundef nonnull align 8 dereferenceable(16) %42)
  %44 = getelementptr inbounds %class.RNVQueue, ptr %11, i32 0, i32 0
  %45 = call noundef i32 @_ZNK8RNVArray8NEntriesEv(ptr noundef nonnull align 8 dereferenceable(16) %44)
  %46 = icmp eq i32 %43, %45
  br i1 %46, label %48, label %47

47:                                               ; preds = %41
  call void (ptr, ...) @_Z7RNAbortPKcz(ptr noundef @.str, ptr noundef @.str.1, i32 noundef 218, ptr noundef @.str.2)
  br label %48

48:                                               ; preds = %47, %41
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #5
  %49 = getelementptr inbounds %class.RNVQueue, ptr %11, i32 0, i32 2
  %50 = load i32, ptr %49, align 4, !tbaa !13
  %51 = getelementptr inbounds %class.RNVQueue, ptr %11, i32 0, i32 1
  %52 = load i32, ptr %51, align 8, !tbaa !16
  %53 = add nsw i32 %50, %52
  %54 = load i32, ptr %5, align 4, !tbaa !9
  %55 = sub nsw i32 %53, %54
  store i32 %55, ptr %8, align 4, !tbaa !9
  %56 = load i32, ptr %8, align 4, !tbaa !9
  %57 = icmp sgt i32 %56, 0
  br i1 %57, label %58, label %86

58:                                               ; preds = %48
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #5
  %59 = getelementptr inbounds %class.RNVQueue, ptr %11, i32 0, i32 2
  %60 = load i32, ptr %59, align 4, !tbaa !13
  %61 = getelementptr inbounds %class.RNVQueue, ptr %11, i32 0, i32 1
  %62 = load i32, ptr %61, align 8, !tbaa !16
  %63 = add nsw i32 %60, %62
  %64 = getelementptr inbounds %class.RNVQueue, ptr %11, i32 0, i32 0
  %65 = call noundef i32 @_ZNK8RNVArray8NEntriesEv(ptr noundef nonnull align 8 dereferenceable(16) %64)
  %66 = sub nsw i32 %63, %65
  store i32 %66, ptr %9, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #5
  %67 = load i32, ptr %8, align 4, !tbaa !9
  %68 = load i32, ptr %9, align 4, !tbaa !9
  %69 = sub nsw i32 %67, %68
  store i32 %69, ptr %10, align 4, !tbaa !9
  %70 = load i32, ptr %10, align 4, !tbaa !9
  %71 = icmp sgt i32 %70, 0
  br i1 %71, label %72, label %76

72:                                               ; preds = %58
  %73 = getelementptr inbounds %class.RNVQueue, ptr %11, i32 0, i32 0
  %74 = load i32, ptr %10, align 4, !tbaa !9
  %75 = load i32, ptr %5, align 4, !tbaa !9
  call void @_ZN8RNVArray5ShiftEiii(ptr noundef nonnull align 8 dereferenceable(16) %73, i32 noundef 0, i32 noundef %74, i32 noundef %75)
  br label %76

76:                                               ; preds = %72, %58
  %77 = load i32, ptr %9, align 4, !tbaa !9
  %78 = icmp sgt i32 %77, 0
  br i1 %78, label %79, label %85

79:                                               ; preds = %76
  %80 = getelementptr inbounds %class.RNVQueue, ptr %11, i32 0, i32 0
  %81 = load i32, ptr %10, align 4, !tbaa !9
  %82 = load i32, ptr %9, align 4, !tbaa !9
  %83 = load i32, ptr %10, align 4, !tbaa !9
  %84 = sub nsw i32 0, %83
  call void @_ZN8RNVArray5ShiftEiii(ptr noundef nonnull align 8 dereferenceable(16) %80, i32 noundef %81, i32 noundef %82, i32 noundef %84)
  br label %85

85:                                               ; preds = %79, %76
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #5
  br label %86

86:                                               ; preds = %85, %48
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #5
  br label %87

87:                                               ; preds = %86, %2
  ret void
}

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

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

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

declare void @_Z7RNAbortPKcz(ptr noundef, ...) #3

declare void @_ZN8RNVArray6ResizeEi(ptr noundef nonnull align 8 dereferenceable(16), i32 noundef) #3

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

declare void @_ZN8RNVArray5ShiftEiii(ptr noundef nonnull align 8 dereferenceable(16), i32 noundef, i32 noundef, i32 noundef) #3

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 = { "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 = { inlinehint 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 #5 = { 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 = !{!"int", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = !{!14, !10, i64 20}
!14 = !{!"_ZTS8RNVQueue", !15, i64 0, !10, i64 16, !10, i64 20}
!15 = !{!"_ZTS8RNVArray", !6, i64 0, !10, i64 8, !10, i64 12}
!16 = !{!14, !10, i64 16}


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

@.str = external hidden unnamed_addr constant [41 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [43 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [89 x i8], align 1

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN8RNVQueue6ResizeEi(ptr noundef nonnull align 8 dereferenceable(24) %0, i32 noundef %1) local_unnamed_addr #0 align 2 {
  %3 = tail call noundef i32 @_ZNK8RNVQueue10NAllocatedEv(ptr noundef nonnull align 8 dereferenceable(24) %0)
  %4 = icmp slt i32 %3, %1
  br i1 %4, label %5, label %39

5:                                                ; preds = %2
  %6 = tail call noundef i32 @_ZNK8RNVQueue10NAllocatedEv(ptr noundef nonnull align 8 dereferenceable(24) %0)
  %7 = tail call noundef i32 @_ZNK8RNVArray10NAllocatedEv(ptr noundef nonnull align 8 dereferenceable(16) %0)
  %8 = tail call noundef i32 @_ZNK8RNVArray8NEntriesEv(ptr noundef nonnull align 8 dereferenceable(16) %0)
  %9 = icmp eq i32 %7, %8
  br i1 %9, label %11, label %10

10:                                               ; preds = %5
  tail call void (ptr, ...) @_Z7RNAbortPKcz(ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 213, ptr noundef nonnull @.str.2)
  br label %11

11:                                               ; preds = %10, %5
  tail call void @_ZN8RNVArray6ResizeEi(ptr noundef nonnull align 8 dereferenceable(16) %0, i32 noundef %1)
  %12 = tail call noundef i32 @_ZNK8RNVArray10NAllocatedEv(ptr noundef nonnull align 8 dereferenceable(16) %0)
  %13 = sub nsw i32 %12, %6
  %14 = icmp sgt i32 %13, 0
  br i1 %14, label %.lr.ph, label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph, %11
  %15 = tail call noundef i32 @_ZNK8RNVArray10NAllocatedEv(ptr noundef nonnull align 8 dereferenceable(16) %0)
  %16 = tail call noundef i32 @_ZNK8RNVArray8NEntriesEv(ptr noundef nonnull align 8 dereferenceable(16) %0)
  %17 = icmp eq i32 %15, %16
  br i1 %17, label %21, label %20

.lr.ph:                                           ; preds = %11, %.lr.ph
  %.021 = phi i32 [ %19, %.lr.ph ], [ 0, %11 ]
  %18 = tail call noundef ptr @_ZN8RNVArray6InsertEPv(ptr noundef nonnull align 8 dereferenceable(16) %0, ptr noundef null)
  %19 = add nuw nsw i32 %.021, 1
  %exitcond.not = icmp eq i32 %19, %13
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph, !llvm.loop !5

20:                                               ; preds = %._crit_edge
  tail call void (ptr, ...) @_Z7RNAbortPKcz(ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 218, ptr noundef nonnull @.str.2)
  br label %21

21:                                               ; preds = %20, %._crit_edge
  %22 = getelementptr inbounds i8, ptr %0, i64 20
  %23 = load i32, ptr %22, align 4, !tbaa !7
  %24 = getelementptr inbounds i8, ptr %0, i64 16
  %25 = load i32, ptr %24, align 8, !tbaa !14
  %26 = add nsw i32 %25, %23
  %27 = sub nsw i32 %26, %6
  %28 = icmp sgt i32 %27, 0
  br i1 %28, label %29, label %39

29:                                               ; preds = %21
  %30 = tail call noundef i32 @_ZNK8RNVArray8NEntriesEv(ptr noundef nonnull align 8 dereferenceable(16) %0)
  %31 = sub nsw i32 %26, %30
  %32 = sub nsw i32 %27, %31
  %33 = icmp sgt i32 %32, 0
  br i1 %33, label %34, label %35

34:                                               ; preds = %29
  tail call void @_ZN8RNVArray5ShiftEiii(ptr noundef nonnull align 8 dereferenceable(16) %0, i32 noundef 0, i32 noundef %32, i32 noundef %6)
  br label %35

35:                                               ; preds = %34, %29
  %36 = icmp sgt i32 %31, 0
  br i1 %36, label %37, label %39

37:                                               ; preds = %35
  %38 = sub nsw i32 0, %32
  tail call void @_ZN8RNVArray5ShiftEiii(ptr noundef nonnull align 8 dereferenceable(16) %0, i32 noundef %32, i32 noundef %31, i32 noundef %38)
  br label %39

39:                                               ; preds = %21, %37, %35, %2
  ret void
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZNK8RNVArray8NEntriesEv(ptr noundef nonnull align 8 dereferenceable(16)) local_unnamed_addr #1 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZNK8RNVQueue10NAllocatedEv(ptr noundef nonnull align 8 dereferenceable(24)) local_unnamed_addr #1 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZNK8RNVArray10NAllocatedEv(ptr noundef nonnull align 8 dereferenceable(16)) local_unnamed_addr #1 align 2

declare void @_Z7RNAbortPKcz(ptr noundef, ...) local_unnamed_addr #2

declare void @_ZN8RNVArray6ResizeEi(ptr noundef nonnull align 8 dereferenceable(16), i32 noundef) local_unnamed_addr #2

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

declare void @_ZN8RNVArray5ShiftEiii(ptr noundef nonnull align 8 dereferenceable(16), i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #2

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" }
attributes #1 = { 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 #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 = { inlinehint 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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}
!7 = !{!8, !13, i64 20}
!8 = !{!"_ZTS8RNVQueue", !9, i64 0, !13, i64 16, !13, i64 20}
!9 = !{!"_ZTS8RNVArray", !10, i64 0, !13, i64 8, !13, i64 12}
!10 = !{!"any pointer", !11, i64 0}
!11 = !{!"omnipotent char", !12, i64 0}
!12 = !{!"Simple C++ TBAA"}
!13 = !{!"int", !11, i64 0}
!14 = !{!8, !13, i64 16}


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