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

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

@_ZN2rw7versionE = external global i32, align 4

; 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 @_ZN2rw3ps215writeNativeSkinEPNS_6StreamEiPvi(ptr noundef %0, i32 noundef %1, ptr noundef %2, i32 noundef %3) #1 {
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca [4 x i8], align 1
  %10 = alloca ptr, align 8
  %11 = alloca i8, align 1
  %12 = alloca [4 x i32], align 16
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !9
  store ptr %2, ptr %7, align 8, !tbaa !5
  store i32 %3, ptr %8, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  %13 = load ptr, ptr %5, align 8, !tbaa !5
  %14 = load i32, ptr %6, align 4, !tbaa !9
  %15 = sub nsw i32 %14, 12
  %16 = call noundef zeroext i1 @_ZN2rw16writeChunkHeaderEPNS_6StreamEii(ptr noundef %13, i32 noundef 1, i32 noundef %15)
  %17 = load ptr, ptr %5, align 8, !tbaa !5
  %18 = call noundef i32 @_ZN2rw6Stream8writeU32Ej(ptr noundef nonnull align 8 dereferenceable(8) %17, i32 noundef 4)
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  %19 = load ptr, ptr %7, align 8, !tbaa !5
  %20 = load i32, ptr %8, align 4, !tbaa !9
  %21 = sext i32 %20 to i64
  %22 = getelementptr inbounds i8, ptr %19, i64 %21
  %23 = load ptr, ptr %22, align 8, !tbaa !5
  store ptr %23, ptr %10, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 1, ptr %11) #4
  %24 = load i32, ptr @_ZN2rw7versionE, align 4, !tbaa !9
  %25 = icmp slt i32 %24, 212992
  %26 = zext i1 %25 to i8
  store i8 %26, ptr %11, align 1, !tbaa !11
  %27 = load ptr, ptr %10, align 8, !tbaa !5
  %28 = getelementptr inbounds %"struct.rw::Skin", ptr %27, i32 0, i32 0
  %29 = load i32, ptr %28, align 8, !tbaa !13
  %30 = trunc i32 %29 to i8
  %31 = getelementptr inbounds [4 x i8], ptr %9, i64 0, i64 0
  store i8 %30, ptr %31, align 1, !tbaa !15
  %32 = load i8, ptr %11, align 1, !tbaa !11, !range !16, !noundef !17
  %33 = trunc i8 %32 to i1
  br i1 %33, label %34, label %37

34:                                               ; preds = %4
  %35 = getelementptr inbounds [4 x i8], ptr %9, i64 0, i64 1
  store i8 0, ptr %35, align 1, !tbaa !15
  %36 = getelementptr inbounds [4 x i8], ptr %9, i64 0, i64 2
  store i8 0, ptr %36, align 1, !tbaa !15
  br label %48

37:                                               ; preds = %4
  %38 = load ptr, ptr %10, align 8, !tbaa !5
  %39 = getelementptr inbounds %"struct.rw::Skin", ptr %38, i32 0, i32 1
  %40 = load i32, ptr %39, align 4, !tbaa !18
  %41 = trunc i32 %40 to i8
  %42 = getelementptr inbounds [4 x i8], ptr %9, i64 0, i64 1
  store i8 %41, ptr %42, align 1, !tbaa !15
  %43 = load ptr, ptr %10, align 8, !tbaa !5
  %44 = getelementptr inbounds %"struct.rw::Skin", ptr %43, i32 0, i32 2
  %45 = load i32, ptr %44, align 8, !tbaa !19
  %46 = trunc i32 %45 to i8
  %47 = getelementptr inbounds [4 x i8], ptr %9, i64 0, i64 2
  store i8 %46, ptr %47, align 1, !tbaa !15
  br label %48

48:                                               ; preds = %37, %34
  %49 = getelementptr inbounds [4 x i8], ptr %9, i64 0, i64 3
  store i8 0, ptr %49, align 1, !tbaa !15
  %50 = load ptr, ptr %5, align 8, !tbaa !5
  %51 = getelementptr inbounds [4 x i8], ptr %9, i64 0, i64 0
  %52 = load ptr, ptr %50, align 8, !tbaa !20
  %53 = getelementptr inbounds ptr, ptr %52, i64 3
  %54 = load ptr, ptr %53, align 8
  %55 = call noundef i32 %54(ptr noundef nonnull align 8 dereferenceable(8) %50, ptr noundef %51, i32 noundef 4)
  %56 = load i8, ptr %11, align 1, !tbaa !11, !range !16, !noundef !17
  %57 = trunc i8 %56 to i1
  br i1 %57, label %70, label %58

58:                                               ; preds = %48
  %59 = load ptr, ptr %5, align 8, !tbaa !5
  %60 = load ptr, ptr %10, align 8, !tbaa !5
  %61 = getelementptr inbounds %"struct.rw::Skin", ptr %60, i32 0, i32 3
  %62 = load ptr, ptr %61, align 8, !tbaa !22
  %63 = load ptr, ptr %10, align 8, !tbaa !5
  %64 = getelementptr inbounds %"struct.rw::Skin", ptr %63, i32 0, i32 1
  %65 = load i32, ptr %64, align 4, !tbaa !18
  %66 = load ptr, ptr %59, align 8, !tbaa !20
  %67 = getelementptr inbounds ptr, ptr %66, i64 3
  %68 = load ptr, ptr %67, align 8
  %69 = call noundef i32 %68(ptr noundef nonnull align 8 dereferenceable(8) %59, ptr noundef %62, i32 noundef %65)
  br label %70

70:                                               ; preds = %58, %48
  %71 = load ptr, ptr %5, align 8, !tbaa !5
  %72 = load ptr, ptr %10, align 8, !tbaa !5
  %73 = getelementptr inbounds %"struct.rw::Skin", ptr %72, i32 0, i32 4
  %74 = load ptr, ptr %73, align 8, !tbaa !23
  %75 = load ptr, ptr %10, align 8, !tbaa !5
  %76 = getelementptr inbounds %"struct.rw::Skin", ptr %75, i32 0, i32 0
  %77 = load i32, ptr %76, align 8, !tbaa !13
  %78 = mul nsw i32 %77, 64
  %79 = call noundef i32 @_ZN2rw6Stream7write32EPKvj(ptr noundef nonnull align 8 dereferenceable(8) %71, ptr noundef %74, i32 noundef %78)
  %80 = load i8, ptr %11, align 1, !tbaa !11, !range !16, !noundef !17
  %81 = trunc i8 %80 to i1
  br i1 %81, label %89, label %82

82:                                               ; preds = %70
  call void @llvm.lifetime.start.p0(i64 16, ptr %12) #4
  call void @llvm.memset.p0.i64(ptr align 16 %12, i8 0, i64 16, i1 false)
  %83 = load ptr, ptr %5, align 8, !tbaa !5
  %84 = getelementptr inbounds [4 x i32], ptr %12, i64 0, i64 0
  %85 = call noundef i32 @_ZN2rw6Stream7write32EPKvj(ptr noundef nonnull align 8 dereferenceable(8) %83, ptr noundef %84, i32 noundef 16)
  %86 = load ptr, ptr %5, align 8, !tbaa !5
  %87 = load ptr, ptr %10, align 8, !tbaa !5
  %88 = call noundef ptr @_ZN2rw18writeSkinSplitDataEPNS_6StreamEPNS_4SkinE(ptr noundef %86, ptr noundef %87)
  call void @llvm.lifetime.end.p0(i64 16, ptr %12) #4
  br label %89

89:                                               ; preds = %82, %70
  %90 = load ptr, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 1, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  ret ptr %90
}

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 @_ZN2rw6Stream7write32EPKvj(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef, i32 noundef) #2

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

declare noundef ptr @_ZN2rw18writeSkinSplitDataEPNS_6StreamEPNS_4SkinE(ptr noundef, ptr noundef) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #2 = { "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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
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, !12, i64 0}
!12 = !{!"bool", !7, i64 0}
!13 = !{!14, !10, i64 0}
!14 = !{!"_ZTSN2rw4SkinE", !10, i64 0, !10, i64 4, !10, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !10, i64 48, !10, i64 52, !10, i64 56, !6, i64 64, !6, i64 72, !6, i64 80, !6, i64 88, !6, i64 96, !10, i64 104}
!15 = !{!7, !7, i64 0}
!16 = !{i8 0, i8 2}
!17 = !{}
!18 = !{!14, !10, i64 4}
!19 = !{!14, !10, i64 8}
!20 = !{!21, !21, i64 0}
!21 = !{!"vtable pointer", !8, i64 0}
!22 = !{!14, !6, i64 16}
!23 = !{!14, !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"

@_ZN2rw7versionE = external local_unnamed_addr global i32, align 4

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: mustprogress 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 @_ZN2rw3ps215writeNativeSkinEPNS_6StreamEiPvi(ptr noundef returned %0, i32 noundef %1, ptr nocapture noundef readonly %2, i32 noundef %3) local_unnamed_addr #1 {
  %5 = alloca [4 x i8], align 1
  %6 = alloca [4 x i32], align 16
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %5) #4
  %7 = add nsw i32 %1, -12
  %8 = tail call noundef zeroext i1 @_ZN2rw16writeChunkHeaderEPNS_6StreamEii(ptr noundef %0, i32 noundef 1, i32 noundef %7)
  %9 = tail call noundef i32 @_ZN2rw6Stream8writeU32Ej(ptr noundef nonnull align 8 dereferenceable(8) %0, i32 noundef 4)
  %10 = sext i32 %3 to i64
  %11 = getelementptr inbounds i8, ptr %2, i64 %10
  %12 = load ptr, ptr %11, align 8, !tbaa !5
  %13 = load i32, ptr @_ZN2rw7versionE, align 4, !tbaa !9
  %14 = icmp slt i32 %13, 212992
  %15 = load i32, ptr %12, align 8, !tbaa !11
  %16 = trunc i32 %15 to i8
  store i8 %16, ptr %5, align 1, !tbaa !13
  br i1 %14, label %.critedge.critedge, label %17

17:                                               ; preds = %4
  %18 = getelementptr inbounds i8, ptr %12, i64 4
  %19 = load i32, ptr %18, align 4, !tbaa !14
  %20 = trunc i32 %19 to i8
  %21 = getelementptr inbounds i8, ptr %12, i64 8
  %22 = load i32, ptr %21, align 8, !tbaa !15
  %23 = trunc i32 %22 to i8
  %24 = getelementptr inbounds i8, ptr %5, i64 1
  store i8 %20, ptr %24, align 1
  %25 = getelementptr inbounds i8, ptr %5, i64 2
  store i8 %23, ptr %25, align 1
  %26 = getelementptr inbounds i8, ptr %5, i64 3
  store i8 0, ptr %26, align 1, !tbaa !13
  %27 = load ptr, ptr %0, align 8, !tbaa !16
  %28 = getelementptr inbounds i8, ptr %27, i64 24
  %29 = load ptr, ptr %28, align 8
  %30 = call noundef i32 %29(ptr noundef nonnull align 8 dereferenceable(8) %0, ptr noundef nonnull %5, i32 noundef 4)
  %31 = getelementptr inbounds i8, ptr %12, i64 16
  %32 = load ptr, ptr %31, align 8, !tbaa !18
  %33 = getelementptr inbounds i8, ptr %12, i64 4
  %34 = load i32, ptr %33, align 4, !tbaa !14
  %35 = load ptr, ptr %0, align 8, !tbaa !16
  %36 = getelementptr inbounds i8, ptr %35, i64 24
  %37 = load ptr, ptr %36, align 8
  %38 = call noundef i32 %37(ptr noundef nonnull align 8 dereferenceable(8) %0, ptr noundef %32, i32 noundef %34)
  %39 = getelementptr inbounds i8, ptr %12, i64 24
  %40 = load ptr, ptr %39, align 8, !tbaa !19
  %41 = load i32, ptr %12, align 8, !tbaa !11
  %42 = shl nsw i32 %41, 6
  %43 = call noundef i32 @_ZN2rw6Stream7write32EPKvj(ptr noundef nonnull align 8 dereferenceable(8) %0, ptr noundef %40, i32 noundef %42)
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %6) #4
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(16) %6, i8 0, i64 16, i1 false)
  %44 = call noundef i32 @_ZN2rw6Stream7write32EPKvj(ptr noundef nonnull align 8 dereferenceable(8) %0, ptr noundef nonnull %6, i32 noundef 16)
  %45 = call noundef ptr @_ZN2rw18writeSkinSplitDataEPNS_6StreamEPNS_4SkinE(ptr noundef nonnull %0, ptr noundef nonnull %12)
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %6) #4
  br label %58

.critedge.critedge:                               ; preds = %4
  %46 = getelementptr inbounds i8, ptr %5, i64 1
  store i8 0, ptr %46, align 1
  %47 = getelementptr inbounds i8, ptr %5, i64 2
  store i8 0, ptr %47, align 1
  %48 = getelementptr inbounds i8, ptr %5, i64 3
  store i8 0, ptr %48, align 1, !tbaa !13
  %49 = load ptr, ptr %0, align 8, !tbaa !16
  %50 = getelementptr inbounds i8, ptr %49, i64 24
  %51 = load ptr, ptr %50, align 8
  %52 = call noundef i32 %51(ptr noundef nonnull align 8 dereferenceable(8) %0, ptr noundef nonnull %5, i32 noundef 4)
  %53 = getelementptr inbounds i8, ptr %12, i64 24
  %54 = load ptr, ptr %53, align 8, !tbaa !19
  %55 = load i32, ptr %12, align 8, !tbaa !11
  %56 = shl nsw i32 %55, 6
  %57 = call noundef i32 @_ZN2rw6Stream7write32EPKvj(ptr noundef nonnull align 8 dereferenceable(8) %0, ptr noundef %54, i32 noundef %56)
  br label %58

58:                                               ; preds = %.critedge.critedge, %17
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %5) #4
  ret ptr %0
}

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

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

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

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

declare noundef ptr @_ZN2rw18writeSkinSplitDataEPNS_6StreamEPNS_4SkinE(ptr noundef, ptr noundef) local_unnamed_addr #2

attributes #0 = { mustprogress 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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
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, !10, i64 0}
!12 = !{!"_ZTSN2rw4SkinE", !10, i64 0, !10, i64 4, !10, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !10, i64 48, !10, i64 52, !10, i64 56, !6, i64 64, !6, i64 72, !6, i64 80, !6, i64 88, !6, i64 96, !10, i64 104}
!13 = !{!7, !7, i64 0}
!14 = !{!12, !10, i64 4}
!15 = !{!12, !10, i64 8}
!16 = !{!17, !17, i64 0}
!17 = !{!"vtable pointer", !8, i64 0}
!18 = !{!12, !6, i64 16}
!19 = !{!12, !6, i64 24}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,MergedLoadStoreMotionPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass