; LLVM IR from kmilo17pet/QuarkTS-cpp :: src/fsm.ll (ZN3qOS12stateMachine12stateOnEntryEPNS_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::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: 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 void @_ZN3qOS12stateMachine30timeoutPerformSpecifiedActionsEPNS_2sm5stateENS1_8signalIDE(ptr noundef nonnull align 8 dereferenceable(240), ptr noundef, i32 noundef) #2 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 void @_ZN3qOS12stateMachine12stateOnEntryEPNS_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 -3, 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::stateMachine", ptr %7, i32 0, i32 5
  %17 = load ptr, ptr %16, align 8, !tbaa !14
  %18 = icmp ne ptr null, %17
  br i1 %18, label %19, label %26

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

24:                                               ; preds = %19
  %25 = load ptr, ptr %4, align 8, !tbaa !5
  call void @_ZN3qOS12stateMachine30timeoutPerformSpecifiedActionsEPNS_2sm5stateENS1_8signalIDE(ptr noundef nonnull align 8 dereferenceable(240) %7, ptr noundef %25, i32 noundef -3) #4
  br label %26

26:                                               ; preds = %24, %19, %2
  call void @llvm.lifetime.end.p0(i64 16, ptr %5) #4
  ret void
}

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 104}
!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, !10, 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, !11, 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 = !{!19, !6, i64 40}


; 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 void @_ZN3qOS12stateMachine30timeoutPerformSpecifiedActionsEPNS_2sm5stateENS1_8signalIDE(ptr noundef nonnull align 8 dereferenceable(240), ptr noundef, i32 noundef) local_unnamed_addr #2 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 void @_ZN3qOS12stateMachine12stateOnEntryEPNS_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 -3, 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 -3, 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 104
  %6 = load ptr, ptr %5, align 8, !tbaa !12
  %.not = icmp eq ptr %6, null
  br i1 %.not, label %11, label %7

7:                                                ; preds = %2
  %8 = getelementptr inbounds i8, ptr %1, i64 40
  %9 = load ptr, ptr %8, align 8, !tbaa !19
  %.not6 = icmp eq ptr %9, null
  br i1 %.not6, label %11, label %10

10:                                               ; preds = %7
  call void @_ZN3qOS12stateMachine30timeoutPerformSpecifiedActionsEPNS_2sm5stateENS1_8signalIDE(ptr noundef nonnull align 8 dereferenceable(240) %0, ptr noundef nonnull %1, i32 noundef -3) #3
  br label %11

11:                                               ; preds = %10, %7, %2
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %3) #3
  ret void
}

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


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,SROAPass