; LLVM IR from kmilo17pet/QuarkTS-cpp :: src/fsm.ll (ZN3qOS12stateMachine13stateOnSignalEPNS_2sm5stateENS1_8signal_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::sm::state" = type { ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, i64, i64, ptr }
%"class.qOS::sm::stateHandler" = type { ptr, ptr, ptr, ptr, ptr, i8, i16, i32, ptr, ptr, 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
declare dso_local void @_ZNK3qOS2sm5state20sweepTransitionTableERNS0_12stateHandlerE(ptr noundef nonnull align 8 dereferenceable(88), ptr noundef nonnull align 8 dereferenceable(72)) #1 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN3qOS12stateMachine10transitionEPNS_2sm5stateENS1_11historyModeE(ptr noundef nonnull align 8 dereferenceable(240), ptr noundef, i8 noundef zeroext) #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) #1 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) #1 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) #2

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

22:                                               ; preds = %4
  %23 = load ptr, ptr %7, align 8, !tbaa !5
  call void @_ZNK3qOS2sm5state20sweepTransitionTableERNS0_12stateHandlerE(ptr noundef nonnull align 8 dereferenceable(88) %23, ptr noundef nonnull align 8 dereferenceable(72) %12) #3
  br label %24

24:                                               ; preds = %22, %4
  %25 = load ptr, ptr %7, align 8, !tbaa !5
  %26 = call noundef signext i16 @_ZN3qOS12stateMachine21invokeStateActivitiesEPNS_2sm5stateE(ptr noundef nonnull align 8 dereferenceable(240) %12, ptr noundef %25) #3
  store i16 %26, ptr %8, align 2, !tbaa !15
  %27 = getelementptr inbounds %"class.qOS::sm::stateHandler", ptr %12, i32 0, i32 2
  %28 = load ptr, ptr %27, align 8, !tbaa !17
  %29 = icmp ne ptr null, %28
  br i1 %29, label %30, label %35

30:                                               ; preds = %24
  %31 = getelementptr inbounds %"class.qOS::sm::stateHandler", ptr %12, i32 0, i32 2
  %32 = load ptr, ptr %31, align 8, !tbaa !17
  %33 = getelementptr inbounds %"class.qOS::sm::stateHandler", ptr %12, i32 0, i32 5
  %34 = load i8, ptr %33, align 8, !tbaa !20
  call void @_ZN3qOS12stateMachine10transitionEPNS_2sm5stateENS1_11historyModeE(ptr noundef nonnull align 8 dereferenceable(240) %12, ptr noundef %32, i8 noundef zeroext %34) #3
  store i16 -32763, ptr %8, align 2, !tbaa !15
  br label %35

35:                                               ; preds = %30, %24
  %36 = load i16, ptr %8, align 2, !tbaa !15
  call void @llvm.lifetime.end.p0(i64 2, ptr %8) #3
  ret i16 %36
}

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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 = !{i64 0, i64 4, !10, i64 8, i64 8, !5}
!10 = !{!11, !11, i64 0}
!11 = !{!"_ZTSN3qOS2sm8signalIDE", !7, i64 0}
!12 = !{!13, !6, i64 48}
!13 = !{!"_ZTSN3qOS2sm5stateE", !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !14, i64 64, !14, i64 72, !6, i64 80}
!14 = !{!"long", !7, i64 0}
!15 = !{!16, !16, i64 0}
!16 = !{!"_ZTSN3qOS2sm6statusE", !7, i64 0}
!17 = !{!18, !6, i64 16}
!18 = !{!"_ZTSN3qOS2sm12stateHandlerE", !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !19, i64 40, !16, i64 42, !11, i64 44, !6, i64 48, !6, i64 56, !6, i64 64}
!19 = !{!"_ZTSN3qOS2sm11historyModeE", !7, i64 0}
!20 = !{!18, !19, 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"

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZNK3qOS2sm5state20sweepTransitionTableERNS0_12stateHandlerE(ptr noundef nonnull align 8 dereferenceable(88), ptr noundef nonnull align 8 dereferenceable(72)) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN3qOS12stateMachine10transitionEPNS_2sm5stateENS1_11historyModeE(ptr noundef nonnull align 8 dereferenceable(240), ptr noundef, i8 noundef zeroext) local_unnamed_addr #0 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 #0 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 #0 align 2

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef signext i16 @_ZN3qOS12stateMachine13stateOnSignalEPNS_2sm5stateENS1_8signal_tE(ptr noundef nonnull align 8 dereferenceable(240) %0, ptr noundef %1, i32 %2, ptr %3) local_unnamed_addr #0 align 2 {
  tail call void @_ZN3qOS12stateMachine14prepareHandlerENS_2sm8signal_tEPNS1_5stateE(ptr noundef nonnull align 8 dereferenceable(240) %0, i32 %2, ptr %3, ptr noundef %1) #1
  %5 = getelementptr inbounds i8, ptr %1, i64 48
  %6 = load ptr, ptr %5, align 8, !tbaa !5
  %.not = icmp eq ptr %6, null
  br i1 %.not, label %8, label %7

7:                                                ; preds = %4
  tail call void @_ZNK3qOS2sm5state20sweepTransitionTableERNS0_12stateHandlerE(ptr noundef nonnull align 8 dereferenceable(88) %1, ptr noundef nonnull align 8 dereferenceable(72) %0) #1
  br label %8

8:                                                ; preds = %7, %4
  %9 = tail call noundef signext i16 @_ZN3qOS12stateMachine21invokeStateActivitiesEPNS_2sm5stateE(ptr noundef nonnull align 8 dereferenceable(240) %0, ptr noundef nonnull %1) #1
  %10 = getelementptr inbounds i8, ptr %0, i64 16
  %11 = load ptr, ptr %10, align 8, !tbaa !11
  %.not9 = icmp eq ptr %11, null
  br i1 %.not9, label %15, label %12

12:                                               ; preds = %8
  %13 = getelementptr inbounds i8, ptr %0, i64 40
  %14 = load i8, ptr %13, align 8, !tbaa !16
  tail call void @_ZN3qOS12stateMachine10transitionEPNS_2sm5stateENS1_11historyModeE(ptr noundef nonnull align 8 dereferenceable(240) %0, ptr noundef nonnull %11, i8 noundef zeroext %14) #1
  br label %15

15:                                               ; preds = %12, %8
  %.0 = phi i16 [ -32763, %12 ], [ %9, %8 ]
  ret i16 %.0
}

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 = { 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 48}
!6 = !{!"_ZTSN3qOS2sm5stateE", !7, i64 8, !7, i64 16, !7, i64 24, !7, i64 32, !7, i64 40, !7, i64 48, !7, i64 56, !10, i64 64, !10, i64 72, !7, i64 80}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"long", !8, i64 0}
!11 = !{!12, !7, i64 16}
!12 = !{!"_ZTSN3qOS2sm12stateHandlerE", !7, i64 8, !7, i64 16, !7, i64 24, !7, i64 32, !13, i64 40, !14, i64 42, !15, i64 44, !7, i64 48, !7, i64 56, !7, i64 64}
!13 = !{!"_ZTSN3qOS2sm11historyModeE", !8, i64 0}
!14 = !{!"_ZTSN3qOS2sm6statusE", !8, i64 0}
!15 = !{!"_ZTSN3qOS2sm8signalIDE", !8, i64 0}
!16 = !{!12, !13, i64 40}


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