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

; 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::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::LLLink" = type { ptr, ptr }
%"struct.rw::LinkList" = type { %"struct.rw::LLLink" }
%"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 }

; 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 noundef ptr @_ZN2rw5Frame14forAllChildrenEPFPS0_S1_PvES2_(ptr noundef nonnull align 8 dereferenceable(200) %0, ptr noundef %1, ptr noundef %2) #1 align 2 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store ptr %2, ptr %7, align 8, !tbaa !5
  %11 = load ptr, ptr %5, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #2
  %12 = getelementptr inbounds %"struct.rw::Frame", ptr %11, i32 0, i32 5
  %13 = load ptr, ptr %12, align 8, !tbaa !9
  store ptr %13, ptr %9, align 8, !tbaa !5
  br label %14

14:                                               ; preds = %29, %3
  %15 = load ptr, ptr %9, align 8, !tbaa !5
  %16 = icmp ne ptr %15, null
  br i1 %16, label %18, label %17

17:                                               ; preds = %14
  store i32 2, ptr %10, align 4
  br label %31

18:                                               ; preds = %14
  %19 = load ptr, ptr %9, align 8, !tbaa !5
  %20 = getelementptr inbounds %"struct.rw::Frame", ptr %19, i32 0, i32 6
  %21 = load ptr, ptr %20, align 8, !tbaa !18
  store ptr %21, ptr %8, align 8, !tbaa !5
  %22 = load ptr, ptr %6, align 8, !tbaa !5
  %23 = load ptr, ptr %9, align 8, !tbaa !5
  %24 = load ptr, ptr %7, align 8, !tbaa !5
  %25 = call noundef ptr %22(ptr noundef %23, ptr noundef %24)
  %26 = icmp eq ptr %25, null
  br i1 %26, label %27, label %28

27:                                               ; preds = %18
  store ptr %11, ptr %4, align 8
  store i32 1, ptr %10, align 4
  br label %31

28:                                               ; preds = %18
  br label %29

29:                                               ; preds = %28
  %30 = load ptr, ptr %8, align 8, !tbaa !5
  store ptr %30, ptr %9, align 8, !tbaa !5
  br label %14, !llvm.loop !19

31:                                               ; preds = %27, %17
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #2
  %32 = load i32, ptr %10, align 4
  switch i32 %32, label %34 [
    i32 2, label %33
  ]

33:                                               ; preds = %31
  store ptr %11, ptr %4, align 8
  store i32 1, ptr %10, align 4
  br label %34

34:                                               ; preds = %33, %31
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #2
  %35 = load ptr, ptr %4, align 8
  ret ptr %35
}

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 = { 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"}


; 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 ptr @_ZN2rw5Frame14forAllChildrenEPFPS0_S1_PvES2_(ptr noundef nonnull readonly returned align 8 dereferenceable(200) %0, ptr nocapture noundef readonly %1, ptr noundef %2) local_unnamed_addr #0 align 2 {
  %4 = getelementptr inbounds i8, ptr %0, i64 176
  %5 = load ptr, ptr %4, align 8, !tbaa !5
  br label %6

6:                                                ; preds = %7, %3
  %.08 = phi ptr [ %5, %3 ], [ %9, %7 ]
  %.not = icmp eq ptr %.08, null
  br i1 %.not, label %.critedge, label %7

7:                                                ; preds = %6
  %8 = getelementptr inbounds i8, ptr %.08, i64 184
  %9 = load ptr, ptr %8, align 8, !tbaa !17
  %10 = tail call noundef ptr %1(ptr noundef nonnull %.08, ptr noundef %2)
  %11 = icmp eq ptr %10, null
  br i1 %11, label %.critedge, label %6, !llvm.loop !18

.critedge:                                        ; preds = %6, %7
  ret ptr %0
}

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

!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"}


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