; LLVM IR from GPUOpen-LibrariesAndSDKs/TAN :: amf/public/common/AMFFactory.ll (ZN16AMFFactoryHelper9TerminateEv)

; 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.AMFFactoryHelper = type { ptr, ptr, ptr, ptr, ptr, i64, i64, %"class.std::vector" }
%"class.std::vector" = type { %"struct.std::_Vector_base" }
%"struct.std::_Vector_base" = type { %"struct.std::_Vector_base<AMFFactoryHelper::ComponentHolder, std::allocator<AMFFactoryHelper::ComponentHolder>>::_Vector_impl" }
%"struct.std::_Vector_base<AMFFactoryHelper::ComponentHolder, std::allocator<AMFFactoryHelper::ComponentHolder>>::_Vector_impl" = type { %"struct.std::_Vector_base<AMFFactoryHelper::ComponentHolder, std::allocator<AMFFactoryHelper::ComponentHolder>>::_Vector_impl_data" }
%"struct.std::_Vector_base<AMFFactoryHelper::ComponentHolder, std::allocator<AMFFactoryHelper::ComponentHolder>>::_Vector_impl_data" = type { ptr, ptr, ptr }

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN16AMFFactoryHelper9TerminateEv(ptr noundef nonnull align 8 dereferenceable(80) %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.AMFFactoryHelper, ptr %3, i32 0, i32 1
  %5 = load ptr, ptr %4, align 8, !tbaa !9
  %6 = icmp ne ptr %5, null
  br i1 %6, label %7, label %22

7:                                                ; preds = %1
  %8 = getelementptr inbounds %class.AMFFactoryHelper, ptr %3, i32 0, i32 6
  %9 = call i64 @amf_atomic_dec(ptr noundef %8)
  %10 = getelementptr inbounds %class.AMFFactoryHelper, ptr %3, i32 0, i32 6
  %11 = load i64, ptr %10, align 8, !tbaa !16
  %12 = icmp eq i64 %11, 0
  br i1 %12, label %13, label %21

13:                                               ; preds = %7
  %14 = getelementptr inbounds %class.AMFFactoryHelper, ptr %3, i32 0, i32 1
  %15 = load ptr, ptr %14, align 8, !tbaa !9
  %16 = call i32 @amf_free_library(ptr noundef %15)
  %17 = getelementptr inbounds %class.AMFFactoryHelper, ptr %3, i32 0, i32 1
  store ptr null, ptr %17, align 8, !tbaa !9
  %18 = getelementptr inbounds %class.AMFFactoryHelper, ptr %3, i32 0, i32 2
  store ptr null, ptr %18, align 8, !tbaa !17
  %19 = getelementptr inbounds %class.AMFFactoryHelper, ptr %3, i32 0, i32 3
  store ptr null, ptr %19, align 8, !tbaa !18
  %20 = getelementptr inbounds %class.AMFFactoryHelper, ptr %3, i32 0, i32 4
  store ptr null, ptr %20, align 8, !tbaa !19
  br label %21

21:                                               ; preds = %13, %7
  br label %22

22:                                               ; preds = %21, %1
  ret i32 0
}

declare i64 @amf_atomic_dec(ptr noundef) #1

declare i32 @amf_free_library(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, !6, i64 8}
!10 = !{!"_ZTS16AMFFactoryHelper", !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !11, i64 40, !11, i64 48, !12, i64 56}
!11 = !{!"long", !7, i64 0}
!12 = !{!"_ZTSSt6vectorIN16AMFFactoryHelper15ComponentHolderESaIS1_EE", !13, i64 0}
!13 = !{!"_ZTSSt12_Vector_baseIN16AMFFactoryHelper15ComponentHolderESaIS1_EE", !14, i64 0}
!14 = !{!"_ZTSNSt12_Vector_baseIN16AMFFactoryHelper15ComponentHolderESaIS1_EE12_Vector_implE", !15, i64 0}
!15 = !{!"_ZTSNSt12_Vector_baseIN16AMFFactoryHelper15ComponentHolderESaIS1_EE17_Vector_impl_dataE", !6, i64 0, !6, i64 8, !6, i64 16}
!16 = !{!10, !11, i64 48}
!17 = !{!10, !6, i64 16}
!18 = !{!10, !6, i64 24}
!19 = !{!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 noundef i32 @_ZN16AMFFactoryHelper9TerminateEv(ptr noundef nonnull align 8 dereferenceable(80) %0) local_unnamed_addr #0 align 2 {
  %2 = getelementptr inbounds i8, ptr %0, i64 8
  %3 = load ptr, ptr %2, align 8, !tbaa !5
  %.not = icmp eq ptr %3, null
  br i1 %.not, label %12, label %4

4:                                                ; preds = %1
  %5 = getelementptr inbounds i8, ptr %0, i64 48
  %6 = tail call i64 @amf_atomic_dec(ptr noundef nonnull %5)
  %7 = load i64, ptr %5, align 8, !tbaa !15
  %8 = icmp eq i64 %7, 0
  br i1 %8, label %9, label %12

9:                                                ; preds = %4
  %10 = load ptr, ptr %2, align 8, !tbaa !5
  %11 = tail call i32 @amf_free_library(ptr noundef %10)
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(32) %2, i8 0, i64 32, i1 false)
  br label %12

12:                                               ; preds = %4, %9, %1
  ret i32 0
}

declare i64 @amf_atomic_dec(ptr noundef) local_unnamed_addr #1

declare i32 @amf_free_library(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, !7, i64 8}
!6 = !{!"_ZTS16AMFFactoryHelper", !7, i64 8, !7, i64 16, !7, i64 24, !7, i64 32, !10, i64 40, !10, i64 48, !11, i64 56}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"long", !8, i64 0}
!11 = !{!"_ZTSSt6vectorIN16AMFFactoryHelper15ComponentHolderESaIS1_EE", !12, i64 0}
!12 = !{!"_ZTSSt12_Vector_baseIN16AMFFactoryHelper15ComponentHolderESaIS1_EE", !13, i64 0}
!13 = !{!"_ZTSNSt12_Vector_baseIN16AMFFactoryHelper15ComponentHolderESaIS1_EE12_Vector_implE", !14, i64 0}
!14 = !{!"_ZTSNSt12_Vector_baseIN16AMFFactoryHelper15ComponentHolderESaIS1_EE17_Vector_impl_dataE", !7, i64 0, !7, i64 8, !7, i64 16}
!15 = !{!6, !10, i64 48}


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