; LLVM IR from lzyrapx/Competitive-Programming :: ACdream/1103（树链剖分+最小费用最大流）.ll (Z4readv)

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

6:                                                ; preds = %21, %0
  %7 = load i8, ptr %3, align 1, !tbaa !9
  %8 = sext i8 %7 to i32
  %9 = icmp slt i32 %8, 48
  br i1 %9, label %14, label %10

10:                                               ; preds = %6
  %11 = load i8, ptr %3, align 1, !tbaa !9
  %12 = sext i8 %11 to i32
  %13 = icmp slt i32 57, %12
  br label %14

14:                                               ; preds = %10, %6
  %15 = phi i1 [ true, %6 ], [ %13, %10 ]
  br i1 %15, label %16, label %24

16:                                               ; preds = %14
  %17 = load i8, ptr %3, align 1, !tbaa !9
  %18 = sext i8 %17 to i32
  %19 = icmp eq i32 %18, 45
  br i1 %19, label %20, label %21

20:                                               ; preds = %16
  store i32 -1, ptr %2, align 4, !tbaa !5
  br label %21

21:                                               ; preds = %20, %16
  %22 = call i32 @getchar()
  %23 = trunc i32 %22 to i8
  store i8 %23, ptr %3, align 1, !tbaa !9
  br label %6, !llvm.loop !10

24:                                               ; preds = %14
  br label %25

25:                                               ; preds = %35, %24
  %26 = load i8, ptr %3, align 1, !tbaa !9
  %27 = sext i8 %26 to i32
  %28 = icmp sle i32 48, %27
  br i1 %28, label %29, label %33

29:                                               ; preds = %25
  %30 = load i8, ptr %3, align 1, !tbaa !9
  %31 = sext i8 %30 to i32
  %32 = icmp sle i32 %31, 57
  br label %33

33:                                               ; preds = %29, %25
  %34 = phi i1 [ false, %25 ], [ %32, %29 ]
  br i1 %34, label %35, label %44

35:                                               ; preds = %33
  %36 = load i32, ptr %1, align 4, !tbaa !5
  %37 = mul nsw i32 %36, 10
  %38 = load i8, ptr %3, align 1, !tbaa !9
  %39 = sext i8 %38 to i32
  %40 = add nsw i32 %37, %39
  %41 = sub nsw i32 %40, 48
  store i32 %41, ptr %1, align 4, !tbaa !5
  %42 = call i32 @getchar()
  %43 = trunc i32 %42 to i8
  store i8 %43, ptr %3, align 1, !tbaa !9
  br label %25, !llvm.loop !12

44:                                               ; preds = %33
  %45 = load i32, ptr %1, align 4, !tbaa !5
  %46 = load i32, ptr %2, align 4, !tbaa !5
  %47 = mul nsw i32 %45, %46
  call void @llvm.lifetime.end.p0(i64 1, ptr %3) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %1) #3
  ret i32 %47
}

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


; 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 @_Z4readv() local_unnamed_addr #0 {
  %1 = tail call i32 @getchar()
  %sext14 = shl i32 %1, 24
  %2 = ashr exact i32 %sext14, 24
  %3 = add nsw i32 %2, -58
  %4 = icmp ult i32 %3, -10
  br i1 %4, label %.lr.ph, label %.lr.ph20.preheader

.lr.ph20.preheader:                               ; preds = %.lr.ph, %0
  %.pre-phi = phi i32 [ %2, %0 ], [ %7, %.lr.ph ]
  %.09.lcssa = phi i32 [ 1, %0 ], [ %spec.select, %.lr.ph ]
  br label %.lr.ph20

.lr.ph:                                           ; preds = %0, %.lr.ph
  %sext16 = phi i32 [ %sext, %.lr.ph ], [ %sext14, %0 ]
  %.0915 = phi i32 [ %spec.select, %.lr.ph ], [ 1, %0 ]
  %5 = icmp eq i32 %sext16, 754974720
  %spec.select = select i1 %5, i32 -1, i32 %.0915
  %6 = tail call i32 @getchar()
  %sext = shl i32 %6, 24
  %7 = ashr exact i32 %sext, 24
  %8 = add nsw i32 %7, -58
  %9 = icmp ult i32 %8, -10
  br i1 %9, label %.lr.ph, label %.lr.ph20.preheader, !llvm.loop !5

.lr.ph20:                                         ; preds = %.lr.ph20.preheader, %.lr.ph20
  %10 = phi i32 [ %15, %.lr.ph20 ], [ %.pre-phi, %.lr.ph20.preheader ]
  %.01119 = phi i32 [ %13, %.lr.ph20 ], [ 0, %.lr.ph20.preheader ]
  %11 = mul nsw i32 %.01119, 10
  %12 = add i32 %11, -48
  %13 = add i32 %12, %10
  %14 = tail call i32 @getchar()
  %sext13 = shl i32 %14, 24
  %15 = ashr exact i32 %sext13, 24
  %16 = add nsw i32 %15, -48
  %17 = icmp ult i32 %16, 10
  br i1 %17, label %.lr.ph20, label %._crit_edge, !llvm.loop !7

._crit_edge:                                      ; preds = %.lr.ph20
  %18 = mul nsw i32 %13, %.09.lcssa
  ret i32 %18
}

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