; LLVM IR from aap/librw :: src/geometry.ll (ZN2rw8Geometry21removeUnusedMaterialsEv)

; 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::MemoryFunctions" = type { ptr, ptr, ptr, ptr, ptr }
%"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::MeshHeader" = type { i32, i16, i16, i32, i32 }
%"struct.rw::Mesh" = type { ptr, i32, ptr }
%"struct.rw::Triangle" = type { [3 x i16], i16 }

@_ZN2rw6Engine8memfuncsE = external global %"struct.rw::MemoryFunctions", align 8
@.str.17 = external hidden unnamed_addr constant [76 x i8], align 1
@.str.18 = external hidden unnamed_addr constant [76 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

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef ptr @_ZN2rw14mustmalloc_LOCEmjPKc(i64 noundef, i32 noundef, ptr noundef) #1

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZN2rw10MeshHeader9getMeshesEv(ptr noundef nonnull align 4 dereferenceable(16)) #3 align 2

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

declare noundef ptr @_ZN2rw8Geometry14allocateMeshesEiji(ptr noundef nonnull align 8 dereferenceable(168), i32 noundef, i32 noundef, i32 noundef) #4

declare void @_ZN2rw10MeshHeader12setupIndicesEv(ptr noundef nonnull align 4 dereferenceable(16)) #4

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN2rw8Geometry21removeUnusedMaterialsEv(ptr noundef nonnull align 8 dereferenceable(168) %0) #5 align 2 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca ptr, align 8
  %14 = alloca ptr, align 8
  %15 = alloca i32, align 4
  %16 = alloca i32, align 4
  %17 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  %18 = load ptr, ptr %2, align 8
  %19 = getelementptr inbounds %"struct.rw::Geometry", ptr %18, i32 0, i32 12
  %20 = load ptr, ptr %19, align 8, !tbaa !9
  %21 = icmp eq ptr %20, null
  br i1 %21, label %22, label %23

22:                                               ; preds = %1
  br label %283

23:                                               ; preds = %1
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #6
  %24 = getelementptr inbounds %"struct.rw::Geometry", ptr %18, i32 0, i32 12
  %25 = load ptr, ptr %24, align 8, !tbaa !9
  store ptr %25, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #6
  %26 = load ptr, ptr %3, align 8, !tbaa !5
  %27 = call noundef ptr @_ZN2rw10MeshHeader9getMeshesEv(ptr noundef nonnull align 4 dereferenceable(16) %26)
  store ptr %27, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #6
  store i32 0, ptr %5, align 4, !tbaa !15
  br label %28

28:                                               ; preds = %46, %23
  %29 = load i32, ptr %5, align 4, !tbaa !15
  %30 = load ptr, ptr %3, align 8, !tbaa !5
  %31 = getelementptr inbounds %"struct.rw::MeshHeader", ptr %30, i32 0, i32 1
  %32 = load i16, ptr %31, align 4, !tbaa !16
  %33 = zext i16 %32 to i32
  %34 = icmp ult i32 %29, %33
  br i1 %34, label %36, label %35

35:                                               ; preds = %28
  store i32 2, ptr %6, align 4
  br label %49

36:                                               ; preds = %28
  %37 = load ptr, ptr %4, align 8, !tbaa !5
  %38 = load i32, ptr %5, align 4, !tbaa !15
  %39 = zext i32 %38 to i64
  %40 = getelementptr inbounds %"struct.rw::Mesh", ptr %37, i64 %39
  %41 = getelementptr inbounds %"struct.rw::Mesh", ptr %40, i32 0, i32 0
  %42 = load ptr, ptr %41, align 8, !tbaa !18
  %43 = icmp eq ptr %42, null
  br i1 %43, label %44, label %45

44:                                               ; preds = %36
  store i32 1, ptr %6, align 4
  br label %49

45:                                               ; preds = %36
  br label %46

46:                                               ; preds = %45
  %47 = load i32, ptr %5, align 4, !tbaa !15
  %48 = add i32 %47, 1
  store i32 %48, ptr %5, align 4, !tbaa !15
  br label %28, !llvm.loop !20

49:                                               ; preds = %44, %35
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #6
  %50 = load i32, ptr %6, align 4
  switch i32 %50, label %281 [
    i32 2, label %51
  ]

51:                                               ; preds = %49
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #6
  %52 = getelementptr inbounds %"struct.rw::Geometry", ptr %18, i32 0, i32 11
  %53 = getelementptr inbounds %"struct.rw::MaterialList", ptr %52, i32 0, i32 1
  %54 = load i32, ptr %53, align 8, !tbaa !22
  %55 = sext i32 %54 to i64
  %56 = mul i64 %55, 4
  %57 = call noundef ptr @_ZN2rw14mustmalloc_LOCEmjPKc(i64 noundef %56, i32 noundef 65551, ptr noundef @.str.17)
  store ptr %57, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #6
  %58 = getelementptr inbounds %"struct.rw::Geometry", ptr %18, i32 0, i32 11
  %59 = getelementptr inbounds %"struct.rw::MaterialList", ptr %58, i32 0, i32 1
  %60 = load i32, ptr %59, align 8, !tbaa !22
  %61 = sext i32 %60 to i64
  %62 = mul i64 %61, 8
  %63 = call noundef ptr @_ZN2rw14mustmalloc_LOCEmjPKc(i64 noundef %62, i32 noundef 196615, ptr noundef @.str.18)
  store ptr %63, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #6
  store i32 0, ptr %9, align 4, !tbaa !15
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #6
  store i32 0, ptr %10, align 4, !tbaa !15
  br label %64

64:                                               ; preds = %113, %51
  %65 = load i32, ptr %10, align 4, !tbaa !15
  %66 = load ptr, ptr %3, align 8, !tbaa !5
  %67 = getelementptr inbounds %"struct.rw::MeshHeader", ptr %66, i32 0, i32 1
  %68 = load i16, ptr %67, align 4, !tbaa !16
  %69 = zext i16 %68 to i32
  %70 = icmp ult i32 %65, %69
  br i1 %70, label %72, label %71

71:                                               ; preds = %64
  store i32 5, ptr %6, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #6
  br label %116

72:                                               ; preds = %64
  %73 = load ptr, ptr %4, align 8, !tbaa !5
  %74 = load i32, ptr %10, align 4, !tbaa !15
  %75 = zext i32 %74 to i64
  %76 = getelementptr inbounds %"struct.rw::Mesh", ptr %73, i64 %75
  %77 = getelementptr inbounds %"struct.rw::Mesh", ptr %76, i32 0, i32 1
  %78 = load i32, ptr %77, align 8, !tbaa !23
  %79 = icmp ule i32 %78, 0
  br i1 %79, label %80, label %81

80:                                               ; preds = %72
  br label %113

81:                                               ; preds = %72
  %82 = load ptr, ptr %4, align 8, !tbaa !5
  %83 = load i32, ptr %10, align 4, !tbaa !15
  %84 = zext i32 %83 to i64
  %85 = getelementptr inbounds %"struct.rw::Mesh", ptr %82, i64 %84
  %86 = getelementptr inbounds %"struct.rw::Mesh", ptr %85, i32 0, i32 2
  %87 = load ptr, ptr %86, align 8, !tbaa !24
  %88 = load ptr, ptr %8, align 8, !tbaa !5
  %89 = load i32, ptr %9, align 4, !tbaa !15
  %90 = sext i32 %89 to i64
  %91 = getelementptr inbounds ptr, ptr %88, i64 %90
  store ptr %87, ptr %91, align 8, !tbaa !5
  %92 = load ptr, ptr %4, align 8, !tbaa !5
  %93 = load i32, ptr %10, align 4, !tbaa !15
  %94 = zext i32 %93 to i64
  %95 = getelementptr inbounds %"struct.rw::Mesh", ptr %92, i64 %94
  %96 = getelementptr inbounds %"struct.rw::Mesh", ptr %95, i32 0, i32 2
  %97 = load ptr, ptr %96, align 8, !tbaa !24
  call void @_ZN2rw8Material6addRefEv(ptr noundef nonnull align 8 dereferenceable(40) %97)
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #6
  %98 = getelementptr inbounds %"struct.rw::Geometry", ptr %18, i32 0, i32 11
  %99 = load ptr, ptr %4, align 8, !tbaa !5
  %100 = load i32, ptr %10, align 4, !tbaa !15
  %101 = zext i32 %100 to i64
  %102 = getelementptr inbounds %"struct.rw::Mesh", ptr %99, i64 %101
  %103 = getelementptr inbounds %"struct.rw::Mesh", ptr %102, i32 0, i32 2
  %104 = load ptr, ptr %103, align 8, !tbaa !24
  %105 = call noundef i32 @_ZN2rw12MaterialList9findIndexEPNS_8MaterialE(ptr noundef nonnull align 8 dereferenceable(16) %98, ptr noundef %104)
  store i32 %105, ptr %11, align 4, !tbaa !15
  %106 = load i32, ptr %9, align 4, !tbaa !15
  %107 = load ptr, ptr %7, align 8, !tbaa !5
  %108 = load i32, ptr %11, align 4, !tbaa !15
  %109 = sext i32 %108 to i64
  %110 = getelementptr inbounds i32, ptr %107, i64 %109
  store i32 %106, ptr %110, align 4, !tbaa !15
  %111 = load i32, ptr %9, align 4, !tbaa !15
  %112 = add nsw i32 %111, 1
  store i32 %112, ptr %9, align 4, !tbaa !15
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #6
  br label %113

113:                                              ; preds = %81, %80
  %114 = load i32, ptr %10, align 4, !tbaa !15
  %115 = add i32 %114, 1
  store i32 %115, ptr %10, align 4, !tbaa !15
  br label %64, !llvm.loop !25

116:                                              ; preds = %71
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #6
  store i32 0, ptr %12, align 4, !tbaa !15
  br label %117

117:                                              ; preds = %132, %116
  %118 = load i32, ptr %12, align 4, !tbaa !15
  %119 = getelementptr inbounds %"struct.rw::Geometry", ptr %18, i32 0, i32 11
  %120 = getelementptr inbounds %"struct.rw::MaterialList", ptr %119, i32 0, i32 1
  %121 = load i32, ptr %120, align 8, !tbaa !22
  %122 = icmp slt i32 %118, %121
  br i1 %122, label %124, label %123

123:                                              ; preds = %117
  store i32 8, ptr %6, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #6
  br label %135

124:                                              ; preds = %117
  %125 = getelementptr inbounds %"struct.rw::Geometry", ptr %18, i32 0, i32 11
  %126 = getelementptr inbounds %"struct.rw::MaterialList", ptr %125, i32 0, i32 0
  %127 = load ptr, ptr %126, align 8, !tbaa !26
  %128 = load i32, ptr %12, align 4, !tbaa !15
  %129 = sext i32 %128 to i64
  %130 = getelementptr inbounds ptr, ptr %127, i64 %129
  %131 = load ptr, ptr %130, align 8, !tbaa !5
  call void @_ZN2rw8Material7destroyEv(ptr noundef nonnull align 8 dereferenceable(40) %131)
  br label %132

132:                                              ; preds = %124
  %133 = load i32, ptr %12, align 4, !tbaa !15
  %134 = add nsw i32 %133, 1
  store i32 %134, ptr %12, align 4, !tbaa !15
  br label %117, !llvm.loop !27

135:                                              ; preds = %123
  %136 = load ptr, ptr getelementptr inbounds (%"struct.rw::MemoryFunctions", ptr @_ZN2rw6Engine8memfuncsE, i32 0, i32 2), align 8, !tbaa !28
  %137 = getelementptr inbounds %"struct.rw::Geometry", ptr %18, i32 0, i32 11
  %138 = getelementptr inbounds %"struct.rw::MaterialList", ptr %137, i32 0, i32 0
  %139 = load ptr, ptr %138, align 8, !tbaa !26
  call void %136(ptr noundef %139)
  %140 = load ptr, ptr %8, align 8, !tbaa !5
  %141 = getelementptr inbounds %"struct.rw::Geometry", ptr %18, i32 0, i32 11
  %142 = getelementptr inbounds %"struct.rw::MaterialList", ptr %141, i32 0, i32 0
  store ptr %140, ptr %142, align 8, !tbaa !26
  %143 = getelementptr inbounds %"struct.rw::Geometry", ptr %18, i32 0, i32 11
  %144 = getelementptr inbounds %"struct.rw::MaterialList", ptr %143, i32 0, i32 1
  %145 = load i32, ptr %144, align 8, !tbaa !22
  %146 = getelementptr inbounds %"struct.rw::Geometry", ptr %18, i32 0, i32 11
  %147 = getelementptr inbounds %"struct.rw::MaterialList", ptr %146, i32 0, i32 2
  store i32 %145, ptr %147, align 4, !tbaa !30
  %148 = load i32, ptr %9, align 4, !tbaa !15
  %149 = getelementptr inbounds %"struct.rw::Geometry", ptr %18, i32 0, i32 11
  %150 = getelementptr inbounds %"struct.rw::MaterialList", ptr %149, i32 0, i32 1
  store i32 %148, ptr %150, align 8, !tbaa !22
  %151 = getelementptr inbounds %"struct.rw::Geometry", ptr %18, i32 0, i32 12
  store ptr null, ptr %151, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #6
  %152 = load i32, ptr %9, align 4, !tbaa !15
  %153 = load ptr, ptr %3, align 8, !tbaa !5
  %154 = getelementptr inbounds %"struct.rw::MeshHeader", ptr %153, i32 0, i32 3
  %155 = load i32, ptr %154, align 4, !tbaa !31
  %156 = call noundef ptr @_ZN2rw8Geometry14allocateMeshesEiji(ptr noundef nonnull align 8 dereferenceable(168) %18, i32 noundef %152, i32 noundef %155, i32 noundef 0)
  store ptr %156, ptr %13, align 8, !tbaa !5
  %157 = load ptr, ptr %3, align 8, !tbaa !5
  %158 = getelementptr inbounds %"struct.rw::MeshHeader", ptr %157, i32 0, i32 0
  %159 = load i32, ptr %158, align 4, !tbaa !32
  %160 = load ptr, ptr %13, align 8, !tbaa !5
  %161 = getelementptr inbounds %"struct.rw::MeshHeader", ptr %160, i32 0, i32 0
  store i32 %159, ptr %161, align 4, !tbaa !32
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #6
  %162 = load ptr, ptr %13, align 8, !tbaa !5
  %163 = call noundef ptr @_ZN2rw10MeshHeader9getMeshesEv(ptr noundef nonnull align 4 dereferenceable(16) %162)
  store ptr %163, ptr %14, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #6
  store i32 0, ptr %15, align 4, !tbaa !15
  br label %164

164:                                              ; preds = %200, %135
  %165 = load i32, ptr %15, align 4, !tbaa !15
  %166 = load ptr, ptr %3, align 8, !tbaa !5
  %167 = getelementptr inbounds %"struct.rw::MeshHeader", ptr %166, i32 0, i32 1
  %168 = load i16, ptr %167, align 4, !tbaa !16
  %169 = zext i16 %168 to i32
  %170 = icmp ult i32 %165, %169
  br i1 %170, label %172, label %171

171:                                              ; preds = %164
  store i32 11, ptr %6, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #6
  br label %203

172:                                              ; preds = %164
  %173 = load ptr, ptr %4, align 8, !tbaa !5
  %174 = load i32, ptr %15, align 4, !tbaa !15
  %175 = zext i32 %174 to i64
  %176 = getelementptr inbounds %"struct.rw::Mesh", ptr %173, i64 %175
  %177 = getelementptr inbounds %"struct.rw::Mesh", ptr %176, i32 0, i32 1
  %178 = load i32, ptr %177, align 8, !tbaa !23
  %179 = icmp ule i32 %178, 0
  br i1 %179, label %180, label %181

180:                                              ; preds = %172
  br label %200

181:                                              ; preds = %172
  %182 = load ptr, ptr %4, align 8, !tbaa !5
  %183 = load i32, ptr %15, align 4, !tbaa !15
  %184 = zext i32 %183 to i64
  %185 = getelementptr inbounds %"struct.rw::Mesh", ptr %182, i64 %184
  %186 = getelementptr inbounds %"struct.rw::Mesh", ptr %185, i32 0, i32 1
  %187 = load i32, ptr %186, align 8, !tbaa !23
  %188 = load ptr, ptr %14, align 8, !tbaa !5
  %189 = getelementptr inbounds %"struct.rw::Mesh", ptr %188, i32 0, i32 1
  store i32 %187, ptr %189, align 8, !tbaa !23
  %190 = load ptr, ptr %4, align 8, !tbaa !5
  %191 = load i32, ptr %15, align 4, !tbaa !15
  %192 = zext i32 %191 to i64
  %193 = getelementptr inbounds %"struct.rw::Mesh", ptr %190, i64 %192
  %194 = getelementptr inbounds %"struct.rw::Mesh", ptr %193, i32 0, i32 2
  %195 = load ptr, ptr %194, align 8, !tbaa !24
  %196 = load ptr, ptr %14, align 8, !tbaa !5
  %197 = getelementptr inbounds %"struct.rw::Mesh", ptr %196, i32 0, i32 2
  store ptr %195, ptr %197, align 8, !tbaa !24
  %198 = load ptr, ptr %14, align 8, !tbaa !5
  %199 = getelementptr inbounds %"struct.rw::Mesh", ptr %198, i32 1
  store ptr %199, ptr %14, align 8, !tbaa !5
  br label %200

200:                                              ; preds = %181, %180
  %201 = load i32, ptr %15, align 4, !tbaa !15
  %202 = add i32 %201, 1
  store i32 %202, ptr %15, align 4, !tbaa !15
  br label %164, !llvm.loop !33

203:                                              ; preds = %171
  %204 = load ptr, ptr %13, align 8, !tbaa !5
  call void @_ZN2rw10MeshHeader12setupIndicesEv(ptr noundef nonnull align 4 dereferenceable(16) %204)
  %205 = load ptr, ptr %13, align 8, !tbaa !5
  %206 = call noundef ptr @_ZN2rw10MeshHeader9getMeshesEv(ptr noundef nonnull align 4 dereferenceable(16) %205)
  store ptr %206, ptr %14, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %16) #6
  store i32 0, ptr %16, align 4, !tbaa !15
  br label %207

207:                                              ; preds = %244, %203
  %208 = load i32, ptr %16, align 4, !tbaa !15
  %209 = load ptr, ptr %3, align 8, !tbaa !5
  %210 = getelementptr inbounds %"struct.rw::MeshHeader", ptr %209, i32 0, i32 1
  %211 = load i16, ptr %210, align 4, !tbaa !16
  %212 = zext i16 %211 to i32
  %213 = icmp ult i32 %208, %212
  br i1 %213, label %215, label %214

214:                                              ; preds = %207
  store i32 14, ptr %6, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %16) #6
  br label %247

215:                                              ; preds = %207
  %216 = load ptr, ptr %4, align 8, !tbaa !5
  %217 = load i32, ptr %16, align 4, !tbaa !15
  %218 = zext i32 %217 to i64
  %219 = getelementptr inbounds %"struct.rw::Mesh", ptr %216, i64 %218
  %220 = getelementptr inbounds %"struct.rw::Mesh", ptr %219, i32 0, i32 1
  %221 = load i32, ptr %220, align 8, !tbaa !23
  %222 = icmp ule i32 %221, 0
  br i1 %222, label %223, label %224

223:                                              ; preds = %215
  br label %244

224:                                              ; preds = %215
  %225 = load ptr, ptr %14, align 8, !tbaa !5
  %226 = getelementptr inbounds %"struct.rw::Mesh", ptr %225, i32 0, i32 0
  %227 = load ptr, ptr %226, align 8, !tbaa !18
  %228 = load ptr, ptr %4, align 8, !tbaa !5
  %229 = load i32, ptr %16, align 4, !tbaa !15
  %230 = zext i32 %229 to i64
  %231 = getelementptr inbounds %"struct.rw::Mesh", ptr %228, i64 %230
  %232 = getelementptr inbounds %"struct.rw::Mesh", ptr %231, i32 0, i32 0
  %233 = load ptr, ptr %232, align 8, !tbaa !18
  %234 = load ptr, ptr %4, align 8, !tbaa !5
  %235 = load i32, ptr %16, align 4, !tbaa !15
  %236 = zext i32 %235 to i64
  %237 = getelementptr inbounds %"struct.rw::Mesh", ptr %234, i64 %236
  %238 = getelementptr inbounds %"struct.rw::Mesh", ptr %237, i32 0, i32 1
  %239 = load i32, ptr %238, align 8, !tbaa !23
  %240 = zext i32 %239 to i64
  %241 = mul i64 %240, 2
  call void @llvm.memcpy.p0.p0.i64(ptr align 2 %227, ptr align 2 %233, i64 %241, i1 false)
  %242 = load ptr, ptr %14, align 8, !tbaa !5
  %243 = getelementptr inbounds %"struct.rw::Mesh", ptr %242, i32 1
  store ptr %243, ptr %14, align 8, !tbaa !5
  br label %244

244:                                              ; preds = %224, %223
  %245 = load i32, ptr %16, align 4, !tbaa !15
  %246 = add i32 %245, 1
  store i32 %246, ptr %16, align 4, !tbaa !15
  br label %207, !llvm.loop !34

247:                                              ; preds = %214
  %248 = load ptr, ptr getelementptr inbounds (%"struct.rw::MemoryFunctions", ptr @_ZN2rw6Engine8memfuncsE, i32 0, i32 2), align 8, !tbaa !28
  %249 = load ptr, ptr %3, align 8, !tbaa !5
  call void %248(ptr noundef %249)
  call void @llvm.lifetime.start.p0(i64 4, ptr %17) #6
  store i32 0, ptr %17, align 4, !tbaa !15
  br label %250

250:                                              ; preds = %275, %247
  %251 = load i32, ptr %17, align 4, !tbaa !15
  %252 = getelementptr inbounds %"struct.rw::Geometry", ptr %18, i32 0, i32 3
  %253 = load i32, ptr %252, align 8, !tbaa !35
  %254 = icmp slt i32 %251, %253
  br i1 %254, label %256, label %255

255:                                              ; preds = %250
  store i32 17, ptr %6, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %17) #6
  br label %278

256:                                              ; preds = %250
  %257 = load ptr, ptr %7, align 8, !tbaa !5
  %258 = getelementptr inbounds %"struct.rw::Geometry", ptr %18, i32 0, i32 7
  %259 = load ptr, ptr %258, align 8, !tbaa !36
  %260 = load i32, ptr %17, align 4, !tbaa !15
  %261 = sext i32 %260 to i64
  %262 = getelementptr inbounds %"struct.rw::Triangle", ptr %259, i64 %261
  %263 = getelementptr inbounds %"struct.rw::Triangle", ptr %262, i32 0, i32 1
  %264 = load i16, ptr %263, align 2, !tbaa !37
  %265 = zext i16 %264 to i64
  %266 = getelementptr inbounds i32, ptr %257, i64 %265
  %267 = load i32, ptr %266, align 4, !tbaa !15
  %268 = trunc i32 %267 to i16
  %269 = getelementptr inbounds %"struct.rw::Geometry", ptr %18, i32 0, i32 7
  %270 = load ptr, ptr %269, align 8, !tbaa !36
  %271 = load i32, ptr %17, align 4, !tbaa !15
  %272 = sext i32 %271 to i64
  %273 = getelementptr inbounds %"struct.rw::Triangle", ptr %270, i64 %272
  %274 = getelementptr inbounds %"struct.rw::Triangle", ptr %273, i32 0, i32 1
  store i16 %268, ptr %274, align 2, !tbaa !37
  br label %275

275:                                              ; preds = %256
  %276 = load i32, ptr %17, align 4, !tbaa !15
  %277 = add nsw i32 %276, 1
  store i32 %277, ptr %17, align 4, !tbaa !15
  br label %250, !llvm.loop !39

278:                                              ; preds = %255
  %279 = load ptr, ptr getelementptr inbounds (%"struct.rw::MemoryFunctions", ptr @_ZN2rw6Engine8memfuncsE, i32 0, i32 2), align 8, !tbaa !28
  %280 = load ptr, ptr %7, align 8, !tbaa !5
  call void %279(ptr noundef %280)
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #6
  store i32 0, ptr %6, align 4
  br label %281

281:                                              ; preds = %278, %49
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #6
  %282 = load i32, ptr %6, align 4
  switch i32 %282, label %284 [
    i32 0, label %283
    i32 1, label %283
  ]

283:                                              ; preds = %281, %281, %22
  ret void

284:                                              ; preds = %281
  unreachable
}

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN2rw8Material7destroyEv(ptr noundef nonnull align 8 dereferenceable(40)) #5 align 2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { inlinehint 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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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 #4 = { "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 = { 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 #6 = { 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 144}
!10 = !{!"_ZTSN2rw8GeometryE", !11, i64 0, !12, i64 16, !13, i64 20, !12, i64 24, !12, i64 28, !12, i64 32, !12, i64 36, !6, i64 40, !6, i64 48, !7, i64 56, !6, i64 120, !14, i64 128, !6, i64 144, !6, i64 152, !12, i64 160}
!11 = !{!"_ZTSN2rw6ObjectE", !7, i64 0, !7, i64 1, !7, i64 2, !7, i64 3, !6, i64 8}
!12 = !{!"int", !7, i64 0}
!13 = !{!"short", !7, i64 0}
!14 = !{!"_ZTSN2rw12MaterialListE", !6, i64 0, !12, i64 8, !12, i64 12}
!15 = !{!12, !12, i64 0}
!16 = !{!17, !13, i64 4}
!17 = !{!"_ZTSN2rw10MeshHeaderE", !12, i64 0, !13, i64 4, !13, i64 6, !12, i64 8, !12, i64 12}
!18 = !{!19, !6, i64 0}
!19 = !{!"_ZTSN2rw4MeshE", !6, i64 0, !12, i64 8, !6, i64 16}
!20 = distinct !{!20, !21}
!21 = !{!"llvm.loop.mustprogress"}
!22 = !{!10, !12, i64 136}
!23 = !{!19, !12, i64 8}
!24 = !{!19, !6, i64 16}
!25 = distinct !{!25, !21}
!26 = !{!10, !6, i64 128}
!27 = distinct !{!27, !21}
!28 = !{!29, !6, i64 16}
!29 = !{!"_ZTSN2rw15MemoryFunctionsE", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32}
!30 = !{!10, !12, i64 140}
!31 = !{!17, !12, i64 8}
!32 = !{!17, !12, i64 0}
!33 = distinct !{!33, !21}
!34 = distinct !{!34, !21}
!35 = !{!10, !12, i64 24}
!36 = !{!10, !6, i64 40}
!37 = !{!38, !13, i64 6}
!38 = !{!"_ZTSN2rw8TriangleE", !7, i64 0, !13, i64 6}
!39 = distinct !{!39, !21}


; 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::MemoryFunctions" = type { ptr, ptr, ptr, ptr, ptr }
%"struct.rw::Mesh" = type { ptr, i32, ptr }
%"struct.rw::Triangle" = type { [3 x i16], i16 }

@_ZN2rw6Engine8memfuncsE = external local_unnamed_addr global %"struct.rw::MemoryFunctions", align 8
@.str.17 = external hidden unnamed_addr constant [76 x i8], align 1
@.str.18 = external hidden unnamed_addr constant [76 x i8], align 1

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef ptr @_ZN2rw14mustmalloc_LOCEmjPKc(i64 noundef, i32 noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZN2rw10MeshHeader9getMeshesEv(ptr noundef nonnull align 4 dereferenceable(16)) local_unnamed_addr #2 align 2

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

declare noundef ptr @_ZN2rw8Geometry14allocateMeshesEiji(ptr noundef nonnull align 8 dereferenceable(168), i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #3

declare void @_ZN2rw10MeshHeader12setupIndicesEv(ptr noundef nonnull align 4 dereferenceable(16)) local_unnamed_addr #3

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN2rw8Geometry21removeUnusedMaterialsEv(ptr noundef nonnull align 8 dereferenceable(168) %0) local_unnamed_addr #4 align 2 {
  %2 = getelementptr inbounds i8, ptr %0, i64 144
  %3 = load ptr, ptr %2, align 8, !tbaa !5
  %4 = icmp eq ptr %3, null
  br i1 %4, label %.loopexit, label %5

5:                                                ; preds = %1
  %6 = tail call noundef ptr @_ZN2rw10MeshHeader9getMeshesEv(ptr noundef nonnull align 4 dereferenceable(16) %3)
  %7 = getelementptr inbounds i8, ptr %3, i64 4
  %8 = load i16, ptr %7, align 4, !tbaa !14
  %.not79.not = icmp eq i16 %8, 0
  br i1 %.not79.not, label %.critedge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %5
  %wide.trip.count = zext i16 %8 to i64
  br label %.lr.ph

9:                                                ; preds = %.lr.ph
  %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 %.critedge, label %.lr.ph, !llvm.loop !16

.lr.ph:                                           ; preds = %.lr.ph.preheader, %9
  %indvars.iv = phi i64 [ 0, %.lr.ph.preheader ], [ %indvars.iv.next, %9 ]
  %10 = getelementptr inbounds %"struct.rw::Mesh", ptr %6, i64 %indvars.iv
  %11 = load ptr, ptr %10, align 8, !tbaa !18
  %12 = icmp eq ptr %11, null
  br i1 %12, label %.loopexit, label %9

.critedge:                                        ; preds = %9, %5
  %13 = getelementptr inbounds i8, ptr %0, i64 128
  %14 = getelementptr inbounds i8, ptr %0, i64 136
  %15 = load i32, ptr %14, align 8, !tbaa !20
  %16 = sext i32 %15 to i64
  %17 = shl nsw i64 %16, 2
  %18 = tail call noundef ptr @_ZN2rw14mustmalloc_LOCEmjPKc(i64 noundef %17, i32 noundef 65551, ptr noundef nonnull @.str.17)
  %19 = load i32, ptr %14, align 8, !tbaa !20
  %20 = sext i32 %19 to i64
  %21 = shl nsw i64 %20, 3
  %22 = tail call noundef ptr @_ZN2rw14mustmalloc_LOCEmjPKc(i64 noundef %21, i32 noundef 196615, ptr noundef nonnull @.str.18)
  %23 = load i16, ptr %7, align 4, !tbaa !14
  %.not100 = icmp eq i16 %23, 0
  br i1 %.not100, label %.preheader, label %.lr.ph83

.preheader:                                       ; preds = %41, %.critedge
  %.073.lcssa = phi i32 [ 0, %.critedge ], [ %.174, %41 ]
  %24 = load i32, ptr %14, align 8, !tbaa !20
  %25 = icmp sgt i32 %24, 0
  br i1 %25, label %.lr.ph85, label %._crit_edge

.lr.ph83:                                         ; preds = %.critedge, %41
  %26 = phi i16 [ %42, %41 ], [ %23, %.critedge ]
  %indvars.iv104 = phi i64 [ %indvars.iv.next105, %41 ], [ 0, %.critedge ]
  %.07381 = phi i32 [ %.174, %41 ], [ 0, %.critedge ]
  %27 = getelementptr inbounds %"struct.rw::Mesh", ptr %6, i64 %indvars.iv104
  %28 = getelementptr inbounds i8, ptr %27, i64 8
  %29 = load i32, ptr %28, align 8, !tbaa !21
  %30 = icmp eq i32 %29, 0
  br i1 %30, label %41, label %31

31:                                               ; preds = %.lr.ph83
  %32 = getelementptr inbounds i8, ptr %27, i64 16
  %33 = load ptr, ptr %32, align 8, !tbaa !22
  %34 = sext i32 %.07381 to i64
  %35 = getelementptr inbounds ptr, ptr %22, i64 %34
  store ptr %33, ptr %35, align 8, !tbaa !23
  tail call void @_ZN2rw8Material6addRefEv(ptr noundef nonnull align 8 dereferenceable(40) %33)
  %36 = load ptr, ptr %32, align 8, !tbaa !22
  %37 = tail call noundef i32 @_ZN2rw12MaterialList9findIndexEPNS_8MaterialE(ptr noundef nonnull align 8 dereferenceable(16) %13, ptr noundef %36)
  %38 = sext i32 %37 to i64
  %39 = getelementptr inbounds i32, ptr %18, i64 %38
  store i32 %.07381, ptr %39, align 4, !tbaa !24
  %40 = add nsw i32 %.07381, 1
  %.pre = load i16, ptr %7, align 4, !tbaa !14
  br label %41

41:                                               ; preds = %.lr.ph83, %31
  %42 = phi i16 [ %26, %.lr.ph83 ], [ %.pre, %31 ]
  %.174 = phi i32 [ %.07381, %.lr.ph83 ], [ %40, %31 ]
  %indvars.iv.next105 = add nuw nsw i64 %indvars.iv104, 1
  %43 = zext i16 %42 to i64
  %44 = icmp ult i64 %indvars.iv.next105, %43
  br i1 %44, label %.lr.ph83, label %.preheader, !llvm.loop !25

._crit_edge:                                      ; preds = %.lr.ph85, %.preheader
  %45 = load ptr, ptr getelementptr inbounds (i8, ptr @_ZN2rw6Engine8memfuncsE, i64 16), align 8, !tbaa !26
  %46 = load ptr, ptr %13, align 8, !tbaa !28
  tail call void %45(ptr noundef %46)
  store ptr %22, ptr %13, align 8, !tbaa !28
  %47 = load i32, ptr %14, align 8, !tbaa !20
  %48 = getelementptr inbounds i8, ptr %0, i64 140
  store i32 %47, ptr %48, align 4, !tbaa !29
  store i32 %.073.lcssa, ptr %14, align 8, !tbaa !20
  store ptr null, ptr %2, align 8, !tbaa !5
  %49 = getelementptr inbounds i8, ptr %3, i64 8
  %50 = load i32, ptr %49, align 4, !tbaa !30
  %51 = tail call noundef ptr @_ZN2rw8Geometry14allocateMeshesEiji(ptr noundef nonnull align 8 dereferenceable(168) %0, i32 noundef %.073.lcssa, i32 noundef %50, i32 noundef 0)
  %52 = load i32, ptr %3, align 4, !tbaa !31
  store i32 %52, ptr %51, align 4, !tbaa !31
  %53 = tail call noundef ptr @_ZN2rw10MeshHeader9getMeshesEv(ptr noundef nonnull align 4 dereferenceable(16) %51)
  %54 = load i16, ptr %7, align 4, !tbaa !14
  %.not101 = icmp eq i16 %54, 0
  br i1 %.not101, label %._crit_edge90, label %.lr.ph89.preheader

.lr.ph89.preheader:                               ; preds = %._crit_edge
  %wide.trip.count113 = zext i16 %54 to i64
  %xtraiter = and i64 %wide.trip.count113, 1
  %55 = icmp eq i16 %54, 1
  br i1 %55, label %._crit_edge90.loopexit.unr-lcssa, label %.lr.ph89.preheader.new

.lr.ph89.preheader.new:                           ; preds = %.lr.ph89.preheader
  %unroll_iter = and i64 %wide.trip.count113, 65534
  br label %.lr.ph89

.lr.ph85:                                         ; preds = %.preheader, %.lr.ph85
  %indvars.iv107 = phi i64 [ %indvars.iv.next108, %.lr.ph85 ], [ 0, %.preheader ]
  %56 = load ptr, ptr %13, align 8, !tbaa !28
  %57 = getelementptr inbounds ptr, ptr %56, i64 %indvars.iv107
  %58 = load ptr, ptr %57, align 8, !tbaa !23
  tail call void @_ZN2rw8Material7destroyEv(ptr noundef nonnull align 8 dereferenceable(40) %58)
  %indvars.iv.next108 = add nuw nsw i64 %indvars.iv107, 1
  %59 = load i32, ptr %14, align 8, !tbaa !20
  %60 = sext i32 %59 to i64
  %61 = icmp slt i64 %indvars.iv.next108, %60
  br i1 %61, label %.lr.ph85, label %._crit_edge, !llvm.loop !32

._crit_edge90.loopexit.unr-lcssa:                 ; preds = %93, %.lr.ph89.preheader
  %indvars.iv110.unr = phi i64 [ 0, %.lr.ph89.preheader ], [ %indvars.iv.next111.1, %93 ]
  %.06886.unr = phi ptr [ %53, %.lr.ph89.preheader ], [ %.1.1, %93 ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge90, label %.lr.ph89.epil

.lr.ph89.epil:                                    ; preds = %._crit_edge90.loopexit.unr-lcssa
  %62 = getelementptr inbounds %"struct.rw::Mesh", ptr %6, i64 %indvars.iv110.unr
  %63 = getelementptr inbounds i8, ptr %62, i64 8
  %64 = load i32, ptr %63, align 8, !tbaa !21
  %65 = icmp eq i32 %64, 0
  br i1 %65, label %._crit_edge90, label %66

66:                                               ; preds = %.lr.ph89.epil
  %67 = getelementptr inbounds i8, ptr %.06886.unr, i64 8
  store i32 %64, ptr %67, align 8, !tbaa !21
  %68 = getelementptr inbounds i8, ptr %62, i64 16
  %69 = load ptr, ptr %68, align 8, !tbaa !22
  %70 = getelementptr inbounds i8, ptr %.06886.unr, i64 16
  store ptr %69, ptr %70, align 8, !tbaa !22
  br label %._crit_edge90

._crit_edge90:                                    ; preds = %._crit_edge90.loopexit.unr-lcssa, %66, %.lr.ph89.epil, %._crit_edge
  tail call void @_ZN2rw10MeshHeader12setupIndicesEv(ptr noundef nonnull align 4 dereferenceable(16) %51)
  %71 = tail call noundef ptr @_ZN2rw10MeshHeader9getMeshesEv(ptr noundef nonnull align 4 dereferenceable(16) %51)
  %72 = load i16, ptr %7, align 4, !tbaa !14
  %.not102 = icmp eq i16 %72, 0
  br i1 %.not102, label %._crit_edge95, label %.lr.ph94

.lr.ph89:                                         ; preds = %93, %.lr.ph89.preheader.new
  %indvars.iv110 = phi i64 [ 0, %.lr.ph89.preheader.new ], [ %indvars.iv.next111.1, %93 ]
  %.06886 = phi ptr [ %53, %.lr.ph89.preheader.new ], [ %.1.1, %93 ]
  %niter = phi i64 [ 0, %.lr.ph89.preheader.new ], [ %niter.next.1, %93 ]
  %73 = getelementptr inbounds %"struct.rw::Mesh", ptr %6, i64 %indvars.iv110
  %74 = getelementptr inbounds i8, ptr %73, i64 8
  %75 = load i32, ptr %74, align 8, !tbaa !21
  %76 = icmp eq i32 %75, 0
  br i1 %76, label %.lr.ph89.1, label %77

77:                                               ; preds = %.lr.ph89
  %78 = getelementptr inbounds i8, ptr %.06886, i64 8
  store i32 %75, ptr %78, align 8, !tbaa !21
  %79 = getelementptr inbounds i8, ptr %73, i64 16
  %80 = load ptr, ptr %79, align 8, !tbaa !22
  %81 = getelementptr inbounds i8, ptr %.06886, i64 16
  store ptr %80, ptr %81, align 8, !tbaa !22
  %82 = getelementptr inbounds i8, ptr %.06886, i64 24
  br label %.lr.ph89.1

.lr.ph89.1:                                       ; preds = %.lr.ph89, %77
  %.1 = phi ptr [ %.06886, %.lr.ph89 ], [ %82, %77 ]
  %indvars.iv.next111 = or disjoint i64 %indvars.iv110, 1
  %83 = getelementptr inbounds %"struct.rw::Mesh", ptr %6, i64 %indvars.iv.next111
  %84 = getelementptr inbounds i8, ptr %83, i64 8
  %85 = load i32, ptr %84, align 8, !tbaa !21
  %86 = icmp eq i32 %85, 0
  br i1 %86, label %93, label %87

87:                                               ; preds = %.lr.ph89.1
  %88 = getelementptr inbounds i8, ptr %.1, i64 8
  store i32 %85, ptr %88, align 8, !tbaa !21
  %89 = getelementptr inbounds i8, ptr %83, i64 16
  %90 = load ptr, ptr %89, align 8, !tbaa !22
  %91 = getelementptr inbounds i8, ptr %.1, i64 16
  store ptr %90, ptr %91, align 8, !tbaa !22
  %92 = getelementptr inbounds i8, ptr %.1, i64 24
  br label %93

93:                                               ; preds = %87, %.lr.ph89.1
  %.1.1 = phi ptr [ %.1, %.lr.ph89.1 ], [ %92, %87 ]
  %indvars.iv.next111.1 = add nuw nsw i64 %indvars.iv110, 2
  %niter.next.1 = add i64 %niter, 2
  %niter.ncmp.1 = icmp eq i64 %niter.next.1, %unroll_iter
  br i1 %niter.ncmp.1, label %._crit_edge90.loopexit.unr-lcssa, label %.lr.ph89, !llvm.loop !33

._crit_edge95:                                    ; preds = %112, %._crit_edge90
  %94 = load ptr, ptr getelementptr inbounds (i8, ptr @_ZN2rw6Engine8memfuncsE, i64 16), align 8, !tbaa !26
  tail call void %94(ptr noundef nonnull %3)
  %95 = getelementptr inbounds i8, ptr %0, i64 24
  %96 = load i32, ptr %95, align 8, !tbaa !34
  %97 = icmp sgt i32 %96, 0
  br i1 %97, label %.lr.ph98, label %._crit_edge99

.lr.ph98:                                         ; preds = %._crit_edge95
  %98 = getelementptr inbounds i8, ptr %0, i64 40
  %99 = load ptr, ptr %98, align 8, !tbaa !35
  %wide.trip.count121 = zext nneg i32 %96 to i64
  %xtraiter124 = and i64 %wide.trip.count121, 3
  %100 = icmp ult i32 %96, 4
  br i1 %100, label %._crit_edge99.loopexit.unr-lcssa, label %.lr.ph98.new

.lr.ph98.new:                                     ; preds = %.lr.ph98
  %unroll_iter126 = and i64 %wide.trip.count121, 2147483644
  br label %123

.lr.ph94:                                         ; preds = %._crit_edge90, %112
  %101 = phi i16 [ %113, %112 ], [ %72, %._crit_edge90 ]
  %indvars.iv115 = phi i64 [ %indvars.iv.next116, %112 ], [ 0, %._crit_edge90 ]
  %.291 = phi ptr [ %.3, %112 ], [ %71, %._crit_edge90 ]
  %102 = getelementptr inbounds %"struct.rw::Mesh", ptr %6, i64 %indvars.iv115
  %103 = getelementptr inbounds i8, ptr %102, i64 8
  %104 = load i32, ptr %103, align 8, !tbaa !21
  %105 = icmp eq i32 %104, 0
  br i1 %105, label %112, label %106

106:                                              ; preds = %.lr.ph94
  %107 = load ptr, ptr %.291, align 8, !tbaa !18
  %108 = load ptr, ptr %102, align 8, !tbaa !18
  %109 = zext i32 %104 to i64
  %110 = shl nuw nsw i64 %109, 1
  tail call void @llvm.memcpy.p0.p0.i64(ptr align 2 %107, ptr align 2 %108, i64 %110, i1 false)
  %111 = getelementptr inbounds i8, ptr %.291, i64 24
  %.pre123 = load i16, ptr %7, align 4, !tbaa !14
  br label %112

112:                                              ; preds = %.lr.ph94, %106
  %113 = phi i16 [ %101, %.lr.ph94 ], [ %.pre123, %106 ]
  %.3 = phi ptr [ %.291, %.lr.ph94 ], [ %111, %106 ]
  %indvars.iv.next116 = add nuw nsw i64 %indvars.iv115, 1
  %114 = zext i16 %113 to i64
  %115 = icmp ult i64 %indvars.iv.next116, %114
  br i1 %115, label %.lr.ph94, label %._crit_edge95, !llvm.loop !36

._crit_edge99.loopexit.unr-lcssa:                 ; preds = %123, %.lr.ph98
  %indvars.iv118.unr = phi i64 [ 0, %.lr.ph98 ], [ %indvars.iv.next119.3, %123 ]
  %lcmp.mod125.not = icmp eq i64 %xtraiter124, 0
  br i1 %lcmp.mod125.not, label %._crit_edge99, label %.epil.preheader

.epil.preheader:                                  ; preds = %._crit_edge99.loopexit.unr-lcssa, %.epil.preheader
  %indvars.iv118.epil = phi i64 [ %indvars.iv.next119.epil, %.epil.preheader ], [ %indvars.iv118.unr, %._crit_edge99.loopexit.unr-lcssa ]
  %epil.iter = phi i64 [ %epil.iter.next, %.epil.preheader ], [ 0, %._crit_edge99.loopexit.unr-lcssa ]
  %116 = getelementptr inbounds %"struct.rw::Triangle", ptr %99, i64 %indvars.iv118.epil, i32 1
  %117 = load i16, ptr %116, align 2, !tbaa !37
  %118 = zext i16 %117 to i64
  %119 = getelementptr inbounds i32, ptr %18, i64 %118
  %120 = load i32, ptr %119, align 4, !tbaa !24
  %121 = trunc i32 %120 to i16
  store i16 %121, ptr %116, align 2, !tbaa !37
  %indvars.iv.next119.epil = add nuw nsw i64 %indvars.iv118.epil, 1
  %epil.iter.next = add i64 %epil.iter, 1
  %epil.iter.cmp.not = icmp eq i64 %epil.iter.next, %xtraiter124
  br i1 %epil.iter.cmp.not, label %._crit_edge99, label %.epil.preheader, !llvm.loop !39

._crit_edge99:                                    ; preds = %._crit_edge99.loopexit.unr-lcssa, %.epil.preheader, %._crit_edge95
  %122 = load ptr, ptr getelementptr inbounds (i8, ptr @_ZN2rw6Engine8memfuncsE, i64 16), align 8, !tbaa !26
  tail call void %122(ptr noundef %18)
  br label %.loopexit

123:                                              ; preds = %123, %.lr.ph98.new
  %indvars.iv118 = phi i64 [ 0, %.lr.ph98.new ], [ %indvars.iv.next119.3, %123 ]
  %niter127 = phi i64 [ 0, %.lr.ph98.new ], [ %niter127.next.3, %123 ]
  %124 = getelementptr inbounds %"struct.rw::Triangle", ptr %99, i64 %indvars.iv118, i32 1
  %125 = load i16, ptr %124, align 2, !tbaa !37
  %126 = zext i16 %125 to i64
  %127 = getelementptr inbounds i32, ptr %18, i64 %126
  %128 = load i32, ptr %127, align 4, !tbaa !24
  %129 = trunc i32 %128 to i16
  store i16 %129, ptr %124, align 2, !tbaa !37
  %indvars.iv.next119 = or disjoint i64 %indvars.iv118, 1
  %130 = getelementptr inbounds %"struct.rw::Triangle", ptr %99, i64 %indvars.iv.next119, i32 1
  %131 = load i16, ptr %130, align 2, !tbaa !37
  %132 = zext i16 %131 to i64
  %133 = getelementptr inbounds i32, ptr %18, i64 %132
  %134 = load i32, ptr %133, align 4, !tbaa !24
  %135 = trunc i32 %134 to i16
  store i16 %135, ptr %130, align 2, !tbaa !37
  %indvars.iv.next119.1 = or disjoint i64 %indvars.iv118, 2
  %136 = getelementptr inbounds %"struct.rw::Triangle", ptr %99, i64 %indvars.iv.next119.1, i32 1
  %137 = load i16, ptr %136, align 2, !tbaa !37
  %138 = zext i16 %137 to i64
  %139 = getelementptr inbounds i32, ptr %18, i64 %138
  %140 = load i32, ptr %139, align 4, !tbaa !24
  %141 = trunc i32 %140 to i16
  store i16 %141, ptr %136, align 2, !tbaa !37
  %indvars.iv.next119.2 = or disjoint i64 %indvars.iv118, 3
  %142 = getelementptr inbounds %"struct.rw::Triangle", ptr %99, i64 %indvars.iv.next119.2, i32 1
  %143 = load i16, ptr %142, align 2, !tbaa !37
  %144 = zext i16 %143 to i64
  %145 = getelementptr inbounds i32, ptr %18, i64 %144
  %146 = load i32, ptr %145, align 4, !tbaa !24
  %147 = trunc i32 %146 to i16
  store i16 %147, ptr %142, align 2, !tbaa !37
  %indvars.iv.next119.3 = add nuw nsw i64 %indvars.iv118, 4
  %niter127.next.3 = add i64 %niter127, 4
  %niter127.ncmp.3 = icmp eq i64 %niter127.next.3, %unroll_iter126
  br i1 %niter127.ncmp.3, label %._crit_edge99.loopexit.unr-lcssa, label %123, !llvm.loop !41

.loopexit:                                        ; preds = %.lr.ph, %._crit_edge99, %1
  ret void
}

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN2rw8Material7destroyEv(ptr noundef nonnull align 8 dereferenceable(40)) local_unnamed_addr #4 align 2

attributes #0 = { inlinehint 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 nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 = { "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 = { 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 144}
!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, !12, i64 4}
!15 = !{!"_ZTSN2rw10MeshHeaderE", !11, i64 0, !12, i64 4, !12, i64 6, !11, i64 8, !11, i64 12}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}
!18 = !{!19, !10, i64 0}
!19 = !{!"_ZTSN2rw4MeshE", !10, i64 0, !11, i64 8, !10, i64 16}
!20 = !{!6, !11, i64 136}
!21 = !{!19, !11, i64 8}
!22 = !{!19, !10, i64 16}
!23 = !{!10, !10, i64 0}
!24 = !{!11, !11, i64 0}
!25 = distinct !{!25, !17}
!26 = !{!27, !10, i64 16}
!27 = !{!"_ZTSN2rw15MemoryFunctionsE", !10, i64 0, !10, i64 8, !10, i64 16, !10, i64 24, !10, i64 32}
!28 = !{!6, !10, i64 128}
!29 = !{!6, !11, i64 140}
!30 = !{!15, !11, i64 8}
!31 = !{!15, !11, i64 0}
!32 = distinct !{!32, !17}
!33 = distinct !{!33, !17}
!34 = !{!6, !11, i64 24}
!35 = !{!6, !10, i64 40}
!36 = distinct !{!36, !17}
!37 = !{!38, !12, i64 6}
!38 = !{!"_ZTSN2rw8TriangleE", !8, i64 0, !12, i64 6}
!39 = distinct !{!39, !40}
!40 = !{!"llvm.loop.unroll.disable"}
!41 = distinct !{!41, !17}


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