; LLVM IR from tangjz/acm-icpc :: lydsy (5544)

; 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"

@buf = external dso_local global [19 x i8], align 16
@f = external dso_local global [19 x i64], align 16
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [6 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 @buf)
  store i64 1, ptr @f, align 16, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #4
  store i32 0, ptr %2, align 4, !tbaa !9
  br label %5

5:                                                ; preds = %68, %0
  %6 = load i32, ptr %2, align 4, !tbaa !9
  %7 = sext i32 %6 to i64
  %8 = getelementptr inbounds [19 x i8], ptr @buf, i64 0, i64 %7
  %9 = load i8, ptr %8, align 1, !tbaa !11
  %10 = icmp ne i8 %9, 0
  br i1 %10, label %17, label %11

11:                                               ; preds = %5
  %12 = load i32, ptr %2, align 4, !tbaa !9
  %13 = sext i32 %12 to i64
  %14 = getelementptr inbounds [19 x i64], ptr @f, i64 0, i64 %13
  %15 = load i64, ptr %14, align 8, !tbaa !5
  %16 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i64 noundef %15)
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #4
  ret i32 0

17:                                               ; preds = %5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #4
  %18 = load i32, ptr %2, align 4, !tbaa !9
  %19 = sext i32 %18 to i64
  %20 = getelementptr inbounds [19 x i8], ptr @buf, i64 0, i64 %19
  %21 = load i8, ptr %20, align 1, !tbaa !11
  %22 = sext i8 %21 to i32
  %23 = sub nsw i32 %22, 48
  store i32 %23, ptr %3, align 4, !tbaa !9
  %24 = load i32, ptr %2, align 4, !tbaa !9
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds [19 x i64], ptr @f, i64 0, i64 %25
  %27 = load i64, ptr %26, align 8, !tbaa !5
  %28 = load i32, ptr %3, align 4, !tbaa !9
  %29 = sub nsw i32 9, %28
  %30 = call i32 @llvm.abs.i32(i32 %29, i1 true)
  %31 = sub nsw i32 10, %30
  %32 = sext i32 %31 to i64
  %33 = mul nsw i64 %27, %32
  %34 = load i32, ptr %2, align 4, !tbaa !9
  %35 = add nsw i32 %34, 1
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds [19 x i64], ptr @f, i64 0, i64 %36
  store i64 %33, ptr %37, align 8, !tbaa !5
  %38 = load i32, ptr %2, align 4, !tbaa !9
  %39 = icmp ne i32 %38, 0
  br i1 %39, label %40, label %66

40:                                               ; preds = %17
  %41 = load i32, ptr %2, align 4, !tbaa !9
  %42 = sub nsw i32 %41, 1
  %43 = sext i32 %42 to i64
  %44 = getelementptr inbounds [19 x i8], ptr @buf, i64 0, i64 %43
  %45 = load i8, ptr %44, align 1, !tbaa !11
  %46 = sext i8 %45 to i32
  %47 = icmp eq i32 %46, 49
  br i1 %47, label %48, label %66

48:                                               ; preds = %40
  %49 = load i32, ptr %2, align 4, !tbaa !9
  %50 = sub nsw i32 %49, 1
  %51 = sext i32 %50 to i64
  %52 = getelementptr inbounds [19 x i64], ptr @f, i64 0, i64 %51
  %53 = load i64, ptr %52, align 8, !tbaa !5
  %54 = load i32, ptr %3, align 4, !tbaa !9
  %55 = add nsw i32 %54, 1
  %56 = call i32 @llvm.abs.i32(i32 %55, i1 true)
  %57 = sub nsw i32 10, %56
  %58 = sext i32 %57 to i64
  %59 = mul nsw i64 %53, %58
  %60 = load i32, ptr %2, align 4, !tbaa !9
  %61 = add nsw i32 %60, 1
  %62 = sext i32 %61 to i64
  %63 = getelementptr inbounds [19 x i64], ptr @f, i64 0, i64 %62
  %64 = load i64, ptr %63, align 8, !tbaa !5
  %65 = add nsw i64 %64, %59
  store i64 %65, ptr %63, align 8, !tbaa !5
  br label %66

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

67:                                               ; preds = %66
  br label %68

68:                                               ; preds = %67
  %69 = load i32, ptr %2, align 4, !tbaa !9
  %70 = add nsw i32 %69, 1
  store i32 %70, ptr %2, align 4, !tbaa !9
  br label %5, !llvm.loop !12
}

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

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

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.abs.i32(i32, i1 immarg) #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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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 = !{!"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 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}


; 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"

@buf = external dso_local global [19 x i8], align 16
@f = external dso_local local_unnamed_addr global [19 x i64], align 16
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [6 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 @buf)
  store i64 1, ptr @f, align 16, !tbaa !5
  %2 = load i8, ptr @buf, align 16, !tbaa !9
  %.not14 = icmp eq i8 %2, 0
  br i1 %.not14, label %._crit_edge, label %3

3:                                                ; preds = %0
  %4 = sext i8 %2 to i32
  %5 = sub nsw i32 57, %4
  %6 = tail call i32 @llvm.abs.i32(i32 %5, i1 true)
  %7 = sub nsw i32 10, %6
  %8 = sext i32 %7 to i64
  store i64 %8, ptr getelementptr inbounds (i8, ptr @f, i64 8), align 8, !tbaa !5
  %9 = load i8, ptr getelementptr inbounds (i8, ptr @buf, i64 1), align 1, !tbaa !9
  %.not.peel = icmp eq i8 %9, 0
  br i1 %.not.peel, label %._crit_edge, label %.lr.ph.peel.next

._crit_edge:                                      ; preds = %34, %3, %0
  %10 = phi i64 [ 1, %0 ], [ %8, %3 ], [ %35, %34 ]
  %11 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i64 noundef %10)
  ret i32 0

.lr.ph.peel.next:                                 ; preds = %3, %34
  %12 = phi i64 [ %35, %34 ], [ %8, %3 ]
  %indvars.iv = phi i64 [ %indvars.iv.next, %34 ], [ 1, %3 ]
  %13 = phi i8 [ %37, %34 ], [ %9, %3 ]
  %14 = sext i8 %13 to i32
  %15 = sub nsw i32 57, %14
  %16 = tail call i32 @llvm.abs.i32(i32 %15, i1 true)
  %17 = sub nsw i32 10, %16
  %18 = sext i32 %17 to i64
  %19 = mul nsw i64 %12, %18
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %20 = getelementptr inbounds [19 x i64], ptr @f, i64 0, i64 %indvars.iv.next
  store i64 %19, ptr %20, align 8, !tbaa !5
  %21 = add nsw i64 %indvars.iv, -1
  %22 = getelementptr inbounds [19 x i8], ptr @buf, i64 0, i64 %21
  %23 = load i8, ptr %22, align 1, !tbaa !9
  %24 = icmp eq i8 %23, 49
  br i1 %24, label %25, label %34

25:                                               ; preds = %.lr.ph.peel.next
  %26 = getelementptr inbounds [19 x i64], ptr @f, i64 0, i64 %21
  %27 = load i64, ptr %26, align 8, !tbaa !5
  %28 = add nsw i32 %14, -47
  %29 = tail call i32 @llvm.abs.i32(i32 %28, i1 true)
  %30 = sub nsw i32 10, %29
  %31 = sext i32 %30 to i64
  %32 = mul nsw i64 %27, %31
  %33 = add nsw i64 %32, %19
  store i64 %33, ptr %20, align 8, !tbaa !5
  br label %34

34:                                               ; preds = %25, %.lr.ph.peel.next
  %35 = phi i64 [ %33, %25 ], [ %19, %.lr.ph.peel.next ]
  %36 = getelementptr inbounds [19 x i8], ptr @buf, i64 0, i64 %indvars.iv.next
  %37 = load i8, ptr %36, align 1, !tbaa !9
  %.not = icmp eq i8 %37, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph.peel.next, !llvm.loop !10
}

; 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

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.abs.i32(i32, i1 immarg) #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 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }

!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 = !{!7, !7, i64 0}
!10 = distinct !{!10, !11, !12}
!11 = !{!"llvm.loop.mustprogress"}
!12 = !{!"llvm.loop.peeled.count", i32 1}


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