; LLVM IR from aap/librw :: src/ps2/ps2.ll (ZN2rw3ps219makeDefaultPipelineEv)

; 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::ps2::PipeAttribute" = type { ptr, i32 }
%"class.rw::ps2::MatPipeline" = type { %"class.rw::Pipeline", i32, i32, i32, i32, [10 x ptr], ptr, ptr, ptr, ptr }
%"class.rw::Pipeline" = type { i32, i32, i32 }

@_ZN2rw3ps214defaultObjPipeE = external dso_local global ptr, align 8
@_ZN2rw3ps214defaultMatPipeE = external dso_local global ptr, align 8
@_ZN2rw3ps29attribXYZE = external dso_local global %"struct.rw::ps2::PipeAttribute", align 8
@_ZN2rw3ps28attribUVE = external dso_local global %"struct.rw::ps2::PipeAttribute", align 8
@_ZN2rw3ps210attribRGBAE = external dso_local global %"struct.rw::ps2::PipeAttribute", align 8
@_ZN2rw3ps212attribNormalE = external dso_local global %"struct.rw::ps2::PipeAttribute", 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
declare dso_local noundef ptr @_ZN2rw3ps211MatPipeline6createEv() #1 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN2rw3ps211MatPipeline17setTriBufferSizesEjj(ptr noundef nonnull align 8 dereferenceable(144), i32 noundef, i32 noundef) #2 align 2

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN2rw3ps219genericUninstanceCBEPNS0_11MatPipelineEPNS_8GeometryEPjPNS_4MeshEPPh(ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef) #1

; Function Attrs: mustprogress uwtable
define dso_local noundef ptr @_ZN2rw3ps219makeDefaultPipelineEv() #1 {
  %1 = alloca ptr, align 8
  %2 = alloca i32, align 4
  %3 = alloca ptr, align 8
  %4 = load ptr, ptr @_ZN2rw3ps214defaultMatPipeE, align 8, !tbaa !5
  %5 = icmp eq ptr %4, null
  br i1 %5, label %6, label %33

6:                                                ; preds = %0
  call void @llvm.lifetime.start.p0(i64 8, ptr %1) #3
  %7 = call noundef ptr @_ZN2rw3ps211MatPipeline6createEv()
  store ptr %7, ptr %1, align 8, !tbaa !5
  %8 = load ptr, ptr %1, align 8, !tbaa !5
  %9 = getelementptr inbounds %"class.rw::ps2::MatPipeline", ptr %8, i32 0, i32 5
  %10 = getelementptr inbounds [10 x ptr], ptr %9, i64 0, i64 0
  store ptr @_ZN2rw3ps29attribXYZE, ptr %10, align 8, !tbaa !5
  %11 = load ptr, ptr %1, align 8, !tbaa !5
  %12 = getelementptr inbounds %"class.rw::ps2::MatPipeline", ptr %11, i32 0, i32 5
  %13 = getelementptr inbounds [10 x ptr], ptr %12, i64 0, i64 1
  store ptr @_ZN2rw3ps28attribUVE, ptr %13, align 8, !tbaa !5
  %14 = load ptr, ptr %1, align 8, !tbaa !5
  %15 = getelementptr inbounds %"class.rw::ps2::MatPipeline", ptr %14, i32 0, i32 5
  %16 = getelementptr inbounds [10 x ptr], ptr %15, i64 0, i64 2
  store ptr @_ZN2rw3ps210attribRGBAE, ptr %16, align 8, !tbaa !5
  %17 = load ptr, ptr %1, align 8, !tbaa !5
  %18 = getelementptr inbounds %"class.rw::ps2::MatPipeline", ptr %17, i32 0, i32 5
  %19 = getelementptr inbounds [10 x ptr], ptr %18, i64 0, i64 3
  store ptr @_ZN2rw3ps212attribNormalE, ptr %19, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #3
  %20 = call noundef i32 @_ZN2rw3ps211MatPipeline12getVertCountEjjjj(i32 noundef 976, i32 noundef 4, i32 noundef 3, i32 noundef 2)
  store i32 %20, ptr %2, align 4, !tbaa !9
  %21 = load ptr, ptr %1, align 8, !tbaa !5
  %22 = load i32, ptr %2, align 4, !tbaa !9
  call void @_ZN2rw3ps211MatPipeline17setTriBufferSizesEjj(ptr noundef nonnull align 8 dereferenceable(144) %21, i32 noundef 4, i32 noundef %22)
  %23 = load ptr, ptr %1, align 8, !tbaa !5
  %24 = getelementptr inbounds %"class.rw::ps2::MatPipeline", ptr %23, i32 0, i32 2
  %25 = load i32, ptr %24, align 8, !tbaa !11
  %26 = load i32, ptr %2, align 4, !tbaa !9
  %27 = mul i32 %25, %26
  %28 = load ptr, ptr %1, align 8, !tbaa !5
  %29 = getelementptr inbounds %"class.rw::ps2::MatPipeline", ptr %28, i32 0, i32 1
  store i32 %27, ptr %29, align 4, !tbaa !14
  %30 = load ptr, ptr %1, align 8, !tbaa !5
  %31 = getelementptr inbounds %"class.rw::ps2::MatPipeline", ptr %30, i32 0, i32 7
  store ptr @_ZN2rw3ps219genericUninstanceCBEPNS0_11MatPipelineEPNS_8GeometryEPjPNS_4MeshEPPh, ptr %31, align 8, !tbaa !15
  %32 = load ptr, ptr %1, align 8, !tbaa !5
  store ptr %32, ptr @_ZN2rw3ps214defaultMatPipeE, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %1) #3
  br label %33

33:                                               ; preds = %6, %0
  %34 = load ptr, ptr @_ZN2rw3ps214defaultObjPipeE, align 8, !tbaa !5
  %35 = icmp eq ptr %34, null
  br i1 %35, label %36, label %39

36:                                               ; preds = %33
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #3
  %37 = call noundef ptr @_ZN2rw3ps211ObjPipeline6createEv()
  store ptr %37, ptr %3, align 8, !tbaa !5
  %38 = load ptr, ptr %3, align 8, !tbaa !5
  store ptr %38, ptr @_ZN2rw3ps214defaultObjPipeE, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  br label %39

39:                                               ; preds = %36, %33
  %40 = load ptr, ptr @_ZN2rw3ps214defaultObjPipeE, align 8, !tbaa !5
  ret ptr %40
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZN2rw3ps211MatPipeline12getVertCountEjjjj(i32 noundef, i32 noundef, i32 noundef, i32 noundef) #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 = { 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, !10, i64 16}
!12 = !{!"_ZTSN2rw3ps211MatPipelineE", !13, i64 0, !10, i64 12, !10, i64 16, !10, i64 20, !10, i64 24, !7, i64 32, !6, i64 112, !6, i64 120, !6, i64 128, !6, i64 136}
!13 = !{!"_ZTSN2rw8PipelineE", !10, i64 0, !10, i64 4, !10, i64 8}
!14 = !{!12, !10, i64 12}
!15 = !{!12, !6, i64 120}


; 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::ps2::PipeAttribute" = type { ptr, i32 }

@_ZN2rw3ps214defaultObjPipeE = external dso_local local_unnamed_addr global ptr, align 8
@_ZN2rw3ps214defaultMatPipeE = external dso_local local_unnamed_addr global ptr, align 8
@_ZN2rw3ps29attribXYZE = external dso_local global %"struct.rw::ps2::PipeAttribute", align 8
@_ZN2rw3ps28attribUVE = external dso_local global %"struct.rw::ps2::PipeAttribute", align 8
@_ZN2rw3ps210attribRGBAE = external dso_local global %"struct.rw::ps2::PipeAttribute", align 8
@_ZN2rw3ps212attribNormalE = external dso_local global %"struct.rw::ps2::PipeAttribute", align 8

; Function Attrs: mustprogress uwtable
declare dso_local noundef ptr @_ZN2rw3ps211MatPipeline6createEv() local_unnamed_addr #0 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN2rw3ps211MatPipeline17setTriBufferSizesEjj(ptr noundef nonnull align 8 dereferenceable(144), i32 noundef, i32 noundef) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef ptr @_ZN2rw3ps211ObjPipeline6createEv() local_unnamed_addr #0 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN2rw3ps219genericUninstanceCBEPNS0_11MatPipelineEPNS_8GeometryEPjPNS_4MeshEPPh(ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef) #0

; Function Attrs: mustprogress uwtable
define dso_local noundef ptr @_ZN2rw3ps219makeDefaultPipelineEv() local_unnamed_addr #0 {
  %1 = load ptr, ptr @_ZN2rw3ps214defaultMatPipeE, align 8, !tbaa !5
  %2 = icmp eq ptr %1, null
  br i1 %2, label %3, label %15

3:                                                ; preds = %0
  %4 = tail call noundef ptr @_ZN2rw3ps211MatPipeline6createEv()
  %5 = getelementptr inbounds i8, ptr %4, i64 32
  store ptr @_ZN2rw3ps29attribXYZE, ptr %5, align 8, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %4, i64 40
  store ptr @_ZN2rw3ps28attribUVE, ptr %6, align 8, !tbaa !5
  %7 = getelementptr inbounds i8, ptr %4, i64 48
  store ptr @_ZN2rw3ps210attribRGBAE, ptr %7, align 8, !tbaa !5
  %8 = getelementptr inbounds i8, ptr %4, i64 56
  store ptr @_ZN2rw3ps212attribNormalE, ptr %8, align 8, !tbaa !5
  %9 = tail call noundef i32 @_ZN2rw3ps211MatPipeline12getVertCountEjjjj(i32 noundef 976, i32 noundef 4, i32 noundef 3, i32 noundef 2)
  tail call void @_ZN2rw3ps211MatPipeline17setTriBufferSizesEjj(ptr noundef nonnull align 8 dereferenceable(144) %4, i32 noundef 4, i32 noundef %9)
  %10 = getelementptr inbounds i8, ptr %4, i64 16
  %11 = load i32, ptr %10, align 8, !tbaa !9
  %12 = mul i32 %11, %9
  %13 = getelementptr inbounds i8, ptr %4, i64 12
  store i32 %12, ptr %13, align 4, !tbaa !13
  %14 = getelementptr inbounds i8, ptr %4, i64 120
  store ptr @_ZN2rw3ps219genericUninstanceCBEPNS0_11MatPipelineEPNS_8GeometryEPjPNS_4MeshEPPh, ptr %14, align 8, !tbaa !14
  store ptr %4, ptr @_ZN2rw3ps214defaultMatPipeE, align 8, !tbaa !5
  br label %15

15:                                               ; preds = %3, %0
  %16 = load ptr, ptr @_ZN2rw3ps214defaultObjPipeE, align 8, !tbaa !5
  %17 = icmp eq ptr %16, null
  br i1 %17, label %18, label %20

18:                                               ; preds = %15
  %19 = tail call noundef ptr @_ZN2rw3ps211ObjPipeline6createEv()
  store ptr %19, ptr @_ZN2rw3ps214defaultObjPipeE, align 8, !tbaa !5
  br label %20

20:                                               ; preds = %18, %15
  %21 = phi ptr [ %19, %18 ], [ %16, %15 ]
  ret ptr %21
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZN2rw3ps211MatPipeline12getVertCountEjjjj(i32 noundef, i32 noundef, i32 noundef, i32 noundef) 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" }

!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, !12, i64 16}
!10 = !{!"_ZTSN2rw3ps211MatPipelineE", !11, i64 0, !12, i64 12, !12, i64 16, !12, i64 20, !12, i64 24, !7, i64 32, !6, i64 112, !6, i64 120, !6, i64 128, !6, i64 136}
!11 = !{!"_ZTSN2rw8PipelineE", !12, i64 0, !12, i64 4, !12, i64 8}
!12 = !{!"int", !7, i64 0}
!13 = !{!10, !12, i64 12}
!14 = !{!10, !6, i64 120}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,SROAPass,TailCallElimPass