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

; 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
@m = external dso_local global i32, align 4
@ans = 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 [3 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [4 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
  %3 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  %4 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n, ptr noundef @m)
  %5 = load i32, ptr @m, align 4, !tbaa !5
  %6 = icmp eq i32 %5, 10
  br i1 %6, label %7, label %26

7:                                                ; preds = %0
  %8 = load i32, ptr @n, align 4, !tbaa !5
  %9 = icmp eq i32 %8, 1
  br i1 %9, label %10, label %12

10:                                               ; preds = %7
  %11 = call i32 @puts(ptr noundef @.str.1)
  br label %25

12:                                               ; preds = %7
  %13 = call i32 @putchar(i32 noundef 49)
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #4
  store i32 1, ptr %2, align 4, !tbaa !5
  br label %14

14:                                               ; preds = %21, %12
  %15 = load i32, ptr %2, align 4, !tbaa !5
  %16 = load i32, ptr @n, align 4, !tbaa !5
  %17 = icmp slt i32 %15, %16
  br i1 %17, label %19, label %18

18:                                               ; preds = %14
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #4
  br label %24

19:                                               ; preds = %14
  %20 = call i32 @putchar(i32 noundef 48)
  br label %21

21:                                               ; preds = %19
  %22 = load i32, ptr %2, align 4, !tbaa !5
  %23 = add nsw i32 %22, 1
  store i32 %23, ptr %2, align 4, !tbaa !5
  br label %14, !llvm.loop !9

24:                                               ; preds = %18
  br label %25

25:                                               ; preds = %24, %10
  store i32 0, ptr %1, align 4
  br label %57

26:                                               ; preds = %0
  %27 = load i32, ptr @n, align 4, !tbaa !5
  %28 = icmp eq i32 %27, 1
  br i1 %28, label %29, label %32

29:                                               ; preds = %26
  %30 = load i32, ptr @m, align 4, !tbaa !5
  %31 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i32 noundef %30)
  store i32 0, ptr %1, align 4
  br label %57

32:                                               ; preds = %26
  store i32 1, ptr @ans, align 4, !tbaa !5
  %33 = call i32 @putchar(i32 noundef 49)
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #4
  store i32 2, ptr %3, align 4, !tbaa !5
  br label %34

34:                                               ; preds = %45, %32
  %35 = load i32, ptr %3, align 4, !tbaa !5
  %36 = load i32, ptr @n, align 4, !tbaa !5
  %37 = icmp slt i32 %35, %36
  br i1 %37, label %39, label %38

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

39:                                               ; preds = %34
  %40 = load i32, ptr @ans, align 4, !tbaa !5
  %41 = mul nsw i32 %40, 10
  %42 = load i32, ptr @m, align 4, !tbaa !5
  %43 = srem i32 %41, %42
  store i32 %43, ptr @ans, align 4, !tbaa !5
  %44 = call i32 @putchar(i32 noundef 48)
  br label %45

45:                                               ; preds = %39
  %46 = load i32, ptr %3, align 4, !tbaa !5
  %47 = add nsw i32 %46, 1
  store i32 %47, ptr %3, align 4, !tbaa !5
  br label %34, !llvm.loop !11

48:                                               ; preds = %38
  %49 = load i32, ptr @ans, align 4, !tbaa !5
  %50 = mul nsw i32 %49, 10
  %51 = load i32, ptr @m, align 4, !tbaa !5
  %52 = srem i32 %50, %51
  store i32 %52, ptr @ans, align 4, !tbaa !5
  %53 = load i32, ptr @m, align 4, !tbaa !5
  %54 = load i32, ptr @ans, align 4, !tbaa !5
  %55 = sub nsw i32 %53, %54
  %56 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i32 noundef %55)
  store i32 0, ptr %1, align 4
  br label %57

57:                                               ; preds = %48, %29, %25
  %58 = load i32, ptr %1, align 4
  ret i32 %58
}

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

declare i32 @puts(ptr noundef) #1

; Function Attrs: inlinehint mustprogress uwtable
declare i32 @putchar(i32 noundef) #2

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #3

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #3

declare i32 @printf(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 = { inlinehint 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 #3 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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"}
!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"

@n = external dso_local global i32, align 4
@m = external dso_local global i32, align 4
@ans = external dso_local local_unnamed_addr global i32, align 4
@.str = external hidden unnamed_addr constant [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [4 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 @m)
  %2 = load i32, ptr @m, align 4, !tbaa !5
  %3 = icmp eq i32 %2, 10
  %4 = load i32, ptr @n, align 4, !tbaa !5
  %5 = icmp eq i32 %4, 1
  br i1 %3, label %6, label %17

6:                                                ; preds = %0
  br i1 %5, label %7, label %9

7:                                                ; preds = %6
  %8 = tail call i32 @puts(ptr noundef nonnull dereferenceable(1) @.str.1)
  br label %.loopexit

9:                                                ; preds = %6
  %10 = tail call i32 @putchar(i32 noundef 49)
  %11 = load i32, ptr @n, align 4, !tbaa !5
  %12 = icmp sgt i32 %11, 1
  br i1 %12, label %.lr.ph11, label %.loopexit

.lr.ph11:                                         ; preds = %9, %.lr.ph11
  %.059 = phi i32 [ %14, %.lr.ph11 ], [ 1, %9 ]
  %13 = tail call i32 @putchar(i32 noundef 48)
  %14 = add nuw nsw i32 %.059, 1
  %15 = load i32, ptr @n, align 4, !tbaa !5
  %16 = icmp slt i32 %14, %15
  br i1 %16, label %.lr.ph11, label %.loopexit, !llvm.loop !9

17:                                               ; preds = %0
  br i1 %5, label %18, label %20

18:                                               ; preds = %17
  %19 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i32 noundef %2)
  br label %.loopexit

20:                                               ; preds = %17
  store i32 1, ptr @ans, align 4, !tbaa !5
  %21 = tail call i32 @putchar(i32 noundef 49)
  %22 = load i32, ptr @n, align 4, !tbaa !5
  %23 = icmp sgt i32 %22, 2
  br i1 %23, label %.lr.ph, label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph, %20
  %24 = load i32, ptr @ans, align 4, !tbaa !5
  %25 = mul nsw i32 %24, 10
  %26 = load i32, ptr @m, align 4, !tbaa !5
  %27 = srem i32 %25, %26
  store i32 %27, ptr @ans, align 4, !tbaa !5
  %28 = sub nsw i32 %26, %27
  %29 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i32 noundef %28)
  br label %.loopexit

.lr.ph:                                           ; preds = %20, %.lr.ph
  %.08 = phi i32 [ %35, %.lr.ph ], [ 2, %20 ]
  %30 = load i32, ptr @ans, align 4, !tbaa !5
  %31 = mul nsw i32 %30, 10
  %32 = load i32, ptr @m, align 4, !tbaa !5
  %33 = srem i32 %31, %32
  store i32 %33, ptr @ans, align 4, !tbaa !5
  %34 = tail call i32 @putchar(i32 noundef 48)
  %35 = add nuw nsw i32 %.08, 1
  %36 = load i32, ptr @n, align 4, !tbaa !5
  %37 = icmp slt i32 %35, %36
  br i1 %37, label %.lr.ph, label %._crit_edge, !llvm.loop !11

.loopexit:                                        ; preds = %.lr.ph11, %9, %7, %._crit_edge, %18
  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 @puts(ptr nocapture noundef readonly) local_unnamed_addr #1

; Function Attrs: inlinehint mustprogress nofree nounwind uwtable
declare noundef i32 @putchar(i32 noundef) local_unnamed_addr #2

; 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" }
attributes #2 = { inlinehint mustprogress nofree 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" }

!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,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass