; LLVM IR from tangjz/acm-icpc :: lydsy (3739)

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

@mu = external dso_local global [10000001 x i8], align 16
@tot = external dso_local global i32, align 4
@prime = external dso_local global [833333 x i32], align 16
@d = external dso_local global [10000001 x i32], align 16
@c = external dso_local global i32, align 4
@p = external dso_local global [10 x i32], align 16
@q = external dso_local global i32, align 4
@mx = external dso_local global i32, align 4
@a = external dso_local global [1001 x i32], align 16
@ord = external dso_local global [1001 x i32], align 16
@sum = external dso_local global i32, align 4
@idx = external dso_local global i32, align 4
@ans = external dso_local global i32, align 4
@out = external dso_local global [1001 x i32], align 16
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [4 x i8], align 1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_Z3cmpRKiS0_(ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) #0

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z3dfsii(i32 noundef, i32 noundef) #1

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #2 {
  %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
  store i32 0, ptr %1, align 4
  %12 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @q)
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #6
  store i32 0, ptr %2, align 4, !tbaa !5
  br label %13

13:                                               ; preds = %39, %0
  %14 = load i32, ptr %2, align 4, !tbaa !5
  %15 = load i32, ptr @q, align 4, !tbaa !5
  %16 = icmp slt i32 %14, %15
  br i1 %16, label %18, label %17

17:                                               ; preds = %13
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #6
  br label %42

18:                                               ; preds = %13
  %19 = load i32, ptr %2, align 4, !tbaa !5
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds i32, ptr @a, i64 %20
  %22 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %21)
  %23 = load i32, ptr @mx, align 4, !tbaa !5
  %24 = load i32, ptr %2, align 4, !tbaa !5
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds [1001 x i32], ptr @a, i64 0, i64 %25
  %27 = load i32, ptr %26, align 4, !tbaa !5
  %28 = icmp slt i32 %23, %27
  br i1 %28, label %29, label %34

29:                                               ; preds = %18
  %30 = load i32, ptr %2, align 4, !tbaa !5
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds [1001 x i32], ptr @a, i64 0, i64 %31
  %33 = load i32, ptr %32, align 4, !tbaa !5
  store i32 %33, ptr @mx, align 4, !tbaa !5
  br label %34

34:                                               ; preds = %29, %18
  %35 = load i32, ptr %2, align 4, !tbaa !5
  %36 = load i32, ptr %2, align 4, !tbaa !5
  %37 = sext i32 %36 to i64
  %38 = getelementptr inbounds [1001 x i32], ptr @ord, i64 0, i64 %37
  store i32 %35, ptr %38, align 4, !tbaa !5
  br label %39

39:                                               ; preds = %34
  %40 = load i32, ptr %2, align 4, !tbaa !5
  %41 = add nsw i32 %40, 1
  store i32 %41, ptr %2, align 4, !tbaa !5
  br label %13, !llvm.loop !9

42:                                               ; preds = %17
  %43 = load i32, ptr @q, align 4, !tbaa !5
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds i32, ptr @ord, i64 %44
  call void @_ZSt4sortIPiPFbRKiS2_EEvT_S5_T0_(ptr noundef @ord, ptr noundef %45, ptr noundef @_Z3cmpRKiS0_)
  store i8 1, ptr getelementptr inbounds ([10000001 x i8], ptr @mu, i64 0, i64 1), align 1, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #6
  store i32 2, ptr %3, align 4, !tbaa !5
  br label %46

46:                                               ; preds = %128, %42
  %47 = load i32, ptr %3, align 4, !tbaa !5
  %48 = load i32, ptr @mx, align 4, !tbaa !5
  %49 = icmp sle i32 %47, %48
  br i1 %49, label %51, label %50

50:                                               ; preds = %46
  store i32 5, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #6
  br label %131

51:                                               ; preds = %46
  %52 = load i32, ptr %3, align 4, !tbaa !5
  %53 = sext i32 %52 to i64
  %54 = getelementptr inbounds [10000001 x i32], ptr @d, i64 0, i64 %53
  %55 = load i32, ptr %54, align 4, !tbaa !5
  %56 = icmp ne i32 %55, 0
  br i1 %56, label %69, label %57

57:                                               ; preds = %51
  %58 = load i32, ptr %3, align 4, !tbaa !5
  %59 = sext i32 %58 to i64
  %60 = getelementptr inbounds [10000001 x i8], ptr @mu, i64 0, i64 %59
  store i8 -1, ptr %60, align 1, !tbaa !11
  %61 = load i32, ptr %3, align 4, !tbaa !5
  %62 = load i32, ptr %3, align 4, !tbaa !5
  %63 = sext i32 %62 to i64
  %64 = getelementptr inbounds [10000001 x i32], ptr @d, i64 0, i64 %63
  store i32 %61, ptr %64, align 4, !tbaa !5
  %65 = load i32, ptr @tot, align 4, !tbaa !5
  %66 = add nsw i32 %65, 1
  store i32 %66, ptr @tot, align 4, !tbaa !5
  %67 = sext i32 %65 to i64
  %68 = getelementptr inbounds [833333 x i32], ptr @prime, i64 0, i64 %67
  store i32 %61, ptr %68, align 4, !tbaa !5
  br label %69

69:                                               ; preds = %57, %51
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #6
  store i32 0, ptr %5, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #6
  %70 = load i32, ptr @mx, align 4, !tbaa !5
  %71 = load i32, ptr %3, align 4, !tbaa !5
  %72 = sdiv i32 %70, %71
  store i32 %72, ptr %6, align 4, !tbaa !5
  br label %73

73:                                               ; preds = %123, %69
  %74 = load i32, ptr %5, align 4, !tbaa !5
  %75 = sext i32 %74 to i64
  %76 = getelementptr inbounds [833333 x i32], ptr @prime, i64 0, i64 %75
  %77 = load i32, ptr %76, align 4, !tbaa !5
  %78 = load i32, ptr %6, align 4, !tbaa !5
  %79 = icmp sle i32 %77, %78
  br i1 %79, label %81, label %80

80:                                               ; preds = %73
  store i32 8, ptr %4, align 4
  br label %126

81:                                               ; preds = %73
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #6
  %82 = load i32, ptr %3, align 4, !tbaa !5
  %83 = load i32, ptr %5, align 4, !tbaa !5
  %84 = sext i32 %83 to i64
  %85 = getelementptr inbounds [833333 x i32], ptr @prime, i64 0, i64 %84
  %86 = load i32, ptr %85, align 4, !tbaa !5
  %87 = mul nsw i32 %82, %86
  store i32 %87, ptr %7, align 4, !tbaa !5
  %88 = load i32, ptr %5, align 4, !tbaa !5
  %89 = sext i32 %88 to i64
  %90 = getelementptr inbounds [833333 x i32], ptr @prime, i64 0, i64 %89
  %91 = load i32, ptr %90, align 4, !tbaa !5
  %92 = load i32, ptr %7, align 4, !tbaa !5
  %93 = sext i32 %92 to i64
  %94 = getelementptr inbounds [10000001 x i32], ptr @d, i64 0, i64 %93
  store i32 %91, ptr %94, align 4, !tbaa !5
  %95 = load i32, ptr %3, align 4, !tbaa !5
  %96 = sext i32 %95 to i64
  %97 = getelementptr inbounds [10000001 x i32], ptr @d, i64 0, i64 %96
  %98 = load i32, ptr %97, align 4, !tbaa !5
  %99 = load i32, ptr %5, align 4, !tbaa !5
  %100 = sext i32 %99 to i64
  %101 = getelementptr inbounds [833333 x i32], ptr @prime, i64 0, i64 %100
  %102 = load i32, ptr %101, align 4, !tbaa !5
  %103 = icmp eq i32 %98, %102
  br i1 %103, label %104, label %108

104:                                              ; preds = %81
  %105 = load i32, ptr %7, align 4, !tbaa !5
  %106 = sext i32 %105 to i64
  %107 = getelementptr inbounds [10000001 x i8], ptr @mu, i64 0, i64 %106
  store i8 0, ptr %107, align 1, !tbaa !11
  store i32 8, ptr %4, align 4
  br label %120

108:                                              ; preds = %81
  %109 = load i32, ptr %3, align 4, !tbaa !5
  %110 = sext i32 %109 to i64
  %111 = getelementptr inbounds [10000001 x i8], ptr @mu, i64 0, i64 %110
  %112 = load i8, ptr %111, align 1, !tbaa !11
  %113 = sext i8 %112 to i32
  %114 = sub nsw i32 0, %113
  %115 = trunc i32 %114 to i8
  %116 = load i32, ptr %7, align 4, !tbaa !5
  %117 = sext i32 %116 to i64
  %118 = getelementptr inbounds [10000001 x i8], ptr @mu, i64 0, i64 %117
  store i8 %115, ptr %118, align 1, !tbaa !11
  br label %119

119:                                              ; preds = %108
  store i32 0, ptr %4, align 4
  br label %120

120:                                              ; preds = %119, %104
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #6
  %121 = load i32, ptr %4, align 4
  switch i32 %121, label %126 [
    i32 0, label %122
  ]

122:                                              ; preds = %120
  br label %123

123:                                              ; preds = %122
  %124 = load i32, ptr %5, align 4, !tbaa !5
  %125 = add nsw i32 %124, 1
  store i32 %125, ptr %5, align 4, !tbaa !5
  br label %73, !llvm.loop !12

126:                                              ; preds = %120, %80
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #6
  br label %127

127:                                              ; preds = %126
  br label %128

128:                                              ; preds = %127
  %129 = load i32, ptr %3, align 4, !tbaa !5
  %130 = add nsw i32 %129, 1
  store i32 %130, ptr %3, align 4, !tbaa !5
  br label %46, !llvm.loop !13

131:                                              ; preds = %50
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #6
  store i32 0, ptr %8, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #6
  store i32 0, ptr %9, align 4, !tbaa !5
  br label %132

132:                                              ; preds = %215, %131
  %133 = load i32, ptr %8, align 4, !tbaa !5
  %134 = load i32, ptr @mx, align 4, !tbaa !5
  %135 = icmp sle i32 %133, %134
  br i1 %135, label %137, label %136

136:                                              ; preds = %132
  store i32 11, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #6
  br label %218

137:                                              ; preds = %132
  %138 = load i32, ptr %8, align 4, !tbaa !5
  %139 = sext i32 %138 to i64
  %140 = getelementptr inbounds [10000001 x i8], ptr @mu, i64 0, i64 %139
  %141 = load i8, ptr %140, align 1, !tbaa !11
  %142 = icmp ne i8 %141, 0
  br i1 %142, label %143, label %186

143:                                              ; preds = %137
  store i32 0, ptr @c, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #6
  %144 = load i32, ptr %8, align 4, !tbaa !5
  store i32 %144, ptr %10, align 4, !tbaa !5
  br label %145

145:                                              ; preds = %153, %143
  %146 = load i32, ptr %10, align 4, !tbaa !5
  %147 = sext i32 %146 to i64
  %148 = getelementptr inbounds [10000001 x i32], ptr @d, i64 0, i64 %147
  %149 = load i32, ptr %148, align 4, !tbaa !5
  %150 = icmp ne i32 %149, 0
  br i1 %150, label %152, label %151

151:                                              ; preds = %145
  store i32 14, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #6
  br label %168

152:                                              ; preds = %145
  br label %153

153:                                              ; preds = %152
  %154 = load i32, ptr %10, align 4, !tbaa !5
  %155 = sext i32 %154 to i64
  %156 = getelementptr inbounds [10000001 x i32], ptr @d, i64 0, i64 %155
  %157 = load i32, ptr %156, align 4, !tbaa !5
  %158 = load i32, ptr @c, align 4, !tbaa !5
  %159 = add nsw i32 %158, 1
  store i32 %159, ptr @c, align 4, !tbaa !5
  %160 = sext i32 %158 to i64
  %161 = getelementptr inbounds [10 x i32], ptr @p, i64 0, i64 %160
  store i32 %157, ptr %161, align 4, !tbaa !5
  %162 = load i32, ptr %10, align 4, !tbaa !5
  %163 = sext i32 %162 to i64
  %164 = getelementptr inbounds [10000001 x i32], ptr @d, i64 0, i64 %163
  %165 = load i32, ptr %164, align 4, !tbaa !5
  %166 = load i32, ptr %10, align 4, !tbaa !5
  %167 = sdiv i32 %166, %165
  store i32 %167, ptr %10, align 4, !tbaa !5
  br label %145, !llvm.loop !14

168:                                              ; preds = %151
  store i32 0, ptr @sum, align 4, !tbaa !5
  %169 = load i32, ptr %8, align 4, !tbaa !5
  store i32 %169, ptr @idx, align 4, !tbaa !5
  call void @_Z3dfsii(i32 noundef 0, i32 noundef 1)
  %170 = load i32, ptr %8, align 4, !tbaa !5
  %171 = sext i32 %170 to i64
  %172 = getelementptr inbounds [10000001 x i8], ptr @mu, i64 0, i64 %171
  %173 = load i8, ptr %172, align 1, !tbaa !11
  %174 = sext i8 %173 to i32
  %175 = icmp sgt i32 %174, 0
  br i1 %175, label %176, label %180

176:                                              ; preds = %168
  %177 = load i32, ptr @sum, align 4, !tbaa !5
  %178 = load i32, ptr @ans, align 4, !tbaa !5
  %179 = add nsw i32 %178, %177
  store i32 %179, ptr @ans, align 4, !tbaa !5
  br label %184

180:                                              ; preds = %168
  %181 = load i32, ptr @sum, align 4, !tbaa !5
  %182 = load i32, ptr @ans, align 4, !tbaa !5
  %183 = sub nsw i32 %182, %181
  store i32 %183, ptr @ans, align 4, !tbaa !5
  br label %184

184:                                              ; preds = %180, %176
  %185 = phi ptr [ @ans, %176 ], [ @ans, %180 ]
  br label %186

186:                                              ; preds = %184, %137
  br label %187

187:                                              ; preds = %211, %186
  %188 = load i32, ptr %9, align 4, !tbaa !5
  %189 = load i32, ptr @q, align 4, !tbaa !5
  %190 = icmp slt i32 %188, %189
  br i1 %190, label %191, label %201

191:                                              ; preds = %187
  %192 = load i32, ptr %9, align 4, !tbaa !5
  %193 = sext i32 %192 to i64
  %194 = getelementptr inbounds [1001 x i32], ptr @ord, i64 0, i64 %193
  %195 = load i32, ptr %194, align 4, !tbaa !5
  %196 = sext i32 %195 to i64
  %197 = getelementptr inbounds [1001 x i32], ptr @a, i64 0, i64 %196
  %198 = load i32, ptr %197, align 4, !tbaa !5
  %199 = load i32, ptr %8, align 4, !tbaa !5
  %200 = icmp eq i32 %198, %199
  br label %201

201:                                              ; preds = %191, %187
  %202 = phi i1 [ false, %187 ], [ %200, %191 ]
  br i1 %202, label %203, label %214

203:                                              ; preds = %201
  %204 = load i32, ptr @ans, align 4, !tbaa !5
  %205 = load i32, ptr %9, align 4, !tbaa !5
  %206 = sext i32 %205 to i64
  %207 = getelementptr inbounds [1001 x i32], ptr @ord, i64 0, i64 %206
  %208 = load i32, ptr %207, align 4, !tbaa !5
  %209 = sext i32 %208 to i64
  %210 = getelementptr inbounds [1001 x i32], ptr @out, i64 0, i64 %209
  store i32 %204, ptr %210, align 4, !tbaa !5
  br label %211

211:                                              ; preds = %203
  %212 = load i32, ptr %9, align 4, !tbaa !5
  %213 = add nsw i32 %212, 1
  store i32 %213, ptr %9, align 4, !tbaa !5
  br label %187, !llvm.loop !15

214:                                              ; preds = %201
  br label %215

215:                                              ; preds = %214
  %216 = load i32, ptr %8, align 4, !tbaa !5
  %217 = add nsw i32 %216, 1
  store i32 %217, ptr %8, align 4, !tbaa !5
  br label %132, !llvm.loop !16

218:                                              ; preds = %136
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #6
  store i32 0, ptr %11, align 4, !tbaa !5
  br label %219

219:                                              ; preds = %230, %218
  %220 = load i32, ptr %11, align 4, !tbaa !5
  %221 = load i32, ptr @q, align 4, !tbaa !5
  %222 = icmp slt i32 %220, %221
  br i1 %222, label %224, label %223

223:                                              ; preds = %219
  store i32 20, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #6
  br label %233

224:                                              ; preds = %219
  %225 = load i32, ptr %11, align 4, !tbaa !5
  %226 = sext i32 %225 to i64
  %227 = getelementptr inbounds [1001 x i32], ptr @out, i64 0, i64 %226
  %228 = load i32, ptr %227, align 4, !tbaa !5
  %229 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i32 noundef %228)
  br label %230

230:                                              ; preds = %224
  %231 = load i32, ptr %11, align 4, !tbaa !5
  %232 = add nsw i32 %231, 1
  store i32 %232, ptr %11, align 4, !tbaa !5
  br label %219, !llvm.loop !17

233:                                              ; preds = %223
  ret i32 0
}

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

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

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

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZSt4sortIPiPFbRKiS2_EEvT_S5_T0_(ptr noundef, ptr noundef, ptr noundef) #5

declare i32 @printf(ptr noundef, ...) #3

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

@mu = external dso_local local_unnamed_addr global [10000001 x i8], align 16
@tot = external dso_local local_unnamed_addr global i32, align 4
@prime = external dso_local local_unnamed_addr global [833333 x i32], align 16
@d = external dso_local local_unnamed_addr global [10000001 x i32], align 16
@c = external dso_local local_unnamed_addr global i32, align 4
@p = external dso_local local_unnamed_addr global [10 x i32], align 16
@q = external dso_local global i32, align 4
@mx = external dso_local local_unnamed_addr global i32, align 4
@a = external dso_local global [1001 x i32], align 16
@ord = external dso_local global [1001 x i32], align 16
@sum = external dso_local local_unnamed_addr global i32, align 4
@idx = external dso_local local_unnamed_addr global i32, align 4
@ans = external dso_local local_unnamed_addr global i32, align 4
@out = external dso_local local_unnamed_addr global [1001 x i32], align 16
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [4 x i8], align 1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_Z3cmpRKiS0_(ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) #0

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z3dfsii(i32 noundef, i32 noundef) local_unnamed_addr #1

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

.._crit_edge_crit_edge:                           ; preds = %0
  %.pre117 = sext i32 %2 to i64
  br label %._crit_edge

._crit_edge:                                      ; preds = %13, %.._crit_edge_crit_edge
  %.pre-phi = phi i64 [ %.pre117, %.._crit_edge_crit_edge ], [ %17, %13 ]
  %4 = getelementptr inbounds i32, ptr @ord, i64 %.pre-phi
  tail call void @_ZSt4sortIPiPFbRKiS2_EEvT_S5_T0_(ptr noundef nonnull @ord, ptr noundef nonnull %4, ptr noundef nonnull @_Z3cmpRKiS0_)
  store i8 1, ptr getelementptr inbounds (i8, ptr @mu, i64 1), align 1, !tbaa !9
  %5 = load i32, ptr @mx, align 4, !tbaa !5
  %.not69 = icmp slt i32 %5, 2
  br i1 %.not69, label %.preheader62, label %.lr.ph73.preheader

.lr.ph73.preheader:                               ; preds = %._crit_edge
  %tot.promoted = load i32, ptr @tot, align 4, !tbaa !5
  %6 = add nuw i32 %5, 1
  %wide.trip.count = zext i32 %6 to i64
  br label %.lr.ph73

.lr.ph:                                           ; preds = %0, %13
  %indvars.iv = phi i64 [ %indvars.iv.next, %13 ], [ 0, %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 @mx, align 4, !tbaa !5
  %10 = load i32, ptr %7, align 4, !tbaa !5
  %11 = icmp slt i32 %9, %10
  br i1 %11, label %12, label %13

12:                                               ; preds = %.lr.ph
  store i32 %10, ptr @mx, align 4, !tbaa !5
  br label %13

13:                                               ; preds = %12, %.lr.ph
  %14 = getelementptr inbounds [1001 x i32], ptr @ord, i64 0, i64 %indvars.iv
  %15 = trunc nuw nsw i64 %indvars.iv to i32
  store i32 %15, ptr %14, align 4, !tbaa !5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %16 = load i32, ptr @q, align 4, !tbaa !5
  %17 = sext i32 %16 to i64
  %18 = icmp slt i64 %indvars.iv.next, %17
  br i1 %18, label %.lr.ph, label %._crit_edge, !llvm.loop !10

.preheader62:                                     ; preds = %.loopexit, %._crit_edge
  %.not5686 = icmp slt i32 %5, 0
  br i1 %.not5686, label %.preheader62..preheader_crit_edge, label %.lr.ph89

.preheader62..preheader_crit_edge:                ; preds = %.preheader62
  %.pre = load i32, ptr @q, align 4, !tbaa !5
  br label %.preheader

.lr.ph73:                                         ; preds = %.lr.ph73.preheader, %.loopexit
  %indvars.iv100 = phi i64 [ 2, %.lr.ph73.preheader ], [ %indvars.iv.next101, %.loopexit ]
  %19 = phi i32 [ %tot.promoted, %.lr.ph73.preheader ], [ %29, %.loopexit ]
  %20 = getelementptr inbounds [10000001 x i32], ptr @d, i64 0, i64 %indvars.iv100
  %21 = load i32, ptr %20, align 4, !tbaa !5
  %.not59 = icmp eq i32 %21, 0
  br i1 %.not59, label %22, label %.lr.ph73._crit_edge

.lr.ph73._crit_edge:                              ; preds = %.lr.ph73
  %.pre120 = trunc nuw nsw i64 %indvars.iv100 to i32
  br label %28

22:                                               ; preds = %.lr.ph73
  %23 = getelementptr inbounds [10000001 x i8], ptr @mu, i64 0, i64 %indvars.iv100
  store i8 -1, ptr %23, align 1, !tbaa !9
  %24 = trunc nuw nsw i64 %indvars.iv100 to i32
  store i32 %24, ptr %20, align 4, !tbaa !5
  %25 = add nsw i32 %19, 1
  store i32 %25, ptr @tot, align 4, !tbaa !5
  %26 = sext i32 %19 to i64
  %27 = getelementptr inbounds [833333 x i32], ptr @prime, i64 0, i64 %26
  store i32 %24, ptr %27, align 4, !tbaa !5
  br label %28

28:                                               ; preds = %.lr.ph73._crit_edge, %22
  %.pre-phi121 = phi i32 [ %.pre120, %.lr.ph73._crit_edge ], [ %24, %22 ]
  %29 = phi i32 [ %19, %.lr.ph73._crit_edge ], [ %25, %22 ]
  %30 = sdiv i32 %5, %.pre-phi121
  %31 = load i32, ptr @prime, align 16, !tbaa !5
  %.not6065 = icmp sgt i32 %31, %30
  br i1 %.not6065, label %.loopexit, label %.lr.ph68

.lr.ph68:                                         ; preds = %28
  %32 = getelementptr inbounds [10000001 x i8], ptr @mu, i64 0, i64 %indvars.iv100
  br label %33

33:                                               ; preds = %.lr.ph68, %40
  %indvars.iv97 = phi i64 [ 0, %.lr.ph68 ], [ %indvars.iv.next98, %40 ]
  %34 = phi i32 [ %31, %.lr.ph68 ], [ %45, %40 ]
  %35 = mul nsw i32 %34, %.pre-phi121
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds [10000001 x i32], ptr @d, i64 0, i64 %36
  store i32 %34, ptr %37, align 4, !tbaa !5
  %38 = load i32, ptr %20, align 4, !tbaa !5
  %.not61 = icmp eq i32 %38, %34
  br i1 %.not61, label %.thread, label %40

.thread:                                          ; preds = %33
  %39 = getelementptr inbounds [10000001 x i8], ptr @mu, i64 0, i64 %36
  store i8 0, ptr %39, align 1, !tbaa !9
  br label %.loopexit

40:                                               ; preds = %33
  %41 = load i8, ptr %32, align 1, !tbaa !9
  %42 = sub i8 0, %41
  %43 = getelementptr inbounds [10000001 x i8], ptr @mu, i64 0, i64 %36
  store i8 %42, ptr %43, align 1, !tbaa !9
  %indvars.iv.next98 = add nuw nsw i64 %indvars.iv97, 1
  %44 = getelementptr inbounds [833333 x i32], ptr @prime, i64 0, i64 %indvars.iv.next98
  %45 = load i32, ptr %44, align 4, !tbaa !5
  %.not60 = icmp sgt i32 %45, %30
  br i1 %.not60, label %.loopexit, label %33, !llvm.loop !12

.loopexit:                                        ; preds = %40, %28, %.thread
  %indvars.iv.next101 = add nuw nsw i64 %indvars.iv100, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next101, %wide.trip.count
  br i1 %exitcond.not, label %.preheader62, label %.lr.ph73, !llvm.loop !13

.preheader:                                       ; preds = %.critedge, %.preheader62..preheader_crit_edge
  %46 = phi i32 [ %.pre, %.preheader62..preheader_crit_edge ], [ %66, %.critedge ]
  %47 = icmp sgt i32 %46, 0
  br i1 %47, label %.lr.ph91, label %._crit_edge92

.lr.ph89:                                         ; preds = %.preheader62, %.critedge
  %indvars.iv110 = phi i64 [ %indvars.iv.next111, %.critedge ], [ 0, %.preheader62 ]
  %.04688 = phi i32 [ %.1.lcssa, %.critedge ], [ 0, %.preheader62 ]
  %48 = getelementptr inbounds [10000001 x i8], ptr @mu, i64 0, i64 %indvars.iv110
  %49 = load i8, ptr %48, align 1, !tbaa !9
  %.not57 = icmp eq i8 %49, 0
  br i1 %.not57, label %65, label %50

50:                                               ; preds = %.lr.ph89
  store i32 0, ptr @c, align 4, !tbaa !5
  %51 = getelementptr inbounds [10000001 x i32], ptr @d, i64 0, i64 %indvars.iv110
  %52 = load i32, ptr %51, align 4, !tbaa !5
  %.not5874 = icmp eq i32 %52, 0
  %.pre118 = trunc nuw nsw i64 %indvars.iv110 to i32
  br i1 %.not5874, label %._crit_edge116, label %.lr.ph77

._crit_edge78:                                    ; preds = %.lr.ph77
  %53 = trunc nuw i64 %indvars.iv.next104 to i32
  store i32 %53, ptr @c, align 4, !tbaa !5
  br label %._crit_edge116

._crit_edge116:                                   ; preds = %50, %._crit_edge78
  store i32 0, ptr @sum, align 4, !tbaa !5
  store i32 %.pre118, ptr @idx, align 4, !tbaa !5
  tail call void @_Z3dfsii(i32 noundef 0, i32 noundef 1)
  %54 = load i8, ptr %48, align 1, !tbaa !9
  %55 = icmp sgt i8 %54, 0
  %56 = load i32, ptr @sum, align 4, !tbaa !5
  %57 = load i32, ptr @ans, align 4, !tbaa !5
  %58 = sub i32 0, %56
  %.sink.p = select i1 %55, i32 %56, i32 %58
  %.sink = add i32 %57, %.sink.p
  store i32 %.sink, ptr @ans, align 4, !tbaa !5
  br label %65

.lr.ph77:                                         ; preds = %50, %.lr.ph77
  %indvars.iv103 = phi i64 [ %indvars.iv.next104, %.lr.ph77 ], [ 0, %50 ]
  %59 = phi i32 [ %64, %.lr.ph77 ], [ %52, %50 ]
  %.04575 = phi i32 [ %61, %.lr.ph77 ], [ %.pre118, %50 ]
  %indvars.iv.next104 = add nuw nsw i64 %indvars.iv103, 1
  %60 = getelementptr inbounds [10 x i32], ptr @p, i64 0, i64 %indvars.iv103
  store i32 %59, ptr %60, align 4, !tbaa !5
  %61 = sdiv i32 %.04575, %59
  %62 = sext i32 %61 to i64
  %63 = getelementptr inbounds [10000001 x i32], ptr @d, i64 0, i64 %62
  %64 = load i32, ptr %63, align 4, !tbaa !5
  %.not58 = icmp eq i32 %64, 0
  br i1 %.not58, label %._crit_edge78, label %.lr.ph77, !llvm.loop !14

65:                                               ; preds = %._crit_edge116, %.lr.ph89
  %66 = load i32, ptr @q, align 4, !tbaa !5
  %67 = icmp slt i32 %.04688, %66
  br i1 %67, label %.lr.ph82, label %.critedge

.lr.ph82:                                         ; preds = %65
  %68 = load i32, ptr @ans, align 4
  %69 = sext i32 %.04688 to i64
  %70 = sext i32 %66 to i64
  br label %71

71:                                               ; preds = %.lr.ph82, %79
  %indvars.iv106 = phi i64 [ %69, %.lr.ph82 ], [ %indvars.iv.next107, %79 ]
  %72 = getelementptr inbounds [1001 x i32], ptr @ord, i64 0, i64 %indvars.iv106
  %73 = load i32, ptr %72, align 4, !tbaa !5
  %74 = sext i32 %73 to i64
  %75 = getelementptr inbounds [1001 x i32], ptr @a, i64 0, i64 %74
  %76 = load i32, ptr %75, align 4, !tbaa !5
  %77 = zext i32 %76 to i64
  %78 = icmp eq i64 %indvars.iv110, %77
  br i1 %78, label %79, label %.critedge.loopexit.split.loop.exit

79:                                               ; preds = %71
  %80 = getelementptr inbounds [1001 x i32], ptr @out, i64 0, i64 %74
  store i32 %68, ptr %80, align 4, !tbaa !5
  %indvars.iv.next107 = add nsw i64 %indvars.iv106, 1
  %exitcond109.not = icmp eq i64 %indvars.iv.next107, %70
  br i1 %exitcond109.not, label %.critedge, label %71, !llvm.loop !15

.critedge.loopexit.split.loop.exit:               ; preds = %71
  %81 = trunc nsw i64 %indvars.iv106 to i32
  br label %.critedge

.critedge:                                        ; preds = %79, %.critedge.loopexit.split.loop.exit, %65
  %.1.lcssa = phi i32 [ %.04688, %65 ], [ %81, %.critedge.loopexit.split.loop.exit ], [ %66, %79 ]
  %indvars.iv.next111 = add nuw nsw i64 %indvars.iv110, 1
  %82 = load i32, ptr @mx, align 4, !tbaa !5
  %83 = sext i32 %82 to i64
  %.not56.not = icmp slt i64 %indvars.iv110, %83
  br i1 %.not56.not, label %.lr.ph89, label %.preheader, !llvm.loop !16

._crit_edge92:                                    ; preds = %.lr.ph91, %.preheader
  ret i32 0

.lr.ph91:                                         ; preds = %.preheader, %.lr.ph91
  %indvars.iv113 = phi i64 [ %indvars.iv.next114, %.lr.ph91 ], [ 0, %.preheader ]
  %84 = getelementptr inbounds [1001 x i32], ptr @out, i64 0, i64 %indvars.iv113
  %85 = load i32, ptr %84, align 4, !tbaa !5
  %86 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i32 noundef %85)
  %indvars.iv.next114 = add nuw nsw i64 %indvars.iv113, 1
  %87 = load i32, ptr @q, align 4, !tbaa !5
  %88 = sext i32 %87 to i64
  %89 = icmp slt i64 %indvars.iv.next114, %88
  br i1 %89, label %.lr.ph91, label %._crit_edge92, !llvm.loop !17
}

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

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZSt4sortIPiPFbRKiS2_EEvT_S5_T0_(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #4

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

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

!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 = !{!7, !7, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}
!12 = distinct !{!12, !11}
!13 = distinct !{!13, !11}
!14 = distinct !{!14, !11}
!15 = distinct !{!15, !11}
!16 = distinct !{!16, !11}
!17 = distinct !{!17, !11}


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