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

; 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::digitalChannel" = type <{ %"class.qOS::input::channel", i32, [4 x i8], ptr, ptr, ptr, i8, [7 x i8], i64, i8, [7 x i8] }>
%"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
define dso_local void @_ZN3qOS5input14digitalChannel16fallingEdgeStateERS1_(ptr noundef nonnull align 8 dereferenceable(129) %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::digitalChannel", ptr %6, i32 0, i32 1
  %8 = load i32, ptr %7, align 8, !tbaa !11
  %9 = icmp ne i32 0, %8
  br i1 %9, label %10, label %31

10:                                               ; preds = %1
  %11 = load ptr, ptr %2, align 8, !tbaa !5
  %12 = getelementptr inbounds %"class.qOS::input::digitalChannel", ptr %11, i32 0, i32 5
  store ptr @_ZN3qOS5input14digitalChannel15risingEdgeStateERS1_, ptr %12, align 8, !tbaa !18
  %13 = load ptr, ptr %2, align 8, !tbaa !5
  call void @_ZN3qOS5input7channel13dispatchEventENS0_5eventE(ptr noundef nonnull align 8 dereferenceable(80) %13, i32 noundef 4) #3
  %14 = load ptr, ptr %2, align 8, !tbaa !5
  call void @_ZN3qOS5input7channel13dispatchEventENS0_5eventE(ptr noundef nonnull align 8 dereferenceable(80) %14, i32 noundef 2) #3
  %15 = load i64, ptr %3, align 8, !tbaa !9
  %16 = load ptr, ptr %2, align 8, !tbaa !5
  %17 = getelementptr inbounds %"class.qOS::input::channel", ptr %16, i32 0, i32 5
  %18 = load i64, ptr %17, align 8, !tbaa !19
  %19 = sub i64 %15, %18
  %20 = load ptr, ptr %2, align 8, !tbaa !5
  %21 = getelementptr inbounds %"class.qOS::input::digitalChannel", ptr %20, i32 0, i32 8
  %22 = load i64, ptr %21, align 8, !tbaa !20
  %23 = icmp ugt i64 %19, %22
  br i1 %23, label %24, label %27

24:                                               ; preds = %10
  %25 = load ptr, ptr %2, align 8, !tbaa !5
  %26 = getelementptr inbounds %"class.qOS::input::digitalChannel", ptr %25, i32 0, i32 9
  store i8 0, ptr %26, align 8, !tbaa !21
  br label %27

27:                                               ; preds = %24, %10
  %28 = load i64, ptr %3, align 8, !tbaa !9
  %29 = load ptr, ptr %2, align 8, !tbaa !5
  %30 = getelementptr inbounds %"class.qOS::input::channel", ptr %29, i32 0, i32 5
  store i64 %28, ptr %30, align 8, !tbaa !19
  br label %31

31:                                               ; preds = %27, %1
  %32 = load i64, ptr %3, align 8, !tbaa !9
  %33 = load ptr, ptr %2, align 8, !tbaa !5
  %34 = getelementptr inbounds %"class.qOS::input::channel", ptr %33, i32 0, i32 5
  %35 = load i64, ptr %34, align 8, !tbaa !19
  %36 = sub i64 %32, %35
  %37 = load ptr, ptr %2, align 8, !tbaa !5
  %38 = getelementptr inbounds %"class.qOS::input::channel", ptr %37, i32 0, i32 7
  %39 = load i64, ptr %38, align 8, !tbaa !22
  %40 = icmp ugt i64 %36, %39
  br i1 %40, label %41, label %48

41:                                               ; preds = %31
  %42 = load ptr, ptr %2, align 8, !tbaa !5
  %43 = getelementptr inbounds %"class.qOS::input::digitalChannel", ptr %42, i32 0, i32 5
  store ptr @_ZN3qOS5input14digitalChannel16steadyInLowStateERS1_, ptr %43, align 8, !tbaa !18
  %44 = load ptr, ptr %2, align 8, !tbaa !5
  call void @_ZN3qOS5input7channel13dispatchEventENS0_5eventE(ptr noundef nonnull align 8 dereferenceable(80) %44, i32 noundef 12) #3
  %45 = load i64, ptr %3, align 8, !tbaa !9
  %46 = load ptr, ptr %2, align 8, !tbaa !5
  %47 = getelementptr inbounds %"class.qOS::input::channel", ptr %46, i32 0, i32 5
  store i64 %45, ptr %47, align 8, !tbaa !19
  br label %48

48:                                               ; preds = %41, %31
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  ret void
}

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN3qOS5input14digitalChannel16steadyInLowStateERS1_(ptr noundef nonnull align 8 dereferenceable(129)) #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 = !{!"_ZTSN3qOS5input14digitalChannelE", !13, i64 0, !16, i64 80, !6, i64 88, !6, i64 96, !6, i64 104, !17, i64 112, !10, i64 120, !7, i64 128}
!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 = !{!"bool", !7, i64 0}
!18 = !{!12, !6, i64 104}
!19 = !{!13, !10, i64 56}
!20 = !{!12, !10, i64 120}
!21 = !{!12, !7, i64 128}
!22 = !{!13, !10, i64 72}


; 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
define dso_local void @_ZN3qOS5input14digitalChannel16fallingEdgeStateERS1_(ptr noundef nonnull align 8 dereferenceable(129) %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
  %.not = icmp eq i32 %5, 0
  br i1 %.not, label %._crit_edge, label %6

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

6:                                                ; preds = %1
  %7 = getelementptr inbounds i8, ptr %0, i64 104
  store ptr @_ZN3qOS5input14digitalChannel15risingEdgeStateERS1_, ptr %7, align 8, !tbaa !18
  tail call void @_ZN3qOS5input7channel13dispatchEventENS0_5eventE(ptr noundef nonnull align 8 dereferenceable(80) %0, i32 noundef 4) #2
  tail call void @_ZN3qOS5input7channel13dispatchEventENS0_5eventE(ptr noundef nonnull align 8 dereferenceable(80) %0, i32 noundef 2) #2
  %8 = getelementptr inbounds i8, ptr %0, i64 56
  %9 = load i64, ptr %8, align 8, !tbaa !17
  %10 = sub i64 %3, %9
  %11 = getelementptr inbounds i8, ptr %0, i64 120
  %12 = load i64, ptr %11, align 8, !tbaa !19
  %13 = icmp ugt i64 %10, %12
  br i1 %13, label %14, label %16

14:                                               ; preds = %6
  %15 = getelementptr inbounds i8, ptr %0, i64 128
  store i8 0, ptr %15, align 8, !tbaa !20
  br label %16

16:                                               ; preds = %14, %6
  store i64 %3, ptr %8, align 8, !tbaa !17
  br label %17

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

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

26:                                               ; preds = %23, %17
  ret void
}

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN3qOS5input14digitalChannel16steadyInLowStateERS1_(ptr noundef nonnull align 8 dereferenceable(129)) #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 = !{!"_ZTSN3qOS5input14digitalChannelE", !11, i64 0, !15, i64 80, !6, i64 88, !6, i64 96, !6, i64 104, !16, i64 112, !14, i64 120, !7, i64 128}
!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 = !{!"bool", !7, i64 0}
!17 = !{!11, !14, i64 56}
!18 = !{!10, !6, i64 104}
!19 = !{!10, !14, i64 120}
!20 = !{!10, !7, i64 128}
!21 = !{!11, !14, i64 72}


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