; LLVM IR from ShahjalalShohag/code-library :: Dynamic Programming Optimizations/Divide and Conquer Optimization.ll (Z2scv)

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

5:                                                ; preds = %17, %0
  %6 = load i32, ptr %1, align 4, !tbaa !5
  %7 = icmp slt i32 %6, 48
  br i1 %7, label %11, label %8

8:                                                ; preds = %5
  %9 = load i32, ptr %1, align 4, !tbaa !5
  %10 = icmp sgt i32 %9, 57
  br i1 %10, label %11, label %14

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

14:                                               ; preds = %11, %8
  %15 = phi i1 [ false, %8 ], [ %13, %11 ]
  br i1 %15, label %16, label %19

16:                                               ; preds = %14
  br label %17

17:                                               ; preds = %16
  %18 = call i32 @getchar()
  store i32 %18, ptr %1, align 4, !tbaa !5
  br label %5, !llvm.loop !9

19:                                               ; preds = %14
  %20 = load i32, ptr %1, align 4, !tbaa !5
  %21 = icmp eq i32 %20, 45
  br i1 %21, label %22, label %24

22:                                               ; preds = %19
  store i32 1, ptr %3, align 4, !tbaa !5
  %23 = call i32 @getchar()
  store i32 %23, ptr %1, align 4, !tbaa !5
  br label %24

24:                                               ; preds = %22, %19
  br label %25

25:                                               ; preds = %42, %24
  %26 = load i32, ptr %1, align 4, !tbaa !5
  %27 = icmp sgt i32 %26, 47
  br i1 %27, label %28, label %31

28:                                               ; preds = %25
  %29 = load i32, ptr %1, align 4, !tbaa !5
  %30 = icmp slt i32 %29, 58
  br label %31

31:                                               ; preds = %28, %25
  %32 = phi i1 [ false, %25 ], [ %30, %28 ]
  br i1 %32, label %33, label %44

33:                                               ; preds = %31
  %34 = load i32, ptr %2, align 4, !tbaa !5
  %35 = shl i32 %34, 1
  %36 = load i32, ptr %2, align 4, !tbaa !5
  %37 = shl i32 %36, 3
  %38 = add nsw i32 %35, %37
  %39 = load i32, ptr %1, align 4, !tbaa !5
  %40 = add nsw i32 %38, %39
  %41 = sub nsw i32 %40, 48
  store i32 %41, ptr %2, align 4, !tbaa !5
  br label %42

42:                                               ; preds = %33
  %43 = call i32 @getchar()
  store i32 %43, ptr %1, align 4, !tbaa !5
  br label %25, !llvm.loop !11

44:                                               ; preds = %31
  %45 = load i32, ptr %3, align 4, !tbaa !5
  %46 = icmp ne i32 %45, 0
  br i1 %46, label %47, label %50

47:                                               ; preds = %44
  %48 = load i32, ptr %2, align 4, !tbaa !5
  %49 = sub nsw i32 0, %48
  store i32 %49, ptr %2, align 4, !tbaa !5
  br label %50

50:                                               ; preds = %47, %44
  %51 = load i32, ptr %2, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, 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 %51
}

; 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 = 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 @_Z2scv() local_unnamed_addr #0 {
  %1 = tail call i32 @getchar()
  %2 = add i32 %1, -58
  %or.cond18 = icmp ult i32 %2, -10
  %3 = icmp ne i32 %1, 45
  %or.cond319 = and i1 %3, %or.cond18
  br i1 %or.cond319, label %.lr.ph, label %.critedge

.lr.ph:                                           ; preds = %0, %.lr.ph
  %4 = tail call i32 @getchar()
  %5 = add i32 %4, -58
  %or.cond = icmp ult i32 %5, -10
  %6 = icmp ne i32 %4, 45
  %or.cond3 = and i1 %6, %or.cond
  br i1 %or.cond3, label %.lr.ph, label %.critedge, !llvm.loop !5

.critedge:                                        ; preds = %.lr.ph, %0
  %.016.lcssa = phi i32 [ %1, %0 ], [ %4, %.lr.ph ]
  %.not = icmp eq i32 %.016.lcssa, 45
  br i1 %.not, label %7, label %9

7:                                                ; preds = %.critedge
  %8 = tail call i32 @getchar()
  br label %9

9:                                                ; preds = %7, %.critedge
  %.117 = phi i32 [ %8, %7 ], [ %.016.lcssa, %.critedge ]
  %10 = add i32 %.117, -48
  %11 = icmp ult i32 %10, 10
  br i1 %11, label %.lr.ph22, label %._crit_edge

.lr.ph22:                                         ; preds = %9, %.lr.ph22
  %.01521 = phi i32 [ %14, %.lr.ph22 ], [ 0, %9 ]
  %.220 = phi i32 [ %15, %.lr.ph22 ], [ %.117, %9 ]
  %12 = mul i32 %.01521, 10
  %13 = add nsw i32 %.220, -48
  %14 = add i32 %13, %12
  %15 = tail call i32 @getchar()
  %16 = add i32 %15, -48
  %17 = icmp ult i32 %16, 10
  br i1 %17, label %.lr.ph22, label %._crit_edge, !llvm.loop !7

._crit_edge:                                      ; preds = %.lr.ph22, %9
  %.015.lcssa = phi i32 [ 0, %9 ], [ %14, %.lr.ph22 ]
  %18 = sub nsw i32 0, %.015.lcssa
  %spec.select = select i1 %.not, i32 %18, i32 %.015.lcssa
  ret i32 %spec.select
}

; 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