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

; 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
@f = external dso_local global [501 x i32], align 16
@.str = 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
  store i32 0, ptr %1, align 4
  %4 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n)
  store i32 1, ptr @m, align 4, !tbaa !5
  br label %5

5:                                                ; preds = %20, %0
  %6 = load i32, ptr @m, align 4, !tbaa !5
  %7 = sub nsw i32 %6, 1
  %8 = sext i32 %7 to i64
  %9 = getelementptr inbounds [501 x i32], ptr @f, i64 0, i64 %8
  %10 = load i32, ptr %9, align 4, !tbaa !5
  %11 = load i32, ptr @m, align 4, !tbaa !5
  %12 = add nsw i32 %10, %11
  %13 = sub nsw i32 %12, 1
  %14 = load i32, ptr @m, align 4, !tbaa !5
  %15 = sext i32 %14 to i64
  %16 = getelementptr inbounds [501 x i32], ptr @f, i64 0, i64 %15
  store i32 %13, ptr %16, align 4, !tbaa !5
  %17 = load i32, ptr @n, align 4, !tbaa !5
  %18 = icmp sle i32 %13, %17
  br i1 %18, label %19, label %23

19:                                               ; preds = %5
  br label %20

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

23:                                               ; preds = %5
  call void @llvm.lifetime.start.p0(i64 1, ptr %2) #4
  store i8 97, ptr %2, align 1, !tbaa !11
  %24 = load i32, ptr @n, align 4, !tbaa !5
  %25 = icmp ne i32 %24, 0
  br i1 %25, label %28, label %26

26:                                               ; preds = %23
  %27 = call i32 @putchar(i32 noundef 97)
  br label %28

28:                                               ; preds = %26, %23
  br label %29

29:                                               ; preds = %63, %28
  %30 = load i32, ptr @m, align 4, !tbaa !5
  %31 = add nsw i32 %30, -1
  store i32 %31, ptr @m, align 4, !tbaa !5
  %32 = icmp sgt i32 %30, 2
  br i1 %32, label %33, label %64

33:                                               ; preds = %29
  br label %34

34:                                               ; preds = %54, %33
  %35 = load i32, ptr @n, align 4, !tbaa !5
  %36 = load i32, ptr @m, align 4, !tbaa !5
  %37 = sext i32 %36 to i64
  %38 = getelementptr inbounds [501 x i32], ptr @f, i64 0, i64 %37
  %39 = load i32, ptr %38, align 4, !tbaa !5
  %40 = icmp sge i32 %35, %39
  br i1 %40, label %41, label %63

41:                                               ; preds = %34
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #4
  store i32 0, ptr %3, align 4, !tbaa !5
  br label %42

42:                                               ; preds = %51, %41
  %43 = load i32, ptr %3, align 4, !tbaa !5
  %44 = load i32, ptr @m, align 4, !tbaa !5
  %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 %3) #4
  br label %54

47:                                               ; preds = %42
  %48 = load i8, ptr %2, align 1, !tbaa !11
  %49 = sext i8 %48 to i32
  %50 = call i32 @putchar(i32 noundef %49)
  br label %51

51:                                               ; preds = %47
  %52 = load i32, ptr %3, align 4, !tbaa !5
  %53 = add nsw i32 %52, 1
  store i32 %53, ptr %3, align 4, !tbaa !5
  br label %42, !llvm.loop !12

54:                                               ; preds = %46
  %55 = load i8, ptr %2, align 1, !tbaa !11
  %56 = add i8 %55, 1
  store i8 %56, ptr %2, align 1, !tbaa !11
  %57 = load i32, ptr @m, align 4, !tbaa !5
  %58 = sext i32 %57 to i64
  %59 = getelementptr inbounds [501 x i32], ptr @f, i64 0, i64 %58
  %60 = load i32, ptr %59, align 4, !tbaa !5
  %61 = load i32, ptr @n, align 4, !tbaa !5
  %62 = sub nsw i32 %61, %60
  store i32 %62, ptr @n, align 4, !tbaa !5
  br label %34, !llvm.loop !13

63:                                               ; preds = %34
  br label %29, !llvm.loop !14

64:                                               ; preds = %29
  %65 = call i32 @putchar(i32 noundef 10)
  call void @llvm.lifetime.end.p0(i64 1, ptr %2) #4
  ret i32 0
}

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: inlinehint mustprogress uwtable
declare i32 @putchar(i32 noundef) #3

; 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 = { 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 #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 = !{!7, !7, i64 0}
!12 = distinct !{!12, !10}
!13 = distinct !{!13, !10}
!14 = distinct !{!14, !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 local_unnamed_addr global i32, align 4
@f = external dso_local local_unnamed_addr global [501 x i32], align 16
@.str = 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)
  %2 = load i32, ptr @n, align 4, !tbaa !5
  %.pre = load i32, ptr @f, align 16, !tbaa !5
  br label %3

3:                                                ; preds = %3, %0
  %4 = phi i32 [ %7, %3 ], [ %.pre, %0 ]
  %indvars.iv = phi i64 [ %indvars.iv.next, %3 ], [ 1, %0 ]
  %5 = trunc i64 %indvars.iv to i32
  %6 = add i32 %5, -1
  %7 = add i32 %6, %4
  %8 = getelementptr inbounds [501 x i32], ptr @f, i64 0, i64 %indvars.iv
  store i32 %7, ptr %8, align 4, !tbaa !5
  %.not = icmp sgt i32 %7, %2
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  br i1 %.not, label %9, label %3, !llvm.loop !9

9:                                                ; preds = %3
  %10 = trunc nuw nsw i64 %indvars.iv to i32
  store i32 %10, ptr @m, align 4, !tbaa !5
  %.not7 = icmp eq i32 %2, 0
  br i1 %.not7, label %11, label %13

11:                                               ; preds = %9
  %12 = tail call i32 @putchar(i32 noundef 97)
  %.pr.pre = load i32, ptr @m, align 4, !tbaa !5
  br label %13

13:                                               ; preds = %11, %9
  %.pr = phi i32 [ %.pr.pre, %11 ], [ %10, %9 ]
  %14 = add nsw i32 %.pr, -1
  store i32 %14, ptr @m, align 4, !tbaa !5
  %15 = icmp sgt i32 %.pr, 2
  br i1 %15, label %.preheader9.preheader, label %._crit_edge20

.preheader9.preheader:                            ; preds = %13
  %.pre28 = load i32, ptr @n, align 4, !tbaa !5
  br label %.preheader9

.loopexit:                                        ; preds = %._crit_edge, %.preheader9
  %16 = phi i32 [ %n.promoted, %.preheader9 ], [ %33, %._crit_edge ]
  %.1.lcssa = phi i8 [ %.0419, %.preheader9 ], [ %29, %._crit_edge ]
  %.lcssa10 = phi i32 [ %19, %.preheader9 ], [ %27, %._crit_edge ]
  %17 = add nsw i32 %.lcssa10, -1
  store i32 %17, ptr @m, align 4, !tbaa !5
  %18 = icmp sgt i32 %.lcssa10, 2
  br i1 %18, label %.preheader9, label %._crit_edge20, !llvm.loop !11

.preheader9:                                      ; preds = %.preheader9.preheader, %.loopexit
  %19 = phi i32 [ %17, %.loopexit ], [ %14, %.preheader9.preheader ]
  %n.promoted = phi i32 [ %16, %.loopexit ], [ %.pre28, %.preheader9.preheader ]
  %.0419 = phi i8 [ %.1.lcssa, %.loopexit ], [ 97, %.preheader9.preheader ]
  %20 = zext nneg i32 %19 to i64
  %21 = getelementptr inbounds [501 x i32], ptr @f, i64 0, i64 %20
  %22 = load i32, ptr %21, align 4, !tbaa !5
  %.not813 = icmp slt i32 %n.promoted, %22
  br i1 %.not813, label %.loopexit, label %.preheader

.preheader:                                       ; preds = %.preheader9, %._crit_edge
  %23 = phi i32 [ %27, %._crit_edge ], [ %19, %.preheader9 ]
  %24 = phi i32 [ %33, %._crit_edge ], [ %n.promoted, %.preheader9 ]
  %.114 = phi i8 [ %29, %._crit_edge ], [ %.0419, %.preheader9 ]
  %25 = icmp sgt i32 %23, 0
  br i1 %25, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %.preheader
  %26 = sext i8 %.114 to i32
  br label %34

._crit_edge.loopexit:                             ; preds = %34
  %.pre29 = load i32, ptr @n, align 4, !tbaa !5
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %.preheader
  %27 = phi i32 [ %23, %.preheader ], [ %37, %._crit_edge.loopexit ]
  %28 = phi i32 [ %24, %.preheader ], [ %.pre29, %._crit_edge.loopexit ]
  %29 = add i8 %.114, 1
  %30 = sext i32 %27 to i64
  %31 = getelementptr inbounds [501 x i32], ptr @f, i64 0, i64 %30
  %32 = load i32, ptr %31, align 4, !tbaa !5
  %33 = sub nsw i32 %28, %32
  store i32 %33, ptr @n, align 4, !tbaa !5
  %.not8 = icmp slt i32 %33, %32
  br i1 %.not8, label %.loopexit, label %.preheader, !llvm.loop !12

34:                                               ; preds = %.lr.ph, %34
  %.012 = phi i32 [ 0, %.lr.ph ], [ %36, %34 ]
  %35 = tail call i32 @putchar(i32 noundef %26)
  %36 = add nuw nsw i32 %.012, 1
  %37 = load i32, ptr @m, align 4, !tbaa !5
  %38 = icmp slt i32 %36, %37
  br i1 %38, label %34, label %._crit_edge.loopexit, !llvm.loop !14

._crit_edge20:                                    ; preds = %.loopexit, %13
  %39 = tail call i32 @putchar(i32 noundef 10)
  ret i32 0
}

; Function Attrs: nofree nounwind
declare noundef i32 @__isoc99_scanf(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

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}
!12 = distinct !{!12, !10, !13}
!13 = !{!"llvm.loop.unswitch.partial.disable"}
!14 = distinct !{!14, !10}


; Effective O3 passes: ADCEPass,BDCEPass,CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopInstSimplifyPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimpleLoopUnswitchPass,SimplifyCFGPass,TailCallElimPass