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

; 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: nounwind
declare noundef zeroext i1 @_ZN3qOS5timer3setEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) #1

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef zeroext i1 @_ZN3qOS12stateMachine10timeoutSetEmm(ptr noundef nonnull align 8 dereferenceable(240) %0, i64 noundef %1, i64 noundef %2) #2 align 2 {
  %4 = alloca ptr, align 8
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  %7 = alloca i8, align 1
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i64 %1, ptr %5, align 8, !tbaa !9
  store i64 %2, ptr %6, align 8, !tbaa !9
  %8 = load ptr, ptr %4, align 8
  call void @llvm.lifetime.start.p0(i64 1, ptr %7) #3
  store i8 0, ptr %7, align 1, !tbaa !11
  %9 = load i64, ptr %5, align 8, !tbaa !9
  %10 = icmp ult i64 %9, 3
  br i1 %10, label %11, label %25

11:                                               ; preds = %3
  %12 = getelementptr inbounds %"class.qOS::stateMachine", ptr %8, i32 0, i32 5
  %13 = load ptr, ptr %12, align 8, !tbaa !13
  %14 = icmp ne ptr null, %13
  br i1 %14, label %15, label %24

15:                                               ; preds = %11
  %16 = getelementptr inbounds %"class.qOS::stateMachine", ptr %8, i32 0, i32 5
  %17 = load ptr, ptr %16, align 8, !tbaa !13
  %18 = getelementptr inbounds %"class.qOS::sm::timeoutSpec", ptr %17, i32 0, i32 1
  %19 = load i64, ptr %5, align 8, !tbaa !9
  %20 = getelementptr inbounds [3 x %"class.qOS::timer"], ptr %18, i64 0, i64 %19
  %21 = load i64, ptr %6, align 8, !tbaa !9
  %22 = call noundef zeroext i1 @_ZN3qOS5timer3setEm(ptr noundef nonnull align 8 dereferenceable(24) %20, i64 noundef %21) #3
  %23 = zext i1 %22 to i8
  store i8 %23, ptr %7, align 1, !tbaa !11
  br label %24

24:                                               ; preds = %15, %11
  br label %25

25:                                               ; preds = %24, %3
  %26 = load i8, ptr %7, align 1, !tbaa !11, !range !21, !noundef !22
  %27 = trunc i8 %26 to i1
  call void @llvm.lifetime.end.p0(i64 1, ptr %7) #3
  ret i1 %27
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 }

!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 = !{i8 0, i8 2}
!22 = !{}


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

%"class.qOS::timer" = type { ptr, i64, i64 }

; Function Attrs: nounwind
declare noundef zeroext i1 @_ZN3qOS5timer3setEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef zeroext i1 @_ZN3qOS12stateMachine10timeoutSetEmm(ptr nocapture noundef nonnull readonly align 8 dereferenceable(240) %0, i64 noundef %1, i64 noundef %2) local_unnamed_addr #1 align 2 {
  %4 = icmp ult i64 %1, 3
  br i1 %4, label %5, label %12

5:                                                ; preds = %3
  %6 = getelementptr inbounds i8, ptr %0, i64 104
  %7 = load ptr, ptr %6, align 8, !tbaa !5
  %.not = icmp eq ptr %7, null
  br i1 %.not, label %12, label %8

8:                                                ; preds = %5
  %9 = getelementptr inbounds i8, ptr %7, i64 8
  %10 = getelementptr inbounds [3 x %"class.qOS::timer"], ptr %9, i64 0, i64 %1
  %11 = tail call noundef zeroext i1 @_ZN3qOS5timer3setEm(ptr noundef nonnull align 8 dereferenceable(24) %10, i64 noundef %2) #2
  br label %12

12:                                               ; preds = %5, %8, %3
  %.0 = phi i1 [ %11, %8 ], [ false, %5 ], [ false, %3 ]
  ret i1 %.0
}

attributes #0 = { 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 #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 = { 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}


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