; LLVM IR from Ryuk17/SpeechAlgorithms :: SpeechCodec/G711/src (g711)

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

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

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

; Function Attrs: nounwind uwtable
define dso_local signext i16 @ulaw2linear(i8 noundef zeroext %0) #1 {
  %2 = alloca i8, align 1
  %3 = alloca i16, align 2
  store i8 %0, ptr %2, align 1, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 2, ptr %3) #2
  %4 = load i8, ptr %2, align 1, !tbaa !5
  %5 = zext i8 %4 to i32
  %6 = xor i32 %5, -1
  %7 = trunc i32 %6 to i8
  store i8 %7, ptr %2, align 1, !tbaa !5
  %8 = load i8, ptr %2, align 1, !tbaa !5
  %9 = zext i8 %8 to i32
  %10 = and i32 %9, 15
  %11 = shl i32 %10, 3
  %12 = add nsw i32 %11, 132
  %13 = trunc i32 %12 to i16
  store i16 %13, ptr %3, align 2, !tbaa !8
  %14 = load i8, ptr %2, align 1, !tbaa !5
  %15 = zext i8 %14 to i32
  %16 = and i32 %15, 112
  %17 = lshr i32 %16, 4
  %18 = load i16, ptr %3, align 2, !tbaa !8
  %19 = sext i16 %18 to i32
  %20 = shl i32 %19, %17
  %21 = trunc i32 %20 to i16
  store i16 %21, ptr %3, align 2, !tbaa !8
  %22 = load i8, ptr %2, align 1, !tbaa !5
  %23 = zext i8 %22 to i32
  %24 = and i32 %23, 128
  %25 = icmp ne i32 %24, 0
  br i1 %25, label %26, label %30

26:                                               ; preds = %1
  %27 = load i16, ptr %3, align 2, !tbaa !8
  %28 = sext i16 %27 to i32
  %29 = sub nsw i32 132, %28
  br label %34

30:                                               ; preds = %1
  %31 = load i16, ptr %3, align 2, !tbaa !8
  %32 = sext i16 %31 to i32
  %33 = sub nsw i32 %32, 132
  br label %34

34:                                               ; preds = %30, %26
  %35 = phi i32 [ %29, %26 ], [ %33, %30 ]
  %36 = trunc i32 %35 to i16
  call void @llvm.lifetime.end.p0(i64 2, ptr %3) #2
  ret i16 %36
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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"}
!8 = !{!9, !9, i64 0}
!9 = !{!"short", !6, 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 nofree norecurse nosync nounwind willreturn memory(none) uwtable
define dso_local signext range(i16 -32124, 32125) i16 @ulaw2linear(i8 noundef zeroext %0) local_unnamed_addr #0 {
  %2 = xor i8 %0, -1
  %.tr = zext i8 %2 to i16
  %3 = shl nuw nsw i16 %.tr, 3
  %4 = and i16 %3, 120
  %5 = or disjoint i16 %4, 132
  %6 = lshr i8 %2, 4
  %7 = and i8 %6, 7
  %8 = zext nneg i8 %7 to i16
  %9 = shl nuw nsw i16 %5, %8
  %.not = icmp slt i8 %0, 0
  %10 = sub nsw i16 132, %9
  %11 = add nsw i16 %9, -132
  %12 = select i1 %.not, i16 %11, i16 %10
  ret i16 %12
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(none) 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)"}


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