; LLVM IR from modlfo/AudioEngine :: AudioEngine/JuceLibraryCode/modules/juce_audio_formats/codecs/oggvorbis (blocksize)

; 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.oggpack_buffer = type { i64, i32, ptr, ptr, i64 }
%struct.vorbis_info = type { i32, i32, i64, i64, i64, i64, i64, ptr }
%struct.ogg_packet = type { ptr, i64, i64, i64, i64, i64 }
%struct.codec_setup_info = type { [2 x i64], i32, i32, i32, i32, i32, i32, [64 x ptr], [64 x i32], [64 x ptr], [64 x i32], [64 x ptr], [64 x i32], [64 x ptr], [256 x ptr], ptr, [4 x ptr], %struct.vorbis_info_psy_global, %struct.bitrate_manager_info, %struct.highlevel_encode_setup, i32 }
%struct.vorbis_info_psy_global = type { i32, [7 x float], [7 x float], float, float, float, [15 x i32], [2 x [15 x i32]], [15 x i32], [15 x i32], [2 x [15 x i32]] }
%struct.bitrate_manager_info = type { i64, i64, i64, i64, double, double }
%struct.highlevel_encode_setup = type { i32, ptr, double, double, float, i32, i64, i64, double, i64, i64, double, i32, i32, i32, double, double, i32, double, double, double, double, [4 x %struct.highlevel_byblocktype] }
%struct.highlevel_byblocktype = type { double, double, double, double }
%struct.vorbis_info_mode = type { i32, i32, i32, i32 }

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

declare void @oggpack_readinit(ptr noundef, ptr noundef, i32 noundef) #1

declare i64 @oggpack_read(ptr noundef, i32 noundef) #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 i64 @vorbis_packet_blocksize(ptr noundef %0, ptr noundef %1) #2 {
  %3 = alloca i64, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca %struct.oggpack_buffer, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  %12 = load ptr, ptr %4, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.vorbis_info, ptr %12, i32 0, i32 7
  %14 = load ptr, ptr %13, align 8, !tbaa !9
  store ptr %14, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 40, ptr %7) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  %15 = load ptr, ptr %5, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.ogg_packet, ptr %15, i32 0, i32 0
  %17 = load ptr, ptr %16, align 8, !tbaa !13
  %18 = load ptr, ptr %5, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.ogg_packet, ptr %18, i32 0, i32 1
  %20 = load i64, ptr %19, align 8, !tbaa !15
  %21 = trunc i64 %20 to i32
  call void @oggpack_readinit(ptr noundef %7, ptr noundef %17, i32 noundef %21)
  %22 = call i64 @oggpack_read(ptr noundef %7, i32 noundef 1)
  %23 = icmp ne i64 %22, 0
  br i1 %23, label %24, label %25

24:                                               ; preds = %2
  store i64 -135, ptr %3, align 8
  store i32 1, ptr %9, align 4
  br label %58

25:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  store i32 0, ptr %10, align 4, !tbaa !16
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  %26 = load ptr, ptr %6, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.codec_setup_info, ptr %26, i32 0, i32 1
  %28 = load i32, ptr %27, align 8, !tbaa !17
  store i32 %28, ptr %11, align 4, !tbaa !16
  br label %29

29:                                               ; preds = %32, %25
  %30 = load i32, ptr %11, align 4, !tbaa !16
  %31 = icmp sgt i32 %30, 1
  br i1 %31, label %32, label %37

32:                                               ; preds = %29
  %33 = load i32, ptr %10, align 4, !tbaa !16
  %34 = add nsw i32 %33, 1
  store i32 %34, ptr %10, align 4, !tbaa !16
  %35 = load i32, ptr %11, align 4, !tbaa !16
  %36 = ashr i32 %35, 1
  store i32 %36, ptr %11, align 4, !tbaa !16
  br label %29, !llvm.loop !24

37:                                               ; preds = %29
  %38 = load i32, ptr %10, align 4, !tbaa !16
  %39 = call i64 @oggpack_read(ptr noundef %7, i32 noundef %38)
  %40 = trunc i64 %39 to i32
  store i32 %40, ptr %8, align 4, !tbaa !16
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  %41 = load i32, ptr %8, align 4, !tbaa !16
  %42 = icmp eq i32 %41, -1
  br i1 %42, label %43, label %44

43:                                               ; preds = %37
  store i64 -136, ptr %3, align 8
  store i32 1, ptr %9, align 4
  br label %58

44:                                               ; preds = %37
  %45 = load ptr, ptr %6, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.codec_setup_info, ptr %45, i32 0, i32 0
  %47 = load ptr, ptr %6, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.codec_setup_info, ptr %47, i32 0, i32 7
  %49 = load i32, ptr %8, align 4, !tbaa !16
  %50 = sext i32 %49 to i64
  %51 = getelementptr inbounds [64 x ptr], ptr %48, i64 0, i64 %50
  %52 = load ptr, ptr %51, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.vorbis_info_mode, ptr %52, i32 0, i32 0
  %54 = load i32, ptr %53, align 4, !tbaa !26
  %55 = sext i32 %54 to i64
  %56 = getelementptr inbounds [2 x i64], ptr %46, i64 0, i64 %55
  %57 = load i64, ptr %56, align 8, !tbaa !28
  store i64 %57, ptr %3, align 8
  store i32 1, ptr %9, align 4
  br label %58

58:                                               ; preds = %44, %43, %24
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 40, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  %59 = load i64, ptr %3, align 8
  ret i64 %59
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { "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 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 #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, !6, i64 48}
!10 = !{!"vorbis_info", !11, i64 0, !11, i64 4, !12, i64 8, !12, i64 16, !12, i64 24, !12, i64 32, !12, i64 40, !6, i64 48}
!11 = !{!"int", !7, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!14, !6, i64 0}
!14 = !{!"", !6, i64 0, !12, i64 8, !12, i64 16, !12, i64 24, !12, i64 32, !12, i64 40}
!15 = !{!14, !12, i64 8}
!16 = !{!11, !11, i64 0}
!17 = !{!18, !11, i64 16}
!18 = !{!"codec_setup_info", !7, i64 0, !11, i64 16, !11, i64 20, !11, i64 24, !11, i64 28, !11, i64 32, !11, i64 36, !7, i64 40, !7, i64 552, !7, i64 808, !7, i64 1320, !7, i64 1576, !7, i64 2088, !7, i64 2344, !7, i64 2856, !6, i64 4904, !7, i64 4912, !19, i64 4944, !21, i64 5440, !23, i64 5488, !11, i64 5776}
!19 = !{!"", !11, i64 0, !7, i64 4, !7, i64 32, !20, i64 60, !20, i64 64, !20, i64 68, !7, i64 72, !7, i64 132, !7, i64 252, !7, i64 312, !7, i64 372}
!20 = !{!"float", !7, i64 0}
!21 = !{!"bitrate_manager_info", !12, i64 0, !12, i64 8, !12, i64 16, !12, i64 24, !22, i64 32, !22, i64 40}
!22 = !{!"double", !7, i64 0}
!23 = !{!"highlevel_encode_setup", !11, i64 0, !6, i64 8, !22, i64 16, !22, i64 24, !20, i64 32, !11, i64 36, !12, i64 40, !12, i64 48, !22, i64 56, !12, i64 64, !12, i64 72, !22, i64 80, !11, i64 88, !11, i64 92, !11, i64 96, !22, i64 104, !22, i64 112, !11, i64 120, !22, i64 128, !22, i64 136, !22, i64 144, !22, i64 152, !7, i64 160}
!24 = distinct !{!24, !25}
!25 = !{!"llvm.loop.mustprogress"}
!26 = !{!27, !11, i64 0}
!27 = !{!"", !11, i64 0, !11, i64 4, !11, i64 8, !11, i64 12}
!28 = !{!12, !12, 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"

%struct.oggpack_buffer = type { i64, i32, ptr, ptr, i64 }

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

declare void @oggpack_readinit(ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #1

declare i64 @oggpack_read(ptr noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress 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 i64 @vorbis_packet_blocksize(ptr nocapture noundef readonly %0, ptr nocapture noundef readonly %1) local_unnamed_addr #2 {
  %3 = alloca %struct.oggpack_buffer, align 8
  %4 = getelementptr inbounds i8, ptr %0, i64 48
  %5 = load ptr, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 40, ptr nonnull %3) #3
  %6 = load ptr, ptr %1, align 8, !tbaa !12
  %7 = getelementptr inbounds i8, ptr %1, i64 8
  %8 = load i64, ptr %7, align 8, !tbaa !14
  %9 = trunc i64 %8 to i32
  call void @oggpack_readinit(ptr noundef nonnull %3, ptr noundef %6, i32 noundef %9) #3
  %10 = call i64 @oggpack_read(ptr noundef nonnull %3, i32 noundef 1) #3
  %.not = icmp eq i64 %10, 0
  br i1 %.not, label %11, label %30

11:                                               ; preds = %2
  %12 = getelementptr inbounds i8, ptr %5, i64 16
  %13 = load i32, ptr %12, align 8, !tbaa !15
  %14 = icmp sgt i32 %13, 1
  br i1 %14, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %11, %.lr.ph
  %.016 = phi i32 [ %16, %.lr.ph ], [ %13, %11 ]
  %.01215 = phi i32 [ %15, %.lr.ph ], [ 0, %11 ]
  %15 = add nuw nsw i32 %.01215, 1
  %16 = lshr i32 %.016, 1
  %17 = icmp ugt i32 %.016, 3
  br i1 %17, label %.lr.ph, label %._crit_edge, !llvm.loop !22

._crit_edge:                                      ; preds = %.lr.ph, %11
  %.012.lcssa = phi i32 [ 0, %11 ], [ %15, %.lr.ph ]
  %18 = call i64 @oggpack_read(ptr noundef nonnull %3, i32 noundef %.012.lcssa) #3
  %19 = and i64 %18, 4294967295
  %20 = icmp eq i64 %19, 4294967295
  br i1 %20, label %30, label %21

21:                                               ; preds = %._crit_edge
  %22 = getelementptr inbounds i8, ptr %5, i64 40
  %sext = shl i64 %18, 32
  %23 = ashr exact i64 %sext, 32
  %24 = getelementptr inbounds [64 x ptr], ptr %22, i64 0, i64 %23
  %25 = load ptr, ptr %24, align 8, !tbaa !24
  %26 = load i32, ptr %25, align 4, !tbaa !25
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds [2 x i64], ptr %5, i64 0, i64 %27
  %29 = load i64, ptr %28, align 8, !tbaa !27
  br label %30

30:                                               ; preds = %._crit_edge, %2, %21
  %.013 = phi i64 [ %29, %21 ], [ -135, %2 ], [ -136, %._crit_edge ]
  call void @llvm.lifetime.end.p0(i64 40, ptr nonnull %3) #3
  ret i64 %.013
}

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { "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 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 #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, !11, i64 48}
!6 = !{!"vorbis_info", !7, i64 0, !7, i64 4, !10, i64 8, !10, i64 16, !10, i64 24, !10, i64 32, !10, i64 40, !11, i64 48}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"long", !8, i64 0}
!11 = !{!"any pointer", !8, i64 0}
!12 = !{!13, !11, i64 0}
!13 = !{!"", !11, i64 0, !10, i64 8, !10, i64 16, !10, i64 24, !10, i64 32, !10, i64 40}
!14 = !{!13, !10, i64 8}
!15 = !{!16, !7, i64 16}
!16 = !{!"codec_setup_info", !8, i64 0, !7, i64 16, !7, i64 20, !7, i64 24, !7, i64 28, !7, i64 32, !7, i64 36, !8, i64 40, !8, i64 552, !8, i64 808, !8, i64 1320, !8, i64 1576, !8, i64 2088, !8, i64 2344, !8, i64 2856, !11, i64 4904, !8, i64 4912, !17, i64 4944, !19, i64 5440, !21, i64 5488, !7, i64 5776}
!17 = !{!"", !7, i64 0, !8, i64 4, !8, i64 32, !18, i64 60, !18, i64 64, !18, i64 68, !8, i64 72, !8, i64 132, !8, i64 252, !8, i64 312, !8, i64 372}
!18 = !{!"float", !8, i64 0}
!19 = !{!"bitrate_manager_info", !10, i64 0, !10, i64 8, !10, i64 16, !10, i64 24, !20, i64 32, !20, i64 40}
!20 = !{!"double", !8, i64 0}
!21 = !{!"highlevel_encode_setup", !7, i64 0, !11, i64 8, !20, i64 16, !20, i64 24, !18, i64 32, !7, i64 36, !10, i64 40, !10, i64 48, !20, i64 56, !10, i64 64, !10, i64 72, !20, i64 80, !7, i64 88, !7, i64 92, !7, i64 96, !20, i64 104, !20, i64 112, !7, i64 120, !20, i64 128, !20, i64 136, !20, i64 144, !20, i64 152, !8, i64 160}
!22 = distinct !{!22, !23}
!23 = !{!"llvm.loop.mustprogress"}
!24 = !{!11, !11, i64 0}
!25 = !{!26, !7, i64 0}
!26 = !{!"", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12}
!27 = !{!10, !10, i64 0}


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