; LLVM IR from tangjz/acm-icpc :: codeforces/complete (662D)

; 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
@sta = external dso_local global [10 x i32], align 16
@pw10 = external dso_local global [10 x i32], align 16
@s = external dso_local global [10 x i32], align 16
@num = external dso_local global i32, align 4
@str = external dso_local global [100 x i8], align 16
@.str = external hidden unnamed_addr constant [3 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
  %4 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  store i32 1, ptr @pw10, align 16, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #5
  store i32 1, ptr %2, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #5
  store i32 1989, ptr %3, align 4, !tbaa !5
  br label %5

5:                                                ; preds = %47, %0
  %6 = load i32, ptr %2, align 4, !tbaa !5
  %7 = icmp slt i32 %6, 10
  br i1 %7, label %9, label %8

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

9:                                                ; preds = %5
  %10 = load i32, ptr %2, align 4, !tbaa !5
  %11 = sub nsw i32 %10, 1
  %12 = sext i32 %11 to i64
  %13 = getelementptr inbounds [10 x i32], ptr @pw10, i64 0, i64 %12
  %14 = load i32, ptr %13, align 4, !tbaa !5
  %15 = mul nsw i32 %14, 10
  %16 = load i32, ptr %2, align 4, !tbaa !5
  %17 = sext i32 %16 to i64
  %18 = getelementptr inbounds [10 x i32], ptr @pw10, i64 0, i64 %17
  store i32 %15, ptr %18, align 4, !tbaa !5
  %19 = load i32, ptr %2, align 4, !tbaa !5
  %20 = sub nsw i32 %19, 1
  %21 = sext i32 %20 to i64
  %22 = getelementptr inbounds [10 x i32], ptr @s, i64 0, i64 %21
  %23 = load i32, ptr %22, align 4, !tbaa !5
  %24 = load i32, ptr %2, align 4, !tbaa !5
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds [10 x i32], ptr @pw10, i64 0, i64 %25
  %27 = load i32, ptr %26, align 4, !tbaa !5
  %28 = add nsw i32 %23, %27
  %29 = load i32, ptr %2, align 4, !tbaa !5
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds [10 x i32], ptr @s, i64 0, i64 %30
  store i32 %28, ptr %31, align 4, !tbaa !5
  %32 = load i32, ptr %3, align 4, !tbaa !5
  %33 = load i32, ptr %2, align 4, !tbaa !5
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds [10 x i32], ptr @pw10, i64 0, i64 %34
  %36 = load i32, ptr %35, align 4, !tbaa !5
  %37 = srem i32 %32, %36
  %38 = load i32, ptr %2, align 4, !tbaa !5
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds [10 x i32], ptr @sta, i64 0, i64 %39
  store i32 %37, ptr %40, align 4, !tbaa !5
  %41 = load i32, ptr %2, align 4, !tbaa !5
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds [10 x i32], ptr @pw10, i64 0, i64 %42
  %44 = load i32, ptr %43, align 4, !tbaa !5
  %45 = load i32, ptr %3, align 4, !tbaa !5
  %46 = add nsw i32 %45, %44
  store i32 %46, ptr %3, align 4, !tbaa !5
  br label %47

47:                                               ; preds = %9
  %48 = load i32, ptr %2, align 4, !tbaa !5
  %49 = add nsw i32 %48, 1
  store i32 %49, ptr %2, align 4, !tbaa !5
  br label %5, !llvm.loop !9

50:                                               ; preds = %8
  %51 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n)
  br label %52

52:                                               ; preds = %98, %50
  %53 = load i32, ptr @n, align 4, !tbaa !5
  %54 = add nsw i32 %53, -1
  store i32 %54, ptr @n, align 4, !tbaa !5
  %55 = icmp ne i32 %53, 0
  br i1 %55, label %56, label %102

56:                                               ; preds = %52
  %57 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef @str)
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #5
  %58 = call i64 @strlen(ptr noundef getelementptr inbounds (i8, ptr @str, i64 4)) #6
  %59 = trunc i64 %58 to i32
  store i32 %59, ptr %4, align 4, !tbaa !5
  %60 = call i32 (ptr, ptr, ...) @__isoc99_sscanf(ptr noundef getelementptr inbounds (i8, ptr @str, i64 4), ptr noundef @.str, ptr noundef @num) #5
  %61 = load i32, ptr @num, align 4, !tbaa !5
  %62 = load i32, ptr %4, align 4, !tbaa !5
  %63 = sext i32 %62 to i64
  %64 = getelementptr inbounds [10 x i32], ptr @sta, i64 0, i64 %63
  %65 = load i32, ptr %64, align 4, !tbaa !5
  %66 = icmp slt i32 %61, %65
  br i1 %66, label %67, label %85

67:                                               ; preds = %56
  %68 = load i32, ptr @num, align 4, !tbaa !5
  %69 = load i32, ptr %4, align 4, !tbaa !5
  %70 = sext i32 %69 to i64
  %71 = getelementptr inbounds [10 x i32], ptr @sta, i64 0, i64 %70
  %72 = load i32, ptr %71, align 4, !tbaa !5
  %73 = sub nsw i32 %68, %72
  %74 = load i32, ptr %4, align 4, !tbaa !5
  %75 = sext i32 %74 to i64
  %76 = getelementptr inbounds [10 x i32], ptr @pw10, i64 0, i64 %75
  %77 = load i32, ptr %76, align 4, !tbaa !5
  %78 = add nsw i32 %73, %77
  %79 = load i32, ptr %4, align 4, !tbaa !5
  %80 = sub nsw i32 %79, 1
  %81 = sext i32 %80 to i64
  %82 = getelementptr inbounds [10 x i32], ptr @s, i64 0, i64 %81
  %83 = load i32, ptr %82, align 4, !tbaa !5
  %84 = add nsw i32 %78, %83
  store i32 %84, ptr @num, align 4, !tbaa !5
  br label %98

85:                                               ; preds = %56
  %86 = load i32, ptr @num, align 4, !tbaa !5
  %87 = load i32, ptr %4, align 4, !tbaa !5
  %88 = sext i32 %87 to i64
  %89 = getelementptr inbounds [10 x i32], ptr @sta, i64 0, i64 %88
  %90 = load i32, ptr %89, align 4, !tbaa !5
  %91 = sub nsw i32 %86, %90
  %92 = load i32, ptr %4, align 4, !tbaa !5
  %93 = sub nsw i32 %92, 1
  %94 = sext i32 %93 to i64
  %95 = getelementptr inbounds [10 x i32], ptr @s, i64 0, i64 %94
  %96 = load i32, ptr %95, align 4, !tbaa !5
  %97 = add nsw i32 %91, %96
  store i32 %97, ptr @num, align 4, !tbaa !5
  br label %98

98:                                               ; preds = %85, %67
  %99 = load i32, ptr @num, align 4, !tbaa !5
  %100 = add nsw i32 %99, 1989
  %101 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i32 noundef %100)
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #5
  br label %52, !llvm.loop !11

102:                                              ; preds = %52
  ret i32 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

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

; Function Attrs: nounwind willreturn memory(read)
declare i64 @strlen(ptr noundef) #3

; Function Attrs: nounwind
declare i32 @__isoc99_sscanf(ptr noundef, ptr noundef, ...) #4

declare i32 @printf(ptr noundef, ...) #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { "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 = { nounwind willreturn memory(read) "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 "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 #5 = { nounwind }
attributes #6 = { nounwind willreturn memory(read) }

!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
@sta = external dso_local local_unnamed_addr global [10 x i32], align 16
@pw10 = external dso_local local_unnamed_addr global [10 x i32], align 16
@s = external dso_local local_unnamed_addr global [10 x i32], align 16
@num = external dso_local global i32, align 4
@str = external dso_local global [100 x i8], align 16
@.str = external hidden unnamed_addr constant [3 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 = load i32, ptr @s, align 16, !tbaa !5
  store <4 x i32> <i32 1, i32 10, i32 100, i32 1000>, ptr @pw10, align 16, !tbaa !5
  %2 = insertelement <4 x i32> poison, i32 %1, i64 0
  %3 = shufflevector <4 x i32> %2, <4 x i32> poison, <4 x i32> zeroinitializer
  %4 = add nsw <4 x i32> %3, <i32 10, i32 110, i32 1110, i32 11110>
  store <4 x i32> %4, ptr getelementptr inbounds (i8, ptr @s, i64 4), align 4, !tbaa !5
  store <4 x i32> <i32 9, i32 99, i32 99, i32 3099>, ptr getelementptr inbounds (i8, ptr @sta, i64 4), align 4, !tbaa !5
  store <4 x i32> <i32 10000, i32 100000, i32 1000000, i32 10000000>, ptr getelementptr inbounds (i8, ptr @pw10, i64 16), align 16, !tbaa !5
  store i32 100000000, ptr getelementptr inbounds (i8, ptr @pw10, i64 32), align 16, !tbaa !5
  %5 = add nsw <4 x i32> %3, <i32 111110, i32 1111110, i32 11111110, i32 111111110>
  store <4 x i32> %5, ptr getelementptr inbounds (i8, ptr @s, i64 20), align 4, !tbaa !5
  store <4 x i32> <i32 13099, i32 113099, i32 1113099, i32 11113099>, ptr getelementptr inbounds (i8, ptr @sta, i64 20), align 4, !tbaa !5
  store i32 1000000000, ptr getelementptr inbounds (i8, ptr @pw10, i64 36), align 4, !tbaa !5
  %6 = add nsw i32 %1, 1111111110
  store i32 %6, ptr getelementptr inbounds (i8, ptr @s, i64 36), align 4, !tbaa !5
  store i32 111113099, ptr getelementptr inbounds (i8, ptr @sta, i64 36), align 4, !tbaa !5
  %7 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @n)
  %8 = load i32, ptr @n, align 4, !tbaa !5
  %9 = add nsw i32 %8, -1
  store i32 %9, ptr @n, align 4, !tbaa !5
  %.not26 = icmp eq i32 %8, 0
  br i1 %.not26, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %0, %23
  %10 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull @str)
  %11 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) getelementptr inbounds (i8, ptr @str, i64 4)) #3
  %12 = tail call i32 (ptr, ptr, ...) @__isoc99_sscanf(ptr noundef nonnull getelementptr inbounds (i8, ptr @str, i64 4), ptr noundef nonnull @.str, ptr noundef nonnull @num) #4
  %13 = load i32, ptr @num, align 4, !tbaa !5
  %sext = shl i64 %11, 32
  %14 = ashr exact i64 %sext, 32
  %15 = getelementptr inbounds [10 x i32], ptr @sta, i64 0, i64 %14
  %16 = load i32, ptr %15, align 4, !tbaa !5
  %17 = icmp slt i32 %13, %16
  %18 = sub i32 %13, %16
  br i1 %17, label %19, label %23

19:                                               ; preds = %.lr.ph
  %20 = getelementptr inbounds [10 x i32], ptr @pw10, i64 0, i64 %14
  %21 = load i32, ptr %20, align 4, !tbaa !5
  %22 = add nsw i32 %18, %21
  br label %23

23:                                               ; preds = %.lr.ph, %19
  %.sink = phi i32 [ %22, %19 ], [ %18, %.lr.ph ]
  %sext22 = add i64 %sext, -4294967296
  %24 = ashr exact i64 %sext22, 32
  %25 = getelementptr inbounds [10 x i32], ptr @s, i64 0, i64 %24
  %26 = load i32, ptr %25, align 4, !tbaa !5
  %27 = add nsw i32 %.sink, %26
  store i32 %27, ptr @num, align 4, !tbaa !5
  %28 = add nsw i32 %27, 1989
  %29 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i32 noundef %28)
  %30 = load i32, ptr @n, align 4, !tbaa !5
  %31 = add nsw i32 %30, -1
  store i32 %31, ptr @n, align 4, !tbaa !5
  %.not = icmp eq i32 %30, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !9

._crit_edge:                                      ; preds = %23, %0
  ret i32 0
}

; Function Attrs: nofree nounwind
declare noundef i32 @__isoc99_scanf(ptr nocapture noundef readonly, ...) local_unnamed_addr #1

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
declare i64 @strlen(ptr nocapture noundef) local_unnamed_addr #2

; Function Attrs: nofree nounwind
declare noundef i32 @__isoc99_sscanf(ptr nocapture noundef readonly, 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" }
attributes #2 = { mustprogress nofree nounwind willreturn memory(argmem: read) "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 = { nounwind willreturn memory(read) }
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"}


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