; LLVM IR from FedericaPaoli1/stm32-speech-recognition-and-traduction :: Drivers/BSP/Components/cs43l22 (cs43l22)

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

@OutputDev = external dso_local global i8, align 1

; Function Attrs: nounwind uwtable
define dso_local i32 @cs43l22_SetOutputMode(i16 noundef zeroext %0, i8 noundef zeroext %1) #0 {
  %3 = alloca i16, align 2
  %4 = alloca i8, align 1
  %5 = alloca i32, align 4
  store i16 %0, ptr %3, align 2, !tbaa !5
  store i8 %1, ptr %4, align 1, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #2
  store i32 0, ptr %5, align 4, !tbaa !10
  %6 = load i8, ptr %4, align 1, !tbaa !9
  %7 = zext i8 %6 to i32
  switch i32 %7, label %36 [
    i32 1, label %8
    i32 2, label %15
    i32 3, label %22
    i32 4, label %29
  ]

8:                                                ; preds = %2
  %9 = load i16, ptr %3, align 2, !tbaa !5
  %10 = trunc i16 %9 to i8
  %11 = call zeroext i8 @CODEC_IO_Write(i8 noundef zeroext %10, i8 noundef zeroext 4, i8 noundef zeroext -6)
  %12 = zext i8 %11 to i32
  %13 = load i32, ptr %5, align 4, !tbaa !10
  %14 = add i32 %13, %12
  store i32 %14, ptr %5, align 4, !tbaa !10
  store volatile i8 -6, ptr @OutputDev, align 1, !tbaa !9
  br label %43

15:                                               ; preds = %2
  %16 = load i16, ptr %3, align 2, !tbaa !5
  %17 = trunc i16 %16 to i8
  %18 = call zeroext i8 @CODEC_IO_Write(i8 noundef zeroext %17, i8 noundef zeroext 4, i8 noundef zeroext -81)
  %19 = zext i8 %18 to i32
  %20 = load i32, ptr %5, align 4, !tbaa !10
  %21 = add i32 %20, %19
  store i32 %21, ptr %5, align 4, !tbaa !10
  store volatile i8 -81, ptr @OutputDev, align 1, !tbaa !9
  br label %43

22:                                               ; preds = %2
  %23 = load i16, ptr %3, align 2, !tbaa !5
  %24 = trunc i16 %23 to i8
  %25 = call zeroext i8 @CODEC_IO_Write(i8 noundef zeroext %24, i8 noundef zeroext 4, i8 noundef zeroext -86)
  %26 = zext i8 %25 to i32
  %27 = load i32, ptr %5, align 4, !tbaa !10
  %28 = add i32 %27, %26
  store i32 %28, ptr %5, align 4, !tbaa !10
  store volatile i8 -86, ptr @OutputDev, align 1, !tbaa !9
  br label %43

29:                                               ; preds = %2
  %30 = load i16, ptr %3, align 2, !tbaa !5
  %31 = trunc i16 %30 to i8
  %32 = call zeroext i8 @CODEC_IO_Write(i8 noundef zeroext %31, i8 noundef zeroext 4, i8 noundef zeroext 5)
  %33 = zext i8 %32 to i32
  %34 = load i32, ptr %5, align 4, !tbaa !10
  %35 = add i32 %34, %33
  store i32 %35, ptr %5, align 4, !tbaa !10
  store volatile i8 5, ptr @OutputDev, align 1, !tbaa !9
  br label %43

36:                                               ; preds = %2
  %37 = load i16, ptr %3, align 2, !tbaa !5
  %38 = trunc i16 %37 to i8
  %39 = call zeroext i8 @CODEC_IO_Write(i8 noundef zeroext %38, i8 noundef zeroext 4, i8 noundef zeroext 5)
  %40 = zext i8 %39 to i32
  %41 = load i32, ptr %5, align 4, !tbaa !10
  %42 = add i32 %41, %40
  store i32 %42, ptr %5, align 4, !tbaa !10
  store volatile i8 5, ptr @OutputDev, align 1, !tbaa !9
  br label %43

43:                                               ; preds = %36, %29, %22, %15, %8
  %44 = load i32, ptr %5, align 4, !tbaa !10
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  ret i32 %44
}

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

; Function Attrs: nounwind uwtable
declare hidden zeroext i8 @CODEC_IO_Write(i8 noundef zeroext, i8 noundef zeroext, i8 noundef zeroext) #0

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

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

@OutputDev = external dso_local global i8, align 1

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 256) i32 @cs43l22_SetOutputMode(i16 noundef zeroext %0, i8 noundef zeroext %1) local_unnamed_addr #0 {
  %3 = icmp ult i8 %1, 5
  %switch.cast = zext i8 %1 to i40
  %switch.shiftamt = shl nuw nsw i40 %switch.cast, 3
  %switch.downshift = lshr i40 24338496005, %switch.shiftamt
  %switch.masked = trunc i40 %switch.downshift to i8
  %.sink12 = select i1 %3, i8 %switch.masked, i8 5
  %4 = trunc i16 %0 to i8
  %5 = tail call zeroext i8 @CODEC_IO_Write(i8 noundef zeroext %4, i8 noundef zeroext 4, i8 noundef zeroext %.sink12)
  store volatile i8 %.sink12, ptr @OutputDev, align 1, !tbaa !5
  %.0 = zext i8 %5 to i32
  ret i32 %.0
}

; Function Attrs: nounwind uwtable
declare hidden zeroext i8 @CODEC_IO_Write(i8 noundef zeroext, i8 noundef zeroext, i8 noundef zeroext) local_unnamed_addr #0

attributes #0 = { 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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}


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