; LLVM IR from bqi343/cp-notebook :: Contests/USACO Solutions/2017-18/Feb 2018/Plat (newbarn)

; 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 }
%"class.std::basic_istream" = type { ptr, i64, %"class.std::basic_ios" }
%"class.std::basic_ios" = type { %"class.std::ios_base", ptr, i8, i8, ptr, ptr, ptr, ptr }
%"class.std::ios_base" = type { ptr, i64, i64, i32, i32, i32, ptr, %"struct.std::ios_base::_Words", [8 x %"struct.std::ios_base::_Words"], i32, ptr, %"class.std::locale" }
%"struct.std::ios_base::_Words" = type { ptr, i64 }
%"class.std::locale" = type { ptr }
%"class.std::basic_ostream" = type { ptr, %"class.std::basic_ios" }

@Q = external dso_local global i32, align 4
@anc = external dso_local global [100001 x [17 x i32]], align 16
@comp = external dso_local global [100001 x i32], align 16
@depth = external dso_local global [100001 x i32], align 16
@cur = external dso_local global i32, align 4
@dia = external dso_local global [100001 x %"struct.std::pair"], align 16
@.str = external hidden unnamed_addr constant [11 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [2 x i8], align 1
@stdin = external global ptr, align 8
@.str.3 = external hidden unnamed_addr constant [12 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [2 x i8], align 1
@stdout = external global ptr, align 8
@_ZSt3cin = external global %"class.std::basic_istream", align 8
@_ZSt4cout = external global %"class.std::basic_ostream", align 8
@.str.5 = external hidden unnamed_addr constant [2 x i8], align 1

; 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 @_Z4distii(i32 noundef, i32 noundef) #1

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #2 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i8, align 1
  %5 = alloca i32, align 4
  %6 = alloca %"struct.std::pair", align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  %11 = load ptr, ptr @stdin, align 8, !tbaa !5
  %12 = call ptr @freopen(ptr noundef @.str, ptr noundef @.str.2, ptr noundef %11)
  %13 = load ptr, ptr @stdout, align 8, !tbaa !5
  %14 = call ptr @freopen(ptr noundef @.str.3, ptr noundef @.str.4, ptr noundef %13)
  %15 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERi(ptr noundef nonnull align 8 dereferenceable(16) @_ZSt3cin, ptr noundef nonnull align 4 dereferenceable(4) @Q)
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #6
  store i32 0, ptr %2, align 4, !tbaa !9
  br label %16

16:                                               ; preds = %180, %0
  %17 = load i32, ptr %2, align 4, !tbaa !9
  %18 = load i32, ptr @Q, align 4, !tbaa !9
  %19 = icmp slt i32 %17, %18
  br i1 %19, label %21, label %20

20:                                               ; preds = %16
  store i32 2, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #6
  br label %183

21:                                               ; preds = %16
  call void @llvm.lifetime.start.p0(i64 1, ptr %4) #6
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #6
  %22 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZStrsIcSt11char_traitsIcEERSt13basic_istreamIT_T0_ES6_RS3_(ptr noundef nonnull align 8 dereferenceable(16) @_ZSt3cin, ptr noundef nonnull align 1 dereferenceable(1) %4)
  %23 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERi(ptr noundef nonnull align 8 dereferenceable(16) %22, ptr noundef nonnull align 4 dereferenceable(4) %5)
  %24 = load i8, ptr %4, align 1, !tbaa !11
  %25 = sext i8 %24 to i32
  %26 = icmp eq i32 %25, 66
  br i1 %26, label %27, label %154

27:                                               ; preds = %21
  %28 = load i32, ptr @cur, align 4, !tbaa !9
  %29 = add nsw i32 %28, 1
  store i32 %29, ptr @cur, align 4, !tbaa !9
  %30 = load i32, ptr %5, align 4, !tbaa !9
  %31 = icmp eq i32 %30, -1
  br i1 %31, label %32, label %40

32:                                               ; preds = %27
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #6
  call void @_ZNSt4pairIiiEC2IRiS2_TnNSt9enable_ifIXaaclsr5_PCCPE22_MoveConstructiblePairIT_T0_EEclsr5_PCCPE30_ImplicitlyMoveConvertiblePairIS4_S5_EEEbE4typeELb1EEEOS4_OS5_(ptr noundef nonnull align 4 dereferenceable(8) %6, ptr noundef nonnull align 4 dereferenceable(4) @cur, ptr noundef nonnull align 4 dereferenceable(4) @cur)
  %33 = load i32, ptr @cur, align 4, !tbaa !9
  %34 = load i32, ptr @cur, align 4, !tbaa !9
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds [100001 x i32], ptr @comp, i64 0, i64 %35
  store i32 %33, ptr %36, align 4, !tbaa !9
  %37 = sext i32 %33 to i64
  %38 = getelementptr inbounds [100001 x %"struct.std::pair"], ptr @dia, i64 0, i64 %37
  %39 = call noundef nonnull align 4 dereferenceable(8) ptr @_ZNSt4pairIiiEaSEOS0_(ptr noundef nonnull align 4 dereferenceable(8) %38, ptr noundef nonnull align 4 dereferenceable(8) %6) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #6
  br label %153

40:                                               ; preds = %27
  %41 = load i32, ptr %5, align 4, !tbaa !9
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds [100001 x i32], ptr @comp, i64 0, i64 %42
  %44 = load i32, ptr %43, align 4, !tbaa !9
  %45 = load i32, ptr @cur, align 4, !tbaa !9
  %46 = sext i32 %45 to i64
  %47 = getelementptr inbounds [100001 x i32], ptr @comp, i64 0, i64 %46
  store i32 %44, ptr %47, align 4, !tbaa !9
  %48 = load i32, ptr %5, align 4, !tbaa !9
  %49 = sext i32 %48 to i64
  %50 = getelementptr inbounds [100001 x i32], ptr @depth, i64 0, i64 %49
  %51 = load i32, ptr %50, align 4, !tbaa !9
  %52 = add nsw i32 %51, 1
  %53 = load i32, ptr @cur, align 4, !tbaa !9
  %54 = sext i32 %53 to i64
  %55 = getelementptr inbounds [100001 x i32], ptr @depth, i64 0, i64 %54
  store i32 %52, ptr %55, align 4, !tbaa !9
  %56 = load i32, ptr %5, align 4, !tbaa !9
  %57 = load i32, ptr @cur, align 4, !tbaa !9
  %58 = sext i32 %57 to i64
  %59 = getelementptr inbounds [100001 x [17 x i32]], ptr @anc, i64 0, i64 %58
  %60 = getelementptr inbounds [17 x i32], ptr %59, i64 0, i64 0
  store i32 %56, ptr %60, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #6
  store i32 1, ptr %7, align 4, !tbaa !9
  br label %61

61:                                               ; preds = %87, %40
  %62 = load i32, ptr %7, align 4, !tbaa !9
  %63 = icmp slt i32 %62, 17
  br i1 %63, label %65, label %64

64:                                               ; preds = %61
  store i32 5, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #6
  br label %90

65:                                               ; preds = %61
  %66 = load i32, ptr @cur, align 4, !tbaa !9
  %67 = sext i32 %66 to i64
  %68 = getelementptr inbounds [100001 x [17 x i32]], ptr @anc, i64 0, i64 %67
  %69 = load i32, ptr %7, align 4, !tbaa !9
  %70 = sub nsw i32 %69, 1
  %71 = sext i32 %70 to i64
  %72 = getelementptr inbounds [17 x i32], ptr %68, i64 0, i64 %71
  %73 = load i32, ptr %72, align 4, !tbaa !9
  %74 = sext i32 %73 to i64
  %75 = getelementptr inbounds [100001 x [17 x i32]], ptr @anc, i64 0, i64 %74
  %76 = load i32, ptr %7, align 4, !tbaa !9
  %77 = sub nsw i32 %76, 1
  %78 = sext i32 %77 to i64
  %79 = getelementptr inbounds [17 x i32], ptr %75, i64 0, i64 %78
  %80 = load i32, ptr %79, align 4, !tbaa !9
  %81 = load i32, ptr @cur, align 4, !tbaa !9
  %82 = sext i32 %81 to i64
  %83 = getelementptr inbounds [100001 x [17 x i32]], ptr @anc, i64 0, i64 %82
  %84 = load i32, ptr %7, align 4, !tbaa !9
  %85 = sext i32 %84 to i64
  %86 = getelementptr inbounds [17 x i32], ptr %83, i64 0, i64 %85
  store i32 %80, ptr %86, align 4, !tbaa !9
  br label %87

87:                                               ; preds = %65
  %88 = load i32, ptr %7, align 4, !tbaa !9
  %89 = add nsw i32 %88, 1
  store i32 %89, ptr %7, align 4, !tbaa !9
  br label %61, !llvm.loop !12

90:                                               ; preds = %64
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #6
  %91 = load i32, ptr @cur, align 4, !tbaa !9
  %92 = sext i32 %91 to i64
  %93 = getelementptr inbounds [100001 x i32], ptr @comp, i64 0, i64 %92
  %94 = load i32, ptr %93, align 4, !tbaa !9
  %95 = sext i32 %94 to i64
  %96 = getelementptr inbounds [100001 x %"struct.std::pair"], ptr @dia, i64 0, i64 %95
  %97 = getelementptr inbounds %"struct.std::pair", ptr %96, i32 0, i32 0
  %98 = load i32, ptr %97, align 8, !tbaa !14
  %99 = load i32, ptr @cur, align 4, !tbaa !9
  %100 = sext i32 %99 to i64
  %101 = getelementptr inbounds [100001 x i32], ptr @comp, i64 0, i64 %100
  %102 = load i32, ptr %101, align 4, !tbaa !9
  %103 = sext i32 %102 to i64
  %104 = getelementptr inbounds [100001 x %"struct.std::pair"], ptr @dia, i64 0, i64 %103
  %105 = getelementptr inbounds %"struct.std::pair", ptr %104, i32 0, i32 1
  %106 = load i32, ptr %105, align 4, !tbaa !16
  %107 = call noundef i32 @_Z4distii(i32 noundef %98, i32 noundef %106)
  store i32 %107, ptr %8, align 4, !tbaa !9
  %108 = load i32, ptr @cur, align 4, !tbaa !9
  %109 = load i32, ptr @cur, align 4, !tbaa !9
  %110 = sext i32 %109 to i64
  %111 = getelementptr inbounds [100001 x i32], ptr @comp, i64 0, i64 %110
  %112 = load i32, ptr %111, align 4, !tbaa !9
  %113 = sext i32 %112 to i64
  %114 = getelementptr inbounds [100001 x %"struct.std::pair"], ptr @dia, i64 0, i64 %113
  %115 = getelementptr inbounds %"struct.std::pair", ptr %114, i32 0, i32 0
  %116 = load i32, ptr %115, align 8, !tbaa !14
  %117 = call noundef i32 @_Z4distii(i32 noundef %108, i32 noundef %116)
  %118 = load i32, ptr %8, align 4, !tbaa !9
  %119 = icmp sgt i32 %117, %118
  br i1 %119, label %120, label %129

120:                                              ; preds = %90
  %121 = load i32, ptr @cur, align 4, !tbaa !9
  %122 = load i32, ptr @cur, align 4, !tbaa !9
  %123 = sext i32 %122 to i64
  %124 = getelementptr inbounds [100001 x i32], ptr @comp, i64 0, i64 %123
  %125 = load i32, ptr %124, align 4, !tbaa !9
  %126 = sext i32 %125 to i64
  %127 = getelementptr inbounds [100001 x %"struct.std::pair"], ptr @dia, i64 0, i64 %126
  %128 = getelementptr inbounds %"struct.std::pair", ptr %127, i32 0, i32 1
  store i32 %121, ptr %128, align 4, !tbaa !16
  br label %152

129:                                              ; preds = %90
  %130 = load i32, ptr @cur, align 4, !tbaa !9
  %131 = load i32, ptr @cur, align 4, !tbaa !9
  %132 = sext i32 %131 to i64
  %133 = getelementptr inbounds [100001 x i32], ptr @comp, i64 0, i64 %132
  %134 = load i32, ptr %133, align 4, !tbaa !9
  %135 = sext i32 %134 to i64
  %136 = getelementptr inbounds [100001 x %"struct.std::pair"], ptr @dia, i64 0, i64 %135
  %137 = getelementptr inbounds %"struct.std::pair", ptr %136, i32 0, i32 1
  %138 = load i32, ptr %137, align 4, !tbaa !16
  %139 = call noundef i32 @_Z4distii(i32 noundef %130, i32 noundef %138)
  %140 = load i32, ptr %8, align 4, !tbaa !9
  %141 = icmp sgt i32 %139, %140
  br i1 %141, label %142, label %151

142:                                              ; preds = %129
  %143 = load i32, ptr @cur, align 4, !tbaa !9
  %144 = load i32, ptr @cur, align 4, !tbaa !9
  %145 = sext i32 %144 to i64
  %146 = getelementptr inbounds [100001 x i32], ptr @comp, i64 0, i64 %145
  %147 = load i32, ptr %146, align 4, !tbaa !9
  %148 = sext i32 %147 to i64
  %149 = getelementptr inbounds [100001 x %"struct.std::pair"], ptr @dia, i64 0, i64 %148
  %150 = getelementptr inbounds %"struct.std::pair", ptr %149, i32 0, i32 0
  store i32 %143, ptr %150, align 8, !tbaa !14
  br label %151

151:                                              ; preds = %142, %129
  br label %152

152:                                              ; preds = %151, %120
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #6
  br label %153

153:                                              ; preds = %152, %32
  br label %179

154:                                              ; preds = %21
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #6
  %155 = load i32, ptr %5, align 4, !tbaa !9
  %156 = sext i32 %155 to i64
  %157 = getelementptr inbounds [100001 x i32], ptr @comp, i64 0, i64 %156
  %158 = load i32, ptr %157, align 4, !tbaa !9
  %159 = sext i32 %158 to i64
  %160 = getelementptr inbounds [100001 x %"struct.std::pair"], ptr @dia, i64 0, i64 %159
  %161 = getelementptr inbounds %"struct.std::pair", ptr %160, i32 0, i32 0
  %162 = load i32, ptr %161, align 8, !tbaa !14
  %163 = load i32, ptr %5, align 4, !tbaa !9
  %164 = call noundef i32 @_Z4distii(i32 noundef %162, i32 noundef %163)
  store i32 %164, ptr %9, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #6
  %165 = load i32, ptr %5, align 4, !tbaa !9
  %166 = sext i32 %165 to i64
  %167 = getelementptr inbounds [100001 x i32], ptr @comp, i64 0, i64 %166
  %168 = load i32, ptr %167, align 4, !tbaa !9
  %169 = sext i32 %168 to i64
  %170 = getelementptr inbounds [100001 x %"struct.std::pair"], ptr @dia, i64 0, i64 %169
  %171 = getelementptr inbounds %"struct.std::pair", ptr %170, i32 0, i32 1
  %172 = load i32, ptr %171, align 4, !tbaa !16
  %173 = load i32, ptr %5, align 4, !tbaa !9
  %174 = call noundef i32 @_Z4distii(i32 noundef %172, i32 noundef %173)
  store i32 %174, ptr %10, align 4, !tbaa !9
  %175 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %9, ptr noundef nonnull align 4 dereferenceable(4) %10)
  %176 = load i32, ptr %175, align 4, !tbaa !9
  %177 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEi(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, i32 noundef %176)
  %178 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc(ptr noundef nonnull align 8 dereferenceable(8) %177, ptr noundef @.str.5)
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #6
  br label %179

179:                                              ; preds = %154, %153
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #6
  call void @llvm.lifetime.end.p0(i64 1, ptr %4) #6
  br label %180

180:                                              ; preds = %179
  %181 = load i32, ptr %2, align 4, !tbaa !9
  %182 = add nsw i32 %181, 1
  store i32 %182, ptr %2, align 4, !tbaa !9
  br label %16, !llvm.loop !17

183:                                              ; preds = %20
  %184 = load i32, ptr %1, align 4
  ret i32 %184
}

declare ptr @freopen(ptr noundef, ptr noundef, ptr noundef) #3

declare noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERi(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef nonnull align 4 dereferenceable(4)) #3

declare noundef nonnull align 8 dereferenceable(16) ptr @_ZStrsIcSt11char_traitsIcEERSt13basic_istreamIT_T0_ES6_RS3_(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef nonnull align 1 dereferenceable(1)) #3

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZNSt4pairIiiEC2IRiS2_TnNSt9enable_ifIXaaclsr5_PCCPE22_MoveConstructiblePairIT_T0_EEclsr5_PCCPE30_ImplicitlyMoveConvertiblePairIS4_S5_EEEbE4typeELb1EEEOS4_OS5_(ptr noundef nonnull align 4 dereferenceable(8), ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) unnamed_addr #1 align 2

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

; Function Attrs: inlinehint mustprogress uwtable
declare noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef) #4

declare noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEi(ptr noundef nonnull align 8 dereferenceable(8), i32 noundef) #3

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) #5

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 = { mustprogress norecurse 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 = { "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 #4 = { inlinehint 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 #5 = { inlinehint 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 #6 = { 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 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = !{!15, !10, i64 0}
!15 = !{!"_ZTSSt4pairIiiE", !10, i64 0, !10, i64 4}
!16 = !{!15, !10, i64 4}
!17 = distinct !{!17, !13}


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

%"struct.std::pair" = type { i32, i32 }
%"class.std::basic_istream" = type { ptr, i64, %"class.std::basic_ios" }
%"class.std::basic_ios" = type { %"class.std::ios_base", ptr, i8, i8, ptr, ptr, ptr, ptr }
%"class.std::ios_base" = type { ptr, i64, i64, i32, i32, i32, ptr, %"struct.std::ios_base::_Words", [8 x %"struct.std::ios_base::_Words"], i32, ptr, %"class.std::locale" }
%"struct.std::ios_base::_Words" = type { ptr, i64 }
%"class.std::locale" = type { ptr }
%"class.std::basic_ostream" = type { ptr, %"class.std::basic_ios" }

@Q = external dso_local global i32, align 4
@anc = external dso_local local_unnamed_addr global [100001 x [17 x i32]], align 16
@comp = external dso_local local_unnamed_addr global [100001 x i32], align 16
@depth = external dso_local local_unnamed_addr global [100001 x i32], align 16
@cur = external dso_local global i32, align 4
@dia = external dso_local global [100001 x %"struct.std::pair"], align 16
@.str = external hidden unnamed_addr constant [11 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [2 x i8], align 1
@stdin = external local_unnamed_addr global ptr, align 8
@.str.3 = external hidden unnamed_addr constant [12 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [2 x i8], align 1
@stdout = external local_unnamed_addr global ptr, align 8
@_ZSt3cin = external global %"class.std::basic_istream", align 8
@_ZSt4cout = external global %"class.std::basic_ostream", align 8
@.str.5 = external hidden unnamed_addr constant [2 x i8], align 1

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

; Function Attrs: mustprogress 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 @_Z4distii(i32 noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() local_unnamed_addr #2 {
  %1 = alloca i8, align 1
  %2 = alloca i32, align 4
  %3 = alloca %"struct.std::pair", align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = load ptr, ptr @stdin, align 8, !tbaa !5
  %7 = tail call ptr @freopen(ptr noundef nonnull @.str, ptr noundef nonnull @.str.2, ptr noundef %6)
  %8 = load ptr, ptr @stdout, align 8, !tbaa !5
  %9 = tail call ptr @freopen(ptr noundef nonnull @.str.3, ptr noundef nonnull @.str.4, ptr noundef %8)
  %10 = tail call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERi(ptr noundef nonnull align 8 dereferenceable(16) @_ZSt3cin, ptr noundef nonnull align 4 dereferenceable(4) @Q)
  %11 = load i32, ptr @Q, align 4, !tbaa !9
  %12 = icmp sgt i32 %11, 0
  br i1 %12, label %.lr.ph, label %._crit_edge

._crit_edge:                                      ; preds = %156, %0
  ret i32 0

.lr.ph:                                           ; preds = %0, %156
  %.014 = phi i32 [ %157, %156 ], [ 0, %0 ]
  call void @llvm.lifetime.start.p0(i64 1, ptr nonnull %1) #6
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %2) #6
  %13 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZStrsIcSt11char_traitsIcEERSt13basic_istreamIT_T0_ES6_RS3_(ptr noundef nonnull align 8 dereferenceable(16) @_ZSt3cin, ptr noundef nonnull align 1 dereferenceable(1) %1)
  %14 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERi(ptr noundef nonnull align 8 dereferenceable(16) %13, ptr noundef nonnull align 4 dereferenceable(4) %2)
  %15 = load i8, ptr %1, align 1, !tbaa !11
  %16 = icmp eq i8 %15, 66
  br i1 %16, label %17, label %135

17:                                               ; preds = %.lr.ph
  %18 = load i32, ptr @cur, align 4, !tbaa !9
  %19 = add nsw i32 %18, 1
  store i32 %19, ptr @cur, align 4, !tbaa !9
  %20 = load i32, ptr %2, align 4, !tbaa !9
  %21 = icmp eq i32 %20, -1
  br i1 %21, label %22, label %28

22:                                               ; preds = %17
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %3) #6
  call void @_ZNSt4pairIiiEC2IRiS2_TnNSt9enable_ifIXaaclsr5_PCCPE22_MoveConstructiblePairIT_T0_EEclsr5_PCCPE30_ImplicitlyMoveConvertiblePairIS4_S5_EEEbE4typeELb1EEEOS4_OS5_(ptr noundef nonnull align 4 dereferenceable(8) %3, ptr noundef nonnull align 4 dereferenceable(4) @cur, ptr noundef nonnull align 4 dereferenceable(4) @cur)
  %23 = load i32, ptr @cur, align 4, !tbaa !9
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds [100001 x i32], ptr @comp, i64 0, i64 %24
  store i32 %23, ptr %25, align 4, !tbaa !9
  %26 = getelementptr inbounds [100001 x %"struct.std::pair"], ptr @dia, i64 0, i64 %24
  %27 = call noundef nonnull align 4 dereferenceable(8) ptr @_ZNSt4pairIiiEaSEOS0_(ptr noundef nonnull align 4 dereferenceable(8) %26, ptr noundef nonnull align 4 dereferenceable(8) %3) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #6
  br label %156

28:                                               ; preds = %17
  %29 = sext i32 %20 to i64
  %30 = getelementptr inbounds [100001 x i32], ptr @comp, i64 0, i64 %29
  %31 = load i32, ptr %30, align 4, !tbaa !9
  %32 = sext i32 %19 to i64
  %33 = getelementptr inbounds [100001 x i32], ptr @comp, i64 0, i64 %32
  store i32 %31, ptr %33, align 4, !tbaa !9
  %34 = getelementptr inbounds [100001 x i32], ptr @depth, i64 0, i64 %29
  %35 = load i32, ptr %34, align 4, !tbaa !9
  %36 = add nsw i32 %35, 1
  %37 = getelementptr inbounds [100001 x i32], ptr @depth, i64 0, i64 %32
  store i32 %36, ptr %37, align 4, !tbaa !9
  %38 = getelementptr inbounds [100001 x [17 x i32]], ptr @anc, i64 0, i64 %32
  store i32 %20, ptr %38, align 4, !tbaa !9
  %39 = getelementptr inbounds [100001 x [17 x i32]], ptr @anc, i64 0, i64 %29, i64 0
  %40 = load i32, ptr %39, align 4, !tbaa !9
  %41 = getelementptr inbounds [100001 x [17 x i32]], ptr @anc, i64 0, i64 %32, i64 1
  store i32 %40, ptr %41, align 4, !tbaa !9
  %42 = sext i32 %40 to i64
  %43 = getelementptr inbounds [100001 x [17 x i32]], ptr @anc, i64 0, i64 %42, i64 1
  %44 = load i32, ptr %43, align 4, !tbaa !9
  %45 = getelementptr inbounds [100001 x [17 x i32]], ptr @anc, i64 0, i64 %32, i64 2
  store i32 %44, ptr %45, align 4, !tbaa !9
  %46 = sext i32 %44 to i64
  %47 = getelementptr inbounds [100001 x [17 x i32]], ptr @anc, i64 0, i64 %46, i64 2
  %48 = load i32, ptr %47, align 4, !tbaa !9
  %49 = getelementptr inbounds [100001 x [17 x i32]], ptr @anc, i64 0, i64 %32, i64 3
  store i32 %48, ptr %49, align 4, !tbaa !9
  %50 = sext i32 %48 to i64
  %51 = getelementptr inbounds [100001 x [17 x i32]], ptr @anc, i64 0, i64 %50, i64 3
  %52 = load i32, ptr %51, align 4, !tbaa !9
  %53 = getelementptr inbounds [100001 x [17 x i32]], ptr @anc, i64 0, i64 %32, i64 4
  store i32 %52, ptr %53, align 4, !tbaa !9
  %54 = sext i32 %52 to i64
  %55 = getelementptr inbounds [100001 x [17 x i32]], ptr @anc, i64 0, i64 %54, i64 4
  %56 = load i32, ptr %55, align 4, !tbaa !9
  %57 = getelementptr inbounds [100001 x [17 x i32]], ptr @anc, i64 0, i64 %32, i64 5
  store i32 %56, ptr %57, align 4, !tbaa !9
  %58 = sext i32 %56 to i64
  %59 = getelementptr inbounds [100001 x [17 x i32]], ptr @anc, i64 0, i64 %58, i64 5
  %60 = load i32, ptr %59, align 4, !tbaa !9
  %61 = getelementptr inbounds [100001 x [17 x i32]], ptr @anc, i64 0, i64 %32, i64 6
  store i32 %60, ptr %61, align 4, !tbaa !9
  %62 = sext i32 %60 to i64
  %63 = getelementptr inbounds [100001 x [17 x i32]], ptr @anc, i64 0, i64 %62, i64 6
  %64 = load i32, ptr %63, align 4, !tbaa !9
  %65 = getelementptr inbounds [100001 x [17 x i32]], ptr @anc, i64 0, i64 %32, i64 7
  store i32 %64, ptr %65, align 4, !tbaa !9
  %66 = sext i32 %64 to i64
  %67 = getelementptr inbounds [100001 x [17 x i32]], ptr @anc, i64 0, i64 %66, i64 7
  %68 = load i32, ptr %67, align 4, !tbaa !9
  %69 = getelementptr inbounds [100001 x [17 x i32]], ptr @anc, i64 0, i64 %32, i64 8
  store i32 %68, ptr %69, align 4, !tbaa !9
  %70 = sext i32 %68 to i64
  %71 = getelementptr inbounds [100001 x [17 x i32]], ptr @anc, i64 0, i64 %70, i64 8
  %72 = load i32, ptr %71, align 4, !tbaa !9
  %73 = getelementptr inbounds [100001 x [17 x i32]], ptr @anc, i64 0, i64 %32, i64 9
  store i32 %72, ptr %73, align 4, !tbaa !9
  %74 = sext i32 %72 to i64
  %75 = getelementptr inbounds [100001 x [17 x i32]], ptr @anc, i64 0, i64 %74, i64 9
  %76 = load i32, ptr %75, align 4, !tbaa !9
  %77 = getelementptr inbounds [100001 x [17 x i32]], ptr @anc, i64 0, i64 %32, i64 10
  store i32 %76, ptr %77, align 4, !tbaa !9
  %78 = sext i32 %76 to i64
  %79 = getelementptr inbounds [100001 x [17 x i32]], ptr @anc, i64 0, i64 %78, i64 10
  %80 = load i32, ptr %79, align 4, !tbaa !9
  %81 = getelementptr inbounds [100001 x [17 x i32]], ptr @anc, i64 0, i64 %32, i64 11
  store i32 %80, ptr %81, align 4, !tbaa !9
  %82 = sext i32 %80 to i64
  %83 = getelementptr inbounds [100001 x [17 x i32]], ptr @anc, i64 0, i64 %82, i64 11
  %84 = load i32, ptr %83, align 4, !tbaa !9
  %85 = getelementptr inbounds [100001 x [17 x i32]], ptr @anc, i64 0, i64 %32, i64 12
  store i32 %84, ptr %85, align 4, !tbaa !9
  %86 = sext i32 %84 to i64
  %87 = getelementptr inbounds [100001 x [17 x i32]], ptr @anc, i64 0, i64 %86, i64 12
  %88 = load i32, ptr %87, align 4, !tbaa !9
  %89 = getelementptr inbounds [100001 x [17 x i32]], ptr @anc, i64 0, i64 %32, i64 13
  store i32 %88, ptr %89, align 4, !tbaa !9
  %90 = sext i32 %88 to i64
  %91 = getelementptr inbounds [100001 x [17 x i32]], ptr @anc, i64 0, i64 %90, i64 13
  %92 = load i32, ptr %91, align 4, !tbaa !9
  %93 = getelementptr inbounds [100001 x [17 x i32]], ptr @anc, i64 0, i64 %32, i64 14
  store i32 %92, ptr %93, align 4, !tbaa !9
  %94 = sext i32 %92 to i64
  %95 = getelementptr inbounds [100001 x [17 x i32]], ptr @anc, i64 0, i64 %94, i64 14
  %96 = load i32, ptr %95, align 4, !tbaa !9
  %97 = getelementptr inbounds [100001 x [17 x i32]], ptr @anc, i64 0, i64 %32, i64 15
  store i32 %96, ptr %97, align 4, !tbaa !9
  %98 = sext i32 %96 to i64
  %99 = getelementptr inbounds [100001 x [17 x i32]], ptr @anc, i64 0, i64 %98, i64 15
  %100 = load i32, ptr %99, align 4, !tbaa !9
  %101 = getelementptr inbounds [100001 x [17 x i32]], ptr @anc, i64 0, i64 %32, i64 16
  store i32 %100, ptr %101, align 4, !tbaa !9
  %102 = sext i32 %31 to i64
  %103 = getelementptr inbounds [100001 x %"struct.std::pair"], ptr @dia, i64 0, i64 %102
  %104 = load i32, ptr %103, align 8, !tbaa !12
  %105 = getelementptr inbounds i8, ptr %103, i64 4
  %106 = load i32, ptr %105, align 4, !tbaa !14
  %107 = call noundef i32 @_Z4distii(i32 noundef %104, i32 noundef %106)
  %108 = load i32, ptr @cur, align 4, !tbaa !9
  %109 = sext i32 %108 to i64
  %110 = getelementptr inbounds [100001 x i32], ptr @comp, i64 0, i64 %109
  %111 = load i32, ptr %110, align 4, !tbaa !9
  %112 = sext i32 %111 to i64
  %113 = getelementptr inbounds [100001 x %"struct.std::pair"], ptr @dia, i64 0, i64 %112
  %114 = load i32, ptr %113, align 8, !tbaa !12
  %115 = call noundef i32 @_Z4distii(i32 noundef %108, i32 noundef %114)
  %116 = icmp sgt i32 %115, %107
  %117 = load i32, ptr @cur, align 4, !tbaa !9
  %118 = sext i32 %117 to i64
  %119 = getelementptr inbounds [100001 x i32], ptr @comp, i64 0, i64 %118
  %120 = load i32, ptr %119, align 4, !tbaa !9
  %121 = sext i32 %120 to i64
  %122 = getelementptr inbounds [100001 x %"struct.std::pair"], ptr @dia, i64 0, i64 %121, i32 1
  br i1 %116, label %123, label %124

123:                                              ; preds = %28
  store i32 %117, ptr %122, align 4, !tbaa !14
  br label %156

124:                                              ; preds = %28
  %125 = load i32, ptr %122, align 4, !tbaa !14
  %126 = call noundef i32 @_Z4distii(i32 noundef %117, i32 noundef %125)
  %127 = icmp sgt i32 %126, %107
  br i1 %127, label %128, label %156

128:                                              ; preds = %124
  %129 = load i32, ptr @cur, align 4, !tbaa !9
  %130 = sext i32 %129 to i64
  %131 = getelementptr inbounds [100001 x i32], ptr @comp, i64 0, i64 %130
  %132 = load i32, ptr %131, align 4, !tbaa !9
  %133 = sext i32 %132 to i64
  %134 = getelementptr inbounds [100001 x %"struct.std::pair"], ptr @dia, i64 0, i64 %133
  store i32 %129, ptr %134, align 8, !tbaa !12
  br label %156

135:                                              ; preds = %.lr.ph
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %4) #6
  %136 = load i32, ptr %2, align 4, !tbaa !9
  %137 = sext i32 %136 to i64
  %138 = getelementptr inbounds [100001 x i32], ptr @comp, i64 0, i64 %137
  %139 = load i32, ptr %138, align 4, !tbaa !9
  %140 = sext i32 %139 to i64
  %141 = getelementptr inbounds [100001 x %"struct.std::pair"], ptr @dia, i64 0, i64 %140
  %142 = load i32, ptr %141, align 8, !tbaa !12
  %143 = call noundef i32 @_Z4distii(i32 noundef %142, i32 noundef %136)
  store i32 %143, ptr %4, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %5) #6
  %144 = load i32, ptr %2, align 4, !tbaa !9
  %145 = sext i32 %144 to i64
  %146 = getelementptr inbounds [100001 x i32], ptr @comp, i64 0, i64 %145
  %147 = load i32, ptr %146, align 4, !tbaa !9
  %148 = sext i32 %147 to i64
  %149 = getelementptr inbounds [100001 x %"struct.std::pair"], ptr @dia, i64 0, i64 %148, i32 1
  %150 = load i32, ptr %149, align 4, !tbaa !14
  %151 = call noundef i32 @_Z4distii(i32 noundef %150, i32 noundef %144)
  store i32 %151, ptr %5, align 4, !tbaa !9
  %152 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %4, ptr noundef nonnull align 4 dereferenceable(4) %5)
  %153 = load i32, ptr %152, align 4, !tbaa !9
  %154 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEi(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, i32 noundef %153)
  %155 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc(ptr noundef nonnull align 8 dereferenceable(8) %154, ptr noundef nonnull @.str.5)
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %5) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %4) #6
  br label %156

156:                                              ; preds = %123, %128, %124, %22, %135
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %2) #6
  call void @llvm.lifetime.end.p0(i64 1, ptr nonnull %1) #6
  %157 = add nuw nsw i32 %.014, 1
  %158 = load i32, ptr @Q, align 4, !tbaa !9
  %159 = icmp slt i32 %157, %158
  br i1 %159, label %.lr.ph, label %._crit_edge, !llvm.loop !15
}

declare ptr @freopen(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #3

declare noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERi(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef nonnull align 4 dereferenceable(4)) local_unnamed_addr #3

declare noundef nonnull align 8 dereferenceable(16) ptr @_ZStrsIcSt11char_traitsIcEERSt13basic_istreamIT_T0_ES6_RS3_(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef nonnull align 1 dereferenceable(1)) local_unnamed_addr #3

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZNSt4pairIiiEC2IRiS2_TnNSt9enable_ifIXaaclsr5_PCCPE22_MoveConstructiblePairIT_T0_EEclsr5_PCCPE30_ImplicitlyMoveConvertiblePairIS4_S5_EEEbE4typeELb1EEEOS4_OS5_(ptr noundef nonnull align 4 dereferenceable(8), ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) unnamed_addr #1 align 2

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

; Function Attrs: inlinehint mustprogress uwtable
declare noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef) local_unnamed_addr #4

declare noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEi(ptr noundef nonnull align 8 dereferenceable(8), i32 noundef) local_unnamed_addr #3

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) local_unnamed_addr #5

attributes #0 = { mustprogress 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 = { mustprogress norecurse 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 = { "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 #4 = { inlinehint 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 #5 = { inlinehint 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 #6 = { 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 = !{!7, !7, i64 0}
!12 = !{!13, !10, i64 0}
!13 = !{!"_ZTSSt4pairIiiE", !10, i64 0, !10, i64 4}
!14 = !{!13, !10, i64 4}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}


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