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

@seg_aend = external hidden global [8 x i16], align 16

; Function Attrs: nounwind uwtable
define dso_local zeroext i8 @linear2alaw(i16 noundef signext %0) #0 {
  %2 = alloca i8, align 1
  %3 = alloca i16, align 2
  %4 = alloca i16, align 2
  %5 = alloca i16, align 2
  %6 = alloca i8, align 1
  %7 = alloca i32, align 4
  store i16 %0, ptr %3, align 2, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 2, ptr %4) #2
  call void @llvm.lifetime.start.p0(i64 2, ptr %5) #2
  call void @llvm.lifetime.start.p0(i64 1, ptr %6) #2
  %8 = load i16, ptr %3, align 2, !tbaa !5
  %9 = sext i16 %8 to i32
  %10 = ashr i32 %9, 3
  %11 = trunc i32 %10 to i16
  store i16 %11, ptr %3, align 2, !tbaa !5
  %12 = load i16, ptr %3, align 2, !tbaa !5
  %13 = sext i16 %12 to i32
  %14 = icmp sge i32 %13, 0
  br i1 %14, label %15, label %16

15:                                               ; preds = %1
  store i16 213, ptr %4, align 2, !tbaa !5
  br label %22

16:                                               ; preds = %1
  store i16 85, ptr %4, align 2, !tbaa !5
  %17 = load i16, ptr %3, align 2, !tbaa !5
  %18 = sext i16 %17 to i32
  %19 = sub nsw i32 0, %18
  %20 = sub nsw i32 %19, 1
  %21 = trunc i32 %20 to i16
  store i16 %21, ptr %3, align 2, !tbaa !5
  br label %22

22:                                               ; preds = %16, %15
  %23 = load i16, ptr %3, align 2, !tbaa !5
  %24 = call signext i16 @search(i16 noundef signext %23, ptr noundef @seg_aend, i16 noundef signext 8)
  store i16 %24, ptr %5, align 2, !tbaa !5
  %25 = load i16, ptr %5, align 2, !tbaa !5
  %26 = sext i16 %25 to i32
  %27 = icmp sge i32 %26, 8
  br i1 %27, label %28, label %33

28:                                               ; preds = %22
  %29 = load i16, ptr %4, align 2, !tbaa !5
  %30 = sext i16 %29 to i32
  %31 = xor i32 127, %30
  %32 = trunc i32 %31 to i8
  store i8 %32, ptr %2, align 1
  store i32 1, ptr %7, align 4
  br label %69

33:                                               ; preds = %22
  %34 = load i16, ptr %5, align 2, !tbaa !5
  %35 = trunc i16 %34 to i8
  %36 = zext i8 %35 to i32
  %37 = shl i32 %36, 4
  %38 = trunc i32 %37 to i8
  store i8 %38, ptr %6, align 1, !tbaa !9
  %39 = load i16, ptr %5, align 2, !tbaa !5
  %40 = sext i16 %39 to i32
  %41 = icmp slt i32 %40, 2
  br i1 %41, label %42, label %51

42:                                               ; preds = %33
  %43 = load i16, ptr %3, align 2, !tbaa !5
  %44 = sext i16 %43 to i32
  %45 = ashr i32 %44, 1
  %46 = and i32 %45, 15
  %47 = load i8, ptr %6, align 1, !tbaa !9
  %48 = zext i8 %47 to i32
  %49 = or i32 %48, %46
  %50 = trunc i32 %49 to i8
  store i8 %50, ptr %6, align 1, !tbaa !9
  br label %62

51:                                               ; preds = %33
  %52 = load i16, ptr %3, align 2, !tbaa !5
  %53 = sext i16 %52 to i32
  %54 = load i16, ptr %5, align 2, !tbaa !5
  %55 = sext i16 %54 to i32
  %56 = ashr i32 %53, %55
  %57 = and i32 %56, 15
  %58 = load i8, ptr %6, align 1, !tbaa !9
  %59 = zext i8 %58 to i32
  %60 = or i32 %59, %57
  %61 = trunc i32 %60 to i8
  store i8 %61, ptr %6, align 1, !tbaa !9
  br label %62

62:                                               ; preds = %51, %42
  %63 = load i8, ptr %6, align 1, !tbaa !9
  %64 = zext i8 %63 to i32
  %65 = load i16, ptr %4, align 2, !tbaa !5
  %66 = sext i16 %65 to i32
  %67 = xor i32 %64, %66
  %68 = trunc i32 %67 to i8
  store i8 %68, ptr %2, align 1
  store i32 1, ptr %7, align 4
  br label %69

69:                                               ; preds = %62, %28
  call void @llvm.lifetime.end.p0(i64 1, ptr %6) #2
  call void @llvm.lifetime.end.p0(i64 2, ptr %5) #2
  call void @llvm.lifetime.end.p0(i64 2, ptr %4) #2
  %70 = load i8, ptr %2, align 1
  ret i8 %70
}

; 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 signext i16 @search(i16 noundef signext, ptr noundef, i16 noundef signext) #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}


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

@seg_aend = external hidden global [8 x i16], align 16

; Function Attrs: nounwind uwtable
define dso_local zeroext i8 @linear2alaw(i16 noundef signext %0) local_unnamed_addr #0 {
  %2 = ashr i16 %0, 3
  %3 = icmp slt i16 %2, 0
  %.lobit = ashr i16 %0, 15
  %.018 = xor i16 %2, %.lobit
  %.017 = select i1 %3, i8 85, i8 -43
  %4 = tail call signext i16 @search(i16 noundef signext %.018, ptr noundef nonnull @seg_aend, i16 noundef signext 8)
  %5 = icmp sgt i16 %4, 7
  br i1 %5, label %6, label %8

6:                                                ; preds = %1
  %7 = xor i8 %.017, 127
  br label %18

8:                                                ; preds = %1
  %.tr = trunc i16 %4 to i8
  %9 = shl i8 %.tr, 4
  %10 = icmp slt i16 %4, 2
  %11 = trunc i16 %.018 to i8
  %12 = lshr i8 %11, 1
  %13 = sext i16 %.018 to i32
  %14 = zext nneg i16 %4 to i32
  %15 = ashr i32 %13, %14
  %16 = trunc i32 %15 to i8
  %.pn.in = select i1 %10, i8 %12, i8 %16
  %.pn = and i8 %.pn.in, 15
  %.0 = or disjoint i8 %.pn, %9
  %17 = xor i8 %.0, %.017
  br label %18

18:                                               ; preds = %8, %6
  %.016 = phi i8 [ %7, %6 ], [ %17, %8 ]
  ret i8 %.016
}

; Function Attrs: nounwind uwtable
declare hidden signext i16 @search(i16 noundef signext, ptr noundef, i16 noundef signext) 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)"}


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