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

; 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
define dso_local void @_ZN3qOS5input13analogChannel18highThresholdStateERS1_(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 6
  %11 = load i32, ptr %10, align 4, !tbaa !17
  %12 = icmp ult 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 @_ZN3qOS5input13analogChannel17lowThresholdStateERS1_, 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 9) #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 %43

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 5
  %27 = load i32, ptr %26, align 8, !tbaa !20
  %28 = load ptr, ptr %2, align 8, !tbaa !5
  %29 = getelementptr inbounds %"class.qOS::input::analogChannel", ptr %28, i32 0, i32 11
  %30 = load i32, ptr %29, align 8, !tbaa !21
  %31 = sub i32 %27, %30
  %32 = icmp ult i32 %24, %31
  br i1 %32, label %33, label %41

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

41:                                               ; preds = %21
  br label %42

42:                                               ; preds = %41, %33
  br label %43

43:                                               ; preds = %42, %13
  %44 = load i64, ptr %3, align 8, !tbaa !9
  %45 = load ptr, ptr %2, align 8, !tbaa !5
  %46 = getelementptr inbounds %"class.qOS::input::channel", ptr %45, i32 0, i32 5
  %47 = load i64, ptr %46, align 8, !tbaa !19
  %48 = sub i64 %44, %47
  %49 = load ptr, ptr %2, align 8, !tbaa !5
  %50 = getelementptr inbounds %"class.qOS::input::channel", ptr %49, i32 0, i32 6
  %51 = load i64, ptr %50, align 8, !tbaa !22
  %52 = icmp ugt i64 %48, %51
  br i1 %52, label %53, label %60

53:                                               ; preds = %43
  %54 = load ptr, ptr %2, align 8, !tbaa !5
  %55 = getelementptr inbounds %"class.qOS::input::analogChannel", ptr %54, i32 0, i32 4
  store ptr @_ZN3qOS5input13analogChannel17steadyInHighStateERS1_, ptr %55, align 8, !tbaa !18
  %56 = load ptr, ptr %2, align 8, !tbaa !5
  call void @_ZN3qOS5input7channel13dispatchEventENS0_5eventE(ptr noundef nonnull align 8 dereferenceable(80) %56, i32 noundef 11) #3
  %57 = load i64, ptr %3, align 8, !tbaa !9
  %58 = load ptr, ptr %2, align 8, !tbaa !5
  %59 = getelementptr inbounds %"class.qOS::input::channel", ptr %58, i32 0, i32 5
  store i64 %57, ptr %59, align 8, !tbaa !19
  br label %60

60:                                               ; preds = %53, %43
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  ret void
}

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN3qOS5input13analogChannel17steadyInHighStateERS1_(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 116}
!18 = !{!12, !6, i64 104}
!19 = !{!13, !10, i64 56}
!20 = !{!12, !16, i64 112}
!21 = !{!12, !16, i64 136}
!22 = !{!13, !10, i64 64}


; 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
define dso_local void @_ZN3qOS5input13analogChannel18highThresholdStateERS1_(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 116
  %7 = load i32, ptr %6, align 4, !tbaa !16
  %8 = icmp ult i32 %5, %7
  br i1 %8, label %9, label %12

9:                                                ; preds = %1
  %10 = getelementptr inbounds i8, ptr %0, i64 104
  store ptr @_ZN3qOS5input13analogChannel17lowThresholdStateERS1_, ptr %10, 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
  %11 = getelementptr inbounds i8, ptr %0, i64 56
  store i64 %3, ptr %11, align 8, !tbaa !18
  br label %22

12:                                               ; preds = %1
  %13 = getelementptr inbounds i8, ptr %0, i64 112
  %14 = load i32, ptr %13, align 8, !tbaa !19
  %15 = getelementptr inbounds i8, ptr %0, i64 136
  %16 = load i32, ptr %15, align 8, !tbaa !20
  %17 = sub i32 %14, %16
  %18 = icmp ult i32 %5, %17
  br i1 %18, label %19, 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 %22

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

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

28:                                               ; preds = %22
  %29 = getelementptr inbounds i8, ptr %0, i64 56
  %30 = getelementptr inbounds i8, ptr %0, i64 104
  store ptr @_ZN3qOS5input13analogChannel17steadyInHighStateERS1_, ptr %30, align 8, !tbaa !17
  tail call void @_ZN3qOS5input7channel13dispatchEventENS0_5eventE(ptr noundef nonnull align 8 dereferenceable(80) %0, i32 noundef 11) #2
  store i64 %3, ptr %29, align 8, !tbaa !18
  br label %31

31:                                               ; preds = %28, %22
  ret void
}

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN3qOS5input13analogChannel17steadyInHighStateERS1_(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 116}
!17 = !{!10, !6, i64 104}
!18 = !{!11, !14, i64 56}
!19 = !{!10, !15, i64 112}
!20 = !{!10, !15, i64 136}
!21 = !{!11, !14, i64 64}


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