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

; 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
@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 [7 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [4 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 @p, ptr noundef @a, ptr noundef @b)
  store i32 2, ptr @g, align 4, !tbaa !5
  br label %75

75:                                               ; preds = %81, %73
  %76 = load i32, ptr @g, align 4, !tbaa !5
  %77 = load i32, ptr @p, align 4, !tbaa !5
  %78 = call noundef zeroext i1 @_Z3oriii(i32 noundef %76, i32 noundef %77)
  br i1 %78, label %79, label %80

79:                                               ; preds = %75
  br label %84

80:                                               ; preds = %75
  br label %81

81:                                               ; preds = %80
  %82 = load i32, ptr @g, align 4, !tbaa !5
  %83 = add nsw i32 %82, 1
  store i32 %83, ptr @g, align 4, !tbaa !5
  br label %75, !llvm.loop !16

84:                                               ; preds = %79
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #6
  %85 = load i32, ptr @g, align 4, !tbaa !5
  %86 = load i32, ptr @p, align 4, !tbaa !5
  %87 = load i32, ptr @b, align 4, !tbaa !5
  %88 = call noundef i32 @_Z4bsgsiii(i32 noundef %85, i32 noundef %86, i32 noundef %87)
  store i32 %88, ptr %5, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #6
  %89 = load i32, ptr @a, align 4, !tbaa !5
  store i32 %89, ptr %6, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #6
  %90 = load i32, ptr @p, align 4, !tbaa !5
  %91 = sub nsw i32 %90, 1
  store i32 %91, 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
  %92 = load i32, ptr %6, align 4, !tbaa !5
  %93 = load i32, ptr %7, align 4, !tbaa !5
  %94 = call noundef i32 @_Z5exgcdiiRiS_(i32 noundef %92, i32 noundef %93, ptr noundef nonnull align 4 dereferenceable(4) %8, ptr noundef nonnull align 4 dereferenceable(4) %9)
  store i32 %94, ptr %10, align 4, !tbaa !5
  %95 = load i32, ptr %5, align 4, !tbaa !5
  %96 = icmp eq i32 %95, -1
  br i1 %96, label %102, label %97

97:                                               ; preds = %84
  %98 = load i32, ptr %5, align 4, !tbaa !5
  %99 = load i32, ptr %10, align 4, !tbaa !5
  %100 = srem i32 %98, %99
  %101 = icmp ne i32 %100, 0
  br i1 %101, label %102, label %104

102:                                              ; preds = %97, %84
  %103 = call i32 @puts(ptr noundef @.str.1)
  store i32 0, ptr %1, align 4
  store i32 1, ptr %3, align 4
  br label %170

104:                                              ; preds = %97
  %105 = load i32, ptr %10, align 4, !tbaa !5
  %106 = load i32, ptr %6, align 4, !tbaa !5
  %107 = sdiv i32 %106, %105
  store i32 %107, ptr %6, align 4, !tbaa !5
  %108 = load i32, ptr %10, align 4, !tbaa !5
  %109 = load i32, ptr %7, align 4, !tbaa !5
  %110 = sdiv i32 %109, %108
  store i32 %110, ptr %7, align 4, !tbaa !5
  %111 = load i32, ptr %10, align 4, !tbaa !5
  %112 = load i32, ptr %5, align 4, !tbaa !5
  %113 = sdiv i32 %112, %111
  store i32 %113, ptr %5, align 4, !tbaa !5
  %114 = load i32, ptr %8, align 4, !tbaa !5
  %115 = sext i32 %114 to i64
  %116 = load i32, ptr %5, align 4, !tbaa !5
  %117 = sext i32 %116 to i64
  %118 = mul nsw i64 %115, %117
  %119 = load i32, ptr %7, align 4, !tbaa !5
  %120 = sext i32 %119 to i64
  %121 = srem i64 %118, %120
  %122 = trunc i64 %121 to i32
  store i32 %122, ptr %8, align 4, !tbaa !5
  %123 = load i32, ptr %8, align 4, !tbaa !5
  %124 = icmp slt i32 %123, 0
  br i1 %124, label %125, label %129

125:                                              ; preds = %104
  %126 = load i32, ptr %7, align 4, !tbaa !5
  %127 = load i32, ptr %8, align 4, !tbaa !5
  %128 = add nsw i32 %127, %126
  store i32 %128, ptr %8, align 4, !tbaa !5
  br label %129

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

130:                                              ; preds = %143, %129
  %131 = load i32, ptr %11, align 4, !tbaa !5
  %132 = load i32, ptr %10, align 4, !tbaa !5
  %133 = icmp slt i32 %131, %132
  br i1 %133, label %135, label %134

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

135:                                              ; preds = %130
  %136 = load i32, ptr @g, align 4, !tbaa !5
  %137 = load i32, ptr %8, align 4, !tbaa !5
  %138 = load i32, ptr @p, align 4, !tbaa !5
  %139 = call noundef i32 @_Z7mod_powiii(i32 noundef %136, i32 noundef %137, i32 noundef %138)
  %140 = load i32, ptr %11, align 4, !tbaa !5
  %141 = sext i32 %140 to i64
  %142 = getelementptr inbounds [32000 x i32], ptr @ans, i64 0, i64 %141
  store i32 %139, ptr %142, align 4, !tbaa !5
  br label %143

143:                                              ; preds = %135
  %144 = load i32, ptr %11, align 4, !tbaa !5
  %145 = add nsw i32 %144, 1
  store i32 %145, ptr %11, align 4, !tbaa !5
  %146 = load i32, ptr %7, align 4, !tbaa !5
  %147 = load i32, ptr %8, align 4, !tbaa !5
  %148 = add nsw i32 %147, %146
  store i32 %148, ptr %8, align 4, !tbaa !5
  br label %130, !llvm.loop !17

149:                                              ; preds = %134
  %150 = load i32, ptr %10, align 4, !tbaa !5
  %151 = sext i32 %150 to i64
  %152 = getelementptr inbounds i32, ptr @ans, i64 %151
  call void @_ZSt4sortIPiEvT_S1_(ptr noundef @ans, ptr noundef %152)
  %153 = load i32, ptr %10, align 4, !tbaa !5
  %154 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i32 noundef %153)
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #6
  store i32 0, ptr %12, align 4, !tbaa !5
  br label %155

155:                                              ; preds = %166, %149
  %156 = load i32, ptr %12, align 4, !tbaa !5
  %157 = load i32, ptr %10, align 4, !tbaa !5
  %158 = icmp slt i32 %156, %157
  br i1 %158, label %160, label %159

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

160:                                              ; preds = %155
  %161 = load i32, ptr %12, align 4, !tbaa !5
  %162 = sext i32 %161 to i64
  %163 = getelementptr inbounds [32000 x i32], ptr @ans, i64 0, i64 %162
  %164 = load i32, ptr %163, align 4, !tbaa !5
  %165 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i32 noundef %164)
  br label %166

166:                                              ; preds = %160
  %167 = load i32, ptr %12, align 4, !tbaa !5
  %168 = add nsw i32 %167, 1
  store i32 %168, ptr %12, align 4, !tbaa !5
  br label %155, !llvm.loop !18

169:                                              ; preds = %159
  store i32 0, ptr %1, align 4
  store i32 1, ptr %3, align 4
  br label %170

170:                                              ; preds = %169, %102
  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
  %171 = load i32, ptr %1, align 4
  ret i32 %171
}

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}


; 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
@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 [7 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [4 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 @p, ptr noundef nonnull @a, ptr noundef nonnull @b)
  store i32 2, ptr @g, align 4, !tbaa !5
  %5 = load i32, ptr @p, align 4, !tbaa !5
  %6 = tail call noundef zeroext i1 @_Z3oriii(i32 noundef 2, i32 noundef %5)
  br i1 %6, label %._crit_edge, label %.lr.ph51

7:                                                ; preds = %0, %.critedge
  %indvars.iv61 = phi i64 [ 2, %0 ], [ %indvars.iv.next62, %.critedge ]
  %8 = phi i32 [ %tot.promoted, %0 ], [ %18, %.critedge ]
  %9 = getelementptr inbounds [32000 x i8], ptr @vis, i64 0, i64 %indvars.iv61
  %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.iv61 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.iv61 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.iv61, %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.next62 = add nuw nsw i64 %indvars.iv61, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next62, 32000
  br i1 %exitcond.not, label %3, label %7, !llvm.loop !15

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

._crit_edge:                                      ; preds = %.lr.ph51, %3
  %38 = load i32, ptr @g, align 4, !tbaa !5
  %39 = load i32, ptr @p, align 4, !tbaa !5
  %40 = load i32, ptr @b, align 4, !tbaa !5
  %41 = tail call noundef i32 @_Z4bsgsiii(i32 noundef %38, i32 noundef %39, i32 noundef %40)
  %42 = load i32, ptr @a, align 4, !tbaa !5
  %43 = load i32, ptr @p, align 4, !tbaa !5
  %44 = add nsw i32 %43, -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
  %45 = call noundef i32 @_Z5exgcdiiRiS_(i32 noundef %42, i32 noundef %44, ptr noundef nonnull align 4 dereferenceable(4) %1, ptr noundef nonnull align 4 dereferenceable(4) %2)
  %46 = icmp eq i32 %41, -1
  br i1 %46, label %50, label %47

47:                                               ; preds = %._crit_edge
  %48 = srem i32 %41, %45
  %49 = sdiv i32 %41, %45
  %.not = icmp eq i32 %48, 0
  br i1 %.not, label %52, label %50

50:                                               ; preds = %47, %._crit_edge
  %51 = call i32 @puts(ptr noundef nonnull dereferenceable(1) @.str.1)
  br label %.loopexit

52:                                               ; preds = %47
  %53 = sdiv i32 %44, %45
  %54 = load i32, ptr %1, align 4, !tbaa !5
  %55 = sext i32 %54 to i64
  %56 = sext i32 %49 to i64
  %57 = mul nsw i64 %55, %56
  %58 = sext i32 %53 to i64
  %59 = srem i64 %57, %58
  %60 = trunc nsw i64 %59 to i32
  %61 = icmp slt i64 %59, 0
  %62 = select i1 %61, i32 %53, i32 0
  %spec.select = add nsw i32 %62, %60
  store i32 %spec.select, ptr %1, align 4, !tbaa !5
  %63 = icmp sgt i32 %45, 0
  br i1 %63, label %.lr.ph55.preheader, label %.loopexit.critedge

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

._crit_edge56:                                    ; preds = %.lr.ph55
  %64 = zext nneg i32 %45 to i64
  %65 = getelementptr inbounds i32, ptr @ans, i64 %64
  call void @_ZSt4sortIPiEvT_S1_(ptr noundef nonnull @ans, ptr noundef nonnull %65)
  %66 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i32 noundef %45)
  br i1 %63, label %.lr.ph59.preheader, label %.loopexit

.lr.ph59.preheader:                               ; preds = %._crit_edge56
  %wide.trip.count71 = zext nneg i32 %45 to i64
  br label %.lr.ph59

.lr.ph55:                                         ; preds = %.lr.ph55.preheader, %.lr.ph55
  %indvars.iv64 = phi i64 [ 0, %.lr.ph55.preheader ], [ %indvars.iv.next65, %.lr.ph55 ]
  %storemerge4652 = phi i32 [ %spec.select, %.lr.ph55.preheader ], [ %72, %.lr.ph55 ]
  %67 = load i32, ptr @g, align 4, !tbaa !5
  %68 = load i32, ptr @p, align 4, !tbaa !5
  %69 = call noundef i32 @_Z7mod_powiii(i32 noundef %67, i32 noundef %storemerge4652, i32 noundef %68)
  %70 = getelementptr inbounds [32000 x i32], ptr @ans, i64 0, i64 %indvars.iv64
  store i32 %69, ptr %70, align 4, !tbaa !5
  %indvars.iv.next65 = add nuw nsw i64 %indvars.iv64, 1
  %71 = load i32, ptr %1, align 4, !tbaa !5
  %72 = add nsw i32 %71, %53
  store i32 %72, ptr %1, align 4, !tbaa !5
  %exitcond67.not = icmp eq i64 %indvars.iv.next65, %wide.trip.count
  br i1 %exitcond67.not, label %._crit_edge56, label %.lr.ph55, !llvm.loop !17

.lr.ph59:                                         ; preds = %.lr.ph59.preheader, %.lr.ph59
  %indvars.iv68 = phi i64 [ 0, %.lr.ph59.preheader ], [ %indvars.iv.next69, %.lr.ph59 ]
  %73 = getelementptr inbounds [32000 x i32], ptr @ans, i64 0, i64 %indvars.iv68
  %74 = load i32, ptr %73, align 4, !tbaa !5
  %75 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i32 noundef %74)
  %indvars.iv.next69 = add nuw nsw i64 %indvars.iv68, 1
  %exitcond72.not = icmp eq i64 %indvars.iv.next69, %wide.trip.count71
  br i1 %exitcond72.not, label %.loopexit, label %.lr.ph59, !llvm.loop !18

.loopexit.critedge:                               ; preds = %52
  %76 = sext i32 %45 to i64
  %77 = getelementptr inbounds i32, ptr @ans, i64 %76
  call void @_ZSt4sortIPiEvT_S1_(ptr noundef nonnull @ans, ptr noundef nonnull %77)
  %78 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i32 noundef %45)
  br label %.loopexit

.loopexit:                                        ; preds = %.lr.ph59, %.loopexit.critedge, %._crit_edge56, %50
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %2) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %1) #6
  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}


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