; LLVM IR from DionysiosB/CodeForces :: 0500-0599 (584D-DimaAndLisa)

; 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"

@.str = external hidden unnamed_addr constant [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [9 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [15 x i8], align 1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_Z7isPrimel(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 i64, align 8
  %3 = alloca i32, align 4
  %4 = alloca i64, align 8
  %5 = alloca i64, align 8
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #4
  %6 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %2)
  %7 = load i64, ptr %2, align 8, !tbaa !5
  %8 = call noundef zeroext i1 @_Z7isPrimel(i64 noundef %7)
  br i1 %8, label %9, label %12

9:                                                ; preds = %0
  %10 = load i64, ptr %2, align 8, !tbaa !5
  %11 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i64 noundef %10)
  store i32 0, ptr %1, align 4
  store i32 1, ptr %3, align 4
  br label %68

12:                                               ; preds = %0
  %13 = load i64, ptr %2, align 8, !tbaa !5
  %14 = sub nsw i64 %13, 2
  %15 = call noundef zeroext i1 @_Z7isPrimel(i64 noundef %14)
  br i1 %15, label %16, label %20

16:                                               ; preds = %12
  %17 = load i64, ptr %2, align 8, !tbaa !5
  %18 = sub nsw i64 %17, 2
  %19 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i64 noundef %18)
  store i32 0, ptr %1, align 4
  store i32 1, ptr %3, align 4
  br label %68

20:                                               ; preds = %12
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #4
  store i64 2, ptr %4, align 8, !tbaa !5
  br label %21

21:                                               ; preds = %62, %20
  %22 = load i64, ptr %4, align 8, !tbaa !5
  %23 = load i64, ptr %2, align 8, !tbaa !5
  %24 = icmp slt i64 %22, %23
  br i1 %24, label %26, label %25

25:                                               ; preds = %21
  store i32 2, ptr %3, align 4
  br label %65

26:                                               ; preds = %21
  %27 = load i64, ptr %2, align 8, !tbaa !5
  %28 = load i64, ptr %4, align 8, !tbaa !5
  %29 = sub nsw i64 %27, %28
  %30 = call noundef zeroext i1 @_Z7isPrimel(i64 noundef %29)
  br i1 %30, label %32, label %31

31:                                               ; preds = %26
  br label %62

32:                                               ; preds = %26
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  store i64 2, ptr %5, align 8, !tbaa !5
  br label %33

33:                                               ; preds = %56, %32
  %34 = load i64, ptr %5, align 8, !tbaa !5
  %35 = load i64, ptr %4, align 8, !tbaa !5
  %36 = icmp slt i64 %34, %35
  br i1 %36, label %38, label %37

37:                                               ; preds = %33
  store i32 5, ptr %3, align 4
  br label %59

38:                                               ; preds = %33
  %39 = load i64, ptr %5, align 8, !tbaa !5
  %40 = call noundef zeroext i1 @_Z7isPrimel(i64 noundef %39)
  br i1 %40, label %41, label %46

41:                                               ; preds = %38
  %42 = load i64, ptr %4, align 8, !tbaa !5
  %43 = load i64, ptr %5, align 8, !tbaa !5
  %44 = sub nsw i64 %42, %43
  %45 = call noundef zeroext i1 @_Z7isPrimel(i64 noundef %44)
  br i1 %45, label %47, label %46

46:                                               ; preds = %41, %38
  br label %56

47:                                               ; preds = %41
  %48 = load i64, ptr %2, align 8, !tbaa !5
  %49 = load i64, ptr %4, align 8, !tbaa !5
  %50 = sub nsw i64 %48, %49
  %51 = load i64, ptr %4, align 8, !tbaa !5
  %52 = load i64, ptr %5, align 8, !tbaa !5
  %53 = sub nsw i64 %51, %52
  %54 = load i64, ptr %5, align 8, !tbaa !5
  %55 = call i32 (ptr, ...) @printf(ptr noundef @.str.3, i64 noundef %50, i64 noundef %53, i64 noundef %54)
  store i32 0, ptr %1, align 4
  store i32 1, ptr %3, align 4
  br label %59

56:                                               ; preds = %46
  %57 = load i64, ptr %5, align 8, !tbaa !5
  %58 = add nsw i64 %57, 1
  store i64 %58, ptr %5, align 8, !tbaa !5
  br label %33, !llvm.loop !9

59:                                               ; preds = %47, %37
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  %60 = load i32, ptr %3, align 4
  switch i32 %60, label %65 [
    i32 5, label %61
  ]

61:                                               ; preds = %59
  br label %62

62:                                               ; preds = %61, %31
  %63 = load i64, ptr %4, align 8, !tbaa !5
  %64 = add nsw i64 %63, 2
  store i64 %64, ptr %4, align 8, !tbaa !5
  br label %21, !llvm.loop !11

65:                                               ; preds = %59, %25
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #4
  %66 = load i32, ptr %3, align 4
  switch i32 %66, label %68 [
    i32 2, label %67
  ]

67:                                               ; preds = %65
  store i32 0, ptr %1, align 4
  store i32 1, ptr %3, align 4
  br label %68

68:                                               ; preds = %67, %65, %16, %9
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #4
  %69 = load i32, ptr %1, align 4
  ret i32 %69
}

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 = !{!"long", !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"

@.str = external hidden unnamed_addr constant [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [9 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [15 x i8], align 1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_Z7isPrimel(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 nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #2 {
  %1 = alloca i64, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %1) #4
  %2 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %1)
  %3 = load i64, ptr %1, align 8, !tbaa !5
  %4 = call noundef zeroext i1 @_Z7isPrimel(i64 noundef %3)
  %5 = load i64, ptr %1, align 8, !tbaa !5
  br i1 %4, label %6, label %8

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

8:                                                ; preds = %0
  %9 = add nsw i64 %5, -2
  %10 = call noundef zeroext i1 @_Z7isPrimel(i64 noundef %9)
  %11 = load i64, ptr %1, align 8, !tbaa !5
  br i1 %10, label %12, label %.preheader25

.preheader25:                                     ; preds = %8
  %.not2230 = icmp sgt i64 %11, 2
  br i1 %.not2230, label %.lr.ph33, label %.critedge24

12:                                               ; preds = %8
  %13 = add nsw i64 %11, -2
  %14 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i64 noundef %13)
  br label %.critedge24

.lr.ph33:                                         ; preds = %.preheader25, %.critedge
  %15 = phi i64 [ %29, %.critedge ], [ %11, %.preheader25 ]
  %.01731 = phi i64 [ %28, %.critedge ], [ 2, %.preheader25 ]
  %16 = sub nsw i64 %15, %.01731
  %17 = call noundef zeroext i1 @_Z7isPrimel(i64 noundef %16)
  %.not28 = icmp ugt i64 %.01731, 2
  %or.cond = and i1 %17, %.not28
  br i1 %or.cond, label %.lr.ph, label %.critedge

.lr.ph:                                           ; preds = %.lr.ph33, %26
  %.029 = phi i64 [ %27, %26 ], [ 2, %.lr.ph33 ]
  %18 = call noundef zeroext i1 @_Z7isPrimel(i64 noundef %.029)
  br i1 %18, label %19, label %26

19:                                               ; preds = %.lr.ph
  %20 = sub nsw i64 %.01731, %.029
  %21 = call noundef zeroext i1 @_Z7isPrimel(i64 noundef %20)
  br i1 %21, label %22, label %26

22:                                               ; preds = %19
  %23 = load i64, ptr %1, align 8, !tbaa !5
  %24 = sub nsw i64 %23, %.01731
  %25 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3, i64 noundef %24, i64 noundef %20, i64 noundef %.029)
  br label %.critedge24

26:                                               ; preds = %.lr.ph, %19
  %27 = add nuw nsw i64 %.029, 1
  %.not = icmp ult i64 %27, %.01731
  br i1 %.not, label %.lr.ph, label %.critedge, !llvm.loop !9

.critedge:                                        ; preds = %26, %.lr.ph33
  %28 = add nuw nsw i64 %.01731, 2
  %29 = load i64, ptr %1, align 8, !tbaa !5
  %.not22 = icmp slt i64 %28, %29
  br i1 %.not22, label %.lr.ph33, label %.critedge24, !llvm.loop !11

.critedge24:                                      ; preds = %.critedge, %.preheader25, %22, %12, %6
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %1) #4
  ret i32 0
}

; 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 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 nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #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 = !{!"long", !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: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass