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

; 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
define dso_local void @_ZN3qOS12stateMachine11exitUpToLCAEh(ptr noundef nonnull align 8 dereferenceable(240) %0, i8 noundef zeroext %1) #1 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca i8, align 1
  %5 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i8 %1, ptr %4, align 1, !tbaa !9
  %6 = load ptr, ptr %3, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #2
  %7 = getelementptr inbounds %"class.qOS::stateMachine", ptr %6, i32 0, i32 1
  %8 = load ptr, ptr %7, align 8, !tbaa !10
  store ptr %8, ptr %5, align 8, !tbaa !5
  br label %9

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

14:                                               ; preds = %9
  %15 = load ptr, ptr %5, align 8, !tbaa !5
  %16 = call noundef ptr @_ZN3qOS12stateMachine11stateOnExitEPNS_2sm5stateE(ptr noundef nonnull align 8 dereferenceable(240) %6, ptr noundef %15) #2
  store ptr %16, ptr %5, align 8, !tbaa !5
  br label %9, !llvm.loop !20

17:                                               ; preds = %9
  br label %18

18:                                               ; preds = %23, %17
  %19 = load i8, ptr %4, align 1, !tbaa !9
  %20 = add i8 %19, -1
  store i8 %20, ptr %4, align 1, !tbaa !9
  %21 = zext i8 %19 to i32
  %22 = icmp ne i32 0, %21
  br i1 %22, label %23, label %26

23:                                               ; preds = %18
  %24 = load ptr, ptr %5, align 8, !tbaa !5
  %25 = call noundef ptr @_ZN3qOS12stateMachine11stateOnExitEPNS_2sm5stateE(ptr noundef nonnull align 8 dereferenceable(240) %6, ptr noundef %24) #2
  store ptr %25, ptr %5, align 8, !tbaa !5
  br label %18, !llvm.loop !22

26:                                               ; preds = %18
  %27 = load ptr, ptr %5, align 8, !tbaa !5
  %28 = getelementptr inbounds %"class.qOS::stateMachine", ptr %6, i32 0, i32 1
  store ptr %27, ptr %28, align 8, !tbaa !10
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #2
  ret void
}

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

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 = !{!7, !7, i64 0}
!10 = !{!11, !6, i64 72}
!11 = !{!"_ZTSN3qOS12stateMachineE", !12, i64 0, !6, i64 72, !6, i64 80, !6, i64 88, !6, i64 96, !6, i64 104, !6, i64 112, !16, i64 120, !18, i64 208, !6, i64 224, !6, i64 232}
!12 = !{!"_ZTSN3qOS2sm12stateHandlerE", !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !13, i64 40, !14, i64 42, !15, i64 44, !6, i64 48, !6, i64 56, !6, i64 64}
!13 = !{!"_ZTSN3qOS2sm11historyModeE", !7, i64 0}
!14 = !{!"_ZTSN3qOS2sm6statusE", !7, i64 0}
!15 = !{!"_ZTSN3qOS2sm8signalIDE", !7, i64 0}
!16 = !{!"_ZTSN3qOS2sm5stateE", !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !17, i64 64, !17, i64 72, !6, i64 80}
!17 = !{!"long", !7, i64 0}
!18 = !{!"_ZTSN3qOS2sm8signal_tE", !15, i64 0, !6, i64 8}
!19 = !{!11, !6, i64 88}
!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
define dso_local void @_ZN3qOS12stateMachine11exitUpToLCAEh(ptr noundef nonnull align 8 dereferenceable(240) %0, i8 noundef zeroext %1) local_unnamed_addr #0 align 2 {
  %3 = getelementptr inbounds i8, ptr %0, i64 72
  %4 = load ptr, ptr %3, align 8, !tbaa !5
  %5 = getelementptr inbounds i8, ptr %0, i64 88
  %6 = load ptr, ptr %5, align 8, !tbaa !17
  %.not7 = icmp eq ptr %4, %6
  br i1 %.not7, label %.preheader, label %.lr.ph

.preheader:                                       ; preds = %.lr.ph, %2
  %.0.lcssa = phi ptr [ %4, %2 ], [ %7, %.lr.ph ]
  %.not69 = icmp eq i8 %1, 0
  br i1 %.not69, label %._crit_edge, label %.lr.ph12

.lr.ph:                                           ; preds = %2, %.lr.ph
  %.08 = phi ptr [ %7, %.lr.ph ], [ %4, %2 ]
  %7 = tail call noundef ptr @_ZN3qOS12stateMachine11stateOnExitEPNS_2sm5stateE(ptr noundef nonnull align 8 dereferenceable(240) %0, ptr noundef %.08) #1
  %8 = load ptr, ptr %5, align 8, !tbaa !17
  %.not = icmp eq ptr %7, %8
  br i1 %.not, label %.preheader, label %.lr.ph, !llvm.loop !18

.lr.ph12:                                         ; preds = %.preheader, %.lr.ph12
  %.111 = phi ptr [ %10, %.lr.ph12 ], [ %.0.lcssa, %.preheader ]
  %.0510 = phi i8 [ %9, %.lr.ph12 ], [ %1, %.preheader ]
  %9 = add i8 %.0510, -1
  %10 = tail call noundef ptr @_ZN3qOS12stateMachine11stateOnExitEPNS_2sm5stateE(ptr noundef nonnull align 8 dereferenceable(240) %0, ptr noundef %.111) #1
  %.not6 = icmp eq i8 %9, 0
  br i1 %.not6, label %._crit_edge, label %.lr.ph12, !llvm.loop !20

._crit_edge:                                      ; preds = %.lr.ph12, %.preheader
  %.1.lcssa = phi ptr [ %.0.lcssa, %.preheader ], [ %10, %.lr.ph12 ]
  store ptr %.1.lcssa, ptr %3, align 8, !tbaa !5
  ret void
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZN3qOS12stateMachine11stateOnExitEPNS_2sm5stateE(ptr noundef nonnull align 8 dereferenceable(240), ptr noundef) local_unnamed_addr #0 align 2

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, !8, i64 72}
!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 88}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}
!20 = distinct !{!20, !19}


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