; LLVM IR from eyangch/competitive-programming :: USACOcontests/gold/2013.01 (seating)

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

@N = external dso_local global i32, align 4
@M = external dso_local global i32, align 4
@ar = external dso_local global [500000 x i32], align 16
@s = external dso_local global ptr, align 8
@.str = external hidden unnamed_addr constant [11 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [2 x i8], align 1
@stdin = external global ptr, align 8
@.str.2 = external hidden unnamed_addr constant [12 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [2 x i8], align 1
@stdout = external global ptr, align 8
@_ZSt3cin = external global %"class.std::basic_istream", align 8
@_ZSt4cout = external global %"class.std::basic_ostream", align 8
@.str.4 = external hidden unnamed_addr constant [2 x i8], align 1

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #0 personality ptr @__gxx_personality_v0 {
  %1 = alloca i32, align 4
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i8, align 1
  %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
  %13 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  %14 = load ptr, ptr @stdin, align 8, !tbaa !5
  %15 = call ptr @freopen(ptr noundef @.str, ptr noundef @.str.1, ptr noundef %14)
  %16 = load ptr, ptr @stdout, align 8, !tbaa !5
  %17 = call ptr @freopen(ptr noundef @.str.2, ptr noundef @.str.3, ptr noundef %16)
  %18 = load ptr, ptr @_ZSt3cin, align 8, !tbaa !9
  %19 = getelementptr i8, ptr %18, i64 -24
  %20 = load i64, ptr %19, align 8
  %21 = getelementptr inbounds i8, ptr @_ZSt3cin, i64 %20
  %22 = call noundef ptr @_ZNSt9basic_iosIcSt11char_traitsIcEE3tieEPSo(ptr noundef nonnull align 8 dereferenceable(264) %21, ptr noundef null)
  %23 = call noundef zeroext i1 @_ZNSt8ios_base15sync_with_stdioEb(i1 noundef zeroext false)
  %24 = 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)
  %25 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERi(ptr noundef nonnull align 8 dereferenceable(16) %24, ptr noundef nonnull align 4 dereferenceable(4) @M)
  %26 = call noalias noundef nonnull ptr @_Znwm(i64 noundef 32) #9
  %27 = load i32, ptr @N, align 4, !tbaa !11
  %28 = sub nsw i32 %27, 1
  invoke void @_ZN4segtC2Eii(ptr noundef nonnull align 8 dereferenceable(32) %26, i32 noundef 0, i32 noundef %28)
          to label %29 unwind label %44

29:                                               ; preds = %0
  store ptr %26, ptr @s, align 8, !tbaa !5
  %30 = load ptr, ptr @s, align 8, !tbaa !5
  %31 = load i32, ptr @N, align 4, !tbaa !11
  %32 = sub nsw i32 %31, 1
  %33 = load i32, ptr @N, align 4, !tbaa !11
  call void @_ZN4segt3updEii(ptr noundef nonnull align 8 dereferenceable(32) %30, i32 noundef %32, i32 noundef %33)
  %34 = load i32, ptr @N, align 4, !tbaa !11
  %35 = load i32, ptr @N, align 4, !tbaa !11
  %36 = sub nsw i32 %35, 1
  %37 = sext i32 %36 to i64
  %38 = getelementptr inbounds [500000 x i32], ptr @ar, i64 0, i64 %37
  store i32 %34, ptr %38, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #10
  store i32 0, ptr %4, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #10
  store i32 0, ptr %5, align 4, !tbaa !11
  br label %39

39:                                               ; preds = %171, %29
  %40 = load i32, ptr %5, align 4, !tbaa !11
  %41 = load i32, ptr @M, align 4, !tbaa !11
  %42 = icmp slt i32 %40, %41
  br i1 %42, label %48, label %43

43:                                               ; preds = %39
  store i32 2, ptr %6, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #10
  br label %174

44:                                               ; preds = %0
  %45 = landingpad { ptr, i32 }
          cleanup
  %46 = extractvalue { ptr, i32 } %45, 0
  store ptr %46, ptr %2, align 8
  %47 = extractvalue { ptr, i32 } %45, 1
  store i32 %47, ptr %3, align 4
  call void @_ZdlPvm(ptr noundef %26, i64 noundef 32) #11
  br label %179

48:                                               ; preds = %39
  call void @llvm.lifetime.start.p0(i64 1, ptr %7) #10
  %49 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZStrsIcSt11char_traitsIcEERSt13basic_istreamIT_T0_ES6_RS3_(ptr noundef nonnull align 8 dereferenceable(16) @_ZSt3cin, ptr noundef nonnull align 1 dereferenceable(1) %7)
  %50 = load i8, ptr %7, align 1, !tbaa !13
  %51 = sext i8 %50 to i32
  %52 = icmp eq i32 %51, 65
  br i1 %52, label %53, label %77

53:                                               ; preds = %48
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #10
  %54 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERi(ptr noundef nonnull align 8 dereferenceable(16) @_ZSt3cin, ptr noundef nonnull align 4 dereferenceable(4) %8)
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #10
  %55 = load ptr, ptr @s, align 8, !tbaa !5
  %56 = load i32, ptr @N, align 4, !tbaa !11
  %57 = sub nsw i32 %56, 1
  %58 = load i32, ptr %8, align 4, !tbaa !11
  %59 = call noundef i32 @_ZN4segt3qryEiii(ptr noundef nonnull align 8 dereferenceable(32) %55, i32 noundef 0, i32 noundef %57, i32 noundef %58)
  store i32 %59, ptr %9, align 4, !tbaa !11
  %60 = load i32, ptr %9, align 4, !tbaa !11
  %61 = icmp eq i32 %60, -1
  br i1 %61, label %62, label %65

62:                                               ; preds = %53
  %63 = load i32, ptr %4, align 4, !tbaa !11
  %64 = add nsw i32 %63, 1
  store i32 %64, ptr %4, align 4, !tbaa !11
  br label %76

65:                                               ; preds = %53
  %66 = load ptr, ptr @s, align 8, !tbaa !5
  %67 = load i32, ptr %9, align 4, !tbaa !11
  %68 = load i32, ptr %8, align 4, !tbaa !11
  %69 = sub nsw i32 0, %68
  call void @_ZN4segt3updEii(ptr noundef nonnull align 8 dereferenceable(32) %66, i32 noundef %67, i32 noundef %69)
  %70 = load i32, ptr %8, align 4, !tbaa !11
  %71 = load i32, ptr %9, align 4, !tbaa !11
  %72 = sext i32 %71 to i64
  %73 = getelementptr inbounds [500000 x i32], ptr @ar, i64 0, i64 %72
  %74 = load i32, ptr %73, align 4, !tbaa !11
  %75 = sub nsw i32 %74, %70
  store i32 %75, ptr %73, align 4, !tbaa !11
  br label %76

76:                                               ; preds = %65, %62
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #10
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #10
  br label %167

77:                                               ; preds = %48
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #10
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #10
  %78 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERi(ptr noundef nonnull align 8 dereferenceable(16) @_ZSt3cin, ptr noundef nonnull align 4 dereferenceable(4) %10)
  %79 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERi(ptr noundef nonnull align 8 dereferenceable(16) %78, ptr noundef nonnull align 4 dereferenceable(4) %11)
  %80 = load i32, ptr %10, align 4, !tbaa !11
  %81 = add nsw i32 %80, -1
  store i32 %81, ptr %10, align 4, !tbaa !11
  %82 = load i32, ptr %11, align 4, !tbaa !11
  %83 = add nsw i32 %82, -1
  store i32 %83, ptr %11, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #10
  %84 = load ptr, ptr @s, align 8, !tbaa !5
  %85 = load i32, ptr %10, align 4, !tbaa !11
  %86 = sub nsw i32 %85, 1
  %87 = load i32, ptr @N, align 4, !tbaa !11
  %88 = sub nsw i32 %87, 1
  %89 = call noundef i32 @_ZN4segt3qryEiii(ptr noundef nonnull align 8 dereferenceable(32) %84, i32 noundef %86, i32 noundef %88, i32 noundef 1)
  store i32 %89, ptr %12, align 4, !tbaa !11
  %90 = load i32, ptr %12, align 4, !tbaa !11
  %91 = icmp eq i32 %90, -1
  br i1 %91, label %92, label %106

92:                                               ; preds = %77
  %93 = load ptr, ptr @s, align 8, !tbaa !5
  %94 = load i32, ptr %11, align 4, !tbaa !11
  %95 = load i32, ptr %11, align 4, !tbaa !11
  %96 = load i32, ptr %10, align 4, !tbaa !11
  %97 = sub nsw i32 %95, %96
  %98 = add nsw i32 %97, 1
  call void @_ZN4segt3updEii(ptr noundef nonnull align 8 dereferenceable(32) %93, i32 noundef %94, i32 noundef %98)
  %99 = load i32, ptr %11, align 4, !tbaa !11
  %100 = load i32, ptr %10, align 4, !tbaa !11
  %101 = sub nsw i32 %99, %100
  %102 = add nsw i32 %101, 1
  %103 = load i32, ptr %11, align 4, !tbaa !11
  %104 = sext i32 %103 to i64
  %105 = getelementptr inbounds [500000 x i32], ptr @ar, i64 0, i64 %104
  store i32 %102, ptr %105, align 4, !tbaa !11
  store i32 4, ptr %6, align 4
  br label %164

106:                                              ; preds = %77
  br label %107

107:                                              ; preds = %123, %106
  %108 = load i32, ptr %12, align 4, !tbaa !11
  %109 = icmp ne i32 %108, -1
  br i1 %109, label %110, label %121

110:                                              ; preds = %107
  %111 = load i32, ptr %12, align 4, !tbaa !11
  %112 = load i32, ptr %12, align 4, !tbaa !11
  %113 = sext i32 %112 to i64
  %114 = getelementptr inbounds [500000 x i32], ptr @ar, i64 0, i64 %113
  %115 = load i32, ptr %114, align 4, !tbaa !11
  %116 = sub nsw i32 %111, %115
  %117 = add nsw i32 %116, 1
  %118 = load i32, ptr %11, align 4, !tbaa !11
  %119 = add nsw i32 %118, 1
  %120 = icmp sle i32 %117, %119
  br label %121

121:                                              ; preds = %110, %107
  %122 = phi i1 [ false, %107 ], [ %120, %110 ]
  br i1 %122, label %123, label %150

123:                                              ; preds = %121
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #10
  %124 = load i32, ptr %12, align 4, !tbaa !11
  %125 = load i32, ptr %12, align 4, !tbaa !11
  %126 = sext i32 %125 to i64
  %127 = getelementptr inbounds [500000 x i32], ptr @ar, i64 0, i64 %126
  %128 = load i32, ptr %127, align 4, !tbaa !11
  %129 = sub nsw i32 %124, %128
  %130 = add nsw i32 %129, 1
  store i32 %130, ptr %13, align 4, !tbaa !11
  %131 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %10, ptr noundef nonnull align 4 dereferenceable(4) %13)
  %132 = load i32, ptr %131, align 4, !tbaa !11
  store i32 %132, ptr %10, align 4, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #10
  %133 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %11, ptr noundef nonnull align 4 dereferenceable(4) %12)
  %134 = load i32, ptr %133, align 4, !tbaa !11
  store i32 %134, ptr %11, align 4, !tbaa !11
  %135 = load ptr, ptr @s, align 8, !tbaa !5
  %136 = load i32, ptr %12, align 4, !tbaa !11
  %137 = load i32, ptr %12, align 4, !tbaa !11
  %138 = sext i32 %137 to i64
  %139 = getelementptr inbounds [500000 x i32], ptr @ar, i64 0, i64 %138
  %140 = load i32, ptr %139, align 4, !tbaa !11
  %141 = sub nsw i32 0, %140
  call void @_ZN4segt3updEii(ptr noundef nonnull align 8 dereferenceable(32) %135, i32 noundef %136, i32 noundef %141)
  %142 = load i32, ptr %12, align 4, !tbaa !11
  %143 = sext i32 %142 to i64
  %144 = getelementptr inbounds [500000 x i32], ptr @ar, i64 0, i64 %143
  store i32 0, ptr %144, align 4, !tbaa !11
  %145 = load ptr, ptr @s, align 8, !tbaa !5
  %146 = load i32, ptr %12, align 4, !tbaa !11
  %147 = load i32, ptr @N, align 4, !tbaa !11
  %148 = sub nsw i32 %147, 1
  %149 = call noundef i32 @_ZN4segt3qryEiii(ptr noundef nonnull align 8 dereferenceable(32) %145, i32 noundef %146, i32 noundef %148, i32 noundef 1)
  store i32 %149, ptr %12, align 4, !tbaa !11
  br label %107, !llvm.loop !14

150:                                              ; preds = %121
  %151 = load ptr, ptr @s, align 8, !tbaa !5
  %152 = load i32, ptr %11, align 4, !tbaa !11
  %153 = load i32, ptr %11, align 4, !tbaa !11
  %154 = load i32, ptr %10, align 4, !tbaa !11
  %155 = sub nsw i32 %153, %154
  %156 = add nsw i32 %155, 1
  call void @_ZN4segt3updEii(ptr noundef nonnull align 8 dereferenceable(32) %151, i32 noundef %152, i32 noundef %156)
  %157 = load i32, ptr %11, align 4, !tbaa !11
  %158 = load i32, ptr %10, align 4, !tbaa !11
  %159 = sub nsw i32 %157, %158
  %160 = add nsw i32 %159, 1
  %161 = load i32, ptr %11, align 4, !tbaa !11
  %162 = sext i32 %161 to i64
  %163 = getelementptr inbounds [500000 x i32], ptr @ar, i64 0, i64 %162
  store i32 %160, ptr %163, align 4, !tbaa !11
  store i32 0, ptr %6, align 4
  br label %164

164:                                              ; preds = %150, %92
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #10
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #10
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #10
  %165 = load i32, ptr %6, align 4
  switch i32 %165, label %168 [
    i32 0, label %166
  ]

166:                                              ; preds = %164
  br label %167

167:                                              ; preds = %166, %76
  store i32 0, ptr %6, align 4
  br label %168

168:                                              ; preds = %167, %164
  call void @llvm.lifetime.end.p0(i64 1, ptr %7) #10
  %169 = load i32, ptr %6, align 4
  switch i32 %169, label %184 [
    i32 0, label %170
    i32 4, label %171
  ]

170:                                              ; preds = %168
  br label %171

171:                                              ; preds = %170, %168
  %172 = load i32, ptr %5, align 4, !tbaa !11
  %173 = add nsw i32 %172, 1
  store i32 %173, ptr %5, align 4, !tbaa !11
  br label %39, !llvm.loop !16

174:                                              ; preds = %43
  %175 = load i32, ptr %4, align 4, !tbaa !11
  %176 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEi(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, i32 noundef %175)
  %177 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc(ptr noundef nonnull align 8 dereferenceable(8) %176, ptr noundef @.str.4)
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #10
  %178 = load i32, ptr %1, align 4
  ret i32 %178

179:                                              ; preds = %44
  %180 = load ptr, ptr %2, align 8
  %181 = load i32, ptr %3, align 4
  %182 = insertvalue { ptr, i32 } poison, ptr %180, 0
  %183 = insertvalue { ptr, i32 } %182, i32 %181, 1
  resume { ptr, i32 } %183

184:                                              ; preds = %168
  unreachable
}

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

; Function Attrs: mustprogress nounwind uwtable
declare noundef ptr @_ZNSt9basic_iosIcSt11char_traitsIcEE3tieEPSo(ptr noundef nonnull align 8 dereferenceable(264), ptr noundef) #2 align 2

declare noundef zeroext i1 @_ZNSt8ios_base15sync_with_stdioEb(i1 noundef zeroext) #1

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: nobuiltin allocsize(0)
declare noundef nonnull ptr @_Znwm(i64 noundef) #3

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN4segtC2Eii(ptr noundef nonnull align 8 dereferenceable(32), i32 noundef, i32 noundef) unnamed_addr #4 align 2

declare i32 @__gxx_personality_v0(...)

; Function Attrs: nobuiltin nounwind
declare void @_ZdlPvm(ptr noundef, i64 noundef) #5

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN4segt3updEii(ptr noundef nonnull align 8 dereferenceable(32), i32 noundef, i32 noundef) #4 align 2

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

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

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

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

; 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)) #7

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

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

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

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

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

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 2}
!4 = !{!"clang version 19.1.0 (git@github.com:llvm/llvm-project.git a4bf6cd7cfb1a1421ba92bca9d017b49936c55e4)"}
!5 = !{!6, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"vtable pointer", !8, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!7, !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = distinct !{!16, !15}


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

@N = external dso_local global i32, align 4
@M = external dso_local global i32, align 4
@ar = external dso_local local_unnamed_addr global [500000 x i32], align 16
@s = external dso_local local_unnamed_addr global ptr, align 8
@.str = external hidden unnamed_addr constant [11 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [2 x i8], align 1
@stdin = external local_unnamed_addr global ptr, align 8
@.str.2 = external hidden unnamed_addr constant [12 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [2 x i8], align 1
@stdout = external local_unnamed_addr global ptr, align 8
@_ZSt3cin = external global %"class.std::basic_istream", align 8
@_ZSt4cout = external global %"class.std::basic_ostream", align 8
@.str.4 = external hidden unnamed_addr constant [2 x i8], align 1

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 personality ptr @__gxx_personality_v0 {
  %1 = alloca i8, align 1
  %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 = load ptr, ptr @stdin, align 8, !tbaa !5
  %8 = tail call ptr @freopen(ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, ptr noundef %7)
  %9 = load ptr, ptr @stdout, align 8, !tbaa !5
  %10 = tail call ptr @freopen(ptr noundef nonnull @.str.2, ptr noundef nonnull @.str.3, ptr noundef %9)
  %11 = load ptr, ptr @_ZSt3cin, align 8, !tbaa !9
  %12 = getelementptr i8, ptr %11, i64 -24
  %13 = load i64, ptr %12, align 8
  %14 = getelementptr inbounds i8, ptr @_ZSt3cin, i64 %13
  %15 = tail call noundef ptr @_ZNSt9basic_iosIcSt11char_traitsIcEE3tieEPSo(ptr noundef nonnull align 8 dereferenceable(264) %14, ptr noundef null)
  %16 = tail call noundef zeroext i1 @_ZNSt8ios_base15sync_with_stdioEb(i1 noundef zeroext false)
  %17 = 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)
  %18 = tail call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERi(ptr noundef nonnull align 8 dereferenceable(16) %17, ptr noundef nonnull align 4 dereferenceable(4) @M)
  %19 = tail call noalias noundef nonnull dereferenceable(32) ptr @_Znwm(i64 noundef 32) #9
  %20 = load i32, ptr @N, align 4, !tbaa !11
  %21 = add nsw i32 %20, -1
  invoke void @_ZN4segtC2Eii(ptr noundef nonnull align 8 dereferenceable(32) %19, i32 noundef 0, i32 noundef %21)
          to label %22 unwind label %33

22:                                               ; preds = %0
  store ptr %19, ptr @s, align 8, !tbaa !5
  %23 = load i32, ptr @N, align 4, !tbaa !11
  %24 = add nsw i32 %23, -1
  tail call void @_ZN4segt3updEii(ptr noundef nonnull align 8 dereferenceable(32) %19, i32 noundef %24, i32 noundef %23)
  %25 = load i32, ptr @N, align 4, !tbaa !11
  %26 = add nsw i32 %25, -1
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds [500000 x i32], ptr @ar, i64 0, i64 %27
  store i32 %25, ptr %28, align 4, !tbaa !11
  %29 = load i32, ptr @M, align 4, !tbaa !11
  %30 = icmp sgt i32 %29, 0
  br i1 %30, label %.lr.ph, label %._crit_edge

._crit_edge:                                      ; preds = %111, %22
  %.0.lcssa = phi i32 [ 0, %22 ], [ %.3, %111 ]
  %31 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEi(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, i32 noundef %.0.lcssa)
  %32 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc(ptr noundef nonnull align 8 dereferenceable(8) %31, ptr noundef nonnull @.str.4)
  ret i32 0

33:                                               ; preds = %0
  %34 = landingpad { ptr, i32 }
          cleanup
  tail call void @_ZdlPvm(ptr noundef nonnull %19, i64 noundef 32) #10
  resume { ptr, i32 } %34

.lr.ph:                                           ; preds = %22, %111
  %.020 = phi i32 [ %.3, %111 ], [ 0, %22 ]
  %.01119 = phi i32 [ %112, %111 ], [ 0, %22 ]
  call void @llvm.lifetime.start.p0(i64 1, ptr nonnull %1) #11
  %35 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZStrsIcSt11char_traitsIcEERSt13basic_istreamIT_T0_ES6_RS3_(ptr noundef nonnull align 8 dereferenceable(16) @_ZSt3cin, ptr noundef nonnull align 1 dereferenceable(1) %1)
  %36 = load i8, ptr %1, align 1, !tbaa !13
  %37 = icmp eq i8 %36, 65
  br i1 %37, label %38, label %58

38:                                               ; preds = %.lr.ph
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %2) #11
  %39 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERi(ptr noundef nonnull align 8 dereferenceable(16) @_ZSt3cin, ptr noundef nonnull align 4 dereferenceable(4) %2)
  %40 = load ptr, ptr @s, align 8, !tbaa !5
  %41 = load i32, ptr @N, align 4, !tbaa !11
  %42 = add nsw i32 %41, -1
  %43 = load i32, ptr %2, align 4, !tbaa !11
  %44 = call noundef i32 @_ZN4segt3qryEiii(ptr noundef nonnull align 8 dereferenceable(32) %40, i32 noundef 0, i32 noundef %42, i32 noundef %43)
  %45 = icmp eq i32 %44, -1
  br i1 %45, label %46, label %48

46:                                               ; preds = %38
  %47 = add nsw i32 %.020, 1
  br label %57

48:                                               ; preds = %38
  %49 = load ptr, ptr @s, align 8, !tbaa !5
  %50 = load i32, ptr %2, align 4, !tbaa !11
  %51 = sub nsw i32 0, %50
  call void @_ZN4segt3updEii(ptr noundef nonnull align 8 dereferenceable(32) %49, i32 noundef %44, i32 noundef %51)
  %52 = load i32, ptr %2, align 4, !tbaa !11
  %53 = sext i32 %44 to i64
  %54 = getelementptr inbounds [500000 x i32], ptr @ar, i64 0, i64 %53
  %55 = load i32, ptr %54, align 4, !tbaa !11
  %56 = sub nsw i32 %55, %52
  store i32 %56, ptr %54, align 4, !tbaa !11
  br label %57

57:                                               ; preds = %48, %46
  %.1 = phi i32 [ %47, %46 ], [ %.020, %48 ]
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %2) #11
  br label %111

58:                                               ; preds = %.lr.ph
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %3) #11
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %4) #11
  %59 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERi(ptr noundef nonnull align 8 dereferenceable(16) @_ZSt3cin, ptr noundef nonnull align 4 dereferenceable(4) %3)
  %60 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERi(ptr noundef nonnull align 8 dereferenceable(16) %59, ptr noundef nonnull align 4 dereferenceable(4) %4)
  %61 = load i32, ptr %3, align 4, !tbaa !11
  %62 = add nsw i32 %61, -1
  store i32 %62, ptr %3, align 4, !tbaa !11
  %63 = load i32, ptr %4, align 4, !tbaa !11
  %64 = add nsw i32 %63, -1
  store i32 %64, ptr %4, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %5) #11
  %65 = load ptr, ptr @s, align 8, !tbaa !5
  %66 = add nsw i32 %61, -2
  %67 = load i32, ptr @N, align 4, !tbaa !11
  %68 = add nsw i32 %67, -1
  %69 = call noundef i32 @_ZN4segt3qryEiii(ptr noundef nonnull align 8 dereferenceable(32) %65, i32 noundef %66, i32 noundef %68, i32 noundef 1)
  store i32 %69, ptr %5, align 4, !tbaa !11
  %.not15 = icmp eq i32 %69, -1
  br i1 %.not15, label %70, label %.preheader

70:                                               ; preds = %58
  %71 = load ptr, ptr @s, align 8, !tbaa !5
  %72 = load i32, ptr %4, align 4, !tbaa !11
  %73 = load i32, ptr %3, align 4, !tbaa !11
  %74 = add i32 %72, 1
  %75 = sub i32 %74, %73
  call void @_ZN4segt3updEii(ptr noundef nonnull align 8 dereferenceable(32) %71, i32 noundef %72, i32 noundef %75)
  br label %106

.preheader:                                       ; preds = %58, %82
  %76 = phi i32 [ %100, %82 ], [ %69, %58 ]
  %77 = sext i32 %76 to i64
  %78 = getelementptr inbounds [500000 x i32], ptr @ar, i64 0, i64 %77
  %79 = load i32, ptr %78, align 4, !tbaa !11
  %80 = sub nsw i32 %76, %79
  %81 = load i32, ptr %4, align 4, !tbaa !11
  %.not14 = icmp sgt i32 %80, %81
  br i1 %.not14, label %.critedge, label %82

82:                                               ; preds = %.preheader
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %6) #11
  %83 = add nsw i32 %80, 1
  store i32 %83, ptr %6, align 4, !tbaa !11
  %84 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %3, ptr noundef nonnull align 4 dereferenceable(4) %6)
  %85 = load i32, ptr %84, align 4, !tbaa !11
  store i32 %85, ptr %3, align 4, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %6) #11
  %86 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %4, ptr noundef nonnull align 4 dereferenceable(4) %5)
  %87 = load i32, ptr %86, align 4, !tbaa !11
  store i32 %87, ptr %4, align 4, !tbaa !11
  %88 = load ptr, ptr @s, align 8, !tbaa !5
  %89 = load i32, ptr %5, align 4, !tbaa !11
  %90 = sext i32 %89 to i64
  %91 = getelementptr inbounds [500000 x i32], ptr @ar, i64 0, i64 %90
  %92 = load i32, ptr %91, align 4, !tbaa !11
  %93 = sub nsw i32 0, %92
  call void @_ZN4segt3updEii(ptr noundef nonnull align 8 dereferenceable(32) %88, i32 noundef %89, i32 noundef %93)
  %94 = load i32, ptr %5, align 4, !tbaa !11
  %95 = sext i32 %94 to i64
  %96 = getelementptr inbounds [500000 x i32], ptr @ar, i64 0, i64 %95
  store i32 0, ptr %96, align 4, !tbaa !11
  %97 = load ptr, ptr @s, align 8, !tbaa !5
  %98 = load i32, ptr @N, align 4, !tbaa !11
  %99 = add nsw i32 %98, -1
  %100 = call noundef i32 @_ZN4segt3qryEiii(ptr noundef nonnull align 8 dereferenceable(32) %97, i32 noundef %94, i32 noundef %99, i32 noundef 1)
  store i32 %100, ptr %5, align 4, !tbaa !11
  %.not = icmp eq i32 %100, -1
  br i1 %.not, label %..critedge_crit_edge, label %.preheader, !llvm.loop !14

..critedge_crit_edge:                             ; preds = %82
  %.pre = load i32, ptr %4, align 4, !tbaa !11
  br label %.critedge

.critedge:                                        ; preds = %.preheader, %..critedge_crit_edge
  %101 = phi i32 [ %.pre, %..critedge_crit_edge ], [ %81, %.preheader ]
  %102 = load ptr, ptr @s, align 8, !tbaa !5
  %103 = load i32, ptr %3, align 4, !tbaa !11
  %104 = add i32 %101, 1
  %105 = sub i32 %104, %103
  call void @_ZN4segt3updEii(ptr noundef nonnull align 8 dereferenceable(32) %102, i32 noundef %101, i32 noundef %105)
  br label %106

106:                                              ; preds = %.critedge, %70
  %.sink26 = load i32, ptr %3, align 4, !tbaa !11
  %.sink = load i32, ptr %4, align 4, !tbaa !11
  %107 = add i32 %.sink, 1
  %108 = sub i32 %107, %.sink26
  %109 = sext i32 %.sink to i64
  %110 = getelementptr inbounds [500000 x i32], ptr @ar, i64 0, i64 %109
  store i32 %108, ptr %110, align 4, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %5) #11
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %4) #11
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %3) #11
  br label %111

111:                                              ; preds = %106, %57
  %.3 = phi i32 [ %.1, %57 ], [ %.020, %106 ]
  call void @llvm.lifetime.end.p0(i64 1, ptr nonnull %1) #11
  %112 = add nuw nsw i32 %.01119, 1
  %113 = load i32, ptr @M, align 4, !tbaa !11
  %114 = icmp slt i32 %112, %113
  br i1 %114, label %.lr.ph, label %._crit_edge, !llvm.loop !16
}

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

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

declare noundef zeroext i1 @_ZNSt8ios_base15sync_with_stdioEb(i1 noundef zeroext) local_unnamed_addr #1

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: nobuiltin allocsize(0)
declare noundef nonnull ptr @_Znwm(i64 noundef) local_unnamed_addr #3

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN4segtC2Eii(ptr noundef nonnull align 8 dereferenceable(32), i32 noundef, i32 noundef) unnamed_addr #4 align 2

declare i32 @__gxx_personality_v0(...)

; Function Attrs: nobuiltin nounwind
declare void @_ZdlPvm(ptr noundef, i64 noundef) local_unnamed_addr #5

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN4segt3updEii(ptr noundef nonnull align 8 dereferenceable(32), i32 noundef, i32 noundef) local_unnamed_addr #4 align 2

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

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

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

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

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

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

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

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

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

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

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 2}
!4 = !{!"clang version 19.1.0 (git@github.com:llvm/llvm-project.git a4bf6cd7cfb1a1421ba92bca9d017b49936c55e4)"}
!5 = !{!6, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"vtable pointer", !8, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!7, !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = distinct !{!16, !15}


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