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

; 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 }
%"class.qOS::sm::timeoutSpec" = type { i32, [3 x %"class.qOS::timer"] }
%"class.qOS::timer" = type { ptr, i64, i64 }

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZN3qOS2sm14SIGNAL_TIMEOUTEm(i64 noundef) #4

; Function Attrs: nounwind
declare void @_ZN3qOS5timer6disarmEv(ptr noundef nonnull align 8 dereferenceable(24)) #3

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

12:                                               ; preds = %2
  %13 = load i64, ptr %4, align 8, !tbaa !9
  %14 = icmp ult i64 %13, 3
  br i1 %14, label %15, label %46

15:                                               ; preds = %12
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #5
  call void @llvm.lifetime.start.p0(i64 16, ptr %7) #5
  call void @_ZN3qOS2sm8signal_tC2Ev(ptr noundef nonnull align 8 dereferenceable(16) %7) #5
  %16 = getelementptr inbounds %"class.qOS::stateMachine", ptr %8, i32 0, i32 4
  %17 = load ptr, ptr %16, align 8, !tbaa !21
  %18 = call noundef i64 @_ZNK3qOS5queue5countEv(ptr noundef nonnull align 8 dereferenceable(64) %17) #5
  store i64 %18, ptr %6, align 8, !tbaa !9
  br label %19

19:                                               ; preds = %39, %15
  %20 = load i64, ptr %6, align 8, !tbaa !9
  %21 = add i64 %20, -1
  store i64 %21, ptr %6, align 8, !tbaa !9
  %22 = icmp ne i64 0, %20
  br i1 %22, label %23, label %40

23:                                               ; preds = %19
  %24 = getelementptr inbounds %"class.qOS::stateMachine", ptr %8, i32 0, i32 4
  %25 = load ptr, ptr %24, align 8, !tbaa !21
  %26 = call noundef zeroext i1 @_ZN3qOS5queue7receiveEPv(ptr noundef nonnull align 8 dereferenceable(64) %25, ptr noundef %7) #5
  br i1 %26, label %27, label %39

27:                                               ; preds = %23
  %28 = getelementptr inbounds %"struct.qOS::sm::signal_t", ptr %7, i32 0, i32 0
  %29 = load i32, ptr %28, align 8, !tbaa !22
  %30 = load i64, ptr %4, align 8, !tbaa !9
  %31 = invoke noundef i32 @_ZN3qOS2sm14SIGNAL_TIMEOUTEm(i64 noundef %30)
          to label %32 unwind label %49

32:                                               ; preds = %27
  %33 = icmp ne i32 %29, %31
  br i1 %33, label %34, label %38

34:                                               ; preds = %32
  %35 = getelementptr inbounds %"class.qOS::stateMachine", ptr %8, i32 0, i32 4
  %36 = load ptr, ptr %35, align 8, !tbaa !21
  %37 = call noundef zeroext i1 @_ZN3qOS5queue4sendEPvNS_13queueSendModeE(ptr noundef nonnull align 8 dereferenceable(64) %36, ptr noundef %7, i32 noundef 0) #5
  br label %38

38:                                               ; preds = %34, %32
  br label %39

39:                                               ; preds = %38, %23
  br label %19, !llvm.loop !23

40:                                               ; preds = %19
  %41 = getelementptr inbounds %"class.qOS::stateMachine", ptr %8, i32 0, i32 5
  %42 = load ptr, ptr %41, align 8, !tbaa !13
  %43 = getelementptr inbounds %"class.qOS::sm::timeoutSpec", ptr %42, i32 0, i32 1
  %44 = load i64, ptr %4, align 8, !tbaa !9
  %45 = getelementptr inbounds [3 x %"class.qOS::timer"], ptr %43, i64 0, i64 %44
  call void @_ZN3qOS5timer6disarmEv(ptr noundef nonnull align 8 dereferenceable(24) %45) #5
  store i8 1, ptr %5, align 1, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 16, ptr %7) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #5
  br label %46

46:                                               ; preds = %40, %12, %2
  %47 = load i8, ptr %5, align 1, !tbaa !11, !range !25, !noundef !26
  %48 = trunc i8 %47 to i1
  call void @llvm.lifetime.end.p0(i64 1, ptr %5) #5
  ret i1 %48

49:                                               ; preds = %27
  %50 = landingpad { ptr, i32 }
          catch ptr null
  %51 = extractvalue { ptr, i32 } %50, 0
  call void @__clang_call_terminate(ptr %51) #6
  unreachable
}

; Function Attrs: nounwind
declare noundef i64 @_ZNK3qOS5queue5countEv(ptr noundef nonnull align 8 dereferenceable(64)) #3

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

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 = { 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 = { 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 #5 = { nounwind }
attributes #6 = { 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, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"bool", !7, i64 0}
!13 = !{!14, !6, i64 104}
!14 = !{!"_ZTSN3qOS12stateMachineE", !15, i64 0, !6, i64 72, !6, i64 80, !6, i64 88, !6, i64 96, !6, i64 104, !6, i64 112, !19, 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, !18, i64 44, !6, i64 48, !6, i64 56, !6, i64 64}
!16 = !{!"_ZTSN3qOS2sm11historyModeE", !7, i64 0}
!17 = !{!"_ZTSN3qOS2sm6statusE", !7, i64 0}
!18 = !{!"_ZTSN3qOS2sm8signalIDE", !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, !10, i64 64, !10, i64 72, !6, i64 80}
!20 = !{!"_ZTSN3qOS2sm8signal_tE", !18, i64 0, !6, i64 8}
!21 = !{!14, !6, i64 96}
!22 = !{!20, !18, i64 0}
!23 = distinct !{!23, !24}
!24 = !{!"llvm.loop.mustprogress"}
!25 = !{i8 0, i8 2}
!26 = !{}


; 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 }
%"class.qOS::timer" = type { ptr, i64, i64 }

; 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

declare i32 @__gxx_personality_v0(...)

; 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: nounwind
declare noundef zeroext i1 @_ZN3qOS5queue4sendEPvNS_13queueSendModeE(ptr noundef nonnull align 8 dereferenceable(64), ptr noundef, i32 noundef) local_unnamed_addr #2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZN3qOS2sm14SIGNAL_TIMEOUTEm(i64 noundef) local_unnamed_addr #3

; Function Attrs: nounwind
declare void @_ZN3qOS5timer6disarmEv(ptr noundef nonnull align 8 dereferenceable(24)) local_unnamed_addr #2

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef zeroext i1 @_ZN3qOS12stateMachine11timeoutStopEm(ptr nocapture noundef nonnull readonly align 8 dereferenceable(240) %0, i64 noundef %1) local_unnamed_addr #3 align 2 personality ptr @__gxx_personality_v0 {
  %3 = alloca %"struct.qOS::sm::signal_t", align 8
  %4 = getelementptr inbounds i8, ptr %0, i64 104
  %5 = load ptr, ptr %4, align 8, !tbaa !5
  %6 = icmp ne ptr %5, null
  %7 = icmp ult i64 %1, 3
  %or.cond = and i1 %7, %6
  br i1 %or.cond, label %8, label %25

8:                                                ; preds = %2
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %3) #4
  call void @_ZN3qOS2sm8signal_tC2Ev(ptr noundef nonnull align 8 dereferenceable(16) %3) #4
  %9 = getelementptr inbounds i8, ptr %0, i64 96
  %10 = load ptr, ptr %9, align 8, !tbaa !17
  %11 = call noundef i64 @_ZNK3qOS5queue5countEv(ptr noundef nonnull align 8 dereferenceable(64) %10) #4
  %.not9 = icmp eq i64 %11, 0
  br i1 %.not9, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %8, %21
  %.in = phi i64 [ %12, %21 ], [ %11, %8 ]
  %12 = add i64 %.in, -1
  %13 = load ptr, ptr %9, align 8, !tbaa !17
  %14 = call noundef zeroext i1 @_ZN3qOS5queue7receiveEPv(ptr noundef nonnull align 8 dereferenceable(64) %13, ptr noundef nonnull %3) #4
  br i1 %14, label %15, label %21

15:                                               ; preds = %.lr.ph
  %16 = load i32, ptr %3, align 8, !tbaa !18
  %17 = call noundef i32 @_ZN3qOS2sm14SIGNAL_TIMEOUTEm(i64 noundef %1)
  %.not8 = icmp eq i32 %16, %17
  br i1 %.not8, label %21, label %18

18:                                               ; preds = %15
  %19 = load ptr, ptr %9, align 8, !tbaa !17
  %20 = call noundef zeroext i1 @_ZN3qOS5queue4sendEPvNS_13queueSendModeE(ptr noundef nonnull align 8 dereferenceable(64) %19, ptr noundef nonnull %3, i32 noundef 0) #4
  br label %21

21:                                               ; preds = %15, %18, %.lr.ph
  %.not = icmp eq i64 %12, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !19

._crit_edge:                                      ; preds = %21, %8
  %22 = load ptr, ptr %4, align 8, !tbaa !5
  %23 = getelementptr inbounds i8, ptr %22, i64 8
  %24 = getelementptr inbounds [3 x %"class.qOS::timer"], ptr %23, i64 0, i64 %1
  call void @_ZN3qOS5timer6disarmEv(ptr noundef nonnull align 8 dereferenceable(24) %24) #4
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %3) #4
  br label %25

25:                                               ; preds = %._crit_edge, %2
  ret i1 %or.cond
}

; Function Attrs: nounwind
declare noundef i64 @_ZNK3qOS5queue5countEv(ptr noundef nonnull align 8 dereferenceable(64)) local_unnamed_addr #2

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

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 = { 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 = { 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 #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 104}
!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 = !{!6, !8, i64 96}
!18 = !{!16, !13, i64 0}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass