; LLVM IR from kmilo17pet/QuarkTS-cpp :: src/fsm.ll (ZNK3qOS12stateMachine11levelsToLCAEPNS_2sm5stateE)

; 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.qOS::stateMachine" = type { %"class.qOS::sm::stateHandler", ptr, ptr, ptr, ptr, ptr, ptr, %"class.qOS::sm::state", %"struct.qOS::sm::signal_t", ptr, ptr }
%"class.qOS::sm::stateHandler" = type { ptr, ptr, ptr, ptr, ptr, i8, i16, i32, ptr, ptr, ptr }
%"class.qOS::sm::state" = type { ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, i64, i64, ptr }
%"struct.qOS::sm::signal_t" = type { i32, ptr }

; 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
define dso_local noundef zeroext i8 @_ZNK3qOS12stateMachine11levelsToLCAEPNS_2sm5stateE(ptr noundef nonnull align 8 dereferenceable(240) %0, ptr noundef %1) #1 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i8, align 1
  %6 = alloca i8, align 1
  %7 = alloca i8, align 1
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  %11 = load ptr, ptr %3, align 8
  call void @llvm.lifetime.start.p0(i64 1, ptr %5) #2
  store i8 0, ptr %5, align 1, !tbaa !9
  %12 = getelementptr inbounds %"class.qOS::stateMachine", ptr %11, i32 0, i32 3
  %13 = load ptr, ptr %12, align 8, !tbaa !10
  %14 = load ptr, ptr %4, align 8, !tbaa !5
  %15 = icmp eq ptr %13, %14
  br i1 %15, label %16, label %17

16:                                               ; preds = %2
  store i8 1, ptr %5, align 1, !tbaa !9
  br label %56

17:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 1, ptr %6) #2
  store i8 0, ptr %6, align 1, !tbaa !19
  call void @llvm.lifetime.start.p0(i64 1, ptr %7) #2
  store i8 0, ptr %7, align 1, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #2
  %18 = getelementptr inbounds %"class.qOS::stateMachine", ptr %11, i32 0, i32 3
  %19 = load ptr, ptr %18, align 8, !tbaa !10
  store ptr %19, ptr %8, align 8, !tbaa !5
  br label %20

20:                                               ; preds = %51, %17
  %21 = load ptr, ptr %8, align 8, !tbaa !5
  %22 = icmp ne ptr null, %21
  br i1 %22, label %23, label %27

23:                                               ; preds = %20
  %24 = load i8, ptr %6, align 1, !tbaa !19, !range !21, !noundef !22
  %25 = trunc i8 %24 to i1
  %26 = xor i1 %25, true
  br label %27

27:                                               ; preds = %23, %20
  %28 = phi i1 [ false, %20 ], [ %26, %23 ]
  br i1 %28, label %30, label %29

29:                                               ; preds = %27
  store i32 2, ptr %9, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #2
  br label %55

30:                                               ; preds = %27
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #2
  %31 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %31, ptr %10, align 8, !tbaa !5
  br label %32

32:                                               ; preds = %43, %30
  %33 = load ptr, ptr %10, align 8, !tbaa !5
  %34 = icmp ne ptr null, %33
  br i1 %34, label %36, label %35

35:                                               ; preds = %32
  store i32 5, ptr %9, align 4
  br label %47

36:                                               ; preds = %32
  %37 = load ptr, ptr %8, align 8, !tbaa !5
  %38 = load ptr, ptr %10, align 8, !tbaa !5
  %39 = icmp eq ptr %37, %38
  br i1 %39, label %40, label %42

40:                                               ; preds = %36
  %41 = load i8, ptr %7, align 1, !tbaa !9
  store i8 %41, ptr %5, align 1, !tbaa !9
  store i8 1, ptr %6, align 1, !tbaa !19
  store i32 5, ptr %9, align 4
  br label %47

42:                                               ; preds = %36
  br label %43

43:                                               ; preds = %42
  %44 = load ptr, ptr %10, align 8, !tbaa !5
  %45 = getelementptr inbounds %"class.qOS::sm::state", ptr %44, i32 0, i32 1
  %46 = load ptr, ptr %45, align 8, !tbaa !23
  store ptr %46, ptr %10, align 8, !tbaa !5
  br label %32, !llvm.loop !24

47:                                               ; preds = %40, %35
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #2
  br label %48

48:                                               ; preds = %47
  %49 = load i8, ptr %7, align 1, !tbaa !9
  %50 = add i8 %49, 1
  store i8 %50, ptr %7, align 1, !tbaa !9
  br label %51

51:                                               ; preds = %48
  %52 = load ptr, ptr %8, align 8, !tbaa !5
  %53 = getelementptr inbounds %"class.qOS::sm::state", ptr %52, i32 0, i32 1
  %54 = load ptr, ptr %53, align 8, !tbaa !23
  store ptr %54, ptr %8, align 8, !tbaa !5
  br label %20, !llvm.loop !26

55:                                               ; preds = %29
  call void @llvm.lifetime.end.p0(i64 1, ptr %7) #2
  call void @llvm.lifetime.end.p0(i64 1, ptr %6) #2
  br label %56

56:                                               ; preds = %55, %16
  %57 = load i8, ptr %5, align 1, !tbaa !9
  store i32 1, ptr %9, align 4
  call void @llvm.lifetime.end.p0(i64 1, ptr %5) #2
  ret i8 %57
}

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 = { 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 = !{!7, !7, i64 0}
!10 = !{!11, !6, i64 88}
!11 = !{!"_ZTSN3qOS12stateMachineE", !12, i64 0, !6, i64 72, !6, i64 80, !6, i64 88, !6, i64 96, !6, i64 104, !6, i64 112, !16, i64 120, !18, i64 208, !6, i64 224, !6, i64 232}
!12 = !{!"_ZTSN3qOS2sm12stateHandlerE", !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !13, i64 40, !14, i64 42, !15, i64 44, !6, i64 48, !6, i64 56, !6, i64 64}
!13 = !{!"_ZTSN3qOS2sm11historyModeE", !7, i64 0}
!14 = !{!"_ZTSN3qOS2sm6statusE", !7, i64 0}
!15 = !{!"_ZTSN3qOS2sm8signalIDE", !7, i64 0}
!16 = !{!"_ZTSN3qOS2sm5stateE", !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !17, i64 64, !17, i64 72, !6, i64 80}
!17 = !{!"long", !7, i64 0}
!18 = !{!"_ZTSN3qOS2sm8signal_tE", !15, i64 0, !6, i64 8}
!19 = !{!20, !20, i64 0}
!20 = !{!"bool", !7, i64 0}
!21 = !{i8 0, i8 2}
!22 = !{}
!23 = !{!16, !6, i64 8}
!24 = distinct !{!24, !25}
!25 = !{!"llvm.loop.mustprogress"}
!26 = distinct !{!26, !25}


; 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 nofree norecurse nosync nounwind willreturn memory(read, inaccessiblemem: none) uwtable
define dso_local noundef zeroext i8 @_ZNK3qOS12stateMachine11levelsToLCAEPNS_2sm5stateE(ptr nocapture noundef nonnull readonly align 8 dereferenceable(240) %0, ptr noundef readonly %1) local_unnamed_addr #0 align 2 {
  %3 = getelementptr inbounds i8, ptr %0, i64 88
  %4 = load ptr, ptr %3, align 8, !tbaa !5
  %5 = icmp eq ptr %4, %1
  br i1 %5, label %.loopexit, label %.preheader20

.preheader20:                                     ; preds = %2
  %6 = icmp eq ptr %4, null
  %.not21 = icmp eq ptr %1, null
  %or.cond = or i1 %6, %.not21
  br i1 %or.cond, label %.loopexit, label %.preheader

.preheader:                                       ; preds = %.preheader20, %._crit_edge
  %.01230 = phi ptr [ %14, %._crit_edge ], [ %4, %.preheader20 ]
  %.01329 = phi i8 [ %12, %._crit_edge ], [ 0, %.preheader20 ]
  br label %7

7:                                                ; preds = %.preheader, %9
  %.022 = phi ptr [ %1, %.preheader ], [ %11, %9 ]
  %8 = icmp eq ptr %.01230, %.022
  br i1 %8, label %.loopexit, label %9

9:                                                ; preds = %7
  %10 = getelementptr inbounds i8, ptr %.022, i64 8
  %11 = load ptr, ptr %10, align 8, !tbaa !17
  %.not = icmp eq ptr %11, null
  br i1 %.not, label %._crit_edge, label %7, !llvm.loop !18

._crit_edge:                                      ; preds = %9
  %12 = add i8 %.01329, 1
  %13 = getelementptr inbounds i8, ptr %.01230, i64 8
  %14 = load ptr, ptr %13, align 8, !tbaa !17
  %15 = icmp eq ptr %14, null
  %.not19 = or i1 %15, %8
  br i1 %.not19, label %.loopexit, label %.preheader, !llvm.loop !20

.loopexit:                                        ; preds = %._crit_edge, %7, %.preheader20, %2
  %.2 = phi i8 [ 1, %2 ], [ 0, %.preheader20 ], [ %.01329, %7 ], [ 0, %._crit_edge ]
  ret i8 %.2
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(read, inaccessiblemem: none) 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, !8, i64 88}
!6 = !{!"_ZTSN3qOS12stateMachineE", !7, i64 0, !8, i64 72, !8, i64 80, !8, i64 88, !8, i64 96, !8, i64 104, !8, i64 112, !14, i64 120, !16, i64 208, !8, i64 224, !8, i64 232}
!7 = !{!"_ZTSN3qOS2sm12stateHandlerE", !8, i64 8, !8, i64 16, !8, i64 24, !8, i64 32, !11, i64 40, !12, i64 42, !13, i64 44, !8, i64 48, !8, i64 56, !8, i64 64}
!8 = !{!"any pointer", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C++ TBAA"}
!11 = !{!"_ZTSN3qOS2sm11historyModeE", !9, i64 0}
!12 = !{!"_ZTSN3qOS2sm6statusE", !9, i64 0}
!13 = !{!"_ZTSN3qOS2sm8signalIDE", !9, i64 0}
!14 = !{!"_ZTSN3qOS2sm5stateE", !8, i64 8, !8, i64 16, !8, i64 24, !8, i64 32, !8, i64 40, !8, i64 48, !8, i64 56, !15, i64 64, !15, i64 72, !8, i64 80}
!15 = !{!"long", !9, i64 0}
!16 = !{!"_ZTSN3qOS2sm8signal_tE", !13, i64 0, !8, i64 8}
!17 = !{!14, !8, i64 8}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}
!20 = distinct !{!20, !19}


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