; LLVM IR from tangjz/acm-icpc :: 51nod (1038)

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

@tot = external dso_local global i32, align 4
@prime = external dso_local global [32000 x i32], align 16
@t = external dso_local global i32, align 4
@p = external dso_local global i32, align 4
@a = external dso_local global i32, align 4
@b = external dso_local global i32, align 4
@g = external dso_local global i32, align 4
@ans = external dso_local global [32000 x i32], align 16
@vis = external dso_local global [32000 x i8], align 16
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [12 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [3 x i8], align 1

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_Z5exgcdiiRiS_(i32 noundef, i32 noundef, ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) #0

; 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: mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z7mod_powiii(i32 noundef, i32 noundef, i32 noundef) #2

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_Z3oriii(i32 noundef, i32 noundef) #2

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

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

16:                                               ; preds = %13
  store i32 2, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #6
  br label %73

17:                                               ; preds = %13
  %18 = load i32, ptr %2, align 4, !tbaa !5
  %19 = sext i32 %18 to i64
  %20 = getelementptr inbounds [32000 x i8], ptr @vis, i64 0, i64 %19
  %21 = load i8, ptr %20, align 1, !tbaa !9, !range !11, !noundef !12
  %22 = trunc i8 %21 to i1
  br i1 %22, label %29, label %23

23:                                               ; preds = %17
  %24 = load i32, ptr %2, align 4, !tbaa !5
  %25 = load i32, ptr @tot, align 4, !tbaa !5
  %26 = add nsw i32 %25, 1
  store i32 %26, ptr @tot, align 4, !tbaa !5
  %27 = sext i32 %25 to i64
  %28 = getelementptr inbounds [32000 x i32], ptr @prime, i64 0, i64 %27
  store i32 %24, ptr %28, align 4, !tbaa !5
  br label %29

29:                                               ; preds = %23, %17
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #6
  store i32 0, ptr %4, align 4, !tbaa !5
  br label %30

30:                                               ; preds = %65, %29
  %31 = load i32, ptr %4, align 4, !tbaa !5
  %32 = load i32, ptr @tot, align 4, !tbaa !5
  %33 = icmp slt i32 %31, %32
  br i1 %33, label %34, label %44

34:                                               ; preds = %30
  %35 = load i32, ptr %2, align 4, !tbaa !5
  %36 = sext i32 %35 to i64
  %37 = load i32, ptr %4, align 4, !tbaa !5
  %38 = sext i32 %37 to i64
  %39 = getelementptr inbounds [32000 x i32], ptr @prime, i64 0, i64 %38
  %40 = load i32, ptr %39, align 4, !tbaa !5
  %41 = sext i32 %40 to i64
  %42 = mul nsw i64 %36, %41
  %43 = icmp slt i64 %42, 32000
  br label %44

44:                                               ; preds = %34, %30
  %45 = phi i1 [ false, %30 ], [ %43, %34 ]
  br i1 %45, label %47, label %46

46:                                               ; preds = %44
  store i32 5, ptr %3, align 4
  br label %68

47:                                               ; preds = %44
  %48 = load i32, ptr %2, align 4, !tbaa !5
  %49 = load i32, ptr %4, align 4, !tbaa !5
  %50 = sext i32 %49 to i64
  %51 = getelementptr inbounds [32000 x i32], ptr @prime, i64 0, i64 %50
  %52 = load i32, ptr %51, align 4, !tbaa !5
  %53 = mul nsw i32 %48, %52
  %54 = sext i32 %53 to i64
  %55 = getelementptr inbounds [32000 x i8], ptr @vis, i64 0, i64 %54
  store i8 1, ptr %55, align 1, !tbaa !9
  %56 = load i32, ptr %2, align 4, !tbaa !5
  %57 = load i32, ptr %4, align 4, !tbaa !5
  %58 = sext i32 %57 to i64
  %59 = getelementptr inbounds [32000 x i32], ptr @prime, i64 0, i64 %58
  %60 = load i32, ptr %59, align 4, !tbaa !5
  %61 = srem i32 %56, %60
  %62 = icmp eq i32 %61, 0
  br i1 %62, label %63, label %64

63:                                               ; preds = %47
  store i32 5, ptr %3, align 4
  br label %68

64:                                               ; preds = %47
  br label %65

65:                                               ; preds = %64
  %66 = load i32, ptr %4, align 4, !tbaa !5
  %67 = add nsw i32 %66, 1
  store i32 %67, ptr %4, align 4, !tbaa !5
  br label %30, !llvm.loop !13

68:                                               ; preds = %63, %46
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #6
  br label %69

69:                                               ; preds = %68
  br label %70

70:                                               ; preds = %69
  %71 = load i32, ptr %2, align 4, !tbaa !5
  %72 = add nsw i32 %71, 1
  store i32 %72, ptr %2, align 4, !tbaa !5
  br label %13, !llvm.loop !15

73:                                               ; preds = %16
  %74 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @t)
  br label %75

75:                                               ; preds = %184, %182, %73
  %76 = load i32, ptr @t, align 4, !tbaa !5
  %77 = add nsw i32 %76, -1
  store i32 %77, ptr @t, align 4, !tbaa !5
  %78 = icmp ne i32 %76, 0
  br i1 %78, label %79, label %185

79:                                               ; preds = %75
  %80 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef @p, ptr noundef @a, ptr noundef @b)
  store i32 2, ptr @g, align 4, !tbaa !5
  br label %81

81:                                               ; preds = %87, %79
  %82 = load i32, ptr @g, align 4, !tbaa !5
  %83 = load i32, ptr @p, align 4, !tbaa !5
  %84 = call noundef zeroext i1 @_Z3oriii(i32 noundef %82, i32 noundef %83)
  br i1 %84, label %85, label %86

85:                                               ; preds = %81
  br label %90

86:                                               ; preds = %81
  br label %87

87:                                               ; preds = %86
  %88 = load i32, ptr @g, align 4, !tbaa !5
  %89 = add nsw i32 %88, 1
  store i32 %89, ptr @g, align 4, !tbaa !5
  br label %81, !llvm.loop !16

90:                                               ; preds = %85
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #6
  %91 = load i32, ptr @g, align 4, !tbaa !5
  %92 = load i32, ptr @p, align 4, !tbaa !5
  %93 = load i32, ptr @b, align 4, !tbaa !5
  %94 = call noundef i32 @_Z4bsgsiii(i32 noundef %91, i32 noundef %92, i32 noundef %93)
  store i32 %94, ptr %5, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #6
  %95 = load i32, ptr @a, align 4, !tbaa !5
  store i32 %95, ptr %6, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #6
  %96 = load i32, ptr @p, align 4, !tbaa !5
  %97 = sub nsw i32 %96, 1
  store i32 %97, ptr %7, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #6
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #6
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #6
  %98 = load i32, ptr %6, align 4, !tbaa !5
  %99 = load i32, ptr %7, align 4, !tbaa !5
  %100 = call noundef i32 @_Z5exgcdiiRiS_(i32 noundef %98, i32 noundef %99, ptr noundef nonnull align 4 dereferenceable(4) %8, ptr noundef nonnull align 4 dereferenceable(4) %9)
  store i32 %100, ptr %10, align 4, !tbaa !5
  %101 = load i32, ptr %5, align 4, !tbaa !5
  %102 = icmp eq i32 %101, -1
  br i1 %102, label %108, label %103

103:                                              ; preds = %90
  %104 = load i32, ptr %5, align 4, !tbaa !5
  %105 = load i32, ptr %10, align 4, !tbaa !5
  %106 = srem i32 %104, %105
  %107 = icmp ne i32 %106, 0
  br i1 %107, label %108, label %110

108:                                              ; preds = %103, %90
  %109 = call i32 @puts(ptr noundef @.str.2)
  store i32 8, ptr %3, align 4
  br label %182, !llvm.loop !17

110:                                              ; preds = %103
  %111 = load i32, ptr %10, align 4, !tbaa !5
  %112 = load i32, ptr %6, align 4, !tbaa !5
  %113 = sdiv i32 %112, %111
  store i32 %113, ptr %6, align 4, !tbaa !5
  %114 = load i32, ptr %10, align 4, !tbaa !5
  %115 = load i32, ptr %7, align 4, !tbaa !5
  %116 = sdiv i32 %115, %114
  store i32 %116, ptr %7, align 4, !tbaa !5
  %117 = load i32, ptr %10, align 4, !tbaa !5
  %118 = load i32, ptr %5, align 4, !tbaa !5
  %119 = sdiv i32 %118, %117
  store i32 %119, ptr %5, align 4, !tbaa !5
  %120 = load i32, ptr %8, align 4, !tbaa !5
  %121 = sext i32 %120 to i64
  %122 = load i32, ptr %5, align 4, !tbaa !5
  %123 = sext i32 %122 to i64
  %124 = mul nsw i64 %121, %123
  %125 = load i32, ptr %7, align 4, !tbaa !5
  %126 = sext i32 %125 to i64
  %127 = srem i64 %124, %126
  %128 = trunc i64 %127 to i32
  store i32 %128, ptr %8, align 4, !tbaa !5
  %129 = load i32, ptr %8, align 4, !tbaa !5
  %130 = icmp slt i32 %129, 0
  br i1 %130, label %131, label %135

131:                                              ; preds = %110
  %132 = load i32, ptr %7, align 4, !tbaa !5
  %133 = load i32, ptr %8, align 4, !tbaa !5
  %134 = add nsw i32 %133, %132
  store i32 %134, ptr %8, align 4, !tbaa !5
  br label %135

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

136:                                              ; preds = %149, %135
  %137 = load i32, ptr %11, align 4, !tbaa !5
  %138 = load i32, ptr %10, align 4, !tbaa !5
  %139 = icmp slt i32 %137, %138
  br i1 %139, label %141, label %140

140:                                              ; preds = %136
  store i32 13, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #6
  br label %155

141:                                              ; preds = %136
  %142 = load i32, ptr @g, align 4, !tbaa !5
  %143 = load i32, ptr %8, align 4, !tbaa !5
  %144 = load i32, ptr @p, align 4, !tbaa !5
  %145 = call noundef i32 @_Z7mod_powiii(i32 noundef %142, i32 noundef %143, i32 noundef %144)
  %146 = load i32, ptr %11, align 4, !tbaa !5
  %147 = sext i32 %146 to i64
  %148 = getelementptr inbounds [32000 x i32], ptr @ans, i64 0, i64 %147
  store i32 %145, ptr %148, align 4, !tbaa !5
  br label %149

149:                                              ; preds = %141
  %150 = load i32, ptr %11, align 4, !tbaa !5
  %151 = add nsw i32 %150, 1
  store i32 %151, ptr %11, align 4, !tbaa !5
  %152 = load i32, ptr %7, align 4, !tbaa !5
  %153 = load i32, ptr %8, align 4, !tbaa !5
  %154 = add nsw i32 %153, %152
  store i32 %154, ptr %8, align 4, !tbaa !5
  br label %136, !llvm.loop !18

155:                                              ; preds = %140
  %156 = load i32, ptr %10, align 4, !tbaa !5
  %157 = sext i32 %156 to i64
  %158 = getelementptr inbounds i32, ptr @ans, i64 %157
  call void @_ZSt4sortIPiEvT_S1_(ptr noundef @ans, ptr noundef %158)
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #6
  store i32 0, ptr %12, align 4, !tbaa !5
  br label %159

159:                                              ; preds = %178, %155
  %160 = load i32, ptr %12, align 4, !tbaa !5
  %161 = load i32, ptr %10, align 4, !tbaa !5
  %162 = icmp slt i32 %160, %161
  br i1 %162, label %164, label %163

163:                                              ; preds = %159
  store i32 16, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #6
  br label %181

164:                                              ; preds = %159
  %165 = load i32, ptr %12, align 4, !tbaa !5
  %166 = sext i32 %165 to i64
  %167 = getelementptr inbounds [32000 x i32], ptr @ans, i64 0, i64 %166
  %168 = load i32, ptr %167, align 4, !tbaa !5
  %169 = load i32, ptr %12, align 4, !tbaa !5
  %170 = load i32, ptr %10, align 4, !tbaa !5
  %171 = sub nsw i32 %170, 1
  %172 = icmp eq i32 %169, %171
  %173 = zext i1 %172 to i64
  %174 = getelementptr inbounds [3 x i8], ptr @.str.4, i64 0, i64 %173
  %175 = load i8, ptr %174, align 1, !tbaa !19
  %176 = sext i8 %175 to i32
  %177 = call i32 (ptr, ...) @printf(ptr noundef @.str.3, i32 noundef %168, i32 noundef %176)
  br label %178

178:                                              ; preds = %164
  %179 = load i32, ptr %12, align 4, !tbaa !5
  %180 = add nsw i32 %179, 1
  store i32 %180, ptr %12, align 4, !tbaa !5
  br label %159, !llvm.loop !20

181:                                              ; preds = %163
  store i32 0, ptr %3, align 4
  br label %182

182:                                              ; preds = %181, %108
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #6
  %183 = load i32, ptr %3, align 4
  switch i32 %183, label %186 [
    i32 0, label %184
    i32 8, label %75
  ]

184:                                              ; preds = %182
  br label %75, !llvm.loop !17

185:                                              ; preds = %75
  ret i32 0

186:                                              ; preds = %182
  unreachable
}

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

declare i32 @puts(ptr noundef) #4

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

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

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 = { 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 = { 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 #4 = { "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 = { 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 = !{!10, !10, i64 0}
!10 = !{!"bool", !7, i64 0}
!11 = !{i8 0, i8 2}
!12 = !{}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}
!16 = distinct !{!16, !14}
!17 = distinct !{!17, !14}
!18 = distinct !{!18, !14}
!19 = !{!7, !7, i64 0}
!20 = distinct !{!20, !14}


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

@tot = external dso_local local_unnamed_addr global i32, align 4
@prime = external dso_local local_unnamed_addr global [32000 x i32], align 16
@t = external dso_local global i32, align 4
@p = external dso_local global i32, align 4
@a = external dso_local global i32, align 4
@b = external dso_local global i32, align 4
@g = external dso_local local_unnamed_addr global i32, align 4
@ans = external dso_local global [32000 x i32], align 16
@vis = external dso_local local_unnamed_addr global [32000 x i8], align 16
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [12 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [3 x i8], align 1

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_Z5exgcdiiRiS_(i32 noundef, i32 noundef, ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) local_unnamed_addr #0

; 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: mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z7mod_powiii(i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #2

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_Z3oriii(i32 noundef, i32 noundef) local_unnamed_addr #2

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() local_unnamed_addr #3 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %tot.promoted = load i32, ptr @tot, align 4, !tbaa !5
  br label %7

3:                                                ; preds = %.critedge
  %4 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @t)
  %5 = load i32, ptr @t, align 4, !tbaa !5
  %6 = add nsw i32 %5, -1
  store i32 %6, ptr @t, align 4, !tbaa !5
  %.not60 = icmp eq i32 %5, 0
  br i1 %.not60, label %._crit_edge63, label %.lr.ph62

7:                                                ; preds = %0, %.critedge
  %indvars.iv65 = phi i64 [ 2, %0 ], [ %indvars.iv.next66, %.critedge ]
  %8 = phi i32 [ %tot.promoted, %0 ], [ %18, %.critedge ]
  %9 = getelementptr inbounds [32000 x i8], ptr @vis, i64 0, i64 %indvars.iv65
  %10 = load i8, ptr %9, align 1, !tbaa !9, !range !11, !noundef !12
  %11 = trunc nuw i8 %10 to i1
  br i1 %11, label %17, label %12

12:                                               ; preds = %7
  %13 = add nsw i32 %8, 1
  store i32 %13, ptr @tot, align 4, !tbaa !5
  %14 = sext i32 %8 to i64
  %15 = getelementptr inbounds [32000 x i32], ptr @prime, i64 0, i64 %14
  %16 = trunc nuw nsw i64 %indvars.iv65 to i32
  store i32 %16, ptr %15, align 4, !tbaa !5
  br label %17

17:                                               ; preds = %12, %7
  %18 = phi i32 [ %13, %12 ], [ %8, %7 ]
  %19 = icmp sgt i32 %18, 0
  br i1 %19, label %.lr.ph.preheader, label %.critedge

.lr.ph.preheader:                                 ; preds = %17
  %20 = zext nneg i32 %18 to i64
  %21 = trunc nuw nsw i64 %indvars.iv65 to i32
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %27
  %indvars.iv = phi i64 [ 0, %.lr.ph.preheader ], [ %indvars.iv.next, %27 ]
  %22 = getelementptr inbounds [32000 x i32], ptr @prime, i64 0, i64 %indvars.iv
  %23 = load i32, ptr %22, align 4, !tbaa !5
  %24 = sext i32 %23 to i64
  %25 = mul nsw i64 %indvars.iv65, %24
  %26 = icmp slt i64 %25, 32000
  br i1 %26, label %27, label %.critedge

27:                                               ; preds = %.lr.ph
  %28 = mul nsw i32 %23, %21
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds [32000 x i8], ptr @vis, i64 0, i64 %29
  store i8 1, ptr %30, align 1, !tbaa !9
  %31 = srem i32 %21, %23
  %32 = icmp ne i32 %31, 0
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %33 = icmp ult i64 %indvars.iv.next, %20
  %or.cond = select i1 %32, i1 %33, i1 false
  br i1 %or.cond, label %.lr.ph, label %.critedge, !llvm.loop !13

.critedge:                                        ; preds = %.lr.ph, %27, %17
  %indvars.iv.next66 = add nuw nsw i64 %indvars.iv65, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next66, 32000
  br i1 %exitcond.not, label %3, label %7, !llvm.loop !15

.lr.ph62:                                         ; preds = %3, %.loopexit
  %34 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull @p, ptr noundef nonnull @a, ptr noundef nonnull @b)
  store i32 2, ptr @g, align 4, !tbaa !5
  %35 = load i32, ptr @p, align 4, !tbaa !5
  %36 = call noundef zeroext i1 @_Z3oriii(i32 noundef 2, i32 noundef %35)
  br i1 %36, label %._crit_edge, label %.lr.ph51

.lr.ph51:                                         ; preds = %.lr.ph62, %.lr.ph51
  %37 = load i32, ptr @g, align 4, !tbaa !5
  %38 = add nsw i32 %37, 1
  store i32 %38, ptr @g, align 4, !tbaa !5
  %39 = load i32, ptr @p, align 4, !tbaa !5
  %40 = call noundef zeroext i1 @_Z3oriii(i32 noundef %38, i32 noundef %39)
  br i1 %40, label %._crit_edge, label %.lr.ph51, !llvm.loop !16

._crit_edge:                                      ; preds = %.lr.ph51, %.lr.ph62
  %41 = load i32, ptr @g, align 4, !tbaa !5
  %42 = load i32, ptr @p, align 4, !tbaa !5
  %43 = load i32, ptr @b, align 4, !tbaa !5
  %44 = call noundef i32 @_Z4bsgsiii(i32 noundef %41, i32 noundef %42, i32 noundef %43)
  %45 = load i32, ptr @a, align 4, !tbaa !5
  %46 = load i32, ptr @p, align 4, !tbaa !5
  %47 = add nsw i32 %46, -1
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %1) #6
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %2) #6
  %48 = call noundef i32 @_Z5exgcdiiRiS_(i32 noundef %45, i32 noundef %47, ptr noundef nonnull align 4 dereferenceable(4) %1, ptr noundef nonnull align 4 dereferenceable(4) %2)
  %49 = icmp eq i32 %44, -1
  br i1 %49, label %53, label %50

50:                                               ; preds = %._crit_edge
  %51 = srem i32 %44, %48
  %52 = sdiv i32 %44, %48
  %.not44 = icmp eq i32 %51, 0
  br i1 %.not44, label %55, label %53

53:                                               ; preds = %50, %._crit_edge
  %54 = call i32 @puts(ptr noundef nonnull dereferenceable(1) @.str.2)
  br label %.loopexit, !llvm.loop !17

55:                                               ; preds = %50
  %56 = sdiv i32 %47, %48
  %57 = load i32, ptr %1, align 4, !tbaa !5
  %58 = sext i32 %57 to i64
  %59 = sext i32 %52 to i64
  %60 = mul nsw i64 %58, %59
  %61 = sext i32 %56 to i64
  %62 = srem i64 %60, %61
  %63 = trunc nsw i64 %62 to i32
  %64 = icmp slt i64 %62, 0
  %65 = select i1 %64, i32 %56, i32 0
  %spec.select = add nsw i32 %65, %63
  store i32 %spec.select, ptr %1, align 4, !tbaa !5
  %66 = icmp sgt i32 %48, 0
  br i1 %66, label %.lr.ph55.preheader, label %._crit_edge56.thread

._crit_edge56.thread:                             ; preds = %55
  %67 = sext i32 %48 to i64
  %68 = getelementptr inbounds i32, ptr @ans, i64 %67
  call void @_ZSt4sortIPiEvT_S1_(ptr noundef nonnull @ans, ptr noundef nonnull %68)
  br label %.loopexit

.lr.ph55.preheader:                               ; preds = %55
  %wide.trip.count = zext nneg i32 %48 to i64
  br label %.lr.ph55

._crit_edge56:                                    ; preds = %.lr.ph55
  %69 = zext nneg i32 %48 to i64
  %70 = getelementptr inbounds i32, ptr @ans, i64 %69
  call void @_ZSt4sortIPiEvT_S1_(ptr noundef nonnull @ans, ptr noundef nonnull %70)
  br i1 %66, label %.lr.ph59, label %.loopexit

.lr.ph59:                                         ; preds = %._crit_edge56
  %71 = add nsw i32 %48, -1
  %72 = zext nneg i32 %71 to i64
  %wide.trip.count75 = zext nneg i32 %48 to i64
  br label %79

.lr.ph55:                                         ; preds = %.lr.ph55.preheader, %.lr.ph55
  %indvars.iv68 = phi i64 [ 0, %.lr.ph55.preheader ], [ %indvars.iv.next69, %.lr.ph55 ]
  %storemerge4652 = phi i32 [ %spec.select, %.lr.ph55.preheader ], [ %78, %.lr.ph55 ]
  %73 = load i32, ptr @g, align 4, !tbaa !5
  %74 = load i32, ptr @p, align 4, !tbaa !5
  %75 = call noundef i32 @_Z7mod_powiii(i32 noundef %73, i32 noundef %storemerge4652, i32 noundef %74)
  %76 = getelementptr inbounds [32000 x i32], ptr @ans, i64 0, i64 %indvars.iv68
  store i32 %75, ptr %76, align 4, !tbaa !5
  %indvars.iv.next69 = add nuw nsw i64 %indvars.iv68, 1
  %77 = load i32, ptr %1, align 4, !tbaa !5
  %78 = add nsw i32 %77, %56
  store i32 %78, ptr %1, align 4, !tbaa !5
  %exitcond71.not = icmp eq i64 %indvars.iv.next69, %wide.trip.count
  br i1 %exitcond71.not, label %._crit_edge56, label %.lr.ph55, !llvm.loop !18

79:                                               ; preds = %.lr.ph59, %79
  %indvars.iv72 = phi i64 [ 0, %.lr.ph59 ], [ %indvars.iv.next73, %79 ]
  %80 = getelementptr inbounds [32000 x i32], ptr @ans, i64 0, i64 %indvars.iv72
  %81 = load i32, ptr %80, align 4, !tbaa !5
  %82 = icmp eq i64 %indvars.iv72, %72
  %83 = zext i1 %82 to i64
  %84 = getelementptr inbounds [3 x i8], ptr @.str.4, i64 0, i64 %83
  %85 = load i8, ptr %84, align 1, !tbaa !19
  %86 = sext i8 %85 to i32
  %87 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3, i32 noundef %81, i32 noundef %86)
  %indvars.iv.next73 = add nuw nsw i64 %indvars.iv72, 1
  %exitcond76.not = icmp eq i64 %indvars.iv.next73, %wide.trip.count75
  br i1 %exitcond76.not, label %.loopexit, label %79, !llvm.loop !20

.loopexit:                                        ; preds = %79, %._crit_edge56.thread, %._crit_edge56, %53
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %2) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %1) #6
  %88 = load i32, ptr @t, align 4, !tbaa !5
  %89 = add nsw i32 %88, -1
  store i32 %89, ptr @t, align 4, !tbaa !5
  %.not = icmp eq i32 %88, 0
  br i1 %.not, label %._crit_edge63, label %.lr.ph62

._crit_edge63:                                    ; preds = %.loopexit, %3
  ret i32 0
}

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

; Function Attrs: nofree nounwind
declare noundef i32 @puts(ptr nocapture noundef readonly) local_unnamed_addr #4

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

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

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 = { 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 = { 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 #4 = { 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 #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 = !{!10, !10, i64 0}
!10 = !{!"bool", !7, i64 0}
!11 = !{i8 0, i8 2}
!12 = !{}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}
!16 = distinct !{!16, !14}
!17 = distinct !{!17, !14}
!18 = distinct !{!18, !14}
!19 = !{!7, !7, i64 0}
!20 = distinct !{!20, !14}


; Effective O3 passes: CorrelatedValuePropagationPass,DivRemPairsPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopInstSimplifyPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass