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

; 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::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 @_ZN5daisy6Switch8DebounceEv(ptr noundef nonnull align 4 dereferenceable(36) %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::Switch", 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::Switch", ptr %4, i32 0, i32 0
  %9 = load i32, ptr %8, align 4, !tbaa !21
  %10 = sub i32 %7, %9
  %11 = icmp uge i32 %10, 1
  br i1 %11, label %12, label %47

12:                                               ; preds = %1
  %13 = load i32, ptr %3, align 4, !tbaa !9
  %14 = getelementptr inbounds %"class.daisy::Switch", ptr %4, i32 0, i32 0
  store i32 %13, ptr %14, align 4, !tbaa !21
  %15 = getelementptr inbounds %"class.daisy::Switch", ptr %4, i32 0, i32 1
  store i8 1, ptr %15, align 4, !tbaa !11
  %16 = getelementptr inbounds %"class.daisy::Switch", ptr %4, i32 0, i32 4
  %17 = load i8, ptr %16, align 4, !tbaa !22
  %18 = zext i8 %17 to i32
  %19 = shl i32 %18, 1
  %20 = getelementptr inbounds %"class.daisy::Switch", ptr %4, i32 0, i32 5
  %21 = load i8, ptr %20, align 1, !tbaa !23, !range !24, !noundef !25
  %22 = trunc i8 %21 to i1
  br i1 %22, label %23, label %29

23:                                               ; preds = %12
  %24 = getelementptr inbounds %"class.daisy::Switch", ptr %4, i32 0, i32 3
  %25 = call zeroext i8 @dsy_gpio_read(ptr noundef %24)
  %26 = icmp ne i8 %25, 0
  %27 = xor i1 %26, true
  %28 = zext i1 %27 to i32
  br label %33

29:                                               ; preds = %12
  %30 = getelementptr inbounds %"class.daisy::Switch", ptr %4, i32 0, i32 3
  %31 = call zeroext i8 @dsy_gpio_read(ptr noundef %30)
  %32 = zext i8 %31 to i32
  br label %33

33:                                               ; preds = %29, %23
  %34 = phi i32 [ %28, %23 ], [ %32, %29 ]
  %35 = or i32 %19, %34
  %36 = trunc i32 %35 to i8
  %37 = getelementptr inbounds %"class.daisy::Switch", ptr %4, i32 0, i32 4
  store i8 %36, ptr %37, align 4, !tbaa !22
  %38 = getelementptr inbounds %"class.daisy::Switch", ptr %4, i32 0, i32 4
  %39 = load i8, ptr %38, align 4, !tbaa !22
  %40 = zext i8 %39 to i32
  %41 = icmp eq i32 %40, 127
  br i1 %41, label %42, label %46

42:                                               ; preds = %33
  %43 = call noundef i32 @_ZN5daisy6System6GetNowEv()
  %44 = uitofp i32 %43 to float
  %45 = getelementptr inbounds %"class.daisy::Switch", ptr %4, i32 0, i32 6
  store float %44, ptr %45, align 4, !tbaa !26
  br label %46

46:                                               ; preds = %42, %33
  br label %47

47:                                               ; preds = %46, %1
  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

; 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 = !{!"_ZTSN5daisy6SwitchE", !10, i64 0, !13, i64 4, !14, i64 8, !15, i64 12, !7, i64 28, !13, i64 29, !20, i64 32}
!13 = !{!"bool", !7, i64 0}
!14 = !{!"_ZTSN5daisy6Switch4TypeE", !7, i64 0}
!15 = !{!"_ZTS8dsy_gpio", !16, i64 0, !18, i64 8, !19, i64 12}
!16 = !{!"_ZTS12dsy_gpio_pin", !17, i64 0, !7, i64 4}
!17 = !{!"_ZTS13dsy_gpio_port", !7, i64 0}
!18 = !{!"_ZTS13dsy_gpio_mode", !7, i64 0}
!19 = !{!"_ZTS13dsy_gpio_pull", !7, i64 0}
!20 = !{!"float", !7, i64 0}
!21 = !{!12, !10, i64 0}
!22 = !{!12, !7, i64 28}
!23 = !{!12, !13, i64 29}
!24 = !{i8 0, i8 2}
!25 = !{}
!26 = !{!12, !20, i64 32}


; 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 @_ZN5daisy6Switch8DebounceEv(ptr noundef nonnull align 4 dereferenceable(36) %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 !18
  %.not = icmp eq i32 %2, %4
  br i1 %.not, label %22, label %5

5:                                                ; preds = %1
  store i32 %2, ptr %0, align 4, !tbaa !18
  store i8 1, ptr %3, align 4, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %0, i64 28
  %7 = load i8, ptr %6, align 4, !tbaa !19
  %8 = shl i8 %7, 1
  %9 = getelementptr inbounds i8, ptr %0, i64 29
  %10 = load i8, ptr %9, align 1, !tbaa !20, !range !21, !noundef !22
  %11 = trunc nuw i8 %10 to i1
  %12 = getelementptr inbounds i8, ptr %0, i64 12
  %13 = tail call zeroext i8 @dsy_gpio_read(ptr noundef nonnull %12)
  %.not2 = icmp eq i8 %13, 0
  %14 = zext i1 %.not2 to i8
  %15 = select i1 %11, i8 %14, i8 %13
  %16 = or i8 %15, %8
  store i8 %16, ptr %6, align 4, !tbaa !19
  %17 = icmp eq i8 %16, 127
  br i1 %17, label %18, label %22

18:                                               ; preds = %5
  %19 = tail call noundef i32 @_ZN5daisy6System6GetNowEv()
  %20 = uitofp i32 %19 to float
  %21 = getelementptr inbounds i8, ptr %0, i64 32
  store float %20, ptr %21, align 4, !tbaa !23
  br label %22

22:                                               ; preds = %5, %18, %1
  ret void
}

declare zeroext i8 @dsy_gpio_read(ptr noundef) 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 = !{!"_ZTSN5daisy6SwitchE", !7, i64 0, !10, i64 4, !11, i64 8, !12, i64 12, !8, i64 28, !10, i64 29, !17, i64 32}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"bool", !8, i64 0}
!11 = !{!"_ZTSN5daisy6Switch4TypeE", !8, i64 0}
!12 = !{!"_ZTS8dsy_gpio", !13, i64 0, !15, i64 8, !16, i64 12}
!13 = !{!"_ZTS12dsy_gpio_pin", !14, i64 0, !8, i64 4}
!14 = !{!"_ZTS13dsy_gpio_port", !8, i64 0}
!15 = !{!"_ZTS13dsy_gpio_mode", !8, i64 0}
!16 = !{!"_ZTS13dsy_gpio_pull", !8, i64 0}
!17 = !{!"float", !8, i64 0}
!18 = !{!6, !7, i64 0}
!19 = !{!6, !8, i64 28}
!20 = !{!6, !10, i64 29}
!21 = !{i8 0, i8 2}
!22 = !{}
!23 = !{!6, !17, i64 32}


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