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

; 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 }
%"struct.qOS::sm::transition" = type { i32, ptr, ptr, i8, ptr }
%"class.qOS::sm::stateHandler" = type { ptr, ptr, ptr, ptr, ptr, i8, i16, i32, ptr, ptr, 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 @_ZNK3qOS2sm5state20sweepTransitionTableERNS0_12stateHandlerE(ptr noundef nonnull align 8 dereferenceable(88) %0, ptr noundef nonnull align 8 dereferenceable(72) %1) #1 align 2 personality ptr @__gxx_personality_v0 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i64, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i64, align 8
  %8 = alloca i32, align 4
  %9 = alloca i8, align 1
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  %10 = load ptr, ptr %3, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  %11 = getelementptr inbounds %"class.qOS::sm::state", ptr %10, i32 0, i32 8
  %12 = load i64, ptr %11, align 8, !tbaa !9
  store i64 %12, ptr %5, align 8, !tbaa !12
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  store i64 0, ptr %7, align 8, !tbaa !12
  br label %13

13:                                               ; preds = %89, %2
  %14 = load i64, ptr %7, align 8, !tbaa !12
  %15 = load i64, ptr %5, align 8, !tbaa !12
  %16 = icmp ult i64 %14, %15
  br i1 %16, label %18, label %17

17:                                               ; preds = %13
  store i32 2, ptr %8, align 4
  br label %92

18:                                               ; preds = %13
  %19 = getelementptr inbounds %"class.qOS::sm::state", ptr %10, i32 0, i32 6
  %20 = load ptr, ptr %19, align 8, !tbaa !13
  %21 = load i64, ptr %7, align 8, !tbaa !12
  %22 = getelementptr inbounds %"struct.qOS::sm::transition", ptr %20, i64 %21
  store ptr %22, ptr %6, align 8, !tbaa !5
  %23 = load ptr, ptr %4, align 8, !tbaa !5
  %24 = getelementptr inbounds %"class.qOS::sm::stateHandler", ptr %23, i32 0, i32 7
  %25 = load i32, ptr %24, align 4, !tbaa !14
  %26 = icmp uge i32 %25, -7
  br i1 %26, label %27, label %35

27:                                               ; preds = %18
  %28 = load ptr, ptr %4, align 8, !tbaa !5
  %29 = getelementptr inbounds %"class.qOS::sm::stateHandler", ptr %28, i32 0, i32 7
  %30 = load i32, ptr %29, align 4, !tbaa !14
  %31 = icmp ule i32 %30, -5
  br i1 %31, label %32, label %35

32:                                               ; preds = %27
  %33 = load ptr, ptr %4, align 8, !tbaa !5
  %34 = getelementptr inbounds %"class.qOS::sm::stateHandler", ptr %33, i32 0, i32 8
  store ptr null, ptr %34, align 8, !tbaa !19
  br label %35

35:                                               ; preds = %32, %27, %18
  %36 = load ptr, ptr %4, align 8, !tbaa !5
  %37 = getelementptr inbounds %"class.qOS::sm::stateHandler", ptr %36, i32 0, i32 7
  %38 = load i32, ptr %37, align 4, !tbaa !14
  %39 = load ptr, ptr %6, align 8, !tbaa !5
  %40 = getelementptr inbounds %"struct.qOS::sm::transition", ptr %39, i32 0, i32 0
  %41 = load i32, ptr %40, align 8, !tbaa !20
  %42 = icmp eq i32 %38, %41
  br i1 %42, label %43, label %88

43:                                               ; preds = %35
  %44 = load ptr, ptr %4, align 8, !tbaa !5
  %45 = getelementptr inbounds %"class.qOS::sm::stateHandler", ptr %44, i32 0, i32 8
  %46 = load ptr, ptr %45, align 8, !tbaa !19
  %47 = load ptr, ptr %6, align 8, !tbaa !5
  %48 = getelementptr inbounds %"struct.qOS::sm::transition", ptr %47, i32 0, i32 4
  %49 = load ptr, ptr %48, align 8, !tbaa !22
  %50 = icmp eq ptr %46, %49
  br i1 %50, label %51, label %88

51:                                               ; preds = %43
  call void @llvm.lifetime.start.p0(i64 1, ptr %9) #3
  store i8 1, ptr %9, align 1, !tbaa !23
  %52 = load ptr, ptr %6, align 8, !tbaa !5
  %53 = getelementptr inbounds %"struct.qOS::sm::transition", ptr %52, i32 0, i32 1
  %54 = load ptr, ptr %53, align 8, !tbaa !25
  %55 = icmp ne ptr null, %54
  br i1 %55, label %56, label %64

56:                                               ; preds = %51
  %57 = load ptr, ptr %6, align 8, !tbaa !5
  %58 = getelementptr inbounds %"struct.qOS::sm::transition", ptr %57, i32 0, i32 1
  %59 = load ptr, ptr %58, align 8, !tbaa !25
  %60 = load ptr, ptr %4, align 8, !tbaa !5
  %61 = invoke noundef zeroext i1 %59(ptr noundef nonnull align 8 dereferenceable(72) %60)
          to label %62 unwind label %94

62:                                               ; preds = %56
  %63 = zext i1 %61 to i8
  store i8 %63, ptr %9, align 1, !tbaa !23
  br label %64

64:                                               ; preds = %62, %51
  %65 = load i8, ptr %9, align 1, !tbaa !23, !range !26, !noundef !27
  %66 = trunc i8 %65 to i1
  br i1 %66, label %67, label %84

67:                                               ; preds = %64
  %68 = load ptr, ptr %6, align 8, !tbaa !5
  %69 = getelementptr inbounds %"struct.qOS::sm::transition", ptr %68, i32 0, i32 2
  %70 = load ptr, ptr %69, align 8, !tbaa !28
  %71 = icmp ne ptr null, %70
  br i1 %71, label %72, label %83

72:                                               ; preds = %67
  %73 = load ptr, ptr %6, align 8, !tbaa !5
  %74 = getelementptr inbounds %"struct.qOS::sm::transition", ptr %73, i32 0, i32 2
  %75 = load ptr, ptr %74, align 8, !tbaa !28
  %76 = load ptr, ptr %4, align 8, !tbaa !5
  %77 = getelementptr inbounds %"class.qOS::sm::stateHandler", ptr %76, i32 0, i32 2
  store ptr %75, ptr %77, align 8, !tbaa !29
  %78 = load ptr, ptr %6, align 8, !tbaa !5
  %79 = getelementptr inbounds %"struct.qOS::sm::transition", ptr %78, i32 0, i32 3
  %80 = load i8, ptr %79, align 8, !tbaa !30
  %81 = load ptr, ptr %4, align 8, !tbaa !5
  %82 = getelementptr inbounds %"class.qOS::sm::stateHandler", ptr %81, i32 0, i32 5
  store i8 %80, ptr %82, align 8, !tbaa !31
  store i32 2, ptr %8, align 4
  br label %85

83:                                               ; preds = %67
  br label %84

84:                                               ; preds = %83, %64
  store i32 0, ptr %8, align 4
  br label %85

85:                                               ; preds = %84, %72
  call void @llvm.lifetime.end.p0(i64 1, ptr %9) #3
  %86 = load i32, ptr %8, align 4
  switch i32 %86, label %92 [
    i32 0, label %87
  ]

87:                                               ; preds = %85
  br label %88

88:                                               ; preds = %87, %43, %35
  br label %89

89:                                               ; preds = %88
  %90 = load i64, ptr %7, align 8, !tbaa !12
  %91 = add i64 %90, 1
  store i64 %91, ptr %7, align 8, !tbaa !12
  br label %13, !llvm.loop !32

92:                                               ; preds = %85, %17
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  br label %93

93:                                               ; preds = %92
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  ret void

94:                                               ; preds = %56
  %95 = landingpad { ptr, i32 }
          catch ptr null
  %96 = extractvalue { ptr, i32 } %95, 0
  call void @__clang_call_terminate(ptr %96) #4
  unreachable
}

declare i32 @__gxx_personality_v0(...)

; Function Attrs: noinline noreturn nounwind uwtable
declare hidden void @__clang_call_terminate(ptr noundef) #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 = { noinline noreturn nounwind uwtable "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 }
attributes #4 = { noreturn 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, !11, i64 64}
!10 = !{!"_ZTSN3qOS2sm5stateE", !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !11, i64 64, !11, i64 72, !6, i64 80}
!11 = !{!"long", !7, i64 0}
!12 = !{!11, !11, i64 0}
!13 = !{!10, !6, i64 48}
!14 = !{!15, !18, i64 44}
!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 = !{!15, !6, i64 48}
!20 = !{!21, !18, i64 0}
!21 = !{!"_ZTSN3qOS2sm10transitionE", !18, i64 0, !6, i64 8, !6, i64 16, !16, i64 24, !6, i64 32}
!22 = !{!21, !6, i64 32}
!23 = !{!24, !24, i64 0}
!24 = !{!"bool", !7, i64 0}
!25 = !{!21, !6, i64 8}
!26 = !{i8 0, i8 2}
!27 = !{}
!28 = !{!21, !6, i64 16}
!29 = !{!15, !6, i64 16}
!30 = !{!21, !16, i64 24}
!31 = !{!15, !16, i64 40}
!32 = distinct !{!32, !33}
!33 = !{!"llvm.loop.mustprogress"}


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

%"struct.qOS::sm::transition" = type { i32, ptr, ptr, i8, ptr }

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZNK3qOS2sm5state20sweepTransitionTableERNS0_12stateHandlerE(ptr nocapture noundef nonnull readonly align 8 dereferenceable(88) %0, ptr noundef nonnull align 8 dereferenceable(72) %1) local_unnamed_addr #0 align 2 personality ptr @__gxx_personality_v0 {
  %3 = getelementptr inbounds i8, ptr %0, i64 64
  %4 = load i64, ptr %3, align 8, !tbaa !5
  %.not32 = icmp eq i64 %4, 0
  br i1 %.not32, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %2
  %5 = getelementptr inbounds i8, ptr %0, i64 48
  %6 = getelementptr inbounds i8, ptr %1, i64 44
  %7 = getelementptr inbounds i8, ptr %1, i64 48
  br label %8

8:                                                ; preds = %.lr.ph, %34
  %.02231 = phi i64 [ 0, %.lr.ph ], [ %35, %34 ]
  %9 = load ptr, ptr %5, align 8, !tbaa !11
  %10 = getelementptr inbounds %"struct.qOS::sm::transition", ptr %9, i64 %.02231
  %11 = load i32, ptr %6, align 4, !tbaa !12
  %12 = add i32 %11, 7
  %or.cond = icmp ult i32 %12, 3
  br i1 %or.cond, label %13, label %14

13:                                               ; preds = %8
  store ptr null, ptr %7, align 8, !tbaa !17
  br label %14

14:                                               ; preds = %13, %8
  %15 = load i32, ptr %10, align 8, !tbaa !18
  %16 = icmp eq i32 %11, %15
  br i1 %16, label %17, label %34

17:                                               ; preds = %14
  %18 = load ptr, ptr %7, align 8, !tbaa !17
  %19 = getelementptr inbounds i8, ptr %10, i64 32
  %20 = load ptr, ptr %19, align 8, !tbaa !20
  %21 = icmp eq ptr %18, %20
  br i1 %21, label %22, label %34

22:                                               ; preds = %17
  %23 = getelementptr inbounds i8, ptr %10, i64 8
  %24 = load ptr, ptr %23, align 8, !tbaa !21
  %.not = icmp eq ptr %24, null
  br i1 %.not, label %.critedge, label %25

25:                                               ; preds = %22
  %26 = invoke noundef zeroext i1 %24(ptr noundef nonnull align 8 dereferenceable(72) %1)
          to label %27 unwind label %36

27:                                               ; preds = %25
  br i1 %26, label %.critedge, label %34

.critedge:                                        ; preds = %22, %27
  %28 = getelementptr inbounds i8, ptr %10, i64 16
  %29 = load ptr, ptr %28, align 8, !tbaa !22
  %.not26 = icmp eq ptr %29, null
  br i1 %.not26, label %34, label %.critedge28

.critedge28:                                      ; preds = %.critedge
  %30 = getelementptr inbounds i8, ptr %1, i64 16
  store ptr %29, ptr %30, align 8, !tbaa !23
  %31 = getelementptr inbounds i8, ptr %10, i64 24
  %32 = load i8, ptr %31, align 8, !tbaa !24
  %33 = getelementptr inbounds i8, ptr %1, i64 40
  store i8 %32, ptr %33, align 8, !tbaa !25
  br label %.loopexit

34:                                               ; preds = %.critedge, %27, %14, %17
  %35 = add nuw i64 %.02231, 1
  %exitcond.not = icmp eq i64 %35, %4
  br i1 %exitcond.not, label %.loopexit, label %8, !llvm.loop !26

.loopexit:                                        ; preds = %34, %2, %.critedge28
  ret void

36:                                               ; preds = %25
  %37 = landingpad { ptr, i32 }
          catch ptr null
  %38 = extractvalue { ptr, i32 } %37, 0
  tail call void @__clang_call_terminate(ptr %38) #2
  unreachable
}

declare i32 @__gxx_personality_v0(...)

; Function Attrs: noinline noreturn nounwind uwtable
declare hidden void @__clang_call_terminate(ptr noundef) local_unnamed_addr #1

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 = { noinline noreturn nounwind uwtable "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 = { noreturn 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, !10, i64 64}
!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 48}
!12 = !{!13, !16, i64 44}
!13 = !{!"_ZTSN3qOS2sm12stateHandlerE", !7, i64 8, !7, i64 16, !7, i64 24, !7, i64 32, !14, i64 40, !15, i64 42, !16, i64 44, !7, i64 48, !7, i64 56, !7, i64 64}
!14 = !{!"_ZTSN3qOS2sm11historyModeE", !8, i64 0}
!15 = !{!"_ZTSN3qOS2sm6statusE", !8, i64 0}
!16 = !{!"_ZTSN3qOS2sm8signalIDE", !8, i64 0}
!17 = !{!13, !7, i64 48}
!18 = !{!19, !16, i64 0}
!19 = !{!"_ZTSN3qOS2sm10transitionE", !16, i64 0, !7, i64 8, !7, i64 16, !14, i64 24, !7, i64 32}
!20 = !{!19, !7, i64 32}
!21 = !{!19, !7, i64 8}
!22 = !{!19, !7, i64 16}
!23 = !{!13, !7, i64 16}
!24 = !{!19, !14, i64 24}
!25 = !{!13, !14, i64 40}
!26 = distinct !{!26, !27}
!27 = !{!"llvm.loop.mustprogress"}


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