; LLVM IR from kmilo17pet/QuarkTS-cpp :: src/kernel.ll (ZN3qOS4core3addERNS_4taskERNS_12stateMachineEhmNS_9taskStateEPv)

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

%"class.qOS::task" = type <{ %"class.qOS::node", ptr, ptr, ptr, ptr, ptr, i64, [11 x i8], [5 x i8], %"class.qOS::timer", i32, [4 x i8], i64, i32, i32, i32, i8, i8, [2 x i8] }>
%"class.qOS::node" = type { ptr, ptr, ptr, ptr }
%"class.qOS::timer" = type { ptr, i64, i64 }
%"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 }
%"struct.qOS::sm::signal_t" = type { i32, ptr }

@_ZN3qOS4task8PERIODICE = external constant i32, align 4

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZN3qOS4core3addERNS_4taskEPFvRNS_9taskEventEEhmiNS_9taskStateEPv(ptr noundef nonnull align 8 dereferenceable(800), ptr noundef nonnull align 8 dereferenceable(150), ptr noundef, i8 noundef zeroext, i64 noundef, i32 noundef, i32 noundef, ptr noundef) #0 align 2

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef zeroext i1 @_ZN3qOS4core3addERNS_4taskERNS_12stateMachineEhmNS_9taskStateEPv(ptr noundef nonnull align 8 dereferenceable(800) %0, ptr noundef nonnull align 8 dereferenceable(150) %1, ptr noundef nonnull align 8 dereferenceable(240) %2, i8 noundef zeroext %3, i64 noundef %4, i32 noundef %5, ptr noundef %6) #0 align 2 {
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i8, align 1
  %12 = alloca i64, align 8
  %13 = alloca i32, align 4
  %14 = alloca ptr, align 8
  %15 = alloca i8, align 1
  store ptr %0, ptr %8, align 8, !tbaa !5
  store ptr %1, ptr %9, align 8, !tbaa !5
  store ptr %2, ptr %10, align 8, !tbaa !5
  store i8 %3, ptr %11, align 1, !tbaa !9
  store i64 %4, ptr %12, align 8, !tbaa !10
  store i32 %5, ptr %13, align 4, !tbaa !12
  store ptr %6, ptr %14, align 8, !tbaa !5
  %16 = load ptr, ptr %8, align 8
  call void @llvm.lifetime.start.p0(i64 1, ptr %15) #3
  %17 = load ptr, ptr %9, align 8, !tbaa !5
  %18 = load i8, ptr %11, align 1, !tbaa !9
  %19 = load i64, ptr %12, align 8, !tbaa !10
  %20 = load i32, ptr @_ZN3qOS4task8PERIODICE, align 4, !tbaa !14
  %21 = load i32, ptr %13, align 4, !tbaa !12
  %22 = load ptr, ptr %14, align 8, !tbaa !5
  %23 = call noundef zeroext i1 @_ZN3qOS4core3addERNS_4taskEPFvRNS_9taskEventEEhmiNS_9taskStateEPv(ptr noundef nonnull align 8 dereferenceable(800) %16, ptr noundef nonnull align 8 dereferenceable(150) %17, ptr noundef @_ZL15fsmTaskCallbackRN3qOS9taskEventE, i8 noundef zeroext %18, i64 noundef %19, i32 noundef %20, i32 noundef %21, ptr noundef %22) #3
  %24 = zext i1 %23 to i8
  store i8 %24, ptr %15, align 1, !tbaa !16
  %25 = load i8, ptr %15, align 1, !tbaa !16, !range !18, !noundef !19
  %26 = trunc i8 %25 to i1
  br i1 %26, label %27, label %46

27:                                               ; preds = %7
  %28 = load ptr, ptr %10, align 8, !tbaa !5
  %29 = load ptr, ptr %9, align 8, !tbaa !5
  %30 = getelementptr inbounds %"class.qOS::task", ptr %29, i32 0, i32 4
  store ptr %28, ptr %30, align 8, !tbaa !20
  %31 = load ptr, ptr %9, align 8, !tbaa !5
  %32 = load ptr, ptr %10, align 8, !tbaa !5
  %33 = getelementptr inbounds %"class.qOS::stateMachine", ptr %32, i32 0, i32 9
  store ptr %31, ptr %33, align 8, !tbaa !25
  %34 = load ptr, ptr %10, align 8, !tbaa !5
  %35 = getelementptr inbounds %"class.qOS::stateMachine", ptr %34, i32 0, i32 4
  %36 = load ptr, ptr %35, align 8, !tbaa !33
  %37 = icmp ne ptr null, %36
  br i1 %37, label %38, label %45

38:                                               ; preds = %27
  %39 = load ptr, ptr %9, align 8, !tbaa !5
  %40 = load ptr, ptr %10, align 8, !tbaa !5
  %41 = getelementptr inbounds %"class.qOS::stateMachine", ptr %40, i32 0, i32 4
  %42 = load ptr, ptr %41, align 8, !tbaa !33
  %43 = call noundef zeroext i1 @_ZN3qOS4task11attachQueueERNS_5queueENS_13queueLinkModeEm(ptr noundef nonnull align 8 dereferenceable(150) %39, ptr noundef nonnull align 8 dereferenceable(64) %42, i32 noundef 16, i64 noundef 1) #3
  %44 = zext i1 %43 to i8
  store i8 %44, ptr %15, align 1, !tbaa !16
  br label %45

45:                                               ; preds = %38, %27
  br label %46

46:                                               ; preds = %45, %7
  %47 = load i8, ptr %15, align 1, !tbaa !16, !range !18, !noundef !19
  %48 = trunc i8 %47 to i1
  call void @llvm.lifetime.end.p0(i64 1, ptr %15) #3
  ret i1 %48
}

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: mustprogress nounwind uwtable
declare hidden void @_ZL15fsmTaskCallbackRN3qOS9taskEventE(ptr noundef nonnull align 8 dereferenceable(48)) #0

; Function Attrs: nounwind
declare noundef zeroext i1 @_ZN3qOS4task11attachQueueERNS_5queueENS_13queueLinkModeEm(ptr noundef nonnull align 8 dereferenceable(150), ptr noundef nonnull align 8 dereferenceable(64), i32 noundef, i64 noundef) #2

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #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 = !{!7, !7, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"long", !7, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"_ZTSN3qOS9taskStateE", !7, i64 0}
!14 = !{!15, !15, i64 0}
!15 = !{!"int", !7, i64 0}
!16 = !{!17, !17, i64 0}
!17 = !{!"bool", !7, i64 0}
!18 = !{i8 0, i8 2}
!19 = !{}
!20 = !{!21, !6, i64 56}
!21 = !{!"_ZTSN3qOS4taskE", !22, i64 0, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !6, i64 64, !11, i64 72, !7, i64 80, !23, i64 96, !15, i64 120, !11, i64 128, !15, i64 136, !15, i64 140, !15, i64 144, !7, i64 148, !24, i64 149}
!22 = !{!"_ZTSN3qOS4nodeE", !6, i64 8, !6, i64 16, !6, i64 24}
!23 = !{!"_ZTSN3qOS5timerE", !11, i64 8, !11, i64 16}
!24 = !{!"_ZTSN3qOS7triggerE", !7, i64 0}
!25 = !{!26, !6, i64 224}
!26 = !{!"_ZTSN3qOS12stateMachineE", !27, i64 0, !6, i64 72, !6, i64 80, !6, i64 88, !6, i64 96, !6, i64 104, !6, i64 112, !31, i64 120, !32, i64 208, !6, i64 224, !6, i64 232}
!27 = !{!"_ZTSN3qOS2sm12stateHandlerE", !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !28, i64 40, !29, i64 42, !30, i64 44, !6, i64 48, !6, i64 56, !6, i64 64}
!28 = !{!"_ZTSN3qOS2sm11historyModeE", !7, i64 0}
!29 = !{!"_ZTSN3qOS2sm6statusE", !7, i64 0}
!30 = !{!"_ZTSN3qOS2sm8signalIDE", !7, i64 0}
!31 = !{!"_ZTSN3qOS2sm5stateE", !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !11, i64 64, !11, i64 72, !6, i64 80}
!32 = !{!"_ZTSN3qOS2sm8signal_tE", !30, i64 0, !6, i64 8}
!33 = !{!26, !6, i64 96}


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

@_ZN3qOS4task8PERIODICE = external local_unnamed_addr constant i32, align 4

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZN3qOS4core3addERNS_4taskEPFvRNS_9taskEventEEhmiNS_9taskStateEPv(ptr noundef nonnull align 8 dereferenceable(800), ptr noundef nonnull align 8 dereferenceable(150), ptr noundef, i8 noundef zeroext, i64 noundef, i32 noundef, i32 noundef, ptr noundef) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef zeroext i1 @_ZN3qOS4core3addERNS_4taskERNS_12stateMachineEhmNS_9taskStateEPv(ptr noundef nonnull align 8 dereferenceable(800) %0, ptr noundef nonnull align 8 dereferenceable(150) %1, ptr noundef nonnull align 8 dereferenceable(240) %2, i8 noundef zeroext %3, i64 noundef %4, i32 noundef %5, ptr noundef %6) local_unnamed_addr #0 align 2 {
  %8 = load i32, ptr @_ZN3qOS4task8PERIODICE, align 4, !tbaa !5
  %9 = tail call noundef zeroext i1 @_ZN3qOS4core3addERNS_4taskEPFvRNS_9taskEventEEhmiNS_9taskStateEPv(ptr noundef nonnull align 8 dereferenceable(800) %0, ptr noundef nonnull align 8 dereferenceable(150) %1, ptr noundef nonnull @_ZL15fsmTaskCallbackRN3qOS9taskEventE, i8 noundef zeroext %3, i64 noundef %4, i32 noundef %8, i32 noundef %5, ptr noundef %6) #2
  br i1 %9, label %10, label %17

10:                                               ; preds = %7
  %11 = getelementptr inbounds i8, ptr %1, i64 56
  store ptr %2, ptr %11, align 8, !tbaa !9
  %12 = getelementptr inbounds i8, ptr %2, i64 224
  store ptr %1, ptr %12, align 8, !tbaa !16
  %13 = getelementptr inbounds i8, ptr %2, i64 96
  %14 = load ptr, ptr %13, align 8, !tbaa !24
  %.not = icmp eq ptr %14, null
  br i1 %.not, label %17, label %15

15:                                               ; preds = %10
  %16 = tail call noundef zeroext i1 @_ZN3qOS4task11attachQueueERNS_5queueENS_13queueLinkModeEm(ptr noundef nonnull align 8 dereferenceable(150) %1, ptr noundef nonnull align 8 dereferenceable(64) %14, i32 noundef 16, i64 noundef 1) #2
  br label %17

17:                                               ; preds = %10, %15, %7
  %.0.in = phi i1 [ %16, %15 ], [ true, %10 ], [ false, %7 ]
  ret i1 %.0.in
}

; Function Attrs: mustprogress nounwind uwtable
declare hidden void @_ZL15fsmTaskCallbackRN3qOS9taskEventE(ptr noundef nonnull align 8 dereferenceable(48)) #0

; Function Attrs: nounwind
declare noundef zeroext i1 @_ZN3qOS4task11attachQueueERNS_5queueENS_13queueLinkModeEm(ptr noundef nonnull align 8 dereferenceable(150), ptr noundef nonnull align 8 dereferenceable(64), i32 noundef, i64 noundef) local_unnamed_addr #1

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 "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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !12, i64 56}
!10 = !{!"_ZTSN3qOS4taskE", !11, i64 0, !12, i64 32, !12, i64 40, !12, i64 48, !12, i64 56, !12, i64 64, !13, i64 72, !7, i64 80, !14, i64 96, !6, i64 120, !13, i64 128, !6, i64 136, !6, i64 140, !6, i64 144, !7, i64 148, !15, i64 149}
!11 = !{!"_ZTSN3qOS4nodeE", !12, i64 8, !12, i64 16, !12, i64 24}
!12 = !{!"any pointer", !7, i64 0}
!13 = !{!"long", !7, i64 0}
!14 = !{!"_ZTSN3qOS5timerE", !13, i64 8, !13, i64 16}
!15 = !{!"_ZTSN3qOS7triggerE", !7, i64 0}
!16 = !{!17, !12, i64 224}
!17 = !{!"_ZTSN3qOS12stateMachineE", !18, i64 0, !12, i64 72, !12, i64 80, !12, i64 88, !12, i64 96, !12, i64 104, !12, i64 112, !22, i64 120, !23, i64 208, !12, i64 224, !12, i64 232}
!18 = !{!"_ZTSN3qOS2sm12stateHandlerE", !12, i64 8, !12, i64 16, !12, i64 24, !12, i64 32, !19, i64 40, !20, i64 42, !21, i64 44, !12, i64 48, !12, i64 56, !12, i64 64}
!19 = !{!"_ZTSN3qOS2sm11historyModeE", !7, i64 0}
!20 = !{!"_ZTSN3qOS2sm6statusE", !7, i64 0}
!21 = !{!"_ZTSN3qOS2sm8signalIDE", !7, i64 0}
!22 = !{!"_ZTSN3qOS2sm5stateE", !12, i64 8, !12, i64 16, !12, i64 24, !12, i64 32, !12, i64 40, !12, i64 48, !12, i64 56, !13, i64 64, !13, i64 72, !12, i64 80}
!23 = !{!"_ZTSN3qOS2sm8signal_tE", !21, i64 0, !12, i64 8}
!24 = !{!17, !12, i64 96}


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