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

; 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 i64, align 8
@p = external dso_local global i32, align 4
@m = external dso_local global i32, align 4
@dig = external dso_local global [61 x i32], align 16
@.str = external hidden unnamed_addr constant [7 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.3 = 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 i32, align 4
  store i32 0, ptr %1, align 4
  %3 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n, ptr noundef @p)
  br label %4

4:                                                ; preds = %25, %0
  %5 = load i64, ptr @n, align 8, !tbaa !5
  %6 = icmp ne i64 %5, 0
  br i1 %6, label %7, label %39

7:                                                ; preds = %4
  %8 = load i64, ptr @n, align 8, !tbaa !5
  %9 = load i32, ptr @p, align 4, !tbaa !9
  %10 = sext i32 %9 to i64
  %11 = srem i64 %8, %10
  %12 = trunc i64 %11 to i32
  %13 = load i32, ptr @m, align 4, !tbaa !9
  %14 = sext i32 %13 to i64
  %15 = getelementptr inbounds [61 x i32], ptr @dig, i64 0, i64 %14
  store i32 %12, ptr %15, align 4, !tbaa !9
  %16 = icmp slt i32 %12, 0
  br i1 %16, label %17, label %25

17:                                               ; preds = %7
  %18 = load i32, ptr @p, align 4, !tbaa !9
  %19 = load i32, ptr @m, align 4, !tbaa !9
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds [61 x i32], ptr @dig, i64 0, i64 %20
  %22 = load i32, ptr %21, align 4, !tbaa !9
  %23 = add nsw i32 %22, %18
  store i32 %23, ptr %21, align 4, !tbaa !9
  %24 = icmp ne i32 %23, 0
  br label %25

25:                                               ; preds = %17, %7
  %26 = phi i1 [ false, %7 ], [ %24, %17 ]
  %27 = load i64, ptr @n, align 8, !tbaa !5
  %28 = load i32, ptr @m, align 4, !tbaa !9
  %29 = add nsw i32 %28, 1
  store i32 %29, ptr @m, align 4, !tbaa !9
  %30 = sext i32 %28 to i64
  %31 = getelementptr inbounds [61 x i32], ptr @dig, i64 0, i64 %30
  %32 = load i32, ptr %31, align 4, !tbaa !9
  %33 = sext i32 %32 to i64
  %34 = sub nsw i64 %27, %33
  %35 = load i32, ptr @p, align 4, !tbaa !9
  %36 = sub nsw i32 0, %35
  %37 = sext i32 %36 to i64
  %38 = sdiv i64 %34, %37
  store i64 %38, ptr @n, align 8, !tbaa !5
  br label %4, !llvm.loop !11

39:                                               ; preds = %4
  %40 = load i32, ptr @m, align 4, !tbaa !9
  %41 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i32 noundef %40)
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #3
  store i32 0, ptr %2, align 4, !tbaa !9
  br label %42

42:                                               ; preds = %61, %39
  %43 = load i32, ptr %2, align 4, !tbaa !9
  %44 = load i32, ptr @m, align 4, !tbaa !9
  %45 = icmp slt i32 %43, %44
  br i1 %45, label %47, label %46

46:                                               ; preds = %42
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #3
  br label %64

47:                                               ; preds = %42
  %48 = load i32, ptr %2, align 4, !tbaa !9
  %49 = sext i32 %48 to i64
  %50 = getelementptr inbounds [61 x i32], ptr @dig, i64 0, i64 %49
  %51 = load i32, ptr %50, align 4, !tbaa !9
  %52 = load i32, ptr %2, align 4, !tbaa !9
  %53 = load i32, ptr @m, align 4, !tbaa !9
  %54 = sub nsw i32 %53, 1
  %55 = icmp eq i32 %52, %54
  %56 = zext i1 %55 to i64
  %57 = getelementptr inbounds [3 x i8], ptr @.str.3, i64 0, i64 %56
  %58 = load i8, ptr %57, align 1, !tbaa !13
  %59 = sext i8 %58 to i32
  %60 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i32 noundef %51, i32 noundef %59)
  br label %61

61:                                               ; preds = %47
  %62 = load i32, ptr %2, align 4, !tbaa !9
  %63 = add nsw i32 %62, 1
  store i32 %63, ptr %2, align 4, !tbaa !9
  br label %42, !llvm.loop !14

64:                                               ; preds = %46
  ret i32 0
}

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

declare i32 @printf(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

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 = !{!"long long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = !{!7, !7, i64 0}
!14 = distinct !{!14, !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"

@n = external dso_local global i64, align 8
@p = external dso_local global i32, align 4
@m = external dso_local local_unnamed_addr global i32, align 4
@dig = external dso_local local_unnamed_addr global [61 x i32], align 16
@.str = external hidden unnamed_addr constant [7 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.3 = 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 @n, ptr noundef nonnull @p)
  %.pr = load i64, ptr @n, align 8, !tbaa !5
  %.not6 = icmp eq i64 %.pr, 0
  %.pre = load i32, ptr @m, align 4, !tbaa !9
  br i1 %.not6, label %._crit_edge17, label %.lr.ph

.lr.ph:                                           ; preds = %0
  %2 = load i32, ptr @p, align 4, !tbaa !9
  %3 = sext i32 %2 to i64
  %4 = sub nsw i32 0, %2
  %5 = sext i32 %4 to i64
  %6 = sext i32 %.pre to i64
  br label %7

7:                                                ; preds = %.lr.ph, %7
  %indvars.iv = phi i64 [ %6, %.lr.ph ], [ %indvars.iv.next, %7 ]
  %8 = phi i64 [ %.pr, %.lr.ph ], [ %16, %7 ]
  %9 = srem i64 %8, %3
  %10 = trunc nsw i64 %9 to i32
  %11 = getelementptr inbounds [61 x i32], ptr @dig, i64 0, i64 %indvars.iv
  %12 = icmp slt i64 %9, 0
  %13 = select i1 %12, i32 %2, i32 0
  %spec.select = add nsw i32 %13, %10
  store i32 %spec.select, ptr %11, align 4, !tbaa !9
  %indvars.iv.next = add nsw i64 %indvars.iv, 1
  %14 = sext i32 %spec.select to i64
  %15 = sub nsw i64 %8, %14
  %16 = sdiv i64 %15, %5
  %.not = icmp eq i64 %16, 0
  br i1 %.not, label %._crit_edge, label %7, !llvm.loop !11

._crit_edge:                                      ; preds = %7
  %17 = trunc nsw i64 %indvars.iv.next to i32
  store i32 %17, ptr @m, align 4, !tbaa !9
  store i64 0, ptr @n, align 8, !tbaa !5
  br label %._crit_edge17

._crit_edge17:                                    ; preds = %0, %._crit_edge
  %18 = phi i32 [ %17, %._crit_edge ], [ %.pre, %0 ]
  %19 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i32 noundef %18)
  %20 = load i32, ptr @m, align 4, !tbaa !9
  %21 = icmp sgt i32 %20, 0
  br i1 %21, label %.lr.ph10, label %._crit_edge11

._crit_edge11:                                    ; preds = %.lr.ph10, %._crit_edge17
  ret i32 0

.lr.ph10:                                         ; preds = %._crit_edge17, %.lr.ph10
  %indvars.iv14 = phi i64 [ %indvars.iv.next15, %.lr.ph10 ], [ 0, %._crit_edge17 ]
  %22 = phi i32 [ %33, %.lr.ph10 ], [ %20, %._crit_edge17 ]
  %23 = getelementptr inbounds [61 x i32], ptr @dig, i64 0, i64 %indvars.iv14
  %24 = load i32, ptr %23, align 4, !tbaa !9
  %25 = add nsw i32 %22, -1
  %26 = zext i32 %25 to i64
  %27 = icmp eq i64 %indvars.iv14, %26
  %28 = zext i1 %27 to i64
  %29 = getelementptr inbounds [3 x i8], ptr @.str.3, i64 0, i64 %28
  %30 = load i8, ptr %29, align 1, !tbaa !13
  %31 = sext i8 %30 to i32
  %32 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i32 noundef %24, i32 noundef %31)
  %indvars.iv.next15 = add nuw nsw i64 %indvars.iv14, 1
  %33 = load i32, ptr @m, align 4, !tbaa !9
  %34 = sext i32 %33 to i64
  %35 = icmp slt i64 %indvars.iv.next15, %34
  br i1 %35, label %.lr.ph10, label %._crit_edge11, !llvm.loop !14
}

; 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 = !{!"long long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = !{!7, !7, i64 0}
!14 = distinct !{!14, !12}


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