; 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_uend = external hidden global [8 x i16], align 16

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

; Function Attrs: nounwind uwtable
declare hidden signext i16 @search(i16 noundef signext, ptr noundef, i16 noundef signext) #1

; 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 zeroext i8 @linear2ulaw(i16 noundef signext %0) #1 {
  %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, 2
  %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 slt i32 %13, 0
  br i1 %14, label %15, label %20

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

20:                                               ; preds = %1
  store i16 255, ptr %4, align 2, !tbaa !5
  br label %21

21:                                               ; preds = %20, %15
  %22 = load i16, ptr %3, align 2, !tbaa !5
  %23 = sext i16 %22 to i32
  %24 = icmp sgt i32 %23, 8159
  br i1 %24, label %25, label %26

25:                                               ; preds = %21
  store i16 8159, ptr %3, align 2, !tbaa !5
  br label %26

26:                                               ; preds = %25, %21
  %27 = load i16, ptr %3, align 2, !tbaa !5
  %28 = sext i16 %27 to i32
  %29 = add nsw i32 %28, 33
  %30 = trunc i32 %29 to i16
  store i16 %30, ptr %3, align 2, !tbaa !5
  %31 = load i16, ptr %3, align 2, !tbaa !5
  %32 = call signext i16 @search(i16 noundef signext %31, ptr noundef @seg_uend, i16 noundef signext 8)
  store i16 %32, ptr %5, align 2, !tbaa !5
  %33 = load i16, ptr %5, align 2, !tbaa !5
  %34 = sext i16 %33 to i32
  %35 = icmp sge i32 %34, 8
  br i1 %35, label %36, label %41

36:                                               ; preds = %26
  %37 = load i16, ptr %4, align 2, !tbaa !5
  %38 = sext i16 %37 to i32
  %39 = xor i32 127, %38
  %40 = trunc i32 %39 to i8
  store i8 %40, ptr %2, align 1
  store i32 1, ptr %7, align 4
  br label %62

41:                                               ; preds = %26
  %42 = load i16, ptr %5, align 2, !tbaa !5
  %43 = sext i16 %42 to i32
  %44 = shl i32 %43, 4
  %45 = trunc i32 %44 to i8
  %46 = zext i8 %45 to i32
  %47 = load i16, ptr %3, align 2, !tbaa !5
  %48 = sext i16 %47 to i32
  %49 = load i16, ptr %5, align 2, !tbaa !5
  %50 = sext i16 %49 to i32
  %51 = add nsw i32 %50, 1
  %52 = ashr i32 %48, %51
  %53 = and i32 %52, 15
  %54 = or i32 %46, %53
  %55 = trunc i32 %54 to i8
  store i8 %55, ptr %6, align 1, !tbaa !9
  %56 = load i8, ptr %6, align 1, !tbaa !9
  %57 = zext i8 %56 to i32
  %58 = load i16, ptr %4, align 2, !tbaa !5
  %59 = sext i16 %58 to i32
  %60 = xor i32 %57, %59
  %61 = trunc i32 %60 to i8
  store i8 %61, ptr %2, align 1
  store i32 1, ptr %7, align 4
  br label %62

62:                                               ; preds = %41, %36
  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
  %63 = load i8, ptr %2, align 1
  ret i8 %63
}

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 = !{!"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_uend = external hidden global [8 x i16], align 16

; Function Attrs: nounwind uwtable
declare hidden signext i16 @search(i16 noundef signext, ptr noundef, i16 noundef signext) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local zeroext i8 @linear2ulaw(i16 noundef signext %0) local_unnamed_addr #0 {
  %2 = ashr i16 %0, 2
  %3 = icmp slt i16 %2, 0
  %.015 = select i1 %3, i32 127, i32 255
  %.014 = tail call i16 @llvm.abs.i16(i16 %2, i1 true)
  %4 = tail call i16 @llvm.umin.i16(i16 %.014, i16 8159)
  %narrow18 = add nuw nsw i16 %4, 33
  %5 = tail call signext i16 @search(i16 noundef signext %narrow18, ptr noundef nonnull @seg_uend, i16 noundef signext 8)
  %6 = icmp sgt i16 %5, 7
  br i1 %6, label %7, label %10

7:                                                ; preds = %1
  %8 = trunc nuw i32 %.015 to i8
  %9 = and i8 %8, -128
  br label %20

10:                                               ; preds = %1
  %11 = sext i16 %5 to i32
  %.tr = zext i16 %5 to i32
  %12 = shl nuw nsw i32 %.tr, 4
  %13 = zext nneg i16 %narrow18 to i32
  %14 = add nsw i32 %11, 1
  %15 = lshr i32 %13, %14
  %16 = and i32 %15, 15
  %17 = or disjoint i32 %16, %12
  %18 = xor i32 %17, %.015
  %19 = trunc i32 %18 to i8
  br label %20

20:                                               ; preds = %10, %7
  %.0 = phi i8 [ %9, %7 ], [ %19, %10 ]
  ret i8 %.0
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i16 @llvm.umin.i16(i16, i16) #1

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i16 @llvm.abs.i16(i16, i1 immarg) #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 speculatable willreturn memory(none) }

!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: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass