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

; 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.OggVorbis_File = type { ptr, i32, i64, i64, %struct.ogg_sync_state, i32, ptr, ptr, ptr, ptr, ptr, ptr, i64, i32, i64, i32, double, double, %struct.ogg_stream_state, %struct.vorbis_dsp_state, %struct.vorbis_block, %struct.ov_callbacks }
%struct.ogg_sync_state = type { ptr, i32, i32, i32, i32, i32, i32 }
%struct.ogg_stream_state = type { ptr, i64, i64, i64, ptr, ptr, i64, i64, i64, i64, [282 x i8], i32, i32, i32, i64, i64, i64, i64 }
%struct.vorbis_dsp_state = type { i32, ptr, ptr, ptr, i32, i32, i32, i32, i32, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, ptr }
%struct.vorbis_block = type { ptr, %struct.oggpack_buffer, i64, i64, i64, i32, i32, i32, i64, i64, ptr, ptr, i64, i64, i64, ptr, i64, i64, i64, i64, ptr }
%struct.oggpack_buffer = type { i64, i32, ptr, ptr, i64 }
%struct.ov_callbacks = type { ptr, ptr, ptr, ptr }

; 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: nounwind uwtable
define dso_local i64 @ov_raw_total(ptr noundef %0, i32 noundef %1) #1 {
  %3 = alloca i64, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i64, align 8
  %7 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  %8 = load ptr, ptr %4, align 8, !tbaa !5
  %9 = getelementptr inbounds %struct.OggVorbis_File, ptr %8, i32 0, i32 13
  %10 = load i32, ptr %9, align 8, !tbaa !11
  %11 = icmp slt i32 %10, 2
  br i1 %11, label %12, label %13

12:                                               ; preds = %2
  store i64 -131, ptr %3, align 8
  br label %63

13:                                               ; preds = %2
  %14 = load ptr, ptr %4, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.OggVorbis_File, ptr %14, i32 0, i32 1
  %16 = load i32, ptr %15, align 8, !tbaa !21
  %17 = icmp ne i32 %16, 0
  br i1 %17, label %18, label %24

18:                                               ; preds = %13
  %19 = load i32, ptr %5, align 4, !tbaa !9
  %20 = load ptr, ptr %4, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.OggVorbis_File, ptr %20, i32 0, i32 5
  %22 = load i32, ptr %21, align 8, !tbaa !22
  %23 = icmp sge i32 %19, %22
  br i1 %23, label %24, label %25

24:                                               ; preds = %18, %13
  store i64 -131, ptr %3, align 8
  br label %63

25:                                               ; preds = %18
  %26 = load i32, ptr %5, align 4, !tbaa !9
  %27 = icmp slt i32 %26, 0
  br i1 %27, label %28, label %46

28:                                               ; preds = %25
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #2
  store i64 0, ptr %6, align 8, !tbaa !23
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #2
  store i32 0, ptr %7, align 4, !tbaa !9
  br label %29

29:                                               ; preds = %41, %28
  %30 = load i32, ptr %7, align 4, !tbaa !9
  %31 = load ptr, ptr %4, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.OggVorbis_File, ptr %31, i32 0, i32 5
  %33 = load i32, ptr %32, align 8, !tbaa !22
  %34 = icmp slt i32 %30, %33
  br i1 %34, label %35, label %44

35:                                               ; preds = %29
  %36 = load ptr, ptr %4, align 8, !tbaa !5
  %37 = load i32, ptr %7, align 4, !tbaa !9
  %38 = call i64 @ov_raw_total(ptr noundef %36, i32 noundef %37)
  %39 = load i64, ptr %6, align 8, !tbaa !23
  %40 = add nsw i64 %39, %38
  store i64 %40, ptr %6, align 8, !tbaa !23
  br label %41

41:                                               ; preds = %35
  %42 = load i32, ptr %7, align 4, !tbaa !9
  %43 = add nsw i32 %42, 1
  store i32 %43, ptr %7, align 4, !tbaa !9
  br label %29, !llvm.loop !24

44:                                               ; preds = %29
  %45 = load i64, ptr %6, align 8, !tbaa !23
  store i64 %45, ptr %3, align 8
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #2
  br label %63

46:                                               ; preds = %25
  %47 = load ptr, ptr %4, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.OggVorbis_File, ptr %47, i32 0, i32 6
  %49 = load ptr, ptr %48, align 8, !tbaa !26
  %50 = load i32, ptr %5, align 4, !tbaa !9
  %51 = add nsw i32 %50, 1
  %52 = sext i32 %51 to i64
  %53 = getelementptr inbounds i64, ptr %49, i64 %52
  %54 = load i64, ptr %53, align 8, !tbaa !23
  %55 = load ptr, ptr %4, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.OggVorbis_File, ptr %55, i32 0, i32 6
  %57 = load ptr, ptr %56, align 8, !tbaa !26
  %58 = load i32, ptr %5, align 4, !tbaa !9
  %59 = sext i32 %58 to i64
  %60 = getelementptr inbounds i64, ptr %57, i64 %59
  %61 = load i64, ptr %60, align 8, !tbaa !23
  %62 = sub nsw i64 %54, %61
  store i64 %62, ptr %3, align 8
  br label %63

63:                                               ; preds = %46, %44, %24, %12
  %64 = load i64, ptr %3, align 8
  ret i64 %64
}

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 = !{!"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 128}
!12 = !{!"OggVorbis_File", !6, i64 0, !10, i64 8, !13, i64 16, !13, i64 24, !14, i64 32, !10, i64 64, !6, i64 72, !6, i64 80, !6, i64 88, !6, i64 96, !6, i64 104, !6, i64 112, !13, i64 120, !10, i64 128, !13, i64 136, !10, i64 144, !15, i64 152, !15, i64 160, !16, i64 168, !17, i64 576, !18, i64 720, !20, i64 912}
!13 = !{!"long", !7, i64 0}
!14 = !{!"", !6, i64 0, !10, i64 8, !10, i64 12, !10, i64 16, !10, i64 20, !10, i64 24, !10, i64 28}
!15 = !{!"double", !7, i64 0}
!16 = !{!"", !6, i64 0, !13, i64 8, !13, i64 16, !13, i64 24, !6, i64 32, !6, i64 40, !13, i64 48, !13, i64 56, !13, i64 64, !13, i64 72, !7, i64 80, !10, i64 364, !10, i64 368, !10, i64 372, !13, i64 376, !13, i64 384, !13, i64 392, !13, i64 400}
!17 = !{!"vorbis_dsp_state", !10, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !10, i64 32, !10, i64 36, !10, i64 40, !10, i64 44, !10, i64 48, !13, i64 56, !13, i64 64, !13, i64 72, !13, i64 80, !13, i64 88, !13, i64 96, !13, i64 104, !13, i64 112, !13, i64 120, !13, i64 128, !6, i64 136}
!18 = !{!"vorbis_block", !6, i64 0, !19, i64 8, !13, i64 48, !13, i64 56, !13, i64 64, !10, i64 72, !10, i64 76, !10, i64 80, !13, i64 88, !13, i64 96, !6, i64 104, !6, i64 112, !13, i64 120, !13, i64 128, !13, i64 136, !6, i64 144, !13, i64 152, !13, i64 160, !13, i64 168, !13, i64 176, !6, i64 184}
!19 = !{!"", !13, i64 0, !10, i64 8, !6, i64 16, !6, i64 24, !13, i64 32}
!20 = !{!"", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24}
!21 = !{!12, !10, i64 8}
!22 = !{!12, !10, i64 64}
!23 = !{!13, !13, i64 0}
!24 = distinct !{!24, !25}
!25 = !{!"llvm.loop.mustprogress"}
!26 = !{!12, !6, i64 72}


; 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: nofree nosync nounwind memory(read, inaccessiblemem: none) uwtable
define dso_local i64 @ov_raw_total(ptr nocapture noundef readonly %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = getelementptr inbounds i8, ptr %0, i64 128
  %4 = load i32, ptr %3, align 8, !tbaa !5
  %5 = icmp slt i32 %4, 2
  br i1 %5, label %.loopexit, label %6

6:                                                ; preds = %2
  %7 = getelementptr inbounds i8, ptr %0, i64 8
  %8 = load i32, ptr %7, align 8, !tbaa !19
  %.not = icmp eq i32 %8, 0
  br i1 %.not, label %.loopexit, label %9

9:                                                ; preds = %6
  %10 = getelementptr inbounds i8, ptr %0, i64 64
  %11 = load i32, ptr %10, align 8, !tbaa !20
  %.not19 = icmp sgt i32 %11, %1
  br i1 %.not19, label %12, label %.loopexit

12:                                               ; preds = %9
  %13 = icmp slt i32 %1, 0
  br i1 %13, label %.preheader, label %18

.preheader:                                       ; preds = %12
  %14 = icmp sgt i32 %11, 0
  br i1 %14, label %.lr.ph, label %.loopexit

.lr.ph:                                           ; preds = %.preheader, %.lr.ph
  %.021 = phi i32 [ %17, %.lr.ph ], [ 0, %.preheader ]
  %.01620 = phi i64 [ %16, %.lr.ph ], [ 0, %.preheader ]
  %15 = tail call i64 @ov_raw_total(ptr noundef %0, i32 noundef %.021)
  %16 = add nsw i64 %15, %.01620
  %17 = add nuw nsw i32 %.021, 1
  %exitcond.not = icmp eq i32 %17, %11
  br i1 %exitcond.not, label %.loopexit, label %.lr.ph, !llvm.loop !21

18:                                               ; preds = %12
  %19 = getelementptr inbounds i8, ptr %0, i64 72
  %20 = load ptr, ptr %19, align 8, !tbaa !23
  %21 = zext nneg i32 %1 to i64
  %22 = getelementptr inbounds i64, ptr %20, i64 %21
  %23 = getelementptr inbounds i8, ptr %22, i64 8
  %24 = load i64, ptr %23, align 8, !tbaa !24
  %25 = load i64, ptr %22, align 8, !tbaa !24
  %26 = sub nsw i64 %24, %25
  br label %.loopexit

.loopexit:                                        ; preds = %.lr.ph, %.preheader, %6, %9, %2, %18
  %.017 = phi i64 [ %26, %18 ], [ -131, %2 ], [ -131, %9 ], [ -131, %6 ], [ 0, %.preheader ], [ %16, %.lr.ph ]
  ret i64 %.017
}

attributes #0 = { nofree nosync nounwind memory(read, inaccessiblemem: 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)"}
!5 = !{!6, !10, i64 128}
!6 = !{!"OggVorbis_File", !7, i64 0, !10, i64 8, !11, i64 16, !11, i64 24, !12, i64 32, !10, i64 64, !7, i64 72, !7, i64 80, !7, i64 88, !7, i64 96, !7, i64 104, !7, i64 112, !11, i64 120, !10, i64 128, !11, i64 136, !10, i64 144, !13, i64 152, !13, i64 160, !14, i64 168, !15, i64 576, !16, i64 720, !18, i64 912}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"long", !8, i64 0}
!12 = !{!"", !7, i64 0, !10, i64 8, !10, i64 12, !10, i64 16, !10, i64 20, !10, i64 24, !10, i64 28}
!13 = !{!"double", !8, i64 0}
!14 = !{!"", !7, i64 0, !11, i64 8, !11, i64 16, !11, i64 24, !7, i64 32, !7, i64 40, !11, i64 48, !11, i64 56, !11, i64 64, !11, i64 72, !8, i64 80, !10, i64 364, !10, i64 368, !10, i64 372, !11, i64 376, !11, i64 384, !11, i64 392, !11, i64 400}
!15 = !{!"vorbis_dsp_state", !10, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !10, i64 32, !10, i64 36, !10, i64 40, !10, i64 44, !10, i64 48, !11, i64 56, !11, i64 64, !11, i64 72, !11, i64 80, !11, i64 88, !11, i64 96, !11, i64 104, !11, i64 112, !11, i64 120, !11, i64 128, !7, i64 136}
!16 = !{!"vorbis_block", !7, i64 0, !17, i64 8, !11, i64 48, !11, i64 56, !11, i64 64, !10, i64 72, !10, i64 76, !10, i64 80, !11, i64 88, !11, i64 96, !7, i64 104, !7, i64 112, !11, i64 120, !11, i64 128, !11, i64 136, !7, i64 144, !11, i64 152, !11, i64 160, !11, i64 168, !11, i64 176, !7, i64 184}
!17 = !{!"", !11, i64 0, !10, i64 8, !7, i64 16, !7, i64 24, !11, i64 32}
!18 = !{!"", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24}
!19 = !{!6, !10, i64 8}
!20 = !{!6, !10, i64 64}
!21 = distinct !{!21, !22}
!22 = !{!"llvm.loop.mustprogress"}
!23 = !{!6, !7, i64 72}
!24 = !{!11, !11, i64 0}


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