; LLVM IR from aap/librw :: src/skin.ll (ZN2rw18writeSkinSplitDataEPNS_6StreamEPNS_4SkinE)

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

; Function Attrs: mustprogress uwtable
define dso_local noundef ptr @_ZN2rw18writeSkinSplitDataEPNS_6StreamEPNS_4SkinE(ptr noundef %0, ptr noundef %1) #0 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  %5 = load ptr, ptr %3, align 8, !tbaa !5
  %6 = load ptr, ptr %4, align 8, !tbaa !5
  %7 = getelementptr inbounds %"struct.rw::Skin", ptr %6, i32 0, i32 7
  %8 = load i32, ptr %7, align 8, !tbaa !9
  %9 = call noundef i32 @_ZN2rw6Stream8writeI32Ei(ptr noundef nonnull align 8 dereferenceable(8) %5, i32 noundef %8)
  %10 = load ptr, ptr %3, align 8, !tbaa !5
  %11 = load ptr, ptr %4, align 8, !tbaa !5
  %12 = getelementptr inbounds %"struct.rw::Skin", ptr %11, i32 0, i32 8
  %13 = load i32, ptr %12, align 4, !tbaa !12
  %14 = call noundef i32 @_ZN2rw6Stream8writeI32Ei(ptr noundef nonnull align 8 dereferenceable(8) %10, i32 noundef %13)
  %15 = load ptr, ptr %3, align 8, !tbaa !5
  %16 = load ptr, ptr %4, align 8, !tbaa !5
  %17 = getelementptr inbounds %"struct.rw::Skin", ptr %16, i32 0, i32 9
  %18 = load i32, ptr %17, align 8, !tbaa !13
  %19 = call noundef i32 @_ZN2rw6Stream8writeI32Ei(ptr noundef nonnull align 8 dereferenceable(8) %15, i32 noundef %18)
  %20 = load ptr, ptr %4, align 8, !tbaa !5
  %21 = getelementptr inbounds %"struct.rw::Skin", ptr %20, i32 0, i32 8
  %22 = load i32, ptr %21, align 4, !tbaa !12
  %23 = icmp ne i32 %22, 0
  br i1 %23, label %24, label %45

24:                                               ; preds = %2
  %25 = load ptr, ptr %3, align 8, !tbaa !5
  %26 = load ptr, ptr %4, align 8, !tbaa !5
  %27 = getelementptr inbounds %"struct.rw::Skin", ptr %26, i32 0, i32 10
  %28 = load ptr, ptr %27, align 8, !tbaa !14
  %29 = load ptr, ptr %4, align 8, !tbaa !5
  %30 = getelementptr inbounds %"struct.rw::Skin", ptr %29, i32 0, i32 0
  %31 = load i32, ptr %30, align 8, !tbaa !15
  %32 = load ptr, ptr %4, align 8, !tbaa !5
  %33 = getelementptr inbounds %"struct.rw::Skin", ptr %32, i32 0, i32 8
  %34 = load i32, ptr %33, align 4, !tbaa !12
  %35 = load ptr, ptr %4, align 8, !tbaa !5
  %36 = getelementptr inbounds %"struct.rw::Skin", ptr %35, i32 0, i32 9
  %37 = load i32, ptr %36, align 8, !tbaa !13
  %38 = add nsw i32 %34, %37
  %39 = mul nsw i32 2, %38
  %40 = add nsw i32 %31, %39
  %41 = load ptr, ptr %25, align 8, !tbaa !16
  %42 = getelementptr inbounds ptr, ptr %41, i64 3
  %43 = load ptr, ptr %42, align 8
  %44 = call noundef i32 %43(ptr noundef nonnull align 8 dereferenceable(8) %25, ptr noundef %28, i32 noundef %40)
  br label %45

45:                                               ; preds = %24, %2
  %46 = load ptr, ptr %3, align 8, !tbaa !5
  ret ptr %46
}

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

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

!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, !11, i64 48}
!10 = !{!"_ZTSN2rw4SkinE", !11, i64 0, !11, i64 4, !11, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !11, i64 48, !11, i64 52, !11, i64 56, !6, i64 64, !6, i64 72, !6, i64 80, !6, i64 88, !6, i64 96, !11, i64 104}
!11 = !{!"int", !7, i64 0}
!12 = !{!10, !11, i64 52}
!13 = !{!10, !11, i64 56}
!14 = !{!10, !6, i64 64}
!15 = !{!10, !11, i64 0}
!16 = !{!17, !17, i64 0}
!17 = !{!"vtable pointer", !8, i64 0}


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

; Function Attrs: mustprogress uwtable
define dso_local noundef ptr @_ZN2rw18writeSkinSplitDataEPNS_6StreamEPNS_4SkinE(ptr noundef nonnull returned %0, ptr nocapture noundef readonly %1) local_unnamed_addr #0 {
  %3 = getelementptr inbounds i8, ptr %1, i64 48
  %4 = load i32, ptr %3, align 8, !tbaa !5
  %5 = tail call noundef i32 @_ZN2rw6Stream8writeI32Ei(ptr noundef nonnull align 8 dereferenceable(8) %0, i32 noundef %4)
  %6 = getelementptr inbounds i8, ptr %1, i64 52
  %7 = load i32, ptr %6, align 4, !tbaa !11
  %8 = tail call noundef i32 @_ZN2rw6Stream8writeI32Ei(ptr noundef nonnull align 8 dereferenceable(8) %0, i32 noundef %7)
  %9 = getelementptr inbounds i8, ptr %1, i64 56
  %10 = load i32, ptr %9, align 8, !tbaa !12
  %11 = tail call noundef i32 @_ZN2rw6Stream8writeI32Ei(ptr noundef nonnull align 8 dereferenceable(8) %0, i32 noundef %10)
  %12 = load i32, ptr %6, align 4, !tbaa !11
  %.not = icmp eq i32 %12, 0
  br i1 %.not, label %25, label %13

13:                                               ; preds = %2
  %14 = getelementptr inbounds i8, ptr %1, i64 64
  %15 = load ptr, ptr %14, align 8, !tbaa !13
  %16 = load i32, ptr %1, align 8, !tbaa !14
  %17 = load i32, ptr %9, align 8, !tbaa !12
  %18 = add nsw i32 %17, %12
  %19 = shl nsw i32 %18, 1
  %20 = add nsw i32 %19, %16
  %21 = load ptr, ptr %0, align 8, !tbaa !15
  %22 = getelementptr inbounds i8, ptr %21, i64 24
  %23 = load ptr, ptr %22, align 8
  %24 = tail call noundef i32 %23(ptr noundef nonnull align 8 dereferenceable(8) %0, ptr noundef %15, i32 noundef %20)
  br label %25

25:                                               ; preds = %13, %2
  ret ptr %0
}

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

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

!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, !7, i64 48}
!6 = !{!"_ZTSN2rw4SkinE", !7, i64 0, !7, i64 4, !7, i64 8, !10, i64 16, !10, i64 24, !10, i64 32, !10, i64 40, !7, i64 48, !7, i64 52, !7, i64 56, !10, i64 64, !10, i64 72, !10, i64 80, !10, i64 88, !10, i64 96, !7, i64 104}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!6, !7, i64 52}
!12 = !{!6, !7, i64 56}
!13 = !{!6, !10, i64 64}
!14 = !{!6, !7, i64 0}
!15 = !{!16, !16, i64 0}
!16 = !{!"vtable pointer", !9, i64 0}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InstCombinePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,TailCallElimPass