; LLVM IR from upupming/algorithm :: AdvancedLevel_C++/1026. Table Tennis (30) .ll (Z11findnextvipi)

; 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.std::vector" = type { %"struct.std::_Vector_base" }
%"struct.std::_Vector_base" = type { %"struct.std::_Vector_base<person, std::allocator<person>>::_Vector_impl" }
%"struct.std::_Vector_base<person, std::allocator<person>>::_Vector_impl" = type { %"struct.std::_Vector_base<person, std::allocator<person>>::_Vector_impl_data" }
%"struct.std::_Vector_base<person, std::allocator<person>>::_Vector_impl_data" = type { ptr, ptr, ptr }
%struct.person = type { i32, i32, i32, i8 }

@player = external dso_local global %"class.std::vector", align 8

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(16) ptr @_ZNSt6vectorI6personSaIS0_EEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) #0 align 2

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i32 @_Z11findnextvipi(i32 noundef %0) #0 {
  %2 = alloca i32, align 4
  store i32 %0, ptr %2, align 4, !tbaa !5
  %3 = load i32, ptr %2, align 4, !tbaa !5
  %4 = add nsw i32 %3, 1
  store i32 %4, ptr %2, align 4, !tbaa !5
  br label %5

5:                                                ; preds = %21, %1
  %6 = load i32, ptr %2, align 4, !tbaa !5
  %7 = sext i32 %6 to i64
  %8 = call noundef i64 @_ZNKSt6vectorI6personSaIS0_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) @player) #1
  %9 = icmp ult i64 %7, %8
  br i1 %9, label %10, label %19

10:                                               ; preds = %5
  %11 = load i32, ptr %2, align 4, !tbaa !5
  %12 = sext i32 %11 to i64
  %13 = call noundef nonnull align 4 dereferenceable(16) ptr @_ZNSt6vectorI6personSaIS0_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) @player, i64 noundef %12) #1
  %14 = getelementptr inbounds %struct.person, ptr %13, i32 0, i32 3
  %15 = load i8, ptr %14, align 4, !tbaa !9, !range !12, !noundef !13
  %16 = trunc i8 %15 to i1
  %17 = zext i1 %16 to i32
  %18 = icmp eq i32 %17, 0
  br label %19

19:                                               ; preds = %10, %5
  %20 = phi i1 [ false, %5 ], [ %18, %10 ]
  br i1 %20, label %21, label %24

21:                                               ; preds = %19
  %22 = load i32, ptr %2, align 4, !tbaa !5
  %23 = add nsw i32 %22, 1
  store i32 %23, ptr %2, align 4, !tbaa !5
  br label %5, !llvm.loop !14

24:                                               ; preds = %19
  %25 = load i32, ptr %2, align 4, !tbaa !5
  ret i32 %25
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZNKSt6vectorI6personSaIS0_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24)) #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 = { 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !11, i64 12}
!10 = !{!"_ZTS6person", !6, i64 0, !6, i64 4, !6, i64 8, !11, i64 12}
!11 = !{!"bool", !7, i64 0}
!12 = !{i8 0, i8 2}
!13 = !{}
!14 = distinct !{!14, !15}
!15 = !{!"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.std::vector" = type { %"struct.std::_Vector_base" }
%"struct.std::_Vector_base" = type { %"struct.std::_Vector_base<person, std::allocator<person>>::_Vector_impl" }
%"struct.std::_Vector_base<person, std::allocator<person>>::_Vector_impl" = type { %"struct.std::_Vector_base<person, std::allocator<person>>::_Vector_impl_data" }
%"struct.std::_Vector_base<person, std::allocator<person>>::_Vector_impl_data" = type { ptr, ptr, ptr }

@player = external dso_local global %"class.std::vector", align 8

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef range(i32 -2147483647, -2147483648) i32 @_Z11findnextvipi(i32 noundef %0) local_unnamed_addr #0 {
  %2 = sext i32 %0 to i64
  br label %3

3:                                                ; preds = %6, %1
  %indvars.iv = phi i64 [ %indvars.iv.next, %6 ], [ %2, %1 ]
  %indvars.iv.next = add nsw i64 %indvars.iv, 1
  %4 = tail call noundef i64 @_ZNKSt6vectorI6personSaIS0_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) @player) #1
  %5 = icmp ugt i64 %4, %indvars.iv.next
  br i1 %5, label %6, label %.critedge

6:                                                ; preds = %3
  %7 = tail call noundef nonnull align 4 dereferenceable(16) ptr @_ZNSt6vectorI6personSaIS0_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) @player, i64 noundef %indvars.iv.next) #1
  %8 = getelementptr inbounds i8, ptr %7, i64 12
  %9 = load i8, ptr %8, align 4, !tbaa !5, !range !11, !noundef !12
  %10 = icmp eq i8 %9, 0
  br i1 %10, label %3, label %.critedge, !llvm.loop !13

.critedge:                                        ; preds = %3, %6
  %11 = trunc nsw i64 %indvars.iv.next to i32
  ret i32 %11
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZNKSt6vectorI6personSaIS0_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24)) 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 = { 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, !10, i64 12}
!6 = !{!"_ZTS6person", !7, i64 0, !7, i64 4, !7, i64 8, !10, i64 12}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"bool", !8, i64 0}
!11 = !{i8 0, i8 2}
!12 = !{}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass