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

; 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::state" = type { ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, i64, i64, ptr }
%"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 }
%"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 @_ZN3qOS12stateMachine10transitionEPNS_2sm5stateENS1_11historyModeE(ptr noundef nonnull align 8 dereferenceable(240) %0, ptr noundef %1, i8 noundef zeroext %2) #1 align 2 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i8, align 1
  %7 = alloca ptr, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store i8 %2, ptr %6, align 1, !tbaa !9
  %8 = load ptr, ptr %4, align 8
  %9 = load ptr, ptr %5, align 8, !tbaa !5
  %10 = call noundef zeroext i8 @_ZNK3qOS12stateMachine11levelsToLCAEPNS_2sm5stateE(ptr noundef nonnull align 8 dereferenceable(240) %8, ptr noundef %9) #2
  call void @_ZN3qOS12stateMachine11exitUpToLCAEh(ptr noundef nonnull align 8 dereferenceable(240) %8, i8 noundef zeroext %10) #2
  %11 = load i8, ptr %6, align 1, !tbaa !9
  %12 = zext i8 %11 to i32
  %13 = icmp eq i32 0, %12
  br i1 %13, label %14, label %20

14:                                               ; preds = %3
  %15 = load ptr, ptr %5, align 8, !tbaa !5
  %16 = getelementptr inbounds %"class.qOS::sm::state", ptr %15, i32 0, i32 3
  %17 = load ptr, ptr %16, align 8, !tbaa !11
  %18 = load ptr, ptr %5, align 8, !tbaa !5
  %19 = getelementptr inbounds %"class.qOS::sm::state", ptr %18, i32 0, i32 2
  store ptr %17, ptr %19, align 8, !tbaa !14
  br label %41

20:                                               ; preds = %3
  %21 = load i8, ptr %6, align 1, !tbaa !9
  %22 = zext i8 %21 to i32
  %23 = icmp eq i32 1, %22
  br i1 %23, label %24, label %39

24:                                               ; preds = %20
  %25 = load ptr, ptr %5, align 8, !tbaa !5
  %26 = getelementptr inbounds %"class.qOS::sm::state", ptr %25, i32 0, i32 2
  %27 = load ptr, ptr %26, align 8, !tbaa !14
  %28 = icmp ne ptr null, %27
  br i1 %28, label %29, label %38

29:                                               ; preds = %24
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #2
  %30 = load ptr, ptr %5, align 8, !tbaa !5
  %31 = getelementptr inbounds %"class.qOS::sm::state", ptr %30, i32 0, i32 2
  %32 = load ptr, ptr %31, align 8, !tbaa !14
  store ptr %32, ptr %7, align 8, !tbaa !5
  %33 = load ptr, ptr %7, align 8, !tbaa !5
  %34 = getelementptr inbounds %"class.qOS::sm::state", ptr %33, i32 0, i32 3
  %35 = load ptr, ptr %34, align 8, !tbaa !11
  %36 = load ptr, ptr %7, align 8, !tbaa !5
  %37 = getelementptr inbounds %"class.qOS::sm::state", ptr %36, i32 0, i32 2
  store ptr %35, ptr %37, align 8, !tbaa !14
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #2
  br label %38

38:                                               ; preds = %29, %24
  br label %40

39:                                               ; preds = %20
  br label %40

40:                                               ; preds = %39, %38
  br label %41

41:                                               ; preds = %40, %14
  %42 = load ptr, ptr %5, align 8, !tbaa !5
  %43 = getelementptr inbounds %"class.qOS::stateMachine", ptr %8, i32 0, i32 2
  store ptr %42, ptr %43, align 8, !tbaa !15
  ret void
}

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i8 @_ZNK3qOS12stateMachine11levelsToLCAEPNS_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 = !{!10, !10, i64 0}
!10 = !{!"_ZTSN3qOS2sm11historyModeE", !7, i64 0}
!11 = !{!12, !6, i64 24}
!12 = !{!"_ZTSN3qOS2sm5stateE", !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !13, i64 64, !13, i64 72, !6, i64 80}
!13 = !{!"long", !7, i64 0}
!14 = !{!12, !6, i64 16}
!15 = !{!16, !6, i64 80}
!16 = !{!"_ZTSN3qOS12stateMachineE", !17, i64 0, !6, i64 72, !6, i64 80, !6, i64 88, !6, i64 96, !6, i64 104, !6, i64 112, !12, i64 120, !20, i64 208, !6, i64 224, !6, i64 232}
!17 = !{!"_ZTSN3qOS2sm12stateHandlerE", !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !10, i64 40, !18, i64 42, !19, i64 44, !6, i64 48, !6, i64 56, !6, i64 64}
!18 = !{!"_ZTSN3qOS2sm6statusE", !7, i64 0}
!19 = !{!"_ZTSN3qOS2sm8signalIDE", !7, i64 0}
!20 = !{!"_ZTSN3qOS2sm8signal_tE", !19, 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: mustprogress nounwind uwtable
define dso_local void @_ZN3qOS12stateMachine10transitionEPNS_2sm5stateENS1_11historyModeE(ptr noundef nonnull align 8 dereferenceable(240) %0, ptr noundef %1, i8 noundef zeroext %2) local_unnamed_addr #0 align 2 {
  %4 = tail call noundef zeroext i8 @_ZNK3qOS12stateMachine11levelsToLCAEPNS_2sm5stateE(ptr noundef nonnull align 8 dereferenceable(240) %0, ptr noundef %1) #1
  tail call void @_ZN3qOS12stateMachine11exitUpToLCAEh(ptr noundef nonnull align 8 dereferenceable(240) %0, i8 noundef zeroext %4) #1
  switch i8 %2, label %11 [
    i8 0, label %.sink.split
    i8 1, label %5
  ]

5:                                                ; preds = %3
  %6 = getelementptr inbounds i8, ptr %1, i64 16
  %7 = load ptr, ptr %6, align 8, !tbaa !5
  %.not = icmp eq ptr %7, null
  br i1 %.not, label %11, label %.sink.split

.sink.split:                                      ; preds = %5, %3
  %.sink = phi ptr [ %1, %3 ], [ %7, %5 ]
  %8 = getelementptr inbounds i8, ptr %.sink, i64 24
  %9 = load ptr, ptr %8, align 8, !tbaa !11
  %10 = getelementptr inbounds i8, ptr %.sink, i64 16
  store ptr %9, ptr %10, align 8, !tbaa !5
  br label %11

11:                                               ; preds = %.sink.split, %3, %5
  %12 = getelementptr inbounds i8, ptr %0, i64 80
  store ptr %1, ptr %12, align 8, !tbaa !12
  ret void
}

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i8 @_ZNK3qOS12stateMachine11levelsToLCAEPNS_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, !7, i64 16}
!6 = !{!"_ZTSN3qOS2sm5stateE", !7, i64 8, !7, i64 16, !7, i64 24, !7, i64 32, !7, i64 40, !7, i64 48, !7, i64 56, !10, i64 64, !10, i64 72, !7, i64 80}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"long", !8, i64 0}
!11 = !{!6, !7, i64 24}
!12 = !{!13, !7, i64 80}
!13 = !{!"_ZTSN3qOS12stateMachineE", !14, i64 0, !7, i64 72, !7, i64 80, !7, i64 88, !7, i64 96, !7, i64 104, !7, i64 112, !6, i64 120, !18, i64 208, !7, i64 224, !7, i64 232}
!14 = !{!"_ZTSN3qOS2sm12stateHandlerE", !7, i64 8, !7, i64 16, !7, i64 24, !7, i64 32, !15, i64 40, !16, i64 42, !17, i64 44, !7, i64 48, !7, i64 56, !7, i64 64}
!15 = !{!"_ZTSN3qOS2sm11historyModeE", !8, i64 0}
!16 = !{!"_ZTSN3qOS2sm6statusE", !8, i64 0}
!17 = !{!"_ZTSN3qOS2sm8signalIDE", !8, i64 0}
!18 = !{!"_ZTSN3qOS2sm8signal_tE", !17, i64 0, !7, i64 8}


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