; LLVM IR from tangjz/acm-icpc :: 51nod (1009)

; 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
@pw10 = external dso_local global i32, align 4
@ans = external dso_local global i32, align 4
@s = external dso_local global [10 x i8], align 1
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = 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
  %5 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  %6 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n)
  %7 = load i32, ptr @n, align 4, !tbaa !5
  %8 = add nsw i32 %7, 1
  %9 = call i32 (ptr, ptr, ...) @sprintf(ptr noundef @s, ptr noundef @.str, i32 noundef %8) #5
  %10 = call i64 @strlen(ptr noundef @s) #6
  %11 = trunc i64 %10 to i32
  store i32 %11, ptr @n, align 4, !tbaa !5
  store i32 1, ptr @pw10, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #5
  store i32 1, ptr %2, align 4, !tbaa !5
  br label %12

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

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

17:                                               ; preds = %12
  %18 = load i32, ptr @pw10, align 4, !tbaa !5
  %19 = mul nsw i32 %18, 10
  store i32 %19, ptr @pw10, align 4, !tbaa !5
  br label %20

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

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

24:                                               ; preds = %88, %23
  %25 = load i32, ptr %3, align 4, !tbaa !5
  %26 = load i32, ptr @n, align 4, !tbaa !5
  %27 = icmp slt i32 %25, %26
  br i1 %27, label %29, label %28

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

29:                                               ; preds = %24
  %30 = load i32, ptr %3, align 4, !tbaa !5
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds [10 x i8], ptr @s, i64 0, i64 %31
  %33 = load i8, ptr %32, align 1, !tbaa !11
  %34 = sext i8 %33 to i32
  %35 = icmp sgt i32 %34, 48
  br i1 %35, label %36, label %76

36:                                               ; preds = %29
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #5
  %37 = load i32, ptr @pw10, align 4, !tbaa !5
  %38 = load i32, ptr %3, align 4, !tbaa !5
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds [10 x i8], ptr @s, i64 0, i64 %39
  %41 = load i8, ptr %40, align 1, !tbaa !11
  %42 = sext i8 %41 to i32
  %43 = sub nsw i32 %42, 48
  %44 = mul nsw i32 %37, %43
  store i32 %44, ptr %5, align 4, !tbaa !5
  %45 = load i32, ptr %5, align 4, !tbaa !5
  %46 = load i32, ptr %4, align 4, !tbaa !5
  %47 = mul nsw i32 %45, %46
  %48 = load i32, ptr @ans, align 4, !tbaa !5
  %49 = add nsw i32 %48, %47
  store i32 %49, ptr @ans, align 4, !tbaa !5
  %50 = load i32, ptr %3, align 4, !tbaa !5
  %51 = add nsw i32 %50, 1
  %52 = load i32, ptr @n, align 4, !tbaa !5
  %53 = icmp slt i32 %51, %52
  br i1 %53, label %54, label %64

54:                                               ; preds = %36
  %55 = load i32, ptr %5, align 4, !tbaa !5
  %56 = sdiv i32 %55, 10
  %57 = load i32, ptr @n, align 4, !tbaa !5
  %58 = load i32, ptr %3, align 4, !tbaa !5
  %59 = sub nsw i32 %57, %58
  %60 = sub nsw i32 %59, 1
  %61 = mul nsw i32 %56, %60
  %62 = load i32, ptr @ans, align 4, !tbaa !5
  %63 = add nsw i32 %62, %61
  store i32 %63, ptr @ans, align 4, !tbaa !5
  br label %64

64:                                               ; preds = %54, %36
  %65 = load i32, ptr %3, align 4, !tbaa !5
  %66 = sext i32 %65 to i64
  %67 = getelementptr inbounds [10 x i8], ptr @s, i64 0, i64 %66
  %68 = load i8, ptr %67, align 1, !tbaa !11
  %69 = sext i8 %68 to i32
  %70 = icmp sgt i32 %69, 49
  br i1 %70, label %71, label %75

71:                                               ; preds = %64
  %72 = load i32, ptr @pw10, align 4, !tbaa !5
  %73 = load i32, ptr @ans, align 4, !tbaa !5
  %74 = add nsw i32 %73, %72
  store i32 %74, ptr @ans, align 4, !tbaa !5
  br label %75

75:                                               ; preds = %71, %64
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #5
  br label %76

76:                                               ; preds = %75, %29
  %77 = load i32, ptr @pw10, align 4, !tbaa !5
  %78 = sdiv i32 %77, 10
  store i32 %78, ptr @pw10, align 4, !tbaa !5
  %79 = load i32, ptr %3, align 4, !tbaa !5
  %80 = sext i32 %79 to i64
  %81 = getelementptr inbounds [10 x i8], ptr @s, i64 0, i64 %80
  %82 = load i8, ptr %81, align 1, !tbaa !11
  %83 = sext i8 %82 to i32
  %84 = icmp eq i32 %83, 49
  %85 = zext i1 %84 to i32
  %86 = load i32, ptr %4, align 4, !tbaa !5
  %87 = add nsw i32 %86, %85
  store i32 %87, ptr %4, align 4, !tbaa !5
  br label %88

88:                                               ; preds = %76
  %89 = load i32, ptr %3, align 4, !tbaa !5
  %90 = add nsw i32 %89, 1
  store i32 %90, ptr %3, align 4, !tbaa !5
  br label %24, !llvm.loop !12

91:                                               ; preds = %28
  %92 = load i32, ptr @ans, align 4, !tbaa !5
  %93 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i32 noundef %92)
  ret i32 0
}

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

; Function Attrs: nounwind
declare i32 @sprintf(ptr noundef, ptr noundef, ...) #2

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

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

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

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 = { 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 #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = !{!7, !7, i64 0}
!12 = distinct !{!12, !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
@pw10 = external dso_local local_unnamed_addr global i32, align 4
@ans = external dso_local local_unnamed_addr global i32, align 4
@s = external dso_local global [10 x i8], align 1
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = 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)
  %2 = load i32, ptr @n, align 4, !tbaa !5
  %3 = add nsw i32 %2, 1
  %4 = tail call i32 (ptr, ptr, ...) @sprintf(ptr noundef nonnull dereferenceable(1) @s, ptr noundef nonnull dereferenceable(1) @.str, i32 noundef %3) #4
  %5 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) @s) #5
  %6 = trunc i64 %5 to i32
  store i32 %6, ptr @n, align 4, !tbaa !5
  store i32 1, ptr @pw10, align 4, !tbaa !5
  %7 = icmp sgt i32 %6, 1
  br i1 %7, label %.lr.ph.preheader, label %.preheader

.lr.ph.preheader:                                 ; preds = %0
  %8 = add nsw i32 %6, -1
  %min.iters.check = icmp ult i32 %6, 9
  br i1 %min.iters.check, label %.lr.ph.preheader35, label %vector.ph

.lr.ph.preheader35:                               ; preds = %middle.block, %.lr.ph.preheader
  %.018.ph = phi i32 [ 1, %.lr.ph.preheader ], [ %ind.end, %middle.block ]
  %.ph = phi i32 [ 1, %.lr.ph.preheader ], [ %12, %middle.block ]
  br label %.lr.ph

vector.ph:                                        ; preds = %.lr.ph.preheader
  %n.vec = and i32 %8, -8
  %ind.end = or disjoint i32 %n.vec, 1
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i32 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %vec.phi = phi <4 x i32> [ <i32 1, i32 1, i32 1, i32 1>, %vector.ph ], [ %9, %vector.body ]
  %vec.phi34 = phi <4 x i32> [ <i32 1, i32 1, i32 1, i32 1>, %vector.ph ], [ %10, %vector.body ]
  %9 = mul <4 x i32> %vec.phi, <i32 10, i32 10, i32 10, i32 10>
  %10 = mul <4 x i32> %vec.phi34, <i32 10, i32 10, i32 10, i32 10>
  %index.next = add nuw i32 %index, 8
  %11 = icmp eq i32 %index.next, %n.vec
  br i1 %11, label %middle.block, label %vector.body, !llvm.loop !9

middle.block:                                     ; preds = %vector.body
  %bin.rdx = mul <4 x i32> %10, %9
  %12 = tail call i32 @llvm.vector.reduce.mul.v4i32(<4 x i32> %bin.rdx)
  %cmp.n = icmp eq i32 %8, %n.vec
  br i1 %cmp.n, label %..preheader_crit_edge, label %.lr.ph.preheader35

..preheader_crit_edge:                            ; preds = %.lr.ph, %middle.block
  %.lcssa33 = phi i32 [ %12, %middle.block ], [ %16, %.lr.ph ]
  store i32 %.lcssa33, ptr @pw10, align 4, !tbaa !5
  br label %.preheader

.preheader:                                       ; preds = %..preheader_crit_edge, %0
  %pw10.promoted19 = phi i32 [ %.lcssa33, %..preheader_crit_edge ], [ 1, %0 ]
  %ans.promoted = load i32, ptr @ans, align 4, !tbaa !5
  %13 = icmp sgt i32 %6, 0
  br i1 %13, label %.lr.ph26.preheader, label %18

.lr.ph26.preheader:                               ; preds = %.preheader
  %14 = and i64 %5, 2147483647
  %wide.trip.count = and i64 %5, 2147483647
  br label %.lr.ph26

.lr.ph:                                           ; preds = %.lr.ph.preheader35, %.lr.ph
  %.018 = phi i32 [ %17, %.lr.ph ], [ %.018.ph, %.lr.ph.preheader35 ]
  %15 = phi i32 [ %16, %.lr.ph ], [ %.ph, %.lr.ph.preheader35 ]
  %16 = mul nuw nsw i32 %15, 10
  %17 = add nuw nsw i32 %.018, 1
  %exitcond.not = icmp eq i32 %17, %6
  br i1 %exitcond.not, label %..preheader_crit_edge, label %.lr.ph, !llvm.loop !13

._crit_edge:                                      ; preds = %43
  store i32 %44, ptr @pw10, align 4, !tbaa !5
  br label %18

18:                                               ; preds = %._crit_edge, %.preheader
  %19 = phi i32 [ %storemerge20, %._crit_edge ], [ %ans.promoted, %.preheader ]
  %20 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i32 noundef %19)
  ret i32 0

.lr.ph26:                                         ; preds = %.lr.ph26.preheader, %43
  %indvars.iv = phi i64 [ 0, %.lr.ph26.preheader ], [ %indvars.iv.next.pre-phi, %43 ]
  %.01425 = phi i32 [ 0, %.lr.ph26.preheader ], [ %47, %43 ]
  %21 = phi i32 [ %pw10.promoted19, %.lr.ph26.preheader ], [ %44, %43 ]
  %storemerge2122 = phi i32 [ %ans.promoted, %.lr.ph26.preheader ], [ %storemerge20, %43 ]
  %22 = getelementptr inbounds [10 x i8], ptr @s, i64 0, i64 %indvars.iv
  %23 = load i8, ptr %22, align 1, !tbaa !14
  %24 = icmp sgt i8 %23, 48
  br i1 %24, label %25, label %.lr.ph26._crit_edge

.lr.ph26._crit_edge:                              ; preds = %.lr.ph26
  %.pre = add nuw nsw i64 %indvars.iv, 1
  br label %43

25:                                               ; preds = %.lr.ph26
  %26 = zext nneg i8 %23 to i32
  %27 = add nsw i32 %26, -48
  %28 = mul nsw i32 %21, %27
  %29 = mul nsw i32 %28, %.01425
  %30 = add nsw i32 %29, %storemerge2122
  %31 = add nuw nsw i64 %indvars.iv, 1
  %32 = icmp slt i64 %31, %14
  br i1 %32, label %33, label %40

33:                                               ; preds = %25
  %34 = sdiv i32 %28, 10
  %35 = trunc nuw nsw i64 %indvars.iv to i32
  %36 = xor i32 %35, -1
  %37 = add i32 %36, %6
  %38 = mul nsw i32 %34, %37
  %39 = add nsw i32 %30, %38
  br label %40

40:                                               ; preds = %33, %25
  %storemerge = phi i32 [ %39, %33 ], [ %30, %25 ]
  store i32 %storemerge, ptr @ans, align 4, !tbaa !5
  %.not = icmp eq i8 %23, 49
  br i1 %.not, label %43, label %41

41:                                               ; preds = %40
  %42 = add nsw i32 %storemerge, %21
  store i32 %42, ptr @ans, align 4, !tbaa !5
  br label %43

43:                                               ; preds = %.lr.ph26._crit_edge, %40, %41
  %indvars.iv.next.pre-phi = phi i64 [ %.pre, %.lr.ph26._crit_edge ], [ %31, %40 ], [ %31, %41 ]
  %storemerge20 = phi i32 [ %storemerge2122, %.lr.ph26._crit_edge ], [ %storemerge, %40 ], [ %42, %41 ]
  %44 = sdiv i32 %21, 10
  %45 = icmp eq i8 %23, 49
  %46 = zext i1 %45 to i32
  %47 = add nuw nsw i32 %.01425, %46
  %exitcond30.not = icmp eq i64 %indvars.iv.next.pre-phi, %wide.trip.count
  br i1 %exitcond30.not, label %._crit_edge, label %.lr.ph26, !llvm.loop !15
}

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

; Function Attrs: nofree nounwind
declare noundef i32 @sprintf(ptr noalias nocapture noundef writeonly, 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 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #1

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.vector.reduce.mul.v4i32(<4 x i32>) #3

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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #4 = { nounwind }
attributes #5 = { 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, !11, !12}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!"llvm.loop.isvectorized", i32 1}
!12 = !{!"llvm.loop.unroll.runtime.disable"}
!13 = distinct !{!13, !10, !12, !11}
!14 = !{!7, !7, i64 0}
!15 = distinct !{!15, !10}


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