; LLVM IR from aap/librw :: src/texture.ll (ZN2rw13TexDictionary7destroyEv)

; 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.rw::PluginList" = type { i32, i32, %"struct.rw::LinkList" }
%"struct.rw::LinkList" = type { %"struct.rw::LLLink" }
%"struct.rw::LLLink" = type { ptr, ptr }
%"struct.rw::MemoryFunctions" = type { ptr, ptr, ptr, ptr, ptr }
%"struct.rw::TextureGlobals" = type { ptr, ptr, i32, i32, i32, i32, %"struct.rw::LinkList", %"struct.rw::LinkList" }
%"struct.rw::TexDictionary" = type { %"struct.rw::Object", %"struct.rw::LinkList", %"struct.rw::LLLink" }
%"struct.rw::Object" = type { i8, i8, i8, i8, ptr }

@_ZN2rw13TexDictionary12numAllocatedE = external dso_local global i32, align 4
@_ZN2rw13TexDictionary9s_plglistE = external dso_local global %"struct.rw::PluginList", align 8
@_ZN2rw19textureModuleOffsetE = external dso_local global i32, align 4
@_ZN2rw6engineE = external global ptr, align 8
@_ZN2rw6Engine8memfuncsE = external global %"struct.rw::MemoryFunctions", align 8

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

; 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 void @_ZN2rw13TexDictionary7destroyEv(ptr noundef nonnull align 8 dereferenceable(48) %0) #1 align 2 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  %6 = load ptr, ptr %2, align 8
  %7 = load ptr, ptr @_ZN2rw6engineE, align 8, !tbaa !5
  %8 = load i32, ptr @_ZN2rw19textureModuleOffsetE, align 4, !tbaa !9
  %9 = sext i32 %8 to i64
  %10 = getelementptr inbounds i8, ptr %7, i64 %9
  %11 = getelementptr inbounds %"struct.rw::TextureGlobals", ptr %10, i32 0, i32 1
  %12 = load ptr, ptr %11, align 8, !tbaa !11
  %13 = icmp eq ptr %12, %6
  br i1 %13, label %14, label %20

14:                                               ; preds = %1
  %15 = load ptr, ptr @_ZN2rw6engineE, align 8, !tbaa !5
  %16 = load i32, ptr @_ZN2rw19textureModuleOffsetE, align 4, !tbaa !9
  %17 = sext i32 %16 to i64
  %18 = getelementptr inbounds i8, ptr %15, i64 %17
  %19 = getelementptr inbounds %"struct.rw::TextureGlobals", ptr %18, i32 0, i32 1
  store ptr null, ptr %19, align 8, !tbaa !11
  br label %20

20:                                               ; preds = %14, %1
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #4
  store ptr null, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #4
  %21 = getelementptr inbounds %"struct.rw::TexDictionary", ptr %6, i32 0, i32 1
  %22 = getelementptr inbounds %"struct.rw::LinkList", ptr %21, i32 0, i32 0
  %23 = getelementptr inbounds %"struct.rw::LLLink", ptr %22, i32 0, i32 0
  %24 = load ptr, ptr %23, align 8, !tbaa !15
  store ptr %24, ptr %4, align 8, !tbaa !5
  br label %25

25:                                               ; preds = %39, %20
  %26 = load ptr, ptr %4, align 8, !tbaa !5
  %27 = getelementptr inbounds %"struct.rw::LLLink", ptr %26, i32 0, i32 0
  %28 = load ptr, ptr %27, align 8, !tbaa !18
  store ptr %28, ptr %3, align 8, !tbaa !5
  %29 = load ptr, ptr %4, align 8, !tbaa !5
  %30 = getelementptr inbounds %"struct.rw::TexDictionary", ptr %6, i32 0, i32 1
  %31 = call noundef ptr @_ZN2rw8LinkList3endEv(ptr noundef nonnull align 8 dereferenceable(16) %30)
  %32 = icmp ne ptr %29, %31
  br i1 %32, label %34, label %33

33:                                               ; preds = %25
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #4
  br label %41

34:                                               ; preds = %25
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  %35 = load ptr, ptr %4, align 8, !tbaa !5
  %36 = call noundef ptr @_ZN2rw7Texture8fromDictEPNS_6LLLinkE(ptr noundef %35)
  store ptr %36, ptr %5, align 8, !tbaa !5
  %37 = load ptr, ptr %5, align 8, !tbaa !5
  call void @_ZN2rw13TexDictionary6removeEPNS_7TextureE(ptr noundef nonnull align 8 dereferenceable(48) %6, ptr noundef %37)
  %38 = load ptr, ptr %5, align 8, !tbaa !5
  call void @_ZN2rw7Texture7destroyEv(ptr noundef nonnull align 8 dereferenceable(120) %38)
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  br label %39

39:                                               ; preds = %34
  %40 = load ptr, ptr %3, align 8, !tbaa !5
  store ptr %40, ptr %4, align 8, !tbaa !5
  br label %25, !llvm.loop !19

41:                                               ; preds = %33
  call void @_ZN2rw10PluginList8destructEPv(ptr noundef nonnull align 8 dereferenceable(24) @_ZN2rw13TexDictionary9s_plglistE, ptr noundef %6)
  %42 = getelementptr inbounds %"struct.rw::TexDictionary", ptr %6, i32 0, i32 2
  call void @_ZN2rw6LLLink6removeEv(ptr noundef nonnull align 8 dereferenceable(16) %42)
  %43 = load ptr, ptr getelementptr inbounds (%"struct.rw::MemoryFunctions", ptr @_ZN2rw6Engine8memfuncsE, i32 0, i32 2), align 8, !tbaa !21
  call void %43(ptr noundef %6)
  %44 = load i32, ptr @_ZN2rw13TexDictionary12numAllocatedE, align 4, !tbaa !9
  %45 = add nsw i32 %44, -1
  store i32 %45, ptr @_ZN2rw13TexDictionary12numAllocatedE, align 4, !tbaa !9
  ret void
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZN2rw8LinkList3endEv(ptr noundef nonnull align 8 dereferenceable(16)) #2 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZN2rw7Texture8fromDictEPNS_6LLLinkE(ptr noundef) #2 align 2

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN2rw7Texture7destroyEv(ptr noundef nonnull align 8 dereferenceable(120)) #1 align 2

declare void @_ZN2rw10PluginList8destructEPv(ptr noundef nonnull align 8 dereferenceable(24), ptr noundef) #3

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN2rw6LLLink6removeEv(ptr noundef nonnull align 8 dereferenceable(16)) #2 align 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 = { mustprogress 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 = { "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 }

!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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !6, i64 8}
!12 = !{!"_ZTSN2rw14TextureGlobalsE", !6, i64 0, !6, i64 8, !10, i64 16, !10, i64 20, !10, i64 24, !10, i64 28, !13, i64 32, !13, i64 48}
!13 = !{!"_ZTSN2rw8LinkListE", !14, i64 0}
!14 = !{!"_ZTSN2rw6LLLinkE", !6, i64 0, !6, i64 8}
!15 = !{!16, !6, i64 16}
!16 = !{!"_ZTSN2rw13TexDictionaryE", !17, i64 0, !13, i64 16, !14, i64 32}
!17 = !{!"_ZTSN2rw6ObjectE", !7, i64 0, !7, i64 1, !7, i64 2, !7, i64 3, !6, i64 8}
!18 = !{!14, !6, i64 0}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}
!21 = !{!22, !6, i64 16}
!22 = !{!"_ZTSN2rw15MemoryFunctionsE", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !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"

%"struct.rw::PluginList" = type { i32, i32, %"struct.rw::LinkList" }
%"struct.rw::LinkList" = type { %"struct.rw::LLLink" }
%"struct.rw::LLLink" = type { ptr, ptr }
%"struct.rw::MemoryFunctions" = type { ptr, ptr, ptr, ptr, ptr }

@_ZN2rw13TexDictionary12numAllocatedE = external dso_local local_unnamed_addr global i32, align 4
@_ZN2rw13TexDictionary9s_plglistE = external dso_local global %"struct.rw::PluginList", align 8
@_ZN2rw19textureModuleOffsetE = external dso_local local_unnamed_addr global i32, align 4
@_ZN2rw6engineE = external local_unnamed_addr global ptr, align 8
@_ZN2rw6Engine8memfuncsE = external local_unnamed_addr global %"struct.rw::MemoryFunctions", align 8

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN2rw13TexDictionary7destroyEv(ptr noundef nonnull align 8 dereferenceable(48) %0) local_unnamed_addr #0 align 2 {
  %2 = load ptr, ptr @_ZN2rw6engineE, align 8, !tbaa !5
  %3 = load i32, ptr @_ZN2rw19textureModuleOffsetE, align 4, !tbaa !9
  %4 = sext i32 %3 to i64
  %5 = getelementptr inbounds i8, ptr %2, i64 %4
  %6 = getelementptr inbounds i8, ptr %5, i64 8
  %7 = load ptr, ptr %6, align 8, !tbaa !11
  %8 = icmp eq ptr %7, %0
  br i1 %8, label %9, label %10

9:                                                ; preds = %1
  store ptr null, ptr %6, align 8, !tbaa !11
  br label %10

10:                                               ; preds = %9, %1
  %11 = getelementptr inbounds i8, ptr %0, i64 16
  %12 = load ptr, ptr %11, align 8, !tbaa !15
  %13 = load ptr, ptr %12, align 8, !tbaa !18
  %14 = tail call noundef ptr @_ZN2rw8LinkList3endEv(ptr noundef nonnull align 8 dereferenceable(16) %11)
  %.not7 = icmp eq ptr %12, %14
  br i1 %.not7, label %._crit_edge, label %.lr.ph

._crit_edge:                                      ; preds = %.lr.ph, %10
  tail call void @_ZN2rw10PluginList8destructEPv(ptr noundef nonnull align 8 dereferenceable(24) @_ZN2rw13TexDictionary9s_plglistE, ptr noundef nonnull %0)
  %15 = getelementptr inbounds i8, ptr %0, i64 32
  tail call void @_ZN2rw6LLLink6removeEv(ptr noundef nonnull align 8 dereferenceable(16) %15)
  %16 = load ptr, ptr getelementptr inbounds (i8, ptr @_ZN2rw6Engine8memfuncsE, i64 16), align 8, !tbaa !19
  tail call void %16(ptr noundef nonnull %0)
  %17 = load i32, ptr @_ZN2rw13TexDictionary12numAllocatedE, align 4, !tbaa !9
  %18 = add nsw i32 %17, -1
  store i32 %18, ptr @_ZN2rw13TexDictionary12numAllocatedE, align 4, !tbaa !9
  ret void

.lr.ph:                                           ; preds = %10, %.lr.ph
  %19 = phi ptr [ %21, %.lr.ph ], [ %13, %10 ]
  %.08 = phi ptr [ %19, %.lr.ph ], [ %12, %10 ]
  %20 = tail call noundef ptr @_ZN2rw7Texture8fromDictEPNS_6LLLinkE(ptr noundef nonnull %.08)
  tail call void @_ZN2rw13TexDictionary6removeEPNS_7TextureE(ptr noundef nonnull align 8 dereferenceable(48) %0, ptr noundef %20)
  tail call void @_ZN2rw7Texture7destroyEv(ptr noundef nonnull align 8 dereferenceable(120) %20)
  %21 = load ptr, ptr %19, align 8, !tbaa !18
  %22 = tail call noundef ptr @_ZN2rw8LinkList3endEv(ptr noundef nonnull align 8 dereferenceable(16) %11)
  %.not = icmp eq ptr %19, %22
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !21
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZN2rw8LinkList3endEv(ptr noundef nonnull align 8 dereferenceable(16)) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZN2rw7Texture8fromDictEPNS_6LLLinkE(ptr noundef) local_unnamed_addr #1 align 2

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN2rw7Texture7destroyEv(ptr noundef nonnull align 8 dereferenceable(120)) local_unnamed_addr #0 align 2

declare void @_ZN2rw10PluginList8destructEPv(ptr noundef nonnull align 8 dereferenceable(24), ptr noundef) local_unnamed_addr #2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN2rw6LLLink6removeEv(ptr noundef nonnull align 8 dereferenceable(16)) local_unnamed_addr #1 align 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 = { mustprogress 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 #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" }

!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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !6, i64 8}
!12 = !{!"_ZTSN2rw14TextureGlobalsE", !6, i64 0, !6, i64 8, !10, i64 16, !10, i64 20, !10, i64 24, !10, i64 28, !13, i64 32, !13, i64 48}
!13 = !{!"_ZTSN2rw8LinkListE", !14, i64 0}
!14 = !{!"_ZTSN2rw6LLLinkE", !6, i64 0, !6, i64 8}
!15 = !{!16, !6, i64 16}
!16 = !{!"_ZTSN2rw13TexDictionaryE", !17, i64 0, !13, i64 16, !14, i64 32}
!17 = !{!"_ZTSN2rw6ObjectE", !7, i64 0, !7, i64 1, !7, i64 2, !7, i64 3, !6, i64 8}
!18 = !{!14, !6, i64 0}
!19 = !{!20, !6, i64 16}
!20 = !{!"_ZTSN2rw15MemoryFunctionsE", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32}
!21 = distinct !{!21, !22}
!22 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass