; LLVM IR from clangen/musikcube :: src/plugins/stockencoders/FfmpegEncoder.ll (ZN13FfmpegEncoder7CleanupEv)

; 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.FfmpegEncoder = type { %"class.musik::core::sdk::IBlockingEncoder", i8, ptr, i32, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, i64, %"class.std::__cxx11::basic_string", i32, i32 }
%"class.musik::core::sdk::IBlockingEncoder" = type { %"class.musik::core::sdk::IEncoder" }
%"class.musik::core::sdk::IEncoder" = type { ptr }
%"class.std::__cxx11::basic_string" = type { %"struct.std::__cxx11::basic_string<char>::_Alloc_hider", i64, %union.anon }
%"struct.std::__cxx11::basic_string<char>::_Alloc_hider" = type { ptr }
%union.anon = type { i64, [8 x i8] }

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN13FfmpegEncoder7CleanupEv(ptr noundef nonnull align 8 dereferenceable(152) %0) #0 align 2 {
  %2 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  %3 = load ptr, ptr %2, align 8
  %4 = getelementptr inbounds %class.FfmpegEncoder, ptr %3, i32 0, i32 1
  store i8 0, ptr %4, align 8, !tbaa !9
  %5 = getelementptr inbounds %class.FfmpegEncoder, ptr %3, i32 0, i32 10
  %6 = load ptr, ptr %5, align 8, !tbaa !18
  %7 = icmp ne ptr %6, null
  br i1 %7, label %8, label %11

8:                                                ; preds = %1
  %9 = getelementptr inbounds %class.FfmpegEncoder, ptr %3, i32 0, i32 10
  call void @av_frame_free(ptr noundef %9)
  %10 = getelementptr inbounds %class.FfmpegEncoder, ptr %3, i32 0, i32 10
  store ptr null, ptr %10, align 8, !tbaa !18
  br label %11

11:                                               ; preds = %8, %1
  %12 = getelementptr inbounds %class.FfmpegEncoder, ptr %3, i32 0, i32 11
  %13 = load ptr, ptr %12, align 8, !tbaa !19
  %14 = icmp ne ptr %13, null
  br i1 %14, label %15, label %18

15:                                               ; preds = %11
  %16 = getelementptr inbounds %class.FfmpegEncoder, ptr %3, i32 0, i32 11
  call void @av_frame_free(ptr noundef %16)
  %17 = getelementptr inbounds %class.FfmpegEncoder, ptr %3, i32 0, i32 11
  store ptr null, ptr %17, align 8, !tbaa !19
  br label %18

18:                                               ; preds = %15, %11
  %19 = getelementptr inbounds %class.FfmpegEncoder, ptr %3, i32 0, i32 8
  %20 = load ptr, ptr %19, align 8, !tbaa !20
  %21 = icmp ne ptr %20, null
  br i1 %21, label %22, label %26

22:                                               ; preds = %18
  %23 = getelementptr inbounds %class.FfmpegEncoder, ptr %3, i32 0, i32 8
  %24 = load ptr, ptr %23, align 8, !tbaa !20
  call void @av_free(ptr noundef %24)
  %25 = getelementptr inbounds %class.FfmpegEncoder, ptr %3, i32 0, i32 8
  store ptr null, ptr %25, align 8, !tbaa !20
  br label %26

26:                                               ; preds = %22, %18
  %27 = getelementptr inbounds %class.FfmpegEncoder, ptr %3, i32 0, i32 6
  %28 = load ptr, ptr %27, align 8, !tbaa !21
  %29 = icmp ne ptr %28, null
  br i1 %29, label %30, label %38

30:                                               ; preds = %26
  %31 = getelementptr inbounds %class.FfmpegEncoder, ptr %3, i32 0, i32 6
  %32 = load ptr, ptr %31, align 8, !tbaa !21
  call void @avcodec_flush_buffers(ptr noundef %32)
  %33 = getelementptr inbounds %class.FfmpegEncoder, ptr %3, i32 0, i32 6
  call void @avcodec_free_context(ptr noundef %33)
  %34 = getelementptr inbounds %class.FfmpegEncoder, ptr %3, i32 0, i32 6
  %35 = load ptr, ptr %34, align 8, !tbaa !21
  call void @av_free(ptr noundef %35)
  %36 = getelementptr inbounds %class.FfmpegEncoder, ptr %3, i32 0, i32 6
  store ptr null, ptr %36, align 8, !tbaa !21
  %37 = getelementptr inbounds %class.FfmpegEncoder, ptr %3, i32 0, i32 5
  store ptr null, ptr %37, align 8, !tbaa !22
  br label %38

38:                                               ; preds = %30, %26
  %39 = getelementptr inbounds %class.FfmpegEncoder, ptr %3, i32 0, i32 7
  %40 = load ptr, ptr %39, align 8, !tbaa !23
  %41 = icmp ne ptr %40, null
  br i1 %41, label %42, label %46

42:                                               ; preds = %38
  %43 = getelementptr inbounds %class.FfmpegEncoder, ptr %3, i32 0, i32 7
  %44 = load ptr, ptr %43, align 8, !tbaa !23
  call void @avformat_free_context(ptr noundef %44)
  %45 = getelementptr inbounds %class.FfmpegEncoder, ptr %3, i32 0, i32 7
  store ptr null, ptr %45, align 8, !tbaa !23
  br label %46

46:                                               ; preds = %42, %38
  %47 = getelementptr inbounds %class.FfmpegEncoder, ptr %3, i32 0, i32 9
  %48 = load ptr, ptr %47, align 8, !tbaa !24
  %49 = icmp ne ptr %48, null
  br i1 %49, label %50, label %54

50:                                               ; preds = %46
  %51 = getelementptr inbounds %class.FfmpegEncoder, ptr %3, i32 0, i32 9
  %52 = load ptr, ptr %51, align 8, !tbaa !24
  call void @av_free(ptr noundef %52)
  %53 = getelementptr inbounds %class.FfmpegEncoder, ptr %3, i32 0, i32 9
  store ptr null, ptr %53, align 8, !tbaa !24
  br label %54

54:                                               ; preds = %50, %46
  %55 = getelementptr inbounds %class.FfmpegEncoder, ptr %3, i32 0, i32 12
  %56 = load ptr, ptr %55, align 8, !tbaa !25
  %57 = icmp ne ptr %56, null
  br i1 %57, label %58, label %61

58:                                               ; preds = %54
  %59 = getelementptr inbounds %class.FfmpegEncoder, ptr %3, i32 0, i32 12
  call void @swr_free(ptr noundef %59)
  %60 = getelementptr inbounds %class.FfmpegEncoder, ptr %3, i32 0, i32 12
  store ptr null, ptr %60, align 8, !tbaa !25
  br label %61

61:                                               ; preds = %58, %54
  %62 = getelementptr inbounds %class.FfmpegEncoder, ptr %3, i32 0, i32 4
  %63 = load ptr, ptr %62, align 8, !tbaa !26
  %64 = icmp ne ptr %63, null
  br i1 %64, label %65, label %69

65:                                               ; preds = %61
  %66 = getelementptr inbounds %class.FfmpegEncoder, ptr %3, i32 0, i32 4
  %67 = load ptr, ptr %66, align 8, !tbaa !26
  call void @av_audio_fifo_free(ptr noundef %67)
  %68 = getelementptr inbounds %class.FfmpegEncoder, ptr %3, i32 0, i32 4
  store ptr null, ptr %68, align 8, !tbaa !26
  br label %69

69:                                               ; preds = %65, %61
  ret void
}

declare void @av_frame_free(ptr noundef) #1

declare void @av_free(ptr noundef) #1

declare void @avcodec_flush_buffers(ptr noundef) #1

declare void @avcodec_free_context(ptr noundef) #1

declare void @avformat_free_context(ptr noundef) #1

declare void @swr_free(ptr noundef) #1

declare void @av_audio_fifo_free(ptr noundef) #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, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !13, i64 8}
!10 = !{!"_ZTS13FfmpegEncoder", !11, i64 0, !13, i64 8, !6, i64 16, !14, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !6, i64 64, !6, i64 72, !6, i64 80, !6, i64 88, !6, i64 96, !15, i64 104, !16, i64 112, !14, i64 144, !14, i64 148}
!11 = !{!"_ZTSN5musik4core3sdk16IBlockingEncoderE", !12, i64 0}
!12 = !{!"_ZTSN5musik4core3sdk8IEncoderE"}
!13 = !{!"bool", !7, i64 0}
!14 = !{!"int", !7, i64 0}
!15 = !{!"long", !7, i64 0}
!16 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE", !17, i64 0, !15, i64 8, !7, i64 16}
!17 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_Alloc_hiderE", !6, i64 0}
!18 = !{!10, !6, i64 80}
!19 = !{!10, !6, i64 88}
!20 = !{!10, !6, i64 64}
!21 = !{!10, !6, i64 48}
!22 = !{!10, !6, i64 40}
!23 = !{!10, !6, i64 56}
!24 = !{!10, !6, i64 72}
!25 = !{!10, !6, i64 96}
!26 = !{!10, !6, i64 32}


; 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
define dso_local void @_ZN13FfmpegEncoder7CleanupEv(ptr noundef nonnull align 8 dereferenceable(152) %0) local_unnamed_addr #0 align 2 {
  %2 = getelementptr inbounds i8, ptr %0, i64 8
  store i8 0, ptr %2, align 8, !tbaa !5
  %3 = getelementptr inbounds i8, ptr %0, i64 80
  %4 = load ptr, ptr %3, align 8, !tbaa !17
  %.not = icmp eq ptr %4, null
  br i1 %.not, label %6, label %5

5:                                                ; preds = %1
  tail call void @av_frame_free(ptr noundef nonnull %3)
  store ptr null, ptr %3, align 8, !tbaa !17
  br label %6

6:                                                ; preds = %5, %1
  %7 = getelementptr inbounds i8, ptr %0, i64 88
  %8 = load ptr, ptr %7, align 8, !tbaa !18
  %.not5 = icmp eq ptr %8, null
  br i1 %.not5, label %10, label %9

9:                                                ; preds = %6
  tail call void @av_frame_free(ptr noundef nonnull %7)
  store ptr null, ptr %7, align 8, !tbaa !18
  br label %10

10:                                               ; preds = %9, %6
  %11 = getelementptr inbounds i8, ptr %0, i64 64
  %12 = load ptr, ptr %11, align 8, !tbaa !19
  %.not6 = icmp eq ptr %12, null
  br i1 %.not6, label %14, label %13

13:                                               ; preds = %10
  tail call void @av_free(ptr noundef nonnull %12)
  store ptr null, ptr %11, align 8, !tbaa !19
  br label %14

14:                                               ; preds = %13, %10
  %15 = getelementptr inbounds i8, ptr %0, i64 48
  %16 = load ptr, ptr %15, align 8, !tbaa !20
  %.not7 = icmp eq ptr %16, null
  br i1 %.not7, label %20, label %17

17:                                               ; preds = %14
  tail call void @avcodec_flush_buffers(ptr noundef nonnull %16)
  tail call void @avcodec_free_context(ptr noundef nonnull %15)
  %18 = load ptr, ptr %15, align 8, !tbaa !20
  tail call void @av_free(ptr noundef %18)
  %19 = getelementptr inbounds i8, ptr %0, i64 40
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %19, i8 0, i64 16, i1 false)
  br label %20

20:                                               ; preds = %17, %14
  %21 = getelementptr inbounds i8, ptr %0, i64 56
  %22 = load ptr, ptr %21, align 8, !tbaa !21
  %.not8 = icmp eq ptr %22, null
  br i1 %.not8, label %24, label %23

23:                                               ; preds = %20
  tail call void @avformat_free_context(ptr noundef nonnull %22)
  store ptr null, ptr %21, align 8, !tbaa !21
  br label %24

24:                                               ; preds = %23, %20
  %25 = getelementptr inbounds i8, ptr %0, i64 72
  %26 = load ptr, ptr %25, align 8, !tbaa !22
  %.not9 = icmp eq ptr %26, null
  br i1 %.not9, label %28, label %27

27:                                               ; preds = %24
  tail call void @av_free(ptr noundef nonnull %26)
  store ptr null, ptr %25, align 8, !tbaa !22
  br label %28

28:                                               ; preds = %27, %24
  %29 = getelementptr inbounds i8, ptr %0, i64 96
  %30 = load ptr, ptr %29, align 8, !tbaa !23
  %.not10 = icmp eq ptr %30, null
  br i1 %.not10, label %32, label %31

31:                                               ; preds = %28
  tail call void @swr_free(ptr noundef nonnull %29)
  store ptr null, ptr %29, align 8, !tbaa !23
  br label %32

32:                                               ; preds = %31, %28
  %33 = getelementptr inbounds i8, ptr %0, i64 32
  %34 = load ptr, ptr %33, align 8, !tbaa !24
  %.not11 = icmp eq ptr %34, null
  br i1 %.not11, label %36, label %35

35:                                               ; preds = %32
  tail call void @av_audio_fifo_free(ptr noundef nonnull %34)
  store ptr null, ptr %33, align 8, !tbaa !24
  br label %36

36:                                               ; preds = %35, %32
  ret void
}

declare void @av_frame_free(ptr noundef) local_unnamed_addr #1

declare void @av_free(ptr noundef) local_unnamed_addr #1

declare void @avcodec_flush_buffers(ptr noundef) local_unnamed_addr #1

declare void @avcodec_free_context(ptr noundef) local_unnamed_addr #1

declare void @avformat_free_context(ptr noundef) local_unnamed_addr #1

declare void @swr_free(ptr noundef) local_unnamed_addr #1

declare void @av_audio_fifo_free(ptr noundef) local_unnamed_addr #1

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

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" }
attributes #2 = { nocallback nofree nounwind willreturn memory(argmem: write) }

!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, !9, i64 8}
!6 = !{!"_ZTS13FfmpegEncoder", !7, i64 0, !9, i64 8, !12, i64 16, !13, i64 24, !12, i64 32, !12, i64 40, !12, i64 48, !12, i64 56, !12, i64 64, !12, i64 72, !12, i64 80, !12, i64 88, !12, i64 96, !14, i64 104, !15, i64 112, !13, i64 144, !13, i64 148}
!7 = !{!"_ZTSN5musik4core3sdk16IBlockingEncoderE", !8, i64 0}
!8 = !{!"_ZTSN5musik4core3sdk8IEncoderE"}
!9 = !{!"bool", !10, i64 0}
!10 = !{!"omnipotent char", !11, i64 0}
!11 = !{!"Simple C++ TBAA"}
!12 = !{!"any pointer", !10, i64 0}
!13 = !{!"int", !10, i64 0}
!14 = !{!"long", !10, i64 0}
!15 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE", !16, i64 0, !14, i64 8, !10, i64 16}
!16 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_Alloc_hiderE", !12, i64 0}
!17 = !{!6, !12, i64 80}
!18 = !{!6, !12, i64 88}
!19 = !{!6, !12, i64 64}
!20 = !{!6, !12, i64 48}
!21 = !{!6, !12, i64 56}
!22 = !{!6, !12, i64 72}
!23 = !{!6, !12, i64 96}
!24 = !{!6, !12, i64 32}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InstCombinePass,MemCpyOptPass,SROAPass,TailCallElimPass