; LLVM IR from kmilo17pet/QuarkTS-cpp :: src/input.ll (ZN3qOS5input13analogChannel11inBandStateERS1_)

; 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::input::analogChannel" = type { %"class.qOS::input::channel", i32, ptr, ptr, ptr, i32, i32, i32, i32, i32, i32, i32, i64 }
%"class.qOS::input::channel" = type { %"class.qOS::node", i32, i8, ptr, ptr, i64, i64, i64 }
%"class.qOS::node" = type { ptr, ptr, ptr, ptr }

@_ZN3qOS5clock7getTickE = external global ptr, align 8

; 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: inlinehint mustprogress nounwind uwtable
declare dso_local void @_ZN3qOS5input7channel13dispatchEventENS0_5eventE(ptr noundef nonnull align 8 dereferenceable(80), i32 noundef) #1 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN3qOS5input13analogChannel17lowThresholdStateERS1_(ptr noundef nonnull align 8 dereferenceable(152)) #2 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN3qOS5input13analogChannel18highThresholdStateERS1_(ptr noundef nonnull align 8 dereferenceable(152)) #2 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN3qOS5input13analogChannel11inBandStateERS1_(ptr noundef nonnull align 8 dereferenceable(152) %0) #2 align 2 {
  %2 = alloca ptr, align 8
  %3 = alloca i64, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #3
  %4 = load ptr, ptr @_ZN3qOS5clock7getTickE, align 8, !tbaa !5
  %5 = call noundef i64 %4()
  store i64 %5, ptr %3, align 8, !tbaa !9
  %6 = load ptr, ptr %2, align 8, !tbaa !5
  %7 = getelementptr inbounds %"class.qOS::input::analogChannel", ptr %6, i32 0, i32 1
  %8 = load i32, ptr %7, align 8, !tbaa !11
  %9 = load ptr, ptr %2, align 8, !tbaa !5
  %10 = getelementptr inbounds %"class.qOS::input::analogChannel", ptr %9, i32 0, i32 5
  %11 = load i32, ptr %10, align 8, !tbaa !17
  %12 = icmp ugt i32 %8, %11
  br i1 %12, label %13, label %21

13:                                               ; preds = %1
  %14 = load ptr, ptr %2, align 8, !tbaa !5
  %15 = getelementptr inbounds %"class.qOS::input::analogChannel", ptr %14, i32 0, i32 4
  store ptr @_ZN3qOS5input13analogChannel18highThresholdStateERS1_, ptr %15, align 8, !tbaa !18
  %16 = load ptr, ptr %2, align 8, !tbaa !5
  call void @_ZN3qOS5input7channel13dispatchEventENS0_5eventE(ptr noundef nonnull align 8 dereferenceable(80) %16, i32 noundef 8) #3
  %17 = load ptr, ptr %2, align 8, !tbaa !5
  call void @_ZN3qOS5input7channel13dispatchEventENS0_5eventE(ptr noundef nonnull align 8 dereferenceable(80) %17, i32 noundef 2) #3
  %18 = load i64, ptr %3, align 8, !tbaa !9
  %19 = load ptr, ptr %2, align 8, !tbaa !5
  %20 = getelementptr inbounds %"class.qOS::input::channel", ptr %19, i32 0, i32 5
  store i64 %18, ptr %20, align 8, !tbaa !19
  br label %39

21:                                               ; preds = %1
  %22 = load ptr, ptr %2, align 8, !tbaa !5
  %23 = getelementptr inbounds %"class.qOS::input::analogChannel", ptr %22, i32 0, i32 1
  %24 = load i32, ptr %23, align 8, !tbaa !11
  %25 = load ptr, ptr %2, align 8, !tbaa !5
  %26 = getelementptr inbounds %"class.qOS::input::analogChannel", ptr %25, i32 0, i32 6
  %27 = load i32, ptr %26, align 4, !tbaa !20
  %28 = icmp ult i32 %24, %27
  br i1 %28, label %29, label %37

29:                                               ; preds = %21
  %30 = load ptr, ptr %2, align 8, !tbaa !5
  %31 = getelementptr inbounds %"class.qOS::input::analogChannel", ptr %30, i32 0, i32 4
  store ptr @_ZN3qOS5input13analogChannel17lowThresholdStateERS1_, ptr %31, align 8, !tbaa !18
  %32 = load ptr, ptr %2, align 8, !tbaa !5
  call void @_ZN3qOS5input7channel13dispatchEventENS0_5eventE(ptr noundef nonnull align 8 dereferenceable(80) %32, i32 noundef 9) #3
  %33 = load ptr, ptr %2, align 8, !tbaa !5
  call void @_ZN3qOS5input7channel13dispatchEventENS0_5eventE(ptr noundef nonnull align 8 dereferenceable(80) %33, i32 noundef 2) #3
  %34 = load i64, ptr %3, align 8, !tbaa !9
  %35 = load ptr, ptr %2, align 8, !tbaa !5
  %36 = getelementptr inbounds %"class.qOS::input::channel", ptr %35, i32 0, i32 5
  store i64 %34, ptr %36, align 8, !tbaa !19
  br label %38

37:                                               ; preds = %21
  br label %38

38:                                               ; preds = %37, %29
  br label %39

39:                                               ; preds = %38, %13
  %40 = load i64, ptr %3, align 8, !tbaa !9
  %41 = load ptr, ptr %2, align 8, !tbaa !5
  %42 = getelementptr inbounds %"class.qOS::input::channel", ptr %41, i32 0, i32 5
  %43 = load i64, ptr %42, align 8, !tbaa !19
  %44 = sub i64 %40, %43
  %45 = load ptr, ptr %2, align 8, !tbaa !5
  %46 = getelementptr inbounds %"class.qOS::input::analogChannel", ptr %45, i32 0, i32 12
  %47 = load i64, ptr %46, align 8, !tbaa !21
  %48 = icmp ugt i64 %44, %47
  br i1 %48, label %49, label %56

49:                                               ; preds = %39
  %50 = load ptr, ptr %2, align 8, !tbaa !5
  %51 = getelementptr inbounds %"class.qOS::input::analogChannel", ptr %50, i32 0, i32 4
  store ptr @_ZN3qOS5input13analogChannel17steadyInBandStateERS1_, ptr %51, align 8, !tbaa !18
  %52 = load ptr, ptr %2, align 8, !tbaa !5
  call void @_ZN3qOS5input7channel13dispatchEventENS0_5eventE(ptr noundef nonnull align 8 dereferenceable(80) %52, i32 noundef 13) #3
  %53 = load i64, ptr %3, align 8, !tbaa !9
  %54 = load ptr, ptr %2, align 8, !tbaa !5
  %55 = getelementptr inbounds %"class.qOS::input::channel", ptr %54, i32 0, i32 5
  store i64 %53, ptr %55, align 8, !tbaa !19
  br label %56

56:                                               ; preds = %49, %39
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  ret void
}

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN3qOS5input13analogChannel17steadyInBandStateERS1_(ptr noundef nonnull align 8 dereferenceable(152)) #2 align 2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { inlinehint 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 = { mustprogress 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, !16, i64 80}
!12 = !{!"_ZTSN3qOS5input13analogChannelE", !13, i64 0, !16, i64 80, !6, i64 88, !6, i64 96, !6, i64 104, !16, i64 112, !16, i64 116, !16, i64 120, !16, i64 124, !16, i64 128, !16, i64 132, !16, i64 136, !10, i64 144}
!13 = !{!"_ZTSN3qOS5input7channelE", !14, i64 0, !15, i64 32, !7, i64 36, !6, i64 40, !6, i64 48, !10, i64 56, !10, i64 64, !10, i64 72}
!14 = !{!"_ZTSN3qOS4nodeE", !6, i64 8, !6, i64 16, !6, i64 24}
!15 = !{!"_ZTSN3qOS5input5eventE", !7, i64 0}
!16 = !{!"int", !7, i64 0}
!17 = !{!12, !16, i64 112}
!18 = !{!12, !6, i64 104}
!19 = !{!13, !10, i64 56}
!20 = !{!12, !16, i64 116}
!21 = !{!12, !10, i64 144}


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

@_ZN3qOS5clock7getTickE = external local_unnamed_addr global ptr, align 8

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_ZN3qOS5input7channel13dispatchEventENS0_5eventE(ptr noundef nonnull align 8 dereferenceable(80), i32 noundef) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN3qOS5input13analogChannel17lowThresholdStateERS1_(ptr noundef nonnull align 8 dereferenceable(152)) #1 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN3qOS5input13analogChannel18highThresholdStateERS1_(ptr noundef nonnull align 8 dereferenceable(152)) #1 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN3qOS5input13analogChannel11inBandStateERS1_(ptr noundef nonnull align 8 dereferenceable(152) %0) local_unnamed_addr #1 align 2 {
  %2 = load ptr, ptr @_ZN3qOS5clock7getTickE, align 8, !tbaa !5
  %3 = tail call noundef i64 %2()
  %4 = getelementptr inbounds i8, ptr %0, i64 80
  %5 = load i32, ptr %4, align 8, !tbaa !9
  %6 = getelementptr inbounds i8, ptr %0, i64 112
  %7 = load i32, ptr %6, align 8, !tbaa !16
  %8 = icmp ugt i32 %5, %7
  br i1 %8, label %9, label %12

9:                                                ; preds = %1
  %10 = getelementptr inbounds i8, ptr %0, i64 104
  store ptr @_ZN3qOS5input13analogChannel18highThresholdStateERS1_, ptr %10, align 8, !tbaa !17
  tail call void @_ZN3qOS5input7channel13dispatchEventENS0_5eventE(ptr noundef nonnull align 8 dereferenceable(80) %0, i32 noundef 8) #2
  tail call void @_ZN3qOS5input7channel13dispatchEventENS0_5eventE(ptr noundef nonnull align 8 dereferenceable(80) %0, i32 noundef 2) #2
  %11 = getelementptr inbounds i8, ptr %0, i64 56
  store i64 %3, ptr %11, align 8, !tbaa !18
  br label %19

12:                                               ; preds = %1
  %13 = getelementptr inbounds i8, ptr %0, i64 116
  %14 = load i32, ptr %13, align 4, !tbaa !19
  %15 = icmp ult i32 %5, %14
  br i1 %15, label %16, label %._crit_edge

._crit_edge:                                      ; preds = %12
  %.phi.trans.insert = getelementptr inbounds i8, ptr %0, i64 56
  %.pre = load i64, ptr %.phi.trans.insert, align 8, !tbaa !18
  br label %19

16:                                               ; preds = %12
  %17 = getelementptr inbounds i8, ptr %0, i64 104
  store ptr @_ZN3qOS5input13analogChannel17lowThresholdStateERS1_, ptr %17, align 8, !tbaa !17
  tail call void @_ZN3qOS5input7channel13dispatchEventENS0_5eventE(ptr noundef nonnull align 8 dereferenceable(80) %0, i32 noundef 9) #2
  tail call void @_ZN3qOS5input7channel13dispatchEventENS0_5eventE(ptr noundef nonnull align 8 dereferenceable(80) %0, i32 noundef 2) #2
  %18 = getelementptr inbounds i8, ptr %0, i64 56
  store i64 %3, ptr %18, align 8, !tbaa !18
  br label %19

19:                                               ; preds = %._crit_edge, %16, %9
  %20 = phi i64 [ %.pre, %._crit_edge ], [ %3, %16 ], [ %3, %9 ]
  %21 = sub i64 %3, %20
  %22 = getelementptr inbounds i8, ptr %0, i64 144
  %23 = load i64, ptr %22, align 8, !tbaa !20
  %24 = icmp ugt i64 %21, %23
  br i1 %24, label %25, label %28

25:                                               ; preds = %19
  %26 = getelementptr inbounds i8, ptr %0, i64 56
  %27 = getelementptr inbounds i8, ptr %0, i64 104
  store ptr @_ZN3qOS5input13analogChannel17steadyInBandStateERS1_, ptr %27, align 8, !tbaa !17
  tail call void @_ZN3qOS5input7channel13dispatchEventENS0_5eventE(ptr noundef nonnull align 8 dereferenceable(80) %0, i32 noundef 13) #2
  store i64 %3, ptr %26, align 8, !tbaa !18
  br label %28

28:                                               ; preds = %25, %19
  ret void
}

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN3qOS5input13analogChannel17steadyInBandStateERS1_(ptr noundef nonnull align 8 dereferenceable(152)) #1 align 2

attributes #0 = { inlinehint 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 = { mustprogress 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, !15, i64 80}
!10 = !{!"_ZTSN3qOS5input13analogChannelE", !11, i64 0, !15, i64 80, !6, i64 88, !6, i64 96, !6, i64 104, !15, i64 112, !15, i64 116, !15, i64 120, !15, i64 124, !15, i64 128, !15, i64 132, !15, i64 136, !14, i64 144}
!11 = !{!"_ZTSN3qOS5input7channelE", !12, i64 0, !13, i64 32, !7, i64 36, !6, i64 40, !6, i64 48, !14, i64 56, !14, i64 64, !14, i64 72}
!12 = !{!"_ZTSN3qOS4nodeE", !6, i64 8, !6, i64 16, !6, i64 24}
!13 = !{!"_ZTSN3qOS5input5eventE", !7, i64 0}
!14 = !{!"long", !7, i64 0}
!15 = !{!"int", !7, i64 0}
!16 = !{!10, !15, i64 112}
!17 = !{!10, !6, i64 104}
!18 = !{!11, !14, i64 56}
!19 = !{!10, !15, i64 116}
!20 = !{!10, !14, i64 144}


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