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

; 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 [4641589 x i32], align 16
@mu = external dso_local global [4641589 x i32], align 16
@f = external dso_local global [4641589 x i32], align 16
@vis = external dso_local global [4641589 x i8], align 16
@.str = external hidden unnamed_addr constant [9 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [6 x i8], align 1

; Function Attrs: mustprogress uwtable
declare dso_local noundef i64 @_Z1Fx(i64 noundef) #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 norecurse uwtable
define dso_local noundef i32 @main() #2 {
  %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 i64, align 8
  %7 = alloca i64, align 8
  store i32 0, ptr %1, align 4
  store i32 1, ptr getelementptr inbounds ([4641589 x i32], ptr @f, i64 0, i64 1), align 4, !tbaa !5
  store i32 1, ptr getelementptr inbounds ([4641589 x i32], ptr @mu, i64 0, i64 1), align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #4
  store i32 2, ptr %2, align 4, !tbaa !5
  br label %8

8:                                                ; preds = %102, %0
  %9 = load i32, ptr %2, align 4, !tbaa !5
  %10 = icmp slt i32 %9, 4641589
  br i1 %10, label %12, label %11

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

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

18:                                               ; preds = %12
  %19 = load i32, ptr %2, align 4, !tbaa !5
  %20 = load i32, ptr @tot, align 4, !tbaa !5
  %21 = add nsw i32 %20, 1
  store i32 %21, ptr @tot, align 4, !tbaa !5
  %22 = sext i32 %20 to i64
  %23 = getelementptr inbounds [4641589 x i32], ptr @prime, i64 0, i64 %22
  store i32 %19, ptr %23, align 4, !tbaa !5
  %24 = load i32, ptr %2, align 4, !tbaa !5
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds [4641589 x i32], ptr @mu, i64 0, i64 %25
  store i32 -1, ptr %26, align 4, !tbaa !5
  br label %27

27:                                               ; preds = %18, %12
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #4
  store i32 0, ptr %4, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  %28 = load i32, ptr %2, align 4, !tbaa !5
  %29 = sdiv i32 4641588, %28
  store i32 %29, ptr %5, align 4, !tbaa !5
  br label %30

30:                                               ; preds = %84, %27
  %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 %41

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

41:                                               ; preds = %34, %30
  %42 = phi i1 [ false, %30 ], [ %40, %34 ]
  br i1 %42, label %44, label %43

43:                                               ; preds = %41
  store i32 5, ptr %3, align 4
  br label %87

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

60:                                               ; preds = %44
  %61 = load i32, ptr %2, align 4, !tbaa !5
  %62 = load i32, ptr %4, align 4, !tbaa !5
  %63 = sext i32 %62 to i64
  %64 = getelementptr inbounds [4641589 x i32], ptr @prime, i64 0, i64 %63
  %65 = load i32, ptr %64, align 4, !tbaa !5
  %66 = mul nsw i32 %61, %65
  %67 = sext i32 %66 to i64
  %68 = getelementptr inbounds [4641589 x i32], ptr @mu, i64 0, i64 %67
  store i32 0, ptr %68, align 4, !tbaa !5
  store i32 5, ptr %3, align 4
  br label %87

69:                                               ; preds = %44
  %70 = load i32, ptr %2, align 4, !tbaa !5
  %71 = sext i32 %70 to i64
  %72 = getelementptr inbounds [4641589 x i32], ptr @mu, i64 0, i64 %71
  %73 = load i32, ptr %72, align 4, !tbaa !5
  %74 = sub nsw i32 0, %73
  %75 = load i32, ptr %2, align 4, !tbaa !5
  %76 = load i32, ptr %4, align 4, !tbaa !5
  %77 = sext i32 %76 to i64
  %78 = getelementptr inbounds [4641589 x i32], ptr @prime, i64 0, i64 %77
  %79 = load i32, ptr %78, align 4, !tbaa !5
  %80 = mul nsw i32 %75, %79
  %81 = sext i32 %80 to i64
  %82 = getelementptr inbounds [4641589 x i32], ptr @mu, i64 0, i64 %81
  store i32 %74, ptr %82, align 4, !tbaa !5
  br label %83

83:                                               ; preds = %69
  br label %84

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

87:                                               ; preds = %60, %43
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #4
  br label %88

88:                                               ; preds = %87
  %89 = load i32, ptr %2, align 4, !tbaa !5
  %90 = sub nsw i32 %89, 1
  %91 = sext i32 %90 to i64
  %92 = getelementptr inbounds [4641589 x i32], ptr @f, i64 0, i64 %91
  %93 = load i32, ptr %92, align 4, !tbaa !5
  %94 = load i32, ptr %2, align 4, !tbaa !5
  %95 = sext i32 %94 to i64
  %96 = getelementptr inbounds [4641589 x i32], ptr @mu, i64 0, i64 %95
  %97 = load i32, ptr %96, align 4, !tbaa !5
  %98 = add nsw i32 %93, %97
  %99 = load i32, ptr %2, align 4, !tbaa !5
  %100 = sext i32 %99 to i64
  %101 = getelementptr inbounds [4641589 x i32], ptr @f, i64 0, i64 %100
  store i32 %98, ptr %101, align 4, !tbaa !5
  br label %102

102:                                              ; preds = %88
  %103 = load i32, ptr %2, align 4, !tbaa !5
  %104 = add nsw i32 %103, 1
  store i32 %104, ptr %2, align 4, !tbaa !5
  br label %8, !llvm.loop !15

105:                                              ; preds = %11
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  %106 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %6, ptr noundef %7)
  %107 = load i64, ptr %7, align 8, !tbaa !16
  %108 = call noundef i64 @_Z1Fx(i64 noundef %107)
  %109 = load i64, ptr %6, align 8, !tbaa !16
  %110 = sub nsw i64 %109, 1
  %111 = call noundef i64 @_Z1Fx(i64 noundef %110)
  %112 = sub nsw i64 %108, %111
  %113 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i64 noundef %112)
  store i32 0, ptr %1, align 4
  store i32 1, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  %114 = load i32, ptr %1, align 4
  ret i32 %114
}

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

declare i32 @printf(ptr noundef, ...) #3

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 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 #3 = { "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 = !{!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 = !{!17, !17, i64 0}
!17 = !{!"long long", !7, i64 0}


; 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 [4641589 x i32], align 16
@mu = external dso_local local_unnamed_addr global [4641589 x i32], align 16
@f = external dso_local local_unnamed_addr global [4641589 x i32], align 16
@vis = external dso_local local_unnamed_addr global [4641589 x i8], align 16
@.str = external hidden unnamed_addr constant [9 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [6 x i8], align 1

; Function Attrs: mustprogress uwtable
declare dso_local noundef i64 @_Z1Fx(i64 noundef) 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 norecurse uwtable
define dso_local noundef i32 @main() local_unnamed_addr #2 {
  %1 = alloca i64, align 8
  %2 = alloca i64, align 8
  store i32 1, ptr getelementptr inbounds (i8, ptr @f, i64 4), align 4, !tbaa !5
  store i32 1, ptr getelementptr inbounds (i8, ptr @mu, i64 4), align 4, !tbaa !5
  %tot.promoted = load i32, ptr @tot, align 4, !tbaa !5
  br label %12

3:                                                ; preds = %.critedge
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %1) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %2) #4
  %4 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %1, ptr noundef nonnull %2)
  %5 = load i64, ptr %2, align 8, !tbaa !9
  %6 = call noundef i64 @_Z1Fx(i64 noundef %5)
  %7 = load i64, ptr %1, align 8, !tbaa !9
  %8 = add nsw i64 %7, -1
  %9 = call noundef i64 @_Z1Fx(i64 noundef %8)
  %10 = sub nsw i64 %6, %9
  %11 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i64 noundef %10)
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %1) #4
  ret i32 0

12:                                               ; preds = %0, %.critedge
  %13 = phi i32 [ 1, %0 ], [ %46, %.critedge ]
  %indvars.iv29 = phi i64 [ 2, %0 ], [ %indvars.iv.next30, %.critedge ]
  %14 = phi i32 [ %tot.promoted, %0 ], [ %25, %.critedge ]
  %15 = getelementptr inbounds [4641589 x i8], ptr @vis, i64 0, i64 %indvars.iv29
  %16 = load i8, ptr %15, align 1, !tbaa !11, !range !13, !noundef !14
  %17 = trunc nuw i8 %16 to i1
  br i1 %17, label %._crit_edge, label %18

._crit_edge:                                      ; preds = %12
  %.pre = trunc nuw nsw i64 %indvars.iv29 to i32
  br label %24

18:                                               ; preds = %12
  %19 = add nsw i32 %14, 1
  store i32 %19, ptr @tot, align 4, !tbaa !5
  %20 = sext i32 %14 to i64
  %21 = getelementptr inbounds [4641589 x i32], ptr @prime, i64 0, i64 %20
  %22 = trunc nuw nsw i64 %indvars.iv29 to i32
  store i32 %22, ptr %21, align 4, !tbaa !5
  %23 = getelementptr inbounds [4641589 x i32], ptr @mu, i64 0, i64 %indvars.iv29
  store i32 -1, ptr %23, align 4, !tbaa !5
  br label %24

24:                                               ; preds = %._crit_edge, %18
  %.pre-phi = phi i32 [ %.pre, %._crit_edge ], [ %22, %18 ]
  %25 = phi i32 [ %14, %._crit_edge ], [ %19, %18 ]
  %26 = udiv i32 4641588, %.pre-phi
  %27 = icmp sgt i32 %25, 0
  br i1 %27, label %.lr.ph, label %.critedge

.lr.ph:                                           ; preds = %24
  %28 = getelementptr inbounds [4641589 x i32], ptr @mu, i64 0, i64 %indvars.iv29
  %wide.trip.count = zext nneg i32 %25 to i64
  br label %29

29:                                               ; preds = %.lr.ph, %40
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %40 ]
  %30 = getelementptr inbounds [4641589 x i32], ptr @prime, i64 0, i64 %indvars.iv
  %31 = load i32, ptr %30, align 4, !tbaa !5
  %.not = icmp sgt i32 %31, %26
  br i1 %.not, label %.critedge, label %32

32:                                               ; preds = %29
  %33 = sext i32 %31 to i64
  %34 = mul nsw i64 %indvars.iv29, %33
  %35 = getelementptr inbounds [4641589 x i8], ptr @vis, i64 0, i64 %34
  store i8 1, ptr %35, align 1, !tbaa !11
  %36 = srem i32 %.pre-phi, %31
  %37 = icmp eq i32 %36, 0
  br i1 %37, label %38, label %40

38:                                               ; preds = %32
  %39 = getelementptr inbounds [4641589 x i32], ptr @mu, i64 0, i64 %34
  store i32 0, ptr %39, align 4, !tbaa !5
  br label %.critedge

40:                                               ; preds = %32
  %41 = load i32, ptr %28, align 4, !tbaa !5
  %42 = sub nsw i32 0, %41
  %43 = getelementptr inbounds [4641589 x i32], ptr @mu, i64 0, i64 %34
  store i32 %42, ptr %43, 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 %29, !llvm.loop !15

.critedge:                                        ; preds = %40, %29, %24, %38
  %44 = getelementptr inbounds [4641589 x i32], ptr @mu, i64 0, i64 %indvars.iv29
  %45 = load i32, ptr %44, align 4, !tbaa !5
  %46 = add nsw i32 %45, %13
  %47 = getelementptr inbounds [4641589 x i32], ptr @f, i64 0, i64 %indvars.iv29
  store i32 %46, ptr %47, align 4, !tbaa !5
  %indvars.iv.next30 = add nuw nsw i64 %indvars.iv29, 1
  %exitcond32.not = icmp eq i64 %indvars.iv.next30, 4641589
  br i1 %exitcond32.not, label %3, label %12, !llvm.loop !17
}

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

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

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 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 #3 = { 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 #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 = !{!10, !10, i64 0}
!10 = !{!"long long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"bool", !7, i64 0}
!13 = !{i8 0, i8 2}
!14 = !{}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = distinct !{!17, !16}


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