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

; 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 @_ZN12FormatParser4textEPKc(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
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  %7 = load ptr, ptr %3, align 8
  %8 = load ptr, ptr %4, align 8, !tbaa !5
  %9 = load i8, ptr %8, align 1, !tbaa !9
  %10 = sext i8 %9 to i32
  switch i32 %10, label %27 [
    i32 37, label %11
    i32 0, label %18
  ]

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

18:                                               ; preds = %2
  %19 = load ptr, ptr %4, align 8, !tbaa !5
  %20 = load i8, ptr %19, align 1, !tbaa !9
  %21 = getelementptr inbounds %class.FormatParser, ptr %7, i32 0, i32 2
  %22 = load ptr, ptr %21, align 8, !tbaa !15
  store i8 %20, ptr %22, align 1, !tbaa !9
  store { i64, i64 } { i64 ptrtoint (ptr @_ZN12FormatParser6finishEPKc to i64), i64 0 }, ptr %6, align 8, !tbaa !9
  %23 = getelementptr inbounds { i64, i64 }, ptr %6, i32 0, i32 0
  %24 = load i64, ptr %23, align 8
  %25 = getelementptr inbounds { i64, i64 }, ptr %6, i32 0, i32 1
  %26 = load i64, ptr %25, align 8
  call void @_ZN3FsmIKcE4tranEMS1_FiPS0_E(ptr noundef nonnull align 8 dereferenceable(16) %7, i64 %24, i64 %26)
  br label %33

27:                                               ; preds = %2
  %28 = load ptr, ptr %4, align 8, !tbaa !5
  %29 = load i8, ptr %28, align 1, !tbaa !9
  %30 = getelementptr inbounds %class.FormatParser, ptr %7, i32 0, i32 2
  %31 = load ptr, ptr %30, align 8, !tbaa !15
  %32 = getelementptr inbounds i8, ptr %31, i32 1
  store ptr %32, ptr %30, align 8, !tbaa !15
  store i8 %29, ptr %31, align 1, !tbaa !9
  br label %33

33:                                               ; preds = %27, %18, %11
  ret i32 1
}

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZN12FormatParser6finishEPKc(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, !13, i64 32}
!15 = !{!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 nounwind uwtable
define dso_local noundef i32 @_ZN12FormatParser4textEPKc(ptr noundef nonnull align 8 dereferenceable(64) %0, ptr nocapture noundef readonly %1) local_unnamed_addr #0 align 2 {
  %3 = load i8, ptr %1, align 1, !tbaa !5
  switch i8 %3, label %10 [
    i8 37, label %4
    i8 0, label %7
  ]

4:                                                ; preds = %2
  %5 = getelementptr inbounds i8, ptr %0, i64 36
  store i32 0, ptr %5, align 4, !tbaa !8
  %6 = getelementptr inbounds i8, ptr %0, i64 32
  store i32 0, ptr %6, align 8, !tbaa !13
  tail call void @_ZN3FsmIKcE4tranEMS1_FiPS0_E(ptr noundef nonnull align 8 dereferenceable(16) %0, i64 ptrtoint (ptr @_ZN12FormatParser7controlEPKc to i64), i64 0)
  br label %14

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

10:                                               ; preds = %2
  %11 = getelementptr inbounds i8, ptr %0, i64 24
  %12 = load ptr, ptr %11, align 8, !tbaa !14
  %13 = getelementptr inbounds i8, ptr %12, i64 1
  store ptr %13, ptr %11, align 8, !tbaa !14
  store i8 %3, ptr %12, align 1, !tbaa !5
  br label %14

14:                                               ; preds = %10, %7, %4
  ret i32 1
}

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZN12FormatParser6finishEPKc(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, !12, i64 32}
!14 = !{!9, !11, i64 24}


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