; LLVM IR from aap/librw :: src/d3d/d3d9.ll (ZN2rw4d3d917getSizeNativeDataEPvii)

; 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::Geometry" = type { %"struct.rw::Object", i32, i16, i32, i32, i32, i32, ptr, ptr, [8 x ptr], ptr, %"struct.rw::MaterialList", ptr, ptr, i32 }
%"struct.rw::Object" = type { i8, i8, i8, i8, ptr }
%"struct.rw::MaterialList" = type { ptr, i32, i32 }
%"struct.rw::InstanceDataHeader" = type { i32 }
%"struct.rw::d3d9::InstanceDataHeader" = type { %"struct.rw::InstanceDataHeader", i32, i32, ptr, i32, [2 x %"struct.rw::d3d9::VertexStream"], i32, ptr, i32, i32, ptr }
%"struct.rw::d3d9::VertexStream" = type { ptr, i32, i32, i16, i8, i8 }

; 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 nounwind uwtable
declare dso_local noundef i32 @_ZN2rw4d3d914getDeclarationEPvPNS0_13VertexElementE(ptr noundef, ptr noundef) #1

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i32 @_ZN2rw4d3d917getSizeNativeDataEPvii(ptr noundef %0, i32 noundef %1, i32 noundef %2) #1 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !9
  store i32 %2, ptr %7, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #2
  %13 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %13, ptr %8, align 8, !tbaa !5
  %14 = load ptr, ptr %8, align 8, !tbaa !5
  %15 = getelementptr inbounds %"struct.rw::Geometry", ptr %14, i32 0, i32 13
  %16 = load ptr, ptr %15, align 8, !tbaa !11
  %17 = icmp eq ptr %16, null
  br i1 %17, label %25, label %18

18:                                               ; preds = %3
  %19 = load ptr, ptr %8, align 8, !tbaa !5
  %20 = getelementptr inbounds %"struct.rw::Geometry", ptr %19, i32 0, i32 13
  %21 = load ptr, ptr %20, align 8, !tbaa !11
  %22 = getelementptr inbounds %"struct.rw::InstanceDataHeader", ptr %21, i32 0, i32 0
  %23 = load i32, ptr %22, align 4, !tbaa !16
  %24 = icmp ne i32 %23, 9
  br i1 %24, label %25, label %26

25:                                               ; preds = %18, %3
  store i32 0, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %75

26:                                               ; preds = %18
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #2
  %27 = load ptr, ptr %8, align 8, !tbaa !5
  %28 = getelementptr inbounds %"struct.rw::Geometry", ptr %27, i32 0, i32 13
  %29 = load ptr, ptr %28, align 8, !tbaa !11
  store ptr %29, ptr %10, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #2
  %30 = load ptr, ptr %10, align 8, !tbaa !5
  %31 = getelementptr inbounds %"struct.rw::d3d9::InstanceDataHeader", ptr %30, i32 0, i32 2
  %32 = load i32, ptr %31, align 8, !tbaa !18
  %33 = mul i32 %32, 36
  %34 = add i32 84, %33
  store i32 %34, ptr %11, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #2
  %35 = load ptr, ptr %10, align 8, !tbaa !5
  %36 = getelementptr inbounds %"struct.rw::d3d9::InstanceDataHeader", ptr %35, i32 0, i32 7
  %37 = load ptr, ptr %36, align 8, !tbaa !20
  %38 = call noundef i32 @_ZN2rw4d3d914getDeclarationEPvPNS0_13VertexElementE(ptr noundef %37, ptr noundef null)
  store i32 %38, ptr %12, align 4, !tbaa !9
  %39 = load i32, ptr %12, align 4, !tbaa !9
  %40 = mul i32 %39, 8
  %41 = add i32 4, %40
  %42 = load i32, ptr %11, align 4, !tbaa !9
  %43 = add i32 %42, %41
  store i32 %43, ptr %11, align 4, !tbaa !9
  %44 = load ptr, ptr %10, align 8, !tbaa !5
  %45 = getelementptr inbounds %"struct.rw::d3d9::InstanceDataHeader", ptr %44, i32 0, i32 8
  %46 = load i32, ptr %45, align 8, !tbaa !21
  %47 = mul i32 2, %46
  %48 = load i32, ptr %11, align 4, !tbaa !9
  %49 = add i32 %48, %47
  store i32 %49, ptr %11, align 4, !tbaa !9
  %50 = load ptr, ptr %10, align 8, !tbaa !5
  %51 = getelementptr inbounds %"struct.rw::d3d9::InstanceDataHeader", ptr %50, i32 0, i32 5
  %52 = getelementptr inbounds [2 x %"struct.rw::d3d9::VertexStream"], ptr %51, i64 0, i64 0
  %53 = getelementptr inbounds %"struct.rw::d3d9::VertexStream", ptr %52, i32 0, i32 2
  %54 = load i32, ptr %53, align 4, !tbaa !22
  %55 = load ptr, ptr %10, align 8, !tbaa !5
  %56 = getelementptr inbounds %"struct.rw::d3d9::InstanceDataHeader", ptr %55, i32 0, i32 9
  %57 = load i32, ptr %56, align 4, !tbaa !24
  %58 = mul i32 %54, %57
  %59 = add i32 16, %58
  %60 = load i32, ptr %11, align 4, !tbaa !9
  %61 = add i32 %60, %59
  store i32 %61, ptr %11, align 4, !tbaa !9
  %62 = load ptr, ptr %10, align 8, !tbaa !5
  %63 = getelementptr inbounds %"struct.rw::d3d9::InstanceDataHeader", ptr %62, i32 0, i32 5
  %64 = getelementptr inbounds [2 x %"struct.rw::d3d9::VertexStream"], ptr %63, i64 0, i64 1
  %65 = getelementptr inbounds %"struct.rw::d3d9::VertexStream", ptr %64, i32 0, i32 2
  %66 = load i32, ptr %65, align 4, !tbaa !22
  %67 = load ptr, ptr %10, align 8, !tbaa !5
  %68 = getelementptr inbounds %"struct.rw::d3d9::InstanceDataHeader", ptr %67, i32 0, i32 9
  %69 = load i32, ptr %68, align 4, !tbaa !24
  %70 = mul i32 %66, %69
  %71 = add i32 16, %70
  %72 = load i32, ptr %11, align 4, !tbaa !9
  %73 = add i32 %72, %71
  store i32 %73, ptr %11, align 4, !tbaa !9
  %74 = load i32, ptr %11, align 4, !tbaa !9
  store i32 %74, ptr %4, align 4
  store i32 1, ptr %9, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #2
  br label %75

75:                                               ; preds = %26, %25
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #2
  %76 = load i32, ptr %4, align 4
  ret i32 %76
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 152}
!12 = !{!"_ZTSN2rw8GeometryE", !13, i64 0, !10, i64 16, !14, i64 20, !10, i64 24, !10, i64 28, !10, i64 32, !10, i64 36, !6, i64 40, !6, i64 48, !7, i64 56, !6, i64 120, !15, i64 128, !6, i64 144, !6, i64 152, !10, i64 160}
!13 = !{!"_ZTSN2rw6ObjectE", !7, i64 0, !7, i64 1, !7, i64 2, !7, i64 3, !6, i64 8}
!14 = !{!"short", !7, i64 0}
!15 = !{!"_ZTSN2rw12MaterialListE", !6, i64 0, !10, i64 8, !10, i64 12}
!16 = !{!17, !10, i64 0}
!17 = !{!"_ZTSN2rw18InstanceDataHeaderE", !10, i64 0}
!18 = !{!19, !10, i64 8}
!19 = !{!"_ZTSN2rw4d3d918InstanceDataHeaderE", !17, i64 0, !10, i64 4, !10, i64 8, !6, i64 16, !10, i64 24, !7, i64 32, !10, i64 80, !6, i64 88, !10, i64 96, !10, i64 100, !6, i64 104}
!20 = !{!19, !6, i64 88}
!21 = !{!19, !10, i64 96}
!22 = !{!23, !10, i64 12}
!23 = !{!"_ZTSN2rw4d3d912VertexStreamE", !6, i64 0, !10, i64 8, !10, i64 12, !14, i64 16, !7, i64 18, !7, i64 19}
!24 = !{!19, !10, i64 100}


; 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 nounwind uwtable
declare dso_local noundef i32 @_ZN2rw4d3d914getDeclarationEPvPNS0_13VertexElementE(ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i32 @_ZN2rw4d3d917getSizeNativeDataEPvii(ptr nocapture noundef readonly %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #0 {
  %4 = getelementptr inbounds i8, ptr %0, i64 152
  %5 = load ptr, ptr %4, align 8, !tbaa !5
  %6 = icmp eq ptr %5, null
  br i1 %6, label %30, label %7

7:                                                ; preds = %3
  %8 = load i32, ptr %5, align 4, !tbaa !14
  %.not = icmp eq i32 %8, 9
  br i1 %.not, label %9, label %30

9:                                                ; preds = %7
  %10 = getelementptr inbounds i8, ptr %5, i64 8
  %11 = load i32, ptr %10, align 8, !tbaa !16
  %12 = mul i32 %11, 36
  %13 = getelementptr inbounds i8, ptr %5, i64 88
  %14 = load ptr, ptr %13, align 8, !tbaa !18
  %15 = tail call noundef i32 @_ZN2rw4d3d914getDeclarationEPvPNS0_13VertexElementE(ptr noundef %14, ptr noundef null)
  %16 = shl i32 %15, 3
  %17 = getelementptr inbounds i8, ptr %5, i64 96
  %18 = load i32, ptr %17, align 8, !tbaa !19
  %19 = shl i32 %18, 1
  %20 = getelementptr inbounds i8, ptr %5, i64 44
  %21 = load i32, ptr %20, align 4, !tbaa !20
  %22 = getelementptr inbounds i8, ptr %5, i64 100
  %23 = load i32, ptr %22, align 4, !tbaa !22
  %24 = getelementptr inbounds i8, ptr %5, i64 68
  %25 = load i32, ptr %24, align 4, !tbaa !20
  %reass.add = add i32 %25, %21
  %reass.mul = mul i32 %reass.add, %23
  %26 = add i32 %12, 120
  %27 = add i32 %26, %16
  %28 = add i32 %27, %19
  %29 = add i32 %28, %reass.mul
  br label %30

30:                                               ; preds = %3, %7, %9
  %.0 = phi i32 [ %29, %9 ], [ 0, %7 ], [ 0, %3 ]
  ret i32 %.0
}

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

!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 152}
!6 = !{!"_ZTSN2rw8GeometryE", !7, i64 0, !11, i64 16, !12, i64 20, !11, i64 24, !11, i64 28, !11, i64 32, !11, i64 36, !10, i64 40, !10, i64 48, !8, i64 56, !10, i64 120, !13, i64 128, !10, i64 144, !10, i64 152, !11, i64 160}
!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 = !{!"int", !8, i64 0}
!12 = !{!"short", !8, i64 0}
!13 = !{!"_ZTSN2rw12MaterialListE", !10, i64 0, !11, i64 8, !11, i64 12}
!14 = !{!15, !11, i64 0}
!15 = !{!"_ZTSN2rw18InstanceDataHeaderE", !11, i64 0}
!16 = !{!17, !11, i64 8}
!17 = !{!"_ZTSN2rw4d3d918InstanceDataHeaderE", !15, i64 0, !11, i64 4, !11, i64 8, !10, i64 16, !11, i64 24, !8, i64 32, !11, i64 80, !10, i64 88, !11, i64 96, !11, i64 100, !10, i64 104}
!18 = !{!17, !10, i64 88}
!19 = !{!17, !11, i64 96}
!20 = !{!21, !11, i64 12}
!21 = !{!"_ZTSN2rw4d3d912VertexStreamE", !10, i64 0, !11, i64 8, !11, i64 12, !12, i64 16, !8, i64 18, !8, i64 19}
!22 = !{!17, !11, i64 100}


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