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

; 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
declare dso_local void @_ZN3qOS5input14digitalChannel16fallingEdgeStateERS1_(ptr noundef nonnull align 8 dereferenceable(129)) #2 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN3qOS5input14digitalChannel15risingEdgeStateERS1_(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 eq i32 0, %8
  br i1 %9, label %10, label %45

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 @_ZN3qOS5input14digitalChannel16fallingEdgeStateERS1_, 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 3) #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 ule i64 %19, %22
  br i1 %23, label %24, label %29

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
  %27 = load i8, ptr %26, align 8, !tbaa !21
  %28 = add i8 %27, 1
  store i8 %28, ptr %26, align 8, !tbaa !21
  br label %29

29:                                               ; preds = %24, %10
  %30 = load i64, ptr %3, align 8, !tbaa !9
  %31 = load ptr, ptr %2, align 8, !tbaa !5
  %32 = getelementptr inbounds %"class.qOS::input::channel", ptr %31, i32 0, i32 5
  store i64 %30, ptr %32, align 8, !tbaa !19
  %33 = load ptr, ptr %2, align 8, !tbaa !5
  %34 = getelementptr inbounds %"class.qOS::input::digitalChannel", ptr %33, i32 0, i32 9
  %35 = load i8, ptr %34, align 8, !tbaa !21
  %36 = zext i8 %35 to i32
  switch i32 %36, label %42 [
    i32 0, label %37
    i32 1, label %37
    i32 2, label %38
    i32 3, label %40
  ]

37:                                               ; preds = %29, %29
  br label %44

38:                                               ; preds = %29
  %39 = load ptr, ptr %2, align 8, !tbaa !5
  call void @_ZN3qOS5input7channel13dispatchEventENS0_5eventE(ptr noundef nonnull align 8 dereferenceable(80) %39, i32 noundef 5) #3
  br label %44

40:                                               ; preds = %29
  %41 = load ptr, ptr %2, align 8, !tbaa !5
  call void @_ZN3qOS5input7channel13dispatchEventENS0_5eventE(ptr noundef nonnull align 8 dereferenceable(80) %41, i32 noundef 6) #3
  br label %44

42:                                               ; preds = %29
  %43 = load ptr, ptr %2, align 8, !tbaa !5
  call void @_ZN3qOS5input7channel13dispatchEventENS0_5eventE(ptr noundef nonnull align 8 dereferenceable(80) %43, i32 noundef 7) #3
  br label %44

44:                                               ; preds = %42, %40, %38, %37
  br label %45

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

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

62:                                               ; preds = %55, %45
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  ret void
}

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN3qOS5input14digitalChannel17steadyInHighStateERS1_(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 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 @_ZN3qOS5input14digitalChannel16fallingEdgeStateERS1_(ptr noundef nonnull align 8 dereferenceable(129)) #1 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN3qOS5input14digitalChannel15risingEdgeStateERS1_(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
  %6 = icmp eq i32 %5, 0
  br i1 %6, label %7, label %19

7:                                                ; preds = %1
  %8 = getelementptr inbounds i8, ptr %0, i64 104
  store ptr @_ZN3qOS5input14digitalChannel16fallingEdgeStateERS1_, ptr %8, align 8, !tbaa !17
  tail call void @_ZN3qOS5input7channel13dispatchEventENS0_5eventE(ptr noundef nonnull align 8 dereferenceable(80) %0, i32 noundef 3) #2
  tail call void @_ZN3qOS5input7channel13dispatchEventENS0_5eventE(ptr noundef nonnull align 8 dereferenceable(80) %0, i32 noundef 2) #2
  %9 = getelementptr inbounds i8, ptr %0, i64 56
  %10 = load i64, ptr %9, align 8, !tbaa !18
  %11 = sub i64 %3, %10
  %12 = getelementptr inbounds i8, ptr %0, i64 120
  %13 = load i64, ptr %12, align 8, !tbaa !19
  %.not = icmp ugt i64 %11, %13
  %.phi.trans.insert = getelementptr inbounds i8, ptr %0, i64 128
  %.pre = load i8, ptr %.phi.trans.insert, align 8, !tbaa !20
  br i1 %.not, label %._crit_edge, label %14

14:                                               ; preds = %7
  %15 = add i8 %.pre, 1
  store i8 %15, ptr %.phi.trans.insert, align 8, !tbaa !20
  br label %._crit_edge

._crit_edge:                                      ; preds = %7, %14
  %16 = phi i8 [ %15, %14 ], [ %.pre, %7 ]
  store i64 %3, ptr %9, align 8, !tbaa !18
  switch i8 %16, label %18 [
    i8 0, label %19
    i8 1, label %19
    i8 2, label %.sink.split
    i8 3, label %17
  ]

17:                                               ; preds = %._crit_edge
  br label %.sink.split

18:                                               ; preds = %._crit_edge
  br label %.sink.split

.sink.split:                                      ; preds = %._crit_edge, %18, %17
  %.sink = phi i32 [ 6, %17 ], [ 7, %18 ], [ 5, %._crit_edge ]
  tail call void @_ZN3qOS5input7channel13dispatchEventENS0_5eventE(ptr noundef nonnull align 8 dereferenceable(80) %0, i32 noundef %.sink) #2
  br label %19

19:                                               ; preds = %.sink.split, %._crit_edge, %._crit_edge, %1
  %20 = getelementptr inbounds i8, ptr %0, i64 56
  %21 = load i64, ptr %20, align 8, !tbaa !18
  %22 = sub i64 %3, %21
  %23 = getelementptr inbounds i8, ptr %0, i64 64
  %24 = load i64, ptr %23, align 8, !tbaa !21
  %25 = icmp ugt i64 %22, %24
  br i1 %25, label %26, label %28

26:                                               ; preds = %19
  %27 = getelementptr inbounds i8, ptr %0, i64 104
  store ptr @_ZN3qOS5input14digitalChannel17steadyInHighStateERS1_, ptr %27, 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 %20, align 8, !tbaa !18
  br label %28

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

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


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