; LLVM IR from Tunghohin/Competitive_Coding :: Codeforces/cf1679_B.ll (Z5solvev)

; 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::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" }
%"class.std::map" = type { %"class.std::_Rb_tree" }
%"class.std::_Rb_tree" = type { %"struct.std::_Rb_tree<long long, std::pair<const long long, long long>, std::_Select1st<std::pair<const long long, long long>>, std::less<long long>>::_Rb_tree_impl" }
%"struct.std::_Rb_tree<long long, std::pair<const long long, long long>, std::_Select1st<std::pair<const long long, long long>>, std::less<long long>>::_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 }

@n = external dso_local global i32, align 4
@q = external dso_local global i32, align 4
@_ZSt3cin = external global %"class.std::basic_istream", align 8
@_ZSt4cout = external global %"class.std::basic_ostream", align 8

; Function Attrs: mustprogress uwtable
define dso_local void @_Z5solvev() #0 personality ptr @__gxx_personality_v0 {
  %1 = alloca %"class.std::map", align 8
  %2 = alloca i64, align 8
  %3 = alloca i64, align 8
  %4 = alloca i32, align 4
  %5 = alloca i64, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i64, align 8
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i64, align 8
  %12 = alloca i32, align 4
  %13 = alloca i64, align 8
  %14 = alloca i64, align 8
  %15 = alloca i64, align 8
  %16 = alloca i64, align 8
  %17 = alloca i64, align 8
  %18 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERi(ptr noundef nonnull align 8 dereferenceable(16) @_ZSt3cin, ptr noundef nonnull align 4 dereferenceable(4) @n)
  %19 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERi(ptr noundef nonnull align 8 dereferenceable(16) %18, ptr noundef nonnull align 4 dereferenceable(4) @q)
  call void @llvm.lifetime.start.p0(i64 48, ptr %1) #5
  call void @_ZNSt3mapIxxSt4lessIxESaISt4pairIKxxEEEC2Ev(ptr noundef nonnull align 8 dereferenceable(48) %1) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #5
  store i64 0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #5
  store i64 0, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #5
  store i32 1, ptr %4, align 4, !tbaa !9
  br label %20

20:                                               ; preds = %36, %0
  %21 = load i32, ptr %4, align 4, !tbaa !9
  %22 = load i32, ptr @n, align 4, !tbaa !9
  %23 = icmp sle i32 %21, %22
  br i1 %23, label %25, label %24

24:                                               ; preds = %20
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #5
  br label %48

25:                                               ; preds = %20
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #5
  %26 = invoke noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERx(ptr noundef nonnull align 8 dereferenceable(16) @_ZSt3cin, ptr noundef nonnull align 8 dereferenceable(8) %5)
          to label %27 unwind label %39

27:                                               ; preds = %25
  %28 = load i64, ptr %5, align 8, !tbaa !5
  %29 = load i64, ptr %2, align 8, !tbaa !5
  %30 = add nsw i64 %29, %28
  store i64 %30, ptr %2, align 8, !tbaa !5
  %31 = load i64, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #5
  %32 = load i32, ptr %4, align 4, !tbaa !9
  %33 = sext i32 %32 to i64
  store i64 %33, ptr %8, align 8, !tbaa !5
  %34 = invoke noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt3mapIxxSt4lessIxESaISt4pairIKxxEEEixEOx(ptr noundef nonnull align 8 dereferenceable(48) %1, ptr noundef nonnull align 8 dereferenceable(8) %8)
          to label %35 unwind label %43

35:                                               ; preds = %27
  store i64 %31, ptr %34, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #5
  br label %36

36:                                               ; preds = %35
  %37 = load i32, ptr %4, align 4, !tbaa !9
  %38 = add nsw i32 %37, 1
  store i32 %38, ptr %4, align 4, !tbaa !9
  br label %20, !llvm.loop !11

39:                                               ; preds = %25
  %40 = landingpad { ptr, i32 }
          cleanup
  %41 = extractvalue { ptr, i32 } %40, 0
  store ptr %41, ptr %6, align 8
  %42 = extractvalue { ptr, i32 } %40, 1
  store i32 %42, ptr %7, align 4
  br label %47

43:                                               ; preds = %27
  %44 = landingpad { ptr, i32 }
          cleanup
  %45 = extractvalue { ptr, i32 } %44, 0
  store ptr %45, ptr %6, align 8
  %46 = extractvalue { ptr, i32 } %44, 1
  store i32 %46, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #5
  br label %47

47:                                               ; preds = %43, %39
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #5
  br label %145

48:                                               ; preds = %24
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #5
  store i32 1, ptr %9, align 4, !tbaa !9
  br label %49

49:                                               ; preds = %140, %48
  %50 = load i32, ptr %9, align 4, !tbaa !9
  %51 = load i32, ptr @q, align 4, !tbaa !9
  %52 = icmp sle i32 %50, %51
  br i1 %52, label %54, label %53

53:                                               ; preds = %49
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #5
  br label %144

54:                                               ; preds = %49
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #5
  %55 = invoke noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERi(ptr noundef nonnull align 8 dereferenceable(16) @_ZSt3cin, ptr noundef nonnull align 4 dereferenceable(4) %10)
          to label %56 unwind label %67

56:                                               ; preds = %54
  %57 = load i32, ptr %10, align 4, !tbaa !9
  %58 = icmp eq i32 %57, 2
  br i1 %58, label %59, label %75

59:                                               ; preds = %56
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #5
  %60 = invoke noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERx(ptr noundef nonnull align 8 dereferenceable(16) @_ZSt3cin, ptr noundef nonnull align 8 dereferenceable(8) %11)
          to label %61 unwind label %71

61:                                               ; preds = %59
  call void @_ZNSt3mapIxxSt4lessIxESaISt4pairIKxxEEE5clearEv(ptr noundef nonnull align 8 dereferenceable(48) %1) #5
  %62 = load i64, ptr %11, align 8, !tbaa !5
  %63 = load i32, ptr @n, align 4, !tbaa !9
  %64 = sext i32 %63 to i64
  %65 = mul nsw i64 %62, %64
  store i64 %65, ptr %2, align 8, !tbaa !5
  %66 = load i64, ptr %11, align 8, !tbaa !5
  store i64 %66, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #5
  br label %134

67:                                               ; preds = %137, %134, %54
  %68 = landingpad { ptr, i32 }
          cleanup
  %69 = extractvalue { ptr, i32 } %68, 0
  store ptr %69, ptr %6, align 8
  %70 = extractvalue { ptr, i32 } %68, 1
  store i32 %70, ptr %7, align 4
  br label %143

71:                                               ; preds = %59
  %72 = landingpad { ptr, i32 }
          cleanup
  %73 = extractvalue { ptr, i32 } %72, 0
  store ptr %73, ptr %6, align 8
  %74 = extractvalue { ptr, i32 } %72, 1
  store i32 %74, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #5
  br label %143

75:                                               ; preds = %56
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #5
  %76 = invoke noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERi(ptr noundef nonnull align 8 dereferenceable(16) @_ZSt3cin, ptr noundef nonnull align 4 dereferenceable(4) %12)
          to label %77 unwind label %101

77:                                               ; preds = %75
  %78 = invoke noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERx(ptr noundef nonnull align 8 dereferenceable(16) %76, ptr noundef nonnull align 8 dereferenceable(8) %13)
          to label %79 unwind label %101

79:                                               ; preds = %77
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #5
  %80 = load i32, ptr %12, align 4, !tbaa !9
  %81 = sext i32 %80 to i64
  store i64 %81, ptr %14, align 8, !tbaa !5
  %82 = invoke noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt3mapIxxSt4lessIxESaISt4pairIKxxEEEixEOx(ptr noundef nonnull align 8 dereferenceable(48) %1, ptr noundef nonnull align 8 dereferenceable(8) %14)
          to label %83 unwind label %105

83:                                               ; preds = %79
  %84 = load i64, ptr %82, align 8, !tbaa !5
  %85 = icmp ne i64 %84, 0
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #5
  br i1 %85, label %86, label %117

86:                                               ; preds = %83
  %87 = load i64, ptr %13, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #5
  %88 = load i32, ptr %12, align 4, !tbaa !9
  %89 = sext i32 %88 to i64
  store i64 %89, ptr %15, align 8, !tbaa !5
  %90 = invoke noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt3mapIxxSt4lessIxESaISt4pairIKxxEEEixEOx(ptr noundef nonnull align 8 dereferenceable(48) %1, ptr noundef nonnull align 8 dereferenceable(8) %15)
          to label %91 unwind label %109

91:                                               ; preds = %86
  %92 = load i64, ptr %90, align 8, !tbaa !5
  %93 = sub nsw i64 %87, %92
  %94 = load i64, ptr %2, align 8, !tbaa !5
  %95 = add nsw i64 %94, %93
  store i64 %95, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #5
  %96 = load i64, ptr %13, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #5
  %97 = load i32, ptr %12, align 4, !tbaa !9
  %98 = sext i32 %97 to i64
  store i64 %98, ptr %16, align 8, !tbaa !5
  %99 = invoke noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt3mapIxxSt4lessIxESaISt4pairIKxxEEEixEOx(ptr noundef nonnull align 8 dereferenceable(48) %1, ptr noundef nonnull align 8 dereferenceable(8) %16)
          to label %100 unwind label %113

100:                                              ; preds = %91
  store i64 %96, ptr %99, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #5
  br label %132

101:                                              ; preds = %77, %75
  %102 = landingpad { ptr, i32 }
          cleanup
  %103 = extractvalue { ptr, i32 } %102, 0
  store ptr %103, ptr %6, align 8
  %104 = extractvalue { ptr, i32 } %102, 1
  store i32 %104, ptr %7, align 4
  br label %133

105:                                              ; preds = %79
  %106 = landingpad { ptr, i32 }
          cleanup
  %107 = extractvalue { ptr, i32 } %106, 0
  store ptr %107, ptr %6, align 8
  %108 = extractvalue { ptr, i32 } %106, 1
  store i32 %108, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #5
  br label %133

109:                                              ; preds = %86
  %110 = landingpad { ptr, i32 }
          cleanup
  %111 = extractvalue { ptr, i32 } %110, 0
  store ptr %111, ptr %6, align 8
  %112 = extractvalue { ptr, i32 } %110, 1
  store i32 %112, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #5
  br label %133

113:                                              ; preds = %91
  %114 = landingpad { ptr, i32 }
          cleanup
  %115 = extractvalue { ptr, i32 } %114, 0
  store ptr %115, ptr %6, align 8
  %116 = extractvalue { ptr, i32 } %114, 1
  store i32 %116, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #5
  br label %133

117:                                              ; preds = %83
  %118 = load i64, ptr %13, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %17) #5
  %119 = load i32, ptr %12, align 4, !tbaa !9
  %120 = sext i32 %119 to i64
  store i64 %120, ptr %17, align 8, !tbaa !5
  %121 = invoke noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt3mapIxxSt4lessIxESaISt4pairIKxxEEEixEOx(ptr noundef nonnull align 8 dereferenceable(48) %1, ptr noundef nonnull align 8 dereferenceable(8) %17)
          to label %122 unwind label %128

122:                                              ; preds = %117
  store i64 %118, ptr %121, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %17) #5
  %123 = load i64, ptr %13, align 8, !tbaa !5
  %124 = load i64, ptr %3, align 8, !tbaa !5
  %125 = sub nsw i64 %123, %124
  %126 = load i64, ptr %2, align 8, !tbaa !5
  %127 = add nsw i64 %126, %125
  store i64 %127, ptr %2, align 8, !tbaa !5
  br label %132

128:                                              ; preds = %117
  %129 = landingpad { ptr, i32 }
          cleanup
  %130 = extractvalue { ptr, i32 } %129, 0
  store ptr %130, ptr %6, align 8
  %131 = extractvalue { ptr, i32 } %129, 1
  store i32 %131, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %17) #5
  br label %133

132:                                              ; preds = %122, %100
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #5
  br label %134

133:                                              ; preds = %128, %113, %109, %105, %101
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #5
  br label %143

134:                                              ; preds = %132, %61
  %135 = load i64, ptr %2, align 8, !tbaa !5
  %136 = invoke noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEx(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, i64 noundef %135)
          to label %137 unwind label %67

137:                                              ; preds = %134
  %138 = invoke noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_c(ptr noundef nonnull align 8 dereferenceable(8) %136, i8 noundef signext 10)
          to label %139 unwind label %67

139:                                              ; preds = %137
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #5
  br label %140

140:                                              ; preds = %139
  %141 = load i32, ptr %9, align 4, !tbaa !9
  %142 = add nsw i32 %141, 1
  store i32 %142, ptr %9, align 4, !tbaa !9
  br label %49, !llvm.loop !13

143:                                              ; preds = %133, %71, %67
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #5
  br label %145

144:                                              ; preds = %53
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #5
  call void @_ZNSt3mapIxxSt4lessIxESaISt4pairIKxxEEED2Ev(ptr noundef nonnull align 8 dereferenceable(48) %1) #5
  call void @llvm.lifetime.end.p0(i64 48, ptr %1) #5
  ret void

145:                                              ; preds = %143, %47
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #5
  call void @_ZNSt3mapIxxSt4lessIxESaISt4pairIKxxEEED2Ev(ptr noundef nonnull align 8 dereferenceable(48) %1) #5
  call void @llvm.lifetime.end.p0(i64 48, ptr %1) #5
  br label %146

146:                                              ; preds = %145
  %147 = load ptr, ptr %6, align 8
  %148 = load i32, ptr %7, align 4
  %149 = insertvalue { ptr, i32 } poison, ptr %147, 0
  %150 = insertvalue { ptr, i32 } %149, i32 %148, 1
  resume { ptr, i32 } %150
}

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

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZNSt3mapIxxSt4lessIxESaISt4pairIKxxEEEC2Ev(ptr noundef nonnull align 8 dereferenceable(48)) unnamed_addr #3 align 2

; Function Attrs: mustprogress uwtable
declare noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERx(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef nonnull align 8 dereferenceable(8)) #0 align 2

declare i32 @__gxx_personality_v0(...)

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

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZNSt3mapIxxSt4lessIxESaISt4pairIKxxEEE5clearEv(ptr noundef nonnull align 8 dereferenceable(48)) #3 align 2

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

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZNSt3mapIxxSt4lessIxESaISt4pairIKxxEEED2Ev(ptr noundef nonnull align 8 dereferenceable(48)) unnamed_addr #3 align 2

attributes #0 = { mustprogress uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #1 = { "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #2 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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 #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 = { nounwind }

!llvm.module.flags = !{!0, !1, !2, !3}
!llvm.ident = !{!4}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 2}
!4 = !{!"clang version 19.1.0 (git@github.com:llvm/llvm-project.git a4bf6cd7cfb1a1421ba92bca9d017b49936c55e4)"}
!5 = !{!6, !6, i64 0}
!6 = !{!"long long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !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::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" }
%"class.std::map" = type { %"class.std::_Rb_tree" }
%"class.std::_Rb_tree" = type { %"struct.std::_Rb_tree<long long, std::pair<const long long, long long>, std::_Select1st<std::pair<const long long, long long>>, std::less<long long>>::_Rb_tree_impl" }
%"struct.std::_Rb_tree<long long, std::pair<const long long, long long>, std::_Select1st<std::pair<const long long, long long>>, std::less<long long>>::_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 }

@n = external dso_local global i32, align 4
@q = external dso_local global i32, align 4
@_ZSt3cin = external global %"class.std::basic_istream", align 8
@_ZSt4cout = external global %"class.std::basic_ostream", align 8

; Function Attrs: mustprogress uwtable
define dso_local void @_Z5solvev() local_unnamed_addr #0 personality ptr @__gxx_personality_v0 {
  %1 = alloca %"class.std::map", align 8
  %2 = alloca i64, align 8
  %3 = alloca i64, align 8
  %4 = alloca i32, align 4
  %5 = alloca i64, align 8
  %6 = alloca i32, align 4
  %7 = alloca i64, align 8
  %8 = alloca i64, align 8
  %9 = alloca i64, align 8
  %10 = alloca i64, align 8
  %11 = alloca i64, align 8
  %12 = 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) @n)
  %13 = tail call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERi(ptr noundef nonnull align 8 dereferenceable(16) %12, ptr noundef nonnull align 4 dereferenceable(4) @q)
  call void @llvm.lifetime.start.p0(i64 48, ptr nonnull %1) #5
  call void @_ZNSt3mapIxxSt4lessIxESaISt4pairIKxxEEEC2Ev(ptr noundef nonnull align 8 dereferenceable(48) %1) #5
  %14 = load i32, ptr @n, align 4, !tbaa !5
  %.not34 = icmp slt i32 %14, 1
  br i1 %.not34, label %.preheader, label %.lr.ph

.preheader:                                       ; preds = %20, %0
  %.019.lcssa = phi i64 [ 0, %0 ], [ %21, %20 ]
  %15 = load i32, ptr @q, align 4, !tbaa !5
  %.not2337 = icmp slt i32 %15, 1
  br i1 %.not2337, label %._crit_edge, label %.lr.ph41

.lr.ph:                                           ; preds = %0, %20
  %indvars.iv = phi i64 [ %indvars.iv.next, %20 ], [ 1, %0 ]
  %.01935 = phi i64 [ %21, %20 ], [ 0, %0 ]
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %2) #5
  %16 = invoke noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERx(ptr noundef nonnull align 8 dereferenceable(16) @_ZSt3cin, ptr noundef nonnull align 8 dereferenceable(8) %2)
          to label %17 unwind label %24

17:                                               ; preds = %.lr.ph
  %18 = load i64, ptr %2, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %3) #5
  store i64 %indvars.iv, ptr %3, align 8, !tbaa !9
  %19 = invoke noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt3mapIxxSt4lessIxESaISt4pairIKxxEEEixEOx(ptr noundef nonnull align 8 dereferenceable(48) %1, ptr noundef nonnull align 8 dereferenceable(8) %3)
          to label %20 unwind label %26

20:                                               ; preds = %17
  %21 = add nsw i64 %18, %.01935
  store i64 %18, ptr %19, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %22 = load i32, ptr @n, align 4, !tbaa !5
  %23 = sext i32 %22 to i64
  %.not.not = icmp slt i64 %indvars.iv, %23
  br i1 %.not.not, label %.lr.ph, label %.preheader, !llvm.loop !11

24:                                               ; preds = %.lr.ph
  %25 = landingpad { ptr, i32 }
          cleanup
  br label %28

26:                                               ; preds = %17
  %27 = landingpad { ptr, i32 }
          cleanup
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #5
  br label %28

28:                                               ; preds = %26, %24
  %.pn29 = phi { ptr, i32 } [ %27, %26 ], [ %25, %24 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #5
  br label %94

._crit_edge:                                      ; preds = %90, %.preheader
  call void @_ZNSt3mapIxxSt4lessIxESaISt4pairIKxxEEED2Ev(ptr noundef nonnull align 8 dereferenceable(48) %1) #5
  call void @llvm.lifetime.end.p0(i64 48, ptr nonnull %1) #5
  ret void

.lr.ph41:                                         ; preds = %.preheader, %90
  %.040 = phi i32 [ %91, %90 ], [ 1, %.preheader ]
  %.01739 = phi i64 [ %.118, %90 ], [ 0, %.preheader ]
  %.12038 = phi i64 [ %.322, %90 ], [ %.019.lcssa, %.preheader ]
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %4) #5
  %29 = invoke noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERi(ptr noundef nonnull align 8 dereferenceable(16) @_ZSt3cin, ptr noundef nonnull align 4 dereferenceable(4) %4)
          to label %30 unwind label %40

30:                                               ; preds = %.lr.ph41
  %31 = load i32, ptr %4, align 4, !tbaa !5
  %32 = icmp eq i32 %31, 2
  br i1 %32, label %33, label %44

33:                                               ; preds = %30
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %5) #5
  %34 = invoke noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERx(ptr noundef nonnull align 8 dereferenceable(16) @_ZSt3cin, ptr noundef nonnull align 8 dereferenceable(8) %5)
          to label %35 unwind label %42

35:                                               ; preds = %33
  call void @_ZNSt3mapIxxSt4lessIxESaISt4pairIKxxEEE5clearEv(ptr noundef nonnull align 8 dereferenceable(48) %1) #5
  %36 = load i64, ptr %5, align 8, !tbaa !9
  %37 = load i32, ptr @n, align 4, !tbaa !5
  %38 = sext i32 %37 to i64
  %39 = mul nsw i64 %36, %38
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %5) #5
  br label %86

40:                                               ; preds = %88, %86, %.lr.ph41
  %41 = landingpad { ptr, i32 }
          cleanup
  br label %93

42:                                               ; preds = %33
  %43 = landingpad { ptr, i32 }
          cleanup
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %5) #5
  br label %93

44:                                               ; preds = %30
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %6) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %7) #5
  %45 = invoke noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERi(ptr noundef nonnull align 8 dereferenceable(16) @_ZSt3cin, ptr noundef nonnull align 4 dereferenceable(4) %6)
          to label %46 unwind label %67

46:                                               ; preds = %44
  %47 = invoke noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERx(ptr noundef nonnull align 8 dereferenceable(16) %45, ptr noundef nonnull align 8 dereferenceable(8) %7)
          to label %48 unwind label %67

48:                                               ; preds = %46
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %8) #5
  %49 = load i32, ptr %6, align 4, !tbaa !5
  %50 = sext i32 %49 to i64
  store i64 %50, ptr %8, align 8, !tbaa !9
  %51 = invoke noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt3mapIxxSt4lessIxESaISt4pairIKxxEEEixEOx(ptr noundef nonnull align 8 dereferenceable(48) %1, ptr noundef nonnull align 8 dereferenceable(8) %8)
          to label %52 unwind label %69

52:                                               ; preds = %48
  %53 = load i64, ptr %51, align 8, !tbaa !9
  %.not24 = icmp eq i64 %53, 0
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %8) #5
  %54 = load i64, ptr %7, align 8, !tbaa !9
  br i1 %.not24, label %75, label %55

55:                                               ; preds = %52
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %9) #5
  %56 = load i32, ptr %6, align 4, !tbaa !5
  %57 = sext i32 %56 to i64
  store i64 %57, ptr %9, align 8, !tbaa !9
  %58 = invoke noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt3mapIxxSt4lessIxESaISt4pairIKxxEEEixEOx(ptr noundef nonnull align 8 dereferenceable(48) %1, ptr noundef nonnull align 8 dereferenceable(8) %9)
          to label %59 unwind label %71

59:                                               ; preds = %55
  %60 = load i64, ptr %58, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %9) #5
  %61 = load i64, ptr %7, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %10) #5
  %62 = load i32, ptr %6, align 4, !tbaa !5
  %63 = sext i32 %62 to i64
  store i64 %63, ptr %10, align 8, !tbaa !9
  %64 = invoke noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt3mapIxxSt4lessIxESaISt4pairIKxxEEEixEOx(ptr noundef nonnull align 8 dereferenceable(48) %1, ptr noundef nonnull align 8 dereferenceable(8) %10)
          to label %65 unwind label %73

65:                                               ; preds = %59
  %66 = sub nsw i64 %54, %60
  store i64 %61, ptr %64, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %10) #5
  br label %84

67:                                               ; preds = %46, %44
  %68 = landingpad { ptr, i32 }
          cleanup
  br label %85

69:                                               ; preds = %48
  %70 = landingpad { ptr, i32 }
          cleanup
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %8) #5
  br label %85

71:                                               ; preds = %55
  %72 = landingpad { ptr, i32 }
          cleanup
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %9) #5
  br label %85

73:                                               ; preds = %59
  %74 = landingpad { ptr, i32 }
          cleanup
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %10) #5
  br label %85

75:                                               ; preds = %52
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %11) #5
  %76 = load i32, ptr %6, align 4, !tbaa !5
  %77 = sext i32 %76 to i64
  store i64 %77, ptr %11, align 8, !tbaa !9
  %78 = invoke noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt3mapIxxSt4lessIxESaISt4pairIKxxEEEixEOx(ptr noundef nonnull align 8 dereferenceable(48) %1, ptr noundef nonnull align 8 dereferenceable(8) %11)
          to label %79 unwind label %82

79:                                               ; preds = %75
  store i64 %54, ptr %78, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %11) #5
  %80 = load i64, ptr %7, align 8, !tbaa !9
  %81 = sub nsw i64 %80, %.01739
  br label %84

82:                                               ; preds = %75
  %83 = landingpad { ptr, i32 }
          cleanup
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %11) #5
  br label %85

84:                                               ; preds = %79, %65
  %.pn26 = phi i64 [ %66, %65 ], [ %81, %79 ]
  %.221 = add nsw i64 %.pn26, %.12038
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %7) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %6) #5
  br label %86

85:                                               ; preds = %82, %73, %71, %69, %67
  %.pn = phi { ptr, i32 } [ %74, %73 ], [ %72, %71 ], [ %83, %82 ], [ %70, %69 ], [ %68, %67 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %7) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %6) #5
  br label %93

86:                                               ; preds = %84, %35
  %.322 = phi i64 [ %39, %35 ], [ %.221, %84 ]
  %.118 = phi i64 [ %36, %35 ], [ %.01739, %84 ]
  %87 = invoke noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEx(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, i64 noundef %.322)
          to label %88 unwind label %40

88:                                               ; preds = %86
  %89 = invoke noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_c(ptr noundef nonnull align 8 dereferenceable(8) %87, i8 noundef signext 10)
          to label %90 unwind label %40

90:                                               ; preds = %88
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %4) #5
  %91 = add nuw nsw i32 %.040, 1
  %92 = load i32, ptr @q, align 4, !tbaa !5
  %.not23.not = icmp slt i32 %.040, %92
  br i1 %.not23.not, label %.lr.ph41, label %._crit_edge, !llvm.loop !13

93:                                               ; preds = %85, %42, %40
  %.pn27 = phi { ptr, i32 } [ %41, %40 ], [ %43, %42 ], [ %.pn, %85 ]
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %4) #5
  br label %94

94:                                               ; preds = %93, %28
  %.pn29.pn = phi { ptr, i32 } [ %.pn29, %28 ], [ %.pn27, %93 ]
  call void @_ZNSt3mapIxxSt4lessIxESaISt4pairIKxxEEED2Ev(ptr noundef nonnull align 8 dereferenceable(48) %1) #5
  call void @llvm.lifetime.end.p0(i64 48, ptr nonnull %1) #5
  resume { ptr, i32 } %.pn29.pn
}

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 #1

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZNSt3mapIxxSt4lessIxESaISt4pairIKxxEEEC2Ev(ptr noundef nonnull align 8 dereferenceable(48)) unnamed_addr #3 align 2

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

declare i32 @__gxx_personality_v0(...)

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

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZNSt3mapIxxSt4lessIxESaISt4pairIKxxEEE5clearEv(ptr noundef nonnull align 8 dereferenceable(48)) local_unnamed_addr #3 align 2

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

; 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 #0 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZNSt3mapIxxSt4lessIxESaISt4pairIKxxEEED2Ev(ptr noundef nonnull align 8 dereferenceable(48)) unnamed_addr #3 align 2

attributes #0 = { mustprogress uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #1 = { "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 nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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 #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 = { 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}


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