; LLVM IR from aap/librw :: src/d3d/xbox.ll (ZN2rw4xbox15writeNativeDataEPNS_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::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::xbox::InstanceDataHeader" = type { %"struct.rw::InstanceDataHeader", i32, i16, i16, i32, i32, i32, ptr, i32, ptr, ptr, ptr }
%"struct.rw::xbox::InstanceData" = type { i32, i32, i32, ptr, ptr, i32 }

@.str.1 = external hidden unnamed_addr constant [60 x i8], align 1
@_ZN2rw7versionE = external global i32, align 4
@.str.9 = external hidden unnamed_addr constant [67 x i8], align 1
@__PRETTY_FUNCTION__._ZN2rw4xbox15writeNativeDataEPNS_6StreamEiPvii = external hidden unnamed_addr constant [73 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: mustprogress uwtable
define dso_local noundef ptr @_ZN2rw4xbox15writeNativeDataEPNS_6StreamEiPvii(ptr noundef %0, i32 noundef %1, ptr noundef %2, i32 noundef %3, i32 noundef %4) #1 {
  %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 ptr, align 8
  %16 = alloca ptr, align 8
  %17 = alloca i32, align 4
  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
  %18 = load ptr, ptr %9, align 8, !tbaa !5
  store ptr %18, ptr %12, align 8, !tbaa !5
  %19 = load ptr, ptr %7, align 8, !tbaa !5
  %20 = load i32, ptr %8, align 4, !tbaa !9
  %21 = sub nsw i32 %20, 12
  %22 = call noundef zeroext i1 @_ZN2rw16writeChunkHeaderEPNS_6StreamEii(ptr noundef %19, i32 noundef 1, i32 noundef %21)
  %23 = load ptr, ptr %12, align 8, !tbaa !5
  %24 = getelementptr inbounds %"struct.rw::Geometry", ptr %23, i32 0, i32 13
  %25 = load ptr, ptr %24, align 8, !tbaa !11
  %26 = icmp eq ptr %25, null
  br i1 %26, label %34, label %27

27:                                               ; preds = %5
  %28 = load ptr, ptr %12, align 8, !tbaa !5
  %29 = getelementptr inbounds %"struct.rw::Geometry", ptr %28, i32 0, i32 13
  %30 = load ptr, ptr %29, align 8, !tbaa !11
  %31 = getelementptr inbounds %"struct.rw::InstanceDataHeader", ptr %30, i32 0, i32 0
  %32 = load i32, ptr %31, align 4, !tbaa !16
  %33 = icmp ne i32 %32, 5
  br i1 %33, label %34, label %36

34:                                               ; preds = %27, %5
  %35 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr %35, ptr %6, align 8
  store i32 1, ptr %13, align 4
  br label %180

36:                                               ; preds = %27
  %37 = load ptr, ptr %7, align 8, !tbaa !5
  %38 = call noundef i32 @_ZN2rw6Stream8writeU32Ej(ptr noundef nonnull align 8 dereferenceable(8) %37, i32 noundef 5)
  %39 = load i32, ptr @_ZN2rw7versionE, align 4, !tbaa !9
  %40 = icmp sge i32 %39, 217088
  br i1 %40, label %41, label %42

41:                                               ; preds = %36
  br label %42

42:                                               ; preds = %41, %36
  %43 = phi i1 [ false, %36 ], [ true, %41 ]
  br i1 %43, label %44, label %45

44:                                               ; preds = %42
  br label %47

45:                                               ; preds = %42
  call void @__assert_fail(ptr noundef @.str.9, ptr noundef @.str.1, i32 noundef 138, ptr noundef @__PRETTY_FUNCTION__._ZN2rw4xbox15writeNativeDataEPNS_6StreamEiPvii) #5
  unreachable

46:                                               ; No predecessors!
  br label %47

47:                                               ; preds = %46, %44
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #4
  %48 = load ptr, ptr %12, align 8, !tbaa !5
  %49 = getelementptr inbounds %"struct.rw::Geometry", ptr %48, i32 0, i32 13
  %50 = load ptr, ptr %49, align 8, !tbaa !11
  store ptr %50, ptr %14, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #4
  %51 = load ptr, ptr %14, align 8, !tbaa !5
  %52 = getelementptr inbounds %"struct.rw::xbox::InstanceDataHeader", ptr %51, i32 0, i32 11
  %53 = load ptr, ptr %52, align 8, !tbaa !18
  %54 = getelementptr inbounds i8, ptr %53, i64 24
  store ptr %54, ptr %15, align 8, !tbaa !5
  %55 = load ptr, ptr %14, align 8, !tbaa !5
  %56 = getelementptr inbounds %"struct.rw::xbox::InstanceDataHeader", ptr %55, i32 0, i32 1
  %57 = load i32, ptr %56, align 4, !tbaa !20
  %58 = load ptr, ptr %15, align 8, !tbaa !5
  store i32 %57, ptr %58, align 4, !tbaa !9
  %59 = load ptr, ptr %15, align 8, !tbaa !5
  %60 = getelementptr inbounds i8, ptr %59, i64 4
  store ptr %60, ptr %15, align 8, !tbaa !5
  %61 = load ptr, ptr %14, align 8, !tbaa !5
  %62 = getelementptr inbounds %"struct.rw::xbox::InstanceDataHeader", ptr %61, i32 0, i32 2
  %63 = load i16, ptr %62, align 8, !tbaa !21
  %64 = load ptr, ptr %15, align 8, !tbaa !5
  store i16 %63, ptr %64, align 2, !tbaa !22
  %65 = load ptr, ptr %15, align 8, !tbaa !5
  %66 = getelementptr inbounds i8, ptr %65, i64 2
  store ptr %66, ptr %15, align 8, !tbaa !5
  %67 = load ptr, ptr %14, align 8, !tbaa !5
  %68 = getelementptr inbounds %"struct.rw::xbox::InstanceDataHeader", ptr %67, i32 0, i32 3
  %69 = load i16, ptr %68, align 2, !tbaa !23
  %70 = load ptr, ptr %15, align 8, !tbaa !5
  store i16 %69, ptr %70, align 2, !tbaa !22
  %71 = load ptr, ptr %15, align 8, !tbaa !5
  %72 = getelementptr inbounds i8, ptr %71, i64 2
  store ptr %72, ptr %15, align 8, !tbaa !5
  %73 = load ptr, ptr %14, align 8, !tbaa !5
  %74 = getelementptr inbounds %"struct.rw::xbox::InstanceDataHeader", ptr %73, i32 0, i32 4
  %75 = load i32, ptr %74, align 4, !tbaa !24
  %76 = load ptr, ptr %15, align 8, !tbaa !5
  store i32 %75, ptr %76, align 4, !tbaa !9
  %77 = load ptr, ptr %15, align 8, !tbaa !5
  %78 = getelementptr inbounds i8, ptr %77, i64 4
  store ptr %78, ptr %15, align 8, !tbaa !5
  %79 = load ptr, ptr %14, align 8, !tbaa !5
  %80 = getelementptr inbounds %"struct.rw::xbox::InstanceDataHeader", ptr %79, i32 0, i32 5
  %81 = load i32, ptr %80, align 8, !tbaa !25
  %82 = load ptr, ptr %15, align 8, !tbaa !5
  store i32 %81, ptr %82, align 4, !tbaa !9
  %83 = load ptr, ptr %15, align 8, !tbaa !5
  %84 = getelementptr inbounds i8, ptr %83, i64 4
  store ptr %84, ptr %15, align 8, !tbaa !5
  %85 = load ptr, ptr %14, align 8, !tbaa !5
  %86 = getelementptr inbounds %"struct.rw::xbox::InstanceDataHeader", ptr %85, i32 0, i32 6
  %87 = load i32, ptr %86, align 4, !tbaa !26
  %88 = load ptr, ptr %15, align 8, !tbaa !5
  store i32 %87, ptr %88, align 4, !tbaa !9
  %89 = load ptr, ptr %15, align 8, !tbaa !5
  %90 = getelementptr inbounds i8, ptr %89, i64 4
  store ptr %90, ptr %15, align 8, !tbaa !5
  %91 = load ptr, ptr %15, align 8, !tbaa !5
  %92 = getelementptr inbounds i8, ptr %91, i64 4
  store ptr %92, ptr %15, align 8, !tbaa !5
  %93 = load ptr, ptr %14, align 8, !tbaa !5
  %94 = getelementptr inbounds %"struct.rw::xbox::InstanceDataHeader", ptr %93, i32 0, i32 8
  %95 = load i32, ptr %94, align 8, !tbaa !27
  %96 = load ptr, ptr %15, align 8, !tbaa !5
  store i32 %95, ptr %96, align 4, !tbaa !9
  %97 = load ptr, ptr %15, align 8, !tbaa !5
  %98 = getelementptr inbounds i8, ptr %97, i64 4
  store ptr %98, ptr %15, align 8, !tbaa !5
  %99 = load ptr, ptr %15, align 8, !tbaa !5
  %100 = getelementptr inbounds i8, ptr %99, i64 8
  store ptr %100, ptr %15, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #4
  %101 = load ptr, ptr %14, align 8, !tbaa !5
  %102 = getelementptr inbounds %"struct.rw::xbox::InstanceDataHeader", ptr %101, i32 0, i32 9
  %103 = load ptr, ptr %102, align 8, !tbaa !28
  store ptr %103, ptr %16, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %17) #4
  store i32 0, ptr %17, align 4, !tbaa !9
  br label %104

104:                                              ; preds = %148, %47
  %105 = load i32, ptr %17, align 4, !tbaa !9
  %106 = load ptr, ptr %14, align 8, !tbaa !5
  %107 = getelementptr inbounds %"struct.rw::xbox::InstanceDataHeader", ptr %106, i32 0, i32 3
  %108 = load i16, ptr %107, align 2, !tbaa !23
  %109 = zext i16 %108 to i32
  %110 = icmp slt i32 %105, %109
  br i1 %110, label %112, label %111

111:                                              ; preds = %104
  store i32 2, ptr %13, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %17) #4
  br label %151

112:                                              ; preds = %104
  %113 = load ptr, ptr %16, align 8, !tbaa !5
  %114 = getelementptr inbounds %"struct.rw::xbox::InstanceData", ptr %113, i32 0, i32 0
  %115 = load i32, ptr %114, align 8, !tbaa !29
  %116 = load ptr, ptr %15, align 8, !tbaa !5
  store i32 %115, ptr %116, align 4, !tbaa !9
  %117 = load ptr, ptr %15, align 8, !tbaa !5
  %118 = getelementptr inbounds i8, ptr %117, i64 4
  store ptr %118, ptr %15, align 8, !tbaa !5
  %119 = load ptr, ptr %16, align 8, !tbaa !5
  %120 = getelementptr inbounds %"struct.rw::xbox::InstanceData", ptr %119, i32 0, i32 1
  %121 = load i32, ptr %120, align 4, !tbaa !31
  %122 = load ptr, ptr %15, align 8, !tbaa !5
  store i32 %121, ptr %122, align 4, !tbaa !9
  %123 = load ptr, ptr %15, align 8, !tbaa !5
  %124 = getelementptr inbounds i8, ptr %123, i64 4
  store ptr %124, ptr %15, align 8, !tbaa !5
  %125 = load ptr, ptr %16, align 8, !tbaa !5
  %126 = getelementptr inbounds %"struct.rw::xbox::InstanceData", ptr %125, i32 0, i32 2
  %127 = load i32, ptr %126, align 8, !tbaa !32
  %128 = load ptr, ptr %15, align 8, !tbaa !5
  store i32 %127, ptr %128, align 4, !tbaa !9
  %129 = load ptr, ptr %15, align 8, !tbaa !5
  %130 = getelementptr inbounds i8, ptr %129, i64 4
  store ptr %130, ptr %15, align 8, !tbaa !5
  %131 = load ptr, ptr %16, align 8, !tbaa !5
  %132 = getelementptr inbounds %"struct.rw::xbox::InstanceData", ptr %131, i32 0, i32 3
  %133 = load ptr, ptr %132, align 8, !tbaa !33
  %134 = load ptr, ptr %14, align 8, !tbaa !5
  %135 = getelementptr inbounds %"struct.rw::xbox::InstanceDataHeader", ptr %134, i32 0, i32 11
  %136 = load ptr, ptr %135, align 8, !tbaa !18
  %137 = ptrtoint ptr %133 to i64
  %138 = ptrtoint ptr %136 to i64
  %139 = sub i64 %137, %138
  %140 = trunc i64 %139 to i32
  %141 = load ptr, ptr %15, align 8, !tbaa !5
  store i32 %140, ptr %141, align 4, !tbaa !9
  %142 = load ptr, ptr %15, align 8, !tbaa !5
  %143 = getelementptr inbounds i8, ptr %142, i64 4
  store ptr %143, ptr %15, align 8, !tbaa !5
  %144 = load ptr, ptr %15, align 8, !tbaa !5
  %145 = getelementptr inbounds i8, ptr %144, i64 8
  store ptr %145, ptr %15, align 8, !tbaa !5
  %146 = load ptr, ptr %16, align 8, !tbaa !5
  %147 = getelementptr inbounds %"struct.rw::xbox::InstanceData", ptr %146, i32 1
  store ptr %147, ptr %16, align 8, !tbaa !5
  br label %148

148:                                              ; preds = %112
  %149 = load i32, ptr %17, align 4, !tbaa !9
  %150 = add nsw i32 %149, 1
  store i32 %150, ptr %17, align 4, !tbaa !9
  br label %104, !llvm.loop !34

151:                                              ; preds = %111
  %152 = load ptr, ptr %7, align 8, !tbaa !5
  %153 = load ptr, ptr %14, align 8, !tbaa !5
  %154 = getelementptr inbounds %"struct.rw::xbox::InstanceDataHeader", ptr %153, i32 0, i32 11
  %155 = load ptr, ptr %154, align 8, !tbaa !18
  %156 = getelementptr inbounds i8, ptr %155, i64 24
  %157 = load ptr, ptr %14, align 8, !tbaa !5
  %158 = getelementptr inbounds %"struct.rw::xbox::InstanceDataHeader", ptr %157, i32 0, i32 1
  %159 = load i32, ptr %158, align 4, !tbaa !20
  %160 = load ptr, ptr %152, align 8, !tbaa !36
  %161 = getelementptr inbounds ptr, ptr %160, i64 3
  %162 = load ptr, ptr %161, align 8
  %163 = call noundef i32 %162(ptr noundef nonnull align 8 dereferenceable(8) %152, ptr noundef %156, i32 noundef %159)
  %164 = load ptr, ptr %7, align 8, !tbaa !5
  %165 = load ptr, ptr %14, align 8, !tbaa !5
  %166 = getelementptr inbounds %"struct.rw::xbox::InstanceDataHeader", ptr %165, i32 0, i32 7
  %167 = load ptr, ptr %166, align 8, !tbaa !38
  %168 = load ptr, ptr %14, align 8, !tbaa !5
  %169 = getelementptr inbounds %"struct.rw::xbox::InstanceDataHeader", ptr %168, i32 0, i32 6
  %170 = load i32, ptr %169, align 4, !tbaa !26
  %171 = load ptr, ptr %14, align 8, !tbaa !5
  %172 = getelementptr inbounds %"struct.rw::xbox::InstanceDataHeader", ptr %171, i32 0, i32 5
  %173 = load i32, ptr %172, align 8, !tbaa !25
  %174 = mul nsw i32 %170, %173
  %175 = load ptr, ptr %164, align 8, !tbaa !36
  %176 = getelementptr inbounds ptr, ptr %175, i64 3
  %177 = load ptr, ptr %176, align 8
  %178 = call noundef i32 %177(ptr noundef nonnull align 8 dereferenceable(8) %164, ptr noundef %167, i32 noundef %174)
  %179 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr %179, ptr %6, align 8
  store i32 1, ptr %13, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #4
  br label %180

180:                                              ; preds = %151, %34
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #4
  %181 = load ptr, ptr %6, align 8
  ret ptr %181
}

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

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #3

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #2 = { "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 = { noreturn nounwind "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 }
attributes #5 = { noreturn nounwind }

!llvm.module.flags = !{!0, !1, !2, !3}
!llvm.ident = !{!4}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 2}
!4 = !{!"clang version 19.1.0 (git@github.com:llvm/llvm-project.git a4bf6cd7cfb1a1421ba92bca9d017b49936c55e4)"}
!5 = !{!6, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !6, i64 152}
!12 = !{!"_ZTSN2rw8GeometryE", !13, i64 0, !10, i64 16, !14, i64 20, !10, i64 24, !10, i64 28, !10, i64 32, !10, i64 36, !6, i64 40, !6, i64 48, !7, i64 56, !6, i64 120, !15, i64 128, !6, i64 144, !6, i64 152, !10, i64 160}
!13 = !{!"_ZTSN2rw6ObjectE", !7, i64 0, !7, i64 1, !7, i64 2, !7, i64 3, !6, i64 8}
!14 = !{!"short", !7, i64 0}
!15 = !{!"_ZTSN2rw12MaterialListE", !6, i64 0, !10, i64 8, !10, i64 12}
!16 = !{!17, !10, i64 0}
!17 = !{!"_ZTSN2rw18InstanceDataHeaderE", !10, i64 0}
!18 = !{!19, !6, i64 56}
!19 = !{!"_ZTSN2rw4xbox18InstanceDataHeaderE", !17, i64 0, !10, i64 4, !14, i64 8, !14, i64 10, !10, i64 12, !10, i64 16, !10, i64 20, !6, i64 24, !10, i64 32, !6, i64 40, !6, i64 48, !6, i64 56}
!20 = !{!19, !10, i64 4}
!21 = !{!19, !14, i64 8}
!22 = !{!14, !14, i64 0}
!23 = !{!19, !14, i64 10}
!24 = !{!19, !10, i64 12}
!25 = !{!19, !10, i64 16}
!26 = !{!19, !10, i64 20}
!27 = !{!19, !10, i64 32}
!28 = !{!19, !6, i64 40}
!29 = !{!30, !10, i64 0}
!30 = !{!"_ZTSN2rw4xbox12InstanceDataE", !10, i64 0, !10, i64 4, !10, i64 8, !6, i64 16, !6, i64 24, !10, i64 32}
!31 = !{!30, !10, i64 4}
!32 = !{!30, !10, i64 8}
!33 = !{!30, !6, i64 16}
!34 = distinct !{!34, !35}
!35 = !{!"llvm.loop.mustprogress"}
!36 = !{!37, !37, i64 0}
!37 = !{!"vtable pointer", !8, i64 0}
!38 = !{!19, !6, i64 24}


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

@.str.1 = external hidden unnamed_addr constant [60 x i8], align 1
@_ZN2rw7versionE = external local_unnamed_addr global i32, align 4
@.str.9 = external hidden unnamed_addr constant [67 x i8], align 1
@__PRETTY_FUNCTION__._ZN2rw4xbox15writeNativeDataEPNS_6StreamEiPvii = external hidden unnamed_addr constant [73 x i8], align 1

; Function Attrs: mustprogress uwtable
define dso_local noundef ptr @_ZN2rw4xbox15writeNativeDataEPNS_6StreamEiPvii(ptr noundef returned %0, i32 noundef %1, ptr nocapture noundef readonly %2, i32 noundef %3, i32 noundef %4) local_unnamed_addr #0 {
  %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 %107, label %11

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

13:                                               ; preds = %11
  %14 = tail call noundef i32 @_ZN2rw6Stream8writeU32Ej(ptr noundef nonnull align 8 dereferenceable(8) %0, i32 noundef 5)
  %15 = load i32, ptr @_ZN2rw7versionE, align 4, !tbaa !16
  %16 = icmp sgt i32 %15, 217087
  br i1 %16, label %18, label %17

17:                                               ; preds = %13
  tail call void @__assert_fail(ptr noundef nonnull @.str.9, ptr noundef nonnull @.str.1, i32 noundef 138, ptr noundef nonnull @__PRETTY_FUNCTION__._ZN2rw4xbox15writeNativeDataEPNS_6StreamEiPvii) #3
  unreachable

18:                                               ; preds = %13
  %19 = load ptr, ptr %8, align 8, !tbaa !5
  %20 = getelementptr inbounds i8, ptr %19, i64 56
  %21 = load ptr, ptr %20, align 8, !tbaa !17
  %22 = getelementptr inbounds i8, ptr %21, i64 24
  %23 = getelementptr inbounds i8, ptr %19, i64 4
  %24 = load i32, ptr %23, align 4, !tbaa !19
  store i32 %24, ptr %22, align 4, !tbaa !16
  %25 = getelementptr inbounds i8, ptr %21, i64 28
  %26 = getelementptr inbounds i8, ptr %19, i64 8
  %27 = load i16, ptr %26, align 8, !tbaa !20
  store i16 %27, ptr %25, align 2, !tbaa !21
  %28 = getelementptr inbounds i8, ptr %21, i64 30
  %29 = getelementptr inbounds i8, ptr %19, i64 10
  %30 = load i16, ptr %29, align 2, !tbaa !22
  store i16 %30, ptr %28, align 2, !tbaa !21
  %31 = getelementptr inbounds i8, ptr %21, i64 32
  %32 = getelementptr inbounds i8, ptr %19, i64 12
  %33 = load i32, ptr %32, align 4, !tbaa !23
  store i32 %33, ptr %31, align 4, !tbaa !16
  %34 = getelementptr inbounds i8, ptr %21, i64 36
  %35 = getelementptr inbounds i8, ptr %19, i64 16
  %36 = load i32, ptr %35, align 8, !tbaa !24
  store i32 %36, ptr %34, align 4, !tbaa !16
  %37 = getelementptr inbounds i8, ptr %21, i64 40
  %38 = getelementptr inbounds i8, ptr %19, i64 20
  %39 = load i32, ptr %38, align 4, !tbaa !25
  store i32 %39, ptr %37, align 4, !tbaa !16
  %40 = getelementptr inbounds i8, ptr %21, i64 48
  %41 = getelementptr inbounds i8, ptr %19, i64 32
  %42 = load i32, ptr %41, align 8, !tbaa !26
  store i32 %42, ptr %40, align 4, !tbaa !16
  %43 = zext i16 %30 to i32
  %.not66 = icmp eq i16 %30, 0
  br i1 %.not66, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %18
  %44 = getelementptr inbounds i8, ptr %19, i64 40
  %45 = load ptr, ptr %44, align 8, !tbaa !27
  %46 = getelementptr inbounds i8, ptr %21, i64 60
  %47 = ptrtoint ptr %21 to i64
  %xtraiter = and i32 %43, 1
  %48 = icmp eq i16 %30, 1
  br i1 %48, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph.new

.lr.ph.new:                                       ; preds = %.lr.ph
  %unroll_iter = and i32 %43, 65534
  br label %76

._crit_edge.loopexit.unr-lcssa:                   ; preds = %76, %.lr.ph
  %.05964.unr = phi ptr [ %45, %.lr.ph ], [ %106, %76 ]
  %.06063.unr = phi ptr [ %46, %.lr.ph ], [ %105, %76 ]
  %lcmp.mod.not = icmp eq i32 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge, label %._crit_edge.loopexit.epilog-lcssa

._crit_edge.loopexit.epilog-lcssa:                ; preds = %._crit_edge.loopexit.unr-lcssa
  %49 = load i32, ptr %.05964.unr, align 8, !tbaa !28
  store i32 %49, ptr %.06063.unr, align 4, !tbaa !16
  %50 = getelementptr inbounds i8, ptr %.06063.unr, i64 4
  %51 = getelementptr inbounds i8, ptr %.05964.unr, i64 4
  %52 = load i32, ptr %51, align 4, !tbaa !30
  store i32 %52, ptr %50, align 4, !tbaa !16
  %53 = getelementptr inbounds i8, ptr %.06063.unr, i64 8
  %54 = getelementptr inbounds i8, ptr %.05964.unr, i64 8
  %55 = load i32, ptr %54, align 8, !tbaa !31
  store i32 %55, ptr %53, align 4, !tbaa !16
  %56 = getelementptr inbounds i8, ptr %.06063.unr, i64 12
  %57 = getelementptr inbounds i8, ptr %.05964.unr, i64 16
  %58 = load ptr, ptr %57, align 8, !tbaa !32
  %59 = ptrtoint ptr %58 to i64
  %60 = sub i64 %59, %47
  %61 = trunc i64 %60 to i32
  store i32 %61, ptr %56, align 4, !tbaa !16
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit.epilog-lcssa, %._crit_edge.loopexit.unr-lcssa, %18
  %62 = load i32, ptr %23, align 4, !tbaa !19
  %63 = load ptr, ptr %0, align 8, !tbaa !33
  %64 = getelementptr inbounds i8, ptr %63, i64 24
  %65 = load ptr, ptr %64, align 8
  %66 = tail call noundef i32 %65(ptr noundef nonnull align 8 dereferenceable(8) %0, ptr noundef nonnull %22, i32 noundef %62)
  %67 = getelementptr inbounds i8, ptr %19, i64 24
  %68 = load ptr, ptr %67, align 8, !tbaa !35
  %69 = load i32, ptr %38, align 4, !tbaa !25
  %70 = load i32, ptr %35, align 8, !tbaa !24
  %71 = mul nsw i32 %70, %69
  %72 = load ptr, ptr %0, align 8, !tbaa !33
  %73 = getelementptr inbounds i8, ptr %72, i64 24
  %74 = load ptr, ptr %73, align 8
  %75 = tail call noundef i32 %74(ptr noundef nonnull align 8 dereferenceable(8) %0, ptr noundef %68, i32 noundef %71)
  br label %107

76:                                               ; preds = %76, %.lr.ph.new
  %.05964 = phi ptr [ %45, %.lr.ph.new ], [ %106, %76 ]
  %.06063 = phi ptr [ %46, %.lr.ph.new ], [ %105, %76 ]
  %niter = phi i32 [ 0, %.lr.ph.new ], [ %niter.next.1, %76 ]
  %77 = load i32, ptr %.05964, align 8, !tbaa !28
  store i32 %77, ptr %.06063, align 4, !tbaa !16
  %78 = getelementptr inbounds i8, ptr %.06063, i64 4
  %79 = getelementptr inbounds i8, ptr %.05964, i64 4
  %80 = load i32, ptr %79, align 4, !tbaa !30
  store i32 %80, ptr %78, align 4, !tbaa !16
  %81 = getelementptr inbounds i8, ptr %.06063, i64 8
  %82 = getelementptr inbounds i8, ptr %.05964, i64 8
  %83 = load i32, ptr %82, align 8, !tbaa !31
  store i32 %83, ptr %81, align 4, !tbaa !16
  %84 = getelementptr inbounds i8, ptr %.06063, i64 12
  %85 = getelementptr inbounds i8, ptr %.05964, i64 16
  %86 = load ptr, ptr %85, align 8, !tbaa !32
  %87 = ptrtoint ptr %86 to i64
  %88 = sub i64 %87, %47
  %89 = trunc i64 %88 to i32
  store i32 %89, ptr %84, align 4, !tbaa !16
  %90 = getelementptr inbounds i8, ptr %.06063, i64 24
  %91 = getelementptr inbounds i8, ptr %.05964, i64 40
  %92 = load i32, ptr %91, align 8, !tbaa !28
  store i32 %92, ptr %90, align 4, !tbaa !16
  %93 = getelementptr inbounds i8, ptr %.06063, i64 28
  %94 = getelementptr inbounds i8, ptr %.05964, i64 44
  %95 = load i32, ptr %94, align 4, !tbaa !30
  store i32 %95, ptr %93, align 4, !tbaa !16
  %96 = getelementptr inbounds i8, ptr %.06063, i64 32
  %97 = getelementptr inbounds i8, ptr %.05964, i64 48
  %98 = load i32, ptr %97, align 8, !tbaa !31
  store i32 %98, ptr %96, align 4, !tbaa !16
  %99 = getelementptr inbounds i8, ptr %.06063, i64 36
  %100 = getelementptr inbounds i8, ptr %.05964, i64 56
  %101 = load ptr, ptr %100, align 8, !tbaa !32
  %102 = ptrtoint ptr %101 to i64
  %103 = sub i64 %102, %47
  %104 = trunc i64 %103 to i32
  store i32 %104, ptr %99, align 4, !tbaa !16
  %105 = getelementptr inbounds i8, ptr %.06063, i64 48
  %106 = getelementptr inbounds i8, ptr %.05964, i64 80
  %niter.next.1 = add i32 %niter, 2
  %niter.ncmp.1 = icmp eq i32 %niter.next.1, %unroll_iter
  br i1 %niter.ncmp.1, label %._crit_edge.loopexit.unr-lcssa, label %76, !llvm.loop !36

107:                                              ; preds = %5, %11, %._crit_edge
  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

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #2

attributes #0 = { mustprogress uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #1 = { "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 = { noreturn nounwind "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 = { noreturn 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, !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 = !{!11, !11, i64 0}
!17 = !{!18, !10, i64 56}
!18 = !{!"_ZTSN2rw4xbox18InstanceDataHeaderE", !15, i64 0, !11, i64 4, !12, i64 8, !12, i64 10, !11, i64 12, !11, i64 16, !11, i64 20, !10, i64 24, !11, i64 32, !10, i64 40, !10, i64 48, !10, i64 56}
!19 = !{!18, !11, i64 4}
!20 = !{!18, !12, i64 8}
!21 = !{!12, !12, i64 0}
!22 = !{!18, !12, i64 10}
!23 = !{!18, !11, i64 12}
!24 = !{!18, !11, i64 16}
!25 = !{!18, !11, i64 20}
!26 = !{!18, !11, i64 32}
!27 = !{!18, !10, i64 40}
!28 = !{!29, !11, i64 0}
!29 = !{!"_ZTSN2rw4xbox12InstanceDataE", !11, i64 0, !11, i64 4, !11, i64 8, !10, i64 16, !10, i64 24, !11, i64 32}
!30 = !{!29, !11, i64 4}
!31 = !{!29, !11, i64 8}
!32 = !{!29, !10, i64 16}
!33 = !{!34, !34, i64 0}
!34 = !{!"vtable pointer", !9, i64 0}
!35 = !{!18, !10, i64 24}
!36 = distinct !{!36, !37}
!37 = !{!"llvm.loop.mustprogress"}


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