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

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

%"struct.qOS::sm::signal_t" = type { i32, ptr }
%"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 }

; 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: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN3qOS12stateMachine12stateOnEntryEPNS_2sm5stateE(ptr noundef nonnull align 8 dereferenceable(240), ptr noundef) #2 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef signext i16 @_ZN3qOS12stateMachine13stateOnSignalEPNS_2sm5stateENS1_8signal_tE(ptr noundef nonnull align 8 dereferenceable(240), ptr noundef, i32, ptr) #2 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN3qOS12stateMachine24tracePathAndRetraceEntryEPPNS_2sm5stateE(ptr noundef nonnull align 8 dereferenceable(240), ptr noundef) #2 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN3qOS12stateMachine12traceOnStartEPPNS_2sm5stateE(ptr noundef nonnull align 8 dereferenceable(240), ptr noundef) #2 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local { i32, ptr } @_ZN3qOS12stateMachine15checkForSignalsENS_2sm8signal_tE(ptr noundef nonnull align 8 dereferenceable(240), i32, ptr) #2 align 2

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef zeroext i1 @_ZN3qOS12stateMachine3runENS_2sm8signal_tE(ptr noundef nonnull align 8 dereferenceable(240) %0, i32 %1, ptr %2) #2 align 2 {
  %4 = alloca %"struct.qOS::sm::signal_t", align 8
  %5 = alloca ptr, align 8
  %6 = alloca i8, align 1
  %7 = alloca [5 x ptr], align 16
  %8 = alloca %"struct.qOS::sm::signal_t", align 8
  %9 = alloca %"struct.qOS::sm::signal_t", align 8
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  %12 = alloca %"struct.qOS::sm::signal_t", align 8
  %13 = getelementptr inbounds { i32, ptr }, ptr %4, i32 0, i32 0
  store i32 %1, ptr %13, align 8
  %14 = getelementptr inbounds { i32, ptr }, ptr %4, i32 0, i32 1
  store ptr %2, ptr %14, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  %15 = load ptr, ptr %5, align 8
  call void @llvm.lifetime.start.p0(i64 1, ptr %6) #3
  store i8 0, ptr %6, align 1, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 40, ptr %7) #3
  call void @llvm.lifetime.start.p0(i64 16, ptr %8) #3
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %9, ptr align 8 %4, i64 16, i1 false), !tbaa.struct !11
  %16 = getelementptr inbounds { i32, ptr }, ptr %9, i32 0, i32 0
  %17 = load i32, ptr %16, align 8
  %18 = getelementptr inbounds { i32, ptr }, ptr %9, i32 0, i32 1
  %19 = load ptr, ptr %18, align 8
  %20 = call { i32, ptr } @_ZN3qOS12stateMachine15checkForSignalsENS_2sm8signal_tE(ptr noundef nonnull align 8 dereferenceable(240) %15, i32 %17, ptr %19) #3
  %21 = getelementptr inbounds { i32, ptr }, ptr %8, i32 0, i32 0
  %22 = extractvalue { i32, ptr } %20, 0
  store i32 %22, ptr %21, align 8
  %23 = getelementptr inbounds { i32, ptr }, ptr %8, i32 0, i32 1
  %24 = extractvalue { i32, ptr } %20, 1
  store ptr %24, ptr %23, align 8
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %4, ptr align 8 %8, i64 16, i1 false), !tbaa.struct !11
  call void @llvm.lifetime.end.p0(i64 16, ptr %8) #3
  %25 = getelementptr inbounds %"class.qOS::stateMachine", ptr %15, i32 0, i32 1
  %26 = load ptr, ptr %25, align 8, !tbaa !14
  %27 = icmp eq ptr null, %26
  br i1 %27, label %28, label %35

28:                                               ; preds = %3
  %29 = getelementptr inbounds %"class.qOS::stateMachine", ptr %15, i32 0, i32 7
  %30 = getelementptr inbounds %"class.qOS::stateMachine", ptr %15, i32 0, i32 1
  store ptr %29, ptr %30, align 8, !tbaa !14
  %31 = getelementptr inbounds %"class.qOS::stateMachine", ptr %15, i32 0, i32 2
  store ptr null, ptr %31, align 8, !tbaa !22
  %32 = getelementptr inbounds %"class.qOS::stateMachine", ptr %15, i32 0, i32 1
  %33 = load ptr, ptr %32, align 8, !tbaa !14
  call void @_ZN3qOS12stateMachine12stateOnEntryEPNS_2sm5stateE(ptr noundef nonnull align 8 dereferenceable(240) %15, ptr noundef %33) #3
  %34 = getelementptr inbounds [5 x ptr], ptr %7, i64 0, i64 0
  call void @_ZN3qOS12stateMachine12traceOnStartEPPNS_2sm5stateE(ptr noundef nonnull align 8 dereferenceable(240) %15, ptr noundef %34) #3
  br label %35

35:                                               ; preds = %28, %3
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  %36 = getelementptr inbounds %"class.qOS::stateMachine", ptr %15, i32 0, i32 1
  %37 = load ptr, ptr %36, align 8, !tbaa !14
  store ptr %37, ptr %10, align 8, !tbaa !5
  br label %38

38:                                               ; preds = %62, %35
  %39 = load ptr, ptr %10, align 8, !tbaa !5
  %40 = icmp ne ptr null, %39
  br i1 %40, label %42, label %41

41:                                               ; preds = %38
  store i32 2, ptr %11, align 4
  br label %66

42:                                               ; preds = %38
  %43 = load ptr, ptr %10, align 8, !tbaa !5
  %44 = getelementptr inbounds %"class.qOS::stateMachine", ptr %15, i32 0, i32 3
  store ptr %43, ptr %44, align 8, !tbaa !23
  %45 = load ptr, ptr %10, align 8, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %12, ptr align 8 %4, i64 16, i1 false), !tbaa.struct !11
  %46 = getelementptr inbounds { i32, ptr }, ptr %12, i32 0, i32 0
  %47 = load i32, ptr %46, align 8
  %48 = getelementptr inbounds { i32, ptr }, ptr %12, i32 0, i32 1
  %49 = load ptr, ptr %48, align 8
  %50 = call noundef signext i16 @_ZN3qOS12stateMachine13stateOnSignalEPNS_2sm5stateENS1_8signal_tE(ptr noundef nonnull align 8 dereferenceable(240) %15, ptr noundef %45, i32 %47, ptr %49) #3
  %51 = sext i16 %50 to i32
  %52 = icmp eq i32 -32763, %51
  br i1 %52, label %53, label %61

53:                                               ; preds = %42
  %54 = getelementptr inbounds %"class.qOS::stateMachine", ptr %15, i32 0, i32 2
  %55 = load ptr, ptr %54, align 8, !tbaa !22
  %56 = icmp ne ptr null, %55
  br i1 %56, label %57, label %60

57:                                               ; preds = %53
  %58 = getelementptr inbounds [5 x ptr], ptr %7, i64 0, i64 0
  call void @_ZN3qOS12stateMachine24tracePathAndRetraceEntryEPPNS_2sm5stateE(ptr noundef nonnull align 8 dereferenceable(240) %15, ptr noundef %58) #3
  %59 = getelementptr inbounds [5 x ptr], ptr %7, i64 0, i64 0
  call void @_ZN3qOS12stateMachine12traceOnStartEPPNS_2sm5stateE(ptr noundef nonnull align 8 dereferenceable(240) %15, ptr noundef %59) #3
  br label %60

60:                                               ; preds = %57, %53
  store i8 1, ptr %6, align 1, !tbaa !9
  store i32 2, ptr %11, align 4
  br label %66

61:                                               ; preds = %42
  br label %62

62:                                               ; preds = %61
  %63 = load ptr, ptr %10, align 8, !tbaa !5
  %64 = getelementptr inbounds %"class.qOS::sm::state", ptr %63, i32 0, i32 1
  %65 = load ptr, ptr %64, align 8, !tbaa !24
  store ptr %65, ptr %10, align 8, !tbaa !5
  br label %38, !llvm.loop !25

66:                                               ; preds = %60, %41
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  br label %67

67:                                               ; preds = %66
  %68 = load i8, ptr %6, align 1, !tbaa !9, !range !27, !noundef !28
  %69 = trunc i8 %68 to i1
  store i32 1, ptr %11, align 4
  call void @llvm.lifetime.end.p0(i64 40, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 1, ptr %6) #3
  ret i1 %69
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #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, !10, i64 0}
!10 = !{!"bool", !7, i64 0}
!11 = !{i64 0, i64 4, !12, i64 8, i64 8, !5}
!12 = !{!13, !13, i64 0}
!13 = !{!"_ZTSN3qOS2sm8signalIDE", !7, i64 0}
!14 = !{!15, !6, i64 72}
!15 = !{!"_ZTSN3qOS12stateMachineE", !16, i64 0, !6, i64 72, !6, i64 80, !6, i64 88, !6, i64 96, !6, i64 104, !6, i64 112, !19, i64 120, !21, i64 208, !6, i64 224, !6, i64 232}
!16 = !{!"_ZTSN3qOS2sm12stateHandlerE", !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !17, i64 40, !18, i64 42, !13, i64 44, !6, i64 48, !6, i64 56, !6, i64 64}
!17 = !{!"_ZTSN3qOS2sm11historyModeE", !7, i64 0}
!18 = !{!"_ZTSN3qOS2sm6statusE", !7, i64 0}
!19 = !{!"_ZTSN3qOS2sm5stateE", !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !20, i64 64, !20, i64 72, !6, i64 80}
!20 = !{!"long", !7, i64 0}
!21 = !{!"_ZTSN3qOS2sm8signal_tE", !13, i64 0, !6, i64 8}
!22 = !{!15, !6, i64 80}
!23 = !{!15, !6, i64 88}
!24 = !{!19, !6, i64 8}
!25 = distinct !{!25, !26}
!26 = !{!"llvm.loop.mustprogress"}
!27 = !{i8 0, i8 2}
!28 = !{}


; 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 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 dso_local void @_ZN3qOS12stateMachine12stateOnEntryEPNS_2sm5stateE(ptr noundef nonnull align 8 dereferenceable(240), ptr noundef) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef signext i16 @_ZN3qOS12stateMachine13stateOnSignalEPNS_2sm5stateENS1_8signal_tE(ptr noundef nonnull align 8 dereferenceable(240), ptr noundef, i32, ptr) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN3qOS12stateMachine24tracePathAndRetraceEntryEPPNS_2sm5stateE(ptr noundef nonnull align 8 dereferenceable(240), ptr noundef) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN3qOS12stateMachine12traceOnStartEPPNS_2sm5stateE(ptr noundef nonnull align 8 dereferenceable(240), ptr noundef) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local { i32, ptr } @_ZN3qOS12stateMachine15checkForSignalsENS_2sm8signal_tE(ptr noundef nonnull align 8 dereferenceable(240), i32, ptr) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef zeroext i1 @_ZN3qOS12stateMachine3runENS_2sm8signal_tE(ptr noundef nonnull align 8 dereferenceable(240) %0, i32 %1, ptr %2) local_unnamed_addr #1 align 2 {
  %4 = alloca [5 x ptr], align 16
  call void @llvm.lifetime.start.p0(i64 40, ptr nonnull %4) #2
  %5 = tail call { i32, ptr } @_ZN3qOS12stateMachine15checkForSignalsENS_2sm8signal_tE(ptr noundef nonnull align 8 dereferenceable(240) %0, i32 %1, ptr %2) #2
  %6 = extractvalue { i32, ptr } %5, 0
  %7 = extractvalue { i32, ptr } %5, 1
  %8 = getelementptr inbounds i8, ptr %0, i64 72
  %9 = load ptr, ptr %8, align 8, !tbaa !5
  %10 = icmp eq ptr %9, null
  br i1 %10, label %11, label %.lr.ph

11:                                               ; preds = %3
  %12 = getelementptr inbounds i8, ptr %0, i64 120
  store ptr %12, ptr %8, align 8, !tbaa !9
  %13 = getelementptr inbounds i8, ptr %0, i64 80
  store ptr null, ptr %13, align 8, !tbaa !18
  tail call void @_ZN3qOS12stateMachine12stateOnEntryEPNS_2sm5stateE(ptr noundef nonnull align 8 dereferenceable(240) %0, ptr noundef nonnull %12) #2
  call void @_ZN3qOS12stateMachine12traceOnStartEPPNS_2sm5stateE(ptr noundef nonnull align 8 dereferenceable(240) %0, ptr noundef nonnull %4) #2
  %.019.pre = load ptr, ptr %8, align 8, !tbaa !5
  %.not20.not = icmp eq ptr %.019.pre, null
  br i1 %.not20.not, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %3, %11
  %.01927 = phi ptr [ %.019.pre, %11 ], [ %9, %3 ]
  %14 = getelementptr inbounds i8, ptr %0, i64 88
  br label %17

15:                                               ; preds = %17
  %16 = getelementptr inbounds i8, ptr %.021, i64 8
  %.0 = load ptr, ptr %16, align 8, !tbaa !5
  %.not.not = icmp eq ptr %.0, null
  br i1 %.not.not, label %.loopexit, label %17, !llvm.loop !19

17:                                               ; preds = %.lr.ph, %15
  %.021 = phi ptr [ %.01927, %.lr.ph ], [ %.0, %15 ]
  store ptr %.021, ptr %14, align 8, !tbaa !21
  %18 = call noundef signext i16 @_ZN3qOS12stateMachine13stateOnSignalEPNS_2sm5stateENS1_8signal_tE(ptr noundef nonnull align 8 dereferenceable(240) %0, ptr noundef nonnull %.021, i32 %6, ptr %7) #2
  %19 = icmp eq i16 %18, -32763
  br i1 %19, label %20, label %15

20:                                               ; preds = %17
  %21 = getelementptr inbounds i8, ptr %0, i64 80
  %22 = load ptr, ptr %21, align 8, !tbaa !18
  %.not16 = icmp eq ptr %22, null
  br i1 %.not16, label %.loopexit, label %23

23:                                               ; preds = %20
  call void @_ZN3qOS12stateMachine24tracePathAndRetraceEntryEPPNS_2sm5stateE(ptr noundef nonnull align 8 dereferenceable(240) %0, ptr noundef nonnull %4) #2
  call void @_ZN3qOS12stateMachine12traceOnStartEPPNS_2sm5stateE(ptr noundef nonnull align 8 dereferenceable(240) %0, ptr noundef nonnull %4) #2
  br label %.loopexit

.loopexit:                                        ; preds = %15, %11, %20, %23
  %.not18 = phi i1 [ true, %20 ], [ true, %23 ], [ false, %11 ], [ false, %15 ]
  call void @llvm.lifetime.end.p0(i64 40, ptr nonnull %4) #2
  ret i1 %.not18
}

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


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