; LLVM IR from alenic/realGA :: src/selection_tournament.ll (ZN19TournamentSelection6selectERSt6vectorIfSaIfEERiS4_)

; 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.TournamentSelection = type { %class.Selection, i32, i64, float, ptr, ptr }
%class.Selection = type { ptr }

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN19TournamentSelection6selectERSt6vectorIfSaIfEERiS4_(ptr noundef nonnull align 8 dereferenceable(48) %0, ptr noundef nonnull align 8 dereferenceable(24) %1, ptr noundef nonnull align 4 dereferenceable(4) %2, ptr noundef nonnull align 4 dereferenceable(4) %3) unnamed_addr #0 align 2 {
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store ptr %2, ptr %7, align 8, !tbaa !5
  store ptr %3, ptr %8, align 8, !tbaa !5
  %9 = load ptr, ptr %5, align 8
  %10 = load ptr, ptr %6, align 8, !tbaa !5
  %11 = call noundef i32 @_ZN19TournamentSelection10tournamentERSt6vectorIfSaIfEE(ptr noundef nonnull align 8 dereferenceable(48) %9, ptr noundef nonnull align 8 dereferenceable(24) %10)
  %12 = load ptr, ptr %7, align 8, !tbaa !5
  store i32 %11, ptr %12, align 4, !tbaa !9
  %13 = load ptr, ptr %6, align 8, !tbaa !5
  %14 = call noundef i32 @_ZN19TournamentSelection10tournamentERSt6vectorIfSaIfEE(ptr noundef nonnull align 8 dereferenceable(48) %9, ptr noundef nonnull align 8 dereferenceable(24) %13)
  %15 = load ptr, ptr %8, align 8, !tbaa !5
  store i32 %14, ptr %15, align 4, !tbaa !9
  br label %16

16:                                               ; preds = %22, %4
  %17 = load ptr, ptr %7, align 8, !tbaa !5
  %18 = load i32, ptr %17, align 4, !tbaa !9
  %19 = load ptr, ptr %8, align 8, !tbaa !5
  %20 = load i32, ptr %19, align 4, !tbaa !9
  %21 = icmp eq i32 %18, %20
  br i1 %21, label %22, label %33

22:                                               ; preds = %16
  %23 = getelementptr inbounds %class.TournamentSelection, ptr %9, i32 0, i32 1
  %24 = load i32, ptr %23, align 8, !tbaa !11
  %25 = sub nsw i32 %24, 1
  %26 = call noundef i32 @_ZN4Stat9randIndexEi(i32 noundef %25)
  %27 = load ptr, ptr %7, align 8, !tbaa !5
  store i32 %26, ptr %27, align 4, !tbaa !9
  %28 = getelementptr inbounds %class.TournamentSelection, ptr %9, i32 0, i32 1
  %29 = load i32, ptr %28, align 8, !tbaa !11
  %30 = sub nsw i32 %29, 1
  %31 = call noundef i32 @_ZN4Stat9randIndexEi(i32 noundef %30)
  %32 = load ptr, ptr %8, align 8, !tbaa !5
  store i32 %31, ptr %32, align 4, !tbaa !9
  br label %16, !llvm.loop !16

33:                                               ; preds = %16
  ret void
}

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_ZN19TournamentSelection10tournamentERSt6vectorIfSaIfEE(ptr noundef nonnull align 8 dereferenceable(48), ptr noundef nonnull align 8 dereferenceable(24)) #0 align 2

declare noundef i32 @_ZN4Stat9randIndexEi(i32 noundef) #1

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 = { "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, !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 = !{!12, !10, i64 8}
!12 = !{!"_ZTS19TournamentSelection", !13, i64 0, !10, i64 8, !14, i64 16, !15, i64 24, !6, i64 32, !6, i64 40}
!13 = !{!"_ZTS9Selection"}
!14 = !{!"long", !7, i64 0}
!15 = !{!"float", !7, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"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"

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN19TournamentSelection6selectERSt6vectorIfSaIfEERiS4_(ptr noundef nonnull align 8 dereferenceable(48) %0, ptr noundef nonnull align 8 dereferenceable(24) %1, ptr nocapture noundef nonnull align 4 dereferenceable(4) %2, ptr nocapture noundef nonnull writeonly align 4 dereferenceable(4) %3) unnamed_addr #0 align 2 {
  %5 = tail call noundef i32 @_ZN19TournamentSelection10tournamentERSt6vectorIfSaIfEE(ptr noundef nonnull align 8 dereferenceable(48) %0, ptr noundef nonnull align 8 dereferenceable(24) %1)
  store i32 %5, ptr %2, align 4, !tbaa !5
  %6 = tail call noundef i32 @_ZN19TournamentSelection10tournamentERSt6vectorIfSaIfEE(ptr noundef nonnull align 8 dereferenceable(48) %0, ptr noundef nonnull align 8 dereferenceable(24) %1)
  store i32 %6, ptr %3, align 4, !tbaa !5
  %7 = load i32, ptr %2, align 4, !tbaa !5
  %8 = icmp eq i32 %7, %6
  br i1 %8, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %4
  %9 = getelementptr inbounds i8, ptr %0, i64 8
  br label %10

10:                                               ; preds = %.lr.ph, %10
  %11 = load i32, ptr %9, align 8, !tbaa !9
  %12 = add nsw i32 %11, -1
  %13 = tail call noundef i32 @_ZN4Stat9randIndexEi(i32 noundef %12)
  store i32 %13, ptr %2, align 4, !tbaa !5
  %14 = load i32, ptr %9, align 8, !tbaa !9
  %15 = add nsw i32 %14, -1
  %16 = tail call noundef i32 @_ZN4Stat9randIndexEi(i32 noundef %15)
  store i32 %16, ptr %3, align 4, !tbaa !5
  %17 = load i32, ptr %2, align 4, !tbaa !5
  %18 = icmp eq i32 %17, %16
  br i1 %18, label %10, label %._crit_edge, !llvm.loop !15

._crit_edge:                                      ; preds = %10, %4
  ret void
}

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_ZN19TournamentSelection10tournamentERSt6vectorIfSaIfEE(ptr noundef nonnull align 8 dereferenceable(48), ptr noundef nonnull align 8 dereferenceable(24)) local_unnamed_addr #0 align 2

declare noundef i32 @_ZN4Stat9randIndexEi(i32 noundef) local_unnamed_addr #1

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 = { "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, !6, i64 0}
!6 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !6, i64 8}
!10 = !{!"_ZTS19TournamentSelection", !11, i64 0, !6, i64 8, !12, i64 16, !13, i64 24, !14, i64 32, !14, i64 40}
!11 = !{!"_ZTS9Selection"}
!12 = !{!"long", !7, i64 0}
!13 = !{!"float", !7, i64 0}
!14 = !{!"any pointer", !7, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}


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