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

%"class.qOS::sm::state" = type { ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, i64, i64, 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 }
%"struct.qOS::sm::signal_t" = type { i32, 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

declare i32 @__gxx_personality_v0(...)

; Function Attrs: noinline noreturn nounwind uwtable
declare hidden void @__clang_call_terminate(ptr noundef) #1

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef signext i16 @_ZN3qOS12stateMachine21invokeStateActivitiesEPNS_2sm5stateE(ptr noundef nonnull align 8 dereferenceable(240) %0, ptr noundef %1) #2 align 2 personality ptr @__gxx_personality_v0 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  %6 = load ptr, ptr %3, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  store ptr %6, ptr %5, align 8, !tbaa !5
  %7 = load ptr, ptr %5, align 8, !tbaa !5
  %8 = load ptr, ptr %4, align 8, !tbaa !5
  %9 = getelementptr inbounds %"class.qOS::sm::state", ptr %8, i32 0, i32 10
  store ptr %7, ptr %9, align 8, !tbaa !9
  %10 = getelementptr inbounds %"class.qOS::stateMachine", ptr %6, i32 0, i32 6
  %11 = load ptr, ptr %10, align 8, !tbaa !12
  %12 = icmp ne ptr null, %11
  br i1 %12, label %13, label %19

13:                                               ; preds = %2
  %14 = getelementptr inbounds %"class.qOS::sm::stateHandler", ptr %6, i32 0, i32 6
  store i16 -32767, ptr %14, align 2, !tbaa !19
  %15 = getelementptr inbounds %"class.qOS::stateMachine", ptr %6, i32 0, i32 6
  %16 = load ptr, ptr %15, align 8, !tbaa !12
  %17 = load ptr, ptr %5, align 8, !tbaa !5
  invoke void %16(ptr noundef nonnull align 8 dereferenceable(72) %17)
          to label %18 unwind label %47

18:                                               ; preds = %13
  br label %19

19:                                               ; preds = %18, %2
  %20 = getelementptr inbounds %"class.qOS::sm::stateHandler", ptr %6, i32 0, i32 6
  store i16 -32766, ptr %20, align 2, !tbaa !19
  %21 = load ptr, ptr %4, align 8, !tbaa !5
  %22 = load ptr, ptr %5, align 8, !tbaa !5
  %23 = load ptr, ptr %21, align 8, !tbaa !20
  %24 = getelementptr inbounds ptr, ptr %23, i64 0
  %25 = load ptr, ptr %24, align 8
  %26 = invoke noundef signext i16 %25(ptr noundef nonnull align 8 dereferenceable(88) %21, ptr noundef nonnull align 8 dereferenceable(72) %22)
          to label %27 unwind label %47

27:                                               ; preds = %19
  %28 = getelementptr inbounds %"class.qOS::sm::stateHandler", ptr %6, i32 0, i32 6
  store i16 %26, ptr %28, align 2, !tbaa !19
  %29 = getelementptr inbounds %"class.qOS::stateMachine", ptr %6, i32 0, i32 6
  %30 = load ptr, ptr %29, align 8, !tbaa !12
  %31 = icmp ne ptr null, %30
  br i1 %31, label %32, label %44

32:                                               ; preds = %27
  %33 = getelementptr inbounds %"class.qOS::sm::stateHandler", ptr %6, i32 0, i32 6
  %34 = load i16, ptr %33, align 2, !tbaa !19
  %35 = sext i16 %34 to i32
  %36 = icmp slt i32 %35, -32765
  br i1 %36, label %37, label %39

37:                                               ; preds = %32
  %38 = getelementptr inbounds %"class.qOS::sm::stateHandler", ptr %6, i32 0, i32 6
  store i16 -32765, ptr %38, align 2, !tbaa !19
  br label %39

39:                                               ; preds = %37, %32
  %40 = getelementptr inbounds %"class.qOS::stateMachine", ptr %6, i32 0, i32 6
  %41 = load ptr, ptr %40, align 8, !tbaa !12
  %42 = load ptr, ptr %5, align 8, !tbaa !5
  invoke void %41(ptr noundef nonnull align 8 dereferenceable(72) %42)
          to label %43 unwind label %47

43:                                               ; preds = %39
  br label %44

44:                                               ; preds = %43, %27
  %45 = getelementptr inbounds %"class.qOS::sm::stateHandler", ptr %6, i32 0, i32 6
  %46 = load i16, ptr %45, align 2, !tbaa !19
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  ret i16 %46

47:                                               ; preds = %39, %19, %13
  %48 = landingpad { ptr, i32 }
          catch ptr null
  %49 = extractvalue { ptr, i32 } %48, 0
  call void @__clang_call_terminate(ptr %49) #4
  unreachable
}

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


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

declare i32 @__gxx_personality_v0(...)

; Function Attrs: noinline noreturn nounwind uwtable
declare hidden void @__clang_call_terminate(ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef signext i16 @_ZN3qOS12stateMachine21invokeStateActivitiesEPNS_2sm5stateE(ptr noundef nonnull align 8 dereferenceable(240) %0, ptr noundef %1) local_unnamed_addr #1 align 2 personality ptr @__gxx_personality_v0 {
  %3 = getelementptr inbounds i8, ptr %1, i64 80
  store ptr %0, ptr %3, align 8, !tbaa !5
  %4 = getelementptr inbounds i8, ptr %0, i64 112
  %5 = load ptr, ptr %4, align 8, !tbaa !11
  %.not = icmp eq ptr %5, null
  br i1 %.not, label %8, label %6

6:                                                ; preds = %2
  %7 = getelementptr inbounds i8, ptr %0, i64 42
  store i16 -32767, ptr %7, align 2, !tbaa !18
  invoke void %5(ptr noundef nonnull align 8 dereferenceable(72) %0)
          to label %8 unwind label %21

8:                                                ; preds = %6, %2
  %9 = getelementptr inbounds i8, ptr %0, i64 42
  store i16 -32766, ptr %9, align 2, !tbaa !18
  %10 = load ptr, ptr %1, align 8, !tbaa !19
  %11 = load ptr, ptr %10, align 8
  %12 = invoke noundef signext i16 %11(ptr noundef nonnull align 8 dereferenceable(88) %1, ptr noundef nonnull align 8 dereferenceable(72) %0)
          to label %13 unwind label %21

13:                                               ; preds = %8
  store i16 %12, ptr %9, align 2, !tbaa !18
  %14 = load ptr, ptr %4, align 8, !tbaa !11
  %.not7 = icmp eq ptr %14, null
  br i1 %.not7, label %19, label %15

15:                                               ; preds = %13
  %16 = icmp slt i16 %12, -32765
  br i1 %16, label %17, label %18

17:                                               ; preds = %15
  store i16 -32765, ptr %9, align 2, !tbaa !18
  br label %18

18:                                               ; preds = %17, %15
  invoke void %14(ptr noundef nonnull align 8 dereferenceable(72) %0)
          to label %._crit_edge unwind label %21

._crit_edge:                                      ; preds = %18
  %.pre = load i16, ptr %9, align 2, !tbaa !18
  br label %19

19:                                               ; preds = %._crit_edge, %13
  %20 = phi i16 [ %.pre, %._crit_edge ], [ %12, %13 ]
  ret i16 %20

21:                                               ; preds = %18, %8, %6
  %22 = landingpad { ptr, i32 }
          catch ptr null
  %23 = extractvalue { ptr, i32 } %22, 0
  tail call void @__clang_call_terminate(ptr %23) #2
  unreachable
}

attributes #0 = { noinline noreturn nounwind uwtable "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 = { 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 = { noreturn 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 80}
!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 112}
!12 = !{!"_ZTSN3qOS12stateMachineE", !13, i64 0, !7, i64 72, !7, i64 80, !7, i64 88, !7, i64 96, !7, i64 104, !7, i64 112, !6, i64 120, !17, i64 208, !7, i64 224, !7, i64 232}
!13 = !{!"_ZTSN3qOS2sm12stateHandlerE", !7, i64 8, !7, i64 16, !7, i64 24, !7, i64 32, !14, i64 40, !15, i64 42, !16, i64 44, !7, i64 48, !7, i64 56, !7, i64 64}
!14 = !{!"_ZTSN3qOS2sm11historyModeE", !8, i64 0}
!15 = !{!"_ZTSN3qOS2sm6statusE", !8, i64 0}
!16 = !{!"_ZTSN3qOS2sm8signalIDE", !8, i64 0}
!17 = !{!"_ZTSN3qOS2sm8signal_tE", !16, i64 0, !7, i64 8}
!18 = !{!13, !15, i64 42}
!19 = !{!20, !20, i64 0}
!20 = !{!"vtable pointer", !9, i64 0}


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