; LLVM IR from tangjz/acm-icpc :: codeforces/complete (937B)

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

@p = external dso_local global i32, align 4
@y = external dso_local global i32, align 4
@.str = external hidden unnamed_addr constant [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [3 x i8], align 1

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #0 {
  %1 = alloca i32, align 4
  %2 = alloca i8, align 1
  %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 @p, ptr noundef @y)
  br label %6

6:                                                ; preds = %45, %0
  %7 = load i32, ptr @p, align 4, !tbaa !5
  %8 = load i32, ptr @y, align 4, !tbaa !5
  %9 = icmp slt i32 %7, %8
  br i1 %9, label %10, label %48

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

11:                                               ; preds = %31, %10
  %12 = load i32, ptr %3, align 4, !tbaa !5
  %13 = load i32, ptr @p, align 4, !tbaa !5
  %14 = icmp sle i32 %12, %13
  br i1 %14, label %15, label %21

15:                                               ; preds = %11
  %16 = load i32, ptr %3, align 4, !tbaa !5
  %17 = load i32, ptr %3, align 4, !tbaa !5
  %18 = mul nsw i32 %16, %17
  %19 = load i32, ptr @y, align 4, !tbaa !5
  %20 = icmp sle i32 %18, %19
  br label %21

21:                                               ; preds = %15, %11
  %22 = phi i1 [ false, %11 ], [ %20, %15 ]
  br i1 %22, label %24, label %23

23:                                               ; preds = %21
  store i32 5, ptr %4, align 4
  br label %34

24:                                               ; preds = %21
  %25 = load i32, ptr @y, align 4, !tbaa !5
  %26 = load i32, ptr %3, align 4, !tbaa !5
  %27 = srem i32 %25, %26
  %28 = icmp eq i32 %27, 0
  br i1 %28, label %29, label %30

29:                                               ; preds = %24
  store i8 0, ptr %2, align 1, !tbaa !9
  store i32 5, ptr %4, align 4
  br label %34

30:                                               ; preds = %24
  br label %31

31:                                               ; preds = %30
  %32 = load i32, ptr %3, align 4, !tbaa !5
  %33 = add nsw i32 %32, 1
  store i32 %33, ptr %3, align 4, !tbaa !5
  br label %11, !llvm.loop !11

34:                                               ; preds = %29, %23
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  br label %35

35:                                               ; preds = %34
  %36 = load i8, ptr %2, align 1, !tbaa !9, !range !13, !noundef !14
  %37 = trunc i8 %36 to i1
  br i1 %37, label %38, label %41

38:                                               ; preds = %35
  %39 = load i32, ptr @y, align 4, !tbaa !5
  %40 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i32 noundef %39)
  store i32 0, ptr %1, align 4
  store i32 1, ptr %4, align 4
  br label %42

41:                                               ; preds = %35
  store i32 0, ptr %4, align 4
  br label %42

42:                                               ; preds = %41, %38
  call void @llvm.lifetime.end.p0(i64 1, ptr %2) #3
  %43 = load i32, ptr %4, align 4
  switch i32 %43, label %52 [
    i32 0, label %44
    i32 1, label %50
  ]

44:                                               ; preds = %42
  br label %45

45:                                               ; preds = %44
  %46 = load i32, ptr @y, align 4, !tbaa !5
  %47 = add nsw i32 %46, -1
  store i32 %47, ptr @y, align 4, !tbaa !5
  br label %6, !llvm.loop !15

48:                                               ; preds = %6
  %49 = call i32 @puts(ptr noundef @.str.2)
  store i32 0, ptr %1, align 4
  br label %50

50:                                               ; preds = %48, %42
  %51 = load i32, ptr %1, align 4
  ret i32 %51

52:                                               ; preds = %42
  unreachable
}

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

declare i32 @puts(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 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = !{i8 0, i8 2}
!14 = !{}
!15 = distinct !{!15, !12}


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

@p = external dso_local global i32, align 4
@y = external dso_local global i32, align 4
@.str = external hidden unnamed_addr constant [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [3 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 @p, ptr noundef nonnull @y)
  %2 = load i32, ptr @p, align 4, !tbaa !5
  %.fr = freeze i32 %2
  %y.promoted = load i32, ptr @y, align 4, !tbaa !5
  %3 = icmp slt i32 %.fr, %y.promoted
  br i1 %3, label %.preheader.lr.ph, label %._crit_edge

.preheader.lr.ph:                                 ; preds = %0
  %.not20 = icmp slt i32 %.fr, 2
  br i1 %.not20, label %.critedge, label %.preheader

.preheader:                                       ; preds = %.preheader.lr.ph, %11
  %4 = phi i32 [ %12, %11 ], [ %y.promoted, %.preheader.lr.ph ]
  %.not1221 = icmp slt i32 %4, 4
  br i1 %.not1221, label %.critedge, label %.lr.ph

5:                                                ; preds = %.lr.ph
  %6 = add nuw nsw i32 %.0823, 1
  %.not = icmp sge i32 %.0823, %.fr
  %7 = mul nuw nsw i32 %6, %6
  %.not12 = icmp sgt i32 %7, %4
  %or.cond = select i1 %.not, i1 true, i1 %.not12
  br i1 %or.cond, label %.critedge, label %.lr.ph, !llvm.loop !9

.lr.ph:                                           ; preds = %.preheader, %5
  %.0823 = phi i32 [ %6, %5 ], [ 2, %.preheader ]
  %8 = urem i32 %4, %.0823
  %9 = icmp eq i32 %8, 0
  br i1 %9, label %11, label %5

.critedge:                                        ; preds = %.preheader, %5, %.preheader.lr.ph
  %.lcssa19 = phi i32 [ %y.promoted, %.preheader.lr.ph ], [ %4, %5 ], [ %4, %.preheader ]
  %10 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i32 noundef %.lcssa19)
  br label %15

11:                                               ; preds = %.lr.ph
  %12 = add nsw i32 %4, -1
  store i32 %12, ptr @y, align 4, !tbaa !5
  %13 = icmp slt i32 %.fr, %12
  br i1 %13, label %.preheader, label %._crit_edge, !llvm.loop !11

._crit_edge:                                      ; preds = %11, %0
  %14 = tail call i32 @puts(ptr noundef nonnull dereferenceable(1) @.str.2)
  br label %15

15:                                               ; preds = %.critedge, %._crit_edge
  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 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #1

; Function Attrs: nofree nounwind
declare noundef i32 @puts(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: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopInstSimplifyPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass