; LLVM IR from lichen-community-systems/signaletic :: hosts/daisy/vendor/libDaisy/src/dev (codec_wm8731)

; 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::Wm8731" = type <{ %"class.daisy::I2CHandle", %"struct.daisy::Wm8731::Config", i8, [3 x i8] }>
%"class.daisy::I2CHandle" = type { ptr }
%"struct.daisy::Wm8731::Config" = type { i8, i8, i8, i32, i32 }

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

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN5daisy6Wm873120WriteControlRegisterEht(ptr noundef nonnull align 8 dereferenceable(21) %0, i8 noundef zeroext %1, i16 noundef zeroext %2) #1 align 2 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca i8, align 1
  %7 = alloca i16, align 2
  %8 = alloca i8, align 1
  %9 = alloca i8, align 1
  %10 = alloca [2 x i8], align 1
  %11 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i8 %1, ptr %6, align 1, !tbaa !9
  store i16 %2, ptr %7, align 2, !tbaa !10
  %12 = load ptr, ptr %5, align 8
  call void @llvm.lifetime.start.p0(i64 1, ptr %8) #3
  %13 = load i8, ptr %6, align 1, !tbaa !9
  %14 = zext i8 %13 to i32
  %15 = shl i32 %14, 1
  %16 = and i32 %15, 254
  %17 = load i16, ptr %7, align 2, !tbaa !10
  %18 = zext i16 %17 to i32
  %19 = ashr i32 %18, 8
  %20 = and i32 %19, 1
  %21 = or i32 %16, %20
  %22 = trunc i32 %21 to i8
  store i8 %22, ptr %8, align 1, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 1, ptr %9) #3
  %23 = load i16, ptr %7, align 2, !tbaa !10
  %24 = zext i16 %23 to i32
  %25 = and i32 %24, 255
  %26 = trunc i32 %25 to i8
  store i8 %26, ptr %9, align 1, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 2, ptr %10) #3
  %27 = load i8, ptr %8, align 1, !tbaa !9
  store i8 %27, ptr %10, align 1, !tbaa !9
  %28 = getelementptr inbounds i8, ptr %10, i64 1
  %29 = load i8, ptr %9, align 1, !tbaa !9
  store i8 %29, ptr %28, align 1, !tbaa !9
  %30 = getelementptr inbounds %"class.daisy::Wm8731", ptr %12, i32 0, i32 0
  %31 = getelementptr inbounds %"class.daisy::Wm8731", ptr %12, i32 0, i32 2
  %32 = load i8, ptr %31, align 4, !tbaa !12
  %33 = zext i8 %32 to i16
  %34 = getelementptr inbounds [2 x i8], ptr %10, i64 0, i64 0
  %35 = call noundef i32 @_ZN5daisy9I2CHandle16TransmitBlockingEtPhtj(ptr noundef nonnull align 8 dereferenceable(8) %30, i16 noundef zeroext %33, ptr noundef %34, i16 noundef zeroext 2, i32 noundef 250)
  %36 = icmp ne i32 %35, 0
  br i1 %36, label %37, label %38

37:                                               ; preds = %3
  store i32 1, ptr %4, align 4
  store i32 1, ptr %11, align 4
  br label %39

38:                                               ; preds = %3
  call void @_ZN5daisy6System5DelayEj(i32 noundef 10)
  store i32 0, ptr %4, align 4
  store i32 1, ptr %11, align 4
  br label %39

39:                                               ; preds = %38, %37
  call void @llvm.lifetime.end.p0(i64 2, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 1, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 1, ptr %8) #3
  %40 = load i32, ptr %4, align 4
  ret i32 %40
}

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

declare noundef i32 @_ZN5daisy9I2CHandle16TransmitBlockingEtPhtj(ptr noundef nonnull align 8 dereferenceable(8), i16 noundef zeroext, ptr noundef, i16 noundef zeroext, i32 noundef) #2

declare void @_ZN5daisy6System5DelayEj(i32 noundef) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { "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 = !{!7, !7, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"short", !7, i64 0}
!12 = !{!13, !7, i64 20}
!13 = !{!"_ZTSN5daisy6Wm8731E", !14, i64 0, !15, i64 8, !7, i64 20}
!14 = !{!"_ZTSN5daisy9I2CHandleE", !6, i64 0}
!15 = !{!"_ZTSN5daisy6Wm87316ConfigE", !16, i64 0, !16, i64 1, !16, i64 2, !17, i64 4, !18, i64 8}
!16 = !{!"bool", !7, i64 0}
!17 = !{!"_ZTSN5daisy6Wm87316Config6FormatE", !7, i64 0}
!18 = !{!"_ZTSN5daisy6Wm87316Config10WordLengthE", !7, i64 0}


; 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 nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: mustprogress uwtable
define dso_local noundef range(i32 0, 2) i32 @_ZN5daisy6Wm873120WriteControlRegisterEht(ptr noundef nonnull align 8 dereferenceable(21) %0, i8 noundef zeroext %1, i16 noundef zeroext %2) local_unnamed_addr #1 align 2 {
  %4 = alloca [2 x i8], align 1
  %5 = zext i8 %1 to i16
  %6 = shl nuw nsw i16 %5, 1
  %7 = lshr i16 %2, 8
  %8 = and i16 %7, 1
  %9 = or disjoint i16 %8, %6
  %10 = trunc i16 %9 to i8
  %11 = trunc i16 %2 to i8
  call void @llvm.lifetime.start.p0(i64 2, ptr nonnull %4) #3
  store i8 %10, ptr %4, align 1, !tbaa !5
  %12 = getelementptr inbounds i8, ptr %4, i64 1
  store i8 %11, ptr %12, align 1, !tbaa !5
  %13 = getelementptr inbounds i8, ptr %0, i64 20
  %14 = load i8, ptr %13, align 4, !tbaa !8
  %15 = zext i8 %14 to i16
  %16 = call noundef i32 @_ZN5daisy9I2CHandle16TransmitBlockingEtPhtj(ptr noundef nonnull align 8 dereferenceable(8) %0, i16 noundef zeroext %15, ptr noundef nonnull %4, i16 noundef zeroext 2, i32 noundef 250)
  %.not = icmp eq i32 %16, 0
  br i1 %.not, label %17, label %18

17:                                               ; preds = %3
  call void @_ZN5daisy6System5DelayEj(i32 noundef 10)
  br label %18

18:                                               ; preds = %3, %17
  %.0 = phi i32 [ 0, %17 ], [ 1, %3 ]
  call void @llvm.lifetime.end.p0(i64 2, ptr nonnull %4) #3
  ret i32 %.0
}

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

declare noundef i32 @_ZN5daisy9I2CHandle16TransmitBlockingEtPhtj(ptr noundef nonnull align 8 dereferenceable(8), i16 noundef zeroext, ptr noundef, i16 noundef zeroext, i32 noundef) local_unnamed_addr #2

declare void @_ZN5daisy6System5DelayEj(i32 noundef) local_unnamed_addr #2

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { "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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C++ TBAA"}
!8 = !{!9, !6, i64 20}
!9 = !{!"_ZTSN5daisy6Wm8731E", !10, i64 0, !12, i64 8, !6, i64 20}
!10 = !{!"_ZTSN5daisy9I2CHandleE", !11, i64 0}
!11 = !{!"any pointer", !6, i64 0}
!12 = !{!"_ZTSN5daisy6Wm87316ConfigE", !13, i64 0, !13, i64 1, !13, i64 2, !14, i64 4, !15, i64 8}
!13 = !{!"bool", !6, i64 0}
!14 = !{!"_ZTSN5daisy6Wm87316Config6FormatE", !6, i64 0}
!15 = !{!"_ZTSN5daisy6Wm87316Config10WordLengthE", !6, i64 0}


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