; LLVM IR from lzyrapx/Competitive-Programming :: HDUOJ/5749 .ll (Z7readintv)

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

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_Z7readintv() #0 {
  %1 = alloca i8, align 1
  %2 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 1, ptr %1) #3
  br label %3

3:                                                ; preds = %20, %0
  %4 = call i32 @getchar()
  %5 = trunc i32 %4 to i8
  store i8 %5, ptr %1, align 1, !tbaa !5
  %6 = icmp ne i8 %5, 0
  br i1 %6, label %7, label %18

7:                                                ; preds = %3
  %8 = load i8, ptr %1, align 1, !tbaa !5
  %9 = sext i8 %8 to i32
  %10 = icmp sge i32 %9, 48
  br i1 %10, label %11, label %15

11:                                               ; preds = %7
  %12 = load i8, ptr %1, align 1, !tbaa !5
  %13 = sext i8 %12 to i32
  %14 = icmp sle i32 %13, 57
  br label %15

15:                                               ; preds = %11, %7
  %16 = phi i1 [ false, %7 ], [ %14, %11 ]
  %17 = xor i1 %16, true
  br label %18

18:                                               ; preds = %15, %3
  %19 = phi i1 [ false, %3 ], [ %17, %15 ]
  br i1 %19, label %20, label %21

20:                                               ; preds = %18
  br label %3, !llvm.loop !8

21:                                               ; preds = %18
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #3
  %22 = load i8, ptr %1, align 1, !tbaa !5
  %23 = sext i8 %22 to i32
  %24 = sub nsw i32 %23, 48
  store i32 %24, ptr %2, align 4, !tbaa !10
  br label %25

25:                                               ; preds = %41, %21
  %26 = call i32 @getchar()
  %27 = trunc i32 %26 to i8
  store i8 %27, ptr %1, align 1, !tbaa !5
  %28 = icmp ne i8 %27, 0
  br i1 %28, label %29, label %39

29:                                               ; preds = %25
  %30 = load i8, ptr %1, align 1, !tbaa !5
  %31 = sext i8 %30 to i32
  %32 = icmp sge i32 %31, 48
  br i1 %32, label %33, label %37

33:                                               ; preds = %29
  %34 = load i8, ptr %1, align 1, !tbaa !5
  %35 = sext i8 %34 to i32
  %36 = icmp sle i32 %35, 57
  br label %37

37:                                               ; preds = %33, %29
  %38 = phi i1 [ false, %29 ], [ %36, %33 ]
  br label %39

39:                                               ; preds = %37, %25
  %40 = phi i1 [ false, %25 ], [ %38, %37 ]
  br i1 %40, label %41, label %48

41:                                               ; preds = %39
  %42 = load i32, ptr %2, align 4, !tbaa !10
  %43 = mul nsw i32 %42, 10
  %44 = load i8, ptr %1, align 1, !tbaa !5
  %45 = sext i8 %44 to i32
  %46 = add nsw i32 %43, %45
  %47 = sub nsw i32 %46, 48
  store i32 %47, ptr %2, align 4, !tbaa !10
  br label %25, !llvm.loop !12

48:                                               ; preds = %39
  %49 = load i32, ptr %2, align 4, !tbaa !10
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #3
  call void @llvm.lifetime.end.p0(i64 1, ptr %1) #3
  ret i32 %49
}

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

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

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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" }
attributes #3 = { 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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C++ TBAA"}
!8 = distinct !{!8, !9}
!9 = !{!"llvm.loop.mustprogress"}
!10 = !{!11, !11, i64 0}
!11 = !{!"int", !6, i64 0}
!12 = distinct !{!12, !9}


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

; Function Attrs: mustprogress nofree nounwind uwtable
define dso_local noundef i32 @_Z7readintv() local_unnamed_addr #0 {
  br label %1

1:                                                ; preds = %4, %0
  %2 = tail call i32 @getchar()
  %3 = and i32 %2, 255
  %.not = icmp eq i32 %3, 0
  br i1 %.not, label %.critedge, label %4

4:                                                ; preds = %1
  %sext = shl i32 %2, 24
  %5 = ashr exact i32 %sext, 24
  %6 = add nsw i32 %5, -58
  %7 = icmp ult i32 %6, -10
  br i1 %7, label %1, label %.critedgesplit, !llvm.loop !5

.critedgesplit:                                   ; preds = %4
  %8 = add nsw i32 %5, -48
  br label %.critedge

.critedge:                                        ; preds = %1, %.critedgesplit
  %.pre-phi = phi i32 [ %8, %.critedgesplit ], [ -48, %1 ]
  %9 = tail call i32 @getchar()
  %10 = and i32 %9, 255
  %.not1417 = icmp eq i32 %10, 0
  br i1 %.not1417, label %.critedge2, label %.lr.ph

.lr.ph:                                           ; preds = %.critedge, %15
  %11 = phi i32 [ %18, %15 ], [ %9, %.critedge ]
  %.018 = phi i32 [ %.0, %15 ], [ %.pre-phi, %.critedge ]
  %sext15 = shl i32 %11, 24
  %12 = ashr exact i32 %sext15, 24
  %13 = add nsw i32 %12, -48
  %14 = icmp ult i32 %13, 10
  br i1 %14, label %15, label %.critedge2

15:                                               ; preds = %.lr.ph
  %16 = mul nsw i32 %.018, 10
  %17 = add nsw i32 %12, %16
  %.0 = add nsw i32 %17, -48
  %18 = tail call i32 @getchar()
  %19 = and i32 %18, 255
  %.not14 = icmp eq i32 %19, 0
  br i1 %.not14, label %.critedge2, label %.lr.ph, !llvm.loop !7

.critedge2:                                       ; preds = %.lr.ph, %15, %.critedge
  %.0.lcssa = phi i32 [ %.pre-phi, %.critedge ], [ %.0, %15 ], [ %.018, %.lr.ph ]
  ret i32 %.0.lcssa
}

; 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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}
!7 = distinct !{!7, !6}


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