; LLVM IR from kmilo17pet/QuarkTS-cpp :: src/fsm.ll (ZN3qOS12stateMachine12stateOnStartEPNS_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"

%"struct.qOS::sm::signal_t" = type { i32, ptr }
%"class.qOS::sm::stateHandler" = type { ptr, ptr, ptr, ptr, ptr, i8, i16, i32, ptr, ptr, 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::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: inlinehint mustprogress nounwind uwtable
declare dso_local void @_ZN3qOS2sm8signal_tC2Ev(ptr noundef nonnull align 8 dereferenceable(16)) unnamed_addr #1 align 2

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

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

; 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) #3

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef ptr @_ZN3qOS12stateMachine12stateOnStartEPNS_2sm5stateE(ptr noundef nonnull align 8 dereferenceable(240) %0, ptr noundef %1) #2 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca %"struct.qOS::sm::signal_t", align 8
  %6 = alloca %"struct.qOS::sm::signal_t", 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
  call void @llvm.lifetime.start.p0(i64 16, ptr %5) #4
  call void @_ZN3qOS2sm8signal_tC2Ev(ptr noundef nonnull align 8 dereferenceable(16) %5) #4
  %8 = getelementptr inbounds %"struct.qOS::sm::signal_t", ptr %5, i32 0, i32 0
  store i32 -1, ptr %8, align 8, !tbaa !9
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %6, ptr align 8 %5, i64 16, i1 false), !tbaa.struct !12
  %9 = load ptr, ptr %4, align 8, !tbaa !5
  %10 = getelementptr inbounds { i32, ptr }, ptr %6, i32 0, i32 0
  %11 = load i32, ptr %10, align 8
  %12 = getelementptr inbounds { i32, ptr }, ptr %6, i32 0, i32 1
  %13 = load ptr, ptr %12, align 8
  call void @_ZN3qOS12stateMachine14prepareHandlerENS_2sm8signal_tEPNS1_5stateE(ptr noundef nonnull align 8 dereferenceable(240) %7, i32 %11, ptr %13, ptr noundef %9) #4
  %14 = load ptr, ptr %4, align 8, !tbaa !5
  %15 = call noundef signext i16 @_ZN3qOS12stateMachine21invokeStateActivitiesEPNS_2sm5stateE(ptr noundef nonnull align 8 dereferenceable(240) %7, ptr noundef %14) #4
  %16 = getelementptr inbounds %"class.qOS::sm::stateHandler", ptr %7, i32 0, i32 1
  %17 = load ptr, ptr %16, align 8, !tbaa !14
  %18 = icmp ne ptr null, %17
  br i1 %18, label %19, label %23

19:                                               ; preds = %2
  %20 = getelementptr inbounds %"class.qOS::sm::stateHandler", ptr %7, i32 0, i32 1
  %21 = load ptr, ptr %20, align 8, !tbaa !14
  %22 = getelementptr inbounds %"class.qOS::stateMachine", ptr %7, i32 0, i32 2
  store ptr %21, ptr %22, align 8, !tbaa !18
  br label %34

23:                                               ; preds = %2
  %24 = load ptr, ptr %4, align 8, !tbaa !5
  %25 = getelementptr inbounds %"class.qOS::sm::state", ptr %24, i32 0, i32 2
  %26 = load ptr, ptr %25, align 8, !tbaa !22
  %27 = icmp ne ptr null, %26
  br i1 %27, label %28, label %33

28:                                               ; preds = %23
  %29 = load ptr, ptr %4, align 8, !tbaa !5
  %30 = getelementptr inbounds %"class.qOS::sm::state", ptr %29, i32 0, i32 2
  %31 = load ptr, ptr %30, align 8, !tbaa !22
  %32 = getelementptr inbounds %"class.qOS::stateMachine", ptr %7, i32 0, i32 2
  store ptr %31, ptr %32, align 8, !tbaa !18
  br label %33

33:                                               ; preds = %28, %23
  br label %34

34:                                               ; preds = %33, %19
  %35 = getelementptr inbounds %"class.qOS::stateMachine", ptr %7, i32 0, i32 2
  %36 = load ptr, ptr %35, align 8, !tbaa !18
  call void @llvm.lifetime.end.p0(i64 16, ptr %5) #4
  ret ptr %36
}

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


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

%"struct.qOS::sm::signal_t" = type { i32, ptr }

; 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: inlinehint mustprogress nounwind uwtable
declare dso_local void @_ZN3qOS2sm8signal_tC2Ev(ptr noundef nonnull align 8 dereferenceable(16)) unnamed_addr #1 align 2

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

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef ptr @_ZN3qOS12stateMachine12stateOnStartEPNS_2sm5stateE(ptr noundef nonnull align 8 dereferenceable(240) %0, ptr noundef %1) local_unnamed_addr #2 align 2 {
  %3 = alloca %"struct.qOS::sm::signal_t", align 8
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %3) #3
  call void @_ZN3qOS2sm8signal_tC2Ev(ptr noundef nonnull align 8 dereferenceable(16) %3) #3
  store i32 -1, ptr %3, align 8, !tbaa !5
  %.sroa.21.0..sroa_idx = getelementptr inbounds i8, ptr %3, i64 8
  %.sroa.21.0.copyload = load ptr, ptr %.sroa.21.0..sroa_idx, align 8, !tbaa !11
  call void @_ZN3qOS12stateMachine14prepareHandlerENS_2sm8signal_tEPNS1_5stateE(ptr noundef nonnull align 8 dereferenceable(240) %0, i32 -1, ptr %.sroa.21.0.copyload, ptr noundef %1) #3
  %4 = call noundef signext i16 @_ZN3qOS12stateMachine21invokeStateActivitiesEPNS_2sm5stateE(ptr noundef nonnull align 8 dereferenceable(240) %0, ptr noundef %1) #3
  %5 = getelementptr inbounds i8, ptr %0, i64 8
  %6 = load ptr, ptr %5, align 8, !tbaa !12
  %.not = icmp eq ptr %6, null
  br i1 %.not, label %9, label %7

7:                                                ; preds = %2
  %8 = getelementptr inbounds i8, ptr %0, i64 80
  store ptr %6, ptr %8, align 8, !tbaa !16
  br label %13

9:                                                ; preds = %2
  %10 = getelementptr inbounds i8, ptr %1, i64 16
  %11 = load ptr, ptr %10, align 8, !tbaa !20
  %.not7 = icmp eq ptr %11, null
  %.phi.trans.insert = getelementptr inbounds i8, ptr %0, i64 80
  br i1 %.not7, label %._crit_edge, label %12

._crit_edge:                                      ; preds = %9
  %.pre = load ptr, ptr %.phi.trans.insert, align 8, !tbaa !16
  br label %13

12:                                               ; preds = %9
  store ptr %11, ptr %.phi.trans.insert, align 8, !tbaa !16
  br label %13

13:                                               ; preds = %._crit_edge, %12, %7
  %14 = phi ptr [ %.pre, %._crit_edge ], [ %11, %12 ], [ %6, %7 ]
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %3) #3
  ret ptr %14
}

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


; Effective O3 passes: BDCEPass,EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,SROAPass,SimplifyCFGPass