; LLVM IR from lichen-community-systems/signaletic :: hosts/daisy/vendor/libDaisy/src/hid/encoder.ll (ZN5daisy7Encoder8DebounceEv)

; 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.daisy::Encoder" = type { i32, i8, %"class.daisy::Switch", %struct.dsy_gpio, %struct.dsy_gpio, i8, i8, i32 }
%"class.daisy::Switch" = type { i32, i8, i32, %struct.dsy_gpio, i8, i8, float }
%struct.dsy_gpio = type { %struct.dsy_gpio_pin, i32, i32 }
%struct.dsy_gpio_pin = type { i32, i8 }

declare noundef i32 @_ZN5daisy6System6GetNowEv() #0

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN5daisy7Encoder8DebounceEv(ptr noundef nonnull align 4 dereferenceable(84) %0) #1 align 2 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  %4 = load ptr, ptr %2, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  %5 = call noundef i32 @_ZN5daisy6System6GetNowEv()
  store i32 %5, ptr %3, align 4, !tbaa !9
  %6 = getelementptr inbounds %"class.daisy::Encoder", ptr %4, i32 0, i32 1
  store i8 0, ptr %6, align 4, !tbaa !11
  %7 = load i32, ptr %3, align 4, !tbaa !9
  %8 = getelementptr inbounds %"class.daisy::Encoder", ptr %4, i32 0, i32 0
  %9 = load i32, ptr %8, align 4, !tbaa !22
  %10 = sub i32 %7, %9
  %11 = icmp uge i32 %10, 1
  br i1 %11, label %12, label %66

12:                                               ; preds = %1
  %13 = load i32, ptr %3, align 4, !tbaa !9
  %14 = getelementptr inbounds %"class.daisy::Encoder", ptr %4, i32 0, i32 0
  store i32 %13, ptr %14, align 4, !tbaa !22
  %15 = getelementptr inbounds %"class.daisy::Encoder", ptr %4, i32 0, i32 1
  store i8 1, ptr %15, align 4, !tbaa !11
  %16 = getelementptr inbounds %"class.daisy::Encoder", ptr %4, i32 0, i32 5
  %17 = load i8, ptr %16, align 4, !tbaa !23
  %18 = zext i8 %17 to i32
  %19 = shl i32 %18, 1
  %20 = getelementptr inbounds %"class.daisy::Encoder", ptr %4, i32 0, i32 3
  %21 = call zeroext i8 @dsy_gpio_read(ptr noundef %20)
  %22 = zext i8 %21 to i32
  %23 = or i32 %19, %22
  %24 = trunc i32 %23 to i8
  %25 = getelementptr inbounds %"class.daisy::Encoder", ptr %4, i32 0, i32 5
  store i8 %24, ptr %25, align 4, !tbaa !23
  %26 = getelementptr inbounds %"class.daisy::Encoder", ptr %4, i32 0, i32 6
  %27 = load i8, ptr %26, align 1, !tbaa !24
  %28 = zext i8 %27 to i32
  %29 = shl i32 %28, 1
  %30 = getelementptr inbounds %"class.daisy::Encoder", ptr %4, i32 0, i32 4
  %31 = call zeroext i8 @dsy_gpio_read(ptr noundef %30)
  %32 = zext i8 %31 to i32
  %33 = or i32 %29, %32
  %34 = trunc i32 %33 to i8
  %35 = getelementptr inbounds %"class.daisy::Encoder", ptr %4, i32 0, i32 6
  store i8 %34, ptr %35, align 1, !tbaa !24
  %36 = getelementptr inbounds %"class.daisy::Encoder", ptr %4, i32 0, i32 7
  store i32 0, ptr %36, align 4, !tbaa !25
  %37 = getelementptr inbounds %"class.daisy::Encoder", ptr %4, i32 0, i32 5
  %38 = load i8, ptr %37, align 4, !tbaa !23
  %39 = zext i8 %38 to i32
  %40 = and i32 %39, 3
  %41 = icmp eq i32 %40, 2
  br i1 %41, label %42, label %50

42:                                               ; preds = %12
  %43 = getelementptr inbounds %"class.daisy::Encoder", ptr %4, i32 0, i32 6
  %44 = load i8, ptr %43, align 1, !tbaa !24
  %45 = zext i8 %44 to i32
  %46 = and i32 %45, 3
  %47 = icmp eq i32 %46, 0
  br i1 %47, label %48, label %50

48:                                               ; preds = %42
  %49 = getelementptr inbounds %"class.daisy::Encoder", ptr %4, i32 0, i32 7
  store i32 1, ptr %49, align 4, !tbaa !25
  br label %65

50:                                               ; preds = %42, %12
  %51 = getelementptr inbounds %"class.daisy::Encoder", ptr %4, i32 0, i32 6
  %52 = load i8, ptr %51, align 1, !tbaa !24
  %53 = zext i8 %52 to i32
  %54 = and i32 %53, 3
  %55 = icmp eq i32 %54, 2
  br i1 %55, label %56, label %64

56:                                               ; preds = %50
  %57 = getelementptr inbounds %"class.daisy::Encoder", ptr %4, i32 0, i32 5
  %58 = load i8, ptr %57, align 4, !tbaa !23
  %59 = zext i8 %58 to i32
  %60 = and i32 %59, 3
  %61 = icmp eq i32 %60, 0
  br i1 %61, label %62, label %64

62:                                               ; preds = %56
  %63 = getelementptr inbounds %"class.daisy::Encoder", ptr %4, i32 0, i32 7
  store i32 -1, ptr %63, align 4, !tbaa !25
  br label %64

64:                                               ; preds = %62, %56, %50
  br label %65

65:                                               ; preds = %64, %48
  br label %66

66:                                               ; preds = %65, %1
  %67 = getelementptr inbounds %"class.daisy::Encoder", ptr %4, i32 0, i32 2
  call void @_ZN5daisy6Switch8DebounceEv(ptr noundef nonnull align 4 dereferenceable(36) %67)
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  ret void
}

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #2

declare zeroext i8 @dsy_gpio_read(ptr noundef) #0

declare void @_ZN5daisy6Switch8DebounceEv(ptr noundef nonnull align 4 dereferenceable(36)) #0

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #2

attributes #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = !{!"int", !7, i64 0}
!11 = !{!12, !13, i64 4}
!12 = !{!"_ZTSN5daisy7EncoderE", !10, i64 0, !13, i64 4, !14, i64 8, !16, i64 44, !16, i64 60, !7, i64 76, !7, i64 77, !10, i64 80}
!13 = !{!"bool", !7, i64 0}
!14 = !{!"_ZTSN5daisy6SwitchE", !10, i64 0, !13, i64 4, !15, i64 8, !16, i64 12, !7, i64 28, !13, i64 29, !21, i64 32}
!15 = !{!"_ZTSN5daisy6Switch4TypeE", !7, i64 0}
!16 = !{!"_ZTS8dsy_gpio", !17, i64 0, !19, i64 8, !20, i64 12}
!17 = !{!"_ZTS12dsy_gpio_pin", !18, i64 0, !7, i64 4}
!18 = !{!"_ZTS13dsy_gpio_port", !7, i64 0}
!19 = !{!"_ZTS13dsy_gpio_mode", !7, i64 0}
!20 = !{!"_ZTS13dsy_gpio_pull", !7, i64 0}
!21 = !{!"float", !7, i64 0}
!22 = !{!12, !10, i64 0}
!23 = !{!12, !7, i64 76}
!24 = !{!12, !7, i64 77}
!25 = !{!12, !10, i64 80}


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

declare noundef i32 @_ZN5daisy6System6GetNowEv() local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN5daisy7Encoder8DebounceEv(ptr noundef nonnull align 4 dereferenceable(84) %0) local_unnamed_addr #1 align 2 {
  %2 = tail call noundef i32 @_ZN5daisy6System6GetNowEv()
  %3 = getelementptr inbounds i8, ptr %0, i64 4
  store i8 0, ptr %3, align 4, !tbaa !5
  %4 = load i32, ptr %0, align 4, !tbaa !19
  %.not = icmp eq i32 %2, %4
  br i1 %.not, label %.thread2, label %5

5:                                                ; preds = %1
  store i32 %2, ptr %0, align 4, !tbaa !19
  store i8 1, ptr %3, align 4, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %0, i64 76
  %7 = load i8, ptr %6, align 4, !tbaa !20
  %8 = shl i8 %7, 1
  %9 = getelementptr inbounds i8, ptr %0, i64 44
  %10 = tail call zeroext i8 @dsy_gpio_read(ptr noundef nonnull %9)
  %11 = or i8 %8, %10
  store i8 %11, ptr %6, align 4, !tbaa !20
  %12 = getelementptr inbounds i8, ptr %0, i64 77
  %13 = load i8, ptr %12, align 1, !tbaa !21
  %14 = shl i8 %13, 1
  %15 = getelementptr inbounds i8, ptr %0, i64 60
  %16 = tail call zeroext i8 @dsy_gpio_read(ptr noundef nonnull %15)
  %17 = or i8 %14, %16
  store i8 %17, ptr %12, align 1, !tbaa !21
  %18 = getelementptr inbounds i8, ptr %0, i64 80
  store i32 0, ptr %18, align 4, !tbaa !22
  %19 = load i8, ptr %6, align 4, !tbaa !20
  %20 = and i8 %19, 3
  %21 = icmp eq i8 %20, 2
  %22 = and i8 %17, 3
  br i1 %21, label %23, label %25

23:                                               ; preds = %5
  %24 = icmp eq i8 %22, 0
  br i1 %24, label %.thread2.sink.split, label %.thread2

25:                                               ; preds = %5
  %26 = icmp eq i8 %22, 2
  %27 = icmp eq i8 %20, 0
  %or.cond = and i1 %26, %27
  br i1 %or.cond, label %.thread2.sink.split, label %.thread2

.thread2.sink.split:                              ; preds = %25, %23
  %.sink = phi i32 [ 1, %23 ], [ -1, %25 ]
  store i32 %.sink, ptr %18, align 4, !tbaa !22
  br label %.thread2

.thread2:                                         ; preds = %.thread2.sink.split, %23, %25, %1
  %28 = getelementptr inbounds i8, ptr %0, i64 8
  tail call void @_ZN5daisy6Switch8DebounceEv(ptr noundef nonnull align 4 dereferenceable(36) %28)
  ret void
}

declare zeroext i8 @dsy_gpio_read(ptr noundef) local_unnamed_addr #0

declare void @_ZN5daisy6Switch8DebounceEv(ptr noundef nonnull align 4 dereferenceable(36)) local_unnamed_addr #0

attributes #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" }

!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 4}
!6 = !{!"_ZTSN5daisy7EncoderE", !7, i64 0, !10, i64 4, !11, i64 8, !13, i64 44, !13, i64 60, !8, i64 76, !8, i64 77, !7, i64 80}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"bool", !8, i64 0}
!11 = !{!"_ZTSN5daisy6SwitchE", !7, i64 0, !10, i64 4, !12, i64 8, !13, i64 12, !8, i64 28, !10, i64 29, !18, i64 32}
!12 = !{!"_ZTSN5daisy6Switch4TypeE", !8, i64 0}
!13 = !{!"_ZTS8dsy_gpio", !14, i64 0, !16, i64 8, !17, i64 12}
!14 = !{!"_ZTS12dsy_gpio_pin", !15, i64 0, !8, i64 4}
!15 = !{!"_ZTS13dsy_gpio_port", !8, i64 0}
!16 = !{!"_ZTS13dsy_gpio_mode", !8, i64 0}
!17 = !{!"_ZTS13dsy_gpio_pull", !8, i64 0}
!18 = !{!"float", !8, i64 0}
!19 = !{!6, !7, i64 0}
!20 = !{!6, !8, i64 76}
!21 = !{!6, !8, i64 77}
!22 = !{!6, !7, i64 80}


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