; LLVM IR from VoidRune/Audio-engine :: src (minivorbis)

; 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_sync_state = type { ptr, i32, i32, i32, i32, i32, i32 }

; Function Attrs: nounwind allocsize(0)
declare noalias ptr @malloc(i64 noundef) #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 allocsize(1)
declare ptr @realloc(ptr noundef, i64 noundef) #2

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memmove.p0.p0.i64(ptr nocapture writeonly, ptr nocapture readonly, i64, i1 immarg) #3

; Function Attrs: nounwind uwtable
declare dso_local i32 @ogg_sync_clear(ptr noundef) #4

; Function Attrs: nounwind uwtable
declare dso_local i32 @ogg_sync_check(ptr noundef) #4

; Function Attrs: nounwind uwtable
define dso_local ptr @ogg_sync_buffer(ptr noundef %0, i64 noundef %1) #4 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i64 %1, ptr %5, align 8, !tbaa !9
  %9 = load ptr, ptr %4, align 8, !tbaa !5
  %10 = call i32 @ogg_sync_check(ptr noundef %9)
  %11 = icmp ne i32 %10, 0
  br i1 %11, label %12, label %13

12:                                               ; preds = %2
  store ptr null, ptr %3, align 8
  br label %107

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

18:                                               ; preds = %13
  %19 = load ptr, ptr %4, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.ogg_sync_state, ptr %19, i32 0, i32 3
  %21 = load i32, ptr %20, align 8, !tbaa !11
  %22 = load ptr, ptr %4, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.ogg_sync_state, ptr %22, i32 0, i32 2
  %24 = load i32, ptr %23, align 4, !tbaa !14
  %25 = sub nsw i32 %24, %21
  store i32 %25, ptr %23, align 4, !tbaa !14
  %26 = load ptr, ptr %4, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.ogg_sync_state, ptr %26, i32 0, i32 2
  %28 = load i32, ptr %27, align 4, !tbaa !14
  %29 = icmp sgt i32 %28, 0
  br i1 %29, label %30, label %46

30:                                               ; preds = %18
  %31 = load ptr, ptr %4, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.ogg_sync_state, ptr %31, i32 0, i32 0
  %33 = load ptr, ptr %32, align 8, !tbaa !15
  %34 = load ptr, ptr %4, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.ogg_sync_state, ptr %34, i32 0, i32 0
  %36 = load ptr, ptr %35, align 8, !tbaa !15
  %37 = load ptr, ptr %4, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.ogg_sync_state, ptr %37, i32 0, i32 3
  %39 = load i32, ptr %38, align 8, !tbaa !11
  %40 = sext i32 %39 to i64
  %41 = getelementptr inbounds i8, ptr %36, i64 %40
  %42 = load ptr, ptr %4, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.ogg_sync_state, ptr %42, i32 0, i32 2
  %44 = load i32, ptr %43, align 4, !tbaa !14
  %45 = sext i32 %44 to i64
  call void @llvm.memmove.p0.p0.i64(ptr align 1 %33, ptr align 1 %41, i64 %45, i1 false)
  br label %46

46:                                               ; preds = %30, %18
  %47 = load ptr, ptr %4, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.ogg_sync_state, ptr %47, i32 0, i32 3
  store i32 0, ptr %48, align 8, !tbaa !11
  br label %49

49:                                               ; preds = %46, %13
  %50 = load i64, ptr %5, align 8, !tbaa !9
  %51 = load ptr, ptr %4, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.ogg_sync_state, ptr %51, i32 0, i32 1
  %53 = load i32, ptr %52, align 8, !tbaa !16
  %54 = load ptr, ptr %4, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.ogg_sync_state, ptr %54, i32 0, i32 2
  %56 = load i32, ptr %55, align 4, !tbaa !14
  %57 = sub nsw i32 %53, %56
  %58 = sext i32 %57 to i64
  %59 = icmp sgt i64 %50, %58
  br i1 %59, label %60, label %98

60:                                               ; preds = %49
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #5
  %61 = load i64, ptr %5, align 8, !tbaa !9
  %62 = load ptr, ptr %4, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.ogg_sync_state, ptr %62, i32 0, i32 2
  %64 = load i32, ptr %63, align 4, !tbaa !14
  %65 = sext i32 %64 to i64
  %66 = add nsw i64 %61, %65
  %67 = add nsw i64 %66, 4096
  store i64 %67, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #5
  %68 = load ptr, ptr %4, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct.ogg_sync_state, ptr %68, i32 0, i32 0
  %70 = load ptr, ptr %69, align 8, !tbaa !15
  %71 = icmp ne ptr %70, null
  br i1 %71, label %72, label %78

72:                                               ; preds = %60
  %73 = load ptr, ptr %4, align 8, !tbaa !5
  %74 = getelementptr inbounds %struct.ogg_sync_state, ptr %73, i32 0, i32 0
  %75 = load ptr, ptr %74, align 8, !tbaa !15
  %76 = load i64, ptr %6, align 8, !tbaa !9
  %77 = call ptr @realloc(ptr noundef %75, i64 noundef %76) #6
  store ptr %77, ptr %7, align 8, !tbaa !5
  br label %81

78:                                               ; preds = %60
  %79 = load i64, ptr %6, align 8, !tbaa !9
  %80 = call noalias ptr @malloc(i64 noundef %79) #7
  store ptr %80, ptr %7, align 8, !tbaa !5
  br label %81

81:                                               ; preds = %78, %72
  %82 = load ptr, ptr %7, align 8, !tbaa !5
  %83 = icmp ne ptr %82, null
  br i1 %83, label %87, label %84

84:                                               ; preds = %81
  %85 = load ptr, ptr %4, align 8, !tbaa !5
  %86 = call i32 @ogg_sync_clear(ptr noundef %85)
  store ptr null, ptr %3, align 8
  store i32 1, ptr %8, align 4
  br label %95

87:                                               ; preds = %81
  %88 = load ptr, ptr %7, align 8, !tbaa !5
  %89 = load ptr, ptr %4, align 8, !tbaa !5
  %90 = getelementptr inbounds %struct.ogg_sync_state, ptr %89, i32 0, i32 0
  store ptr %88, ptr %90, align 8, !tbaa !15
  %91 = load i64, ptr %6, align 8, !tbaa !9
  %92 = trunc i64 %91 to i32
  %93 = load ptr, ptr %4, align 8, !tbaa !5
  %94 = getelementptr inbounds %struct.ogg_sync_state, ptr %93, i32 0, i32 1
  store i32 %92, ptr %94, align 8, !tbaa !16
  store i32 0, ptr %8, align 4
  br label %95

95:                                               ; preds = %87, %84
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #5
  %96 = load i32, ptr %8, align 4
  switch i32 %96, label %109 [
    i32 0, label %97
    i32 1, label %107
  ]

97:                                               ; preds = %95
  br label %98

98:                                               ; preds = %97, %49
  %99 = load ptr, ptr %4, align 8, !tbaa !5
  %100 = getelementptr inbounds %struct.ogg_sync_state, ptr %99, i32 0, i32 0
  %101 = load ptr, ptr %100, align 8, !tbaa !15
  %102 = load ptr, ptr %4, align 8, !tbaa !5
  %103 = getelementptr inbounds %struct.ogg_sync_state, ptr %102, i32 0, i32 2
  %104 = load i32, ptr %103, align 4, !tbaa !14
  %105 = sext i32 %104 to i64
  %106 = getelementptr inbounds i8, ptr %101, i64 %105
  store ptr %106, ptr %3, align 8
  br label %107

107:                                              ; preds = %98, %95, %12
  %108 = load ptr, ptr %3, align 8
  ret ptr %108

109:                                              ; preds = %95
  unreachable
}

attributes #0 = { nounwind allocsize(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 = { nounwind allocsize(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 #3 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { 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 #5 = { nounwind }
attributes #6 = { nounwind allocsize(1) }
attributes #7 = { nounwind allocsize(0) }

!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 = !{!"long", !7, i64 0}
!11 = !{!12, !13, i64 16}
!12 = !{!"", !6, i64 0, !13, i64 8, !13, i64 12, !13, i64 16, !13, i64 20, !13, i64 24, !13, i64 28}
!13 = !{!"int", !7, i64 0}
!14 = !{!12, !13, i64 12}
!15 = !{!12, !6, i64 0}
!16 = !{!12, !13, i64 8}


; 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: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind willreturn allockind("realloc") allocsize(1) memory(argmem: readwrite, inaccessiblemem: readwrite)
declare noalias noundef ptr @realloc(ptr allocptr nocapture noundef, i64 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memmove.p0.p0.i64(ptr nocapture writeonly, ptr nocapture readonly, i64, i1 immarg) #2

; Function Attrs: nounwind uwtable
declare dso_local i32 @ogg_sync_clear(ptr noundef) local_unnamed_addr #3

; Function Attrs: nounwind uwtable
declare dso_local i32 @ogg_sync_check(ptr noundef) local_unnamed_addr #3

; Function Attrs: nounwind uwtable
define dso_local ptr @ogg_sync_buffer(ptr noundef %0, i64 noundef %1) local_unnamed_addr #3 {
  %3 = tail call i32 @ogg_sync_check(ptr noundef %0)
  %.not = icmp eq i32 %3, 0
  br i1 %.not, label %4, label %43

4:                                                ; preds = %2
  %5 = getelementptr inbounds i8, ptr %0, i64 16
  %6 = load i32, ptr %5, align 8, !tbaa !5
  %.not34 = icmp eq i32 %6, 0
  br i1 %.not34, label %18, label %7

7:                                                ; preds = %4
  %8 = getelementptr inbounds i8, ptr %0, i64 12
  %9 = load i32, ptr %8, align 4, !tbaa !11
  %10 = sub nsw i32 %9, %6
  store i32 %10, ptr %8, align 4, !tbaa !11
  %11 = icmp sgt i32 %10, 0
  br i1 %11, label %12, label %17

12:                                               ; preds = %7
  %13 = load ptr, ptr %0, align 8, !tbaa !12
  %14 = sext i32 %6 to i64
  %15 = getelementptr inbounds i8, ptr %13, i64 %14
  %16 = zext nneg i32 %10 to i64
  tail call void @llvm.memmove.p0.p0.i64(ptr align 1 %13, ptr nonnull align 1 %15, i64 %16, i1 false)
  br label %17

17:                                               ; preds = %12, %7
  store i32 0, ptr %5, align 8, !tbaa !5
  br label %18

18:                                               ; preds = %17, %4
  %19 = getelementptr inbounds i8, ptr %0, i64 8
  %20 = load i32, ptr %19, align 8, !tbaa !13
  %21 = getelementptr inbounds i8, ptr %0, i64 12
  %22 = load i32, ptr %21, align 4, !tbaa !11
  %23 = sub nsw i32 %20, %22
  %24 = sext i32 %23 to i64
  %25 = icmp slt i64 %24, %1
  %.pre = load ptr, ptr %0, align 8, !tbaa !12
  br i1 %25, label %26, label %38

26:                                               ; preds = %18
  %27 = sext i32 %22 to i64
  %28 = add i64 %1, 4096
  %29 = add i64 %28, %27
  %.not35 = icmp eq ptr %.pre, null
  br i1 %.not35, label %32, label %30

30:                                               ; preds = %26
  %31 = tail call ptr @realloc(ptr noundef nonnull %.pre, i64 noundef %29) #4
  br label %34

32:                                               ; preds = %26
  %33 = tail call noalias ptr @malloc(i64 noundef %29) #5
  br label %34

34:                                               ; preds = %32, %30
  %.028 = phi ptr [ %31, %30 ], [ %33, %32 ]
  %.not36 = icmp eq ptr %.028, null
  br i1 %.not36, label %36, label %.thread

.thread:                                          ; preds = %34
  store ptr %.028, ptr %0, align 8, !tbaa !12
  %35 = trunc i64 %29 to i32
  store i32 %35, ptr %19, align 8, !tbaa !13
  %.pre38 = load i32, ptr %21, align 4, !tbaa !11
  br label %38

36:                                               ; preds = %34
  %37 = tail call i32 @ogg_sync_clear(ptr noundef nonnull %0)
  br label %43

38:                                               ; preds = %.thread, %18
  %39 = phi i32 [ %.pre38, %.thread ], [ %22, %18 ]
  %40 = phi ptr [ %.028, %.thread ], [ %.pre, %18 ]
  %41 = sext i32 %39 to i64
  %42 = getelementptr inbounds i8, ptr %40, i64 %41
  br label %43

43:                                               ; preds = %36, %2, %38
  %.1 = phi ptr [ null, %36 ], [ %42, %38 ], [ null, %2 ]
  ret ptr %.1
}

attributes #0 = { mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" "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 nounwind willreturn allockind("realloc") allocsize(1) memory(argmem: readwrite, inaccessiblemem: readwrite) "alloc-family"="malloc" "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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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 allocsize(1) }
attributes #5 = { nounwind allocsize(0) }

!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 16}
!6 = !{!"", !7, i64 0, !10, i64 8, !10, i64 12, !10, i64 16, !10, i64 20, !10, i64 24, !10, i64 28}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!6, !10, i64 12}
!12 = !{!6, !7, i64 0}
!13 = !{!6, !10, i64 8}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass