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

; 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
declare dso_local noundef i32 @_ZN12FormatParser4textEPKc(ptr noundef nonnull align 8 dereferenceable(64), ptr noundef) #1 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN12FormatParser7controlEPKc(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
  %6 = alloca { i64, i64 }, align 8
  %7 = alloca { i64, i64 }, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  %8 = load ptr, ptr %3, align 8
  %9 = load ptr, ptr %4, align 8, !tbaa !5
  %10 = load i8, ptr %9, align 1, !tbaa !9
  %11 = sext i8 %10 to i32
  switch i32 %11, label %39 [
    i32 37, label %12
    i32 45, label %22
    i32 48, label %24
    i32 49, label %26
    i32 50, label %26
    i32 51, label %26
    i32 52, label %26
    i32 53, label %26
    i32 54, label %26
    i32 55, label %26
    i32 56, label %26
    i32 57, label %26
    i32 99, label %36
    i32 115, label %36
    i32 100, label %36
    i32 104, label %36
    i32 117, label %36
  ]

12:                                               ; preds = %2
  %13 = load ptr, ptr %4, align 8, !tbaa !5
  %14 = load i8, ptr %13, align 1, !tbaa !9
  %15 = getelementptr inbounds %class.FormatParser, ptr %8, i32 0, i32 2
  %16 = load ptr, ptr %15, align 8, !tbaa !10
  %17 = getelementptr inbounds i8, ptr %16, i32 1
  store ptr %17, ptr %15, align 8, !tbaa !10
  store i8 %14, ptr %16, align 1, !tbaa !9
  store { i64, i64 } { i64 ptrtoint (ptr @_ZN12FormatParser4textEPKc to i64), i64 0 }, ptr %5, align 8, !tbaa !9
  %18 = getelementptr inbounds { i64, i64 }, ptr %5, i32 0, i32 0
  %19 = load i64, ptr %18, align 8
  %20 = getelementptr inbounds { i64, i64 }, ptr %5, i32 0, i32 1
  %21 = load i64, ptr %20, align 8
  call void @_ZN3FsmIKcE4tranEMS1_FiPS0_E(ptr noundef nonnull align 8 dereferenceable(16) %8, i64 %19, i64 %21)
  br label %46

22:                                               ; preds = %2
  %23 = getelementptr inbounds %class.FormatParser, ptr %8, i32 0, i32 3
  store i32 1, ptr %23, align 8, !tbaa !14
  br label %46

24:                                               ; preds = %2
  %25 = getelementptr inbounds %class.FormatParser, ptr %8, i32 0, i32 3
  store i32 2, ptr %25, align 8, !tbaa !14
  br label %26

26:                                               ; preds = %24, %2, %2, %2, %2, %2, %2, %2, %2, %2
  %27 = load ptr, ptr %4, align 8, !tbaa !5
  %28 = load i8, ptr %27, align 1, !tbaa !9
  %29 = sext i8 %28 to i32
  %30 = sub nsw i32 %29, 48
  %31 = getelementptr inbounds %class.FormatParser, ptr %8, i32 0, i32 4
  store i32 %30, ptr %31, align 4, !tbaa !15
  store { i64, i64 } { i64 ptrtoint (ptr @_ZN12FormatParser10controlDigEPKc to i64), i64 0 }, ptr %6, align 8, !tbaa !9
  %32 = getelementptr inbounds { i64, i64 }, ptr %6, i32 0, i32 0
  %33 = load i64, ptr %32, align 8
  %34 = getelementptr inbounds { i64, i64 }, ptr %6, i32 0, i32 1
  %35 = load i64, ptr %34, align 8
  call void @_ZN3FsmIKcE4tranEMS1_FiPS0_E(ptr noundef nonnull align 8 dereferenceable(16) %8, i64 %33, i64 %35)
  br label %46

36:                                               ; preds = %2, %2, %2, %2, %2
  %37 = load ptr, ptr %4, align 8, !tbaa !5
  %38 = call noundef i32 @_ZN12FormatParser12processParamEPKc(ptr noundef nonnull align 8 dereferenceable(64) %8, ptr noundef %37)
  br label %46

39:                                               ; preds = %2
  %40 = getelementptr inbounds %class.FormatParser, ptr %8, i32 0, i32 2
  %41 = load ptr, ptr %40, align 8, !tbaa !10
  store i8 0, ptr %41, align 1, !tbaa !9
  store { i64, i64 } { i64 ptrtoint (ptr @_ZN12FormatParser5errorEPKc to i64), i64 0 }, ptr %7, align 8, !tbaa !9
  %42 = getelementptr inbounds { i64, i64 }, ptr %7, i32 0, i32 0
  %43 = load i64, ptr %42, align 8
  %44 = getelementptr inbounds { i64, i64 }, ptr %7, i32 0, i32 1
  %45 = load i64, ptr %44, align 8
  call void @_ZN3FsmIKcE4tranEMS1_FiPS0_E(ptr noundef nonnull align 8 dereferenceable(16) %8, i64 %43, i64 %45)
  br label %46

46:                                               ; preds = %39, %36, %26, %22, %12
  ret i32 1
}

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

; 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, !6, i64 24}
!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, !13, i64 32}
!15 = !{!11, !13, i64 36}


; 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
declare dso_local noundef i32 @_ZN12FormatParser4textEPKc(ptr noundef nonnull align 8 dereferenceable(64), ptr noundef) #1 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN12FormatParser7controlEPKc(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 %19 [
    i8 37, label %4
    i8 45, label %8
    i8 48, label %10
    i8 49, label %12
    i8 50, label %12
    i8 51, label %12
    i8 52, label %12
    i8 53, label %12
    i8 54, label %12
    i8 55, label %12
    i8 56, label %12
    i8 57, label %12
    i8 99, label %17
    i8 115, label %17
    i8 100, label %17
    i8 104, label %17
    i8 117, label %17
  ]

4:                                                ; preds = %2
  %5 = getelementptr inbounds i8, ptr %0, i64 24
  %6 = load ptr, ptr %5, align 8, !tbaa !8
  %7 = getelementptr inbounds i8, ptr %6, i64 1
  store ptr %7, ptr %5, align 8, !tbaa !8
  store i8 37, ptr %6, align 1, !tbaa !5
  tail call void @_ZN3FsmIKcE4tranEMS1_FiPS0_E(ptr noundef nonnull align 8 dereferenceable(16) %0, i64 ptrtoint (ptr @_ZN12FormatParser4textEPKc to i64), i64 0)
  br label %22

8:                                                ; preds = %2
  %9 = getelementptr inbounds i8, ptr %0, i64 32
  store i32 1, ptr %9, align 8, !tbaa !13
  br label %22

10:                                               ; preds = %2
  %11 = getelementptr inbounds i8, ptr %0, i64 32
  store i32 2, ptr %11, align 8, !tbaa !13
  %.pre = load i8, ptr %1, align 1, !tbaa !5
  br label %12

12:                                               ; preds = %10, %2, %2, %2, %2, %2, %2, %2, %2, %2
  %13 = phi i8 [ %.pre, %10 ], [ %3, %2 ], [ %3, %2 ], [ %3, %2 ], [ %3, %2 ], [ %3, %2 ], [ %3, %2 ], [ %3, %2 ], [ %3, %2 ], [ %3, %2 ]
  %14 = sext i8 %13 to i32
  %15 = add nsw i32 %14, -48
  %16 = getelementptr inbounds i8, ptr %0, i64 36
  store i32 %15, ptr %16, align 4, !tbaa !14
  tail call void @_ZN3FsmIKcE4tranEMS1_FiPS0_E(ptr noundef nonnull align 8 dereferenceable(16) %0, i64 ptrtoint (ptr @_ZN12FormatParser10controlDigEPKc to i64), i64 0)
  br label %22

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

19:                                               ; preds = %2
  %20 = getelementptr inbounds i8, ptr %0, i64 24
  %21 = load ptr, ptr %20, align 8, !tbaa !8
  store i8 0, ptr %21, 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 %22

22:                                               ; preds = %19, %17, %12, %8, %4
  ret i32 1
}

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

; 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, !11, i64 24}
!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, !12, i64 32}
!14 = !{!9, !12, i64 36}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InstCombinePass,SROAPass,TailCallElimPass