; LLVM IR from tangjz/acm-icpc :: lydsy/1103.ll (Z4scanRi)

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

@_ZZ4scanRiE2ch = external hidden global i32, align 4

; Function Attrs: mustprogress uwtable
define dso_local void @_Z4scanRi(ptr noundef nonnull align 4 dereferenceable(4) %0) #0 {
  %2 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  br label %3

3:                                                ; preds = %11, %1
  %4 = call i32 @getchar()
  store i32 %4, ptr @_ZZ4scanRiE2ch, align 4, !tbaa !9
  %5 = icmp slt i32 %4, 48
  br i1 %5, label %9, label %6

6:                                                ; preds = %3
  %7 = load i32, ptr @_ZZ4scanRiE2ch, align 4, !tbaa !9
  %8 = icmp sgt i32 %7, 57
  br label %9

9:                                                ; preds = %6, %3
  %10 = phi i1 [ true, %3 ], [ %8, %6 ]
  br i1 %10, label %11, label %12

11:                                               ; preds = %9
  br label %3, !llvm.loop !11

12:                                               ; preds = %9
  %13 = load i32, ptr @_ZZ4scanRiE2ch, align 4, !tbaa !9
  %14 = sub nsw i32 %13, 48
  %15 = load ptr, ptr %2, align 8, !tbaa !5
  store i32 %14, ptr %15, align 4, !tbaa !9
  br label %16

16:                                               ; preds = %24, %12
  %17 = call i32 @getchar()
  store i32 %17, ptr @_ZZ4scanRiE2ch, align 4, !tbaa !9
  %18 = icmp sge i32 %17, 48
  br i1 %18, label %19, label %22

19:                                               ; preds = %16
  %20 = load i32, ptr @_ZZ4scanRiE2ch, align 4, !tbaa !9
  %21 = icmp sle i32 %20, 57
  br label %22

22:                                               ; preds = %19, %16
  %23 = phi i1 [ false, %16 ], [ %21, %19 ]
  br i1 %23, label %24, label %36

24:                                               ; preds = %22
  %25 = load ptr, ptr %2, align 8, !tbaa !5
  %26 = load i32, ptr %25, align 4, !tbaa !9
  %27 = shl i32 %26, 3
  %28 = load ptr, ptr %2, align 8, !tbaa !5
  %29 = load i32, ptr %28, align 4, !tbaa !9
  %30 = shl i32 %29, 1
  %31 = add nsw i32 %27, %30
  %32 = load i32, ptr @_ZZ4scanRiE2ch, align 4, !tbaa !9
  %33 = sub nsw i32 %32, 48
  %34 = add nsw i32 %31, %33
  %35 = load ptr, ptr %2, align 8, !tbaa !5
  store i32 %34, ptr %35, align 4, !tbaa !9
  br label %16, !llvm.loop !13

36:                                               ; preds = %22
  ret void
}

; Function Attrs: inlinehint mustprogress uwtable
declare i32 @getchar() #1

attributes #0 = { 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 #1 = { 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" }

!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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}


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

@_ZZ4scanRiE2ch = external hidden local_unnamed_addr global i32, align 4

; Function Attrs: mustprogress nofree nounwind uwtable
define dso_local void @_Z4scanRi(ptr nocapture noundef nonnull align 4 dereferenceable(4) %0) local_unnamed_addr #0 {
  br label %2

2:                                                ; preds = %2, %1
  %3 = tail call i32 @getchar()
  store i32 %3, ptr @_ZZ4scanRiE2ch, align 4, !tbaa !5
  %4 = add i32 %3, -58
  %5 = icmp ult i32 %4, -10
  br i1 %5, label %2, label %6, !llvm.loop !9

6:                                                ; preds = %2
  %7 = add nsw i32 %3, -48
  store i32 %7, ptr %0, align 4, !tbaa !5
  %8 = tail call i32 @getchar()
  store i32 %8, ptr @_ZZ4scanRiE2ch, align 4, !tbaa !5
  %9 = add i32 %8, -48
  %10 = icmp ult i32 %9, 10
  br i1 %10, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %6, %.lr.ph
  %11 = phi i32 [ %16, %.lr.ph ], [ %9, %6 ]
  %12 = load i32, ptr %0, align 4, !tbaa !5
  %13 = mul i32 %12, 10
  %14 = add nsw i32 %13, %11
  store i32 %14, ptr %0, align 4, !tbaa !5
  %15 = tail call i32 @getchar()
  store i32 %15, ptr @_ZZ4scanRiE2ch, align 4, !tbaa !5
  %16 = add i32 %15, -48
  %17 = icmp ult i32 %16, 10
  br i1 %17, label %.lr.ph, label %._crit_edge, !llvm.loop !11

._crit_edge:                                      ; preds = %.lr.ph, %6
  ret void
}

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

attributes #0 = { 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" }
attributes #1 = { 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,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass