; 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_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: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #0

; Function Attrs: nounwind allocsize(0)
declare noalias ptr @malloc(i64 noundef) #1

; Function Attrs: nounwind uwtable
define dso_local i32 @ogg_stream_init(ptr noundef %0, i32 noundef %1) #2 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  %6 = load ptr, ptr %4, align 8, !tbaa !5
  %7 = icmp ne ptr %6, null
  br i1 %7, label %8, label %57

8:                                                ; preds = %2
  %9 = load ptr, ptr %4, align 8, !tbaa !5
  call void @llvm.memset.p0.i64(ptr align 8 %9, i8 0, i64 408, i1 false)
  %10 = load ptr, ptr %4, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct.ogg_stream_state, ptr %10, i32 0, i32 1
  store i64 16384, ptr %11, align 8, !tbaa !11
  %12 = load ptr, ptr %4, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.ogg_stream_state, ptr %12, i32 0, i32 6
  store i64 1024, ptr %13, align 8, !tbaa !14
  %14 = load ptr, ptr %4, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.ogg_stream_state, ptr %14, i32 0, i32 1
  %16 = load i64, ptr %15, align 8, !tbaa !11
  %17 = mul i64 %16, 1
  %18 = call noalias ptr @malloc(i64 noundef %17) #3
  %19 = load ptr, ptr %4, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.ogg_stream_state, ptr %19, i32 0, i32 0
  store ptr %18, ptr %20, align 8, !tbaa !15
  %21 = load ptr, ptr %4, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.ogg_stream_state, ptr %21, i32 0, i32 6
  %23 = load i64, ptr %22, align 8, !tbaa !14
  %24 = mul i64 %23, 4
  %25 = call noalias ptr @malloc(i64 noundef %24) #3
  %26 = load ptr, ptr %4, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.ogg_stream_state, ptr %26, i32 0, i32 4
  store ptr %25, ptr %27, align 8, !tbaa !16
  %28 = load ptr, ptr %4, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.ogg_stream_state, ptr %28, i32 0, i32 6
  %30 = load i64, ptr %29, align 8, !tbaa !14
  %31 = mul i64 %30, 8
  %32 = call noalias ptr @malloc(i64 noundef %31) #3
  %33 = load ptr, ptr %4, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.ogg_stream_state, ptr %33, i32 0, i32 5
  store ptr %32, ptr %34, align 8, !tbaa !17
  %35 = load ptr, ptr %4, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.ogg_stream_state, ptr %35, i32 0, i32 0
  %37 = load ptr, ptr %36, align 8, !tbaa !15
  %38 = icmp ne ptr %37, null
  br i1 %38, label %39, label %49

39:                                               ; preds = %8
  %40 = load ptr, ptr %4, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.ogg_stream_state, ptr %40, i32 0, i32 4
  %42 = load ptr, ptr %41, align 8, !tbaa !16
  %43 = icmp ne ptr %42, null
  br i1 %43, label %44, label %49

44:                                               ; preds = %39
  %45 = load ptr, ptr %4, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.ogg_stream_state, ptr %45, i32 0, i32 5
  %47 = load ptr, ptr %46, align 8, !tbaa !17
  %48 = icmp ne ptr %47, null
  br i1 %48, label %52, label %49

49:                                               ; preds = %44, %39, %8
  %50 = load ptr, ptr %4, align 8, !tbaa !5
  %51 = call i32 @ogg_stream_clear(ptr noundef %50)
  store i32 -1, ptr %3, align 4
  br label %58

52:                                               ; preds = %44
  %53 = load i32, ptr %5, align 4, !tbaa !9
  %54 = sext i32 %53 to i64
  %55 = load ptr, ptr %4, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.ogg_stream_state, ptr %55, i32 0, i32 14
  store i64 %54, ptr %56, align 8, !tbaa !18
  store i32 0, ptr %3, align 4
  br label %58

57:                                               ; preds = %2
  store i32 -1, ptr %3, align 4
  br label %58

58:                                               ; preds = %57, %52, %49
  %59 = load i32, ptr %3, align 4
  ret i32 %59
}

; Function Attrs: nounwind uwtable
declare dso_local i32 @ogg_stream_clear(ptr noundef) #2

attributes #0 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #1 = { 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 #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 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 = !{!"int", !7, i64 0}
!11 = !{!12, !13, i64 8}
!12 = !{!"", !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}
!13 = !{!"long", !7, i64 0}
!14 = !{!12, !13, i64 48}
!15 = !{!12, !6, i64 0}
!16 = !{!12, !6, i64 32}
!17 = !{!12, !6, i64 40}
!18 = !{!12, !13, i64 376}


; 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 nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #0

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local range(i32 -1, 1) i32 @ogg_stream_init(ptr noundef %0, i32 noundef %1) local_unnamed_addr #2 {
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %18, label %3

3:                                                ; preds = %2
  %4 = getelementptr inbounds i8, ptr %0, i64 16
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(408) %4, i8 0, i64 392, i1 false)
  %5 = getelementptr inbounds i8, ptr %0, i64 8
  store i64 16384, ptr %5, align 8, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %0, i64 48
  store i64 1024, ptr %6, align 8, !tbaa !12
  %7 = tail call noalias dereferenceable_or_null(16384) ptr @malloc(i64 noundef 16384) #3
  store ptr %7, ptr %0, align 8, !tbaa !13
  %8 = tail call noalias dereferenceable_or_null(4096) ptr @malloc(i64 noundef 4096) #3
  %9 = getelementptr inbounds i8, ptr %0, i64 32
  store ptr %8, ptr %9, align 8, !tbaa !14
  %10 = tail call noalias dereferenceable_or_null(8192) ptr @malloc(i64 noundef 8192) #3
  %11 = getelementptr inbounds i8, ptr %0, i64 40
  store ptr %10, ptr %11, align 8, !tbaa !15
  %.not17 = icmp eq ptr %7, null
  br i1 %.not17, label %13, label %12

12:                                               ; preds = %3
  %.not18 = icmp eq ptr %8, null
  %.not19 = icmp eq ptr %10, null
  %or.cond = or i1 %.not18, %.not19
  br i1 %or.cond, label %13, label %15

13:                                               ; preds = %12, %3
  %14 = tail call i32 @ogg_stream_clear(ptr noundef nonnull %0)
  br label %18

15:                                               ; preds = %12
  %16 = sext i32 %1 to i64
  %17 = getelementptr inbounds i8, ptr %0, i64 376
  store i64 %16, ptr %17, align 8, !tbaa !16
  br label %18

18:                                               ; preds = %2, %15, %13
  %.0 = phi i32 [ 0, %15 ], [ -1, %13 ], [ -1, %2 ]
  ret i32 %.0
}

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

attributes #0 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #1 = { 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 #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 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 8}
!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 48}
!13 = !{!6, !7, i64 0}
!14 = !{!6, !7, i64 32}
!15 = !{!6, !7, i64 40}
!16 = !{!6, !10, i64 376}


; Effective O3 passes: DSEPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,SROAPass,SimplifyCFGPass,TailCallElimPass