; LLVM IR from clangen/musikcube :: src/plugins/stockencoders/LameEncoder.ll (ZN11LameEncoder5FlushEPPc)

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

%class.LameEncoder = type { %"class.musik::core::sdk::IStreamingEncoder", %struct.DataBuffer, %struct.DataBuffer.0, ptr }
%"class.musik::core::sdk::IStreamingEncoder" = type { %"class.musik::core::sdk::IEncoder" }
%"class.musik::core::sdk::IEncoder" = type { ptr }
%struct.DataBuffer = type { ptr, i64, i64, i64 }
%struct.DataBuffer.0 = type { ptr, i64, i64, i64 }

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN10DataBufferIhE5resetEm(ptr noundef nonnull align 8 dereferenceable(32), i64 noundef) #1 align 2

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

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN11LameEncoder5FlushEPPc(ptr noundef nonnull align 8 dereferenceable(80) %0, ptr noundef %1) unnamed_addr #1 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  %6 = load ptr, ptr %3, align 8
  %7 = getelementptr inbounds %class.LameEncoder, ptr %6, i32 0, i32 1
  %8 = getelementptr inbounds %struct.DataBuffer, ptr %7, i32 0, i32 2
  %9 = load i64, ptr %8, align 8, !tbaa !9
  %10 = icmp ult i64 %9, 7200
  br i1 %10, label %11, label %13

11:                                               ; preds = %2
  %12 = getelementptr inbounds %class.LameEncoder, ptr %6, i32 0, i32 1
  call void @_ZN10DataBufferIhE5resetEm(ptr noundef nonnull align 8 dereferenceable(32) %12, i64 noundef 7200)
  br label %13

13:                                               ; preds = %11, %2
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  %14 = getelementptr inbounds %class.LameEncoder, ptr %6, i32 0, i32 3
  %15 = load ptr, ptr %14, align 8, !tbaa !16
  %16 = getelementptr inbounds %class.LameEncoder, ptr %6, i32 0, i32 1
  %17 = getelementptr inbounds %struct.DataBuffer, ptr %16, i32 0, i32 0
  %18 = load ptr, ptr %17, align 8, !tbaa !17
  %19 = getelementptr inbounds %class.LameEncoder, ptr %6, i32 0, i32 1
  %20 = getelementptr inbounds %struct.DataBuffer, ptr %19, i32 0, i32 2
  %21 = load i64, ptr %20, align 8, !tbaa !9
  %22 = trunc i64 %21 to i32
  %23 = call i32 @lame_encode_flush(ptr noundef %15, ptr noundef %18, i32 noundef %22)
  store i32 %23, ptr %5, align 4, !tbaa !18
  %24 = getelementptr inbounds %class.LameEncoder, ptr %6, i32 0, i32 1
  %25 = getelementptr inbounds %struct.DataBuffer, ptr %24, i32 0, i32 0
  %26 = load ptr, ptr %25, align 8, !tbaa !17
  %27 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %26, ptr %27, align 8, !tbaa !5
  %28 = load i32, ptr %5, align 4, !tbaa !18
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  ret i32 %28
}

declare i32 @lame_encode_flush(ptr noundef, ptr noundef, i32 noundef) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress 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 = { "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++ TBAA"}
!9 = !{!10, !14, i64 24}
!10 = !{!"_ZTS11LameEncoder", !11, i64 0, !13, i64 8, !15, i64 40, !6, i64 72}
!11 = !{!"_ZTSN5musik4core3sdk17IStreamingEncoderE", !12, i64 0}
!12 = !{!"_ZTSN5musik4core3sdk8IEncoderE"}
!13 = !{!"_ZTS10DataBufferIhE", !6, i64 0, !14, i64 8, !14, i64 16, !14, i64 24}
!14 = !{!"long", !7, i64 0}
!15 = !{!"_ZTS10DataBufferIfE", !6, i64 0, !14, i64 8, !14, i64 16, !14, i64 24}
!16 = !{!10, !6, i64 72}
!17 = !{!10, !6, i64 8}
!18 = !{!19, !19, i64 0}
!19 = !{!"int", !7, 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"

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN10DataBufferIhE5resetEm(ptr noundef nonnull align 8 dereferenceable(32), i64 noundef) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN11LameEncoder5FlushEPPc(ptr noundef nonnull align 8 dereferenceable(80) %0, ptr nocapture noundef writeonly %1) unnamed_addr #0 align 2 {
  %3 = getelementptr inbounds i8, ptr %0, i64 8
  %4 = getelementptr inbounds i8, ptr %0, i64 24
  %5 = load i64, ptr %4, align 8, !tbaa !5
  %6 = icmp ult i64 %5, 7200
  br i1 %6, label %7, label %8

7:                                                ; preds = %2
  tail call void @_ZN10DataBufferIhE5resetEm(ptr noundef nonnull align 8 dereferenceable(32) %3, i64 noundef 7200)
  %.pre = load i64, ptr %4, align 8, !tbaa !5
  br label %8

8:                                                ; preds = %7, %2
  %9 = phi i64 [ %.pre, %7 ], [ %5, %2 ]
  %10 = getelementptr inbounds i8, ptr %0, i64 72
  %11 = load ptr, ptr %10, align 8, !tbaa !15
  %12 = load ptr, ptr %3, align 8, !tbaa !16
  %13 = trunc i64 %9 to i32
  %14 = tail call i32 @lame_encode_flush(ptr noundef %11, ptr noundef %12, i32 noundef %13)
  %15 = load ptr, ptr %3, align 8, !tbaa !16
  store ptr %15, ptr %1, align 8, !tbaa !17
  ret i32 %14
}

declare i32 @lame_encode_flush(ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #1

attributes #0 = { mustprogress 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 #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" }

!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, !13, i64 24}
!6 = !{!"_ZTS11LameEncoder", !7, i64 0, !9, i64 8, !14, i64 40, !10, i64 72}
!7 = !{!"_ZTSN5musik4core3sdk17IStreamingEncoderE", !8, i64 0}
!8 = !{!"_ZTSN5musik4core3sdk8IEncoderE"}
!9 = !{!"_ZTS10DataBufferIhE", !10, i64 0, !13, i64 8, !13, i64 16, !13, i64 24}
!10 = !{!"any pointer", !11, i64 0}
!11 = !{!"omnipotent char", !12, i64 0}
!12 = !{!"Simple C++ TBAA"}
!13 = !{!"long", !11, i64 0}
!14 = !{!"_ZTS10DataBufferIfE", !10, i64 0, !13, i64 8, !13, i64 16, !13, i64 24}
!15 = !{!6, !10, i64 72}
!16 = !{!6, !10, i64 8}
!17 = !{!10, !10, i64 0}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,TailCallElimPass