; LLVM IR from sp-nitech/SPTK :: third_party/REAPER/wave/codec_riff.ll (ZNK4sptk6reaper9UlawCodec11UlawToInt16Eh)

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

29:                                               ; preds = %2
  %30 = load i16, ptr %5, align 2, !tbaa !10
  %31 = sext i16 %30 to i32
  %32 = sub nsw i32 132, %31
  br label %37

33:                                               ; preds = %2
  %34 = load i16, ptr %5, align 2, !tbaa !10
  %35 = sext i16 %34 to i32
  %36 = sub nsw i32 %35, 132
  br label %37

37:                                               ; preds = %33, %29
  %38 = phi i32 [ %32, %29 ], [ %36, %33 ]
  %39 = ashr i32 %38, 2
  %40 = trunc i32 %39 to i16
  call void @llvm.lifetime.end.p0(i64 2, ptr %5) #2
  ret i16 %40
}

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

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(none) uwtable
define dso_local noundef signext range(i16 -8031, 8032) i16 @_ZNK4sptk6reaper9UlawCodec11UlawToInt16Eh(ptr nocapture noundef nonnull readnone align 1 dereferenceable(1) %0, i8 noundef zeroext %1) local_unnamed_addr #0 align 2 {
  %3 = xor i8 %1, -1
  %.tr = zext i8 %3 to i32
  %4 = shl nuw nsw i32 %.tr, 3
  %5 = and i32 %4, 120
  %6 = or disjoint i32 %5, 132
  %7 = lshr i8 %3, 4
  %8 = and i8 %7, 7
  %9 = zext nneg i8 %8 to i32
  %10 = shl nuw nsw i32 %6, %9
  %.not = icmp slt i8 %1, 0
  %11 = sub nsw i32 132, %10
  %12 = add nuw nsw i32 %10, 262012
  %13 = select i1 %.not, i32 %12, i32 %11
  %14 = lshr exact i32 %13, 2
  %15 = trunc i32 %14 to i16
  ret i16 %15
}

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: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass