; LLVM IR from aap/librw :: src/frame.ll (ZN2rw5Frame16destroyHierarchyEv)

; 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::Frame" = type { %"struct.rw::Object", %"struct.rw::LLLink", %"struct.rw::LinkList", %"struct.rw::Matrix", %"struct.rw::Matrix", ptr, ptr, ptr }
%"struct.rw::Object" = type { i8, i8, i8, i8, ptr }
%"struct.rw::Matrix" = type { %"struct.rw::V3d", i32, %"struct.rw::V3d", i32, %"struct.rw::V3d", i32, %"struct.rw::V3d", i32 }
%"struct.rw::V3d" = type { float, float, float }

@_ZN2rw5Frame9s_plglistE = external dso_local global %"struct.rw::PluginList", align 8
@.str.2 = external hidden unnamed_addr constant [57 x i8], align 1
@_ZN2rw6Engine8memfuncsE = external global %"struct.rw::MemoryFunctions", align 8
@.str.4 = external hidden unnamed_addr constant [27 x i8], align 1
@__PRETTY_FUNCTION__._ZN2rw5Frame16destroyHierarchyEv = external hidden unnamed_addr constant [35 x i8], align 1

; 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

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

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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN2rw5Frame16destroyHierarchyEv(ptr noundef nonnull align 8 dereferenceable(200) %0) #3 align 2 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  %5 = load ptr, ptr %2, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #5
  %6 = getelementptr inbounds %"struct.rw::Frame", ptr %5, i32 0, i32 5
  %7 = load ptr, ptr %6, align 8, !tbaa !9
  store ptr %7, ptr %4, align 8, !tbaa !5
  br label %8

8:                                                ; preds = %17, %1
  %9 = load ptr, ptr %4, align 8, !tbaa !5
  %10 = icmp ne ptr %9, null
  br i1 %10, label %12, label %11

11:                                               ; preds = %8
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #5
  br label %19

12:                                               ; preds = %8
  %13 = load ptr, ptr %4, align 8, !tbaa !5
  %14 = getelementptr inbounds %"struct.rw::Frame", ptr %13, i32 0, i32 6
  %15 = load ptr, ptr %14, align 8, !tbaa !18
  store ptr %15, ptr %3, align 8, !tbaa !5
  %16 = load ptr, ptr %4, align 8, !tbaa !5
  call void @_ZN2rw5Frame16destroyHierarchyEv(ptr noundef nonnull align 8 dereferenceable(200) %16)
  br label %17

17:                                               ; preds = %12
  %18 = load ptr, ptr %3, align 8, !tbaa !5
  store ptr %18, ptr %4, align 8, !tbaa !5
  br label %8, !llvm.loop !19

19:                                               ; preds = %11
  %20 = getelementptr inbounds %"struct.rw::Frame", ptr %5, i32 0, i32 2
  %21 = call noundef i32 @_ZN2rw8LinkList7isEmptyEv(ptr noundef nonnull align 8 dereferenceable(16) %20)
  %22 = icmp ne i32 %21, 0
  br i1 %22, label %23, label %24

23:                                               ; preds = %19
  br label %26

24:                                               ; preds = %19
  call void @__assert_fail(ptr noundef @.str.4, ptr noundef @.str.2, i32 noundef 79, ptr noundef @__PRETTY_FUNCTION__._ZN2rw5Frame16destroyHierarchyEv) #6
  unreachable

25:                                               ; No predecessors!
  br label %26

26:                                               ; preds = %25, %23
  call void @_ZN2rw10PluginList8destructEPv(ptr noundef nonnull align 8 dereferenceable(24) @_ZN2rw5Frame9s_plglistE, ptr noundef %5)
  %27 = getelementptr inbounds %"struct.rw::Frame", ptr %5, i32 0, i32 0
  %28 = getelementptr inbounds %"struct.rw::Object", ptr %27, i32 0, i32 3
  %29 = load i8, ptr %28, align 1, !tbaa !21
  %30 = zext i8 %29 to i32
  %31 = and i32 %30, 3
  %32 = icmp ne i32 %31, 0
  br i1 %32, label %33, label %35

33:                                               ; preds = %26
  %34 = getelementptr inbounds %"struct.rw::Frame", ptr %5, i32 0, i32 1
  call void @_ZN2rw6LLLink6removeEv(ptr noundef nonnull align 8 dereferenceable(16) %34)
  br label %35

35:                                               ; preds = %33, %26
  %36 = load ptr, ptr getelementptr inbounds (%"struct.rw::MemoryFunctions", ptr @_ZN2rw6Engine8memfuncsE, i32 0, i32 2), align 8, !tbaa !22
  call void %36(ptr noundef %5)
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #5
  ret void
}

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

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #4

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 = { 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 #4 = { noreturn nounwind "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 #5 = { nounwind }
attributes #6 = { noreturn 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, !6, i64 176}
!10 = !{!"_ZTSN2rw5FrameE", !11, i64 0, !12, i64 16, !13, i64 32, !14, i64 48, !14, i64 112, !6, i64 176, !6, i64 184, !6, i64 192}
!11 = !{!"_ZTSN2rw6ObjectE", !7, i64 0, !7, i64 1, !7, i64 2, !7, i64 3, !6, i64 8}
!12 = !{!"_ZTSN2rw6LLLinkE", !6, i64 0, !6, i64 8}
!13 = !{!"_ZTSN2rw8LinkListE", !12, i64 0}
!14 = !{!"_ZTSN2rw6MatrixE", !15, i64 0, !17, i64 12, !15, i64 16, !17, i64 28, !15, i64 32, !17, i64 44, !15, i64 48, !17, i64 60}
!15 = !{!"_ZTSN2rw3V3dE", !16, i64 0, !16, i64 4, !16, i64 8}
!16 = !{!"float", !7, i64 0}
!17 = !{!"int", !7, i64 0}
!18 = !{!10, !6, i64 184}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}
!21 = !{!10, !7, i64 3}
!22 = !{!23, !6, i64 16}
!23 = !{!"_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 }

@_ZN2rw5Frame9s_plglistE = external dso_local global %"struct.rw::PluginList", align 8
@.str.2 = external hidden unnamed_addr constant [57 x i8], align 1
@_ZN2rw6Engine8memfuncsE = external local_unnamed_addr global %"struct.rw::MemoryFunctions", align 8
@.str.4 = external hidden unnamed_addr constant [27 x i8], align 1
@__PRETTY_FUNCTION__._ZN2rw5Frame16destroyHierarchyEv = external hidden unnamed_addr constant [35 x i8], align 1

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

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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN2rw5Frame16destroyHierarchyEv(ptr noundef nonnull align 8 dereferenceable(200) %0) local_unnamed_addr #2 align 2 {
  %2 = getelementptr inbounds i8, ptr %0, i64 176
  %3 = load ptr, ptr %2, align 8, !tbaa !5
  %.not7 = icmp eq ptr %3, null
  br i1 %.not7, label %._crit_edge, label %.lr.ph

._crit_edge:                                      ; preds = %.lr.ph, %1
  %4 = getelementptr inbounds i8, ptr %0, i64 32
  %5 = tail call noundef i32 @_ZN2rw8LinkList7isEmptyEv(ptr noundef nonnull align 8 dereferenceable(16) %4)
  %.not5 = icmp eq i32 %5, 0
  br i1 %.not5, label %8, label %9

.lr.ph:                                           ; preds = %1, %.lr.ph
  %.08 = phi ptr [ %7, %.lr.ph ], [ %3, %1 ]
  %6 = getelementptr inbounds i8, ptr %.08, i64 184
  %7 = load ptr, ptr %6, align 8, !tbaa !17
  tail call void @_ZN2rw5Frame16destroyHierarchyEv(ptr noundef nonnull align 8 dereferenceable(200) %.08)
  %.not = icmp eq ptr %7, null
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !18

8:                                                ; preds = %._crit_edge
  tail call void @__assert_fail(ptr noundef nonnull @.str.4, ptr noundef nonnull @.str.2, i32 noundef 79, ptr noundef nonnull @__PRETTY_FUNCTION__._ZN2rw5Frame16destroyHierarchyEv) #4
  unreachable

9:                                                ; preds = %._crit_edge
  tail call void @_ZN2rw10PluginList8destructEPv(ptr noundef nonnull align 8 dereferenceable(24) @_ZN2rw5Frame9s_plglistE, ptr noundef nonnull %0)
  %10 = getelementptr inbounds i8, ptr %0, i64 3
  %11 = load i8, ptr %10, align 1, !tbaa !20
  %12 = and i8 %11, 3
  %.not6 = icmp eq i8 %12, 0
  br i1 %.not6, label %15, label %13

13:                                               ; preds = %9
  %14 = getelementptr inbounds i8, ptr %0, i64 16
  tail call void @_ZN2rw6LLLink6removeEv(ptr noundef nonnull align 8 dereferenceable(16) %14)
  br label %15

15:                                               ; preds = %13, %9
  %16 = load ptr, ptr getelementptr inbounds (i8, ptr @_ZN2rw6Engine8memfuncsE, i64 16), align 8, !tbaa !21
  tail call void %16(ptr noundef nonnull %0)
  ret void
}

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

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #3

attributes #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 = { 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 #3 = { noreturn nounwind "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 = { noreturn 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, !10, i64 176}
!6 = !{!"_ZTSN2rw5FrameE", !7, i64 0, !11, i64 16, !12, i64 32, !13, i64 48, !13, i64 112, !10, i64 176, !10, i64 184, !10, i64 192}
!7 = !{!"_ZTSN2rw6ObjectE", !8, i64 0, !8, i64 1, !8, i64 2, !8, i64 3, !10, i64 8}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!"_ZTSN2rw6LLLinkE", !10, i64 0, !10, i64 8}
!12 = !{!"_ZTSN2rw8LinkListE", !11, i64 0}
!13 = !{!"_ZTSN2rw6MatrixE", !14, i64 0, !16, i64 12, !14, i64 16, !16, i64 28, !14, i64 32, !16, i64 44, !14, i64 48, !16, i64 60}
!14 = !{!"_ZTSN2rw3V3dE", !15, i64 0, !15, i64 4, !15, i64 8}
!15 = !{!"float", !8, i64 0}
!16 = !{!"int", !8, i64 0}
!17 = !{!6, !10, i64 184}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}
!20 = !{!6, !8, i64 3}
!21 = !{!22, !10, i64 16}
!22 = !{!"_ZTSN2rw15MemoryFunctionsE", !10, i64 0, !10, i64 8, !10, i64 16, !10, i64 24, !10, i64 32}


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