; LLVM IR from bqi343/cp-notebook :: Contests/USACO Solutions/2014-15/Feb 2015/Feb 2015 Gold (15 Feb G1)

; 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::map" = type { %"class.std::_Rb_tree.0" }
%"class.std::_Rb_tree.0" = type { %"struct.std::_Rb_tree<int, std::pair<const int, int>, std::_Select1st<std::pair<const int, int>>, std::less<int>>::_Rb_tree_impl" }
%"struct.std::_Rb_tree<int, std::pair<const int, int>, std::_Select1st<std::pair<const int, int>>, std::less<int>>::_Rb_tree_impl" = type { [8 x i8], %"struct.std::_Rb_tree_header" }
%"struct.std::_Rb_tree_header" = type { %"struct.std::_Rb_tree_node_base", i64 }
%"struct.std::_Rb_tree_node_base" = type { i32, ptr, ptr, ptr }
%"class.std::vector" = type { %"struct.std::_Vector_base" }
%"struct.std::_Vector_base" = type { %"struct.std::_Vector_base<int, std::allocator<int>>::_Vector_impl" }
%"struct.std::_Vector_base<int, std::allocator<int>>::_Vector_impl" = type { %"struct.std::_Vector_base<int, std::allocator<int>>::_Vector_impl_data" }
%"struct.std::_Vector_base<int, std::allocator<int>>::_Vector_impl_data" = type { ptr, ptr, ptr }
%"class.std::basic_ofstream" = type { %"class.std::basic_ostream.base", %"class.std::basic_filebuf", %"class.std::basic_ios" }
%"class.std::basic_ostream.base" = type { ptr }
%"class.std::basic_filebuf" = type { %"class.std::basic_streambuf", %union.pthread_mutex_t, %"class.std::__basic_file", i32, %struct.__mbstate_t, %struct.__mbstate_t, %struct.__mbstate_t, ptr, i64, i8, i8, i8, i8, ptr, ptr, i8, ptr, ptr, i64, ptr, ptr }
%"class.std::basic_streambuf" = type { ptr, ptr, ptr, ptr, ptr, ptr, ptr, %"class.std::locale" }
%"class.std::locale" = type { ptr }
%union.pthread_mutex_t = type { %struct.__pthread_mutex_s }
%struct.__pthread_mutex_s = type { i32, i32, i32, i32, i32, i16, i16, %struct.__pthread_internal_list }
%struct.__pthread_internal_list = type { ptr, ptr }
%"class.std::__basic_file" = type <{ ptr, i8, [7 x i8] }>
%struct.__mbstate_t = type { i32, %union.anon }
%union.anon = type { i32 }
%"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 }

@R = external dso_local global i32, align 4
@C = external dso_local global i32, align 4
@grid = external dso_local global [750 x [750 x i32]], align 16
@conv = external dso_local global [526501 x %"class.std::map"], align 16
@bit = external dso_local global [526501 x %"class.std::vector"], align 16
@.str.5 = external hidden unnamed_addr constant [14 x i8], align 1

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

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

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

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

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z4initv() #2

declare i32 @__gxx_personality_v0(...)

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

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #3 personality ptr @__gxx_personality_v0 {
  %1 = alloca i32, align 4
  %2 = alloca %"class.std::basic_ofstream", align 8
  %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 i64, align 8
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 512, ptr %2) #4
  call void @_ZNSt14basic_ofstreamIcSt11char_traitsIcEEC1EPKcSt13_Ios_Openmode(ptr noundef nonnull align 8 dereferenceable(248) %2, ptr noundef @.str.5, i32 noundef 16)
  invoke void @_Z4initv()
          to label %9 unwind label %16

9:                                                ; preds = %0
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  %10 = load i32, ptr @R, align 4, !tbaa !5
  %11 = sub nsw i32 %10, 1
  store i32 %11, ptr %5, align 4, !tbaa !5
  br label %12

12:                                               ; preds = %153, %9
  %13 = load i32, ptr %5, align 4, !tbaa !5
  %14 = icmp sge i32 %13, 0
  br i1 %14, label %20, label %15

15:                                               ; preds = %12
  store i32 2, ptr %6, align 4
  br label %156

16:                                               ; preds = %0
  %17 = landingpad { ptr, i32 }
          cleanup
  %18 = extractvalue { ptr, i32 } %17, 0
  store ptr %18, ptr %3, align 8
  %19 = extractvalue { ptr, i32 } %17, 1
  store i32 %19, ptr %4, align 4
  br label %163

20:                                               ; preds = %12
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  store i32 0, ptr %7, align 4, !tbaa !5
  br label %21

21:                                               ; preds = %147, %20
  %22 = load i32, ptr %7, align 4, !tbaa !5
  %23 = load i32, ptr @C, align 4, !tbaa !5
  %24 = icmp slt i32 %22, %23
  br i1 %24, label %26, label %25

25:                                               ; preds = %21
  store i32 5, ptr %6, align 4
  br label %150

26:                                               ; preds = %21
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  store i64 0, ptr %8, align 8, !tbaa !9
  %27 = load i32, ptr %5, align 4, !tbaa !5
  %28 = load i32, ptr @R, align 4, !tbaa !5
  %29 = sub nsw i32 %28, 1
  %30 = icmp eq i32 %27, %29
  br i1 %30, label %31, label %37

31:                                               ; preds = %26
  %32 = load i32, ptr %7, align 4, !tbaa !5
  %33 = load i32, ptr @C, align 4, !tbaa !5
  %34 = sub nsw i32 %33, 1
  %35 = icmp eq i32 %32, %34
  br i1 %35, label %36, label %37

36:                                               ; preds = %31
  store i64 1, ptr %8, align 8, !tbaa !9
  br label %105

37:                                               ; preds = %31, %26
  %38 = load i32, ptr @C, align 4, !tbaa !5
  %39 = sub nsw i32 %38, 1
  %40 = call noundef i32 @_Z5queryii(i32 noundef 0, i32 noundef %39)
  %41 = load i32, ptr %7, align 4, !tbaa !5
  %42 = call noundef i32 @_Z5queryii(i32 noundef 0, i32 noundef %41)
  %43 = sub nsw i32 %40, %42
  %44 = srem i32 %43, 1000000007
  %45 = sext i32 %44 to i64
  store i64 %45, ptr %8, align 8, !tbaa !9
  %46 = load i64, ptr %8, align 8, !tbaa !9
  %47 = load i32, ptr %5, align 4, !tbaa !5
  %48 = sext i32 %47 to i64
  %49 = getelementptr inbounds [750 x [750 x i32]], ptr @grid, i64 0, i64 %48
  %50 = load i32, ptr %7, align 4, !tbaa !5
  %51 = sext i32 %50 to i64
  %52 = getelementptr inbounds [750 x i32], ptr %49, i64 0, i64 %51
  %53 = load i32, ptr %52, align 4, !tbaa !5
  %54 = load i32, ptr %5, align 4, !tbaa !5
  %55 = sext i32 %54 to i64
  %56 = getelementptr inbounds [750 x [750 x i32]], ptr @grid, i64 0, i64 %55
  %57 = load i32, ptr %7, align 4, !tbaa !5
  %58 = sext i32 %57 to i64
  %59 = getelementptr inbounds [750 x i32], ptr %56, i64 0, i64 %58
  %60 = load i32, ptr %59, align 4, !tbaa !5
  %61 = sext i32 %60 to i64
  %62 = getelementptr inbounds [526501 x %"class.std::vector"], ptr @bit, i64 0, i64 %61
  %63 = call noundef i64 @_ZNKSt6vectorIiSaIiEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %62) #4
  %64 = sub i64 %63, 1
  %65 = trunc i64 %64 to i32
  %66 = call noundef i32 @_Z5queryii(i32 noundef %53, i32 noundef %65)
  %67 = sext i32 %66 to i64
  %68 = sub nsw i64 %46, %67
  %69 = srem i64 %68, 1000000007
  store i64 %69, ptr %8, align 8, !tbaa !9
  %70 = load i64, ptr %8, align 8, !tbaa !9
  %71 = load i32, ptr %5, align 4, !tbaa !5
  %72 = sext i32 %71 to i64
  %73 = getelementptr inbounds [750 x [750 x i32]], ptr @grid, i64 0, i64 %72
  %74 = load i32, ptr %7, align 4, !tbaa !5
  %75 = sext i32 %74 to i64
  %76 = getelementptr inbounds [750 x i32], ptr %73, i64 0, i64 %75
  %77 = load i32, ptr %76, align 4, !tbaa !5
  %78 = load i32, ptr %5, align 4, !tbaa !5
  %79 = sext i32 %78 to i64
  %80 = getelementptr inbounds [750 x [750 x i32]], ptr @grid, i64 0, i64 %79
  %81 = load i32, ptr %7, align 4, !tbaa !5
  %82 = sext i32 %81 to i64
  %83 = getelementptr inbounds [750 x i32], ptr %80, i64 0, i64 %82
  %84 = load i32, ptr %83, align 4, !tbaa !5
  %85 = sext i32 %84 to i64
  %86 = getelementptr inbounds [526501 x %"class.std::map"], ptr @conv, i64 0, i64 %85
  %87 = invoke noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt3mapIiiSt4lessIiESaISt4pairIKiiEEEixERS3_(ptr noundef nonnull align 8 dereferenceable(48) %86, ptr noundef nonnull align 4 dereferenceable(4) %7)
          to label %88 unwind label %100

88:                                               ; preds = %37
  %89 = load i32, ptr %87, align 4, !tbaa !5
  %90 = call noundef i32 @_Z5queryii(i32 noundef %77, i32 noundef %89)
  %91 = sext i32 %90 to i64
  %92 = add nsw i64 %70, %91
  %93 = srem i64 %92, 1000000007
  store i64 %93, ptr %8, align 8, !tbaa !9
  br label %94

94:                                               ; preds = %97, %88
  %95 = load i64, ptr %8, align 8, !tbaa !9
  %96 = icmp slt i64 %95, 0
  br i1 %96, label %97, label %104

97:                                               ; preds = %94
  %98 = load i64, ptr %8, align 8, !tbaa !9
  %99 = add nsw i64 %98, 1000000007
  store i64 %99, ptr %8, align 8, !tbaa !9
  br label %94, !llvm.loop !11

100:                                              ; preds = %139, %108, %37
  %101 = landingpad { ptr, i32 }
          cleanup
  %102 = extractvalue { ptr, i32 } %101, 0
  store ptr %102, ptr %3, align 8
  %103 = extractvalue { ptr, i32 } %101, 1
  store i32 %103, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  br label %163

104:                                              ; preds = %94
  br label %105

105:                                              ; preds = %104, %36
  %106 = load i32, ptr %7, align 4, !tbaa !5
  %107 = icmp ne i32 %106, 0
  br i1 %107, label %108, label %133

108:                                              ; preds = %105
  %109 = load i32, ptr %5, align 4, !tbaa !5
  %110 = sext i32 %109 to i64
  %111 = getelementptr inbounds [750 x [750 x i32]], ptr @grid, i64 0, i64 %110
  %112 = load i32, ptr %7, align 4, !tbaa !5
  %113 = sext i32 %112 to i64
  %114 = getelementptr inbounds [750 x i32], ptr %111, i64 0, i64 %113
  %115 = load i32, ptr %114, align 4, !tbaa !5
  %116 = load i32, ptr %5, align 4, !tbaa !5
  %117 = sext i32 %116 to i64
  %118 = getelementptr inbounds [750 x [750 x i32]], ptr @grid, i64 0, i64 %117
  %119 = load i32, ptr %7, align 4, !tbaa !5
  %120 = sext i32 %119 to i64
  %121 = getelementptr inbounds [750 x i32], ptr %118, i64 0, i64 %120
  %122 = load i32, ptr %121, align 4, !tbaa !5
  %123 = sext i32 %122 to i64
  %124 = getelementptr inbounds [526501 x %"class.std::map"], ptr @conv, i64 0, i64 %123
  %125 = invoke noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt3mapIiiSt4lessIiESaISt4pairIKiiEEEixERS3_(ptr noundef nonnull align 8 dereferenceable(48) %124, ptr noundef nonnull align 4 dereferenceable(4) %7)
          to label %126 unwind label %100

126:                                              ; preds = %108
  %127 = load i32, ptr %125, align 4, !tbaa !5
  %128 = load i64, ptr %8, align 8, !tbaa !9
  %129 = trunc i64 %128 to i32
  call void @_Z6updateiii(i32 noundef %115, i32 noundef %127, i32 noundef %129)
  %130 = load i32, ptr %7, align 4, !tbaa !5
  %131 = load i64, ptr %8, align 8, !tbaa !9
  %132 = trunc i64 %131 to i32
  call void @_Z6updateiii(i32 noundef 0, i32 noundef %130, i32 noundef %132)
  br label %133

133:                                              ; preds = %126, %105
  %134 = load i32, ptr %5, align 4, !tbaa !5
  %135 = icmp eq i32 %134, 0
  br i1 %135, label %136, label %143

136:                                              ; preds = %133
  %137 = load i32, ptr %7, align 4, !tbaa !5
  %138 = icmp eq i32 %137, 0
  br i1 %138, label %139, label %143

139:                                              ; preds = %136
  %140 = load i64, ptr %8, align 8, !tbaa !9
  %141 = invoke noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEx(ptr noundef nonnull align 8 dereferenceable(8) %2, i64 noundef %140)
          to label %142 unwind label %100

142:                                              ; preds = %139
  store i32 0, ptr %1, align 4
  store i32 1, ptr %6, align 4
  br label %144

143:                                              ; preds = %136, %133
  store i32 0, ptr %6, align 4
  br label %144

144:                                              ; preds = %143, %142
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  %145 = load i32, ptr %6, align 4
  switch i32 %145, label %150 [
    i32 0, label %146
  ]

146:                                              ; preds = %144
  br label %147

147:                                              ; preds = %146
  %148 = load i32, ptr %7, align 4, !tbaa !5
  %149 = add nsw i32 %148, 1
  store i32 %149, ptr %7, align 4, !tbaa !5
  br label %21, !llvm.loop !13

150:                                              ; preds = %144, %25
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  %151 = load i32, ptr %6, align 4
  switch i32 %151, label %156 [
    i32 5, label %152
  ]

152:                                              ; preds = %150
  br label %153

153:                                              ; preds = %152
  %154 = load i32, ptr %5, align 4, !tbaa !5
  %155 = add nsw i32 %154, -1
  store i32 %155, ptr %5, align 4, !tbaa !5
  br label %12, !llvm.loop !14

156:                                              ; preds = %150, %15
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  %157 = load i32, ptr %6, align 4
  switch i32 %157, label %159 [
    i32 2, label %158
  ]

158:                                              ; preds = %156
  store i32 0, ptr %6, align 4
  br label %159

159:                                              ; preds = %158, %156
  call void @_ZNSt14basic_ofstreamIcSt11char_traitsIcEED1Ev(ptr noundef nonnull align 8 dereferenceable(248) %2) #4
  call void @llvm.lifetime.end.p0(i64 512, ptr %2) #4
  %160 = load i32, ptr %6, align 4
  switch i32 %160, label %169 [
    i32 0, label %161
    i32 1, label %161
  ]

161:                                              ; preds = %159, %159
  %162 = load i32, ptr %1, align 4
  ret i32 %162

163:                                              ; preds = %100, %16
  call void @_ZNSt14basic_ofstreamIcSt11char_traitsIcEED1Ev(ptr noundef nonnull align 8 dereferenceable(248) %2) #4
  call void @llvm.lifetime.end.p0(i64 512, ptr %2) #4
  br label %164

164:                                              ; preds = %163
  %165 = load ptr, ptr %3, align 8
  %166 = load i32, ptr %4, align 4
  %167 = insertvalue { ptr, i32 } poison, ptr %165, 0
  %168 = insertvalue { ptr, i32 } %167, i32 %166, 1
  resume { ptr, i32 } %168

169:                                              ; preds = %159
  unreachable
}

; Function Attrs: mustprogress uwtable
declare void @_ZNSt14basic_ofstreamIcSt11char_traitsIcEEC1EPKcSt13_Ios_Openmode(ptr noundef nonnull align 8 dereferenceable(248), ptr noundef, i32 noundef) unnamed_addr #2 align 2

; Function Attrs: mustprogress uwtable
declare noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEx(ptr noundef nonnull align 8 dereferenceable(8), i64 noundef) #2 align 2

; Function Attrs: mustprogress nounwind uwtable
declare void @_ZNSt14basic_ofstreamIcSt11char_traitsIcEED1Ev(ptr noundef nonnull align 8 dereferenceable(248)) 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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #3 = { 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 #4 = { 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, !10, i64 0}
!10 = !{!"long long", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}
!14 = distinct !{!14, !12}


; 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::map" = type { %"class.std::_Rb_tree.0" }
%"class.std::_Rb_tree.0" = type { %"struct.std::_Rb_tree<int, std::pair<const int, int>, std::_Select1st<std::pair<const int, int>>, std::less<int>>::_Rb_tree_impl" }
%"struct.std::_Rb_tree<int, std::pair<const int, int>, std::_Select1st<std::pair<const int, int>>, std::less<int>>::_Rb_tree_impl" = type { [8 x i8], %"struct.std::_Rb_tree_header" }
%"struct.std::_Rb_tree_header" = type { %"struct.std::_Rb_tree_node_base", i64 }
%"struct.std::_Rb_tree_node_base" = type { i32, ptr, ptr, ptr }
%"class.std::vector" = type { %"struct.std::_Vector_base" }
%"struct.std::_Vector_base" = type { %"struct.std::_Vector_base<int, std::allocator<int>>::_Vector_impl" }
%"struct.std::_Vector_base<int, std::allocator<int>>::_Vector_impl" = type { %"struct.std::_Vector_base<int, std::allocator<int>>::_Vector_impl_data" }
%"struct.std::_Vector_base<int, std::allocator<int>>::_Vector_impl_data" = type { ptr, ptr, ptr }
%"class.std::basic_ofstream" = type { %"class.std::basic_ostream.base", %"class.std::basic_filebuf", %"class.std::basic_ios" }
%"class.std::basic_ostream.base" = type { ptr }
%"class.std::basic_filebuf" = type { %"class.std::basic_streambuf", %union.pthread_mutex_t, %"class.std::__basic_file", i32, %struct.__mbstate_t, %struct.__mbstate_t, %struct.__mbstate_t, ptr, i64, i8, i8, i8, i8, ptr, ptr, i8, ptr, ptr, i64, ptr, ptr }
%"class.std::basic_streambuf" = type { ptr, ptr, ptr, ptr, ptr, ptr, ptr, %"class.std::locale" }
%"class.std::locale" = type { ptr }
%union.pthread_mutex_t = type { %struct.__pthread_mutex_s }
%struct.__pthread_mutex_s = type { i32, i32, i32, i32, i32, i16, i16, %struct.__pthread_internal_list }
%struct.__pthread_internal_list = type { ptr, ptr }
%"class.std::__basic_file" = type <{ ptr, i8, [7 x i8] }>
%struct.__mbstate_t = type { i32, %union.anon }
%union.anon = type { i32 }
%"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 }

@R = external dso_local local_unnamed_addr global i32, align 4
@C = external dso_local local_unnamed_addr global i32, align 4
@grid = external dso_local local_unnamed_addr global [750 x [750 x i32]], align 16
@conv = external dso_local global [526501 x %"class.std::map"], align 16
@bit = external dso_local global [526501 x %"class.std::vector"], align 16
@.str.5 = external hidden unnamed_addr constant [14 x i8], align 1

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

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

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

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

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z4initv() local_unnamed_addr #2

declare i32 @__gxx_personality_v0(...)

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

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() local_unnamed_addr #3 personality ptr @__gxx_personality_v0 {
  %1 = alloca %"class.std::basic_ofstream", align 8
  %2 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 512, ptr nonnull %1) #5
  call void @_ZNSt14basic_ofstreamIcSt11char_traitsIcEEC1EPKcSt13_Ios_Openmode(ptr noundef nonnull align 8 dereferenceable(248) %1, ptr noundef nonnull @.str.5, i32 noundef 16)
  invoke void @_Z4initv()
          to label %3 unwind label %9

3:                                                ; preds = %0
  %4 = load i32, ptr @R, align 4, !tbaa !5
  %5 = icmp sgt i32 %4, 0
  br i1 %5, label %.lr.ph51, label %.loopexit44

.lr.ph51:                                         ; preds = %3
  %6 = load i32, ptr @C, align 4, !tbaa !5
  %7 = icmp sgt i32 %6, 0
  br i1 %7, label %.lr.ph51.split.preheader, label %.loopexit44

.lr.ph51.split.preheader:                         ; preds = %.lr.ph51
  %.02747 = add nsw i32 %4, -1
  %8 = zext nneg i32 %.02747 to i64
  br label %.lr.ph51.split

9:                                                ; preds = %0
  %10 = landingpad { ptr, i32 }
          cleanup
  br label %81

.lr.ph51.split:                                   ; preds = %.lr.ph51.split.preheader, %._crit_edge
  %11 = phi i32 [ %6, %.lr.ph51.split.preheader ], [ %78, %._crit_edge ]
  %indvars.iv = phi i64 [ %8, %.lr.ph51.split.preheader ], [ %indvars.iv.next, %._crit_edge ]
  %.027.in48 = phi i32 [ %4, %.lr.ph51.split.preheader ], [ %80, %._crit_edge ]
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %2) #5
  store i32 0, ptr %2, align 4, !tbaa !5
  %.not3945 = icmp sgt i32 %11, 0
  br i1 %.not3945, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %.lr.ph51.split
  %12 = icmp ne i64 %indvars.iv, 0
  br label %13

13:                                               ; preds = %.lr.ph, %.critedge
  %14 = phi i32 [ %11, %.lr.ph ], [ %76, %.critedge ]
  %storemerge46 = phi i32 [ 0, %.lr.ph ], [ %75, %.critedge ]
  %15 = load i32, ptr @R, align 4, !tbaa !5
  %16 = icmp eq i32 %.027.in48, %15
  %17 = add nsw i32 %14, -1
  %18 = icmp eq i32 %storemerge46, %17
  %or.cond = select i1 %16, i1 %18, i1 false
  br i1 %or.cond, label %.loopexit, label %19

19:                                               ; preds = %13
  %20 = call noundef i32 @_Z5queryii(i32 noundef 0, i32 noundef %17)
  %21 = load i32, ptr %2, align 4, !tbaa !5
  %22 = call noundef i32 @_Z5queryii(i32 noundef 0, i32 noundef %21)
  %23 = load i32, ptr %2, align 4, !tbaa !5
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds [750 x [750 x i32]], ptr @grid, i64 0, i64 %indvars.iv, i64 %24
  %26 = load i32, ptr %25, align 4, !tbaa !5
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds [526501 x %"class.std::vector"], ptr @bit, i64 0, i64 %27
  %29 = call noundef i64 @_ZNKSt6vectorIiSaIiEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %28) #5
  %30 = trunc i64 %29 to i32
  %31 = add i32 %30, -1
  %32 = call noundef i32 @_Z5queryii(i32 noundef %26, i32 noundef %31)
  %33 = load i32, ptr %2, align 4, !tbaa !5
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds [750 x [750 x i32]], ptr @grid, i64 0, i64 %indvars.iv, i64 %34
  %36 = load i32, ptr %35, align 4, !tbaa !5
  %37 = sext i32 %36 to i64
  %38 = getelementptr inbounds [526501 x %"class.std::map"], ptr @conv, i64 0, i64 %37
  %39 = invoke noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt3mapIiiSt4lessIiESaISt4pairIKiiEEEixERS3_(ptr noundef nonnull align 8 dereferenceable(48) %38, ptr noundef nonnull align 4 dereferenceable(4) %2)
          to label %.loopexit.loopexit unwind label %.loopexit43

.loopexit.loopexit:                               ; preds = %19
  %40 = sub nsw i32 %20, %22
  %41 = srem i32 %40, 1000000007
  %42 = sext i32 %41 to i64
  %43 = sext i32 %32 to i64
  %44 = sub nsw i64 %42, %43
  %45 = srem i64 %44, 1000000007
  %46 = load i32, ptr %39, align 4, !tbaa !5
  %47 = call noundef i32 @_Z5queryii(i32 noundef %36, i32 noundef %46)
  %48 = sext i32 %47 to i64
  %49 = add nsw i64 %45, %48
  %50 = srem i64 %49, 1000000007
  %smax = call i64 @llvm.smax.i64(i64 %50, i64 0)
  %.lobit = lshr i64 %50, 63
  %51 = add nsw i64 %50, %.lobit
  %52 = sub nsw i64 %smax, %51
  %53 = udiv i64 %52, 1000000007
  %54 = add nuw nsw i64 %.lobit, %53
  %55 = mul i64 %54, 1000000007
  %56 = add i64 %50, %55
  %.pre = load i32, ptr %2, align 4
  br label %.loopexit

.loopexit43:                                      ; preds = %19, %59
  %lpad.loopexit = landingpad { ptr, i32 }
          cleanup
  br label %57

.loopexit.split-lp:                               ; preds = %73
  %lpad.loopexit.split-lp = landingpad { ptr, i32 }
          cleanup
  br label %57

57:                                               ; preds = %.loopexit.split-lp, %.loopexit43
  %lpad.phi = phi { ptr, i32 } [ %lpad.loopexit, %.loopexit43 ], [ %lpad.loopexit.split-lp, %.loopexit.split-lp ]
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %2) #5
  br label %81

.loopexit:                                        ; preds = %.loopexit.loopexit, %13
  %58 = phi i32 [ %storemerge46, %13 ], [ %.pre, %.loopexit.loopexit ]
  %.1 = phi i64 [ 1, %13 ], [ %56, %.loopexit.loopexit ]
  %.not = icmp eq i32 %58, 0
  br i1 %.not, label %70, label %59

59:                                               ; preds = %.loopexit
  %60 = sext i32 %58 to i64
  %61 = getelementptr inbounds [750 x [750 x i32]], ptr @grid, i64 0, i64 %indvars.iv, i64 %60
  %62 = load i32, ptr %61, align 4, !tbaa !5
  %63 = sext i32 %62 to i64
  %64 = getelementptr inbounds [526501 x %"class.std::map"], ptr @conv, i64 0, i64 %63
  %65 = invoke noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt3mapIiiSt4lessIiESaISt4pairIKiiEEEixERS3_(ptr noundef nonnull align 8 dereferenceable(48) %64, ptr noundef nonnull align 4 dereferenceable(4) %2)
          to label %66 unwind label %.loopexit43

66:                                               ; preds = %59
  %67 = load i32, ptr %65, align 4, !tbaa !5
  %68 = trunc nuw nsw i64 %.1 to i32
  call void @_Z6updateiii(i32 noundef %62, i32 noundef %67, i32 noundef %68)
  %69 = load i32, ptr %2, align 4, !tbaa !5
  call void @_Z6updateiii(i32 noundef 0, i32 noundef %69, i32 noundef %68)
  %.pre55 = load i32, ptr %2, align 4
  br label %70

70:                                               ; preds = %66, %.loopexit
  %71 = phi i32 [ %.pre55, %66 ], [ 0, %.loopexit ]
  %72 = icmp ne i32 %71, 0
  %or.cond.not = select i1 %12, i1 true, i1 %72
  br i1 %or.cond.not, label %.critedge, label %73

73:                                               ; preds = %70
  %74 = invoke noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEx(ptr noundef nonnull align 8 dereferenceable(8) %1, i64 noundef %.1)
          to label %77 unwind label %.loopexit.split-lp

.critedge:                                        ; preds = %70
  %75 = add nsw i32 %71, 1
  store i32 %75, ptr %2, align 4, !tbaa !5
  %76 = load i32, ptr @C, align 4, !tbaa !5
  %.not39 = icmp slt i32 %75, %76
  br i1 %.not39, label %13, label %._crit_edge, !llvm.loop !9

77:                                               ; preds = %73
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %2) #5
  br label %.loopexit44

._crit_edge:                                      ; preds = %.critedge, %.lr.ph51.split
  %78 = phi i32 [ %11, %.lr.ph51.split ], [ %76, %.critedge ]
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %2) #5
  %indvars.iv.next = add nsw i64 %indvars.iv, -1
  %79 = icmp sgt i64 %indvars.iv, 0
  %80 = trunc nuw nsw i64 %indvars.iv to i32
  br i1 %79, label %.lr.ph51.split, label %.loopexit44, !llvm.loop !11

.loopexit44:                                      ; preds = %._crit_edge, %.lr.ph51, %3, %77
  call void @_ZNSt14basic_ofstreamIcSt11char_traitsIcEED1Ev(ptr noundef nonnull align 8 dereferenceable(248) %1) #5
  call void @llvm.lifetime.end.p0(i64 512, ptr nonnull %1) #5
  ret i32 0

81:                                               ; preds = %57, %9
  %.pn = phi { ptr, i32 } [ %lpad.phi, %57 ], [ %10, %9 ]
  call void @_ZNSt14basic_ofstreamIcSt11char_traitsIcEED1Ev(ptr noundef nonnull align 8 dereferenceable(248) %1) #5
  call void @llvm.lifetime.end.p0(i64 512, ptr nonnull %1) #5
  resume { ptr, i32 } %.pn
}

; Function Attrs: mustprogress uwtable
declare void @_ZNSt14basic_ofstreamIcSt11char_traitsIcEEC1EPKcSt13_Ios_Openmode(ptr noundef nonnull align 8 dereferenceable(248), ptr noundef, i32 noundef) unnamed_addr #2 align 2

; Function Attrs: mustprogress uwtable
declare noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEx(ptr noundef nonnull align 8 dereferenceable(8), i64 noundef) local_unnamed_addr #2 align 2

; Function Attrs: mustprogress nounwind uwtable
declare void @_ZNSt14basic_ofstreamIcSt11char_traitsIcEED1Ev(ptr noundef nonnull align 8 dereferenceable(248)) unnamed_addr #0 align 2

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

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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #3 = { 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 #4 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #5 = { 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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10, !12}
!12 = !{!"llvm.loop.unswitch.partial.disable"}


; Effective O3 passes: CorrelatedValuePropagationPass,DSEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopInstSimplifyPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SCCPPass,SROAPass,SimpleLoopUnswitchPass,SimplifyCFGPass