; LLVM IR from eyangch/competitive-programming :: USACOcontests/silver/2019.02 (revegetate)

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

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_Z3recPSt6vectorISt4pairIbiESaIS1_EERA100000_biPi(ptr noundef %0, ptr noundef nonnull align 1 dereferenceable(100000) %1, i32 noundef %2, ptr noundef %3) #0 {
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store i32 %2, ptr %8, align 4, !tbaa !9
  store ptr %3, ptr %9, align 8, !tbaa !5
  %13 = load ptr, ptr %7, align 8, !tbaa !5
  %14 = load i32, ptr %8, align 4, !tbaa !9
  %15 = sext i32 %14 to i64
  %16 = getelementptr inbounds [100000 x i8], ptr %13, i64 0, i64 %15
  %17 = load i8, ptr %16, align 1, !tbaa !11, !range !13, !noundef !14
  %18 = trunc i8 %17 to i1
  br i1 %18, label %19, label %20

19:                                               ; preds = %4
  store i32 0, ptr %5, align 4
  br label %135

20:                                               ; preds = %4
  %21 = load ptr, ptr %7, align 8, !tbaa !5
  %22 = load i32, ptr %8, align 4, !tbaa !9
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds [100000 x i8], ptr %21, i64 0, i64 %23
  store i8 1, ptr %24, align 1, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  store i32 0, ptr %10, align 4, !tbaa !9
  br label %25

25:                                               ; preds = %129, %20
  %26 = load i32, ptr %10, align 4, !tbaa !9
  %27 = zext i32 %26 to i64
  %28 = load ptr, ptr %6, align 8, !tbaa !5
  %29 = load i32, ptr %8, align 4, !tbaa !9
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds %"class.std::vector", ptr %28, i64 %30
  %32 = call noundef i64 @_ZNKSt6vectorISt4pairIbiESaIS1_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %31) #3
  %33 = icmp ult i64 %27, %32
  br i1 %33, label %35, label %34

34:                                               ; preds = %25
  store i32 2, ptr %11, align 4
  br label %132

35:                                               ; preds = %25
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #3
  %36 = load ptr, ptr %6, align 8, !tbaa !5
  %37 = load i32, ptr %8, align 4, !tbaa !9
  %38 = sext i32 %37 to i64
  %39 = getelementptr inbounds %"class.std::vector", ptr %36, i64 %38
  %40 = load i32, ptr %10, align 4, !tbaa !9
  %41 = zext i32 %40 to i64
  %42 = call noundef nonnull align 4 dereferenceable(8) ptr @_ZNSt6vectorISt4pairIbiESaIS1_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %39, i64 noundef %41) #3
  %43 = getelementptr inbounds %"struct.std::pair", ptr %42, i32 0, i32 0
  %44 = load i8, ptr %43, align 4, !tbaa !15, !range !13, !noundef !14
  %45 = trunc i8 %44 to i1
  %46 = zext i1 %45 to i32
  %47 = icmp eq i32 %46, 1
  br i1 %47, label %48, label %49

48:                                               ; preds = %35
  store i32 -1, ptr %12, align 4, !tbaa !9
  br label %50

49:                                               ; preds = %35
  store i32 1, ptr %12, align 4, !tbaa !9
  br label %50

50:                                               ; preds = %49, %48
  %51 = load ptr, ptr %9, align 8, !tbaa !5
  %52 = load ptr, ptr %6, align 8, !tbaa !5
  %53 = load i32, ptr %8, align 4, !tbaa !9
  %54 = sext i32 %53 to i64
  %55 = getelementptr inbounds %"class.std::vector", ptr %52, i64 %54
  %56 = load i32, ptr %10, align 4, !tbaa !9
  %57 = zext i32 %56 to i64
  %58 = call noundef nonnull align 4 dereferenceable(8) ptr @_ZNSt6vectorISt4pairIbiESaIS1_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %55, i64 noundef %57) #3
  %59 = getelementptr inbounds %"struct.std::pair", ptr %58, i32 0, i32 1
  %60 = load i32, ptr %59, align 4, !tbaa !17
  %61 = sext i32 %60 to i64
  %62 = getelementptr inbounds i32, ptr %51, i64 %61
  %63 = load i32, ptr %62, align 4, !tbaa !9
  %64 = icmp eq i32 %63, 0
  br i1 %64, label %65, label %85

65:                                               ; preds = %50
  %66 = load ptr, ptr %9, align 8, !tbaa !5
  %67 = load i32, ptr %8, align 4, !tbaa !9
  %68 = sext i32 %67 to i64
  %69 = getelementptr inbounds i32, ptr %66, i64 %68
  %70 = load i32, ptr %69, align 4, !tbaa !9
  %71 = load i32, ptr %12, align 4, !tbaa !9
  %72 = mul nsw i32 %70, %71
  %73 = load ptr, ptr %9, align 8, !tbaa !5
  %74 = load ptr, ptr %6, align 8, !tbaa !5
  %75 = load i32, ptr %8, align 4, !tbaa !9
  %76 = sext i32 %75 to i64
  %77 = getelementptr inbounds %"class.std::vector", ptr %74, i64 %76
  %78 = load i32, ptr %10, align 4, !tbaa !9
  %79 = zext i32 %78 to i64
  %80 = call noundef nonnull align 4 dereferenceable(8) ptr @_ZNSt6vectorISt4pairIbiESaIS1_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %77, i64 noundef %79) #3
  %81 = getelementptr inbounds %"struct.std::pair", ptr %80, i32 0, i32 1
  %82 = load i32, ptr %81, align 4, !tbaa !17
  %83 = sext i32 %82 to i64
  %84 = getelementptr inbounds i32, ptr %73, i64 %83
  store i32 %72, ptr %84, align 4, !tbaa !9
  br label %109

85:                                               ; preds = %50
  %86 = load ptr, ptr %9, align 8, !tbaa !5
  %87 = load ptr, ptr %6, align 8, !tbaa !5
  %88 = load i32, ptr %8, align 4, !tbaa !9
  %89 = sext i32 %88 to i64
  %90 = getelementptr inbounds %"class.std::vector", ptr %87, i64 %89
  %91 = load i32, ptr %10, align 4, !tbaa !9
  %92 = zext i32 %91 to i64
  %93 = call noundef nonnull align 4 dereferenceable(8) ptr @_ZNSt6vectorISt4pairIbiESaIS1_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %90, i64 noundef %92) #3
  %94 = getelementptr inbounds %"struct.std::pair", ptr %93, i32 0, i32 1
  %95 = load i32, ptr %94, align 4, !tbaa !17
  %96 = sext i32 %95 to i64
  %97 = getelementptr inbounds i32, ptr %86, i64 %96
  %98 = load i32, ptr %97, align 4, !tbaa !9
  %99 = load ptr, ptr %9, align 8, !tbaa !5
  %100 = load i32, ptr %8, align 4, !tbaa !9
  %101 = sext i32 %100 to i64
  %102 = getelementptr inbounds i32, ptr %99, i64 %101
  %103 = load i32, ptr %102, align 4, !tbaa !9
  %104 = load i32, ptr %12, align 4, !tbaa !9
  %105 = mul nsw i32 %103, %104
  %106 = icmp ne i32 %98, %105
  br i1 %106, label %107, label %108

107:                                              ; preds = %85
  store i32 -1, ptr %5, align 4
  store i32 1, ptr %11, align 4
  br label %126

108:                                              ; preds = %85
  br label %109

109:                                              ; preds = %108, %65
  %110 = load ptr, ptr %6, align 8, !tbaa !5
  %111 = load ptr, ptr %7, align 8, !tbaa !5
  %112 = load ptr, ptr %6, align 8, !tbaa !5
  %113 = load i32, ptr %8, align 4, !tbaa !9
  %114 = sext i32 %113 to i64
  %115 = getelementptr inbounds %"class.std::vector", ptr %112, i64 %114
  %116 = load i32, ptr %10, align 4, !tbaa !9
  %117 = zext i32 %116 to i64
  %118 = call noundef nonnull align 4 dereferenceable(8) ptr @_ZNSt6vectorISt4pairIbiESaIS1_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %115, i64 noundef %117) #3
  %119 = getelementptr inbounds %"struct.std::pair", ptr %118, i32 0, i32 1
  %120 = load i32, ptr %119, align 4, !tbaa !17
  %121 = load ptr, ptr %9, align 8, !tbaa !5
  %122 = call noundef i32 @_Z3recPSt6vectorISt4pairIbiESaIS1_EERA100000_biPi(ptr noundef %110, ptr noundef nonnull align 1 dereferenceable(100000) %111, i32 noundef %120, ptr noundef %121)
  %123 = icmp eq i32 %122, -1
  br i1 %123, label %124, label %125

124:                                              ; preds = %109
  store i32 -1, ptr %5, align 4
  store i32 1, ptr %11, align 4
  br label %126

125:                                              ; preds = %109
  store i32 0, ptr %11, align 4
  br label %126

126:                                              ; preds = %125, %124, %107
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #3
  %127 = load i32, ptr %11, align 4
  switch i32 %127, label %132 [
    i32 0, label %128
  ]

128:                                              ; preds = %126
  br label %129

129:                                              ; preds = %128
  %130 = load i32, ptr %10, align 4, !tbaa !9
  %131 = add i32 %130, 1
  store i32 %131, ptr %10, align 4, !tbaa !9
  br label %25, !llvm.loop !18

132:                                              ; preds = %126, %34
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  %133 = load i32, ptr %11, align 4
  switch i32 %133, label %137 [
    i32 2, label %134
    i32 1, label %135
  ]

134:                                              ; preds = %132
  store i32 1, ptr %5, align 4
  br label %135

135:                                              ; preds = %134, %132, %19
  %136 = load i32, ptr %5, align 4
  ret i32 %136

137:                                              ; preds = %132
  unreachable
}

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

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

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

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 = { 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 = !{i8 0, i8 2}
!14 = !{}
!15 = !{!16, !12, i64 0}
!16 = !{!"_ZTSSt4pairIbiE", !12, i64 0, !10, i64 4}
!17 = !{!16, !10, i64 4}
!18 = distinct !{!18, !19}
!19 = !{!"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<std::pair<bool, int>, std::allocator<std::pair<bool, int>>>::_Vector_impl" }
%"struct.std::_Vector_base<std::pair<bool, int>, std::allocator<std::pair<bool, int>>>::_Vector_impl" = type { %"struct.std::_Vector_base<std::pair<bool, int>, std::allocator<std::pair<bool, int>>>::_Vector_impl_data" }
%"struct.std::_Vector_base<std::pair<bool, int>, std::allocator<std::pair<bool, int>>>::_Vector_impl_data" = type { ptr, ptr, ptr }

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i32 @_Z3recPSt6vectorISt4pairIbiESaIS1_EERA100000_biPi(ptr noundef %0, ptr nocapture noundef nonnull align 1 dereferenceable(100000) %1, i32 noundef %2, ptr nocapture noundef %3) local_unnamed_addr #0 {
  %5 = sext i32 %2 to i64
  %6 = getelementptr inbounds [100000 x i8], ptr %1, i64 0, i64 %5
  %7 = load i8, ptr %6, align 1, !tbaa !5, !range !9, !noundef !10
  %8 = trunc nuw i8 %7 to i1
  br i1 %8, label %.critedge, label %9

9:                                                ; preds = %4
  store i8 1, ptr %6, align 1, !tbaa !5
  %10 = getelementptr inbounds %"class.std::vector", ptr %0, i64 %5
  %11 = tail call noundef i64 @_ZNKSt6vectorISt4pairIbiESaIS1_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %10) #1
  %.not4445.not = icmp eq i64 %11, 0
  br i1 %.not4445.not, label %.critedge, label %.lr.ph

.lr.ph:                                           ; preds = %9
  %12 = getelementptr inbounds i32, ptr %3, i64 %5
  br label %17

13:                                               ; preds = %46
  %14 = add i32 %.03846, 1
  %15 = zext i32 %14 to i64
  %16 = tail call noundef i64 @_ZNKSt6vectorISt4pairIbiESaIS1_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %10) #1
  %.not44 = icmp ugt i64 %16, %15
  br i1 %.not44, label %17, label %.critedge, !llvm.loop !11

17:                                               ; preds = %.lr.ph, %13
  %18 = phi i64 [ 0, %.lr.ph ], [ %15, %13 ]
  %.03846 = phi i32 [ 0, %.lr.ph ], [ %14, %13 ]
  %19 = tail call noundef nonnull align 4 dereferenceable(8) ptr @_ZNSt6vectorISt4pairIbiESaIS1_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %10, i64 noundef %18) #1
  %20 = load i8, ptr %19, align 4, !tbaa !13, !range !9, !noundef !10
  %21 = trunc nuw i8 %20 to i1
  %. = select i1 %21, i32 -1, i32 1
  %22 = tail call noundef nonnull align 4 dereferenceable(8) ptr @_ZNSt6vectorISt4pairIbiESaIS1_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %10, i64 noundef %18) #1
  %23 = getelementptr inbounds i8, ptr %22, i64 4
  %24 = load i32, ptr %23, align 4, !tbaa !16
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds i32, ptr %3, i64 %25
  %27 = load i32, ptr %26, align 4, !tbaa !17
  %28 = icmp eq i32 %27, 0
  br i1 %28, label %29, label %37

29:                                               ; preds = %17
  %30 = load i32, ptr %12, align 4, !tbaa !17
  %31 = mul nsw i32 %30, %.
  %32 = tail call noundef nonnull align 4 dereferenceable(8) ptr @_ZNSt6vectorISt4pairIbiESaIS1_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %10, i64 noundef %18) #1
  %33 = getelementptr inbounds i8, ptr %32, i64 4
  %34 = load i32, ptr %33, align 4, !tbaa !16
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds i32, ptr %3, i64 %35
  store i32 %31, ptr %36, align 4, !tbaa !17
  br label %46

37:                                               ; preds = %17
  %38 = tail call noundef nonnull align 4 dereferenceable(8) ptr @_ZNSt6vectorISt4pairIbiESaIS1_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %10, i64 noundef %18) #1
  %39 = getelementptr inbounds i8, ptr %38, i64 4
  %40 = load i32, ptr %39, align 4, !tbaa !16
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds i32, ptr %3, i64 %41
  %43 = load i32, ptr %42, align 4, !tbaa !17
  %44 = load i32, ptr %12, align 4, !tbaa !17
  %45 = mul nsw i32 %44, %.
  %.not = icmp eq i32 %43, %45
  br i1 %.not, label %46, label %.critedge

46:                                               ; preds = %37, %29
  %47 = tail call noundef nonnull align 4 dereferenceable(8) ptr @_ZNSt6vectorISt4pairIbiESaIS1_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %10, i64 noundef %18) #1
  %48 = getelementptr inbounds i8, ptr %47, i64 4
  %49 = load i32, ptr %48, align 4, !tbaa !16
  %50 = tail call noundef i32 @_Z3recPSt6vectorISt4pairIbiESaIS1_EERA100000_biPi(ptr noundef %0, ptr noundef nonnull align 1 dereferenceable(100000) %1, i32 noundef %49, ptr noundef nonnull %3)
  %.not43 = icmp eq i32 %50, -1
  br i1 %.not43, label %.critedge, label %13

.critedge:                                        ; preds = %37, %13, %46, %9, %4
  %.3 = phi i32 [ 0, %4 ], [ 1, %9 ], [ -1, %37 ], [ 1, %13 ], [ -1, %46 ]
  ret i32 %.3
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZNKSt6vectorISt4pairIbiESaIS1_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 @_ZNSt6vectorISt4pairIbiESaIS1_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 = !{!"bool", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{i8 0, i8 2}
!10 = !{}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = !{!14, !6, i64 0}
!14 = !{!"_ZTSSt4pairIbiE", !6, i64 0, !15, i64 4}
!15 = !{!"int", !7, i64 0}
!16 = !{!14, !15, i64 4}
!17 = !{!15, !15, i64 0}


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