; LLVM IR from DionysiosB/CodeForces :: 0600-0699 (682C-AlyonaAndTree)

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

%"struct.std::pair" = type { i64, i64 }

; Function Attrs: mustprogress uwtable
define dso_local void @_Z3dfsllRKSt6vectorIlSaIlEERKS_IS_ISt4pairIllESaIS5_EESaIS7_EERl(i64 noundef %0, i64 noundef %1, ptr noundef nonnull align 8 dereferenceable(24) %2, ptr noundef nonnull align 8 dereferenceable(24) %3, ptr noundef nonnull align 8 dereferenceable(8) %4) #0 {
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i64, align 8
  %12 = alloca i64, align 8
  %13 = alloca i64, align 8
  store i64 %0, ptr %6, align 8, !tbaa !5
  store i64 %1, ptr %7, align 8, !tbaa !5
  store ptr %2, ptr %8, align 8, !tbaa !9
  store ptr %3, ptr %9, align 8, !tbaa !9
  store ptr %4, ptr %10, align 8, !tbaa !9
  %14 = load i64, ptr %7, align 8, !tbaa !5
  %15 = load ptr, ptr %8, align 8, !tbaa !9
  %16 = load i64, ptr %6, align 8, !tbaa !5
  %17 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNKSt6vectorIlSaIlEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %15, i64 noundef %16) #3
  %18 = load i64, ptr %17, align 8, !tbaa !5
  %19 = icmp sgt i64 %14, %18
  br i1 %19, label %20, label %21

20:                                               ; preds = %5
  br label %63

21:                                               ; preds = %5
  %22 = load ptr, ptr %10, align 8, !tbaa !9
  %23 = load i64, ptr %22, align 8, !tbaa !5
  %24 = add nsw i64 %23, 1
  store i64 %24, ptr %22, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #3
  store i64 0, ptr %11, align 8, !tbaa !5
  br label %25

25:                                               ; preds = %60, %21
  %26 = load i64, ptr %11, align 8, !tbaa !5
  %27 = load ptr, ptr %9, align 8, !tbaa !9
  %28 = load i64, ptr %6, align 8, !tbaa !5
  %29 = call noundef nonnull align 8 dereferenceable(24) ptr @_ZNKSt6vectorIS_ISt4pairIllESaIS1_EESaIS3_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %27, i64 noundef %28) #3
  %30 = call noundef i64 @_ZNKSt6vectorISt4pairIllESaIS1_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %29) #3
  %31 = icmp ult i64 %26, %30
  br i1 %31, label %33, label %32

32:                                               ; preds = %25
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  br label %63

33:                                               ; preds = %25
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #3
  %34 = load ptr, ptr %9, align 8, !tbaa !9
  %35 = load i64, ptr %6, align 8, !tbaa !5
  %36 = call noundef nonnull align 8 dereferenceable(24) ptr @_ZNKSt6vectorIS_ISt4pairIllESaIS1_EESaIS3_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %34, i64 noundef %35) #3
  %37 = load i64, ptr %11, align 8, !tbaa !5
  %38 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNKSt6vectorISt4pairIllESaIS1_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %36, i64 noundef %37) #3
  %39 = getelementptr inbounds %"struct.std::pair", ptr %38, i32 0, i32 0
  %40 = load i64, ptr %39, align 8, !tbaa !11
  store i64 %40, ptr %12, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #3
  %41 = load ptr, ptr %9, align 8, !tbaa !9
  %42 = load i64, ptr %6, align 8, !tbaa !5
  %43 = call noundef nonnull align 8 dereferenceable(24) ptr @_ZNKSt6vectorIS_ISt4pairIllESaIS1_EESaIS3_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %41, i64 noundef %42) #3
  %44 = load i64, ptr %11, align 8, !tbaa !5
  %45 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNKSt6vectorISt4pairIllESaIS1_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %43, i64 noundef %44) #3
  %46 = getelementptr inbounds %"struct.std::pair", ptr %45, i32 0, i32 1
  %47 = load i64, ptr %46, align 8, !tbaa !13
  store i64 %47, ptr %13, align 8, !tbaa !5
  %48 = load i64, ptr %7, align 8, !tbaa !5
  %49 = load i64, ptr %13, align 8, !tbaa !5
  %50 = add nsw i64 %49, %48
  store i64 %50, ptr %13, align 8, !tbaa !5
  %51 = load i64, ptr %13, align 8, !tbaa !5
  %52 = icmp slt i64 %51, 0
  br i1 %52, label %53, label %54

53:                                               ; preds = %33
  store i64 0, ptr %13, align 8, !tbaa !5
  br label %54

54:                                               ; preds = %53, %33
  %55 = load i64, ptr %12, align 8, !tbaa !5
  %56 = load i64, ptr %13, align 8, !tbaa !5
  %57 = load ptr, ptr %8, align 8, !tbaa !9
  %58 = load ptr, ptr %9, align 8, !tbaa !9
  %59 = load ptr, ptr %10, align 8, !tbaa !9
  call void @_Z3dfsllRKSt6vectorIlSaIlEERKS_IS_ISt4pairIllESaIS5_EESaIS7_EERl(i64 noundef %55, i64 noundef %56, ptr noundef nonnull align 8 dereferenceable(24) %57, ptr noundef nonnull align 8 dereferenceable(24) %58, ptr noundef nonnull align 8 dereferenceable(8) %59)
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #3
  br label %60

60:                                               ; preds = %54
  %61 = load i64, ptr %11, align 8, !tbaa !5
  %62 = add nsw i64 %61, 1
  store i64 %62, ptr %11, align 8, !tbaa !5
  br label %25, !llvm.loop !14

63:                                               ; preds = %32, %20
  ret void
}

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

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

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZNKSt6vectorISt4pairIllESaIS1_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24)) #1 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(16) ptr @_ZNKSt6vectorISt4pairIllESaIS1_EEixEm(ptr noundef nonnull align 8 dereferenceable(24), 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) #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 = { 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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !6, i64 0}
!12 = !{!"_ZTSSt4pairIllE", !6, i64 0, !6, i64 8}
!13 = !{!12, !6, i64 8}
!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"

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z3dfsllRKSt6vectorIlSaIlEERKS_IS_ISt4pairIllESaIS5_EESaIS7_EERl(i64 noundef %0, i64 noundef %1, ptr noundef nonnull align 8 dereferenceable(24) %2, ptr noundef nonnull align 8 dereferenceable(24) %3, ptr nocapture noundef nonnull align 8 dereferenceable(8) %4) local_unnamed_addr #0 {
  %6 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNKSt6vectorIlSaIlEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %2, i64 noundef %0) #2
  %7 = load i64, ptr %6, align 8, !tbaa !5
  %8 = icmp slt i64 %7, %1
  br i1 %8, label %.loopexit, label %9

9:                                                ; preds = %5
  %10 = load i64, ptr %4, align 8, !tbaa !5
  %11 = add nsw i64 %10, 1
  store i64 %11, ptr %4, align 8, !tbaa !5
  %12 = tail call noundef nonnull align 8 dereferenceable(24) ptr @_ZNKSt6vectorIS_ISt4pairIllESaIS1_EESaIS3_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %3, i64 noundef %0) #2
  %13 = tail call noundef i64 @_ZNKSt6vectorISt4pairIllESaIS1_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %12) #2
  %.not = icmp eq i64 %13, 0
  br i1 %.not, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %9, %.lr.ph
  %.022 = phi i64 [ %22, %.lr.ph ], [ 0, %9 ]
  %14 = tail call noundef nonnull align 8 dereferenceable(24) ptr @_ZNKSt6vectorIS_ISt4pairIllESaIS1_EESaIS3_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %3, i64 noundef %0) #2
  %15 = tail call noundef nonnull align 8 dereferenceable(16) ptr @_ZNKSt6vectorISt4pairIllESaIS1_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %14, i64 noundef %.022) #2
  %16 = load i64, ptr %15, align 8, !tbaa !9
  %17 = tail call noundef nonnull align 8 dereferenceable(24) ptr @_ZNKSt6vectorIS_ISt4pairIllESaIS1_EESaIS3_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %3, i64 noundef %0) #2
  %18 = tail call noundef nonnull align 8 dereferenceable(16) ptr @_ZNKSt6vectorISt4pairIllESaIS1_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %17, i64 noundef %.022) #2
  %19 = getelementptr inbounds i8, ptr %18, i64 8
  %20 = load i64, ptr %19, align 8, !tbaa !11
  %21 = add nsw i64 %20, %1
  %spec.store.select = tail call i64 @llvm.smax.i64(i64 %21, i64 0)
  tail call void @_Z3dfsllRKSt6vectorIlSaIlEERKS_IS_ISt4pairIllESaIS5_EESaIS7_EERl(i64 noundef %16, i64 noundef %spec.store.select, ptr noundef nonnull align 8 dereferenceable(24) %2, ptr noundef nonnull align 8 dereferenceable(24) %3, ptr noundef nonnull align 8 dereferenceable(8) %4)
  %22 = add nuw nsw i64 %.022, 1
  %23 = tail call noundef nonnull align 8 dereferenceable(24) ptr @_ZNKSt6vectorIS_ISt4pairIllESaIS1_EESaIS3_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %3, i64 noundef %0) #2
  %24 = tail call noundef i64 @_ZNKSt6vectorISt4pairIllESaIS1_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %23) #2
  %25 = icmp ult i64 %22, %24
  br i1 %25, label %.lr.ph, label %.loopexit, !llvm.loop !12

.loopexit:                                        ; preds = %.lr.ph, %9, %5
  ret void
}

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

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

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

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

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i64 @llvm.smax.i64(i64, i64) #1

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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !6, i64 0}
!10 = !{!"_ZTSSt4pairIllE", !6, i64 0, !6, i64 8}
!11 = !{!10, !6, i64 8}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}


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