; LLVM IR from alekras/ao.rtos.cpp :: Library/Display/formatter.ll (ZN12FormatParser10controlDigEPKc)

; 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.FormatParser = type { %class.Fsm, ptr, ptr, i32, i32, [1 x %struct.__va_list_tag] }
%class.Fsm = type { { i64, i64 } }
%struct.__va_list_tag = type { i32, i32, ptr, ptr }

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN3FsmIKcE4tranEMS1_FiPS0_E(ptr noundef nonnull align 8 dereferenceable(16), i64, i64) #0 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN12FormatParser10controlDigEPKc(ptr noundef nonnull align 8 dereferenceable(64) %0, ptr noundef %1) #1 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca { i64, i64 }, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  %6 = load ptr, ptr %3, align 8
  %7 = load ptr, ptr %4, align 8, !tbaa !5
  %8 = load i8, ptr %7, align 1, !tbaa !9
  %9 = sext i8 %8 to i32
  switch i32 %9, label %23 [
    i32 48, label %10
    i32 49, label %10
    i32 50, label %10
    i32 51, label %10
    i32 52, label %10
    i32 53, label %10
    i32 54, label %10
    i32 55, label %10
    i32 56, label %10
    i32 57, label %10
    i32 99, label %20
    i32 115, label %20
    i32 100, label %20
    i32 104, label %20
    i32 117, label %20
  ]

10:                                               ; preds = %2, %2, %2, %2, %2, %2, %2, %2, %2, %2
  %11 = getelementptr inbounds %class.FormatParser, ptr %6, i32 0, i32 4
  %12 = load i32, ptr %11, align 4, !tbaa !10
  %13 = mul nsw i32 %12, 10
  %14 = load ptr, ptr %4, align 8, !tbaa !5
  %15 = load i8, ptr %14, align 1, !tbaa !9
  %16 = sext i8 %15 to i32
  %17 = sub nsw i32 %16, 48
  %18 = add nsw i32 %13, %17
  %19 = getelementptr inbounds %class.FormatParser, ptr %6, i32 0, i32 4
  store i32 %18, ptr %19, align 4, !tbaa !10
  br label %30

20:                                               ; preds = %2, %2, %2, %2, %2
  %21 = load ptr, ptr %4, align 8, !tbaa !5
  %22 = call noundef i32 @_ZN12FormatParser12processParamEPKc(ptr noundef nonnull align 8 dereferenceable(64) %6, ptr noundef %21)
  br label %30

23:                                               ; preds = %2
  %24 = getelementptr inbounds %class.FormatParser, ptr %6, i32 0, i32 2
  %25 = load ptr, ptr %24, align 8, !tbaa !14
  store i8 0, ptr %25, align 1, !tbaa !9
  store { i64, i64 } { i64 ptrtoint (ptr @_ZN12FormatParser5errorEPKc to i64), i64 0 }, ptr %5, align 8, !tbaa !9
  %26 = getelementptr inbounds { i64, i64 }, ptr %5, i32 0, i32 0
  %27 = load i64, ptr %26, align 8
  %28 = getelementptr inbounds { i64, i64 }, ptr %5, i32 0, i32 1
  %29 = load i64, ptr %28, align 8
  call void @_ZN3FsmIKcE4tranEMS1_FiPS0_E(ptr noundef nonnull align 8 dereferenceable(16) %6, i64 %27, i64 %29)
  br label %30

30:                                               ; preds = %23, %20, %10
  ret i32 1
}

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZN12FormatParser5errorEPKc(ptr noundef nonnull align 8 dereferenceable(64), ptr noundef) #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 = { 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" }

!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 = !{!7, !7, i64 0}
!10 = !{!11, !13, i64 36}
!11 = !{!"_ZTS12FormatParser", !12, i64 0, !6, i64 16, !6, i64 24, !13, i64 32, !13, i64 36, !7, i64 40}
!12 = !{!"_ZTS3FsmIKcE", !7, i64 0}
!13 = !{!"int", !7, i64 0}
!14 = !{!11, !6, i64 24}


; 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
declare dso_local void @_ZN3FsmIKcE4tranEMS1_FiPS0_E(ptr noundef nonnull align 8 dereferenceable(16), i64, i64) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN12FormatParser10controlDigEPKc(ptr noundef nonnull align 8 dereferenceable(64) %0, ptr noundef %1) local_unnamed_addr #1 align 2 {
  %3 = load i8, ptr %1, align 1, !tbaa !5
  switch i8 %3, label %13 [
    i8 48, label %4
    i8 49, label %4
    i8 50, label %4
    i8 51, label %4
    i8 52, label %4
    i8 53, label %4
    i8 54, label %4
    i8 55, label %4
    i8 56, label %4
    i8 57, label %4
    i8 99, label %11
    i8 115, label %11
    i8 100, label %11
    i8 104, label %11
    i8 117, label %11
  ]

4:                                                ; preds = %2, %2, %2, %2, %2, %2, %2, %2, %2, %2
  %5 = getelementptr inbounds i8, ptr %0, i64 36
  %6 = load i32, ptr %5, align 4, !tbaa !8
  %7 = mul nsw i32 %6, 10
  %8 = zext nneg i8 %3 to i32
  %9 = add nsw i32 %8, -48
  %10 = add nsw i32 %9, %7
  store i32 %10, ptr %5, align 4, !tbaa !8
  br label %16

11:                                               ; preds = %2, %2, %2, %2, %2
  %12 = tail call noundef i32 @_ZN12FormatParser12processParamEPKc(ptr noundef nonnull align 8 dereferenceable(64) %0, ptr noundef nonnull %1)
  br label %16

13:                                               ; preds = %2
  %14 = getelementptr inbounds i8, ptr %0, i64 24
  %15 = load ptr, ptr %14, align 8, !tbaa !13
  store i8 0, ptr %15, align 1, !tbaa !5
  tail call void @_ZN3FsmIKcE4tranEMS1_FiPS0_E(ptr noundef nonnull align 8 dereferenceable(16) %0, i64 ptrtoint (ptr @_ZN12FormatParser5errorEPKc to i64), i64 0)
  br label %16

16:                                               ; preds = %13, %11, %4
  ret i32 1
}

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZN12FormatParser5errorEPKc(ptr noundef nonnull align 8 dereferenceable(64), ptr noundef) #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 = { 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" }

!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 = !{!9, !12, i64 36}
!9 = !{!"_ZTS12FormatParser", !10, i64 0, !11, i64 16, !11, i64 24, !12, i64 32, !12, i64 36, !6, i64 40}
!10 = !{!"_ZTS3FsmIKcE", !6, i64 0}
!11 = !{!"any pointer", !6, i64 0}
!12 = !{!"int", !6, i64 0}
!13 = !{!9, !11, i64 24}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,InstCombinePass,ReassociatePass,SROAPass,TailCallElimPass