; LLVM IR from kmilo17pet/QuarkTS-cpp :: src/fsm.ll (ZN3qOS12stateMachine24tracePathAndRetraceEntryEPPNS_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::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: mustprogress nounwind uwtable
declare dso_local void @_ZN3qOS12stateMachine12stateOnEntryEPNS_2sm5stateE(ptr noundef nonnull align 8 dereferenceable(240), ptr noundef) #1 align 2

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN3qOS12stateMachine24tracePathAndRetraceEntryEPPNS_2sm5stateE(ptr noundef nonnull align 8 dereferenceable(240) %0, ptr noundef %1) #1 align 2 {
  %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) #2
  %7 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr null, ptr %7, align 8, !tbaa !5
  %8 = getelementptr inbounds %"class.qOS::stateMachine", ptr %6, i32 0, i32 2
  %9 = load ptr, ptr %8, align 8, !tbaa !9
  store ptr %9, ptr %5, align 8, !tbaa !5
  br label %10

10:                                               ; preds = %19, %2
  %11 = load ptr, ptr %5, align 8, !tbaa !5
  %12 = getelementptr inbounds %"class.qOS::stateMachine", ptr %6, i32 0, i32 1
  %13 = load ptr, ptr %12, align 8, !tbaa !18
  %14 = icmp ne ptr %11, %13
  br i1 %14, label %15, label %23

15:                                               ; preds = %10
  %16 = load ptr, ptr %5, align 8, !tbaa !5
  %17 = load ptr, ptr %4, align 8, !tbaa !5
  %18 = getelementptr inbounds ptr, ptr %17, i32 1
  store ptr %18, ptr %4, align 8, !tbaa !5
  store ptr %16, ptr %18, align 8, !tbaa !5
  br label %19

19:                                               ; preds = %15
  %20 = load ptr, ptr %5, align 8, !tbaa !5
  %21 = getelementptr inbounds %"class.qOS::sm::state", ptr %20, i32 0, i32 1
  %22 = load ptr, ptr %21, align 8, !tbaa !19
  store ptr %22, ptr %5, align 8, !tbaa !5
  br label %10, !llvm.loop !20

23:                                               ; preds = %10
  br label %24

24:                                               ; preds = %29, %23
  %25 = load ptr, ptr %4, align 8, !tbaa !5
  %26 = getelementptr inbounds ptr, ptr %25, i32 -1
  store ptr %26, ptr %4, align 8, !tbaa !5
  %27 = load ptr, ptr %25, align 8, !tbaa !5
  store ptr %27, ptr %5, align 8, !tbaa !5
  %28 = icmp ne ptr null, %27
  br i1 %28, label %29, label %31

29:                                               ; preds = %24
  %30 = load ptr, ptr %5, align 8, !tbaa !5
  call void @_ZN3qOS12stateMachine12stateOnEntryEPNS_2sm5stateE(ptr noundef nonnull align 8 dereferenceable(240) %6, ptr noundef %30) #2
  br label %24, !llvm.loop !22

31:                                               ; preds = %24
  %32 = getelementptr inbounds %"class.qOS::stateMachine", ptr %6, i32 0, i32 2
  %33 = load ptr, ptr %32, align 8, !tbaa !9
  %34 = getelementptr inbounds %"class.qOS::stateMachine", ptr %6, i32 0, i32 1
  store ptr %33, ptr %34, align 8, !tbaa !18
  %35 = getelementptr inbounds %"class.qOS::stateMachine", ptr %6, i32 0, i32 2
  store ptr null, ptr %35, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #2
  ret void
}

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


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

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN3qOS12stateMachine24tracePathAndRetraceEntryEPPNS_2sm5stateE(ptr noundef nonnull align 8 dereferenceable(240) %0, ptr nocapture noundef %1) local_unnamed_addr #0 align 2 {
  store ptr null, ptr %1, align 8, !tbaa !5
  %3 = getelementptr inbounds i8, ptr %0, i64 80
  %4 = getelementptr inbounds i8, ptr %0, i64 72
  %.011 = load ptr, ptr %3, align 8, !tbaa !5
  %5 = load ptr, ptr %4, align 8, !tbaa !9
  %.not12 = icmp eq ptr %.011, %5
  br i1 %.not12, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %2, %.lr.ph
  %.014 = phi ptr [ %.0, %.lr.ph ], [ %.011, %2 ]
  %.0813 = phi ptr [ %6, %.lr.ph ], [ %1, %2 ]
  %6 = getelementptr inbounds i8, ptr %.0813, i64 8
  store ptr %.014, ptr %6, align 8, !tbaa !5
  %7 = getelementptr inbounds i8, ptr %.014, i64 8
  %.0 = load ptr, ptr %7, align 8, !tbaa !5
  %8 = load ptr, ptr %4, align 8, !tbaa !9
  %.not = icmp eq ptr %.0, %8
  br i1 %.not, label %.lr.ph17, label %.lr.ph, !llvm.loop !18

.lr.ph17:                                         ; preds = %.lr.ph, %.lr.ph17
  %9 = phi ptr [ %11, %.lr.ph17 ], [ %.014, %.lr.ph ]
  %.116 = phi ptr [ %10, %.lr.ph17 ], [ %6, %.lr.ph ]
  %10 = getelementptr inbounds i8, ptr %.116, i64 -8
  tail call void @_ZN3qOS12stateMachine12stateOnEntryEPNS_2sm5stateE(ptr noundef nonnull align 8 dereferenceable(240) %0, ptr noundef nonnull %9) #1
  %11 = load ptr, ptr %10, align 8, !tbaa !5
  %.not10 = icmp eq ptr %11, null
  br i1 %.not10, label %._crit_edge, label %.lr.ph17, !llvm.loop !20

._crit_edge:                                      ; preds = %.lr.ph17, %2
  %12 = load ptr, ptr %3, align 8, !tbaa !21
  store ptr %12, ptr %4, align 8, !tbaa !9
  store ptr null, ptr %3, align 8, !tbaa !21
  ret void
}

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 }

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


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass