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

; 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
@tot = external dso_local global i32, align 4
@prime = external dso_local global [125000 x i32], align 16
@phi = external dso_local global [1000001 x i32], align 16
@ans = external dso_local global i32, align 4
@vis = external dso_local global [1000001 x i8], align 16
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = 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)
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #3
  store i32 2, ptr %2, align 4, !tbaa !5
  br label %6

6:                                                ; preds = %114, %0
  %7 = load i32, ptr %2, align 4, !tbaa !5
  %8 = load i32, ptr @n, align 4, !tbaa !5
  %9 = icmp sle i32 %7, %8
  br i1 %9, label %11, label %10

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

11:                                               ; preds = %6
  %12 = load i32, ptr %2, align 4, !tbaa !5
  %13 = sext i32 %12 to i64
  %14 = getelementptr inbounds [1000001 x i8], ptr @vis, i64 0, i64 %13
  %15 = load i8, ptr %14, align 1, !tbaa !9, !range !11, !noundef !12
  %16 = trunc i8 %15 to i1
  br i1 %16, label %28, label %17

17:                                               ; preds = %11
  %18 = load i32, ptr %2, align 4, !tbaa !5
  %19 = load i32, ptr @tot, align 4, !tbaa !5
  %20 = add nsw i32 %19, 1
  store i32 %20, ptr @tot, align 4, !tbaa !5
  %21 = sext i32 %19 to i64
  %22 = getelementptr inbounds [125000 x i32], ptr @prime, i64 0, i64 %21
  store i32 %18, ptr %22, align 4, !tbaa !5
  %23 = load i32, ptr %2, align 4, !tbaa !5
  %24 = sub nsw i32 %23, 1
  %25 = load i32, ptr %2, align 4, !tbaa !5
  %26 = sext i32 %25 to i64
  %27 = getelementptr inbounds [1000001 x i32], ptr @phi, i64 0, i64 %26
  store i32 %24, ptr %27, align 4, !tbaa !5
  br label %28

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

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

33:                                               ; preds = %29
  %34 = load i32, ptr %4, align 4, !tbaa !5
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds [125000 x i32], ptr @prime, i64 0, i64 %35
  %37 = load i32, ptr %36, align 4, !tbaa !5
  %38 = load i32, ptr @n, align 4, !tbaa !5
  %39 = load i32, ptr %2, align 4, !tbaa !5
  %40 = sdiv i32 %38, %39
  %41 = icmp sle i32 %37, %40
  br label %42

42:                                               ; preds = %33, %29
  %43 = phi i1 [ false, %29 ], [ %41, %33 ]
  br i1 %43, label %45, label %44

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

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

61:                                               ; preds = %45
  %62 = load i32, ptr %2, align 4, !tbaa !5
  %63 = sext i32 %62 to i64
  %64 = getelementptr inbounds [1000001 x i32], ptr @phi, i64 0, i64 %63
  %65 = load i32, ptr %64, align 4, !tbaa !5
  %66 = load i32, ptr %4, align 4, !tbaa !5
  %67 = sext i32 %66 to i64
  %68 = getelementptr inbounds [125000 x i32], ptr @prime, i64 0, i64 %67
  %69 = load i32, ptr %68, align 4, !tbaa !5
  %70 = mul nsw i32 %65, %69
  %71 = load i32, ptr %2, align 4, !tbaa !5
  %72 = load i32, ptr %4, align 4, !tbaa !5
  %73 = sext i32 %72 to i64
  %74 = getelementptr inbounds [125000 x i32], ptr @prime, i64 0, i64 %73
  %75 = load i32, ptr %74, align 4, !tbaa !5
  %76 = mul nsw i32 %71, %75
  %77 = sext i32 %76 to i64
  %78 = getelementptr inbounds [1000001 x i32], ptr @phi, i64 0, i64 %77
  store i32 %70, ptr %78, align 4, !tbaa !5
  store i32 5, ptr %3, align 4
  br label %102

79:                                               ; preds = %45
  %80 = load i32, ptr %2, align 4, !tbaa !5
  %81 = sext i32 %80 to i64
  %82 = getelementptr inbounds [1000001 x i32], ptr @phi, i64 0, i64 %81
  %83 = load i32, ptr %82, align 4, !tbaa !5
  %84 = load i32, ptr %4, align 4, !tbaa !5
  %85 = sext i32 %84 to i64
  %86 = getelementptr inbounds [125000 x i32], ptr @prime, i64 0, i64 %85
  %87 = load i32, ptr %86, align 4, !tbaa !5
  %88 = sub nsw i32 %87, 1
  %89 = mul nsw i32 %83, %88
  %90 = load i32, ptr %2, align 4, !tbaa !5
  %91 = load i32, ptr %4, align 4, !tbaa !5
  %92 = sext i32 %91 to i64
  %93 = getelementptr inbounds [125000 x i32], ptr @prime, i64 0, i64 %92
  %94 = load i32, ptr %93, align 4, !tbaa !5
  %95 = mul nsw i32 %90, %94
  %96 = sext i32 %95 to i64
  %97 = getelementptr inbounds [1000001 x i32], ptr @phi, i64 0, i64 %96
  store i32 %89, ptr %97, align 4, !tbaa !5
  br label %98

98:                                               ; preds = %79
  br label %99

99:                                               ; preds = %98
  %100 = load i32, ptr %4, align 4, !tbaa !5
  %101 = add nsw i32 %100, 1
  store i32 %101, ptr %4, align 4, !tbaa !5
  br label %29, !llvm.loop !13

102:                                              ; preds = %61, %44
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  br label %103

103:                                              ; preds = %102
  %104 = load i32, ptr @ans, align 4, !tbaa !5
  %105 = sext i32 %104 to i64
  %106 = load i32, ptr %2, align 4, !tbaa !5
  %107 = sext i32 %106 to i64
  %108 = getelementptr inbounds [1000001 x i32], ptr @phi, i64 0, i64 %107
  %109 = load i32, ptr %108, align 4, !tbaa !5
  %110 = sext i32 %109 to i64
  %111 = mul nsw i64 %105, %110
  %112 = srem i64 %111, 1000000007
  %113 = trunc i64 %112 to i32
  store i32 %113, ptr @ans, align 4, !tbaa !5
  br label %114

114:                                              ; preds = %103
  %115 = load i32, ptr %2, align 4, !tbaa !5
  %116 = add nsw i32 %115, 1
  store i32 %116, ptr %2, align 4, !tbaa !5
  br label %6, !llvm.loop !15

117:                                              ; preds = %10
  %118 = load i32, ptr @ans, align 4, !tbaa !5
  %119 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i32 noundef %118)
  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

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


; 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
@tot = external dso_local local_unnamed_addr global i32, align 4
@prime = external dso_local local_unnamed_addr global [125000 x i32], align 16
@phi = external dso_local local_unnamed_addr global [1000001 x i32], align 16
@ans = external dso_local local_unnamed_addr global i32, align 4
@vis = external dso_local local_unnamed_addr global [1000001 x i8], align 16
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = 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
  %ans.promoted = load i32, ptr @ans, align 4, !tbaa !5
  %.not29 = icmp slt i32 %2, 2
  br i1 %.not29, label %4, label %.lr.ph32.preheader

.lr.ph32.preheader:                               ; preds = %0
  %tot.promoted = load i32, ptr @tot, align 4, !tbaa !5
  %3 = add nuw i32 %2, 1
  %wide.trip.count41 = zext i32 %3 to i64
  br label %.lr.ph32

._crit_edge:                                      ; preds = %.critedge
  store i32 %49, ptr @ans, align 4, !tbaa !5
  br label %4

4:                                                ; preds = %._crit_edge, %0
  %5 = phi i32 [ %49, %._crit_edge ], [ %ans.promoted, %0 ]
  %6 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i32 noundef %5)
  ret i32 0

.lr.ph32:                                         ; preds = %.lr.ph32.preheader, %.critedge
  %indvars.iv38 = phi i64 [ 2, %.lr.ph32.preheader ], [ %indvars.iv.next39, %.critedge ]
  %7 = phi i32 [ %tot.promoted, %.lr.ph32.preheader ], [ %21, %.critedge ]
  %8 = phi i32 [ %ans.promoted, %.lr.ph32.preheader ], [ %49, %.critedge ]
  %9 = getelementptr inbounds [1000001 x i8], ptr @vis, i64 0, i64 %indvars.iv38
  %10 = load i8, ptr %9, align 1, !tbaa !9, !range !11, !noundef !12
  %11 = trunc nuw i8 %10 to i1
  br i1 %11, label %20, label %12

12:                                               ; preds = %.lr.ph32
  %13 = add nsw i32 %7, 1
  store i32 %13, ptr @tot, align 4, !tbaa !5
  %14 = sext i32 %7 to i64
  %15 = getelementptr inbounds [125000 x i32], ptr @prime, i64 0, i64 %14
  %16 = trunc nuw nsw i64 %indvars.iv38 to i32
  store i32 %16, ptr %15, align 4, !tbaa !5
  %17 = getelementptr inbounds [1000001 x i32], ptr @phi, i64 0, i64 %indvars.iv38
  %18 = trunc i64 %indvars.iv38 to i32
  %19 = add i32 %18, -1
  store i32 %19, ptr %17, align 4, !tbaa !5
  br label %20

20:                                               ; preds = %12, %.lr.ph32
  %21 = phi i32 [ %13, %12 ], [ %7, %.lr.ph32 ]
  %22 = icmp sgt i32 %21, 0
  br i1 %22, label %.lr.ph, label %.critedge

.lr.ph:                                           ; preds = %20
  %23 = trunc nuw nsw i64 %indvars.iv38 to i32
  %24 = sdiv i32 %2, %23
  %25 = getelementptr inbounds [1000001 x i32], ptr @phi, i64 0, i64 %indvars.iv38
  %wide.trip.count = zext nneg i32 %21 to i64
  br label %26

26:                                               ; preds = %.lr.ph, %39
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %39 ]
  %27 = getelementptr inbounds [125000 x i32], ptr @prime, i64 0, i64 %indvars.iv
  %28 = load i32, ptr %27, align 4, !tbaa !5
  %.not25 = icmp sgt i32 %28, %24
  br i1 %.not25, label %.critedge, label %29

29:                                               ; preds = %26
  %30 = mul nsw i32 %28, %23
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds [1000001 x i8], ptr @vis, i64 0, i64 %31
  store i8 1, ptr %32, align 1, !tbaa !9
  %33 = srem i32 %23, %28
  %34 = icmp eq i32 %33, 0
  %35 = load i32, ptr %25, align 4, !tbaa !5
  br i1 %34, label %36, label %39

36:                                               ; preds = %29
  %37 = mul nsw i32 %35, %28
  %38 = getelementptr inbounds [1000001 x i32], ptr @phi, i64 0, i64 %31
  store i32 %37, ptr %38, align 4, !tbaa !5
  br label %.critedge

39:                                               ; preds = %29
  %40 = add nsw i32 %28, -1
  %41 = mul nsw i32 %35, %40
  %42 = getelementptr inbounds [1000001 x i32], ptr @phi, i64 0, i64 %31
  store i32 %41, ptr %42, 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 %.critedge, label %26, !llvm.loop !13

.critedge:                                        ; preds = %39, %26, %20, %36
  %43 = sext i32 %8 to i64
  %44 = getelementptr inbounds [1000001 x i32], ptr @phi, i64 0, i64 %indvars.iv38
  %45 = load i32, ptr %44, align 4, !tbaa !5
  %46 = sext i32 %45 to i64
  %47 = mul nsw i64 %46, %43
  %48 = srem i64 %47, 1000000007
  %49 = trunc nsw i64 %48 to i32
  %indvars.iv.next39 = add nuw nsw i64 %indvars.iv38, 1
  %exitcond42.not = icmp eq i64 %indvars.iv.next39, %wide.trip.count41
  br i1 %exitcond42.not, label %._crit_edge, label %.lr.ph32, !llvm.loop !15
}

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


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