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

; Unoptimized IR (clang -disable-llvm-passes):
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

@n = external dso_local global i32, align 4
@mod = external dso_local global i32, align 4
@f = external dso_local global [500001 x i32], align 16
@tot = external dso_local global i32, align 4
@idx = external dso_local global [500001 x i32], align 16
@.str = external hidden unnamed_addr constant [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [4 x i8], align 1

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

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

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

19:                                               ; preds = %14
  %20 = load i32, ptr %2, align 4, !tbaa !5
  %21 = sext i32 %20 to i64
  %22 = getelementptr inbounds [500001 x i32], ptr @f, i64 0, i64 %21
  store i32 1000000001, ptr %22, align 4, !tbaa !5
  br label %23

23:                                               ; preds = %19
  %24 = load i32, ptr %2, align 4, !tbaa !5
  %25 = add nsw i32 %24, 1
  store i32 %25, ptr %2, align 4, !tbaa !5
  br label %14, !llvm.loop !9

26:                                               ; preds = %18
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #6
  store i32 1, ptr %3, align 4, !tbaa !5
  br label %27

27:                                               ; preds = %131, %26
  %28 = load i32, ptr %3, align 4, !tbaa !5
  %29 = load i32, ptr @n, align 4, !tbaa !5
  %30 = icmp slt i32 %28, %29
  br i1 %30, label %32, label %31

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

32:                                               ; preds = %27
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #6
  %33 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef %5)
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #6
  store i32 0, ptr %6, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #6
  %34 = load i32, ptr %5, align 4, !tbaa !5
  %35 = load i32, ptr @mod, align 4, !tbaa !5
  %36 = call noundef i32 @_ZSt5__gcdIiET_S0_S0_(i32 noundef %34, i32 noundef %35)
  store i32 %36, ptr %7, align 4, !tbaa !5
  br label %37

37:                                               ; preds = %127, %32
  %38 = load i32, ptr %6, align 4, !tbaa !5
  %39 = load i32, ptr %7, align 4, !tbaa !5
  %40 = icmp slt i32 %38, %39
  br i1 %40, label %42, label %41

41:                                               ; preds = %37
  store i32 8, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #6
  br label %130

42:                                               ; preds = %37
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #6
  store i32 0, ptr @tot, align 4, !tbaa !5
  store i32 0, ptr %8, align 4, !tbaa !5
  %43 = load i32, ptr %6, align 4, !tbaa !5
  %44 = load i32, ptr @tot, align 4, !tbaa !5
  %45 = add nsw i32 %44, 1
  store i32 %45, ptr @tot, align 4, !tbaa !5
  %46 = sext i32 %44 to i64
  %47 = getelementptr inbounds [500001 x i32], ptr @idx, i64 0, i64 %46
  store i32 %43, ptr %47, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #6
  %48 = load i32, ptr %6, align 4, !tbaa !5
  %49 = load i32, ptr %5, align 4, !tbaa !5
  %50 = add nsw i32 %48, %49
  %51 = load i32, ptr @mod, align 4, !tbaa !5
  %52 = srem i32 %50, %51
  store i32 %52, ptr %9, align 4, !tbaa !5
  br label %53

53:                                               ; preds = %79, %42
  %54 = load i32, ptr %9, align 4, !tbaa !5
  %55 = load i32, ptr %6, align 4, !tbaa !5
  %56 = icmp ne i32 %54, %55
  br i1 %56, label %58, label %57

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

58:                                               ; preds = %53
  %59 = load i32, ptr %9, align 4, !tbaa !5
  %60 = sext i32 %59 to i64
  %61 = getelementptr inbounds [500001 x i32], ptr @f, i64 0, i64 %60
  %62 = load i32, ptr %61, align 4, !tbaa !5
  %63 = load i32, ptr %8, align 4, !tbaa !5
  %64 = sext i32 %63 to i64
  %65 = getelementptr inbounds [500001 x i32], ptr @idx, i64 0, i64 %64
  %66 = load i32, ptr %65, align 4, !tbaa !5
  %67 = sext i32 %66 to i64
  %68 = getelementptr inbounds [500001 x i32], ptr @f, i64 0, i64 %67
  %69 = load i32, ptr %68, align 4, !tbaa !5
  %70 = icmp slt i32 %62, %69
  br i1 %70, label %71, label %73

71:                                               ; preds = %58
  %72 = load i32, ptr @tot, align 4, !tbaa !5
  store i32 %72, ptr %8, align 4, !tbaa !5
  br label %73

73:                                               ; preds = %71, %58
  %74 = load i32, ptr %9, align 4, !tbaa !5
  %75 = load i32, ptr @tot, align 4, !tbaa !5
  %76 = add nsw i32 %75, 1
  store i32 %76, ptr @tot, align 4, !tbaa !5
  %77 = sext i32 %75 to i64
  %78 = getelementptr inbounds [500001 x i32], ptr @idx, i64 0, i64 %77
  store i32 %74, ptr %78, align 4, !tbaa !5
  br label %79

79:                                               ; preds = %73
  %80 = load i32, ptr %9, align 4, !tbaa !5
  %81 = load i32, ptr %5, align 4, !tbaa !5
  %82 = add nsw i32 %80, %81
  %83 = load i32, ptr @mod, align 4, !tbaa !5
  %84 = srem i32 %82, %83
  store i32 %84, ptr %9, align 4, !tbaa !5
  br label %53, !llvm.loop !11

85:                                               ; preds = %57
  %86 = load i32, ptr %8, align 4, !tbaa !5
  %87 = sext i32 %86 to i64
  %88 = getelementptr inbounds i32, ptr @idx, i64 %87
  %89 = load i32, ptr @tot, align 4, !tbaa !5
  %90 = sext i32 %89 to i64
  %91 = getelementptr inbounds i32, ptr @idx, i64 %90
  %92 = call noundef ptr @_ZNSt3_V26rotateIPiEET_S2_S2_S2_(ptr noundef @idx, ptr noundef %88, ptr noundef %91)
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #6
  store i32 1, ptr %10, align 4, !tbaa !5
  br label %93

93:                                               ; preds = %123, %85
  %94 = load i32, ptr %10, align 4, !tbaa !5
  %95 = load i32, ptr @tot, align 4, !tbaa !5
  %96 = icmp slt i32 %94, %95
  br i1 %96, label %98, label %97

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

98:                                               ; preds = %93
  %99 = load i32, ptr %10, align 4, !tbaa !5
  %100 = sext i32 %99 to i64
  %101 = getelementptr inbounds [500001 x i32], ptr @idx, i64 0, i64 %100
  %102 = load i32, ptr %101, align 4, !tbaa !5
  %103 = sext i32 %102 to i64
  %104 = getelementptr inbounds [500001 x i32], ptr @f, i64 0, i64 %103
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #6
  %105 = load i32, ptr %10, align 4, !tbaa !5
  %106 = sub nsw i32 %105, 1
  %107 = sext i32 %106 to i64
  %108 = getelementptr inbounds [500001 x i32], ptr @idx, i64 0, i64 %107
  %109 = load i32, ptr %108, align 4, !tbaa !5
  %110 = sext i32 %109 to i64
  %111 = getelementptr inbounds [500001 x i32], ptr @f, i64 0, i64 %110
  %112 = load i32, ptr %111, align 4, !tbaa !5
  %113 = load i32, ptr %5, align 4, !tbaa !5
  %114 = add nsw i32 %112, %113
  store i32 %114, ptr %11, align 4, !tbaa !5
  %115 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %104, ptr noundef nonnull align 4 dereferenceable(4) %11)
  %116 = load i32, ptr %115, align 4, !tbaa !5
  %117 = load i32, ptr %10, align 4, !tbaa !5
  %118 = sext i32 %117 to i64
  %119 = getelementptr inbounds [500001 x i32], ptr @idx, i64 0, i64 %118
  %120 = load i32, ptr %119, align 4, !tbaa !5
  %121 = sext i32 %120 to i64
  %122 = getelementptr inbounds [500001 x i32], ptr @f, i64 0, i64 %121
  store i32 %116, ptr %122, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #6
  br label %123

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

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

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

130:                                              ; preds = %41
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #6
  br label %131

131:                                              ; preds = %130
  %132 = load i32, ptr %3, align 4, !tbaa !5
  %133 = add nsw i32 %132, 1
  store i32 %133, ptr %3, align 4, !tbaa !5
  br label %27, !llvm.loop !14

134:                                              ; preds = %31
  %135 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef @n)
  br label %136

136:                                              ; preds = %152, %134
  %137 = load i32, ptr @n, align 4, !tbaa !5
  %138 = add nsw i32 %137, -1
  store i32 %138, ptr @n, align 4, !tbaa !5
  %139 = icmp ne i32 %137, 0
  br i1 %139, label %140, label %156

140:                                              ; preds = %136
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #6
  %141 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef %12)
  %142 = load i32, ptr %12, align 4, !tbaa !5
  %143 = load i32, ptr %12, align 4, !tbaa !5
  %144 = load i32, ptr @mod, align 4, !tbaa !5
  %145 = srem i32 %143, %144
  %146 = sext i32 %145 to i64
  %147 = getelementptr inbounds [500001 x i32], ptr @f, i64 0, i64 %146
  %148 = load i32, ptr %147, align 4, !tbaa !5
  %149 = icmp sge i32 %142, %148
  br i1 %149, label %150, label %151

150:                                              ; preds = %140
  br label %152

151:                                              ; preds = %140
  br label %152

152:                                              ; preds = %151, %150
  %153 = phi ptr [ @.str.2, %150 ], [ @.str.3, %151 ]
  %154 = getelementptr inbounds [4 x i8], ptr %153, i64 0, i64 0
  %155 = call i32 @puts(ptr noundef %154)
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #6
  br label %136, !llvm.loop !15

156:                                              ; preds = %136
  ret i32 0
}

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

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

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZSt5__gcdIiET_S0_S0_(i32 noundef, i32 noundef) #3

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

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

declare i32 @puts(ptr noundef) #1

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

@n = external dso_local global i32, align 4
@mod = external dso_local global i32, align 4
@f = external dso_local global [500001 x i32], align 16
@tot = external dso_local local_unnamed_addr global i32, align 4
@idx = external dso_local global [500001 x i32], align 16
@.str = external hidden unnamed_addr constant [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [4 x i8], align 1

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

.lr.ph.preheader:                                 ; preds = %0
  %wide.trip.count = zext nneg i32 %5 to i64
  %7 = add nsw i64 %wide.trip.count, -1
  %min.iters.check = icmp ult i32 %5, 9
  br i1 %min.iters.check, label %.lr.ph.preheader61, label %vector.ph

.lr.ph.preheader61:                               ; preds = %middle.block, %.lr.ph.preheader
  %indvars.iv.ph = phi i64 [ 1, %.lr.ph.preheader ], [ %ind.end, %middle.block ]
  br label %.lr.ph

vector.ph:                                        ; preds = %.lr.ph.preheader
  %n.vec = and i64 %7, -8
  %ind.end = or disjoint i64 %n.vec, 1
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %offset.idx = or disjoint i64 %index, 1
  %8 = getelementptr inbounds [500001 x i32], ptr @f, i64 0, i64 %offset.idx
  %9 = getelementptr inbounds i8, ptr %8, i64 16
  store <4 x i32> <i32 1000000001, i32 1000000001, i32 1000000001, i32 1000000001>, ptr %8, align 4, !tbaa !5
  store <4 x i32> <i32 1000000001, i32 1000000001, i32 1000000001, i32 1000000001>, ptr %9, align 4, !tbaa !5
  %index.next = add nuw i64 %index, 8
  %10 = icmp eq i64 %index.next, %n.vec
  br i1 %10, label %middle.block, label %vector.body, !llvm.loop !9

middle.block:                                     ; preds = %vector.body
  %cmp.n = icmp eq i64 %7, %n.vec
  br i1 %cmp.n, label %.preheader, label %.lr.ph.preheader61

.preheader:                                       ; preds = %.lr.ph, %middle.block, %0
  %11 = load i32, ptr @n, align 4, !tbaa !5
  %12 = icmp sgt i32 %11, 1
  br i1 %12, label %.lr.ph45, label %._crit_edge46

.lr.ph:                                           ; preds = %.lr.ph.preheader61, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ %indvars.iv.ph, %.lr.ph.preheader61 ]
  %13 = getelementptr inbounds [500001 x i32], ptr @f, i64 0, i64 %indvars.iv
  store i32 1000000001, ptr %13, align 4, !tbaa !5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %.preheader, label %.lr.ph, !llvm.loop !13

._crit_edge46:                                    ; preds = %._crit_edge43, %.preheader
  %14 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull @n)
  %15 = load i32, ptr @n, align 4, !tbaa !5
  %16 = add nsw i32 %15, -1
  store i32 %16, ptr @n, align 4, !tbaa !5
  %.not47 = icmp eq i32 %15, 0
  br i1 %.not47, label %._crit_edge50, label %.lr.ph49

.lr.ph45:                                         ; preds = %.preheader, %._crit_edge43
  %.02644 = phi i32 [ %22, %._crit_edge43 ], [ 1, %.preheader ]
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %1) #6
  %17 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull %1)
  %18 = load i32, ptr %1, align 4, !tbaa !5
  %19 = load i32, ptr @mod, align 4, !tbaa !5
  %20 = call noundef i32 @_ZSt5__gcdIiET_S0_S0_(i32 noundef %18, i32 noundef %19)
  %21 = icmp sgt i32 %20, 0
  br i1 %21, label %.lr.ph42, label %._crit_edge43

._crit_edge43:                                    ; preds = %._crit_edge39, %.lr.ph45
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %1) #6
  %22 = add nuw nsw i32 %.02644, 1
  %23 = load i32, ptr @n, align 4, !tbaa !5
  %24 = icmp slt i32 %22, %23
  br i1 %24, label %.lr.ph45, label %._crit_edge46, !llvm.loop !14

.lr.ph42:                                         ; preds = %.lr.ph45, %._crit_edge39
  %.02540 = phi i32 [ %49, %._crit_edge39 ], [ 0, %.lr.ph45 ]
  store i32 1, ptr @tot, align 4, !tbaa !5
  store i32 %.02540, ptr @idx, align 16, !tbaa !5
  %25 = load i32, ptr %1, align 4, !tbaa !5
  %26 = load i32, ptr @mod, align 4, !tbaa !5
  %.pn30 = add nsw i32 %.02540, %25
  %.02231 = srem i32 %.pn30, %26
  %.not2832 = icmp eq i32 %.02231, %.02540
  br i1 %.not2832, label %28, label %.lr.ph35

._crit_edge:                                      ; preds = %.lr.ph35
  %27 = trunc nuw i64 %indvars.iv.next53 to i32
  store i32 %27, ptr @tot, align 4, !tbaa !5
  br label %28

28:                                               ; preds = %._crit_edge, %.lr.ph42
  %29 = phi i64 [ %indvars.iv.next53, %._crit_edge ], [ 1, %.lr.ph42 ]
  %.023.lcssa = phi i32 [ %spec.select, %._crit_edge ], [ 0, %.lr.ph42 ]
  %30 = sext i32 %.023.lcssa to i64
  %31 = getelementptr inbounds i32, ptr @idx, i64 %30
  %sext = shl i64 %29, 32
  %32 = ashr exact i64 %sext, 30
  %33 = getelementptr inbounds i8, ptr @idx, i64 %32
  %34 = call noundef ptr @_ZNSt3_V26rotateIPiEET_S2_S2_S2_(ptr noundef nonnull @idx, ptr noundef nonnull %31, ptr noundef nonnull %33)
  %35 = load i32, ptr @tot, align 4, !tbaa !5
  %36 = icmp sgt i32 %35, 1
  br i1 %36, label %.lr.ph38.preheader, label %._crit_edge39

.lr.ph38.preheader:                               ; preds = %28
  %.pre = load i32, ptr @idx, align 16, !tbaa !5
  %.phi.trans.insert = sext i32 %.pre to i64
  %.phi.trans.insert59 = getelementptr inbounds [500001 x i32], ptr @f, i64 0, i64 %.phi.trans.insert
  %.pre60 = load i32, ptr %.phi.trans.insert59, align 4, !tbaa !5
  br label %.lr.ph38

.lr.ph35:                                         ; preds = %.lr.ph42, %.lr.ph35
  %indvars.iv52 = phi i64 [ %indvars.iv.next53, %.lr.ph35 ], [ 1, %.lr.ph42 ]
  %.02234 = phi i32 [ %.022, %.lr.ph35 ], [ %.02231, %.lr.ph42 ]
  %.02333 = phi i32 [ %spec.select, %.lr.ph35 ], [ 0, %.lr.ph42 ]
  %37 = sext i32 %.02234 to i64
  %38 = getelementptr inbounds [500001 x i32], ptr @f, i64 0, i64 %37
  %39 = load i32, ptr %38, align 4, !tbaa !5
  %40 = sext i32 %.02333 to i64
  %41 = getelementptr inbounds [500001 x i32], ptr @idx, i64 0, i64 %40
  %42 = load i32, ptr %41, align 4, !tbaa !5
  %43 = sext i32 %42 to i64
  %44 = getelementptr inbounds [500001 x i32], ptr @f, i64 0, i64 %43
  %45 = load i32, ptr %44, align 4, !tbaa !5
  %46 = icmp slt i32 %39, %45
  %47 = trunc nuw nsw i64 %indvars.iv52 to i32
  %spec.select = select i1 %46, i32 %47, i32 %.02333
  %indvars.iv.next53 = add nuw nsw i64 %indvars.iv52, 1
  %48 = getelementptr inbounds [500001 x i32], ptr @idx, i64 0, i64 %indvars.iv52
  store i32 %.02234, ptr %48, align 4, !tbaa !5
  %.pn = add nsw i32 %.02234, %25
  %.022 = srem i32 %.pn, %26
  %.not28 = icmp eq i32 %.022, %.02540
  br i1 %.not28, label %._crit_edge, label %.lr.ph35, !llvm.loop !15

._crit_edge39:                                    ; preds = %.lr.ph38, %28
  %49 = add nuw nsw i32 %.02540, 1
  %exitcond58.not = icmp eq i32 %49, %20
  br i1 %exitcond58.not, label %._crit_edge43, label %.lr.ph42, !llvm.loop !16

.lr.ph38:                                         ; preds = %.lr.ph38.preheader, %.lr.ph38
  %50 = phi i32 [ %.pre60, %.lr.ph38.preheader ], [ %58, %.lr.ph38 ]
  %indvars.iv55 = phi i64 [ 1, %.lr.ph38.preheader ], [ %indvars.iv.next56, %.lr.ph38 ]
  %51 = getelementptr inbounds [500001 x i32], ptr @idx, i64 0, i64 %indvars.iv55
  %52 = load i32, ptr %51, align 4, !tbaa !5
  %53 = sext i32 %52 to i64
  %54 = getelementptr inbounds [500001 x i32], ptr @f, i64 0, i64 %53
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %2) #6
  %55 = load i32, ptr %1, align 4, !tbaa !5
  %56 = add nsw i32 %55, %50
  store i32 %56, ptr %2, align 4, !tbaa !5
  %57 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %54, ptr noundef nonnull align 4 dereferenceable(4) %2)
  %58 = load i32, ptr %57, align 4, !tbaa !5
  %59 = load i32, ptr %51, align 4, !tbaa !5
  %60 = sext i32 %59 to i64
  %61 = getelementptr inbounds [500001 x i32], ptr @f, i64 0, i64 %60
  store i32 %58, ptr %61, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %2) #6
  %indvars.iv.next56 = add nuw nsw i64 %indvars.iv55, 1
  %62 = load i32, ptr @tot, align 4, !tbaa !5
  %63 = sext i32 %62 to i64
  %64 = icmp slt i64 %indvars.iv.next56, %63
  br i1 %64, label %.lr.ph38, label %._crit_edge39, !llvm.loop !17

.lr.ph49:                                         ; preds = %._crit_edge46, %.lr.ph49
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %3) #6
  %65 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull %3)
  %66 = load i32, ptr %3, align 4, !tbaa !5
  %67 = load i32, ptr @mod, align 4, !tbaa !5
  %68 = srem i32 %66, %67
  %69 = sext i32 %68 to i64
  %70 = getelementptr inbounds [500001 x i32], ptr @f, i64 0, i64 %69
  %71 = load i32, ptr %70, align 4, !tbaa !5
  %.not27 = icmp slt i32 %66, %71
  %.str.2..str.3 = select i1 %.not27, ptr @.str.3, ptr @.str.2
  %72 = call i32 @puts(ptr noundef nonnull dereferenceable(1) %.str.2..str.3)
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %3) #6
  %73 = load i32, ptr @n, align 4, !tbaa !5
  %74 = add nsw i32 %73, -1
  store i32 %74, ptr @n, align 4, !tbaa !5
  %.not = icmp eq i32 %73, 0
  br i1 %.not, label %._crit_edge50, label %.lr.ph49, !llvm.loop !18

._crit_edge50:                                    ; preds = %.lr.ph49, %._crit_edge46
  ret i32 0
}

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

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

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZSt5__gcdIiET_S0_S0_(i32 noundef, i32 noundef) local_unnamed_addr #3

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

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

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

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


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