; LLVM IR from googlecreativelab/open-nsynth-super :: firmware/src/debounce.ll (ZN8Debounce6UpdateEi)

; 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.Debounce = type { i8, i32 }

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN8Debounce6UpdateEi(ptr noundef nonnull align 4 dereferenceable(8) %0, i32 noundef %1) #0 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !9
  %5 = load ptr, ptr %3, align 8
  %6 = getelementptr inbounds %class.Debounce, ptr %5, i32 0, i32 0
  %7 = load i8, ptr %6, align 4, !tbaa !11
  %8 = zext i8 %7 to i32
  %9 = shl i32 %8, 1
  %10 = trunc i32 %9 to i8
  store i8 %10, ptr %6, align 4, !tbaa !11
  %11 = load i32, ptr %4, align 4, !tbaa !9
  %12 = and i32 %11, 1
  %13 = getelementptr inbounds %class.Debounce, ptr %5, i32 0, i32 0
  %14 = load i8, ptr %13, align 4, !tbaa !11
  %15 = zext i8 %14 to i32
  %16 = or i32 %15, %12
  %17 = trunc i32 %16 to i8
  store i8 %17, ptr %13, align 4, !tbaa !11
  %18 = getelementptr inbounds %class.Debounce, ptr %5, i32 0, i32 0
  %19 = load i8, ptr %18, align 4, !tbaa !11
  %20 = zext i8 %19 to i32
  %21 = and i32 %20, 15
  %22 = trunc i32 %21 to i8
  store i8 %22, ptr %18, align 4, !tbaa !11
  %23 = getelementptr inbounds %class.Debounce, ptr %5, i32 0, i32 0
  %24 = load i8, ptr %23, align 4, !tbaa !11
  %25 = zext i8 %24 to i32
  %26 = icmp eq i32 %25, 0
  br i1 %26, label %27, label %29

27:                                               ; preds = %2
  %28 = getelementptr inbounds %class.Debounce, ptr %5, i32 0, i32 1
  store i32 0, ptr %28, align 4, !tbaa !13
  br label %37

29:                                               ; preds = %2
  %30 = getelementptr inbounds %class.Debounce, ptr %5, i32 0, i32 0
  %31 = load i8, ptr %30, align 4, !tbaa !11
  %32 = zext i8 %31 to i32
  %33 = icmp eq i32 %32, 15
  br i1 %33, label %34, label %36

34:                                               ; preds = %29
  %35 = getelementptr inbounds %class.Debounce, ptr %5, i32 0, i32 1
  store i32 1, ptr %35, align 4, !tbaa !13
  br label %36

36:                                               ; preds = %34, %29
  br label %37

37:                                               ; preds = %36, %27
  ret void
}

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

!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, !7, i64 0}
!12 = !{!"_ZTS8Debounce", !7, i64 0, !10, i64 4}
!13 = !{!12, !10, i64 4}


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

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: readwrite) uwtable
define dso_local void @_ZN8Debounce6UpdateEi(ptr nocapture noundef nonnull align 4 dereferenceable(8) %0, i32 noundef %1) local_unnamed_addr #0 align 2 {
  %3 = load i8, ptr %0, align 4, !tbaa !5
  %4 = shl i8 %3, 1
  %5 = trunc i32 %1 to i8
  %6 = and i8 %5, 1
  %.masked = and i8 %4, 14
  %7 = or disjoint i8 %.masked, %6
  store i8 %7, ptr %0, align 4, !tbaa !5
  switch i8 %7, label %10 [
    i8 0, label %.sink.split
    i8 15, label %8
  ]

8:                                                ; preds = %2
  br label %.sink.split

.sink.split:                                      ; preds = %2, %8
  %.sink = phi i32 [ 1, %8 ], [ 0, %2 ]
  %9 = getelementptr inbounds i8, ptr %0, i64 4
  store i32 %.sink, ptr %9, align 4, !tbaa !10
  br label %10

10:                                               ; preds = %.sink.split, %2
  ret void
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: readwrite) 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, !7, i64 0}
!6 = !{!"_ZTS8Debounce", !7, i64 0, !9, i64 4}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!"int", !7, i64 0}
!10 = !{!6, !9, i64 4}


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