; 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_Init(i16 noundef zeroext %0, i16 noundef zeroext %1, i8 noundef zeroext %2, i32 noundef %3) #0 {
  %5 = alloca i16, align 2
  %6 = alloca i16, align 2
  %7 = alloca i8, align 1
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  store i16 %0, ptr %5, align 2, !tbaa !5
  store i16 %1, ptr %6, align 2, !tbaa !5
  store i8 %2, ptr %7, align 1, !tbaa !9
  store i32 %3, ptr %8, align 4, !tbaa !10
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  store i32 0, ptr %9, align 4, !tbaa !10
  call void @AUDIO_IO_Init()
  %10 = load i16, ptr %5, align 2, !tbaa !5
  %11 = trunc i16 %10 to i8
  %12 = call zeroext i8 @CODEC_IO_Write(i8 noundef zeroext %11, i8 noundef zeroext 2, i8 noundef zeroext 1)
  %13 = zext i8 %12 to i32
  %14 = load i32, ptr %9, align 4, !tbaa !10
  %15 = add i32 %14, %13
  store i32 %15, ptr %9, align 4, !tbaa !10
  %16 = load i16, ptr %6, align 2, !tbaa !5
  %17 = zext i16 %16 to i32
  switch i32 %17, label %22 [
    i32 1, label %18
    i32 2, label %19
    i32 3, label %20
    i32 4, label %21
  ]

18:                                               ; preds = %4
  store volatile i8 -6, ptr @OutputDev, align 1, !tbaa !9
  br label %23

19:                                               ; preds = %4
  store volatile i8 -81, ptr @OutputDev, align 1, !tbaa !9
  br label %23

20:                                               ; preds = %4
  store volatile i8 -86, ptr @OutputDev, align 1, !tbaa !9
  br label %23

21:                                               ; preds = %4
  store volatile i8 5, ptr @OutputDev, align 1, !tbaa !9
  br label %23

22:                                               ; preds = %4
  store volatile i8 5, ptr @OutputDev, align 1, !tbaa !9
  br label %23

23:                                               ; preds = %22, %21, %20, %19, %18
  %24 = load i16, ptr %5, align 2, !tbaa !5
  %25 = trunc i16 %24 to i8
  %26 = load volatile i8, ptr @OutputDev, align 1, !tbaa !9
  %27 = call zeroext i8 @CODEC_IO_Write(i8 noundef zeroext %25, i8 noundef zeroext 4, i8 noundef zeroext %26)
  %28 = zext i8 %27 to i32
  %29 = load i32, ptr %9, align 4, !tbaa !10
  %30 = add i32 %29, %28
  store i32 %30, ptr %9, align 4, !tbaa !10
  %31 = load i16, ptr %5, align 2, !tbaa !5
  %32 = trunc i16 %31 to i8
  %33 = call zeroext i8 @CODEC_IO_Write(i8 noundef zeroext %32, i8 noundef zeroext 5, i8 noundef zeroext -127)
  %34 = zext i8 %33 to i32
  %35 = load i32, ptr %9, align 4, !tbaa !10
  %36 = add i32 %35, %34
  store i32 %36, ptr %9, align 4, !tbaa !10
  %37 = load i16, ptr %5, align 2, !tbaa !5
  %38 = trunc i16 %37 to i8
  %39 = call zeroext i8 @CODEC_IO_Write(i8 noundef zeroext %38, i8 noundef zeroext 6, i8 noundef zeroext 4)
  %40 = zext i8 %39 to i32
  %41 = load i32, ptr %9, align 4, !tbaa !10
  %42 = add i32 %41, %40
  store i32 %42, ptr %9, align 4, !tbaa !10
  %43 = load i16, ptr %5, align 2, !tbaa !5
  %44 = load i8, ptr %7, align 1, !tbaa !9
  %45 = call i32 @cs43l22_SetVolume(i16 noundef zeroext %43, i8 noundef zeroext %44)
  %46 = load i32, ptr %9, align 4, !tbaa !10
  %47 = add i32 %46, %45
  store i32 %47, ptr %9, align 4, !tbaa !10
  %48 = load i16, ptr %6, align 2, !tbaa !5
  %49 = zext i16 %48 to i32
  %50 = icmp ne i32 %49, 2
  br i1 %50, label %51, label %70

51:                                               ; preds = %23
  %52 = load i16, ptr %5, align 2, !tbaa !5
  %53 = trunc i16 %52 to i8
  %54 = call zeroext i8 @CODEC_IO_Write(i8 noundef zeroext %53, i8 noundef zeroext 15, i8 noundef zeroext 6)
  %55 = zext i8 %54 to i32
  %56 = load i32, ptr %9, align 4, !tbaa !10
  %57 = add i32 %56, %55
  store i32 %57, ptr %9, align 4, !tbaa !10
  %58 = load i16, ptr %5, align 2, !tbaa !5
  %59 = trunc i16 %58 to i8
  %60 = call zeroext i8 @CODEC_IO_Write(i8 noundef zeroext %59, i8 noundef zeroext 36, i8 noundef zeroext 0)
  %61 = zext i8 %60 to i32
  %62 = load i32, ptr %9, align 4, !tbaa !10
  %63 = add i32 %62, %61
  store i32 %63, ptr %9, align 4, !tbaa !10
  %64 = load i16, ptr %5, align 2, !tbaa !5
  %65 = trunc i16 %64 to i8
  %66 = call zeroext i8 @CODEC_IO_Write(i8 noundef zeroext %65, i8 noundef zeroext 37, i8 noundef zeroext 0)
  %67 = zext i8 %66 to i32
  %68 = load i32, ptr %9, align 4, !tbaa !10
  %69 = add i32 %68, %67
  store i32 %69, ptr %9, align 4, !tbaa !10
  br label %70

70:                                               ; preds = %51, %23
  %71 = load i16, ptr %5, align 2, !tbaa !5
  %72 = trunc i16 %71 to i8
  %73 = call zeroext i8 @CODEC_IO_Write(i8 noundef zeroext %72, i8 noundef zeroext 10, i8 noundef zeroext 0)
  %74 = zext i8 %73 to i32
  %75 = load i32, ptr %9, align 4, !tbaa !10
  %76 = add i32 %75, %74
  store i32 %76, ptr %9, align 4, !tbaa !10
  %77 = load i16, ptr %5, align 2, !tbaa !5
  %78 = trunc i16 %77 to i8
  %79 = call zeroext i8 @CODEC_IO_Write(i8 noundef zeroext %78, i8 noundef zeroext 14, i8 noundef zeroext 4)
  %80 = zext i8 %79 to i32
  %81 = load i32, ptr %9, align 4, !tbaa !10
  %82 = add i32 %81, %80
  store i32 %82, ptr %9, align 4, !tbaa !10
  %83 = load i16, ptr %5, align 2, !tbaa !5
  %84 = trunc i16 %83 to i8
  %85 = call zeroext i8 @CODEC_IO_Write(i8 noundef zeroext %84, i8 noundef zeroext 39, i8 noundef zeroext 0)
  %86 = zext i8 %85 to i32
  %87 = load i32, ptr %9, align 4, !tbaa !10
  %88 = add i32 %87, %86
  store i32 %88, ptr %9, align 4, !tbaa !10
  %89 = load i16, ptr %5, align 2, !tbaa !5
  %90 = trunc i16 %89 to i8
  %91 = call zeroext i8 @CODEC_IO_Write(i8 noundef zeroext %90, i8 noundef zeroext 31, i8 noundef zeroext 15)
  %92 = zext i8 %91 to i32
  %93 = load i32, ptr %9, align 4, !tbaa !10
  %94 = add i32 %93, %92
  store i32 %94, ptr %9, align 4, !tbaa !10
  %95 = load i16, ptr %5, align 2, !tbaa !5
  %96 = trunc i16 %95 to i8
  %97 = call zeroext i8 @CODEC_IO_Write(i8 noundef zeroext %96, i8 noundef zeroext 26, i8 noundef zeroext 10)
  %98 = zext i8 %97 to i32
  %99 = load i32, ptr %9, align 4, !tbaa !10
  %100 = add i32 %99, %98
  store i32 %100, ptr %9, align 4, !tbaa !10
  %101 = load i16, ptr %5, align 2, !tbaa !5
  %102 = trunc i16 %101 to i8
  %103 = call zeroext i8 @CODEC_IO_Write(i8 noundef zeroext %102, i8 noundef zeroext 27, i8 noundef zeroext 10)
  %104 = zext i8 %103 to i32
  %105 = load i32, ptr %9, align 4, !tbaa !10
  %106 = add i32 %105, %104
  store i32 %106, ptr %9, align 4, !tbaa !10
  %107 = load i32, ptr %9, align 4, !tbaa !10
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  ret i32 %107
}

; Function Attrs: nounwind uwtable
declare dso_local i32 @cs43l22_SetVolume(i16 noundef zeroext, i8 noundef zeroext) #0

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

declare void @AUDIO_IO_Init() #2

; 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 = { "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 = !{!"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 i32 @cs43l22_Init(i16 noundef zeroext %0, i16 noundef zeroext %1, i8 noundef zeroext %2, i32 noundef %3) local_unnamed_addr #0 {
  tail call void @AUDIO_IO_Init() #2
  %5 = trunc i16 %0 to i8
  %6 = tail call zeroext i8 @CODEC_IO_Write(i8 noundef zeroext %5, i8 noundef zeroext 2, i8 noundef zeroext 1)
  %7 = zext i8 %6 to i32
  %8 = icmp ult i16 %1, 5
  %switch.cast = zext i16 %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
  %.sink = select i1 %8, i8 %switch.masked, i8 5
  store volatile i8 %.sink, ptr @OutputDev, align 1, !tbaa !5
  %9 = load volatile i8, ptr @OutputDev, align 1, !tbaa !5
  %10 = tail call zeroext i8 @CODEC_IO_Write(i8 noundef zeroext %5, i8 noundef zeroext 4, i8 noundef zeroext %9)
  %11 = zext i8 %10 to i32
  %12 = add nuw nsw i32 %11, %7
  %13 = tail call zeroext i8 @CODEC_IO_Write(i8 noundef zeroext %5, i8 noundef zeroext 5, i8 noundef zeroext -127)
  %14 = zext i8 %13 to i32
  %15 = add nuw nsw i32 %12, %14
  %16 = tail call zeroext i8 @CODEC_IO_Write(i8 noundef zeroext %5, i8 noundef zeroext 6, i8 noundef zeroext 4)
  %17 = zext i8 %16 to i32
  %18 = add nuw nsw i32 %15, %17
  %19 = tail call i32 @cs43l22_SetVolume(i16 noundef zeroext %0, i8 noundef zeroext %2)
  %20 = add i32 %18, %19
  %.not = icmp eq i16 %1, 2
  br i1 %.not, label %31, label %21

21:                                               ; preds = %4
  %22 = tail call zeroext i8 @CODEC_IO_Write(i8 noundef zeroext %5, i8 noundef zeroext 15, i8 noundef zeroext 6)
  %23 = zext i8 %22 to i32
  %24 = add i32 %20, %23
  %25 = tail call zeroext i8 @CODEC_IO_Write(i8 noundef zeroext %5, i8 noundef zeroext 36, i8 noundef zeroext 0)
  %26 = zext i8 %25 to i32
  %27 = add i32 %24, %26
  %28 = tail call zeroext i8 @CODEC_IO_Write(i8 noundef zeroext %5, i8 noundef zeroext 37, i8 noundef zeroext 0)
  %29 = zext i8 %28 to i32
  %30 = add i32 %27, %29
  br label %31

31:                                               ; preds = %21, %4
  %.0 = phi i32 [ %30, %21 ], [ %20, %4 ]
  %32 = tail call zeroext i8 @CODEC_IO_Write(i8 noundef zeroext %5, i8 noundef zeroext 10, i8 noundef zeroext 0)
  %33 = zext i8 %32 to i32
  %34 = add i32 %.0, %33
  %35 = tail call zeroext i8 @CODEC_IO_Write(i8 noundef zeroext %5, i8 noundef zeroext 14, i8 noundef zeroext 4)
  %36 = zext i8 %35 to i32
  %37 = add i32 %34, %36
  %38 = tail call zeroext i8 @CODEC_IO_Write(i8 noundef zeroext %5, i8 noundef zeroext 39, i8 noundef zeroext 0)
  %39 = zext i8 %38 to i32
  %40 = add i32 %37, %39
  %41 = tail call zeroext i8 @CODEC_IO_Write(i8 noundef zeroext %5, i8 noundef zeroext 31, i8 noundef zeroext 15)
  %42 = zext i8 %41 to i32
  %43 = add i32 %40, %42
  %44 = tail call zeroext i8 @CODEC_IO_Write(i8 noundef zeroext %5, i8 noundef zeroext 26, i8 noundef zeroext 10)
  %45 = zext i8 %44 to i32
  %46 = add i32 %43, %45
  %47 = tail call zeroext i8 @CODEC_IO_Write(i8 noundef zeroext %5, i8 noundef zeroext 27, i8 noundef zeroext 10)
  %48 = zext i8 %47 to i32
  %49 = add i32 %46, %48
  ret i32 %49
}

; Function Attrs: nounwind uwtable
declare dso_local i32 @cs43l22_SetVolume(i16 noundef zeroext, i8 noundef zeroext) local_unnamed_addr #0

declare void @AUDIO_IO_Init() local_unnamed_addr #1

; 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" }
attributes #1 = { "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 = { 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/C++ TBAA"}


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