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

; 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
@inv = external dso_local global [1000001 x i32], align 16
@pre = external dso_local global i32, align 4
@cur = external dso_local global i32, align 4
@ans = external dso_local global i32, align 4
@.str = external hidden unnamed_addr constant [3 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 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
  store i32 0, ptr %1, align 4
  %5 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n)
  %6 = load i32, ptr @n, align 4, !tbaa !5
  %7 = add nsw i32 %6, -1
  store i32 %7, ptr @n, align 4, !tbaa !5
  %8 = icmp ne i32 %7, 0
  br i1 %8, label %11, label %9

9:                                                ; preds = %0
  %10 = call i32 @puts(ptr noundef @.str.1)
  store i32 0, ptr %1, align 4
  br label %100

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

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

16:                                               ; preds = %12
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #3
  br label %37

17:                                               ; preds = %12
  %18 = load i32, ptr %2, align 4, !tbaa !5
  %19 = sdiv i32 1000000007, %18
  %20 = sext i32 %19 to i64
  %21 = load i32, ptr %2, align 4, !tbaa !5
  %22 = srem i32 1000000007, %21
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds [1000001 x i32], ptr @inv, i64 0, i64 %23
  %25 = load i32, ptr %24, align 4, !tbaa !5
  %26 = sext i32 %25 to i64
  %27 = mul nsw i64 %20, %26
  %28 = srem i64 %27, 1000000007
  %29 = sub nsw i64 1000000007, %28
  %30 = trunc i64 %29 to i32
  %31 = load i32, ptr %2, align 4, !tbaa !5
  %32 = sext i32 %31 to i64
  %33 = getelementptr inbounds [1000001 x i32], ptr @inv, i64 0, i64 %32
  store i32 %30, ptr %33, align 4, !tbaa !5
  br label %34

34:                                               ; preds = %17
  %35 = load i32, ptr %2, align 4, !tbaa !5
  %36 = add nsw i32 %35, 1
  store i32 %36, ptr %2, align 4, !tbaa !5
  br label %12, !llvm.loop !9

37:                                               ; preds = %16
  store i32 1, ptr @pre, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  store i32 1, ptr %3, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  store i32 2, ptr %4, align 4, !tbaa !5
  br label %38

38:                                               ; preds = %84, %37
  %39 = load i32, ptr %3, align 4, !tbaa !5
  %40 = load i32, ptr @n, align 4, !tbaa !5
  %41 = icmp sle i32 %39, %40
  br i1 %41, label %43, label %42

42:                                               ; preds = %38
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  br label %87

43:                                               ; preds = %38
  %44 = load i32, ptr @pre, align 4, !tbaa !5
  %45 = sext i32 %44 to i64
  %46 = load i32, ptr @n, align 4, !tbaa !5
  %47 = load i32, ptr %3, align 4, !tbaa !5
  %48 = sub nsw i32 %46, %47
  %49 = add nsw i32 %48, 1
  %50 = sext i32 %49 to i64
  %51 = mul nsw i64 %45, %50
  %52 = srem i64 %51, 1000000007
  %53 = load i32, ptr %3, align 4, !tbaa !5
  %54 = sext i32 %53 to i64
  %55 = getelementptr inbounds [1000001 x i32], ptr @inv, i64 0, i64 %54
  %56 = load i32, ptr %55, align 4, !tbaa !5
  %57 = sext i32 %56 to i64
  %58 = mul nsw i64 %52, %57
  %59 = srem i64 %58, 1000000007
  %60 = trunc i64 %59 to i32
  store i32 %60, ptr @cur, align 4, !tbaa !5
  %61 = load i32, ptr @ans, align 4, !tbaa !5
  %62 = sext i32 %61 to i64
  %63 = load i32, ptr @pre, align 4, !tbaa !5
  %64 = sext i32 %63 to i64
  %65 = load i32, ptr @cur, align 4, !tbaa !5
  %66 = sext i32 %65 to i64
  %67 = mul nsw i64 %64, %66
  %68 = srem i64 %67, 1000000007
  %69 = load i32, ptr %4, align 4, !tbaa !5
  %70 = sext i32 %69 to i64
  %71 = mul nsw i64 %68, %70
  %72 = add nsw i64 %62, %71
  %73 = srem i64 %72, 1000000007
  %74 = trunc i64 %73 to i32
  store i32 %74, ptr @ans, align 4, !tbaa !5
  %75 = load i32, ptr @cur, align 4, !tbaa !5
  store i32 %75, ptr @pre, align 4, !tbaa !5
  %76 = load i32, ptr %4, align 4, !tbaa !5
  %77 = load i32, ptr %4, align 4, !tbaa !5
  %78 = add nsw i32 %77, %76
  store i32 %78, ptr %4, align 4, !tbaa !5
  %79 = icmp sge i32 %78, 1000000007
  br i1 %79, label %80, label %83

80:                                               ; preds = %43
  %81 = load i32, ptr %4, align 4, !tbaa !5
  %82 = sub nsw i32 %81, 1000000007
  store i32 %82, ptr %4, align 4, !tbaa !5
  br label %83

83:                                               ; preds = %80, %43
  br label %84

84:                                               ; preds = %83
  %85 = load i32, ptr %3, align 4, !tbaa !5
  %86 = add nsw i32 %85, 1
  store i32 %86, ptr %3, align 4, !tbaa !5
  br label %38, !llvm.loop !11

87:                                               ; preds = %42
  %88 = load i32, ptr @ans, align 4, !tbaa !5
  %89 = sext i32 %88 to i64
  %90 = load i32, ptr @n, align 4, !tbaa !5
  %91 = sext i32 %90 to i64
  %92 = getelementptr inbounds [1000001 x i32], ptr @inv, i64 0, i64 %91
  %93 = load i32, ptr %92, align 4, !tbaa !5
  %94 = sext i32 %93 to i64
  %95 = mul nsw i64 %89, %94
  %96 = srem i64 %95, 1000000007
  %97 = trunc i64 %96 to i32
  store i32 %97, ptr @ans, align 4, !tbaa !5
  %98 = load i32, ptr @ans, align 4, !tbaa !5
  %99 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i32 noundef %98)
  store i32 0, ptr %1, align 4
  br label %100

100:                                              ; preds = %87, %9
  %101 = load i32, ptr %1, align 4
  ret i32 %101
}

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

declare i32 @puts(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

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 = { 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}


; 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
@inv = external dso_local local_unnamed_addr global [1000001 x i32], align 16
@pre = external dso_local local_unnamed_addr global i32, align 4
@cur = external dso_local local_unnamed_addr global i32, align 4
@ans = external dso_local local_unnamed_addr global i32, align 4
@.str = external hidden unnamed_addr constant [3 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 nofree norecurse nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  %1 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @n)
  %2 = load i32, ptr @n, align 4, !tbaa !5
  %3 = add nsw i32 %2, -1
  store i32 %3, ptr @n, align 4, !tbaa !5
  %.not = icmp eq i32 %3, 0
  br i1 %.not, label %4, label %6

4:                                                ; preds = %0
  %5 = tail call i32 @puts(ptr noundef nonnull dereferenceable(1) @.str.1)
  br label %54

6:                                                ; preds = %0
  store i32 1, ptr getelementptr inbounds (i8, ptr @inv, i64 4), align 4, !tbaa !5
  %.not21.not23 = icmp sgt i32 %2, 2
  br i1 %.not21.not23, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %6
  %wide.trip.count = zext nneg i32 %2 to i64
  br label %.lr.ph

._crit_edge:                                      ; preds = %.lr.ph, %6
  store i32 1, ptr @pre, align 4, !tbaa !5
  %ans.promoted = load i32, ptr @ans, align 4, !tbaa !5
  %.not22.not25 = icmp sgt i32 %2, 1
  br i1 %.not22.not25, label %.lr.ph29.preheader, label %22

.lr.ph29.preheader:                               ; preds = %._crit_edge
  %7 = zext nneg i32 %2 to i64
  %wide.trip.count38 = zext nneg i32 %2 to i64
  br label %.lr.ph29

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %indvars.iv = phi i64 [ 2, %.lr.ph.preheader ], [ %indvars.iv.next, %.lr.ph ]
  %8 = trunc nuw nsw i64 %indvars.iv to i32
  %9 = udiv i32 1000000007, %8
  %10 = zext nneg i32 %9 to i64
  %11 = urem i32 1000000007, %8
  %12 = zext nneg i32 %11 to i64
  %13 = getelementptr inbounds [1000001 x i32], ptr @inv, i64 0, i64 %12
  %14 = load i32, ptr %13, align 4, !tbaa !5
  %15 = sext i32 %14 to i64
  %16 = mul nsw i64 %15, %10
  %17 = srem i64 %16, 1000000007
  %18 = trunc nsw i64 %17 to i32
  %19 = sub nsw i32 1000000007, %18
  %20 = getelementptr inbounds [1000001 x i32], ptr @inv, i64 0, i64 %indvars.iv
  store i32 %19, ptr %20, 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 %._crit_edge, label %.lr.ph, !llvm.loop !9

._crit_edge30:                                    ; preds = %.lr.ph29
  %21 = trunc nsw i64 %42 to i32
  store i32 %21, ptr @cur, align 4, !tbaa !5
  store i32 %21, ptr @pre, align 4, !tbaa !5
  br label %22

22:                                               ; preds = %._crit_edge30, %._crit_edge
  %23 = phi i32 [ %50, %._crit_edge30 ], [ %ans.promoted, %._crit_edge ]
  %24 = sext i32 %23 to i64
  %25 = sext i32 %3 to i64
  %26 = getelementptr inbounds [1000001 x i32], ptr @inv, i64 0, i64 %25
  %27 = load i32, ptr %26, align 4, !tbaa !5
  %28 = sext i32 %27 to i64
  %29 = mul nsw i64 %28, %24
  %30 = srem i64 %29, 1000000007
  %31 = trunc nsw i64 %30 to i32
  store i32 %31, ptr @ans, align 4, !tbaa !5
  %32 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i32 noundef %31)
  br label %54

.lr.ph29:                                         ; preds = %.lr.ph29.preheader, %.lr.ph29
  %indvars.iv35 = phi i64 [ 1, %.lr.ph29.preheader ], [ %indvars.iv.next36, %.lr.ph29 ]
  %.027 = phi i32 [ 2, %.lr.ph29.preheader ], [ %spec.select, %.lr.ph29 ]
  %33 = phi i64 [ 1, %.lr.ph29.preheader ], [ %42, %.lr.ph29 ]
  %34 = phi i32 [ %ans.promoted, %.lr.ph29.preheader ], [ %50, %.lr.ph29 ]
  %35 = sub nsw i64 %7, %indvars.iv35
  %36 = mul nsw i64 %33, %35
  %37 = srem i64 %36, 1000000007
  %38 = getelementptr inbounds [1000001 x i32], ptr @inv, i64 0, i64 %indvars.iv35
  %39 = load i32, ptr %38, align 4, !tbaa !5
  %40 = sext i32 %39 to i64
  %41 = mul nsw i64 %37, %40
  %42 = srem i64 %41, 1000000007
  %43 = sext i32 %34 to i64
  %44 = mul nsw i64 %42, %33
  %45 = srem i64 %44, 1000000007
  %46 = sext i32 %.027 to i64
  %47 = mul nsw i64 %45, %46
  %48 = add nsw i64 %47, %43
  %49 = srem i64 %48, 1000000007
  %50 = trunc nsw i64 %49 to i32
  %51 = shl nsw i32 %.027, 1
  %52 = icmp sgt i32 %.027, 500000003
  %53 = add nsw i32 %51, -1000000007
  %spec.select = select i1 %52, i32 %53, i32 %51
  %indvars.iv.next36 = add nuw nsw i64 %indvars.iv35, 1
  %exitcond39.not = icmp eq i64 %indvars.iv.next36, %wide.trip.count38
  br i1 %exitcond39.not, label %._crit_edge30, label %.lr.ph29, !llvm.loop !11

54:                                               ; preds = %22, %4
  ret i32 0
}

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

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

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

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

!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}


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