; LLVM IR from tangjz/acm-icpc :: codeforces/complete (475D)

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

@n = external dso_local global i32, align 4
@q = external dso_local global i32, align 4
@a = external dso_local global [100086 x i32], align 16
@b = external dso_local global [100086 x [18 x i32]], align 16
@Sum = external dso_local global %"class.std::map", align 8
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [7 x i8], align 1

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

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #1 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  %13 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n)
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #5
  store i32 1, ptr %2, align 4, !tbaa !5
  br label %14

14:                                               ; preds = %32, %0
  %15 = load i32, ptr %2, align 4, !tbaa !5
  %16 = load i32, ptr @n, align 4, !tbaa !5
  %17 = icmp sle i32 %15, %16
  br i1 %17, label %19, label %18

18:                                               ; preds = %14
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #5
  br label %35

19:                                               ; preds = %14
  %20 = load i32, ptr %2, align 4, !tbaa !5
  %21 = sext i32 %20 to i64
  %22 = getelementptr inbounds i32, ptr @a, i64 %21
  %23 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %22)
  %24 = load i32, ptr %2, align 4, !tbaa !5
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds [100086 x i32], ptr @a, i64 0, i64 %25
  %27 = load i32, ptr %26, align 4, !tbaa !5
  %28 = load i32, ptr %2, align 4, !tbaa !5
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds [100086 x [18 x i32]], ptr @b, i64 0, i64 %29
  %31 = getelementptr inbounds [18 x i32], ptr %30, i64 0, i64 0
  store i32 %27, ptr %31, align 8, !tbaa !5
  br label %32

32:                                               ; preds = %19
  %33 = load i32, ptr %2, align 4, !tbaa !5
  %34 = add nsw i32 %33, 1
  store i32 %34, ptr %2, align 4, !tbaa !5
  br label %14, !llvm.loop !9

35:                                               ; preds = %18
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #5
  store i32 1, ptr %3, align 4, !tbaa !5
  br label %36

36:                                               ; preds = %80, %35
  %37 = load i32, ptr %3, align 4, !tbaa !5
  %38 = icmp sle i32 %37, 17
  br i1 %38, label %40, label %39

39:                                               ; preds = %36
  store i32 5, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #5
  br label %83

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

41:                                               ; preds = %76, %40
  %42 = load i32, ptr %5, align 4, !tbaa !5
  %43 = load i32, ptr @n, align 4, !tbaa !5
  %44 = icmp sle i32 %42, %43
  br i1 %44, label %46, label %45

45:                                               ; preds = %41
  store i32 8, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #5
  br label %79

46:                                               ; preds = %41
  %47 = load i32, ptr %5, align 4, !tbaa !5
  %48 = sext i32 %47 to i64
  %49 = getelementptr inbounds [100086 x [18 x i32]], ptr @b, i64 0, i64 %48
  %50 = load i32, ptr %3, align 4, !tbaa !5
  %51 = sub nsw i32 %50, 1
  %52 = sext i32 %51 to i64
  %53 = getelementptr inbounds [18 x i32], ptr %49, i64 0, i64 %52
  %54 = load i32, ptr %53, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #5
  %55 = load i32, ptr %5, align 4, !tbaa !5
  %56 = load i32, ptr %3, align 4, !tbaa !5
  %57 = sub nsw i32 %56, 1
  %58 = shl i32 1, %57
  %59 = add nsw i32 %55, %58
  store i32 %59, ptr %6, align 4, !tbaa !5
  %60 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %6, ptr noundef nonnull align 4 dereferenceable(4) @n)
  %61 = load i32, ptr %60, align 4, !tbaa !5
  %62 = sext i32 %61 to i64
  %63 = getelementptr inbounds [100086 x [18 x i32]], ptr @b, i64 0, i64 %62
  %64 = load i32, ptr %3, align 4, !tbaa !5
  %65 = sub nsw i32 %64, 1
  %66 = sext i32 %65 to i64
  %67 = getelementptr inbounds [18 x i32], ptr %63, i64 0, i64 %66
  %68 = load i32, ptr %67, align 4, !tbaa !5
  %69 = call noundef i32 @_Z3gcdii(i32 noundef %54, i32 noundef %68)
  %70 = load i32, ptr %5, align 4, !tbaa !5
  %71 = sext i32 %70 to i64
  %72 = getelementptr inbounds [100086 x [18 x i32]], ptr @b, i64 0, i64 %71
  %73 = load i32, ptr %3, align 4, !tbaa !5
  %74 = sext i32 %73 to i64
  %75 = getelementptr inbounds [18 x i32], ptr %72, i64 0, i64 %74
  store i32 %69, ptr %75, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #5
  br label %76

76:                                               ; preds = %46
  %77 = load i32, ptr %5, align 4, !tbaa !5
  %78 = add nsw i32 %77, 1
  store i32 %78, ptr %5, align 4, !tbaa !5
  br label %41, !llvm.loop !11

79:                                               ; preds = %45
  br label %80

80:                                               ; preds = %79
  %81 = load i32, ptr %3, align 4, !tbaa !5
  %82 = add nsw i32 %81, 1
  store i32 %82, ptr %3, align 4, !tbaa !5
  br label %36, !llvm.loop !12

83:                                               ; preds = %39
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #5
  store i32 1, ptr %7, align 4, !tbaa !5
  br label %84

84:                                               ; preds = %170, %83
  %85 = load i32, ptr %7, align 4, !tbaa !5
  %86 = load i32, ptr @n, align 4, !tbaa !5
  %87 = icmp sle i32 %85, %86
  br i1 %87, label %89, label %88

88:                                               ; preds = %84
  store i32 11, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #5
  br label %173

89:                                               ; preds = %84
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #5
  %90 = load i32, ptr %7, align 4, !tbaa !5
  %91 = sext i32 %90 to i64
  %92 = getelementptr inbounds [100086 x i32], ptr @a, i64 0, i64 %91
  %93 = load i32, ptr %92, align 4, !tbaa !5
  store i32 %93, ptr %8, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #5
  %94 = load i32, ptr %7, align 4, !tbaa !5
  store i32 %94, ptr %9, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #5
  %95 = load i32, ptr %7, align 4, !tbaa !5
  store i32 %95, ptr %10, align 4, !tbaa !5
  br label %96

96:                                               ; preds = %152, %89
  %97 = load i32, ptr %10, align 4, !tbaa !5
  %98 = load i32, ptr @n, align 4, !tbaa !5
  %99 = icmp sle i32 %97, %98
  br i1 %99, label %100, label %169

100:                                              ; preds = %96
  br label %101

101:                                              ; preds = %151, %100
  br label %102

102:                                              ; preds = %101
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #5
  store i32 1, ptr %11, align 4, !tbaa !5
  br label %103

103:                                              ; preds = %124, %102
  %104 = load i32, ptr %10, align 4, !tbaa !5
  %105 = load i32, ptr %11, align 4, !tbaa !5
  %106 = shl i32 1, %105
  %107 = add nsw i32 %104, %106
  %108 = sub nsw i32 %107, 1
  %109 = load i32, ptr @n, align 4, !tbaa !5
  %110 = icmp sle i32 %108, %109
  br i1 %110, label %111, label %122

111:                                              ; preds = %103
  %112 = load i32, ptr %10, align 4, !tbaa !5
  %113 = sext i32 %112 to i64
  %114 = getelementptr inbounds [100086 x [18 x i32]], ptr @b, i64 0, i64 %113
  %115 = load i32, ptr %11, align 4, !tbaa !5
  %116 = sext i32 %115 to i64
  %117 = getelementptr inbounds [18 x i32], ptr %114, i64 0, i64 %116
  %118 = load i32, ptr %117, align 4, !tbaa !5
  %119 = load i32, ptr %8, align 4, !tbaa !5
  %120 = srem i32 %118, %119
  %121 = icmp eq i32 %120, 0
  br label %122

122:                                              ; preds = %111, %103
  %123 = phi i1 [ false, %103 ], [ %121, %111 ]
  br i1 %123, label %124, label %127

124:                                              ; preds = %122
  %125 = load i32, ptr %11, align 4, !tbaa !5
  %126 = add nsw i32 %125, 1
  store i32 %126, ptr %11, align 4, !tbaa !5
  br label %103, !llvm.loop !13

127:                                              ; preds = %122
  %128 = load i32, ptr %11, align 4, !tbaa !5
  %129 = add nsw i32 %128, -1
  store i32 %129, ptr %11, align 4, !tbaa !5
  %130 = load i32, ptr %10, align 4, !tbaa !5
  %131 = load i32, ptr %11, align 4, !tbaa !5
  %132 = shl i32 1, %131
  %133 = add nsw i32 %130, %132
  %134 = sub nsw i32 %133, 1
  store i32 %134, ptr %10, align 4, !tbaa !5
  %135 = load i32, ptr %10, align 4, !tbaa !5
  %136 = load i32, ptr @n, align 4, !tbaa !5
  %137 = icmp eq i32 %135, %136
  br i1 %137, label %147, label %138

138:                                              ; preds = %127
  %139 = load i32, ptr %10, align 4, !tbaa !5
  %140 = add nsw i32 %139, 1
  %141 = sext i32 %140 to i64
  %142 = getelementptr inbounds [100086 x i32], ptr @a, i64 0, i64 %141
  %143 = load i32, ptr %142, align 4, !tbaa !5
  %144 = load i32, ptr %8, align 4, !tbaa !5
  %145 = srem i32 %143, %144
  %146 = icmp ne i32 %145, 0
  br i1 %146, label %147, label %148

147:                                              ; preds = %138, %127
  store i32 17, ptr %4, align 4
  br label %149

148:                                              ; preds = %138
  store i32 0, ptr %4, align 4
  br label %149

149:                                              ; preds = %148, %147
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #5
  %150 = load i32, ptr %4, align 4
  switch i32 %150, label %185 [
    i32 0, label %151
    i32 17, label %152
  ]

151:                                              ; preds = %149
  br label %101, !llvm.loop !14

152:                                              ; preds = %149
  %153 = load i32, ptr %10, align 4, !tbaa !5
  %154 = load i32, ptr %9, align 4, !tbaa !5
  %155 = sub nsw i32 %153, %154
  %156 = add nsw i32 %155, 1
  %157 = sext i32 %156 to i64
  %158 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt3mapIixSt4lessIiESaISt4pairIKixEEEixERS3_(ptr noundef nonnull align 8 dereferenceable(48) @Sum, ptr noundef nonnull align 4 dereferenceable(4) %8)
  %159 = load i64, ptr %158, align 8, !tbaa !15
  %160 = add nsw i64 %159, %157
  store i64 %160, ptr %158, align 8, !tbaa !15
  %161 = load i32, ptr %10, align 4, !tbaa !5
  %162 = add nsw i32 %161, 1
  store i32 %162, ptr %10, align 4, !tbaa !5
  store i32 %162, ptr %9, align 4, !tbaa !5
  %163 = load i32, ptr %8, align 4, !tbaa !5
  %164 = load i32, ptr %10, align 4, !tbaa !5
  %165 = sext i32 %164 to i64
  %166 = getelementptr inbounds [100086 x i32], ptr @a, i64 0, i64 %165
  %167 = load i32, ptr %166, align 4, !tbaa !5
  %168 = call noundef i32 @_Z3gcdii(i32 noundef %163, i32 noundef %167)
  store i32 %168, ptr %8, align 4, !tbaa !5
  br label %96, !llvm.loop !17

169:                                              ; preds = %96
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #5
  br label %170

170:                                              ; preds = %169
  %171 = load i32, ptr %7, align 4, !tbaa !5
  %172 = add nsw i32 %171, 1
  store i32 %172, ptr %7, align 4, !tbaa !5
  br label %84, !llvm.loop !18

173:                                              ; preds = %88
  %174 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @q)
  br label %175

175:                                              ; preds = %179, %173
  %176 = load i32, ptr @q, align 4, !tbaa !5
  %177 = add nsw i32 %176, -1
  store i32 %177, ptr @q, align 4, !tbaa !5
  %178 = icmp ne i32 %176, 0
  br i1 %178, label %179, label %184

179:                                              ; preds = %175
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #5
  %180 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %12)
  %181 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt3mapIixSt4lessIiESaISt4pairIKixEEEixERS3_(ptr noundef nonnull align 8 dereferenceable(48) @Sum, ptr noundef nonnull align 4 dereferenceable(4) %12)
  %182 = load i64, ptr %181, align 8, !tbaa !15
  %183 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i64 noundef %182)
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #5
  br label %175, !llvm.loop !19

184:                                              ; preds = %175
  ret i32 0

185:                                              ; preds = %149
  unreachable
}

declare i32 @__isoc99_scanf(ptr noundef, ...) #2

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

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

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

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

declare i32 @printf(ptr noundef, ...) #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 = { 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 #2 = { "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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { 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 #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 = distinct !{!12, !10}
!13 = distinct !{!13, !10}
!14 = distinct !{!14, !10}
!15 = !{!16, !16, i64 0}
!16 = !{!"long long", !7, i64 0}
!17 = distinct !{!17, !10}
!18 = distinct !{!18, !10}
!19 = distinct !{!19, !10}


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

@n = external dso_local global i32, align 4
@q = external dso_local global i32, align 4
@a = external dso_local global [100086 x i32], align 16
@b = external dso_local local_unnamed_addr global [100086 x [18 x i32]], align 16
@Sum = external dso_local global %"class.std::map", align 8
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [7 x i8], align 1

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

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() local_unnamed_addr #1 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @n)
  %5 = load i32, ptr @n, align 4, !tbaa !5
  %.not56 = icmp slt i32 %5, 1
  br i1 %.not56, label %._crit_edge75, label %.lr.ph

.preheader54:                                     ; preds = %.lr.ph
  %6 = icmp slt i32 %11, 1
  br i1 %6, label %._crit_edge75, label %.preheader53

.lr.ph:                                           ; preds = %0, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 1, %0 ]
  %7 = getelementptr inbounds i32, ptr @a, i64 %indvars.iv
  %8 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %7)
  %9 = load i32, ptr %7, align 4, !tbaa !5
  %10 = getelementptr inbounds [100086 x [18 x i32]], ptr @b, i64 0, i64 %indvars.iv
  store i32 %9, ptr %10, align 8, !tbaa !5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %11 = load i32, ptr @n, align 4, !tbaa !5
  %12 = sext i32 %11 to i64
  %.not.not = icmp slt i64 %indvars.iv, %12
  br i1 %.not.not, label %.lr.ph, label %.preheader54, !llvm.loop !9

.preheader53:                                     ; preds = %.preheader54, %._crit_edge
  %13 = phi i32 [ %17, %._crit_edge ], [ %11, %.preheader54 ]
  %indvars.iv85 = phi i64 [ %indvars.iv.next86, %._crit_edge ], [ 1, %.preheader54 ]
  %.not4958 = icmp slt i32 %13, 1
  br i1 %.not4958, label %._crit_edge, label %.lr.ph60

.lr.ph60:                                         ; preds = %.preheader53
  %14 = add nsw i64 %indvars.iv85, -1
  %15 = trunc nuw nsw i64 %14 to i32
  %16 = shl nuw nsw i32 1, %15
  br label %18

.preheader52:                                     ; preds = %._crit_edge
  %.not4472 = icmp slt i32 %17, 1
  br i1 %.not4472, label %._crit_edge75, label %.lr.ph74

._crit_edge:                                      ; preds = %18, %.preheader53
  %17 = phi i32 [ %13, %.preheader53 ], [ %30, %18 ]
  %indvars.iv.next86 = add nuw nsw i64 %indvars.iv85, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next86, 18
  br i1 %exitcond.not, label %.preheader52, label %.preheader53, !llvm.loop !11

18:                                               ; preds = %.lr.ph60, %18
  %indvars.iv82 = phi i64 [ 1, %.lr.ph60 ], [ %indvars.iv.next83, %18 ]
  %19 = getelementptr inbounds [100086 x [18 x i32]], ptr @b, i64 0, i64 %indvars.iv82, i64 %14
  %20 = load i32, ptr %19, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %1) #5
  %21 = trunc i64 %indvars.iv82 to i32
  %22 = add i32 %16, %21
  store i32 %22, ptr %1, align 4, !tbaa !5
  %23 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %1, ptr noundef nonnull align 4 dereferenceable(4) @n)
  %24 = load i32, ptr %23, align 4, !tbaa !5
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds [100086 x [18 x i32]], ptr @b, i64 0, i64 %25, i64 %14
  %27 = load i32, ptr %26, align 4, !tbaa !5
  %28 = call noundef i32 @_Z3gcdii(i32 noundef %20, i32 noundef %27)
  %29 = getelementptr inbounds [100086 x [18 x i32]], ptr @b, i64 0, i64 %indvars.iv82, i64 %indvars.iv85
  store i32 %28, ptr %29, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %1) #5
  %indvars.iv.next83 = add nuw nsw i64 %indvars.iv82, 1
  %30 = load i32, ptr @n, align 4, !tbaa !5
  %31 = sext i32 %30 to i64
  %.not49.not = icmp slt i64 %indvars.iv82, %31
  br i1 %.not49.not, label %18, label %._crit_edge, !llvm.loop !13

._crit_edge75:                                    ; preds = %._crit_edge71, %0, %.preheader54, %.preheader52
  %32 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @q)
  %33 = load i32, ptr @q, align 4, !tbaa !5
  %34 = add nsw i32 %33, -1
  store i32 %34, ptr @q, align 4, !tbaa !5
  %.not4576 = icmp eq i32 %33, 0
  br i1 %.not4576, label %._crit_edge79, label %.lr.ph78

.lr.ph74:                                         ; preds = %.preheader52, %._crit_edge71
  %35 = phi i32 [ %72, %._crit_edge71 ], [ %17, %.preheader52 ]
  %indvars.iv91 = phi i64 [ %indvars.iv.next92, %._crit_edge71 ], [ 1, %.preheader52 ]
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %2) #5
  %36 = getelementptr inbounds [100086 x i32], ptr @a, i64 0, i64 %indvars.iv91
  %37 = load i32, ptr %36, align 4, !tbaa !5
  store i32 %37, ptr %2, align 4, !tbaa !5
  %38 = sext i32 %35 to i64
  %.not4668 = icmp sgt i64 %indvars.iv91, %38
  br i1 %.not4668, label %._crit_edge71, label %.preheader.preheader

.preheader.preheader:                             ; preds = %.lr.ph74
  %39 = trunc nuw nsw i64 %indvars.iv91 to i32
  br label %.preheader

.preheader:                                       ; preds = %.preheader.preheader, %split
  %40 = phi i32 [ %71, %split ], [ %35, %.preheader.preheader ]
  %.03770 = phi i32 [ %55, %split ], [ %39, %.preheader.preheader ]
  %storemerge69 = phi i32 [ %70, %split ], [ %37, %.preheader.preheader ]
  br label %41

41:                                               ; preds = %.preheader, %58
  %.1 = phi i32 [ %56, %58 ], [ %.03770, %.preheader ]
  %42 = sext i32 %.1 to i64
  %43 = add i32 %.1, -1
  %44 = add i32 %.1, 1
  %.not4762 = icmp sgt i32 %44, %40
  br i1 %.not4762, label %.critedge, label %.lr.ph65

.lr.ph65:                                         ; preds = %41, %50
  %indvars.iv88 = phi i64 [ %indvars.iv.next89, %50 ], [ 1, %41 ]
  %45 = getelementptr inbounds [100086 x [18 x i32]], ptr @b, i64 0, i64 %42, i64 %indvars.iv88
  %46 = load i32, ptr %45, align 4, !tbaa !5
  %47 = srem i32 %46, %storemerge69
  %48 = icmp eq i32 %47, 0
  %49 = trunc nuw nsw i64 %indvars.iv88 to i32
  br i1 %48, label %50, label %.critedge

50:                                               ; preds = %.lr.ph65
  %indvars.iv.next89 = add nuw nsw i64 %indvars.iv88, 1
  %51 = shl nuw i32 2, %49
  %52 = add i32 %43, %51
  %.not47 = icmp sgt i32 %52, %40
  br i1 %.not47, label %.critedge.loopexit.split.loop.exit, label %.lr.ph65, !llvm.loop !14

.critedge.loopexit.split.loop.exit:               ; preds = %50
  %indvars.le = trunc i64 %indvars.iv.next89 to i32
  br label %.critedge

.critedge:                                        ; preds = %.lr.ph65, %.critedge.loopexit.split.loop.exit, %41
  %.0.lcssa = phi i32 [ 1, %41 ], [ %indvars.le, %.critedge.loopexit.split.loop.exit ], [ %49, %.lr.ph65 ]
  %53 = add nsw i32 %.0.lcssa, -1
  %54 = shl nuw i32 1, %53
  %55 = add nsw i32 %54, %.1
  %56 = add nsw i32 %55, -1
  %57 = icmp eq i32 %56, %40
  %.pre95 = sext i32 %55 to i64
  br i1 %57, label %split, label %58

58:                                               ; preds = %.critedge
  %59 = getelementptr inbounds [100086 x i32], ptr @a, i64 0, i64 %.pre95
  %60 = load i32, ptr %59, align 4, !tbaa !5
  %61 = srem i32 %60, %storemerge69
  %.not48 = icmp eq i32 %61, 0
  br i1 %.not48, label %41, label %split

split:                                            ; preds = %58, %.critedge
  %62 = sub i32 %55, %.03770
  %63 = sext i32 %62 to i64
  %64 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt3mapIixSt4lessIiESaISt4pairIKixEEEixERS3_(ptr noundef nonnull align 8 dereferenceable(48) @Sum, ptr noundef nonnull align 4 dereferenceable(4) %2)
  %65 = load i64, ptr %64, align 8, !tbaa !15
  %66 = add nsw i64 %65, %63
  store i64 %66, ptr %64, align 8, !tbaa !15
  %67 = load i32, ptr %2, align 4, !tbaa !5
  %68 = getelementptr inbounds [100086 x i32], ptr @a, i64 0, i64 %.pre95
  %69 = load i32, ptr %68, align 4, !tbaa !5
  %70 = call noundef i32 @_Z3gcdii(i32 noundef %67, i32 noundef %69)
  store i32 %70, ptr %2, align 4, !tbaa !5
  %71 = load i32, ptr @n, align 4, !tbaa !5
  %.not46 = icmp sgt i32 %55, %71
  br i1 %.not46, label %._crit_edge71.loopexit, label %.preheader, !llvm.loop !17

._crit_edge71.loopexit:                           ; preds = %split
  %.pre = sext i32 %71 to i64
  br label %._crit_edge71

._crit_edge71:                                    ; preds = %._crit_edge71.loopexit, %.lr.ph74
  %.pre-phi = phi i64 [ %.pre, %._crit_edge71.loopexit ], [ %38, %.lr.ph74 ]
  %72 = phi i32 [ %71, %._crit_edge71.loopexit ], [ %35, %.lr.ph74 ]
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %2) #5
  %indvars.iv.next92 = add nuw nsw i64 %indvars.iv91, 1
  %.not44.not = icmp slt i64 %indvars.iv91, %.pre-phi
  br i1 %.not44.not, label %.lr.ph74, label %._crit_edge75, !llvm.loop !18

.lr.ph78:                                         ; preds = %._crit_edge75, %.lr.ph78
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %3) #5
  %73 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %3)
  %74 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt3mapIixSt4lessIiESaISt4pairIKixEEEixERS3_(ptr noundef nonnull align 8 dereferenceable(48) @Sum, ptr noundef nonnull align 4 dereferenceable(4) %3)
  %75 = load i64, ptr %74, align 8, !tbaa !15
  %76 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i64 noundef %75)
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %3) #5
  %77 = load i32, ptr @q, align 4, !tbaa !5
  %78 = add nsw i32 %77, -1
  store i32 %78, ptr @q, align 4, !tbaa !5
  %.not45 = icmp eq i32 %77, 0
  br i1 %.not45, label %._crit_edge79, label %.lr.ph78, !llvm.loop !19

._crit_edge79:                                    ; preds = %.lr.ph78, %._crit_edge75
  ret i32 0
}

; Function Attrs: nofree nounwind
declare noundef i32 @__isoc99_scanf(ptr nocapture noundef readonly, ...) local_unnamed_addr #2

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

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

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

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

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #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 = { 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 #2 = { nofree nounwind "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 nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { 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 #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"}
!13 = distinct !{!13, !10}
!14 = distinct !{!14, !10}
!15 = !{!16, !16, i64 0}
!16 = !{!"long long", !7, i64 0}
!17 = distinct !{!17, !10}
!18 = distinct !{!18, !10}
!19 = distinct !{!19, !10}


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