; LLVM IR from tangjz/acm-icpc :: codechef/SEPT18/CHEFZERO.ll (Z5solveb)

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

@n = external dso_local global i32, align 4
@m = external dso_local global i32, align 4
@q = external dso_local global i32, align 4
@mat = external dso_local global [1001 x [1001 x i32]], align 16
@pos = external dso_local global [1001 x [1001 x i32]], align 16
@ord = external dso_local global [1000001 x i32], align 16
@seq = external dso_local global [1000001 x i32], align 16
@len = external dso_local global [1001 x i32], align 16
@sum = external dso_local global [1000001 x i64], align 16
@ans = external dso_local global i64, align 8

; Function Attrs: mustprogress uwtable
define dso_local void @_Z5solveb(i1 noundef zeroext %0) #0 {
  %2 = alloca i8, align 1
  %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 i64, align 8
  %12 = alloca i64, align 8
  %13 = alloca i32, align 4
  %14 = alloca i64, align 8
  %15 = alloca i64, align 8
  %16 = alloca i64, align 8
  %17 = alloca i64, align 8
  %18 = alloca i32, align 4
  %19 = alloca i32, align 4
  %20 = alloca i32, align 4
  %21 = zext i1 %0 to i8
  store i8 %21, ptr %2, align 1, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #4
  %22 = load i32, ptr @n, align 4, !tbaa !9
  %23 = load i32, ptr @m, align 4, !tbaa !9
  %24 = mul nsw i32 %22, %23
  store i32 %24, ptr %3, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #4
  %25 = load i32, ptr %3, align 4, !tbaa !9
  %26 = load i32, ptr @q, align 4, !tbaa !9
  %27 = sdiv i32 %25, %26
  store i32 %27, ptr %4, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  %28 = load i32, ptr %3, align 4, !tbaa !9
  %29 = load i32, ptr @q, align 4, !tbaa !9
  %30 = srem i32 %28, %29
  store i32 %30, ptr %5, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  store i32 0, ptr %6, align 4, !tbaa !9
  br label %31

31:                                               ; preds = %73, %1
  %32 = load i32, ptr %6, align 4, !tbaa !9
  %33 = load i32, ptr %3, align 4, !tbaa !9
  %34 = icmp slt i32 %32, %33
  br i1 %34, label %36, label %35

35:                                               ; preds = %31
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  br label %76

36:                                               ; preds = %31
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  %37 = load i32, ptr %6, align 4, !tbaa !9
  %38 = sext i32 %37 to i64
  %39 = getelementptr inbounds [1000001 x i32], ptr @ord, i64 0, i64 %38
  %40 = load i32, ptr %39, align 4, !tbaa !9
  %41 = load i32, ptr @m, align 4, !tbaa !9
  %42 = sdiv i32 %40, %41
  store i32 %42, ptr %7, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  %43 = load i32, ptr %6, align 4, !tbaa !9
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds [1000001 x i32], ptr @ord, i64 0, i64 %44
  %46 = load i32, ptr %45, align 4, !tbaa !9
  %47 = load i32, ptr @m, align 4, !tbaa !9
  %48 = srem i32 %46, %47
  store i32 %48, ptr %8, align 4, !tbaa !9
  %49 = load i32, ptr %7, align 4, !tbaa !9
  %50 = sext i32 %49 to i64
  %51 = getelementptr inbounds [1001 x [1001 x i32]], ptr @mat, i64 0, i64 %50
  %52 = load i32, ptr %8, align 4, !tbaa !9
  %53 = sext i32 %52 to i64
  %54 = getelementptr inbounds [1001 x i32], ptr %51, i64 0, i64 %53
  %55 = load i32, ptr %54, align 4, !tbaa !9
  %56 = load i32, ptr %6, align 4, !tbaa !9
  %57 = sext i32 %56 to i64
  %58 = getelementptr inbounds [1000001 x i32], ptr @seq, i64 0, i64 %57
  store i32 %55, ptr %58, align 4, !tbaa !9
  %59 = load i32, ptr %6, align 4, !tbaa !9
  %60 = sext i32 %59 to i64
  %61 = getelementptr inbounds [1000001 x i64], ptr @sum, i64 0, i64 %60
  %62 = load i64, ptr %61, align 8, !tbaa !11
  %63 = load i32, ptr %6, align 4, !tbaa !9
  %64 = sext i32 %63 to i64
  %65 = getelementptr inbounds [1000001 x i32], ptr @seq, i64 0, i64 %64
  %66 = load i32, ptr %65, align 4, !tbaa !9
  %67 = sext i32 %66 to i64
  %68 = add nsw i64 %62, %67
  %69 = load i32, ptr %6, align 4, !tbaa !9
  %70 = add nsw i32 %69, 1
  %71 = sext i32 %70 to i64
  %72 = getelementptr inbounds [1000001 x i64], ptr @sum, i64 0, i64 %71
  store i64 %68, ptr %72, align 8, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  br label %73

73:                                               ; preds = %36
  %74 = load i32, ptr %6, align 4, !tbaa !9
  %75 = add nsw i32 %74, 1
  store i32 %75, ptr %6, align 4, !tbaa !9
  br label %31, !llvm.loop !13

76:                                               ; preds = %35
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  store i32 0, ptr %9, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #4
  store i64 9223372036854775807, ptr %11, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #4
  store i64 0, ptr %12, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #4
  store i32 0, ptr %13, align 4, !tbaa !9
  br label %77

77:                                               ; preds = %163, %76
  %78 = load i32, ptr %13, align 4, !tbaa !9
  %79 = load i32, ptr @q, align 4, !tbaa !9
  %80 = icmp slt i32 %78, %79
  br i1 %80, label %82, label %81

81:                                               ; preds = %77
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #4
  br label %166

82:                                               ; preds = %77
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #4
  store i64 0, ptr %14, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #4
  %83 = load i32, ptr %3, align 4, !tbaa !9
  %84 = sext i32 %83 to i64
  %85 = getelementptr inbounds [1000001 x i64], ptr @sum, i64 0, i64 %84
  %86 = load i64, ptr %85, align 8, !tbaa !11
  %87 = load i32, ptr %9, align 4, !tbaa !9
  %88 = sext i32 %87 to i64
  %89 = getelementptr inbounds [1000001 x i64], ptr @sum, i64 0, i64 %88
  %90 = load i64, ptr %89, align 8, !tbaa !11
  %91 = sub nsw i64 %86, %90
  store i64 %91, ptr %15, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #4
  %92 = load i64, ptr %15, align 8, !tbaa !11
  %93 = load i32, ptr @q, align 4, !tbaa !9
  %94 = load i32, ptr %13, align 4, !tbaa !9
  %95 = sub nsw i32 %93, %94
  %96 = sext i32 %95 to i64
  %97 = sdiv i64 %92, %96
  store i64 %97, ptr %16, align 8, !tbaa !11
  %98 = load i32, ptr %9, align 4, !tbaa !9
  %99 = sext i32 %98 to i64
  %100 = getelementptr inbounds i64, ptr @sum, i64 %99
  %101 = load i32, ptr %3, align 4, !tbaa !9
  %102 = sext i32 %101 to i64
  %103 = getelementptr inbounds i64, ptr @sum, i64 %102
  call void @llvm.lifetime.start.p0(i64 8, ptr %17) #4
  %104 = load i32, ptr %9, align 4, !tbaa !9
  %105 = sext i32 %104 to i64
  %106 = getelementptr inbounds [1000001 x i64], ptr @sum, i64 0, i64 %105
  %107 = load i64, ptr %106, align 8, !tbaa !11
  %108 = load i64, ptr %16, align 8, !tbaa !11
  %109 = add nsw i64 %107, %108
  store i64 %109, ptr %17, align 8, !tbaa !11
  %110 = call noundef ptr @_ZSt11upper_boundIPxxET_S1_S1_RKT0_(ptr noundef %100, ptr noundef %103, ptr noundef nonnull align 8 dereferenceable(8) %17)
  %111 = ptrtoint ptr %110 to i64
  %112 = sub i64 %111, ptrtoint (ptr @sum to i64)
  %113 = sdiv exact i64 %112, 8
  %114 = sub nsw i64 %113, 1
  %115 = trunc i64 %114 to i32
  store i32 %115, ptr %10, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %17) #4
  %116 = load i32, ptr %10, align 4, !tbaa !9
  %117 = sext i32 %116 to i64
  %118 = getelementptr inbounds [1000001 x i64], ptr @sum, i64 0, i64 %117
  %119 = load i64, ptr %118, align 8, !tbaa !11
  %120 = load i32, ptr %9, align 4, !tbaa !9
  %121 = sext i32 %120 to i64
  %122 = getelementptr inbounds [1000001 x i64], ptr @sum, i64 0, i64 %121
  %123 = load i64, ptr %122, align 8, !tbaa !11
  %124 = sub nsw i64 %119, %123
  store i64 %124, ptr %14, align 8, !tbaa !11
  %125 = load i32, ptr %10, align 4, !tbaa !9
  %126 = load i32, ptr %3, align 4, !tbaa !9
  %127 = icmp slt i32 %125, %126
  br i1 %127, label %128, label %151

128:                                              ; preds = %82
  %129 = load i64, ptr %14, align 8, !tbaa !11
  %130 = load i32, ptr %10, align 4, !tbaa !9
  %131 = sext i32 %130 to i64
  %132 = getelementptr inbounds [1000001 x i32], ptr @seq, i64 0, i64 %131
  %133 = load i32, ptr %132, align 4, !tbaa !9
  %134 = sext i32 %133 to i64
  %135 = add nsw i64 %129, %134
  %136 = load i64, ptr %16, align 8, !tbaa !11
  %137 = sub nsw i64 %135, %136
  %138 = load i64, ptr %16, align 8, !tbaa !11
  %139 = load i64, ptr %14, align 8, !tbaa !11
  %140 = sub nsw i64 %138, %139
  %141 = icmp slt i64 %137, %140
  br i1 %141, label %142, label %151

142:                                              ; preds = %128
  %143 = load i32, ptr %10, align 4, !tbaa !9
  %144 = add nsw i32 %143, 1
  store i32 %144, ptr %10, align 4, !tbaa !9
  %145 = sext i32 %143 to i64
  %146 = getelementptr inbounds [1000001 x i32], ptr @seq, i64 0, i64 %145
  %147 = load i32, ptr %146, align 4, !tbaa !9
  %148 = sext i32 %147 to i64
  %149 = load i64, ptr %14, align 8, !tbaa !11
  %150 = add nsw i64 %149, %148
  store i64 %150, ptr %14, align 8, !tbaa !11
  br label %151

151:                                              ; preds = %142, %128, %82
  %152 = load i32, ptr %10, align 4, !tbaa !9
  %153 = load i32, ptr %9, align 4, !tbaa !9
  %154 = sub nsw i32 %152, %153
  %155 = load i32, ptr %13, align 4, !tbaa !9
  %156 = sext i32 %155 to i64
  %157 = getelementptr inbounds [1001 x i32], ptr @len, i64 0, i64 %156
  store i32 %154, ptr %157, align 4, !tbaa !9
  %158 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3minIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8) %11, ptr noundef nonnull align 8 dereferenceable(8) %14)
  %159 = load i64, ptr %158, align 8, !tbaa !11
  store i64 %159, ptr %11, align 8, !tbaa !11
  %160 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3maxIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8) %12, ptr noundef nonnull align 8 dereferenceable(8) %14)
  %161 = load i64, ptr %160, align 8, !tbaa !11
  store i64 %161, ptr %12, align 8, !tbaa !11
  %162 = load i32, ptr %10, align 4, !tbaa !9
  store i32 %162, ptr %9, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #4
  br label %163

163:                                              ; preds = %151
  %164 = load i32, ptr %13, align 4, !tbaa !9
  %165 = add nsw i32 %164, 1
  store i32 %165, ptr %13, align 4, !tbaa !9
  br label %77, !llvm.loop !15

166:                                              ; preds = %81
  %167 = load i64, ptr %12, align 8, !tbaa !11
  %168 = load i64, ptr %11, align 8, !tbaa !11
  %169 = sub nsw i64 %167, %168
  %170 = load i64, ptr @ans, align 8, !tbaa !11
  %171 = icmp slt i64 %169, %170
  br i1 %171, label %172, label %220

172:                                              ; preds = %166
  %173 = load i64, ptr %12, align 8, !tbaa !11
  %174 = load i64, ptr %11, align 8, !tbaa !11
  %175 = sub nsw i64 %173, %174
  store i64 %175, ptr @ans, align 8, !tbaa !11
  store i32 0, ptr %9, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %18) #4
  store i32 0, ptr %18, align 4, !tbaa !9
  br label %176

176:                                              ; preds = %216, %172
  %177 = load i32, ptr %18, align 4, !tbaa !9
  %178 = load i32, ptr @q, align 4, !tbaa !9
  %179 = icmp slt i32 %177, %178
  br i1 %179, label %181, label %180

180:                                              ; preds = %176
  call void @llvm.lifetime.end.p0(i64 4, ptr %18) #4
  br label %219

181:                                              ; preds = %176
  %182 = load i32, ptr %9, align 4, !tbaa !9
  %183 = load i32, ptr %18, align 4, !tbaa !9
  %184 = sext i32 %183 to i64
  %185 = getelementptr inbounds [1001 x i32], ptr @len, i64 0, i64 %184
  %186 = load i32, ptr %185, align 4, !tbaa !9
  %187 = add nsw i32 %182, %186
  store i32 %187, ptr %10, align 4, !tbaa !9
  br label %188

188:                                              ; preds = %212, %181
  %189 = load i32, ptr %9, align 4, !tbaa !9
  %190 = load i32, ptr %10, align 4, !tbaa !9
  %191 = icmp slt i32 %189, %190
  br i1 %191, label %192, label %215

192:                                              ; preds = %188
  call void @llvm.lifetime.start.p0(i64 4, ptr %19) #4
  %193 = load i32, ptr %9, align 4, !tbaa !9
  %194 = sext i32 %193 to i64
  %195 = getelementptr inbounds [1000001 x i32], ptr @ord, i64 0, i64 %194
  %196 = load i32, ptr %195, align 4, !tbaa !9
  %197 = load i32, ptr @m, align 4, !tbaa !9
  %198 = sdiv i32 %196, %197
  store i32 %198, ptr %19, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %20) #4
  %199 = load i32, ptr %9, align 4, !tbaa !9
  %200 = sext i32 %199 to i64
  %201 = getelementptr inbounds [1000001 x i32], ptr @ord, i64 0, i64 %200
  %202 = load i32, ptr %201, align 4, !tbaa !9
  %203 = load i32, ptr @m, align 4, !tbaa !9
  %204 = srem i32 %202, %203
  store i32 %204, ptr %20, align 4, !tbaa !9
  %205 = load i32, ptr %18, align 4, !tbaa !9
  %206 = load i32, ptr %19, align 4, !tbaa !9
  %207 = sext i32 %206 to i64
  %208 = getelementptr inbounds [1001 x [1001 x i32]], ptr @pos, i64 0, i64 %207
  %209 = load i32, ptr %20, align 4, !tbaa !9
  %210 = sext i32 %209 to i64
  %211 = getelementptr inbounds [1001 x i32], ptr %208, i64 0, i64 %210
  store i32 %205, ptr %211, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %20) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %19) #4
  br label %212

212:                                              ; preds = %192
  %213 = load i32, ptr %9, align 4, !tbaa !9
  %214 = add nsw i32 %213, 1
  store i32 %214, ptr %9, align 4, !tbaa !9
  br label %188, !llvm.loop !16

215:                                              ; preds = %188
  br label %216

216:                                              ; preds = %215
  %217 = load i32, ptr %18, align 4, !tbaa !9
  %218 = add nsw i32 %217, 1
  store i32 %218, ptr %18, align 4, !tbaa !9
  br label %176, !llvm.loop !17

219:                                              ; preds = %180
  br label %220

220:                                              ; preds = %219, %166
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  %221 = load i8, ptr %2, align 1, !tbaa !5, !range !18, !noundef !19
  %222 = trunc i8 %221 to i1
  br i1 %222, label %227, label %223

223:                                              ; preds = %220
  %224 = load i32, ptr %3, align 4, !tbaa !9
  %225 = sext i32 %224 to i64
  %226 = getelementptr inbounds i32, ptr @ord, i64 %225
  call void @_ZSt7reverseIPiEvT_S1_(ptr noundef @ord, ptr noundef %226)
  call void @_Z5solveb(i1 noundef zeroext true)
  br label %227

227:                                              ; preds = %223, %220
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #4
  ret void
}

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

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

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

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

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

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZSt7reverseIPiEvT_S1_(ptr noundef, 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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #3 = { 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 #4 = { nounwind }

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

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


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

@n = external dso_local local_unnamed_addr global i32, align 4
@m = external dso_local local_unnamed_addr global i32, align 4
@q = external dso_local local_unnamed_addr global i32, align 4
@mat = external dso_local local_unnamed_addr global [1001 x [1001 x i32]], align 16
@pos = external dso_local local_unnamed_addr global [1001 x [1001 x i32]], align 16
@ord = external dso_local global [1000001 x i32], align 16
@seq = external dso_local local_unnamed_addr global [1000001 x i32], align 16
@len = external dso_local local_unnamed_addr global [1001 x i32], align 16
@sum = external dso_local global [1000001 x i64], align 16
@ans = external dso_local local_unnamed_addr global i64, align 8

; Function Attrs: mustprogress uwtable
define dso_local void @_Z5solveb(i1 noundef zeroext %0) local_unnamed_addr #0 {
  %2 = alloca i64, align 8
  %3 = alloca i64, align 8
  %4 = alloca i64, align 8
  %5 = alloca i64, align 8
  %6 = load i32, ptr @n, align 4, !tbaa !5
  %7 = load i32, ptr @m, align 4, !tbaa !5
  %8 = mul nsw i32 %7, %6
  %9 = icmp sgt i32 %8, 0
  br i1 %9, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %1
  %wide.trip.count = zext nneg i32 %8 to i64
  %.pre = load i64, ptr @sum, align 16, !tbaa !9
  br label %.lr.ph

._crit_edge:                                      ; preds = %.lr.ph, %1
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %2) #4
  store i64 9223372036854775807, ptr %2, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %3) #4
  store i64 0, ptr %3, align 8, !tbaa !9
  %10 = load i32, ptr @q, align 4, !tbaa !5
  %11 = icmp sgt i32 %10, 0
  br i1 %11, label %.lr.ph61, label %._crit_edge62

.lr.ph61:                                         ; preds = %._crit_edge
  %12 = sext i32 %8 to i64
  %13 = getelementptr inbounds [1000001 x i64], ptr @sum, i64 0, i64 %12
  br label %31

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %14 = phi i64 [ %.pre, %.lr.ph.preheader ], [ %25, %.lr.ph ]
  %indvars.iv = phi i64 [ 0, %.lr.ph.preheader ], [ %indvars.iv.next, %.lr.ph ]
  %15 = getelementptr inbounds [1000001 x i32], ptr @ord, i64 0, i64 %indvars.iv
  %16 = load i32, ptr %15, align 4, !tbaa !5
  %17 = sdiv i32 %16, %7
  %18 = srem i32 %16, %7
  %19 = sext i32 %17 to i64
  %20 = sext i32 %18 to i64
  %21 = getelementptr inbounds [1001 x [1001 x i32]], ptr @mat, i64 0, i64 %19, i64 %20
  %22 = load i32, ptr %21, align 4, !tbaa !5
  %23 = getelementptr inbounds [1000001 x i32], ptr @seq, i64 0, i64 %indvars.iv
  store i32 %22, ptr %23, align 4, !tbaa !5
  %24 = sext i32 %22 to i64
  %25 = add nsw i64 %14, %24
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %26 = getelementptr inbounds [1000001 x i64], ptr @sum, i64 0, i64 %indvars.iv.next
  store i64 %25, ptr %26, align 8, !tbaa !9
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph, !llvm.loop !11

._crit_edge62.loopexit:                           ; preds = %64
  %.pre86 = load i64, ptr %2, align 8, !tbaa !9
  %27 = sub nsw i64 %70, %.pre86
  br label %._crit_edge62

._crit_edge62:                                    ; preds = %._crit_edge62.loopexit, %._crit_edge
  %.lcssa = phi i32 [ %10, %._crit_edge ], [ %71, %._crit_edge62.loopexit ]
  %28 = phi i64 [ -9223372036854775807, %._crit_edge ], [ %27, %._crit_edge62.loopexit ]
  %29 = load i64, ptr @ans, align 8, !tbaa !9
  %30 = icmp slt i64 %28, %29
  br i1 %30, label %74, label %.loopexit

31:                                               ; preds = %.lr.ph61, %64
  %indvars.iv75 = phi i64 [ 0, %.lr.ph61 ], [ %indvars.iv.next76, %64 ]
  %32 = phi i32 [ %10, %.lr.ph61 ], [ %71, %64 ]
  %.04959 = phi i32 [ 0, %.lr.ph61 ], [ %.051, %64 ]
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %4) #4
  store i64 0, ptr %4, align 8, !tbaa !9
  %33 = load i64, ptr %13, align 8, !tbaa !9
  %34 = sext i32 %.04959 to i64
  %35 = getelementptr inbounds [1000001 x i64], ptr @sum, i64 0, i64 %34
  %36 = load i64, ptr %35, align 8, !tbaa !9
  %37 = sub nsw i64 %33, %36
  %38 = trunc nuw nsw i64 %indvars.iv75 to i32
  %39 = sub nsw i32 %32, %38
  %40 = sext i32 %39 to i64
  %41 = sdiv i64 %37, %40
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %5) #4
  %42 = add nsw i64 %41, %36
  store i64 %42, ptr %5, align 8, !tbaa !9
  %43 = call noundef ptr @_ZSt11upper_boundIPxxET_S1_S1_RKT0_(ptr noundef nonnull %35, ptr noundef nonnull %13, ptr noundef nonnull align 8 dereferenceable(8) %5)
  %44 = ptrtoint ptr %43 to i64
  %45 = sub i64 %44, ptrtoint (ptr @sum to i64)
  %46 = lshr exact i64 %45, 3
  %47 = trunc i64 %46 to i32
  %48 = add i32 %47, -1
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %5) #4
  %49 = sext i32 %48 to i64
  %50 = getelementptr inbounds [1000001 x i64], ptr @sum, i64 0, i64 %49
  %51 = load i64, ptr %50, align 8, !tbaa !9
  %52 = load i64, ptr %35, align 8, !tbaa !9
  %53 = sub nsw i64 %51, %52
  store i64 %53, ptr %4, align 8, !tbaa !9
  %54 = icmp slt i32 %48, %8
  br i1 %54, label %55, label %64

55:                                               ; preds = %31
  %56 = getelementptr inbounds [1000001 x i32], ptr @seq, i64 0, i64 %49
  %57 = load i32, ptr %56, align 4, !tbaa !5
  %58 = sext i32 %57 to i64
  %59 = add nsw i64 %53, %58
  %60 = sub nsw i64 %59, %41
  %61 = sub nsw i64 %41, %53
  %62 = icmp slt i64 %60, %61
  br i1 %62, label %63, label %64

63:                                               ; preds = %55
  store i64 %59, ptr %4, align 8, !tbaa !9
  br label %64

64:                                               ; preds = %63, %55, %31
  %.051 = phi i32 [ %47, %63 ], [ %48, %55 ], [ %48, %31 ]
  %65 = sub nsw i32 %.051, %.04959
  %66 = getelementptr inbounds [1001 x i32], ptr @len, i64 0, i64 %indvars.iv75
  store i32 %65, ptr %66, align 4, !tbaa !5
  %67 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3minIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8) %2, ptr noundef nonnull align 8 dereferenceable(8) %4)
  %68 = load i64, ptr %67, align 8, !tbaa !9
  store i64 %68, ptr %2, align 8, !tbaa !9
  %69 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3maxIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8) %3, ptr noundef nonnull align 8 dereferenceable(8) %4)
  %70 = load i64, ptr %69, align 8, !tbaa !9
  store i64 %70, ptr %3, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #4
  %indvars.iv.next76 = add nuw nsw i64 %indvars.iv75, 1
  %71 = load i32, ptr @q, align 4, !tbaa !5
  %72 = sext i32 %71 to i64
  %73 = icmp slt i64 %indvars.iv.next76, %72
  br i1 %73, label %31, label %._crit_edge62.loopexit, !llvm.loop !13

74:                                               ; preds = %._crit_edge62
  store i64 %28, ptr @ans, align 8, !tbaa !9
  %75 = icmp sgt i32 %.lcssa, 0
  br i1 %75, label %.lr.ph71, label %.loopexit

.lr.ph71:                                         ; preds = %74
  %76 = load i32, ptr @m, align 4
  %wide.trip.count84 = zext nneg i32 %.lcssa to i64
  br label %77

77:                                               ; preds = %.lr.ph71, %._crit_edge66
  %indvars.iv81 = phi i64 [ 0, %.lr.ph71 ], [ %indvars.iv.next82, %._crit_edge66 ]
  %.169 = phi i32 [ 0, %.lr.ph71 ], [ %.2.lcssa, %._crit_edge66 ]
  %78 = getelementptr inbounds [1001 x i32], ptr @len, i64 0, i64 %indvars.iv81
  %79 = load i32, ptr %78, align 4, !tbaa !5
  %80 = icmp sgt i32 %79, 0
  br i1 %80, label %.lr.ph65.preheader, label %._crit_edge66

.lr.ph65.preheader:                               ; preds = %77
  %81 = add nsw i32 %79, %.169
  %82 = sext i32 %.169 to i64
  %83 = sext i32 %81 to i64
  %84 = trunc nuw nsw i64 %indvars.iv81 to i32
  br label %.lr.ph65

.lr.ph65:                                         ; preds = %.lr.ph65.preheader, %.lr.ph65
  %indvars.iv78 = phi i64 [ %82, %.lr.ph65.preheader ], [ %indvars.iv.next79, %.lr.ph65 ]
  %85 = getelementptr inbounds [1000001 x i32], ptr @ord, i64 0, i64 %indvars.iv78
  %86 = load i32, ptr %85, align 4, !tbaa !5
  %87 = sdiv i32 %86, %76
  %88 = srem i32 %86, %76
  %89 = sext i32 %87 to i64
  %90 = sext i32 %88 to i64
  %91 = getelementptr inbounds [1001 x [1001 x i32]], ptr @pos, i64 0, i64 %89, i64 %90
  store i32 %84, ptr %91, align 4, !tbaa !5
  %indvars.iv.next79 = add nsw i64 %indvars.iv78, 1
  %92 = icmp slt i64 %indvars.iv.next79, %83
  br i1 %92, label %.lr.ph65, label %._crit_edge66.loopexit, !llvm.loop !14

._crit_edge66.loopexit:                           ; preds = %.lr.ph65
  %93 = trunc nsw i64 %indvars.iv.next79 to i32
  br label %._crit_edge66

._crit_edge66:                                    ; preds = %._crit_edge66.loopexit, %77
  %.2.lcssa = phi i32 [ %.169, %77 ], [ %93, %._crit_edge66.loopexit ]
  %indvars.iv.next82 = add nuw nsw i64 %indvars.iv81, 1
  %exitcond85.not = icmp eq i64 %indvars.iv.next82, %wide.trip.count84
  br i1 %exitcond85.not, label %.loopexit, label %77, !llvm.loop !15

.loopexit:                                        ; preds = %._crit_edge66, %74, %._crit_edge62
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #4
  br i1 %0, label %97, label %94

94:                                               ; preds = %.loopexit
  %95 = sext i32 %8 to i64
  %96 = getelementptr inbounds i32, ptr @ord, i64 %95
  call void @_ZSt7reverseIPiEvT_S1_(ptr noundef nonnull @ord, ptr noundef nonnull %96)
  call void @_Z5solveb(i1 noundef zeroext true)
  br label %97

97:                                               ; preds = %94, %.loopexit
  ret void
}

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

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

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

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

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

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZSt7reverseIPiEvT_S1_(ptr noundef, ptr noundef) 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 nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #3 = { 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 #4 = { nounwind }

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

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


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