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

; 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::MorphTarget" = type { ptr, %"struct.rw::Sphere", ptr, ptr }
%"struct.rw::Sphere" = type { %"struct.rw::V3d", float }
%"struct.rw::V3d" = type { float, float, float }
%"struct.rw::Mesh" = type { ptr, i32, ptr }

; 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
define dso_local noundef ptr @_ZN2rw3ps214instanceNormalEPjPNS_8GeometryEPNS_4MeshEjj(ptr noundef %0, ptr noundef %1, ptr noundef %2, i32 noundef %3, i32 noundef %4) #1 {
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i16, align 2
  %12 = alloca ptr, align 8
  %13 = alloca ptr, align 8
  %14 = alloca i32, align 4
  %15 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store ptr %2, ptr %8, align 8, !tbaa !5
  store i32 %3, ptr %9, align 4, !tbaa !9
  store i32 %4, ptr %10, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 2, ptr %11) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #2
  %16 = load ptr, ptr %7, align 8, !tbaa !5
  %17 = getelementptr inbounds %"struct.rw::Geometry", ptr %16, i32 0, i32 10
  %18 = load ptr, ptr %17, align 8, !tbaa !11
  %19 = getelementptr inbounds %"struct.rw::MorphTarget", ptr %18, i64 0
  %20 = getelementptr inbounds %"struct.rw::MorphTarget", ptr %19, i32 0, i32 3
  %21 = load ptr, ptr %20, align 8, !tbaa !16
  store ptr %21, ptr %12, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #2
  %22 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %22, ptr %13, align 8, !tbaa !5
  %23 = load ptr, ptr %7, align 8, !tbaa !5
  %24 = getelementptr inbounds %"struct.rw::Geometry", ptr %23, i32 0, i32 1
  %25 = load i32, ptr %24, align 8, !tbaa !21
  %26 = and i32 %25, 16
  %27 = icmp ne i32 %26, 0
  br i1 %27, label %28, label %79

28:                                               ; preds = %5
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #2
  %29 = load i32, ptr %9, align 4, !tbaa !9
  store i32 %29, ptr %14, align 4, !tbaa !9
  br label %30

30:                                               ; preds = %75, %28
  %31 = load i32, ptr %14, align 4, !tbaa !9
  %32 = load i32, ptr %9, align 4, !tbaa !9
  %33 = load i32, ptr %10, align 4, !tbaa !9
  %34 = add i32 %32, %33
  %35 = icmp ult i32 %31, %34
  br i1 %35, label %37, label %36

36:                                               ; preds = %30
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #2
  br label %78

37:                                               ; preds = %30
  %38 = load ptr, ptr %8, align 8, !tbaa !5
  %39 = getelementptr inbounds %"struct.rw::Mesh", ptr %38, i32 0, i32 0
  %40 = load ptr, ptr %39, align 8, !tbaa !22
  %41 = load i32, ptr %14, align 4, !tbaa !9
  %42 = zext i32 %41 to i64
  %43 = getelementptr inbounds i16, ptr %40, i64 %42
  %44 = load i16, ptr %43, align 2, !tbaa !24
  store i16 %44, ptr %11, align 2, !tbaa !24
  %45 = load ptr, ptr %12, align 8, !tbaa !5
  %46 = load i16, ptr %11, align 2, !tbaa !24
  %47 = zext i16 %46 to i64
  %48 = getelementptr inbounds %"struct.rw::V3d", ptr %45, i64 %47
  %49 = getelementptr inbounds %"struct.rw::V3d", ptr %48, i32 0, i32 0
  %50 = load float, ptr %49, align 4, !tbaa !25
  %51 = fmul float %50, 1.270000e+02
  %52 = fptoui float %51 to i8
  %53 = load ptr, ptr %13, align 8, !tbaa !5
  %54 = getelementptr inbounds i8, ptr %53, i32 1
  store ptr %54, ptr %13, align 8, !tbaa !5
  store i8 %52, ptr %53, align 1, !tbaa !26
  %55 = load ptr, ptr %12, align 8, !tbaa !5
  %56 = load i16, ptr %11, align 2, !tbaa !24
  %57 = zext i16 %56 to i64
  %58 = getelementptr inbounds %"struct.rw::V3d", ptr %55, i64 %57
  %59 = getelementptr inbounds %"struct.rw::V3d", ptr %58, i32 0, i32 1
  %60 = load float, ptr %59, align 4, !tbaa !27
  %61 = fmul float %60, 1.270000e+02
  %62 = fptoui float %61 to i8
  %63 = load ptr, ptr %13, align 8, !tbaa !5
  %64 = getelementptr inbounds i8, ptr %63, i32 1
  store ptr %64, ptr %13, align 8, !tbaa !5
  store i8 %62, ptr %63, align 1, !tbaa !26
  %65 = load ptr, ptr %12, align 8, !tbaa !5
  %66 = load i16, ptr %11, align 2, !tbaa !24
  %67 = zext i16 %66 to i64
  %68 = getelementptr inbounds %"struct.rw::V3d", ptr %65, i64 %67
  %69 = getelementptr inbounds %"struct.rw::V3d", ptr %68, i32 0, i32 2
  %70 = load float, ptr %69, align 4, !tbaa !28
  %71 = fmul float %70, 1.270000e+02
  %72 = fptoui float %71 to i8
  %73 = load ptr, ptr %13, align 8, !tbaa !5
  %74 = getelementptr inbounds i8, ptr %73, i32 1
  store ptr %74, ptr %13, align 8, !tbaa !5
  store i8 %72, ptr %73, align 1, !tbaa !26
  br label %75

75:                                               ; preds = %37
  %76 = load i32, ptr %14, align 4, !tbaa !9
  %77 = add i32 %76, 1
  store i32 %77, ptr %14, align 4, !tbaa !9
  br label %30, !llvm.loop !29

78:                                               ; preds = %36
  br label %99

79:                                               ; preds = %5
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #2
  %80 = load i32, ptr %9, align 4, !tbaa !9
  store i32 %80, ptr %15, align 4, !tbaa !9
  br label %81

81:                                               ; preds = %95, %79
  %82 = load i32, ptr %15, align 4, !tbaa !9
  %83 = load i32, ptr %9, align 4, !tbaa !9
  %84 = load i32, ptr %10, align 4, !tbaa !9
  %85 = add i32 %83, %84
  %86 = icmp ult i32 %82, %85
  br i1 %86, label %88, label %87

87:                                               ; preds = %81
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #2
  br label %98

88:                                               ; preds = %81
  %89 = load ptr, ptr %13, align 8, !tbaa !5
  %90 = getelementptr inbounds i8, ptr %89, i32 1
  store ptr %90, ptr %13, align 8, !tbaa !5
  store i8 0, ptr %89, align 1, !tbaa !26
  %91 = load ptr, ptr %13, align 8, !tbaa !5
  %92 = getelementptr inbounds i8, ptr %91, i32 1
  store ptr %92, ptr %13, align 8, !tbaa !5
  store i8 0, ptr %91, align 1, !tbaa !26
  %93 = load ptr, ptr %13, align 8, !tbaa !5
  %94 = getelementptr inbounds i8, ptr %93, i32 1
  store ptr %94, ptr %13, align 8, !tbaa !5
  store i8 0, ptr %93, align 1, !tbaa !26
  br label %95

95:                                               ; preds = %88
  %96 = load i32, ptr %15, align 4, !tbaa !9
  %97 = add i32 %96, 1
  store i32 %97, ptr %15, align 4, !tbaa !9
  br label %81, !llvm.loop !31

98:                                               ; preds = %87
  br label %99

99:                                               ; preds = %98, %78
  br label %100

100:                                              ; preds = %105, %99
  %101 = load ptr, ptr %13, align 8, !tbaa !5
  %102 = ptrtoint ptr %101 to i64
  %103 = urem i64 %102, 16
  %104 = icmp ne i64 %103, 0
  br i1 %104, label %105, label %108

105:                                              ; preds = %100
  %106 = load ptr, ptr %13, align 8, !tbaa !5
  %107 = getelementptr inbounds i8, ptr %106, i32 1
  store ptr %107, ptr %13, align 8, !tbaa !5
  store i8 0, ptr %106, align 1, !tbaa !26
  br label %100, !llvm.loop !32

108:                                              ; preds = %100
  %109 = load ptr, ptr %13, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #2
  call void @llvm.lifetime.end.p0(i64 2, ptr %11) #2
  ret ptr %109
}

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 120}
!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, !6, i64 32}
!17 = !{!"_ZTSN2rw11MorphTargetE", !6, i64 0, !18, i64 8, !6, i64 24, !6, i64 32}
!18 = !{!"_ZTSN2rw6SphereE", !19, i64 0, !20, i64 12}
!19 = !{!"_ZTSN2rw3V3dE", !20, i64 0, !20, i64 4, !20, i64 8}
!20 = !{!"float", !7, i64 0}
!21 = !{!12, !10, i64 16}
!22 = !{!23, !6, i64 0}
!23 = !{!"_ZTSN2rw4MeshE", !6, i64 0, !10, i64 8, !6, i64 16}
!24 = !{!14, !14, i64 0}
!25 = !{!19, !20, i64 0}
!26 = !{!7, !7, i64 0}
!27 = !{!19, !20, i64 4}
!28 = !{!19, !20, i64 8}
!29 = distinct !{!29, !30}
!30 = !{!"llvm.loop.mustprogress"}
!31 = distinct !{!31, !30}
!32 = distinct !{!32, !30}


; 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::V3d" = type { float, float, float }

; Function Attrs: mustprogress nofree norecurse nosync nounwind memory(readwrite, inaccessiblemem: none) uwtable
define dso_local noundef ptr @_ZN2rw3ps214instanceNormalEPjPNS_8GeometryEPNS_4MeshEjj(ptr noundef %0, ptr nocapture noundef readonly %1, ptr nocapture noundef readonly %2, i32 noundef %3, i32 noundef %4) local_unnamed_addr #0 {
  %6 = getelementptr inbounds i8, ptr %1, i64 120
  %7 = load ptr, ptr %6, align 8, !tbaa !5
  %8 = getelementptr inbounds i8, ptr %7, i64 32
  %9 = load ptr, ptr %8, align 8, !tbaa !14
  %10 = getelementptr inbounds i8, ptr %1, i64 16
  %11 = load i32, ptr %10, align 8, !tbaa !19
  %12 = and i32 %11, 16
  %.not = icmp eq i32 %12, 0
  %13 = add i32 %4, %3
  %14 = icmp ugt i32 %13, %3
  br i1 %.not, label %.preheader, label %.preheader32

.preheader32:                                     ; preds = %5
  br i1 %14, label %.lr.ph.preheader, label %.loopexit

.lr.ph.preheader:                                 ; preds = %.preheader32
  %15 = zext i32 %3 to i64
  %wide.trip.count = zext i32 %13 to i64
  br label %.lr.ph

.preheader:                                       ; preds = %5
  br i1 %14, label %.lr.ph38.preheader, label %.loopexit

.lr.ph38.preheader:                               ; preds = %.preheader
  %16 = add i32 %4, -1
  %17 = zext i32 %16 to i64
  %18 = mul nuw nsw i64 %17, 3
  %19 = add nuw nsw i64 %18, 3
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 1 dereferenceable(1) %0, i8 0, i64 %19, i1 false), !tbaa !20
  %scevgep = getelementptr i8, ptr %0, i64 %19
  br label %.loopexit

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %indvars.iv = phi i64 [ %15, %.lr.ph.preheader ], [ %indvars.iv.next, %.lr.ph ]
  %.03034 = phi ptr [ %0, %.lr.ph.preheader ], [ %38, %.lr.ph ]
  %20 = load ptr, ptr %2, align 8, !tbaa !21
  %21 = getelementptr inbounds i16, ptr %20, i64 %indvars.iv
  %22 = load i16, ptr %21, align 2, !tbaa !23
  %23 = zext i16 %22 to i64
  %24 = getelementptr inbounds %"struct.rw::V3d", ptr %9, i64 %23
  %25 = load float, ptr %24, align 4, !tbaa !24
  %26 = fmul float %25, 1.270000e+02
  %27 = fptoui float %26 to i8
  %28 = getelementptr inbounds i8, ptr %.03034, i64 1
  store i8 %27, ptr %.03034, align 1, !tbaa !20
  %29 = getelementptr inbounds i8, ptr %24, i64 4
  %30 = load float, ptr %29, align 4, !tbaa !25
  %31 = fmul float %30, 1.270000e+02
  %32 = fptoui float %31 to i8
  %33 = getelementptr inbounds i8, ptr %.03034, i64 2
  store i8 %32, ptr %28, align 1, !tbaa !20
  %34 = getelementptr inbounds i8, ptr %24, i64 8
  %35 = load float, ptr %34, align 4, !tbaa !26
  %36 = fmul float %35, 1.270000e+02
  %37 = fptoui float %36 to i8
  %38 = getelementptr inbounds i8, ptr %.03034, i64 3
  store i8 %37, ptr %33, align 1, !tbaa !20
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %.loopexit, label %.lr.ph, !llvm.loop !27

.loopexit:                                        ; preds = %.lr.ph, %.lr.ph38.preheader, %.preheader32, %.preheader
  %.2 = phi ptr [ %0, %.preheader ], [ %0, %.preheader32 ], [ %scevgep, %.lr.ph38.preheader ], [ %38, %.lr.ph ]
  %39 = ptrtoint ptr %.2 to i64
  %40 = and i64 %39, 15
  %.not3140 = icmp eq i64 %40, 0
  br i1 %.not3140, label %._crit_edge, label %.lr.ph42.preheader

.lr.ph42.preheader:                               ; preds = %.loopexit
  %41 = and i64 %39, 15
  %42 = sub nuw nsw i64 16, %41
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 1 dereferenceable(1) %.2, i8 0, i64 %42, i1 false), !tbaa !20
  %scevgep48 = getelementptr i8, ptr %.2, i64 %42
  br label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph42.preheader, %.loopexit
  %.3.lcssa = phi ptr [ %.2, %.loopexit ], [ %scevgep48, %.lr.ph42.preheader ]
  ret ptr %.3.lcssa
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #1

attributes #0 = { mustprogress nofree norecurse nosync nounwind memory(readwrite, inaccessiblemem: none) 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 = { nocallback nofree nounwind willreturn memory(argmem: write) }

!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 120}
!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, !10, i64 32}
!15 = !{!"_ZTSN2rw11MorphTargetE", !10, i64 0, !16, i64 8, !10, i64 24, !10, i64 32}
!16 = !{!"_ZTSN2rw6SphereE", !17, i64 0, !18, i64 12}
!17 = !{!"_ZTSN2rw3V3dE", !18, i64 0, !18, i64 4, !18, i64 8}
!18 = !{!"float", !8, i64 0}
!19 = !{!6, !11, i64 16}
!20 = !{!8, !8, i64 0}
!21 = !{!22, !10, i64 0}
!22 = !{!"_ZTSN2rw4MeshE", !10, i64 0, !11, i64 8, !10, i64 16}
!23 = !{!12, !12, i64 0}
!24 = !{!17, !18, i64 0}
!25 = !{!17, !18, i64 4}
!26 = !{!17, !18, i64 8}
!27 = distinct !{!27, !28}
!28 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopIdiomRecognizePass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass