; LLVM IR from glaretechnologies/substrata :: opus/opus-1.3.1/silk (NLSF_decode)

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

%struct.silk_NLSF_CB_struct = type { i16, i16, i16, i16, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }

; Function Attrs: nounwind uwtable
define dso_local void @silk_NLSF_decode(ptr noundef %0, ptr noundef %1, ptr noundef %2) #0 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca [16 x i8], align 16
  %9 = alloca [16 x i16], align 16
  %10 = alloca [16 x i16], align 16
  %11 = alloca i32, align 4
  %12 = alloca ptr, align 8
  %13 = alloca ptr, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store ptr %2, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  call void @llvm.lifetime.start.p0(i64 16, ptr %8) #4
  call void @llvm.lifetime.start.p0(i64 32, ptr %9) #4
  call void @llvm.lifetime.start.p0(i64 32, ptr %10) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #4
  %14 = getelementptr inbounds [16 x i16], ptr %9, i64 0, i64 0
  %15 = getelementptr inbounds [16 x i8], ptr %8, i64 0, i64 0
  %16 = load ptr, ptr %6, align 8, !tbaa !5
  %17 = load ptr, ptr %5, align 8, !tbaa !5
  %18 = getelementptr inbounds i8, ptr %17, i64 0
  %19 = load i8, ptr %18, align 1, !tbaa !9
  %20 = sext i8 %19 to i32
  call void @silk_NLSF_unpack(ptr noundef %14, ptr noundef %15, ptr noundef %16, i32 noundef %20)
  %21 = getelementptr inbounds [16 x i16], ptr %10, i64 0, i64 0
  %22 = load ptr, ptr %5, align 8, !tbaa !5
  %23 = getelementptr inbounds i8, ptr %22, i64 1
  %24 = getelementptr inbounds [16 x i8], ptr %8, i64 0, i64 0
  %25 = load ptr, ptr %6, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.silk_NLSF_CB_struct, ptr %25, i32 0, i32 2
  %27 = load i16, ptr %26, align 4, !tbaa !10
  %28 = sext i16 %27 to i32
  %29 = load ptr, ptr %6, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.silk_NLSF_CB_struct, ptr %29, i32 0, i32 1
  %31 = load i16, ptr %30, align 2, !tbaa !13
  call void @silk_NLSF_residual_dequant(ptr noundef %21, ptr noundef %23, ptr noundef %24, i32 noundef %28, i16 noundef signext %31)
  %32 = load ptr, ptr %6, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.silk_NLSF_CB_struct, ptr %32, i32 0, i32 4
  %34 = load ptr, ptr %33, align 8, !tbaa !14
  %35 = load ptr, ptr %5, align 8, !tbaa !5
  %36 = getelementptr inbounds i8, ptr %35, i64 0
  %37 = load i8, ptr %36, align 1, !tbaa !9
  %38 = sext i8 %37 to i32
  %39 = load ptr, ptr %6, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.silk_NLSF_CB_struct, ptr %39, i32 0, i32 1
  %41 = load i16, ptr %40, align 2, !tbaa !13
  %42 = sext i16 %41 to i32
  %43 = mul nsw i32 %38, %42
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds i8, ptr %34, i64 %44
  store ptr %45, ptr %12, align 8, !tbaa !5
  %46 = load ptr, ptr %6, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.silk_NLSF_CB_struct, ptr %46, i32 0, i32 5
  %48 = load ptr, ptr %47, align 8, !tbaa !15
  %49 = load ptr, ptr %5, align 8, !tbaa !5
  %50 = getelementptr inbounds i8, ptr %49, i64 0
  %51 = load i8, ptr %50, align 1, !tbaa !9
  %52 = sext i8 %51 to i32
  %53 = load ptr, ptr %6, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.silk_NLSF_CB_struct, ptr %53, i32 0, i32 1
  %55 = load i16, ptr %54, align 2, !tbaa !13
  %56 = sext i16 %55 to i32
  %57 = mul nsw i32 %52, %56
  %58 = sext i32 %57 to i64
  %59 = getelementptr inbounds i16, ptr %48, i64 %58
  store ptr %59, ptr %13, align 8, !tbaa !5
  store i32 0, ptr %7, align 4, !tbaa !16
  br label %60

60:                                               ; preds = %108, %3
  %61 = load i32, ptr %7, align 4, !tbaa !16
  %62 = load ptr, ptr %6, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.silk_NLSF_CB_struct, ptr %62, i32 0, i32 1
  %64 = load i16, ptr %63, align 2, !tbaa !13
  %65 = sext i16 %64 to i32
  %66 = icmp slt i32 %61, %65
  br i1 %66, label %67, label %111

67:                                               ; preds = %60
  %68 = load i32, ptr %7, align 4, !tbaa !16
  %69 = sext i32 %68 to i64
  %70 = getelementptr inbounds [16 x i16], ptr %10, i64 0, i64 %69
  %71 = load i16, ptr %70, align 2, !tbaa !18
  %72 = sext i16 %71 to i32
  %73 = shl i32 %72, 14
  %74 = load ptr, ptr %13, align 8, !tbaa !5
  %75 = load i32, ptr %7, align 4, !tbaa !16
  %76 = sext i32 %75 to i64
  %77 = getelementptr inbounds i16, ptr %74, i64 %76
  %78 = load i16, ptr %77, align 2, !tbaa !18
  %79 = sext i16 %78 to i32
  %80 = sdiv i32 %73, %79
  %81 = load ptr, ptr %12, align 8, !tbaa !5
  %82 = load i32, ptr %7, align 4, !tbaa !16
  %83 = sext i32 %82 to i64
  %84 = getelementptr inbounds i8, ptr %81, i64 %83
  %85 = load i8, ptr %84, align 1, !tbaa !9
  %86 = zext i8 %85 to i16
  %87 = sext i16 %86 to i32
  %88 = shl i32 %87, 7
  %89 = add nsw i32 %80, %88
  store i32 %89, ptr %11, align 4, !tbaa !16
  %90 = load i32, ptr %11, align 4, !tbaa !16
  %91 = icmp sgt i32 %90, 32767
  br i1 %91, label %92, label %93

92:                                               ; preds = %67
  br label %101

93:                                               ; preds = %67
  %94 = load i32, ptr %11, align 4, !tbaa !16
  %95 = icmp slt i32 %94, 0
  br i1 %95, label %96, label %97

96:                                               ; preds = %93
  br label %99

97:                                               ; preds = %93
  %98 = load i32, ptr %11, align 4, !tbaa !16
  br label %99

99:                                               ; preds = %97, %96
  %100 = phi i32 [ 0, %96 ], [ %98, %97 ]
  br label %101

101:                                              ; preds = %99, %92
  %102 = phi i32 [ 32767, %92 ], [ %100, %99 ]
  %103 = trunc i32 %102 to i16
  %104 = load ptr, ptr %4, align 8, !tbaa !5
  %105 = load i32, ptr %7, align 4, !tbaa !16
  %106 = sext i32 %105 to i64
  %107 = getelementptr inbounds i16, ptr %104, i64 %106
  store i16 %103, ptr %107, align 2, !tbaa !18
  br label %108

108:                                              ; preds = %101
  %109 = load i32, ptr %7, align 4, !tbaa !16
  %110 = add nsw i32 %109, 1
  store i32 %110, ptr %7, align 4, !tbaa !16
  br label %60, !llvm.loop !19

111:                                              ; preds = %60
  %112 = load ptr, ptr %4, align 8, !tbaa !5
  %113 = load ptr, ptr %6, align 8, !tbaa !5
  %114 = getelementptr inbounds %struct.silk_NLSF_CB_struct, ptr %113, i32 0, i32 11
  %115 = load ptr, ptr %114, align 8, !tbaa !21
  %116 = load ptr, ptr %6, align 8, !tbaa !5
  %117 = getelementptr inbounds %struct.silk_NLSF_CB_struct, ptr %116, i32 0, i32 1
  %118 = load i16, ptr %117, align 2, !tbaa !13
  %119 = sext i16 %118 to i32
  call void @silk_NLSF_stabilize(ptr noundef %112, ptr noundef %115, i32 noundef %119)
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 32, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 32, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 16, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  ret void
}

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

declare void @silk_NLSF_unpack(ptr noundef, ptr noundef, ptr noundef, i32 noundef) #2

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @silk_NLSF_residual_dequant(ptr noundef, ptr noundef, ptr noundef, i32 noundef, i16 noundef signext) #3

declare void @silk_NLSF_stabilize(ptr noundef, ptr noundef, i32 noundef) #2

; 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 = { inlinehint 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 #4 = { 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/C++ TBAA"}
!9 = !{!7, !7, i64 0}
!10 = !{!11, !12, i64 4}
!11 = !{!"", !12, i64 0, !12, i64 2, !12, i64 4, !12, i64 6, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !6, i64 64}
!12 = !{!"short", !7, i64 0}
!13 = !{!11, !12, i64 2}
!14 = !{!11, !6, i64 8}
!15 = !{!11, !6, i64 16}
!16 = !{!17, !17, i64 0}
!17 = !{!"int", !7, i64 0}
!18 = !{!12, !12, i64 0}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}
!21 = !{!11, !6, i64 64}


; 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: nounwind uwtable
define dso_local void @silk_NLSF_decode(ptr noundef %0, ptr noundef %1, ptr noundef %2) local_unnamed_addr #0 {
  %4 = alloca [16 x i8], align 16
  %5 = alloca [16 x i16], align 16
  %6 = alloca [16 x i16], align 16
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %4) #5
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %5) #5
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %6) #5
  %7 = load i8, ptr %1, align 1, !tbaa !5
  %8 = sext i8 %7 to i32
  call void @silk_NLSF_unpack(ptr noundef nonnull %5, ptr noundef nonnull %4, ptr noundef %2, i32 noundef %8) #5
  %9 = getelementptr inbounds i8, ptr %1, i64 1
  %10 = getelementptr inbounds i8, ptr %2, i64 4
  %11 = load i16, ptr %10, align 4, !tbaa !8
  %12 = sext i16 %11 to i32
  %13 = getelementptr inbounds i8, ptr %2, i64 2
  %14 = load i16, ptr %13, align 2, !tbaa !12
  call void @silk_NLSF_residual_dequant(ptr noundef nonnull %6, ptr noundef nonnull %9, ptr noundef nonnull %4, i32 noundef %12, i16 noundef signext %14)
  %15 = getelementptr inbounds i8, ptr %2, i64 8
  %16 = load ptr, ptr %15, align 8, !tbaa !13
  %17 = load i8, ptr %1, align 1, !tbaa !5
  %18 = sext i8 %17 to i64
  %19 = load i16, ptr %13, align 2, !tbaa !12
  %20 = sext i16 %19 to i64
  %21 = mul nsw i64 %20, %18
  %22 = getelementptr inbounds i8, ptr %16, i64 %21
  %23 = getelementptr inbounds i8, ptr %2, i64 16
  %24 = load ptr, ptr %23, align 8, !tbaa !14
  %25 = getelementptr inbounds i16, ptr %24, i64 %21
  %26 = icmp sgt i16 %19, 0
  br i1 %26, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %3, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 0, %3 ]
  %27 = getelementptr inbounds [16 x i16], ptr %6, i64 0, i64 %indvars.iv
  %28 = load i16, ptr %27, align 2, !tbaa !15
  %29 = sext i16 %28 to i32
  %30 = shl nsw i32 %29, 14
  %31 = getelementptr inbounds i16, ptr %25, i64 %indvars.iv
  %32 = load i16, ptr %31, align 2, !tbaa !15
  %33 = sext i16 %32 to i32
  %34 = sdiv i32 %30, %33
  %35 = getelementptr inbounds i8, ptr %22, i64 %indvars.iv
  %36 = load i8, ptr %35, align 1, !tbaa !5
  %37 = zext i8 %36 to i32
  %38 = shl nuw nsw i32 %37, 7
  %39 = add nsw i32 %38, %34
  %40 = call i32 @llvm.smax.i32(i32 %39, i32 0)
  %41 = call i32 @llvm.umin.i32(i32 %40, i32 32767)
  %42 = trunc nuw nsw i32 %41 to i16
  %43 = getelementptr inbounds i16, ptr %0, i64 %indvars.iv
  store i16 %42, ptr %43, align 2, !tbaa !15
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %44 = load i16, ptr %13, align 2, !tbaa !12
  %45 = sext i16 %44 to i64
  %46 = icmp slt i64 %indvars.iv.next, %45
  br i1 %46, label %.lr.ph, label %._crit_edge, !llvm.loop !16

._crit_edge:                                      ; preds = %.lr.ph, %3
  %.lcssa.in = phi i16 [ %19, %3 ], [ %44, %.lr.ph ]
  %.lcssa = sext i16 %.lcssa.in to i32
  %47 = getelementptr inbounds i8, ptr %2, i64 64
  %48 = load ptr, ptr %47, align 8, !tbaa !18
  call void @silk_NLSF_stabilize(ptr noundef %0, ptr noundef %48, i32 noundef %.lcssa) #5
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %6) #5
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %5) #5
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %4) #5
  ret void
}

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

declare void @silk_NLSF_unpack(ptr noundef, ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #2

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @silk_NLSF_residual_dequant(ptr noundef, ptr noundef, ptr noundef, i32 noundef, i16 noundef signext) local_unnamed_addr #3

declare void @silk_NLSF_stabilize(ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #2

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

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.smax.i32(i32, i32) #4

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

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 = { mustprogress 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 = { inlinehint 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 #4 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #5 = { 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, !10, i64 4}
!9 = !{!"", !10, i64 0, !10, i64 2, !10, i64 4, !10, i64 6, !11, i64 8, !11, i64 16, !11, i64 24, !11, i64 32, !11, i64 40, !11, i64 48, !11, i64 56, !11, i64 64}
!10 = !{!"short", !6, i64 0}
!11 = !{!"any pointer", !6, i64 0}
!12 = !{!9, !10, i64 2}
!13 = !{!9, !11, i64 8}
!14 = !{!9, !11, i64 16}
!15 = !{!10, !10, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}
!18 = !{!9, !11, i64 64}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass