; LLVM IR from tangjz/acm-icpc :: codeforces/complete (584D)

; 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
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [8 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [11 x i8], align 1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_Z7isprimei(i32 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
  store i32 0, ptr %1, align 4
  %4 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n)
  %5 = load i32, ptr @n, align 4, !tbaa !5
  %6 = call noundef zeroext i1 @_Z7isprimei(i32 noundef %5)
  br i1 %6, label %7, label %10

7:                                                ; preds = %0
  %8 = load i32, ptr @n, align 4, !tbaa !5
  %9 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i32 noundef %8)
  br label %50

10:                                               ; preds = %0
  %11 = load i32, ptr @n, align 4, !tbaa !5
  %12 = sub nsw i32 %11, 2
  %13 = call noundef zeroext i1 @_Z7isprimei(i32 noundef %12)
  br i1 %13, label %14, label %18

14:                                               ; preds = %10
  %15 = load i32, ptr @n, align 4, !tbaa !5
  %16 = sub nsw i32 %15, 2
  %17 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i32 noundef %16)
  br label %49

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

19:                                               ; preds = %44, %18
  %20 = load i32, ptr %2, align 4, !tbaa !5
  %21 = load i32, ptr @n, align 4, !tbaa !5
  %22 = sub nsw i32 %21, 3
  %23 = load i32, ptr %2, align 4, !tbaa !5
  %24 = sub nsw i32 %22, %23
  %25 = icmp slt i32 %20, %24
  br i1 %25, label %27, label %26

26:                                               ; preds = %19
  store i32 2, ptr %3, align 4
  br label %47

27:                                               ; preds = %19
  %28 = load i32, ptr %2, align 4, !tbaa !5
  %29 = call noundef zeroext i1 @_Z7isprimei(i32 noundef %28)
  br i1 %29, label %30, label %43

30:                                               ; preds = %27
  %31 = load i32, ptr @n, align 4, !tbaa !5
  %32 = sub nsw i32 %31, 3
  %33 = load i32, ptr %2, align 4, !tbaa !5
  %34 = sub nsw i32 %32, %33
  %35 = call noundef zeroext i1 @_Z7isprimei(i32 noundef %34)
  br i1 %35, label %36, label %43

36:                                               ; preds = %30
  %37 = load i32, ptr %2, align 4, !tbaa !5
  %38 = load i32, ptr @n, align 4, !tbaa !5
  %39 = sub nsw i32 %38, 3
  %40 = load i32, ptr %2, align 4, !tbaa !5
  %41 = sub nsw i32 %39, %40
  %42 = call i32 (ptr, ...) @printf(ptr noundef @.str.3, i32 noundef %37, i32 noundef %41)
  store i32 2, ptr %3, align 4
  br label %47

43:                                               ; preds = %30, %27
  br label %44

44:                                               ; preds = %43
  %45 = load i32, ptr %2, align 4, !tbaa !5
  %46 = add nsw i32 %45, 2
  store i32 %46, ptr %2, align 4, !tbaa !5
  br label %19, !llvm.loop !9

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

48:                                               ; preds = %47
  br label %49

49:                                               ; preds = %48, %14
  br label %50

50:                                               ; preds = %49, %7
  ret i32 0
}

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

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

attributes #0 = { 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 #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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


; 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
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [8 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [11 x i8], align 1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_Z7isprimei(i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress norecurse nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #1 {
  %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 = tail call noundef zeroext i1 @_Z7isprimei(i32 noundef %2)
  %4 = load i32, ptr @n, align 4, !tbaa !5
  br i1 %3, label %5, label %7

5:                                                ; preds = %0
  %6 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i32 noundef %4)
  br label %.loopexit

7:                                                ; preds = %0
  %8 = add nsw i32 %4, -2
  %9 = tail call noundef zeroext i1 @_Z7isprimei(i32 noundef %8)
  %10 = load i32, ptr @n, align 4, !tbaa !5
  br i1 %9, label %13, label %.preheader

.preheader:                                       ; preds = %7
  %11 = add i32 %10, -6
  %12 = icmp sgt i32 %11, 3
  br i1 %12, label %.lr.ph, label %.loopexit

13:                                               ; preds = %7
  %14 = add nsw i32 %10, -2
  %15 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i32 noundef %14)
  br label %.loopexit

.lr.ph:                                           ; preds = %.preheader, %26
  %.0.neg10 = phi i32 [ %.0.neg, %26 ], [ -3, %.preheader ]
  %.09 = phi i32 [ %27, %26 ], [ 3, %.preheader ]
  %16 = tail call noundef zeroext i1 @_Z7isprimei(i32 noundef %.09)
  br i1 %16, label %17, label %26

17:                                               ; preds = %.lr.ph
  %18 = load i32, ptr @n, align 4, !tbaa !5
  %19 = add i32 %.0.neg10, -3
  %20 = add i32 %19, %18
  %21 = tail call noundef zeroext i1 @_Z7isprimei(i32 noundef %20)
  br i1 %21, label %22, label %26

22:                                               ; preds = %17
  %23 = load i32, ptr @n, align 4, !tbaa !5
  %24 = add i32 %19, %23
  %25 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3, i32 noundef %.09, i32 noundef %24)
  br label %.loopexit

26:                                               ; preds = %.lr.ph, %17
  %27 = add nuw nsw i32 %.09, 2
  %.0.neg = sub nuw i32 -2, %.09
  %28 = load i32, ptr @n, align 4, !tbaa !5
  %reass.sub = sub i32 %28, %.09
  %29 = add i32 %reass.sub, -5
  %30 = icmp slt i32 %27, %29
  br i1 %30, label %.lr.ph, label %.loopexit, !llvm.loop !9

.loopexit:                                        ; preds = %26, %.preheader, %22, %13, %5
  ret i32 0
}

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

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

attributes #0 = { 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 #1 = { mustprogress 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 #2 = { 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"}


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