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

; 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.ogg_stream_state = type { ptr, i64, i64, i64, ptr, ptr, i64, i64, i64, i64, [282 x i8], i32, i32, i32, i64, i64, i64, i64 }

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

; Function Attrs: nounwind uwtable
define dso_local i32 @ogg_stream_pageout(ptr noundef %0, ptr noundef %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  %6 = load ptr, ptr %4, align 8, !tbaa !5
  %7 = getelementptr inbounds %struct.ogg_stream_state, ptr %6, i32 0, i32 12
  %8 = load i32, ptr %7, align 8, !tbaa !9
  %9 = icmp ne i32 %8, 0
  br i1 %9, label %10, label %15

10:                                               ; preds = %2
  %11 = load ptr, ptr %4, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.ogg_stream_state, ptr %11, i32 0, i32 7
  %13 = load i64, ptr %12, align 8, !tbaa !13
  %14 = icmp ne i64 %13, 0
  br i1 %14, label %39, label %15

15:                                               ; preds = %10, %2
  %16 = load ptr, ptr %4, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.ogg_stream_state, ptr %16, i32 0, i32 2
  %18 = load i64, ptr %17, align 8, !tbaa !14
  %19 = load ptr, ptr %4, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.ogg_stream_state, ptr %19, i32 0, i32 3
  %21 = load i64, ptr %20, align 8, !tbaa !15
  %22 = sub nsw i64 %18, %21
  %23 = icmp sgt i64 %22, 4096
  br i1 %23, label %39, label %24

24:                                               ; preds = %15
  %25 = load ptr, ptr %4, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.ogg_stream_state, ptr %25, i32 0, i32 7
  %27 = load i64, ptr %26, align 8, !tbaa !13
  %28 = icmp sge i64 %27, 255
  br i1 %28, label %39, label %29

29:                                               ; preds = %24
  %30 = load ptr, ptr %4, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.ogg_stream_state, ptr %30, i32 0, i32 7
  %32 = load i64, ptr %31, align 8, !tbaa !13
  %33 = icmp ne i64 %32, 0
  br i1 %33, label %34, label %43

34:                                               ; preds = %29
  %35 = load ptr, ptr %4, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.ogg_stream_state, ptr %35, i32 0, i32 13
  %37 = load i32, ptr %36, align 4, !tbaa !16
  %38 = icmp ne i32 %37, 0
  br i1 %38, label %43, label %39

39:                                               ; preds = %34, %24, %15, %10
  %40 = load ptr, ptr %4, align 8, !tbaa !5
  %41 = load ptr, ptr %5, align 8, !tbaa !5
  %42 = call i32 @ogg_stream_flush(ptr noundef %40, ptr noundef %41)
  store i32 %42, ptr %3, align 4
  br label %44

43:                                               ; preds = %34, %29
  store i32 0, ptr %3, align 4
  br label %44

44:                                               ; preds = %43, %39
  %45 = load i32, ptr %3, align 4
  ret i32 %45
}

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

!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, !12, i64 368}
!10 = !{!"", !6, i64 0, !11, i64 8, !11, i64 16, !11, i64 24, !6, i64 32, !6, i64 40, !11, i64 48, !11, i64 56, !11, i64 64, !11, i64 72, !7, i64 80, !12, i64 364, !12, i64 368, !12, i64 372, !11, i64 376, !11, i64 384, !11, i64 392, !11, i64 400}
!11 = !{!"long", !7, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!10, !11, i64 56}
!14 = !{!10, !11, i64 16}
!15 = !{!10, !11, i64 24}
!16 = !{!10, !12, i64 372}


; 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
declare dso_local i32 @ogg_stream_flush(ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local i32 @ogg_stream_pageout(ptr noundef %0, ptr noundef %1) local_unnamed_addr #0 {
  %3 = getelementptr inbounds i8, ptr %0, i64 368
  %4 = load i32, ptr %3, align 8, !tbaa !5
  %.not = icmp eq i32 %4, 0
  br i1 %.not, label %8, label %5

5:                                                ; preds = %2
  %6 = getelementptr inbounds i8, ptr %0, i64 56
  %7 = load i64, ptr %6, align 8, !tbaa !12
  %.not10 = icmp eq i64 %7, 0
  br i1 %.not10, label %8, label %23

8:                                                ; preds = %5, %2
  %9 = getelementptr inbounds i8, ptr %0, i64 16
  %10 = load i64, ptr %9, align 8, !tbaa !13
  %11 = getelementptr inbounds i8, ptr %0, i64 24
  %12 = load i64, ptr %11, align 8, !tbaa !14
  %13 = sub nsw i64 %10, %12
  %14 = icmp sgt i64 %13, 4096
  br i1 %14, label %23, label %15

15:                                               ; preds = %8
  %16 = getelementptr inbounds i8, ptr %0, i64 56
  %17 = load i64, ptr %16, align 8, !tbaa !12
  %18 = icmp sgt i64 %17, 254
  br i1 %18, label %23, label %19

19:                                               ; preds = %15
  %.not11 = icmp eq i64 %17, 0
  br i1 %.not11, label %25, label %20

20:                                               ; preds = %19
  %21 = getelementptr inbounds i8, ptr %0, i64 372
  %22 = load i32, ptr %21, align 4, !tbaa !15
  %.not12 = icmp eq i32 %22, 0
  br i1 %.not12, label %23, label %25

23:                                               ; preds = %20, %15, %8, %5
  %24 = tail call i32 @ogg_stream_flush(ptr noundef nonnull %0, ptr noundef %1)
  br label %25

25:                                               ; preds = %19, %20, %23
  %.0 = phi i32 [ %24, %23 ], [ 0, %20 ], [ 0, %19 ]
  ret i32 %.0
}

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

!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 368}
!6 = !{!"", !7, i64 0, !10, i64 8, !10, i64 16, !10, i64 24, !7, i64 32, !7, i64 40, !10, i64 48, !10, i64 56, !10, i64 64, !10, i64 72, !8, i64 80, !11, i64 364, !11, i64 368, !11, i64 372, !10, i64 376, !10, i64 384, !10, i64 392, !10, i64 400}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"long", !8, i64 0}
!11 = !{!"int", !8, i64 0}
!12 = !{!6, !10, i64 56}
!13 = !{!6, !10, i64 16}
!14 = !{!6, !10, i64 24}
!15 = !{!6, !11, i64 372}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,InstCombinePass,SROAPass,SimplifyCFGPass,TailCallElimPass