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

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

16:                                               ; preds = %4
  call void @llvm.lifetime.start.p0(i64 16, ptr %10) #4
  call void @_ZN3qOS2sm8signal_tC2Ev(ptr noundef nonnull align 8 dereferenceable(16) %10) #4
  %17 = load i32, ptr %6, align 4, !tbaa !9
  %18 = getelementptr inbounds %"struct.qOS::sm::signal_t", ptr %10, i32 0, i32 0
  store i32 %17, ptr %18, align 8, !tbaa !21
  %19 = load ptr, ptr %7, align 8, !tbaa !5
  %20 = getelementptr inbounds %"struct.qOS::sm::signal_t", ptr %10, i32 0, i32 1
  store ptr %19, ptr %20, align 8, !tbaa !22
  %21 = getelementptr inbounds %"class.qOS::stateMachine", ptr %12, i32 0, i32 4
  %22 = load ptr, ptr %21, align 8, !tbaa !13
  %23 = load i8, ptr %8, align 1, !tbaa !11, !range !23, !noundef !24
  %24 = trunc i8 %23 to i1
  %25 = zext i1 %24 to i64
  %26 = select i1 %24, i32 1, i32 0
  %27 = call noundef zeroext i1 @_ZN3qOS5queue4sendEPvNS_13queueSendModeE(ptr noundef nonnull align 8 dereferenceable(64) %22, ptr noundef %10, i32 noundef %26) #4
  %28 = zext i1 %27 to i8
  store i8 %28, ptr %9, align 1, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 16, ptr %10) #4
  br label %29

29:                                               ; preds = %16, %4
  %30 = load i8, ptr %9, align 1, !tbaa !11, !range !23, !noundef !24
  %31 = trunc i8 %30 to i1
  br i1 %31, label %44, label %32

32:                                               ; preds = %29
  %33 = getelementptr inbounds %"class.qOS::stateMachine", ptr %12, i32 0, i32 8
  %34 = getelementptr inbounds %"struct.qOS::sm::signal_t", ptr %33, i32 0, i32 0
  %35 = load i32, ptr %34, align 8, !tbaa !25
  %36 = icmp eq i32 -4, %35
  br i1 %36, label %37, label %44

37:                                               ; preds = %32
  %38 = load i32, ptr %6, align 4, !tbaa !9
  %39 = getelementptr inbounds %"class.qOS::stateMachine", ptr %12, i32 0, i32 8
  %40 = getelementptr inbounds %"struct.qOS::sm::signal_t", ptr %39, i32 0, i32 0
  store i32 %38, ptr %40, align 8, !tbaa !25
  %41 = load ptr, ptr %7, align 8, !tbaa !5
  %42 = getelementptr inbounds %"class.qOS::stateMachine", ptr %12, i32 0, i32 8
  %43 = getelementptr inbounds %"struct.qOS::sm::signal_t", ptr %42, i32 0, i32 1
  store ptr %41, ptr %43, align 8, !tbaa !26
  store i8 1, ptr %9, align 1, !tbaa !11
  br label %44

44:                                               ; preds = %37, %32, %29
  %45 = load i8, ptr %9, align 1, !tbaa !11, !range !23, !noundef !24
  %46 = trunc i8 %45 to i1
  call void @llvm.lifetime.end.p0(i64 1, ptr %9) #4
  ret i1 %46
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_ZN3qOS2sm8signal_tC2Ev(ptr noundef nonnull align 8 dereferenceable(16)) unnamed_addr #2 align 2

; Function Attrs: nounwind
declare noundef zeroext i1 @_ZN3qOS5queue4sendEPvNS_13queueSendModeE(ptr noundef nonnull align 8 dereferenceable(64), ptr noundef, i32 noundef) #3

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


; 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: mustprogress nounwind uwtable
define dso_local noundef zeroext i1 @_ZN3qOS12stateMachine18internalSignalSendENS_2sm8signalIDEPvb(ptr nocapture noundef nonnull align 8 dereferenceable(240) %0, i32 noundef %1, ptr noundef %2, i1 noundef zeroext %3) local_unnamed_addr #1 align 2 {
  %5 = alloca %"struct.qOS::sm::signal_t", align 8
  %6 = getelementptr inbounds i8, ptr %0, i64 96
  %7 = load ptr, ptr %6, align 8, !tbaa !5
  %.not = icmp eq ptr %7, null
  br i1 %.not, label %.thread, label %8

8:                                                ; preds = %4
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %5) #4
  call void @_ZN3qOS2sm8signal_tC2Ev(ptr noundef nonnull align 8 dereferenceable(16) %5) #4
  store i32 %1, ptr %5, align 8, !tbaa !17
  %9 = getelementptr inbounds i8, ptr %5, i64 8
  store ptr %2, ptr %9, align 8, !tbaa !18
  %10 = load ptr, ptr %6, align 8, !tbaa !5
  %11 = zext i1 %3 to i32
  %12 = call noundef zeroext i1 @_ZN3qOS5queue4sendEPvNS_13queueSendModeE(ptr noundef nonnull align 8 dereferenceable(64) %10, ptr noundef nonnull %5, i32 noundef %11) #4
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %5) #4
  br i1 %12, label %18, label %.thread

.thread:                                          ; preds = %4, %8
  %13 = getelementptr inbounds i8, ptr %0, i64 208
  %14 = load i32, ptr %13, align 8, !tbaa !19
  %15 = icmp eq i32 %14, -4
  br i1 %15, label %16, label %18

16:                                               ; preds = %.thread
  store i32 %1, ptr %13, align 8, !tbaa !19
  %17 = getelementptr inbounds i8, ptr %0, i64 216
  store ptr %2, ptr %17, align 8, !tbaa !20
  br label %18

18:                                               ; preds = %16, %.thread, %8
  %.1 = phi i1 [ true, %8 ], [ true, %16 ], [ false, %.thread ]
  ret i1 %.1
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_ZN3qOS2sm8signal_tC2Ev(ptr noundef nonnull align 8 dereferenceable(16)) unnamed_addr #2 align 2

; Function Attrs: nounwind
declare noundef zeroext i1 @_ZN3qOS5queue4sendEPvNS_13queueSendModeE(ptr noundef nonnull align 8 dereferenceable(64), ptr noundef, i32 noundef) local_unnamed_addr #3

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 = { 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 #3 = { nounwind "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 #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, !8, i64 96}
!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 = !{!16, !13, i64 0}
!18 = !{!16, !8, i64 8}
!19 = !{!6, !13, i64 208}
!20 = !{!6, !8, i64 216}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,PostOrderFunctionAttrsPass,SROAPass