; LLVM IR from glaretechnologies/substrata :: opus/opus-1.3.1/src (repacketizer)

; 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.OpusRepacketizer = type { i8, i32, [48 x ptr], [48 x i16], i32 }

; Function Attrs: nounwind uwtable
declare dso_local ptr @opus_repacketizer_init(ptr noundef nonnull) #0

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

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

; Function Attrs: nounwind uwtable
declare hidden i32 @opus_repacketizer_cat_impl(ptr noundef, ptr noundef, i32 noundef, i32 noundef) #0

; Function Attrs: nounwind uwtable
declare dso_local i32 @opus_repacketizer_out_range_impl(ptr noundef, i32 noundef, i32 noundef, ptr noundef, i32 noundef, i32 noundef, i32 noundef) #0

declare i32 @opus_packet_parse_impl(ptr noundef, i32 noundef, i32 noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef) #2

; Function Attrs: nounwind uwtable
define dso_local i32 @opus_multistream_packet_unpad(ptr noundef %0, i32 noundef %1, i32 noundef %2) #0 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i8, align 1
  %10 = alloca [48 x i16], align 16
  %11 = alloca i32, align 4
  %12 = alloca %struct.OpusRepacketizer, align 8
  %13 = alloca ptr, align 8
  %14 = alloca i32, align 4
  %15 = alloca i32, align 4
  %16 = alloca i32, align 4
  %17 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !9
  store i32 %2, ptr %7, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  call void @llvm.lifetime.start.p0(i64 1, ptr %9) #3
  call void @llvm.lifetime.start.p0(i64 96, ptr %10) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  call void @llvm.lifetime.start.p0(i64 496, ptr %12) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #3
  %18 = load i32, ptr %6, align 4, !tbaa !9
  %19 = icmp slt i32 %18, 1
  br i1 %19, label %20, label %21

20:                                               ; preds = %3
  store i32 -1, ptr %4, align 4
  store i32 1, ptr %15, align 4
  br label %91

21:                                               ; preds = %3
  %22 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %22, ptr %13, align 8, !tbaa !5
  store i32 0, ptr %14, align 4, !tbaa !9
  store i32 0, ptr %8, align 4, !tbaa !9
  br label %23

23:                                               ; preds = %86, %21
  %24 = load i32, ptr %8, align 4, !tbaa !9
  %25 = load i32, ptr %7, align 4, !tbaa !9
  %26 = icmp slt i32 %24, %25
  br i1 %26, label %27, label %89

27:                                               ; preds = %23
  call void @llvm.lifetime.start.p0(i64 4, ptr %16) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %17) #3
  %28 = load i32, ptr %8, align 4, !tbaa !9
  %29 = load i32, ptr %7, align 4, !tbaa !9
  %30 = sub nsw i32 %29, 1
  %31 = icmp ne i32 %28, %30
  %32 = zext i1 %31 to i32
  store i32 %32, ptr %17, align 4, !tbaa !9
  %33 = load i32, ptr %6, align 4, !tbaa !9
  %34 = icmp sle i32 %33, 0
  br i1 %34, label %35, label %36

35:                                               ; preds = %27
  store i32 -4, ptr %4, align 4
  store i32 1, ptr %15, align 4
  br label %83

36:                                               ; preds = %27
  %37 = call ptr @opus_repacketizer_init(ptr noundef %12)
  %38 = load ptr, ptr %5, align 8, !tbaa !5
  %39 = load i32, ptr %6, align 4, !tbaa !9
  %40 = load i32, ptr %17, align 4, !tbaa !9
  %41 = getelementptr inbounds [48 x i16], ptr %10, i64 0, i64 0
  %42 = call i32 @opus_packet_parse_impl(ptr noundef %38, i32 noundef %39, i32 noundef %40, ptr noundef %9, ptr noundef null, ptr noundef %41, ptr noundef null, ptr noundef %11)
  store i32 %42, ptr %16, align 4, !tbaa !9
  %43 = load i32, ptr %16, align 4, !tbaa !9
  %44 = icmp slt i32 %43, 0
  br i1 %44, label %45, label %47

45:                                               ; preds = %36
  %46 = load i32, ptr %16, align 4, !tbaa !9
  store i32 %46, ptr %4, align 4
  store i32 1, ptr %15, align 4
  br label %83

47:                                               ; preds = %36
  %48 = load ptr, ptr %5, align 8, !tbaa !5
  %49 = load i32, ptr %11, align 4, !tbaa !9
  %50 = load i32, ptr %17, align 4, !tbaa !9
  %51 = call i32 @opus_repacketizer_cat_impl(ptr noundef %12, ptr noundef %48, i32 noundef %49, i32 noundef %50)
  store i32 %51, ptr %16, align 4, !tbaa !9
  %52 = load i32, ptr %16, align 4, !tbaa !9
  %53 = icmp slt i32 %52, 0
  br i1 %53, label %54, label %56

54:                                               ; preds = %47
  %55 = load i32, ptr %16, align 4, !tbaa !9
  store i32 %55, ptr %4, align 4
  store i32 1, ptr %15, align 4
  br label %83

56:                                               ; preds = %47
  %57 = getelementptr inbounds %struct.OpusRepacketizer, ptr %12, i32 0, i32 1
  %58 = load i32, ptr %57, align 4, !tbaa !11
  %59 = load ptr, ptr %13, align 8, !tbaa !5
  %60 = load i32, ptr %6, align 4, !tbaa !9
  %61 = load i32, ptr %17, align 4, !tbaa !9
  %62 = call i32 @opus_repacketizer_out_range_impl(ptr noundef %12, i32 noundef 0, i32 noundef %58, ptr noundef %59, i32 noundef %60, i32 noundef %61, i32 noundef 0)
  store i32 %62, ptr %16, align 4, !tbaa !9
  %63 = load i32, ptr %16, align 4, !tbaa !9
  %64 = icmp slt i32 %63, 0
  br i1 %64, label %65, label %67

65:                                               ; preds = %56
  %66 = load i32, ptr %16, align 4, !tbaa !9
  store i32 %66, ptr %4, align 4
  store i32 1, ptr %15, align 4
  br label %83

67:                                               ; preds = %56
  %68 = load i32, ptr %16, align 4, !tbaa !9
  %69 = load i32, ptr %14, align 4, !tbaa !9
  %70 = add nsw i32 %69, %68
  store i32 %70, ptr %14, align 4, !tbaa !9
  br label %71

71:                                               ; preds = %67
  %72 = load i32, ptr %16, align 4, !tbaa !9
  %73 = load ptr, ptr %13, align 8, !tbaa !5
  %74 = sext i32 %72 to i64
  %75 = getelementptr inbounds i8, ptr %73, i64 %74
  store ptr %75, ptr %13, align 8, !tbaa !5
  %76 = load i32, ptr %11, align 4, !tbaa !9
  %77 = load ptr, ptr %5, align 8, !tbaa !5
  %78 = sext i32 %76 to i64
  %79 = getelementptr inbounds i8, ptr %77, i64 %78
  store ptr %79, ptr %5, align 8, !tbaa !5
  %80 = load i32, ptr %11, align 4, !tbaa !9
  %81 = load i32, ptr %6, align 4, !tbaa !9
  %82 = sub nsw i32 %81, %80
  store i32 %82, ptr %6, align 4, !tbaa !9
  store i32 0, ptr %15, align 4
  br label %83

83:                                               ; preds = %71, %65, %54, %45, %35
  call void @llvm.lifetime.end.p0(i64 4, ptr %17) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %16) #3
  %84 = load i32, ptr %15, align 4
  switch i32 %84, label %91 [
    i32 0, label %85
  ]

85:                                               ; preds = %83
  br label %86

86:                                               ; preds = %85
  %87 = load i32, ptr %8, align 4, !tbaa !9
  %88 = add nsw i32 %87, 1
  store i32 %88, ptr %8, align 4, !tbaa !9
  br label %23, !llvm.loop !13

89:                                               ; preds = %23
  %90 = load i32, ptr %14, align 4, !tbaa !9
  store i32 %90, ptr %4, align 4
  store i32 1, ptr %15, align 4
  br label %91

91:                                               ; preds = %89, %83, %20
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #3
  call void @llvm.lifetime.end.p0(i64 496, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 96, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 1, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  %92 = load i32, ptr %4, align 4
  ret i32 %92
}

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 = { 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 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 4}
!12 = !{!"OpusRepacketizer", !7, i64 0, !10, i64 4, !7, i64 8, !7, i64 392, !10, i64 488}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}


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

%struct.OpusRepacketizer = type { i8, i32, [48 x ptr], [48 x i16], i32 }

; Function Attrs: nounwind uwtable
declare dso_local ptr @opus_repacketizer_init(ptr noundef nonnull) local_unnamed_addr #0

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

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

; Function Attrs: nounwind uwtable
declare hidden i32 @opus_repacketizer_cat_impl(ptr noundef, ptr noundef, i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local i32 @opus_repacketizer_out_range_impl(ptr noundef, i32 noundef, i32 noundef, ptr noundef, i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #0

declare i32 @opus_packet_parse_impl(ptr noundef, i32 noundef, i32 noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
define dso_local i32 @opus_multistream_packet_unpad(ptr noundef %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #0 {
  %4 = alloca i8, align 1
  %5 = alloca [48 x i16], align 16
  %6 = alloca i32, align 4
  %7 = alloca %struct.OpusRepacketizer, align 8
  call void @llvm.lifetime.start.p0(i64 1, ptr nonnull %4) #3
  call void @llvm.lifetime.start.p0(i64 96, ptr nonnull %5) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %6) #3
  call void @llvm.lifetime.start.p0(i64 496, ptr nonnull %7) #3
  %8 = icmp slt i32 %1, 1
  br i1 %8, label %.thread, label %.preheader

.preheader:                                       ; preds = %3
  %9 = add nsw i32 %2, -1
  %10 = getelementptr inbounds i8, ptr %7, i64 4
  %11 = icmp sgt i32 %2, 0
  br i1 %11, label %.lr.ph, label %.thread

.lr.ph:                                           ; preds = %.preheader, %27
  %.03156 = phi i32 [ %28, %27 ], [ 0, %.preheader ]
  %.03355 = phi ptr [ %30, %27 ], [ %0, %.preheader ]
  %.03554 = phi i32 [ %35, %27 ], [ 0, %.preheader ]
  %.03653 = phi ptr [ %33, %27 ], [ %0, %.preheader ]
  %.03852 = phi i32 [ %34, %27 ], [ %1, %.preheader ]
  %12 = icmp ne i32 %.03554, %9
  %13 = zext i1 %12 to i32
  %14 = icmp slt i32 %.03852, 1
  br i1 %14, label %.thread, label %15

15:                                               ; preds = %.lr.ph
  %16 = call ptr @opus_repacketizer_init(ptr noundef %7)
  %17 = call i32 @opus_packet_parse_impl(ptr noundef %.03653, i32 noundef %.03852, i32 noundef %13, ptr noundef nonnull %4, ptr noundef null, ptr noundef nonnull %5, ptr noundef null, ptr noundef nonnull %6) #3
  %18 = icmp slt i32 %17, 0
  br i1 %18, label %.thread, label %19

19:                                               ; preds = %15
  %20 = load i32, ptr %6, align 4, !tbaa !5
  %21 = call i32 @opus_repacketizer_cat_impl(ptr noundef nonnull %7, ptr noundef %.03653, i32 noundef %20, i32 noundef %13)
  %22 = icmp slt i32 %21, 0
  br i1 %22, label %.thread, label %23

23:                                               ; preds = %19
  %24 = load i32, ptr %10, align 4, !tbaa !9
  %25 = call i32 @opus_repacketizer_out_range_impl(ptr noundef nonnull %7, i32 noundef 0, i32 noundef %24, ptr noundef %.03355, i32 noundef %.03852, i32 noundef %13, i32 noundef 0)
  %26 = icmp slt i32 %25, 0
  br i1 %26, label %.thread, label %27

27:                                               ; preds = %23
  %28 = add nuw nsw i32 %25, %.03156
  %29 = zext nneg i32 %25 to i64
  %30 = getelementptr inbounds i8, ptr %.03355, i64 %29
  %31 = load i32, ptr %6, align 4, !tbaa !5
  %32 = sext i32 %31 to i64
  %33 = getelementptr inbounds i8, ptr %.03653, i64 %32
  %34 = sub nsw i32 %.03852, %31
  %35 = add nuw nsw i32 %.03554, 1
  %exitcond.not = icmp eq i32 %35, %2
  br i1 %exitcond.not, label %.thread, label %.lr.ph, !llvm.loop !11

.thread:                                          ; preds = %27, %.lr.ph, %15, %19, %23, %.preheader, %3
  %.2 = phi i32 [ -1, %3 ], [ 0, %.preheader ], [ %28, %27 ], [ -4, %.lr.ph ], [ %17, %15 ], [ %21, %19 ], [ %25, %23 ]
  call void @llvm.lifetime.end.p0(i64 496, ptr nonnull %7) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %6) #3
  call void @llvm.lifetime.end.p0(i64 96, ptr nonnull %5) #3
  call void @llvm.lifetime.end.p0(i64 1, ptr nonnull %4) #3
  ret i32 %.2
}

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 = { 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !6, i64 4}
!10 = !{!"OpusRepacketizer", !7, i64 0, !6, i64 4, !7, i64 8, !7, i64 392, !6, i64 488}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}


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