; LLVM IR from aap/librw :: src/d3d/d3d8.ll (ZN2rw4d3d815writeNativeDataEPNS_6StreamEiPvii)

; 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::InstanceDataHeader" = type { i32 }
%"struct.rw::MeshHeader" = type { i32, i16, i16, i32, i32 }
%"struct.rw::d3d8::InstanceDataHeader" = type { %"struct.rw::InstanceDataHeader", i16, i16, ptr }
%"struct.rw::d3d8::InstanceData" = type { i32, i32, i32, i32, ptr, i32, i32, ptr, ptr, i32, i8, i8, i8 }

@_ZN2rw6Engine8memfuncsE = external global %"struct.rw::MemoryFunctions", align 8
@.str.9 = 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

declare noundef ptr @_ZN2rw3d3d11lockIndicesEPvjjj(ptr noundef, i32 noundef, i32 noundef, i32 noundef) #2

declare void @_ZN2rw3d3d13unlockIndicesEPv(ptr noundef) #2

declare noundef ptr @_ZN2rw3d3d12lockVerticesEPvjjj(ptr noundef, i32 noundef, i32 noundef, i32 noundef) #2

declare void @_ZN2rw3d3d14unlockVerticesEPv(ptr noundef) #2

; Function Attrs: mustprogress uwtable
define dso_local noundef ptr @_ZN2rw4d3d815writeNativeDataEPNS_6StreamEiPvii(ptr noundef %0, i32 noundef %1, ptr noundef %2, i32 noundef %3, i32 noundef %4) #3 {
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca ptr, align 8
  %13 = alloca i32, align 4
  %14 = alloca ptr, align 8
  %15 = alloca i32, align 4
  %16 = alloca ptr, align 8
  %17 = alloca ptr, align 8
  %18 = alloca ptr, align 8
  %19 = alloca i32, align 4
  %20 = alloca i32, align 4
  %21 = alloca i32, align 4
  %22 = alloca ptr, align 8
  %23 = alloca ptr, align 8
  store ptr %0, ptr %7, align 8, !tbaa !5
  store i32 %1, ptr %8, align 4, !tbaa !9
  store ptr %2, ptr %9, align 8, !tbaa !5
  store i32 %3, ptr %10, align 4, !tbaa !9
  store i32 %4, ptr %11, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #4
  %24 = load ptr, ptr %9, align 8, !tbaa !5
  store ptr %24, ptr %12, align 8, !tbaa !5
  %25 = load ptr, ptr %7, align 8, !tbaa !5
  %26 = load i32, ptr %8, align 4, !tbaa !9
  %27 = sub nsw i32 %26, 12
  %28 = call noundef zeroext i1 @_ZN2rw16writeChunkHeaderEPNS_6StreamEii(ptr noundef %25, i32 noundef 1, i32 noundef %27)
  %29 = load ptr, ptr %12, align 8, !tbaa !5
  %30 = getelementptr inbounds %"struct.rw::Geometry", ptr %29, i32 0, i32 13
  %31 = load ptr, ptr %30, align 8, !tbaa !11
  %32 = icmp eq ptr %31, null
  br i1 %32, label %40, label %33

33:                                               ; preds = %5
  %34 = load ptr, ptr %12, align 8, !tbaa !5
  %35 = getelementptr inbounds %"struct.rw::Geometry", ptr %34, i32 0, i32 13
  %36 = load ptr, ptr %35, align 8, !tbaa !11
  %37 = getelementptr inbounds %"struct.rw::InstanceDataHeader", ptr %36, i32 0, i32 0
  %38 = load i32, ptr %37, align 4, !tbaa !16
  %39 = icmp ne i32 %38, 8
  br i1 %39, label %40, label %42

40:                                               ; preds = %33, %5
  %41 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr %41, ptr %6, align 8
  store i32 1, ptr %13, align 4
  br label %232

42:                                               ; preds = %33
  %43 = load ptr, ptr %7, align 8, !tbaa !5
  %44 = call noundef i32 @_ZN2rw6Stream8writeU32Ej(ptr noundef nonnull align 8 dereferenceable(8) %43, i32 noundef 8)
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #4
  %45 = load ptr, ptr %12, align 8, !tbaa !5
  %46 = getelementptr inbounds %"struct.rw::Geometry", ptr %45, i32 0, i32 13
  %47 = load ptr, ptr %46, align 8, !tbaa !11
  store ptr %47, ptr %14, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #4
  %48 = load ptr, ptr %12, align 8, !tbaa !5
  %49 = getelementptr inbounds %"struct.rw::Geometry", ptr %48, i32 0, i32 12
  %50 = load ptr, ptr %49, align 8, !tbaa !18
  %51 = getelementptr inbounds %"struct.rw::MeshHeader", ptr %50, i32 0, i32 1
  %52 = load i16, ptr %51, align 4, !tbaa !19
  %53 = zext i16 %52 to i32
  %54 = mul nsw i32 %53, 44
  %55 = add nsw i32 4, %54
  store i32 %55, ptr %15, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #4
  %56 = load i32, ptr %15, align 4, !tbaa !9
  %57 = sext i32 %56 to i64
  %58 = mul i64 %57, 1
  %59 = call noundef ptr @_ZN2rw14mustmalloc_LOCEmjPKc(i64 noundef %58, i32 noundef 65551, ptr noundef @.str.9)
  store ptr %59, ptr %16, align 8, !tbaa !5
  %60 = load ptr, ptr %7, align 8, !tbaa !5
  %61 = load i32, ptr %15, align 4, !tbaa !9
  %62 = call noundef i32 @_ZN2rw6Stream8writeI32Ei(ptr noundef nonnull align 8 dereferenceable(8) %60, i32 noundef %61)
  call void @llvm.lifetime.start.p0(i64 8, ptr %17) #4
  %63 = load ptr, ptr %16, align 8, !tbaa !5
  store ptr %63, ptr %17, align 8, !tbaa !5
  %64 = load ptr, ptr %14, align 8, !tbaa !5
  %65 = getelementptr inbounds %"struct.rw::d3d8::InstanceDataHeader", ptr %64, i32 0, i32 1
  %66 = load i16, ptr %65, align 4, !tbaa !21
  %67 = load ptr, ptr %17, align 8, !tbaa !5
  store i16 %66, ptr %67, align 2, !tbaa !23
  %68 = load ptr, ptr %17, align 8, !tbaa !5
  %69 = getelementptr inbounds i8, ptr %68, i64 2
  store ptr %69, ptr %17, align 8, !tbaa !5
  %70 = load ptr, ptr %14, align 8, !tbaa !5
  %71 = getelementptr inbounds %"struct.rw::d3d8::InstanceDataHeader", ptr %70, i32 0, i32 2
  %72 = load i16, ptr %71, align 2, !tbaa !24
  %73 = load ptr, ptr %17, align 8, !tbaa !5
  store i16 %72, ptr %73, align 2, !tbaa !23
  %74 = load ptr, ptr %17, align 8, !tbaa !5
  %75 = getelementptr inbounds i8, ptr %74, i64 2
  store ptr %75, ptr %17, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %18) #4
  %76 = load ptr, ptr %14, align 8, !tbaa !5
  %77 = getelementptr inbounds %"struct.rw::d3d8::InstanceDataHeader", ptr %76, i32 0, i32 3
  %78 = load ptr, ptr %77, align 8, !tbaa !25
  store ptr %78, ptr %18, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %19) #4
  store i32 0, ptr %19, align 4, !tbaa !9
  br label %79

79:                                               ; preds = %163, %42
  %80 = load i32, ptr %19, align 4, !tbaa !9
  %81 = load ptr, ptr %14, align 8, !tbaa !5
  %82 = getelementptr inbounds %"struct.rw::d3d8::InstanceDataHeader", ptr %81, i32 0, i32 2
  %83 = load i16, ptr %82, align 2, !tbaa !24
  %84 = zext i16 %83 to i32
  %85 = icmp ult i32 %80, %84
  br i1 %85, label %87, label %86

86:                                               ; preds = %79
  store i32 2, ptr %13, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %19) #4
  br label %166

87:                                               ; preds = %79
  %88 = load ptr, ptr %18, align 8, !tbaa !5
  %89 = getelementptr inbounds %"struct.rw::d3d8::InstanceData", ptr %88, i32 0, i32 0
  %90 = load i32, ptr %89, align 8, !tbaa !26
  %91 = load ptr, ptr %17, align 8, !tbaa !5
  store i32 %90, ptr %91, align 4, !tbaa !9
  %92 = load ptr, ptr %17, align 8, !tbaa !5
  %93 = getelementptr inbounds i8, ptr %92, i64 4
  store ptr %93, ptr %17, align 8, !tbaa !5
  %94 = load ptr, ptr %18, align 8, !tbaa !5
  %95 = getelementptr inbounds %"struct.rw::d3d8::InstanceData", ptr %94, i32 0, i32 1
  %96 = load i32, ptr %95, align 4, !tbaa !28
  %97 = load ptr, ptr %17, align 8, !tbaa !5
  store i32 %96, ptr %97, align 4, !tbaa !9
  %98 = load ptr, ptr %17, align 8, !tbaa !5
  %99 = getelementptr inbounds i8, ptr %98, i64 4
  store ptr %99, ptr %17, align 8, !tbaa !5
  %100 = load ptr, ptr %18, align 8, !tbaa !5
  %101 = getelementptr inbounds %"struct.rw::d3d8::InstanceData", ptr %100, i32 0, i32 2
  %102 = load i32, ptr %101, align 8, !tbaa !29
  %103 = load ptr, ptr %17, align 8, !tbaa !5
  store i32 %102, ptr %103, align 4, !tbaa !9
  %104 = load ptr, ptr %17, align 8, !tbaa !5
  %105 = getelementptr inbounds i8, ptr %104, i64 4
  store ptr %105, ptr %17, align 8, !tbaa !5
  %106 = load ptr, ptr %18, align 8, !tbaa !5
  %107 = getelementptr inbounds %"struct.rw::d3d8::InstanceData", ptr %106, i32 0, i32 3
  %108 = load i32, ptr %107, align 4, !tbaa !30
  %109 = load ptr, ptr %17, align 8, !tbaa !5
  store i32 %108, ptr %109, align 4, !tbaa !9
  %110 = load ptr, ptr %17, align 8, !tbaa !5
  %111 = getelementptr inbounds i8, ptr %110, i64 4
  store ptr %111, ptr %17, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %20) #4
  %112 = load ptr, ptr %12, align 8, !tbaa !5
  %113 = getelementptr inbounds %"struct.rw::Geometry", ptr %112, i32 0, i32 11
  %114 = load ptr, ptr %18, align 8, !tbaa !5
  %115 = getelementptr inbounds %"struct.rw::d3d8::InstanceData", ptr %114, i32 0, i32 4
  %116 = load ptr, ptr %115, align 8, !tbaa !31
  %117 = call noundef i32 @_ZN2rw12MaterialList9findIndexEPNS_8MaterialE(ptr noundef nonnull align 8 dereferenceable(16) %113, ptr noundef %116)
  store i32 %117, ptr %20, align 4, !tbaa !9
  %118 = load i32, ptr %20, align 4, !tbaa !9
  %119 = load ptr, ptr %17, align 8, !tbaa !5
  store i32 %118, ptr %119, align 4, !tbaa !9
  %120 = load ptr, ptr %17, align 8, !tbaa !5
  %121 = getelementptr inbounds i8, ptr %120, i64 4
  store ptr %121, ptr %17, align 8, !tbaa !5
  %122 = load ptr, ptr %18, align 8, !tbaa !5
  %123 = getelementptr inbounds %"struct.rw::d3d8::InstanceData", ptr %122, i32 0, i32 5
  %124 = load i32, ptr %123, align 8, !tbaa !32
  %125 = load ptr, ptr %17, align 8, !tbaa !5
  store i32 %124, ptr %125, align 4, !tbaa !9
  %126 = load ptr, ptr %17, align 8, !tbaa !5
  %127 = getelementptr inbounds i8, ptr %126, i64 4
  store ptr %127, ptr %17, align 8, !tbaa !5
  %128 = load ptr, ptr %18, align 8, !tbaa !5
  %129 = getelementptr inbounds %"struct.rw::d3d8::InstanceData", ptr %128, i32 0, i32 6
  %130 = load i32, ptr %129, align 4, !tbaa !33
  %131 = load ptr, ptr %17, align 8, !tbaa !5
  store i32 %130, ptr %131, align 4, !tbaa !9
  %132 = load ptr, ptr %17, align 8, !tbaa !5
  %133 = getelementptr inbounds i8, ptr %132, i64 4
  store ptr %133, ptr %17, align 8, !tbaa !5
  %134 = load ptr, ptr %17, align 8, !tbaa !5
  store i32 0, ptr %134, align 4, !tbaa !9
  %135 = load ptr, ptr %17, align 8, !tbaa !5
  %136 = getelementptr inbounds i8, ptr %135, i64 4
  store ptr %136, ptr %17, align 8, !tbaa !5
  %137 = load ptr, ptr %17, align 8, !tbaa !5
  store i32 0, ptr %137, align 4, !tbaa !9
  %138 = load ptr, ptr %17, align 8, !tbaa !5
  %139 = getelementptr inbounds i8, ptr %138, i64 4
  store ptr %139, ptr %17, align 8, !tbaa !5
  %140 = load ptr, ptr %18, align 8, !tbaa !5
  %141 = getelementptr inbounds %"struct.rw::d3d8::InstanceData", ptr %140, i32 0, i32 9
  %142 = load i32, ptr %141, align 8, !tbaa !34
  %143 = load ptr, ptr %17, align 8, !tbaa !5
  store i32 %142, ptr %143, align 4, !tbaa !9
  %144 = load ptr, ptr %17, align 8, !tbaa !5
  %145 = getelementptr inbounds i8, ptr %144, i64 4
  store ptr %145, ptr %17, align 8, !tbaa !5
  %146 = load ptr, ptr %18, align 8, !tbaa !5
  %147 = getelementptr inbounds %"struct.rw::d3d8::InstanceData", ptr %146, i32 0, i32 10
  %148 = load i8, ptr %147, align 4, !tbaa !35
  %149 = load ptr, ptr %17, align 8, !tbaa !5
  %150 = getelementptr inbounds i8, ptr %149, i32 1
  store ptr %150, ptr %17, align 8, !tbaa !5
  store i8 %148, ptr %149, align 1, !tbaa !36
  %151 = load ptr, ptr %18, align 8, !tbaa !5
  %152 = getelementptr inbounds %"struct.rw::d3d8::InstanceData", ptr %151, i32 0, i32 11
  %153 = load i8, ptr %152, align 1, !tbaa !37
  %154 = load ptr, ptr %17, align 8, !tbaa !5
  %155 = getelementptr inbounds i8, ptr %154, i32 1
  store ptr %155, ptr %17, align 8, !tbaa !5
  store i8 %153, ptr %154, align 1, !tbaa !36
  %156 = load ptr, ptr %18, align 8, !tbaa !5
  %157 = getelementptr inbounds %"struct.rw::d3d8::InstanceData", ptr %156, i32 0, i32 12
  %158 = load i8, ptr %157, align 2, !tbaa !38
  %159 = load ptr, ptr %17, align 8, !tbaa !5
  %160 = getelementptr inbounds i8, ptr %159, i32 1
  store ptr %160, ptr %17, align 8, !tbaa !5
  store i8 %158, ptr %159, align 1, !tbaa !36
  %161 = load ptr, ptr %18, align 8, !tbaa !5
  %162 = getelementptr inbounds %"struct.rw::d3d8::InstanceData", ptr %161, i32 1
  store ptr %162, ptr %18, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %20) #4
  br label %163

163:                                              ; preds = %87
  %164 = load i32, ptr %19, align 4, !tbaa !9
  %165 = add i32 %164, 1
  store i32 %165, ptr %19, align 4, !tbaa !9
  br label %79, !llvm.loop !39

166:                                              ; preds = %86
  %167 = load ptr, ptr %7, align 8, !tbaa !5
  %168 = load ptr, ptr %16, align 8, !tbaa !5
  %169 = load i32, ptr %15, align 4, !tbaa !9
  %170 = load ptr, ptr %167, align 8, !tbaa !41
  %171 = getelementptr inbounds ptr, ptr %170, i64 3
  %172 = load ptr, ptr %171, align 8
  %173 = call noundef i32 %172(ptr noundef nonnull align 8 dereferenceable(8) %167, ptr noundef %168, i32 noundef %169)
  %174 = load ptr, ptr getelementptr inbounds (%"struct.rw::MemoryFunctions", ptr @_ZN2rw6Engine8memfuncsE, i32 0, i32 2), align 8, !tbaa !43
  %175 = load ptr, ptr %16, align 8, !tbaa !5
  call void %174(ptr noundef %175)
  %176 = load ptr, ptr %14, align 8, !tbaa !5
  %177 = getelementptr inbounds %"struct.rw::d3d8::InstanceDataHeader", ptr %176, i32 0, i32 3
  %178 = load ptr, ptr %177, align 8, !tbaa !25
  store ptr %178, ptr %18, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %21) #4
  store i32 0, ptr %21, align 4, !tbaa !9
  br label %179

179:                                              ; preds = %227, %166
  %180 = load i32, ptr %21, align 4, !tbaa !9
  %181 = load ptr, ptr %14, align 8, !tbaa !5
  %182 = getelementptr inbounds %"struct.rw::d3d8::InstanceDataHeader", ptr %181, i32 0, i32 2
  %183 = load i16, ptr %182, align 2, !tbaa !24
  %184 = zext i16 %183 to i32
  %185 = icmp ult i32 %180, %184
  br i1 %185, label %187, label %186

186:                                              ; preds = %179
  store i32 5, ptr %13, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %21) #4
  br label %230

187:                                              ; preds = %179
  call void @llvm.lifetime.start.p0(i64 8, ptr %22) #4
  %188 = load ptr, ptr %18, align 8, !tbaa !5
  %189 = getelementptr inbounds %"struct.rw::d3d8::InstanceData", ptr %188, i32 0, i32 7
  %190 = load ptr, ptr %189, align 8, !tbaa !45
  %191 = call noundef ptr @_ZN2rw3d3d11lockIndicesEPvjjj(ptr noundef %190, i32 noundef 0, i32 noundef 0, i32 noundef 0)
  store ptr %191, ptr %22, align 8, !tbaa !5
  %192 = load ptr, ptr %7, align 8, !tbaa !5
  %193 = load ptr, ptr %22, align 8, !tbaa !5
  %194 = load ptr, ptr %18, align 8, !tbaa !5
  %195 = getelementptr inbounds %"struct.rw::d3d8::InstanceData", ptr %194, i32 0, i32 3
  %196 = load i32, ptr %195, align 4, !tbaa !30
  %197 = mul nsw i32 2, %196
  %198 = load ptr, ptr %192, align 8, !tbaa !41
  %199 = getelementptr inbounds ptr, ptr %198, i64 3
  %200 = load ptr, ptr %199, align 8
  %201 = call noundef i32 %200(ptr noundef nonnull align 8 dereferenceable(8) %192, ptr noundef %193, i32 noundef %197)
  %202 = load ptr, ptr %18, align 8, !tbaa !5
  %203 = getelementptr inbounds %"struct.rw::d3d8::InstanceData", ptr %202, i32 0, i32 7
  %204 = load ptr, ptr %203, align 8, !tbaa !45
  call void @_ZN2rw3d3d13unlockIndicesEPv(ptr noundef %204)
  call void @llvm.lifetime.start.p0(i64 8, ptr %23) #4
  %205 = load ptr, ptr %18, align 8, !tbaa !5
  %206 = getelementptr inbounds %"struct.rw::d3d8::InstanceData", ptr %205, i32 0, i32 8
  %207 = load ptr, ptr %206, align 8, !tbaa !46
  %208 = call noundef ptr @_ZN2rw3d3d12lockVerticesEPvjjj(ptr noundef %207, i32 noundef 0, i32 noundef 0, i32 noundef 0)
  store ptr %208, ptr %23, align 8, !tbaa !5
  %209 = load ptr, ptr %7, align 8, !tbaa !5
  %210 = load ptr, ptr %23, align 8, !tbaa !5
  %211 = load ptr, ptr %18, align 8, !tbaa !5
  %212 = getelementptr inbounds %"struct.rw::d3d8::InstanceData", ptr %211, i32 0, i32 1
  %213 = load i32, ptr %212, align 4, !tbaa !28
  %214 = load ptr, ptr %18, align 8, !tbaa !5
  %215 = getelementptr inbounds %"struct.rw::d3d8::InstanceData", ptr %214, i32 0, i32 2
  %216 = load i32, ptr %215, align 8, !tbaa !29
  %217 = mul nsw i32 %213, %216
  %218 = load ptr, ptr %209, align 8, !tbaa !41
  %219 = getelementptr inbounds ptr, ptr %218, i64 3
  %220 = load ptr, ptr %219, align 8
  %221 = call noundef i32 %220(ptr noundef nonnull align 8 dereferenceable(8) %209, ptr noundef %210, i32 noundef %217)
  %222 = load ptr, ptr %18, align 8, !tbaa !5
  %223 = getelementptr inbounds %"struct.rw::d3d8::InstanceData", ptr %222, i32 0, i32 8
  %224 = load ptr, ptr %223, align 8, !tbaa !46
  call void @_ZN2rw3d3d14unlockVerticesEPv(ptr noundef %224)
  %225 = load ptr, ptr %18, align 8, !tbaa !5
  %226 = getelementptr inbounds %"struct.rw::d3d8::InstanceData", ptr %225, i32 1
  store ptr %226, ptr %18, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %23) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %22) #4
  br label %227

227:                                              ; preds = %187
  %228 = load i32, ptr %21, align 4, !tbaa !9
  %229 = add i32 %228, 1
  store i32 %229, ptr %21, align 4, !tbaa !9
  br label %179, !llvm.loop !47

230:                                              ; preds = %186
  %231 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr %231, ptr %6, align 8
  store i32 1, ptr %13, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %18) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %17) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #4
  br label %232

232:                                              ; preds = %230, %40
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #4
  %233 = load ptr, ptr %6, align 8
  ret ptr %233
}

declare noundef zeroext i1 @_ZN2rw16writeChunkHeaderEPNS_6StreamEii(ptr noundef, i32 noundef, i32 noundef) #2

declare noundef i32 @_ZN2rw6Stream8writeU32Ej(ptr noundef nonnull align 8 dereferenceable(8), i32 noundef) #2

declare noundef i32 @_ZN2rw6Stream8writeI32Ei(ptr noundef nonnull align 8 dereferenceable(8), i32 noundef) #2

declare noundef i32 @_ZN2rw12MaterialList9findIndexEPNS_8MaterialE(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef) #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 = { "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 = { 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 #4 = { 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 = !{!12, !6, i64 144}
!19 = !{!20, !14, i64 4}
!20 = !{!"_ZTSN2rw10MeshHeaderE", !10, i64 0, !14, i64 4, !14, i64 6, !10, i64 8, !10, i64 12}
!21 = !{!22, !14, i64 4}
!22 = !{!"_ZTSN2rw4d3d818InstanceDataHeaderE", !17, i64 0, !14, i64 4, !14, i64 6, !6, i64 8}
!23 = !{!14, !14, i64 0}
!24 = !{!22, !14, i64 6}
!25 = !{!22, !6, i64 8}
!26 = !{!27, !10, i64 0}
!27 = !{!"_ZTSN2rw4d3d812InstanceDataE", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12, !6, i64 16, !10, i64 24, !10, i64 28, !6, i64 32, !6, i64 40, !10, i64 48, !7, i64 52, !7, i64 53, !7, i64 54}
!28 = !{!27, !10, i64 4}
!29 = !{!27, !10, i64 8}
!30 = !{!27, !10, i64 12}
!31 = !{!27, !6, i64 16}
!32 = !{!27, !10, i64 24}
!33 = !{!27, !10, i64 28}
!34 = !{!27, !10, i64 48}
!35 = !{!27, !7, i64 52}
!36 = !{!7, !7, i64 0}
!37 = !{!27, !7, i64 53}
!38 = !{!27, !7, i64 54}
!39 = distinct !{!39, !40}
!40 = !{!"llvm.loop.mustprogress"}
!41 = !{!42, !42, i64 0}
!42 = !{!"vtable pointer", !8, i64 0}
!43 = !{!44, !6, i64 16}
!44 = !{!"_ZTSN2rw15MemoryFunctionsE", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32}
!45 = !{!27, !6, i64 32}
!46 = !{!27, !6, i64 40}
!47 = distinct !{!47, !40}


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

@_ZN2rw6Engine8memfuncsE = external local_unnamed_addr global %"struct.rw::MemoryFunctions", align 8
@.str.9 = 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

declare noundef ptr @_ZN2rw3d3d11lockIndicesEPvjjj(ptr noundef, i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #1

declare void @_ZN2rw3d3d13unlockIndicesEPv(ptr noundef) local_unnamed_addr #1

declare noundef ptr @_ZN2rw3d3d12lockVerticesEPvjjj(ptr noundef, i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #1

declare void @_ZN2rw3d3d14unlockVerticesEPv(ptr noundef) local_unnamed_addr #1

; Function Attrs: mustprogress uwtable
define dso_local noundef ptr @_ZN2rw4d3d815writeNativeDataEPNS_6StreamEiPvii(ptr noundef returned %0, i32 noundef %1, ptr noundef %2, i32 noundef %3, i32 noundef %4) local_unnamed_addr #2 {
  %6 = add nsw i32 %1, -12
  %7 = tail call noundef zeroext i1 @_ZN2rw16writeChunkHeaderEPNS_6StreamEii(ptr noundef %0, i32 noundef 1, i32 noundef %6)
  %8 = getelementptr inbounds i8, ptr %2, i64 152
  %9 = load ptr, ptr %8, align 8, !tbaa !5
  %10 = icmp eq ptr %9, null
  br i1 %10, label %.loopexit, label %11

11:                                               ; preds = %5
  %12 = load i32, ptr %9, align 4, !tbaa !14
  %.not = icmp eq i32 %12, 8
  br i1 %.not, label %13, label %.loopexit

13:                                               ; preds = %11
  %14 = tail call noundef i32 @_ZN2rw6Stream8writeU32Ej(ptr noundef nonnull align 8 dereferenceable(8) %0, i32 noundef 8)
  %15 = load ptr, ptr %8, align 8, !tbaa !5
  %16 = getelementptr inbounds i8, ptr %2, i64 144
  %17 = load ptr, ptr %16, align 8, !tbaa !16
  %18 = getelementptr inbounds i8, ptr %17, i64 4
  %19 = load i16, ptr %18, align 4, !tbaa !17
  %20 = zext i16 %19 to i32
  %21 = mul nuw nsw i32 %20, 44
  %22 = add nuw nsw i32 %21, 4
  %23 = zext nneg i32 %22 to i64
  %24 = tail call noundef ptr @_ZN2rw14mustmalloc_LOCEmjPKc(i64 noundef %23, i32 noundef 65551, ptr noundef nonnull @.str.9)
  %25 = tail call noundef i32 @_ZN2rw6Stream8writeI32Ei(ptr noundef nonnull align 8 dereferenceable(8) %0, i32 noundef %22)
  %26 = getelementptr inbounds i8, ptr %15, i64 4
  %27 = load i16, ptr %26, align 4, !tbaa !19
  store i16 %27, ptr %24, align 2, !tbaa !21
  %28 = getelementptr inbounds i8, ptr %24, i64 2
  %29 = getelementptr inbounds i8, ptr %15, i64 6
  %30 = load i16, ptr %29, align 2, !tbaa !22
  store i16 %30, ptr %28, align 2, !tbaa !21
  %31 = getelementptr inbounds i8, ptr %15, i64 8
  %.not92 = icmp eq i16 %30, 0
  br i1 %.not92, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %13
  %32 = load ptr, ptr %31, align 8, !tbaa !23
  %33 = getelementptr inbounds i8, ptr %24, i64 4
  %34 = getelementptr inbounds i8, ptr %2, i64 128
  br label %42

._crit_edge:                                      ; preds = %42, %13
  %35 = load ptr, ptr %0, align 8, !tbaa !24
  %36 = getelementptr inbounds i8, ptr %35, i64 24
  %37 = load ptr, ptr %36, align 8
  %38 = tail call noundef i32 %37(ptr noundef nonnull align 8 dereferenceable(8) %0, ptr noundef nonnull %24, i32 noundef %22)
  %39 = load ptr, ptr getelementptr inbounds (i8, ptr @_ZN2rw6Engine8memfuncsE, i64 16), align 8, !tbaa !26
  tail call void %39(ptr noundef nonnull %24)
  %40 = load i16, ptr %29, align 2, !tbaa !22
  %.not93 = icmp eq i16 %40, 0
  br i1 %.not93, label %.loopexit, label %.lr.ph91.preheader

.lr.ph91.preheader:                               ; preds = %._crit_edge
  %41 = load ptr, ptr %31, align 8, !tbaa !23
  br label %.lr.ph91

42:                                               ; preds = %.lr.ph, %42
  %.08287 = phi ptr [ %33, %.lr.ph ], [ %77, %42 ]
  %.08386 = phi i32 [ 0, %.lr.ph ], [ %79, %42 ]
  %.08485 = phi ptr [ %32, %.lr.ph ], [ %78, %42 ]
  %43 = load i32, ptr %.08485, align 8, !tbaa !28
  store i32 %43, ptr %.08287, align 4, !tbaa !30
  %44 = getelementptr inbounds i8, ptr %.08287, i64 4
  %45 = getelementptr inbounds i8, ptr %.08485, i64 4
  %46 = load i32, ptr %45, align 4, !tbaa !31
  store i32 %46, ptr %44, align 4, !tbaa !30
  %47 = getelementptr inbounds i8, ptr %.08287, i64 8
  %48 = getelementptr inbounds i8, ptr %.08485, i64 8
  %49 = load i32, ptr %48, align 8, !tbaa !32
  store i32 %49, ptr %47, align 4, !tbaa !30
  %50 = getelementptr inbounds i8, ptr %.08287, i64 12
  %51 = getelementptr inbounds i8, ptr %.08485, i64 12
  %52 = load i32, ptr %51, align 4, !tbaa !33
  store i32 %52, ptr %50, align 4, !tbaa !30
  %53 = getelementptr inbounds i8, ptr %.08287, i64 16
  %54 = getelementptr inbounds i8, ptr %.08485, i64 16
  %55 = load ptr, ptr %54, align 8, !tbaa !34
  %56 = tail call noundef i32 @_ZN2rw12MaterialList9findIndexEPNS_8MaterialE(ptr noundef nonnull align 8 dereferenceable(16) %34, ptr noundef %55)
  store i32 %56, ptr %53, align 4, !tbaa !30
  %57 = getelementptr inbounds i8, ptr %.08287, i64 20
  %58 = getelementptr inbounds i8, ptr %.08485, i64 24
  %59 = load i32, ptr %58, align 8, !tbaa !35
  store i32 %59, ptr %57, align 4, !tbaa !30
  %60 = getelementptr inbounds i8, ptr %.08287, i64 24
  %61 = getelementptr inbounds i8, ptr %.08485, i64 28
  %62 = load i32, ptr %61, align 4, !tbaa !36
  store i32 %62, ptr %60, align 4, !tbaa !30
  %63 = getelementptr inbounds i8, ptr %.08287, i64 28
  store i32 0, ptr %63, align 4, !tbaa !30
  %64 = getelementptr inbounds i8, ptr %.08287, i64 32
  store i32 0, ptr %64, align 4, !tbaa !30
  %65 = getelementptr inbounds i8, ptr %.08287, i64 36
  %66 = getelementptr inbounds i8, ptr %.08485, i64 48
  %67 = load i32, ptr %66, align 8, !tbaa !37
  store i32 %67, ptr %65, align 4, !tbaa !30
  %68 = getelementptr inbounds i8, ptr %.08287, i64 40
  %69 = getelementptr inbounds i8, ptr %.08485, i64 52
  %70 = load i8, ptr %69, align 4, !tbaa !38
  %71 = getelementptr inbounds i8, ptr %.08287, i64 41
  store i8 %70, ptr %68, align 1, !tbaa !39
  %72 = getelementptr inbounds i8, ptr %.08485, i64 53
  %73 = load i8, ptr %72, align 1, !tbaa !40
  %74 = getelementptr inbounds i8, ptr %.08287, i64 42
  store i8 %73, ptr %71, align 1, !tbaa !39
  %75 = getelementptr inbounds i8, ptr %.08485, i64 54
  %76 = load i8, ptr %75, align 2, !tbaa !41
  %77 = getelementptr inbounds i8, ptr %.08287, i64 43
  store i8 %76, ptr %74, align 1, !tbaa !39
  %78 = getelementptr inbounds i8, ptr %.08485, i64 56
  %79 = add nuw nsw i32 %.08386, 1
  %80 = load i16, ptr %29, align 2, !tbaa !22
  %81 = zext i16 %80 to i32
  %82 = icmp ult i32 %79, %81
  br i1 %82, label %42, label %._crit_edge, !llvm.loop !42

.lr.ph91:                                         ; preds = %.lr.ph91.preheader, %.lr.ph91
  %.08189 = phi i32 [ %108, %.lr.ph91 ], [ 0, %.lr.ph91.preheader ]
  %.188 = phi ptr [ %107, %.lr.ph91 ], [ %41, %.lr.ph91.preheader ]
  %83 = getelementptr inbounds i8, ptr %.188, i64 32
  %84 = load ptr, ptr %83, align 8, !tbaa !44
  %85 = tail call noundef ptr @_ZN2rw3d3d11lockIndicesEPvjjj(ptr noundef %84, i32 noundef 0, i32 noundef 0, i32 noundef 0)
  %86 = getelementptr inbounds i8, ptr %.188, i64 12
  %87 = load i32, ptr %86, align 4, !tbaa !33
  %88 = shl nsw i32 %87, 1
  %89 = load ptr, ptr %0, align 8, !tbaa !24
  %90 = getelementptr inbounds i8, ptr %89, i64 24
  %91 = load ptr, ptr %90, align 8
  %92 = tail call noundef i32 %91(ptr noundef nonnull align 8 dereferenceable(8) %0, ptr noundef %85, i32 noundef %88)
  %93 = load ptr, ptr %83, align 8, !tbaa !44
  tail call void @_ZN2rw3d3d13unlockIndicesEPv(ptr noundef %93)
  %94 = getelementptr inbounds i8, ptr %.188, i64 40
  %95 = load ptr, ptr %94, align 8, !tbaa !45
  %96 = tail call noundef ptr @_ZN2rw3d3d12lockVerticesEPvjjj(ptr noundef %95, i32 noundef 0, i32 noundef 0, i32 noundef 0)
  %97 = getelementptr inbounds i8, ptr %.188, i64 4
  %98 = load i32, ptr %97, align 4, !tbaa !31
  %99 = getelementptr inbounds i8, ptr %.188, i64 8
  %100 = load i32, ptr %99, align 8, !tbaa !32
  %101 = mul nsw i32 %100, %98
  %102 = load ptr, ptr %0, align 8, !tbaa !24
  %103 = getelementptr inbounds i8, ptr %102, i64 24
  %104 = load ptr, ptr %103, align 8
  %105 = tail call noundef i32 %104(ptr noundef nonnull align 8 dereferenceable(8) %0, ptr noundef %96, i32 noundef %101)
  %106 = load ptr, ptr %94, align 8, !tbaa !45
  tail call void @_ZN2rw3d3d14unlockVerticesEPv(ptr noundef %106)
  %107 = getelementptr inbounds i8, ptr %.188, i64 56
  %108 = add nuw nsw i32 %.08189, 1
  %109 = load i16, ptr %29, align 2, !tbaa !22
  %110 = zext i16 %109 to i32
  %111 = icmp ult i32 %108, %110
  br i1 %111, label %.lr.ph91, label %.loopexit, !llvm.loop !46

.loopexit:                                        ; preds = %.lr.ph91, %._crit_edge, %5, %11
  ret ptr %0
}

declare noundef zeroext i1 @_ZN2rw16writeChunkHeaderEPNS_6StreamEii(ptr noundef, i32 noundef, i32 noundef) local_unnamed_addr #1

declare noundef i32 @_ZN2rw6Stream8writeU32Ej(ptr noundef nonnull align 8 dereferenceable(8), i32 noundef) local_unnamed_addr #1

declare noundef i32 @_ZN2rw6Stream8writeI32Ei(ptr noundef nonnull align 8 dereferenceable(8), i32 noundef) local_unnamed_addr #1

declare noundef i32 @_ZN2rw12MaterialList9findIndexEPNS_8MaterialE(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef) local_unnamed_addr #1

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 = { "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 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 = !{!6, !10, i64 144}
!17 = !{!18, !12, i64 4}
!18 = !{!"_ZTSN2rw10MeshHeaderE", !11, i64 0, !12, i64 4, !12, i64 6, !11, i64 8, !11, i64 12}
!19 = !{!20, !12, i64 4}
!20 = !{!"_ZTSN2rw4d3d818InstanceDataHeaderE", !15, i64 0, !12, i64 4, !12, i64 6, !10, i64 8}
!21 = !{!12, !12, i64 0}
!22 = !{!20, !12, i64 6}
!23 = !{!20, !10, i64 8}
!24 = !{!25, !25, i64 0}
!25 = !{!"vtable pointer", !9, i64 0}
!26 = !{!27, !10, i64 16}
!27 = !{!"_ZTSN2rw15MemoryFunctionsE", !10, i64 0, !10, i64 8, !10, i64 16, !10, i64 24, !10, i64 32}
!28 = !{!29, !11, i64 0}
!29 = !{!"_ZTSN2rw4d3d812InstanceDataE", !11, i64 0, !11, i64 4, !11, i64 8, !11, i64 12, !10, i64 16, !11, i64 24, !11, i64 28, !10, i64 32, !10, i64 40, !11, i64 48, !8, i64 52, !8, i64 53, !8, i64 54}
!30 = !{!11, !11, i64 0}
!31 = !{!29, !11, i64 4}
!32 = !{!29, !11, i64 8}
!33 = !{!29, !11, i64 12}
!34 = !{!29, !10, i64 16}
!35 = !{!29, !11, i64 24}
!36 = !{!29, !11, i64 28}
!37 = !{!29, !11, i64 48}
!38 = !{!29, !8, i64 52}
!39 = !{!8, !8, i64 0}
!40 = !{!29, !8, i64 53}
!41 = !{!29, !8, i64 54}
!42 = distinct !{!42, !43}
!43 = !{!"llvm.loop.mustprogress"}
!44 = !{!29, !10, i64 32}
!45 = !{!29, !10, i64 40}
!46 = distinct !{!46, !43}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass