; LLVM IR from tangjz/acm-icpc :: buaa/oj3rd/1170.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
@_ZZ4scanRiE1f = 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 = %14, %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 i1 %8, label %9, label %12

9:                                                ; preds = %6, %3
  %10 = load i32, ptr @_ZZ4scanRiE2ch, align 4, !tbaa !9
  %11 = icmp ne i32 %10, 45
  br label %12

12:                                               ; preds = %9, %6
  %13 = phi i1 [ false, %6 ], [ %11, %9 ]
  br i1 %13, label %14, label %15

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

15:                                               ; preds = %12
  %16 = load i32, ptr @_ZZ4scanRiE2ch, align 4, !tbaa !9
  %17 = icmp eq i32 %16, 45
  %18 = zext i1 %17 to i32
  store i32 %18, ptr @_ZZ4scanRiE1f, align 4, !tbaa !9
  %19 = load i32, ptr @_ZZ4scanRiE1f, align 4, !tbaa !9
  %20 = icmp ne i32 %19, 0
  br i1 %20, label %21, label %22

21:                                               ; preds = %15
  br label %25

22:                                               ; preds = %15
  %23 = load i32, ptr @_ZZ4scanRiE2ch, align 4, !tbaa !9
  %24 = sub nsw i32 %23, 48
  br label %25

25:                                               ; preds = %22, %21
  %26 = phi i32 [ 0, %21 ], [ %24, %22 ]
  %27 = load ptr, ptr %2, align 8, !tbaa !5
  store i32 %26, ptr %27, align 4, !tbaa !9
  br label %28

28:                                               ; preds = %36, %25
  %29 = call i32 @getchar()
  store i32 %29, ptr @_ZZ4scanRiE2ch, align 4, !tbaa !9
  %30 = icmp sge i32 %29, 48
  br i1 %30, label %31, label %34

31:                                               ; preds = %28
  %32 = load i32, ptr @_ZZ4scanRiE2ch, align 4, !tbaa !9
  %33 = icmp sle i32 %32, 57
  br label %34

34:                                               ; preds = %31, %28
  %35 = phi i1 [ false, %28 ], [ %33, %31 ]
  br i1 %35, label %36, label %48

36:                                               ; preds = %34
  %37 = load ptr, ptr %2, align 8, !tbaa !5
  %38 = load i32, ptr %37, align 4, !tbaa !9
  %39 = shl i32 %38, 3
  %40 = load ptr, ptr %2, align 8, !tbaa !5
  %41 = load i32, ptr %40, align 4, !tbaa !9
  %42 = shl i32 %41, 1
  %43 = add nsw i32 %39, %42
  %44 = load i32, ptr @_ZZ4scanRiE2ch, align 4, !tbaa !9
  %45 = add nsw i32 %43, %44
  %46 = sub nsw i32 %45, 48
  %47 = load ptr, ptr %2, align 8, !tbaa !5
  store i32 %46, ptr %47, align 4, !tbaa !9
  br label %28, !llvm.loop !13

48:                                               ; preds = %34
  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
@_ZZ4scanRiE1f = 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
  %or.cond = icmp ult i32 %4, -10
  %5 = icmp ne i32 %3, 45
  %or.cond3 = and i1 %5, %or.cond
  br i1 %or.cond3, label %2, label %.critedge, !llvm.loop !9

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

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

._crit_edge:                                      ; preds = %.lr.ph, %.critedge
  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: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass