; LLVM IR from VastoLorde95/Competitive-Programming :: SPOJ/Random/NSYSTEM/n.ll/Z7convertNSt7 (cxx1112basic_stringIcSt11char_traitsIcESaIcEEE)

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

10:                                               ; preds = %71, %1
  %11 = load i32, ptr %4, align 4, !tbaa !9
  %12 = load i32, ptr %3, align 4, !tbaa !9
  %13 = icmp slt i32 %11, %12
  br i1 %13, label %14, label %74

14:                                               ; preds = %10
  %15 = load i32, ptr %4, align 4, !tbaa !9
  %16 = sext i32 %15 to i64
  %17 = call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) %0, i64 noundef %16)
  %18 = load i8, ptr %17, align 1, !tbaa !11
  store i8 %18, ptr %7, align 1, !tbaa !11
  %19 = load i8, ptr %7, align 1, !tbaa !11
  %20 = sext i8 %19 to i32
  %21 = icmp sgt i32 %20, 48
  br i1 %21, label %22, label %30

22:                                               ; preds = %14
  %23 = load i8, ptr %7, align 1, !tbaa !11
  %24 = sext i8 %23 to i32
  %25 = icmp slt i32 %24, 58
  br i1 %25, label %26, label %30

26:                                               ; preds = %22
  %27 = load i8, ptr %7, align 1, !tbaa !11
  %28 = sext i8 %27 to i32
  %29 = sub nsw i32 %28, 48
  store i32 %29, ptr %6, align 4, !tbaa !9
  br label %70

30:                                               ; preds = %22, %14
  %31 = load i8, ptr %7, align 1, !tbaa !11
  %32 = sext i8 %31 to i32
  %33 = icmp eq i32 %32, 109
  br i1 %33, label %34, label %39

34:                                               ; preds = %30
  %35 = load i32, ptr %6, align 4, !tbaa !9
  %36 = mul nsw i32 1000, %35
  %37 = load i32, ptr %5, align 4, !tbaa !9
  %38 = add nsw i32 %37, %36
  store i32 %38, ptr %5, align 4, !tbaa !9
  store i32 1, ptr %6, align 4, !tbaa !9
  br label %69

39:                                               ; preds = %30
  %40 = load i8, ptr %7, align 1, !tbaa !11
  %41 = sext i8 %40 to i32
  %42 = icmp eq i32 %41, 99
  br i1 %42, label %43, label %48

43:                                               ; preds = %39
  %44 = load i32, ptr %6, align 4, !tbaa !9
  %45 = mul nsw i32 100, %44
  %46 = load i32, ptr %5, align 4, !tbaa !9
  %47 = add nsw i32 %46, %45
  store i32 %47, ptr %5, align 4, !tbaa !9
  store i32 1, ptr %6, align 4, !tbaa !9
  br label %68

48:                                               ; preds = %39
  %49 = load i8, ptr %7, align 1, !tbaa !11
  %50 = sext i8 %49 to i32
  %51 = icmp eq i32 %50, 120
  br i1 %51, label %52, label %57

52:                                               ; preds = %48
  %53 = load i32, ptr %6, align 4, !tbaa !9
  %54 = mul nsw i32 10, %53
  %55 = load i32, ptr %5, align 4, !tbaa !9
  %56 = add nsw i32 %55, %54
  store i32 %56, ptr %5, align 4, !tbaa !9
  store i32 1, ptr %6, align 4, !tbaa !9
  br label %67

57:                                               ; preds = %48
  %58 = load i8, ptr %7, align 1, !tbaa !11
  %59 = sext i8 %58 to i32
  %60 = icmp eq i32 %59, 105
  br i1 %60, label %61, label %66

61:                                               ; preds = %57
  %62 = load i32, ptr %6, align 4, !tbaa !9
  %63 = mul nsw i32 1, %62
  %64 = load i32, ptr %5, align 4, !tbaa !9
  %65 = add nsw i32 %64, %63
  store i32 %65, ptr %5, align 4, !tbaa !9
  store i32 1, ptr %6, align 4, !tbaa !9
  br label %66

66:                                               ; preds = %61, %57
  br label %67

67:                                               ; preds = %66, %52
  br label %68

68:                                               ; preds = %67, %43
  br label %69

69:                                               ; preds = %68, %34
  br label %70

70:                                               ; preds = %69, %26
  br label %71

71:                                               ; preds = %70
  %72 = load i32, ptr %4, align 4, !tbaa !9
  %73 = add nsw i32 %72, 1
  store i32 %73, ptr %4, align 4, !tbaa !9
  br label %10, !llvm.loop !12

74:                                               ; preds = %10
  %75 = load i32, ptr %5, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 1, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  ret i32 %75
}

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

; Function Attrs: mustprogress nounwind uwtable
declare noundef i64 @_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE6lengthEv(ptr noundef nonnull align 8 dereferenceable(32)) #2 align 2

; Function Attrs: mustprogress nounwind uwtable
declare noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32), i64 noundef) #2 align 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 = { mustprogress 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 #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 = !{!"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 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}


; 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 nounwind uwtable
define dso_local noundef i32 @_Z7convertNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE(ptr noundef nonnull %0) local_unnamed_addr #0 {
  %2 = tail call noundef i64 @_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE6lengthEv(ptr noundef nonnull align 8 dereferenceable(32) %0) #1
  %3 = trunc i64 %2 to i32
  %4 = icmp sgt i32 %3, 0
  br i1 %4, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %1
  %wide.trip.count = and i64 %2, 2147483647
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %23
  %indvars.iv = phi i64 [ 0, %.lr.ph.preheader ], [ %indvars.iv.next, %23 ]
  %.02227 = phi i32 [ 1, %.lr.ph.preheader ], [ %.1, %23 ]
  %.02326 = phi i32 [ 0, %.lr.ph.preheader ], [ %.124, %23 ]
  %5 = tail call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) %0, i64 noundef %indvars.iv)
  %6 = load i8, ptr %5, align 1, !tbaa !5
  %7 = add i8 %6, -49
  %or.cond = icmp ult i8 %7, 9
  br i1 %or.cond, label %8, label %11

8:                                                ; preds = %.lr.ph
  %9 = zext nneg i8 %6 to i32
  %10 = add nsw i32 %9, -48
  br label %23

11:                                               ; preds = %.lr.ph
  switch i8 %6, label %23 [
    i8 109, label %12
    i8 99, label %15
    i8 120, label %18
    i8 105, label %21
  ]

12:                                               ; preds = %11
  %13 = mul nuw nsw i32 %.02227, 1000
  %14 = add nsw i32 %13, %.02326
  br label %23

15:                                               ; preds = %11
  %16 = mul nuw nsw i32 %.02227, 100
  %17 = add nsw i32 %16, %.02326
  br label %23

18:                                               ; preds = %11
  %19 = mul nuw nsw i32 %.02227, 10
  %20 = add nsw i32 %19, %.02326
  br label %23

21:                                               ; preds = %11
  %22 = add nsw i32 %.02227, %.02326
  br label %23

23:                                               ; preds = %11, %8, %15, %21, %18, %12
  %.124 = phi i32 [ %.02326, %8 ], [ %14, %12 ], [ %17, %15 ], [ %20, %18 ], [ %22, %21 ], [ %.02326, %11 ]
  %.1 = phi i32 [ %10, %8 ], [ 1, %12 ], [ 1, %15 ], [ 1, %18 ], [ 1, %21 ], [ %.02227, %11 ]
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph, !llvm.loop !8

._crit_edge:                                      ; preds = %23, %1
  %.023.lcssa = phi i32 [ 0, %1 ], [ %.124, %23 ]
  ret i32 %.023.lcssa
}

; Function Attrs: mustprogress nounwind uwtable
declare noundef i64 @_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE6lengthEv(ptr noundef nonnull align 8 dereferenceable(32)) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress nounwind uwtable
declare noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32), i64 noundef) local_unnamed_addr #0 align 2

attributes #0 = { mustprogress 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 = { 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"}


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