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

; 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
@q = external dso_local global i32, align 4
@a = external dso_local global [50001 x i32], align 16
@s = external dso_local global [50001 x i32], align 16
@inv = external dso_local global [50001 x i32], align 16
@perms = external dso_local global i32, align 4
@.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

; 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
  store i32 0, ptr %1, align 4
  %9 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n, ptr noundef @q)
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #4
  store i32 1, ptr %2, align 4, !tbaa !5
  br label %10

10:                                               ; preds = %20, %0
  %11 = load i32, ptr %2, align 4, !tbaa !5
  %12 = load i32, ptr @n, align 4, !tbaa !5
  %13 = icmp sle i32 %11, %12
  br i1 %13, label %15, label %14

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

15:                                               ; preds = %10
  %16 = load i32, ptr %2, align 4, !tbaa !5
  %17 = sext i32 %16 to i64
  %18 = getelementptr inbounds i32, ptr @a, i64 %17
  %19 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef %18)
  br label %20

20:                                               ; preds = %15
  %21 = load i32, ptr %2, align 4, !tbaa !5
  %22 = add nsw i32 %21, 1
  store i32 %22, ptr %2, align 4, !tbaa !5
  br label %10, !llvm.loop !9

23:                                               ; preds = %14
  %24 = load i32, ptr @n, align 4, !tbaa !5
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds i32, ptr @a, i64 %25
  %27 = getelementptr inbounds i32, ptr %26, i64 1
  call void @_ZSt4sortIPiEvT_S1_(ptr noundef getelementptr inbounds (i32, ptr @a, i64 1), ptr noundef %27)
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #4
  store i32 1, ptr %3, align 4, !tbaa !5
  br label %28

28:                                               ; preds = %59, %23
  %29 = load i32, ptr %3, align 4, !tbaa !5
  %30 = load i32, ptr @n, align 4, !tbaa !5
  %31 = icmp sle i32 %29, %30
  br i1 %31, label %33, label %32

32:                                               ; preds = %28
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #4
  br label %62

33:                                               ; preds = %28
  %34 = load i32, ptr %3, align 4, !tbaa !5
  %35 = sub nsw i32 %34, 1
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds [50001 x i32], ptr @s, i64 0, i64 %36
  %38 = load i32, ptr %37, align 4, !tbaa !5
  %39 = load i32, ptr %3, align 4, !tbaa !5
  %40 = sext i32 %39 to i64
  %41 = getelementptr inbounds [50001 x i32], ptr @a, i64 0, i64 %40
  %42 = load i32, ptr %41, align 4, !tbaa !5
  %43 = add nsw i32 %38, %42
  %44 = load i32, ptr %3, align 4, !tbaa !5
  %45 = sext i32 %44 to i64
  %46 = getelementptr inbounds [50001 x i32], ptr @s, i64 0, i64 %45
  store i32 %43, ptr %46, align 4, !tbaa !5
  %47 = load i32, ptr %3, align 4, !tbaa !5
  %48 = sext i32 %47 to i64
  %49 = getelementptr inbounds [50001 x i32], ptr @s, i64 0, i64 %48
  %50 = load i32, ptr %49, align 4, !tbaa !5
  %51 = icmp sge i32 %50, 1000000007
  br i1 %51, label %52, label %58

52:                                               ; preds = %33
  %53 = load i32, ptr %3, align 4, !tbaa !5
  %54 = sext i32 %53 to i64
  %55 = getelementptr inbounds [50001 x i32], ptr @s, i64 0, i64 %54
  %56 = load i32, ptr %55, align 4, !tbaa !5
  %57 = sub nsw i32 %56, 1000000007
  store i32 %57, ptr %55, align 4, !tbaa !5
  br label %58

58:                                               ; preds = %52, %33
  br label %59

59:                                               ; preds = %58
  %60 = load i32, ptr %3, align 4, !tbaa !5
  %61 = add nsw i32 %60, 1
  store i32 %61, ptr %3, align 4, !tbaa !5
  br label %28, !llvm.loop !11

62:                                               ; preds = %32
  store i32 1, ptr getelementptr inbounds ([50001 x i32], ptr @inv, i64 0, i64 1), align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #4
  store i32 2, ptr %4, align 4, !tbaa !5
  br label %63

63:                                               ; preds = %86, %62
  %64 = load i32, ptr %4, align 4, !tbaa !5
  %65 = load i32, ptr @n, align 4, !tbaa !5
  %66 = add nsw i32 %65, 1
  %67 = icmp sle i32 %64, %66
  br i1 %67, label %69, label %68

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

69:                                               ; preds = %63
  %70 = load i32, ptr %4, align 4, !tbaa !5
  %71 = sdiv i32 1000000007, %70
  %72 = sext i32 %71 to i64
  %73 = load i32, ptr %4, align 4, !tbaa !5
  %74 = srem i32 1000000007, %73
  %75 = sext i32 %74 to i64
  %76 = getelementptr inbounds [50001 x i32], ptr @inv, i64 0, i64 %75
  %77 = load i32, ptr %76, align 4, !tbaa !5
  %78 = sext i32 %77 to i64
  %79 = mul nsw i64 %72, %78
  %80 = srem i64 %79, 1000000007
  %81 = sub nsw i64 1000000007, %80
  %82 = trunc i64 %81 to i32
  %83 = load i32, ptr %4, align 4, !tbaa !5
  %84 = sext i32 %83 to i64
  %85 = getelementptr inbounds [50001 x i32], ptr @inv, i64 0, i64 %84
  store i32 %82, ptr %85, align 4, !tbaa !5
  br label %86

86:                                               ; preds = %69
  %87 = load i32, ptr %4, align 4, !tbaa !5
  %88 = add nsw i32 %87, 1
  store i32 %88, ptr %4, align 4, !tbaa !5
  br label %63, !llvm.loop !12

89:                                               ; preds = %68
  store i32 1, ptr @perms, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  store i32 2, ptr %5, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  store i32 1, ptr %6, align 4, !tbaa !5
  br label %90

90:                                               ; preds = %126, %89
  %91 = load i32, ptr %5, align 4, !tbaa !5
  %92 = load i32, ptr @n, align 4, !tbaa !5
  %93 = icmp sle i32 %91, %92
  br i1 %93, label %95, label %94

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

95:                                               ; preds = %90
  %96 = load i32, ptr %5, align 4, !tbaa !5
  %97 = sub nsw i32 %96, 1
  %98 = sext i32 %97 to i64
  %99 = getelementptr inbounds [50001 x i32], ptr @a, i64 0, i64 %98
  %100 = load i32, ptr %99, align 4, !tbaa !5
  %101 = load i32, ptr %5, align 4, !tbaa !5
  %102 = sext i32 %101 to i64
  %103 = getelementptr inbounds [50001 x i32], ptr @a, i64 0, i64 %102
  %104 = load i32, ptr %103, align 4, !tbaa !5
  %105 = icmp eq i32 %100, %104
  br i1 %105, label %106, label %109

106:                                              ; preds = %95
  %107 = load i32, ptr %6, align 4, !tbaa !5
  %108 = add nsw i32 %107, 1
  br label %110

109:                                              ; preds = %95
  br label %110

110:                                              ; preds = %109, %106
  %111 = phi i32 [ %108, %106 ], [ 1, %109 ]
  store i32 %111, ptr %6, align 4, !tbaa !5
  %112 = load i32, ptr @perms, align 4, !tbaa !5
  %113 = sext i32 %112 to i64
  %114 = load i32, ptr %6, align 4, !tbaa !5
  %115 = sext i32 %114 to i64
  %116 = getelementptr inbounds [50001 x i32], ptr @inv, i64 0, i64 %115
  %117 = load i32, ptr %116, align 4, !tbaa !5
  %118 = sext i32 %117 to i64
  %119 = mul nsw i64 %113, %118
  %120 = srem i64 %119, 1000000007
  %121 = load i32, ptr %5, align 4, !tbaa !5
  %122 = sext i32 %121 to i64
  %123 = mul nsw i64 %120, %122
  %124 = srem i64 %123, 1000000007
  %125 = trunc i64 %124 to i32
  store i32 %125, ptr @perms, align 4, !tbaa !5
  br label %126

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

129:                                              ; preds = %94
  br label %130

130:                                              ; preds = %134, %129
  %131 = load i32, ptr @q, align 4, !tbaa !5
  %132 = add nsw i32 %131, -1
  store i32 %132, ptr @q, align 4, !tbaa !5
  %133 = icmp ne i32 %131, 0
  br i1 %133, label %134, label %168

134:                                              ; preds = %130
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  %135 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef %7)
  %136 = load i32, ptr @n, align 4, !tbaa !5
  %137 = sext i32 %136 to i64
  %138 = getelementptr inbounds i32, ptr @a, i64 %137
  %139 = getelementptr inbounds i32, ptr %138, i64 1
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  %140 = load i32, ptr %7, align 4, !tbaa !5
  %141 = add nsw i32 %140, 1
  store i32 %141, ptr %8, align 4, !tbaa !5
  %142 = call noundef ptr @_ZSt11lower_boundIPiiET_S1_S1_RKT0_(ptr noundef getelementptr inbounds (i32, ptr @a, i64 1), ptr noundef %139, ptr noundef nonnull align 4 dereferenceable(4) %8)
  %143 = ptrtoint ptr %142 to i64
  %144 = sub i64 %143, ptrtoint (ptr @a to i64)
  %145 = sdiv exact i64 %144, 4
  %146 = sub nsw i64 %145, 1
  %147 = trunc i64 %146 to i32
  store i32 %147, ptr %7, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  %148 = load i32, ptr %7, align 4, !tbaa !5
  %149 = sext i32 %148 to i64
  %150 = getelementptr inbounds [50001 x i32], ptr @s, i64 0, i64 %149
  %151 = load i32, ptr %150, align 4, !tbaa !5
  %152 = sext i32 %151 to i64
  %153 = load i32, ptr @perms, align 4, !tbaa !5
  %154 = sext i32 %153 to i64
  %155 = mul nsw i64 %152, %154
  %156 = srem i64 %155, 1000000007
  %157 = load i32, ptr @n, align 4, !tbaa !5
  %158 = add nsw i32 %157, 1
  %159 = load i32, ptr %7, align 4, !tbaa !5
  %160 = sub nsw i32 %158, %159
  %161 = sext i32 %160 to i64
  %162 = getelementptr inbounds [50001 x i32], ptr @inv, i64 0, i64 %161
  %163 = load i32, ptr %162, align 4, !tbaa !5
  %164 = sext i32 %163 to i64
  %165 = mul nsw i64 %156, %164
  %166 = srem i64 %165, 1000000007
  %167 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i64 noundef %166)
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  br label %130, !llvm.loop !14

168:                                              ; preds = %130
  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: inlinehint mustprogress uwtable
declare dso_local void @_ZSt4sortIPiEvT_S1_(ptr noundef, ptr noundef) #3

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

declare i32 @printf(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 = { 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 #4 = { nounwind }

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

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 2}
!4 = !{!"clang version 19.1.0 (git@github.com:llvm/llvm-project.git a4bf6cd7cfb1a1421ba92bca9d017b49936c55e4)"}
!5 = !{!6, !6, i64 0}
!6 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}
!12 = distinct !{!12, !10}
!13 = distinct !{!13, !10}
!14 = distinct !{!14, !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
@q = external dso_local global i32, align 4
@a = external dso_local global [50001 x i32], align 16
@s = external dso_local local_unnamed_addr global [50001 x i32], align 16
@inv = external dso_local local_unnamed_addr global [50001 x i32], align 16
@perms = external dso_local local_unnamed_addr global i32, align 4
@.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

; 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 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @n, ptr noundef nonnull @q)
  %4 = load i32, ptr @n, align 4, !tbaa !5
  %.not33 = icmp slt i32 %4, 1
  br i1 %.not33, label %.._crit_edge_crit_edge, label %.lr.ph

.._crit_edge_crit_edge:                           ; preds = %0
  %.pre71 = sext i32 %4 to i64
  br label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph, %.._crit_edge_crit_edge
  %.pre-phi = phi i64 [ %.pre71, %.._crit_edge_crit_edge ], [ %13, %.lr.ph ]
  %5 = getelementptr inbounds i32, ptr @a, i64 %.pre-phi
  %6 = getelementptr inbounds i8, ptr %5, i64 4
  tail call void @_ZSt4sortIPiEvT_S1_(ptr noundef nonnull getelementptr inbounds (i8, ptr @a, i64 4), ptr noundef nonnull %6)
  %7 = load i32, ptr @n, align 4, !tbaa !5
  %.not2835 = icmp slt i32 %7, 1
  br i1 %.not2835, label %._crit_edge39.thread, label %.lr.ph38.preheader

._crit_edge39.thread:                             ; preds = %._crit_edge
  store i32 1, ptr getelementptr inbounds (i8, ptr @inv, i64 4), align 4, !tbaa !5
  br label %.preheader.sink.split

.lr.ph38.preheader:                               ; preds = %._crit_edge
  %.pre = load i32, ptr @s, align 16, !tbaa !5
  %8 = zext nneg i32 %7 to i64
  %xtraiter = and i64 %8, 1
  %9 = icmp eq i32 %7, 1
  br i1 %9, label %._crit_edge39.unr-lcssa, label %.lr.ph38.preheader.new

.lr.ph38.preheader.new:                           ; preds = %.lr.ph38.preheader
  %unroll_iter = and i64 %8, 2147483646
  br label %.lr.ph38

.lr.ph:                                           ; preds = %0, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 1, %0 ]
  %10 = getelementptr inbounds i32, ptr @a, i64 %indvars.iv
  %11 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull %10)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %12 = load i32, ptr @n, align 4, !tbaa !5
  %13 = sext i32 %12 to i64
  %.not.not = icmp slt i64 %indvars.iv, %13
  br i1 %.not.not, label %.lr.ph, label %._crit_edge, !llvm.loop !9

._crit_edge39.unr-lcssa:                          ; preds = %.lr.ph38, %.lr.ph38.preheader
  %.unr = phi i32 [ %.pre, %.lr.ph38.preheader ], [ %spec.select.1, %.lr.ph38 ]
  %indvars.iv57.unr = phi i64 [ 1, %.lr.ph38.preheader ], [ %indvars.iv.next58.1, %.lr.ph38 ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge39, label %.lr.ph38.epil

.lr.ph38.epil:                                    ; preds = %._crit_edge39.unr-lcssa
  %14 = getelementptr inbounds [50001 x i32], ptr @a, i64 0, i64 %indvars.iv57.unr
  %15 = load i32, ptr %14, align 4, !tbaa !5
  %16 = add nsw i32 %15, %.unr
  %17 = getelementptr inbounds [50001 x i32], ptr @s, i64 0, i64 %indvars.iv57.unr
  %18 = icmp sgt i32 %16, 1000000006
  %19 = add nsw i32 %16, -1000000007
  %spec.select.epil = select i1 %18, i32 %19, i32 %16
  store i32 %spec.select.epil, ptr %17, align 4, !tbaa !5
  br label %._crit_edge39

._crit_edge39:                                    ; preds = %._crit_edge39.unr-lcssa, %.lr.ph38.epil
  store i32 1, ptr getelementptr inbounds (i8, ptr @inv, i64 4), align 4, !tbaa !5
  br i1 %.not2835, label %.preheader.sink.split, label %.lr.ph44.preheader

.lr.ph44.preheader:                               ; preds = %._crit_edge39
  %20 = add nuw i32 %7, 2
  %wide.trip.count63 = zext i32 %20 to i64
  br label %.lr.ph44

.lr.ph38:                                         ; preds = %.lr.ph38, %.lr.ph38.preheader.new
  %21 = phi i32 [ %.pre, %.lr.ph38.preheader.new ], [ %spec.select.1, %.lr.ph38 ]
  %indvars.iv57 = phi i64 [ 1, %.lr.ph38.preheader.new ], [ %indvars.iv.next58.1, %.lr.ph38 ]
  %niter = phi i64 [ 0, %.lr.ph38.preheader.new ], [ %niter.next.1, %.lr.ph38 ]
  %22 = getelementptr inbounds [50001 x i32], ptr @a, i64 0, i64 %indvars.iv57
  %23 = load i32, ptr %22, align 4, !tbaa !5
  %24 = add nsw i32 %23, %21
  %25 = getelementptr inbounds [50001 x i32], ptr @s, i64 0, i64 %indvars.iv57
  %26 = icmp sgt i32 %24, 1000000006
  %27 = add nsw i32 %24, -1000000007
  %spec.select = select i1 %26, i32 %27, i32 %24
  store i32 %spec.select, ptr %25, align 4, !tbaa !5
  %indvars.iv.next58 = add nuw nsw i64 %indvars.iv57, 1
  %28 = getelementptr inbounds [50001 x i32], ptr @a, i64 0, i64 %indvars.iv.next58
  %29 = load i32, ptr %28, align 4, !tbaa !5
  %30 = add nsw i32 %29, %spec.select
  %31 = getelementptr inbounds [50001 x i32], ptr @s, i64 0, i64 %indvars.iv.next58
  %32 = icmp sgt i32 %30, 1000000006
  %33 = add nsw i32 %30, -1000000007
  %spec.select.1 = select i1 %32, i32 %33, i32 %30
  store i32 %spec.select.1, ptr %31, align 4, !tbaa !5
  %indvars.iv.next58.1 = add nuw nsw i64 %indvars.iv57, 2
  %niter.next.1 = add i64 %niter, 2
  %niter.ncmp.1 = icmp eq i64 %niter.next.1, %unroll_iter
  br i1 %niter.ncmp.1, label %._crit_edge39.unr-lcssa, label %.lr.ph38, !llvm.loop !11

._crit_edge45:                                    ; preds = %.lr.ph44
  store i32 1, ptr @perms, align 4, !tbaa !5
  %.not3046 = icmp eq i32 %7, 1
  br i1 %.not3046, label %.preheader, label %.lr.ph50.preheader

.lr.ph50.preheader:                               ; preds = %._crit_edge45
  %34 = add nuw i32 %7, 1
  %wide.trip.count68 = zext i32 %34 to i64
  %.pre70 = load i32, ptr getelementptr inbounds (i8, ptr @a, i64 4), align 4, !tbaa !5
  br label %.lr.ph50

.lr.ph44:                                         ; preds = %.lr.ph44.preheader, %.lr.ph44
  %indvars.iv60 = phi i64 [ 2, %.lr.ph44.preheader ], [ %indvars.iv.next61, %.lr.ph44 ]
  %35 = trunc nuw nsw i64 %indvars.iv60 to i32
  %36 = udiv i32 1000000007, %35
  %37 = zext nneg i32 %36 to i64
  %38 = urem i32 1000000007, %35
  %39 = zext nneg i32 %38 to i64
  %40 = getelementptr inbounds [50001 x i32], ptr @inv, i64 0, i64 %39
  %41 = load i32, ptr %40, align 4, !tbaa !5
  %42 = sext i32 %41 to i64
  %43 = mul nsw i64 %42, %37
  %44 = srem i64 %43, 1000000007
  %45 = trunc nsw i64 %44 to i32
  %46 = sub nsw i32 1000000007, %45
  %47 = getelementptr inbounds [50001 x i32], ptr @inv, i64 0, i64 %indvars.iv60
  store i32 %46, ptr %47, align 4, !tbaa !5
  %indvars.iv.next61 = add nuw nsw i64 %indvars.iv60, 1
  %exitcond64 = icmp eq i64 %indvars.iv.next61, %wide.trip.count63
  br i1 %exitcond64, label %._crit_edge45, label %.lr.ph44, !llvm.loop !12

..preheader_crit_edge:                            ; preds = %.lr.ph50
  %48 = trunc nsw i64 %65 to i32
  br label %.preheader.sink.split

.preheader.sink.split:                            ; preds = %._crit_edge39, %._crit_edge39.thread, %..preheader_crit_edge
  %.sink = phi i32 [ %48, %..preheader_crit_edge ], [ 1, %._crit_edge39.thread ], [ 1, %._crit_edge39 ]
  store i32 %.sink, ptr @perms, align 4, !tbaa !5
  br label %.preheader

.preheader:                                       ; preds = %.preheader.sink.split, %._crit_edge45
  %49 = load i32, ptr @q, align 4, !tbaa !5
  %50 = add nsw i32 %49, -1
  store i32 %50, ptr @q, align 4, !tbaa !5
  %.not3152 = icmp eq i32 %49, 0
  br i1 %.not3152, label %._crit_edge54, label %.lr.ph53

.lr.ph50:                                         ; preds = %.lr.ph50.preheader, %.lr.ph50
  %51 = phi i32 [ %.pre70, %.lr.ph50.preheader ], [ %54, %.lr.ph50 ]
  %indvars.iv65 = phi i64 [ 2, %.lr.ph50.preheader ], [ %indvars.iv.next66, %.lr.ph50 ]
  %.048 = phi i32 [ 1, %.lr.ph50.preheader ], [ %57, %.lr.ph50 ]
  %52 = phi i64 [ 1, %.lr.ph50.preheader ], [ %65, %.lr.ph50 ]
  %53 = getelementptr inbounds [50001 x i32], ptr @a, i64 0, i64 %indvars.iv65
  %54 = load i32, ptr %53, align 4, !tbaa !5
  %55 = icmp eq i32 %51, %54
  %56 = add nsw i32 %.048, 1
  %57 = select i1 %55, i32 %56, i32 1
  %58 = sext i32 %57 to i64
  %59 = getelementptr inbounds [50001 x i32], ptr @inv, i64 0, i64 %58
  %60 = load i32, ptr %59, align 4, !tbaa !5
  %61 = sext i32 %60 to i64
  %62 = mul nsw i64 %52, %61
  %63 = srem i64 %62, 1000000007
  %64 = mul nsw i64 %63, %indvars.iv65
  %65 = srem i64 %64, 1000000007
  %indvars.iv.next66 = add nuw nsw i64 %indvars.iv65, 1
  %exitcond69.not = icmp eq i64 %indvars.iv.next66, %wide.trip.count68
  br i1 %exitcond69.not, label %..preheader_crit_edge, label %.lr.ph50, !llvm.loop !13

.lr.ph53:                                         ; preds = %.preheader, %.lr.ph53
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %1) #4
  %66 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull %1)
  %67 = load i32, ptr @n, align 4, !tbaa !5
  %68 = sext i32 %67 to i64
  %gep = getelementptr i32, ptr getelementptr inbounds (i8, ptr @a, i64 4), i64 %68
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %2) #4
  %69 = load i32, ptr %1, align 4, !tbaa !5
  %70 = add nsw i32 %69, 1
  store i32 %70, ptr %2, align 4, !tbaa !5
  %71 = call noundef ptr @_ZSt11lower_boundIPiiET_S1_S1_RKT0_(ptr noundef nonnull getelementptr inbounds (i8, ptr @a, i64 4), ptr noundef nonnull %gep, ptr noundef nonnull align 4 dereferenceable(4) %2)
  %72 = ptrtoint ptr %71 to i64
  %73 = sub i64 %72, ptrtoint (ptr @a to i64)
  %74 = lshr exact i64 %73, 2
  %75 = trunc i64 %74 to i32
  %76 = add i32 %75, -1
  store i32 %76, ptr %1, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %2) #4
  %77 = sext i32 %76 to i64
  %78 = getelementptr inbounds [50001 x i32], ptr @s, i64 0, i64 %77
  %79 = load i32, ptr %78, align 4, !tbaa !5
  %80 = sext i32 %79 to i64
  %81 = load i32, ptr @perms, align 4, !tbaa !5
  %82 = sext i32 %81 to i64
  %83 = mul nsw i64 %82, %80
  %84 = srem i64 %83, 1000000007
  %85 = load i32, ptr @n, align 4, !tbaa !5
  %86 = sub i32 %85, %75
  %87 = add i32 %86, 2
  %88 = sext i32 %87 to i64
  %89 = getelementptr inbounds [50001 x i32], ptr @inv, i64 0, i64 %88
  %90 = load i32, ptr %89, align 4, !tbaa !5
  %91 = sext i32 %90 to i64
  %92 = mul nsw i64 %84, %91
  %93 = srem i64 %92, 1000000007
  %94 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i64 noundef %93)
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %1) #4
  %95 = load i32, ptr @q, align 4, !tbaa !5
  %96 = add nsw i32 %95, -1
  store i32 %96, ptr @q, align 4, !tbaa !5
  %.not31 = icmp eq i32 %95, 0
  br i1 %.not31, label %._crit_edge54, label %.lr.ph53, !llvm.loop !14

._crit_edge54:                                    ; preds = %.lr.ph53, %.preheader
  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: inlinehint mustprogress uwtable
declare dso_local void @_ZSt4sortIPiEvT_S1_(ptr noundef, ptr noundef) local_unnamed_addr #3

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

; Function Attrs: nofree nounwind
declare noundef i32 @printf(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 = { 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 #4 = { nounwind }

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

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


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