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

; 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::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 }
%"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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZN3qOS12stateMachine10sendSignalENS_2sm8signalIDEPvb(ptr noundef nonnull align 8 dereferenceable(240), i32 noundef, ptr noundef, i1 noundef zeroext) #1 align 2

declare i32 @__gxx_personality_v0(...)

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN3qOS12stateMachine19timeoutCheckSignalsEv(ptr noundef nonnull align 8 dereferenceable(240) %0) #1 align 2 personality ptr @__gxx_personality_v0 {
  %2 = alloca ptr, align 8
  %3 = alloca i64, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  %4 = load ptr, ptr %2, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #4
  store i64 0, ptr %3, align 8, !tbaa !9
  br label %5

5:                                                ; preds = %44, %1
  %6 = load i64, ptr %3, align 8, !tbaa !9
  %7 = icmp ult i64 %6, 3
  br i1 %7, label %9, label %8

8:                                                ; preds = %5
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #4
  br label %47

9:                                                ; preds = %5
  %10 = getelementptr inbounds %"class.qOS::stateMachine", ptr %4, i32 0, i32 5
  %11 = load ptr, ptr %10, align 8, !tbaa !11
  %12 = getelementptr inbounds %"class.qOS::sm::timeoutSpec", ptr %11, i32 0, i32 1
  %13 = load i64, ptr %3, align 8, !tbaa !9
  %14 = getelementptr inbounds [3 x %"class.qOS::timer"], ptr %12, i64 0, i64 %13
  %15 = call noundef zeroext i1 @_ZNK3qOS5timer7expiredEv(ptr noundef nonnull align 8 dereferenceable(24) %14) #4
  br i1 %15, label %16, label %43

16:                                               ; preds = %9
  %17 = load i64, ptr %3, align 8, !tbaa !9
  %18 = invoke noundef i32 @_ZN3qOS2sm14SIGNAL_TIMEOUTEm(i64 noundef %17)
          to label %19 unwind label %48

19:                                               ; preds = %16
  %20 = call noundef zeroext i1 @_ZN3qOS12stateMachine10sendSignalENS_2sm8signalIDEPvb(ptr noundef nonnull align 8 dereferenceable(240) %4, i32 noundef %18, ptr noundef null, i1 noundef zeroext false) #4
  %21 = getelementptr inbounds %"class.qOS::stateMachine", ptr %4, i32 0, i32 5
  %22 = load ptr, ptr %21, align 8, !tbaa !11
  %23 = getelementptr inbounds %"class.qOS::sm::timeoutSpec", ptr %22, i32 0, i32 0
  %24 = load i32, ptr %23, align 8, !tbaa !19
  %25 = zext i32 %24 to i64
  %26 = load i64, ptr %3, align 8, !tbaa !9
  %27 = shl i64 1, %26
  %28 = and i64 %25, %27
  %29 = icmp ne i64 0, %28
  br i1 %29, label %30, label %36

30:                                               ; preds = %19
  %31 = getelementptr inbounds %"class.qOS::stateMachine", ptr %4, i32 0, i32 5
  %32 = load ptr, ptr %31, align 8, !tbaa !11
  %33 = getelementptr inbounds %"class.qOS::sm::timeoutSpec", ptr %32, i32 0, i32 1
  %34 = load i64, ptr %3, align 8, !tbaa !9
  %35 = getelementptr inbounds [3 x %"class.qOS::timer"], ptr %33, i64 0, i64 %34
  call void @_ZN3qOS5timer6reloadEv(ptr noundef nonnull align 8 dereferenceable(24) %35) #4
  br label %42

36:                                               ; preds = %19
  %37 = getelementptr inbounds %"class.qOS::stateMachine", ptr %4, i32 0, i32 5
  %38 = load ptr, ptr %37, align 8, !tbaa !11
  %39 = getelementptr inbounds %"class.qOS::sm::timeoutSpec", ptr %38, i32 0, i32 1
  %40 = load i64, ptr %3, align 8, !tbaa !9
  %41 = getelementptr inbounds [3 x %"class.qOS::timer"], ptr %39, i64 0, i64 %40
  call void @_ZN3qOS5timer6disarmEv(ptr noundef nonnull align 8 dereferenceable(24) %41) #4
  br label %42

42:                                               ; preds = %36, %30
  br label %43

43:                                               ; preds = %42, %9
  br label %44

44:                                               ; preds = %43
  %45 = load i64, ptr %3, align 8, !tbaa !9
  %46 = add i64 %45, 1
  store i64 %46, ptr %3, align 8, !tbaa !9
  br label %5, !llvm.loop !22

47:                                               ; preds = %8
  ret void

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

; Function Attrs: nounwind
declare noundef zeroext i1 @_ZNK3qOS5timer7expiredEv(ptr noundef nonnull align 8 dereferenceable(24)) #3

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

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

; Function Attrs: nounwind
declare void @_ZN3qOS5timer6disarmEv(ptr noundef nonnull align 8 dereferenceable(24)) #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 = { 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 #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 }
attributes #5 = { 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, !6, i64 104}
!12 = !{!"_ZTSN3qOS12stateMachineE", !13, i64 0, !6, i64 72, !6, i64 80, !6, i64 88, !6, i64 96, !6, i64 104, !6, i64 112, !17, i64 120, !18, i64 208, !6, i64 224, !6, i64 232}
!13 = !{!"_ZTSN3qOS2sm12stateHandlerE", !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !14, i64 40, !15, i64 42, !16, i64 44, !6, i64 48, !6, i64 56, !6, i64 64}
!14 = !{!"_ZTSN3qOS2sm11historyModeE", !7, i64 0}
!15 = !{!"_ZTSN3qOS2sm6statusE", !7, i64 0}
!16 = !{!"_ZTSN3qOS2sm8signalIDE", !7, i64 0}
!17 = !{!"_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}
!18 = !{!"_ZTSN3qOS2sm8signal_tE", !16, i64 0, !6, i64 8}
!19 = !{!20, !21, i64 0}
!20 = !{!"_ZTSN3qOS2sm11timeoutSpecE", !21, i64 0, !7, i64 8}
!21 = !{!"int", !7, i64 0}
!22 = distinct !{!22, !23}
!23 = !{!"llvm.loop.mustprogress"}


; 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 noundef zeroext i1 @_ZN3qOS12stateMachine10sendSignalENS_2sm8signalIDEPvb(ptr noundef nonnull align 8 dereferenceable(240), i32 noundef, ptr noundef, i1 noundef zeroext) local_unnamed_addr #0 align 2

declare i32 @__gxx_personality_v0(...)

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN3qOS12stateMachine19timeoutCheckSignalsEv(ptr noundef nonnull align 8 dereferenceable(240) %0) local_unnamed_addr #0 align 2 personality ptr @__gxx_personality_v0 {
  %2 = getelementptr inbounds i8, ptr %0, i64 104
  %3 = load ptr, ptr %2, align 8, !tbaa !5
  %4 = getelementptr inbounds i8, ptr %3, i64 8
  %5 = tail call noundef zeroext i1 @_ZNK3qOS5timer7expiredEv(ptr noundef nonnull align 8 dereferenceable(24) %4) #2
  br i1 %5, label %6, label %15

6:                                                ; preds = %1
  %7 = tail call noundef i32 @_ZN3qOS2sm14SIGNAL_TIMEOUTEm(i64 noundef 0)
  %8 = tail call noundef zeroext i1 @_ZN3qOS12stateMachine10sendSignalENS_2sm8signalIDEPvb(ptr noundef nonnull align 8 dereferenceable(240) %0, i32 noundef %7, ptr noundef null, i1 noundef zeroext false) #2
  %9 = load ptr, ptr %2, align 8, !tbaa !5
  %10 = load i32, ptr %9, align 8, !tbaa !17
  %11 = and i32 %10, 1
  %.not = icmp eq i32 %11, 0
  %12 = getelementptr inbounds i8, ptr %9, i64 8
  br i1 %.not, label %14, label %13

13:                                               ; preds = %6
  tail call void @_ZN3qOS5timer6reloadEv(ptr noundef nonnull align 8 dereferenceable(24) %12) #2
  br label %15

14:                                               ; preds = %6
  tail call void @_ZN3qOS5timer6disarmEv(ptr noundef nonnull align 8 dereferenceable(24) %12) #2
  br label %15

15:                                               ; preds = %1, %14, %13
  %16 = load ptr, ptr %2, align 8, !tbaa !5
  %17 = getelementptr inbounds i8, ptr %16, i64 32
  %18 = tail call noundef zeroext i1 @_ZNK3qOS5timer7expiredEv(ptr noundef nonnull align 8 dereferenceable(24) %17) #2
  br i1 %18, label %19, label %28

19:                                               ; preds = %15
  %20 = tail call noundef i32 @_ZN3qOS2sm14SIGNAL_TIMEOUTEm(i64 noundef 1)
  %21 = tail call noundef zeroext i1 @_ZN3qOS12stateMachine10sendSignalENS_2sm8signalIDEPvb(ptr noundef nonnull align 8 dereferenceable(240) %0, i32 noundef %20, ptr noundef null, i1 noundef zeroext false) #2
  %22 = load ptr, ptr %2, align 8, !tbaa !5
  %23 = load i32, ptr %22, align 8, !tbaa !17
  %24 = and i32 %23, 2
  %.not.1 = icmp eq i32 %24, 0
  %25 = getelementptr inbounds i8, ptr %22, i64 32
  br i1 %.not.1, label %27, label %26

26:                                               ; preds = %19
  tail call void @_ZN3qOS5timer6reloadEv(ptr noundef nonnull align 8 dereferenceable(24) %25) #2
  br label %28

27:                                               ; preds = %19
  tail call void @_ZN3qOS5timer6disarmEv(ptr noundef nonnull align 8 dereferenceable(24) %25) #2
  br label %28

28:                                               ; preds = %27, %26, %15
  %29 = load ptr, ptr %2, align 8, !tbaa !5
  %30 = getelementptr inbounds i8, ptr %29, i64 56
  %31 = tail call noundef zeroext i1 @_ZNK3qOS5timer7expiredEv(ptr noundef nonnull align 8 dereferenceable(24) %30) #2
  br i1 %31, label %32, label %41

32:                                               ; preds = %28
  %33 = tail call noundef i32 @_ZN3qOS2sm14SIGNAL_TIMEOUTEm(i64 noundef 2)
  %34 = tail call noundef zeroext i1 @_ZN3qOS12stateMachine10sendSignalENS_2sm8signalIDEPvb(ptr noundef nonnull align 8 dereferenceable(240) %0, i32 noundef %33, ptr noundef null, i1 noundef zeroext false) #2
  %35 = load ptr, ptr %2, align 8, !tbaa !5
  %36 = load i32, ptr %35, align 8, !tbaa !17
  %37 = and i32 %36, 4
  %.not.2 = icmp eq i32 %37, 0
  %38 = getelementptr inbounds i8, ptr %35, i64 56
  br i1 %.not.2, label %40, label %39

39:                                               ; preds = %32
  tail call void @_ZN3qOS5timer6reloadEv(ptr noundef nonnull align 8 dereferenceable(24) %38) #2
  br label %41

40:                                               ; preds = %32
  tail call void @_ZN3qOS5timer6disarmEv(ptr noundef nonnull align 8 dereferenceable(24) %38) #2
  br label %41

41:                                               ; preds = %40, %39, %28
  ret void
}

; Function Attrs: nounwind
declare noundef zeroext i1 @_ZNK3qOS5timer7expiredEv(ptr noundef nonnull align 8 dereferenceable(24)) local_unnamed_addr #1

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

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

; Function Attrs: nounwind
declare void @_ZN3qOS5timer6disarmEv(ptr noundef nonnull align 8 dereferenceable(24)) 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, !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 = !{!18, !19, i64 0}
!18 = !{!"_ZTSN3qOS2sm11timeoutSpecE", !19, i64 0, !9, i64 8}
!19 = !{!"int", !9, i64 0}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LICMPass,LoopRotatePass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass