; LLVM IR from tangjz/acm-icpc :: lydsy/1669.ll (Z7ScanIntv)

; 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 @_Z7ScanIntv() #0 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %1) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #4
  store i32 0, ptr %2, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #4
  store i32 0, ptr %3, align 4, !tbaa !5
  br label %4

4:                                                ; preds = %13, %0
  %5 = call i32 @getchar()
  store i32 %5, ptr %1, align 4, !tbaa !5
  %6 = call i32 @isdigit(i32 noundef %5) #5
  %7 = icmp ne i32 %6, 0
  br i1 %7, label %11, label %8

8:                                                ; preds = %4
  %9 = load i32, ptr %1, align 4, !tbaa !5
  %10 = icmp ne i32 %9, 45
  br label %11

11:                                               ; preds = %8, %4
  %12 = phi i1 [ false, %4 ], [ %10, %8 ]
  br i1 %12, label %13, label %14

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

14:                                               ; preds = %11
  %15 = load i32, ptr %1, align 4, !tbaa !5
  %16 = icmp eq i32 %15, 45
  br i1 %16, label %17, label %18

17:                                               ; preds = %14
  store i32 1, ptr %3, align 4, !tbaa !5
  br label %21

18:                                               ; preds = %14
  %19 = load i32, ptr %1, align 4, !tbaa !5
  %20 = sub nsw i32 %19, 48
  store i32 %20, ptr %2, align 4, !tbaa !5
  br label %21

21:                                               ; preds = %18, %17
  br label %22

22:                                               ; preds = %26, %21
  %23 = call i32 @getchar()
  store i32 %23, ptr %1, align 4, !tbaa !5
  %24 = call i32 @isdigit(i32 noundef %23) #5
  %25 = icmp ne i32 %24, 0
  br i1 %25, label %26, label %35

26:                                               ; preds = %22
  %27 = load i32, ptr %2, align 4, !tbaa !5
  %28 = shl i32 %27, 3
  %29 = load i32, ptr %2, align 4, !tbaa !5
  %30 = shl i32 %29, 1
  %31 = add nsw i32 %28, %30
  %32 = load i32, ptr %1, align 4, !tbaa !5
  %33 = add nsw i32 %31, %32
  %34 = sub nsw i32 %33, 48
  store i32 %34, ptr %2, align 4, !tbaa !5
  br label %22, !llvm.loop !11

35:                                               ; preds = %22
  %36 = load i32, ptr %3, align 4, !tbaa !5
  %37 = icmp ne i32 %36, 0
  br i1 %37, label %38, label %41

38:                                               ; preds = %35
  %39 = load i32, ptr %2, align 4, !tbaa !5
  %40 = sub nsw i32 0, %39
  br label %43

41:                                               ; preds = %35
  %42 = load i32, ptr %2, align 4, !tbaa !5
  br label %43

43:                                               ; preds = %41, %38
  %44 = phi i32 [ %40, %38 ], [ %42, %41 ]
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %1) #4
  ret i32 %44
}

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

; Function Attrs: nounwind willreturn memory(read)
declare i32 @isdigit(i32 noundef) #2

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

; 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 = { 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 #3 = { 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 #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}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !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"

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

1:                                                ; preds = %1, %0
  %2 = tail call i32 @getchar()
  %3 = add i32 %2, -58
  %isdigit = icmp ult i32 %3, -10
  %4 = icmp ne i32 %2, 45
  %5 = and i1 %4, %isdigit
  br i1 %5, label %1, label %6, !llvm.loop !5

6:                                                ; preds = %1
  %.not = icmp eq i32 %2, 45
  %7 = add nsw i32 %2, -48
  %.09 = select i1 %.not, i32 0, i32 %7
  %8 = tail call i32 @getchar()
  %isdigittmp12 = add i32 %8, -48
  %isdigit1113 = icmp ult i32 %isdigittmp12, 10
  br i1 %isdigit1113, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %6, %.lr.ph
  %9 = phi i32 [ %13, %.lr.ph ], [ %8, %6 ]
  %.114 = phi i32 [ %12, %.lr.ph ], [ %.09, %6 ]
  %10 = mul i32 %.114, 10
  %11 = add nsw i32 %9, -48
  %12 = add i32 %11, %10
  %13 = tail call i32 @getchar()
  %isdigittmp = add i32 %13, -48
  %isdigit11 = icmp ult i32 %isdigittmp, 10
  br i1 %isdigit11, label %.lr.ph, label %._crit_edge, !llvm.loop !7

._crit_edge:                                      ; preds = %.lr.ph, %6
  %.1.lcssa = phi i32 [ %.09, %6 ], [ %12, %.lr.ph ]
  %14 = sub nsw i32 0, %.1.lcssa
  %15 = select i1 %.not, i32 %14, i32 %.1.lcssa
  ret i32 %15
}

; 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: CorrelatedValuePropagationPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass