; LLVM IR from xirc/cp-algorithm :: atcoder/abc159/e.ll (Z4divxRSt6vectorISt4pairIiiESaIS1_EE)

; 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 { i32, i32 }

@W = external dso_local global i32, align 4
@K = external dso_local global i32, align 4

; 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 nounwind uwtable
declare dso_local noundef i32 @_Z5queryiiii(i32 noundef, i32 noundef, i32 noundef, i32 noundef) #1

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i32 @_Z4divxRSt6vectorISt4pairIiiESaIS1_EE(ptr noundef nonnull align 8 dereferenceable(24) %0) #1 {
  %2 = alloca i32, align 4
  %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 i8, align 1
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #2
  store i32 0, ptr %4, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #2
  store i32 0, ptr %5, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #2
  store i32 1, ptr %6, align 4, !tbaa !9
  br label %13

13:                                               ; preds = %76, %74, %1
  %14 = load i32, ptr %6, align 4, !tbaa !9
  %15 = load i32, ptr @W, align 4, !tbaa !9
  %16 = icmp sle i32 %14, %15
  br i1 %16, label %18, label %17

17:                                               ; preds = %13
  store i32 2, ptr %7, align 4
  br label %77

18:                                               ; preds = %13
  call void @llvm.lifetime.start.p0(i64 1, ptr %8) #2
  store i8 1, ptr %8, align 1, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #2
  store i32 0, ptr %9, align 4, !tbaa !9
  br label %19

19:                                               ; preds = %54, %18
  %20 = load i32, ptr %9, align 4, !tbaa !9
  %21 = sext i32 %20 to i64
  %22 = load ptr, ptr %3, align 8, !tbaa !5
  %23 = call noundef i64 @_ZNKSt6vectorISt4pairIiiESaIS1_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %22) #2
  %24 = icmp ult i64 %21, %23
  br i1 %24, label %26, label %25

25:                                               ; preds = %19
  store i32 4, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #2
  br label %57

26:                                               ; preds = %19
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #2
  %27 = load ptr, ptr %3, align 8, !tbaa !5
  %28 = load i32, ptr %9, align 4, !tbaa !9
  %29 = sext i32 %28 to i64
  %30 = call noundef nonnull align 4 dereferenceable(8) ptr @_ZNSt6vectorISt4pairIiiESaIS1_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %27, i64 noundef %29) #2
  %31 = getelementptr inbounds %"struct.std::pair", ptr %30, i32 0, i32 0
  %32 = load i32, ptr %31, align 4, !tbaa !13
  store i32 %32, ptr %10, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #2
  %33 = load ptr, ptr %3, align 8, !tbaa !5
  %34 = load i32, ptr %9, align 4, !tbaa !9
  %35 = sext i32 %34 to i64
  %36 = call noundef nonnull align 4 dereferenceable(8) ptr @_ZNSt6vectorISt4pairIiiESaIS1_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %33, i64 noundef %35) #2
  %37 = getelementptr inbounds %"struct.std::pair", ptr %36, i32 0, i32 1
  %38 = load i32, ptr %37, align 4, !tbaa !15
  store i32 %38, ptr %11, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #2
  %39 = load i32, ptr %5, align 4, !tbaa !9
  %40 = load i32, ptr %6, align 4, !tbaa !9
  %41 = load i32, ptr %10, align 4, !tbaa !9
  %42 = load i32, ptr %11, align 4, !tbaa !9
  %43 = call noundef i32 @_Z5queryiiii(i32 noundef %39, i32 noundef %40, i32 noundef %41, i32 noundef %42)
  store i32 %43, ptr %12, align 4, !tbaa !9
  %44 = load i32, ptr %12, align 4, !tbaa !9
  %45 = load i32, ptr @K, align 4, !tbaa !9
  %46 = icmp sle i32 %44, %45
  %47 = zext i1 %46 to i32
  %48 = load i8, ptr %8, align 1, !tbaa !11, !range !16, !noundef !17
  %49 = trunc i8 %48 to i1
  %50 = zext i1 %49 to i32
  %51 = and i32 %50, %47
  %52 = icmp ne i32 %51, 0
  %53 = zext i1 %52 to i8
  store i8 %53, ptr %8, align 1, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #2
  br label %54

54:                                               ; preds = %26
  %55 = load i32, ptr %9, align 4, !tbaa !9
  %56 = add nsw i32 %55, 1
  store i32 %56, ptr %9, align 4, !tbaa !9
  br label %19, !llvm.loop !18

57:                                               ; preds = %25
  %58 = load i8, ptr %8, align 1, !tbaa !11, !range !16, !noundef !17
  %59 = trunc i8 %58 to i1
  br i1 %59, label %60, label %63

60:                                               ; preds = %57
  %61 = load i32, ptr %6, align 4, !tbaa !9
  %62 = add nsw i32 %61, 1
  store i32 %62, ptr %6, align 4, !tbaa !9
  store i32 3, ptr %7, align 4
  br label %74, !llvm.loop !20

63:                                               ; preds = %57
  %64 = load i32, ptr %6, align 4, !tbaa !9
  %65 = load i32, ptr %5, align 4, !tbaa !9
  %66 = sub nsw i32 %64, %65
  %67 = icmp sle i32 %66, 1
  br i1 %67, label %68, label %69

68:                                               ; preds = %63
  store i32 100000000, ptr %2, align 4
  store i32 1, ptr %7, align 4
  br label %74

69:                                               ; preds = %63
  %70 = load i32, ptr %4, align 4, !tbaa !9
  %71 = add nsw i32 %70, 1
  store i32 %71, ptr %4, align 4, !tbaa !9
  %72 = load i32, ptr %6, align 4, !tbaa !9
  %73 = sub nsw i32 %72, 1
  store i32 %73, ptr %5, align 4, !tbaa !9
  store i32 0, ptr %7, align 4
  br label %74

74:                                               ; preds = %69, %68, %60
  call void @llvm.lifetime.end.p0(i64 1, ptr %8) #2
  %75 = load i32, ptr %7, align 4
  switch i32 %75, label %77 [
    i32 0, label %76
    i32 3, label %13
  ]

76:                                               ; preds = %74
  br label %13, !llvm.loop !20

77:                                               ; preds = %74, %17
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  %78 = load i32, ptr %7, align 4
  switch i32 %78, label %87 [
    i32 2, label %79
  ]

79:                                               ; preds = %77
  %80 = load ptr, ptr %3, align 8, !tbaa !5
  %81 = call noundef i64 @_ZNKSt6vectorISt4pairIiiESaIS1_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %80) #2
  %82 = sub i64 %81, 1
  %83 = load i32, ptr %4, align 4, !tbaa !9
  %84 = sext i32 %83 to i64
  %85 = add i64 %82, %84
  %86 = trunc i64 %85 to i32
  store i32 %86, ptr %2, align 4
  store i32 1, ptr %7, align 4
  br label %87

87:                                               ; preds = %79, %77
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #2
  %88 = load i32, ptr %2, align 4
  ret i32 %88
}

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

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 = !{!12, !12, i64 0}
!12 = !{!"bool", !7, i64 0}
!13 = !{!14, !10, i64 0}
!14 = !{!"_ZTSSt4pairIiiE", !10, i64 0, !10, i64 4}
!15 = !{!14, !10, i64 4}
!16 = !{i8 0, i8 2}
!17 = !{}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}
!20 = distinct !{!20, !19}


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

@W = external dso_local local_unnamed_addr global i32, align 4
@K = external dso_local local_unnamed_addr global i32, align 4

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z5queryiiii(i32 noundef, i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i32 @_Z4divxRSt6vectorISt4pairIiiESaIS1_EE(ptr noundef nonnull align 8 dereferenceable(24) %0) local_unnamed_addr #0 {
  %2 = load i32, ptr @W, align 4, !tbaa !5
  %.not47 = icmp slt i32 %2, 1
  br i1 %.not47, label %.thread40, label %.preheader

.preheader:                                       ; preds = %1, %22
  %.02450 = phi i32 [ %.125, %22 ], [ 0, %1 ]
  %.02749 = phi i32 [ %.128, %22 ], [ 0, %1 ]
  %.03348 = phi i32 [ %.134, %22 ], [ 1, %1 ]
  %3 = tail call noundef i64 @_ZNKSt6vectorISt4pairIiiESaIS1_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %0) #1
  %.not52 = icmp eq i64 %3, 0
  br i1 %.not52, label %.critedge, label %.lr.ph

._crit_edge:                                      ; preds = %.lr.ph
  br i1 %12, label %.critedge, label %16

.lr.ph:                                           ; preds = %.preheader, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 0, %.preheader ]
  %.03045 = phi i1 [ %12, %.lr.ph ], [ true, %.preheader ]
  %4 = tail call noundef nonnull align 4 dereferenceable(8) ptr @_ZNSt6vectorISt4pairIiiESaIS1_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef %indvars.iv) #1
  %5 = load i32, ptr %4, align 4, !tbaa !9
  %6 = tail call noundef nonnull align 4 dereferenceable(8) ptr @_ZNSt6vectorISt4pairIiiESaIS1_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef %indvars.iv) #1
  %7 = getelementptr inbounds i8, ptr %6, i64 4
  %8 = load i32, ptr %7, align 4, !tbaa !11
  %9 = tail call noundef i32 @_Z5queryiiii(i32 noundef %.02749, i32 noundef %.03348, i32 noundef %5, i32 noundef %8)
  %10 = load i32, ptr @K, align 4, !tbaa !5
  %11 = icmp sle i32 %9, %10
  %12 = and i1 %.03045, %11
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %13 = tail call noundef i64 @_ZNKSt6vectorISt4pairIiiESaIS1_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %0) #1
  %14 = icmp ugt i64 %13, %indvars.iv.next
  br i1 %14, label %.lr.ph, label %._crit_edge, !llvm.loop !12

.critedge:                                        ; preds = %.preheader, %._crit_edge
  %15 = add nsw i32 %.03348, 1
  br label %22, !llvm.loop !14

16:                                               ; preds = %._crit_edge
  %17 = sub nsw i32 %.03348, %.02749
  %18 = icmp slt i32 %17, 2
  br i1 %18, label %.loopexit, label %19

19:                                               ; preds = %16
  %20 = add nsw i32 %.02450, 1
  %21 = add nsw i32 %.03348, -1
  br label %22

22:                                               ; preds = %19, %.critedge
  %.134 = phi i32 [ %15, %.critedge ], [ %.03348, %19 ]
  %.128 = phi i32 [ %.02749, %.critedge ], [ %21, %19 ]
  %.125 = phi i32 [ %.02450, %.critedge ], [ %20, %19 ]
  %23 = load i32, ptr @W, align 4, !tbaa !5
  %.not = icmp sgt i32 %.134, %23
  br i1 %.not, label %.thread40.loopexit, label %.preheader

.thread40.loopexit:                               ; preds = %22
  %24 = add i32 %.125, -1
  br label %.thread40

.thread40:                                        ; preds = %.thread40.loopexit, %1
  %.024.lcssa = phi i32 [ -1, %1 ], [ %24, %.thread40.loopexit ]
  %25 = tail call noundef i64 @_ZNKSt6vectorISt4pairIiiESaIS1_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %0) #1
  %26 = trunc i64 %25 to i32
  %27 = add i32 %.024.lcssa, %26
  br label %.loopexit

.loopexit:                                        ; preds = %16, %.thread40
  %.3 = phi i32 [ %27, %.thread40 ], [ 100000000, %16 ]
  ret i32 %.3
}

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


; Effective O3 passes: ConstraintEliminationPass,CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass