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

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

; 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 void @_ZN3qOS5timer6disarmEv(ptr noundef nonnull align 8 dereferenceable(24)) #1

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef zeroext i1 @_ZN3qOS12stateMachine7installERNS_2sm11timeoutSpecE(ptr noundef nonnull align 8 dereferenceable(240) %0, ptr noundef nonnull align 8 dereferenceable(80) %1) #2 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i64, 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 i64 0, ptr %5, align 8, !tbaa !9
  br label %7

7:                                                ; preds = %18, %2
  %8 = load i64, ptr %5, align 8, !tbaa !9
  %9 = icmp ult i64 %8, 3
  br i1 %9, label %11, label %10

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

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

18:                                               ; preds = %11
  %19 = load i64, ptr %5, align 8, !tbaa !9
  %20 = add i64 %19, 1
  store i64 %20, ptr %5, align 8, !tbaa !9
  br label %7, !llvm.loop !14

21:                                               ; preds = %10
  %22 = load ptr, ptr %4, align 8, !tbaa !5
  %23 = getelementptr inbounds %"class.qOS::stateMachine", ptr %6, i32 0, i32 5
  store ptr %22, ptr %23, align 8, !tbaa !16
  ret i1 true
}

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, !13, i64 0}
!12 = !{!"_ZTSN3qOS2sm11timeoutSpecE", !13, i64 0, !7, i64 8}
!13 = !{!"int", !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = !{!17, !6, i64 104}
!17 = !{!"_ZTSN3qOS12stateMachineE", !18, i64 0, !6, i64 72, !6, i64 80, !6, i64 88, !6, i64 96, !6, i64 104, !6, i64 112, !22, i64 120, !23, i64 208, !6, i64 224, !6, i64 232}
!18 = !{!"_ZTSN3qOS2sm12stateHandlerE", !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !19, i64 40, !20, i64 42, !21, i64 44, !6, i64 48, !6, i64 56, !6, i64 64}
!19 = !{!"_ZTSN3qOS2sm11historyModeE", !7, i64 0}
!20 = !{!"_ZTSN3qOS2sm6statusE", !7, i64 0}
!21 = !{!"_ZTSN3qOS2sm8signalIDE", !7, i64 0}
!22 = !{!"_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}
!23 = !{!"_ZTSN3qOS2sm8signal_tE", !21, i64 0, !6, i64 8}


; 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: nounwind
declare void @_ZN3qOS5timer6disarmEv(ptr noundef nonnull align 8 dereferenceable(24)) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef zeroext i1 @_ZN3qOS12stateMachine7installERNS_2sm11timeoutSpecE(ptr nocapture noundef nonnull writeonly align 8 dereferenceable(240) %0, ptr noundef nonnull align 8 dereferenceable(80) %1) local_unnamed_addr #1 align 2 {
  %3 = getelementptr inbounds i8, ptr %1, i64 8
  tail call void @_ZN3qOS5timer6disarmEv(ptr noundef nonnull align 8 dereferenceable(24) %3) #2
  store i32 0, ptr %1, align 8, !tbaa !5
  %4 = getelementptr inbounds i8, ptr %1, i64 32
  tail call void @_ZN3qOS5timer6disarmEv(ptr noundef nonnull align 8 dereferenceable(24) %4) #2
  store i32 0, ptr %1, align 8, !tbaa !5
  %5 = getelementptr inbounds i8, ptr %1, i64 56
  tail call void @_ZN3qOS5timer6disarmEv(ptr noundef nonnull align 8 dereferenceable(24) %5) #2
  store i32 0, ptr %1, align 8, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %0, i64 104
  store ptr %1, ptr %6, align 8, !tbaa !10
  ret i1 true
}

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


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