; LLVM IR from ASDAlexander77/TypeScriptCompiler :: tsc/tsc-new-parser/scanner.ll (ZN2ts7Scanner10scanDigitsEv)

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

%"class.std::__cxx11::basic_string" = type { %"struct.std::__cxx11::basic_string<wchar_t>::_Alloc_hider", i64, %union.anon }
%"struct.std::__cxx11::basic_string<wchar_t>::_Alloc_hider" = type { ptr }
%union.anon = type { i64, [8 x i8] }
%"class.ts::Scanner" = type { i32, i32, i8, i32, %"struct.ts::safe_string", i32, i32, i32, i32, i32, %"class.std::__cxx11::basic_string", i32, %"class.std::vector.41", i32, i32, %"class.std::function" }
%"struct.ts::safe_string" = type { %"class.std::__cxx11::basic_string" }
%"class.std::vector.41" = type { %"struct.std::_Vector_base.42" }
%"struct.std::_Vector_base.42" = type { %"struct.std::_Vector_base<ptr<ts::data::CommentDirective>, std::allocator<ptr<ts::data::CommentDirective>>>::_Vector_impl" }
%"struct.std::_Vector_base<ptr<ts::data::CommentDirective>, std::allocator<ptr<ts::data::CommentDirective>>>::_Vector_impl" = type { %"struct.std::_Vector_base<ptr<ts::data::CommentDirective>, std::allocator<ptr<ts::data::CommentDirective>>>::_Vector_impl_data" }
%"struct.std::_Vector_base<ptr<ts::data::CommentDirective>, std::allocator<ptr<ts::data::CommentDirective>>>::_Vector_impl_data" = type { ptr, ptr, ptr }
%"class.std::function" = type { %"class.std::_Function_base", ptr }
%"class.std::_Function_base" = type { %"union.std::_Any_data", ptr }
%"union.std::_Any_data" = type { %"union.std::_Nocopy_types" }
%"union.std::_Nocopy_types" = type { { i64, i64 } }

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

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

; Function Attrs: mustprogress nounwind uwtable
declare void @_ZNSt7__cxx1112basic_stringIwSt11char_traitsIwESaIwEED2Ev(ptr noundef nonnull align 8 dereferenceable(32)) unnamed_addr #1 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN2ts11safe_string9substringB5cxx11Eii(ptr dead_on_unwind noalias writable sret(%"class.std::__cxx11::basic_string") align 8, ptr noundef nonnull align 8 dereferenceable(32), i32 noundef, i32 noundef) #2 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_ZN2ts11safe_stringixEi(ptr noundef nonnull align 8 dereferenceable(32), i32 noundef) #2 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZN2ts7Scanner7isDigitE14CharacterCodes(ptr noundef nonnull align 8 dereferenceable(176), i32 noundef) #1 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZN2ts7Scanner12isOctalDigitE14CharacterCodes(ptr noundef nonnull align 8 dereferenceable(176), i32 noundef) #1 align 2

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

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZN2ts7Scanner10scanDigitsEv(ptr noundef nonnull align 8 dereferenceable(176) %0) #2 align 2 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  %4 = alloca i8, align 1
  %5 = alloca %"class.std::__cxx11::basic_string", align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  %6 = load ptr, ptr %2, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  %7 = getelementptr inbounds %"class.ts::Scanner", ptr %6, i32 0, i32 5
  %8 = load i32, ptr %7, align 8, !tbaa !9
  store i32 %8, ptr %3, align 4, !tbaa !29
  call void @llvm.lifetime.start.p0(i64 1, ptr %4) #3
  store i8 1, ptr %4, align 1, !tbaa !30
  br label %9

9:                                                ; preds = %22, %1
  %10 = getelementptr inbounds %"class.ts::Scanner", ptr %6, i32 0, i32 4
  %11 = getelementptr inbounds %"class.ts::Scanner", ptr %6, i32 0, i32 5
  %12 = load i32, ptr %11, align 8, !tbaa !9
  %13 = call noundef i32 @_ZN2ts11safe_stringixEi(ptr noundef nonnull align 8 dereferenceable(32) %10, i32 noundef %12)
  %14 = call noundef zeroext i1 @_ZN2ts7Scanner7isDigitE14CharacterCodes(ptr noundef nonnull align 8 dereferenceable(176) %6, i32 noundef %13)
  br i1 %14, label %15, label %26

15:                                               ; preds = %9
  %16 = getelementptr inbounds %"class.ts::Scanner", ptr %6, i32 0, i32 4
  %17 = getelementptr inbounds %"class.ts::Scanner", ptr %6, i32 0, i32 5
  %18 = load i32, ptr %17, align 8, !tbaa !9
  %19 = call noundef i32 @_ZN2ts11safe_stringixEi(ptr noundef nonnull align 8 dereferenceable(32) %16, i32 noundef %18)
  %20 = call noundef zeroext i1 @_ZN2ts7Scanner12isOctalDigitE14CharacterCodes(ptr noundef nonnull align 8 dereferenceable(176) %6, i32 noundef %19)
  br i1 %20, label %22, label %21

21:                                               ; preds = %15
  store i8 0, ptr %4, align 1, !tbaa !30
  br label %22

22:                                               ; preds = %21, %15
  %23 = getelementptr inbounds %"class.ts::Scanner", ptr %6, i32 0, i32 5
  %24 = load i32, ptr %23, align 8, !tbaa !9
  %25 = add nsw i32 %24, 1
  store i32 %25, ptr %23, align 8, !tbaa !9
  br label %9, !llvm.loop !31

26:                                               ; preds = %9
  call void @llvm.lifetime.start.p0(i64 32, ptr %5) #3
  %27 = getelementptr inbounds %"class.ts::Scanner", ptr %6, i32 0, i32 4
  %28 = load i32, ptr %3, align 4, !tbaa !29
  %29 = getelementptr inbounds %"class.ts::Scanner", ptr %6, i32 0, i32 5
  %30 = load i32, ptr %29, align 8, !tbaa !9
  call void @_ZN2ts11safe_string9substringB5cxx11Eii(ptr dead_on_unwind writable sret(%"class.std::__cxx11::basic_string") align 8 %5, ptr noundef nonnull align 8 dereferenceable(32) %27, i32 noundef %28, i32 noundef %30)
  %31 = getelementptr inbounds %"class.ts::Scanner", ptr %6, i32 0, i32 10
  %32 = call noundef nonnull align 8 dereferenceable(32) ptr @_ZNSt7__cxx1112basic_stringIwSt11char_traitsIwESaIwEEaSEOS4_(ptr noundef nonnull align 8 dereferenceable(32) %31, ptr noundef nonnull align 8 dereferenceable(32) %5) #3
  call void @_ZNSt7__cxx1112basic_stringIwSt11char_traitsIwESaIwEED2Ev(ptr noundef nonnull align 8 dereferenceable(32) %5) #3
  call void @llvm.lifetime.end.p0(i64 32, ptr %5) #3
  %33 = load i8, ptr %4, align 1, !tbaa !30, !range !33, !noundef !34
  %34 = trunc i8 %33 to i1
  call void @llvm.lifetime.end.p0(i64 1, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  ret i1 %34
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { 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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !19, i64 48}
!10 = !{!"_ZTSN2ts7ScannerE", !11, i64 0, !12, i64 4, !13, i64 8, !14, i64 12, !15, i64 16, !19, i64 48, !19, i64 52, !19, i64 56, !19, i64 60, !20, i64 64, !16, i64 72, !21, i64 104, !22, i64 112, !19, i64 136, !26, i64 140, !27, i64 144}
!11 = !{!"_ZTSN2ts10ScriptKindE", !7, i64 0}
!12 = !{!"_ZTSN2ts12ScriptTargetE", !7, i64 0}
!13 = !{!"bool", !7, i64 0}
!14 = !{!"_ZTSN2ts15LanguageVariantE", !7, i64 0}
!15 = !{!"_ZTSN2ts11safe_stringE", !16, i64 0}
!16 = !{!"_ZTSNSt7__cxx1112basic_stringIwSt11char_traitsIwESaIwEEE", !17, i64 0, !18, i64 8, !7, i64 16}
!17 = !{!"_ZTSNSt7__cxx1112basic_stringIwSt11char_traitsIwESaIwEE12_Alloc_hiderE", !6, i64 0}
!18 = !{!"long", !7, i64 0}
!19 = !{!"int", !7, i64 0}
!20 = !{!"_ZTS10SyntaxKind", !7, i64 0}
!21 = !{!"_ZTSN2ts10TokenFlagsE", !7, i64 0}
!22 = !{!"_ZTSSt6vectorI3ptrIN2ts4data16CommentDirectiveEESaIS4_EE", !23, i64 0}
!23 = !{!"_ZTSSt12_Vector_baseI3ptrIN2ts4data16CommentDirectiveEESaIS4_EE", !24, i64 0}
!24 = !{!"_ZTSNSt12_Vector_baseI3ptrIN2ts4data16CommentDirectiveEESaIS4_EE12_Vector_implE", !25, i64 0}
!25 = !{!"_ZTSNSt12_Vector_baseI3ptrIN2ts4data16CommentDirectiveEESaIS4_EE17_Vector_impl_dataE", !6, i64 0, !6, i64 8, !6, i64 16}
!26 = !{!"_ZTSN2ts16JSDocParsingModeE", !7, i64 0}
!27 = !{!"_ZTSSt8functionIFv3ptrIN2ts4data17DiagnosticMessageEEiNSt7__cxx1112basic_stringIwSt11char_traitsIwESaIwEEEEE", !28, i64 0, !6, i64 24}
!28 = !{!"_ZTSSt14_Function_base", !7, i64 0, !6, i64 16}
!29 = !{!19, !19, i64 0}
!30 = !{!13, !13, i64 0}
!31 = distinct !{!31, !32}
!32 = !{!"llvm.loop.mustprogress"}
!33 = !{i8 0, i8 2}
!34 = !{}


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

%"class.std::__cxx11::basic_string" = type { %"struct.std::__cxx11::basic_string<wchar_t>::_Alloc_hider", i64, %union.anon }
%"struct.std::__cxx11::basic_string<wchar_t>::_Alloc_hider" = type { ptr }
%union.anon = type { i64, [8 x i8] }

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

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

; Function Attrs: mustprogress nounwind uwtable
declare void @_ZNSt7__cxx1112basic_stringIwSt11char_traitsIwESaIwEED2Ev(ptr noundef nonnull align 8 dereferenceable(32)) unnamed_addr #1 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN2ts11safe_string9substringB5cxx11Eii(ptr dead_on_unwind noalias writable sret(%"class.std::__cxx11::basic_string") align 8, ptr noundef nonnull align 8 dereferenceable(32), i32 noundef, i32 noundef) local_unnamed_addr #2 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_ZN2ts11safe_stringixEi(ptr noundef nonnull align 8 dereferenceable(32), i32 noundef) local_unnamed_addr #2 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZN2ts7Scanner7isDigitE14CharacterCodes(ptr noundef nonnull align 8 dereferenceable(176), i32 noundef) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZN2ts7Scanner12isOctalDigitE14CharacterCodes(ptr noundef nonnull align 8 dereferenceable(176), i32 noundef) local_unnamed_addr #1 align 2

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

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZN2ts7Scanner10scanDigitsEv(ptr noundef nonnull align 8 dereferenceable(176) %0) local_unnamed_addr #2 align 2 {
  %2 = alloca %"class.std::__cxx11::basic_string", align 8
  %3 = getelementptr inbounds i8, ptr %0, i64 48
  %4 = load i32, ptr %3, align 8, !tbaa !5
  %5 = getelementptr inbounds i8, ptr %0, i64 16
  %6 = tail call noundef i32 @_ZN2ts11safe_stringixEi(ptr noundef nonnull align 8 dereferenceable(32) %5, i32 noundef %4)
  %7 = tail call noundef zeroext i1 @_ZN2ts7Scanner7isDigitE14CharacterCodes(ptr noundef nonnull align 8 dereferenceable(176) %0, i32 noundef %6)
  br i1 %7, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %1, %.lr.ph
  %.02 = phi i1 [ %spec.select, %.lr.ph ], [ true, %1 ]
  %8 = load i32, ptr %3, align 8, !tbaa !5
  %9 = tail call noundef i32 @_ZN2ts11safe_stringixEi(ptr noundef nonnull align 8 dereferenceable(32) %5, i32 noundef %8)
  %10 = tail call noundef zeroext i1 @_ZN2ts7Scanner12isOctalDigitE14CharacterCodes(ptr noundef nonnull align 8 dereferenceable(176) %0, i32 noundef %9)
  %spec.select = select i1 %10, i1 %.02, i1 false
  %11 = load i32, ptr %3, align 8, !tbaa !5
  %12 = add nsw i32 %11, 1
  store i32 %12, ptr %3, align 8, !tbaa !5
  %13 = tail call noundef i32 @_ZN2ts11safe_stringixEi(ptr noundef nonnull align 8 dereferenceable(32) %5, i32 noundef %12)
  %14 = tail call noundef zeroext i1 @_ZN2ts7Scanner7isDigitE14CharacterCodes(ptr noundef nonnull align 8 dereferenceable(176) %0, i32 noundef %13)
  br i1 %14, label %.lr.ph, label %._crit_edge, !llvm.loop !28

._crit_edge:                                      ; preds = %.lr.ph, %1
  %.0.lcssa = phi i1 [ true, %1 ], [ %spec.select, %.lr.ph ]
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %2) #3
  %15 = load i32, ptr %3, align 8, !tbaa !5
  call void @_ZN2ts11safe_string9substringB5cxx11Eii(ptr dead_on_unwind nonnull writable sret(%"class.std::__cxx11::basic_string") align 8 %2, ptr noundef nonnull align 8 dereferenceable(32) %5, i32 noundef %4, i32 noundef %15)
  %16 = getelementptr inbounds i8, ptr %0, i64 72
  %17 = call noundef nonnull align 8 dereferenceable(32) ptr @_ZNSt7__cxx1112basic_stringIwSt11char_traitsIwESaIwEEaSEOS4_(ptr noundef nonnull align 8 dereferenceable(32) %16, ptr noundef nonnull align 8 dereferenceable(32) %2) #3
  call void @_ZNSt7__cxx1112basic_stringIwSt11char_traitsIwESaIwEED2Ev(ptr noundef nonnull align 8 dereferenceable(32) %2) #3
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %2) #3
  ret i1 %.0.lcssa
}

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { 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, !18, i64 48}
!6 = !{!"_ZTSN2ts7ScannerE", !7, i64 0, !10, i64 4, !11, i64 8, !12, i64 12, !13, i64 16, !18, i64 48, !18, i64 52, !18, i64 56, !18, i64 60, !19, i64 64, !14, i64 72, !20, i64 104, !21, i64 112, !18, i64 136, !25, i64 140, !26, i64 144}
!7 = !{!"_ZTSN2ts10ScriptKindE", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"_ZTSN2ts12ScriptTargetE", !8, i64 0}
!11 = !{!"bool", !8, i64 0}
!12 = !{!"_ZTSN2ts15LanguageVariantE", !8, i64 0}
!13 = !{!"_ZTSN2ts11safe_stringE", !14, i64 0}
!14 = !{!"_ZTSNSt7__cxx1112basic_stringIwSt11char_traitsIwESaIwEEE", !15, i64 0, !17, i64 8, !8, i64 16}
!15 = !{!"_ZTSNSt7__cxx1112basic_stringIwSt11char_traitsIwESaIwEE12_Alloc_hiderE", !16, i64 0}
!16 = !{!"any pointer", !8, i64 0}
!17 = !{!"long", !8, i64 0}
!18 = !{!"int", !8, i64 0}
!19 = !{!"_ZTS10SyntaxKind", !8, i64 0}
!20 = !{!"_ZTSN2ts10TokenFlagsE", !8, i64 0}
!21 = !{!"_ZTSSt6vectorI3ptrIN2ts4data16CommentDirectiveEESaIS4_EE", !22, i64 0}
!22 = !{!"_ZTSSt12_Vector_baseI3ptrIN2ts4data16CommentDirectiveEESaIS4_EE", !23, i64 0}
!23 = !{!"_ZTSNSt12_Vector_baseI3ptrIN2ts4data16CommentDirectiveEESaIS4_EE12_Vector_implE", !24, i64 0}
!24 = !{!"_ZTSNSt12_Vector_baseI3ptrIN2ts4data16CommentDirectiveEESaIS4_EE17_Vector_impl_dataE", !16, i64 0, !16, i64 8, !16, i64 16}
!25 = !{!"_ZTSN2ts16JSDocParsingModeE", !8, i64 0}
!26 = !{!"_ZTSSt8functionIFv3ptrIN2ts4data17DiagnosticMessageEEiNSt7__cxx1112basic_stringIwSt11char_traitsIwESaIwEEEEE", !27, i64 0, !16, i64 24}
!27 = !{!"_ZTSSt14_Function_base", !8, i64 0, !16, i64 16}
!28 = distinct !{!28, !29}
!29 = !{!"llvm.loop.mustprogress"}


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