; LLVM IR from aap/librw :: src/texture.ll (ZN2rw13TexDictionary11streamWriteEPNS_6StreamE)

; 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::PluginList" = type { i32, i32, %"struct.rw::LinkList" }
%"struct.rw::LinkList" = type { %"struct.rw::LLLink" }
%"struct.rw::LLLink" = type { ptr, ptr }
%"struct.rw::TexDictionary" = type { %"struct.rw::Object", %"struct.rw::LinkList", %"struct.rw::LLLink" }
%"struct.rw::Object" = type { i8, i8, i8, i8, ptr }

@_ZN2rw13TexDictionary9s_plglistE = external dso_local global %"struct.rw::PluginList", align 8
@_ZN2rw7Texture9s_plglistE = external dso_local global %"struct.rw::PluginList", align 8

; 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 nounwind uwtable
declare dso_local noundef ptr @_ZN2rw8LinkList3endEv(ptr noundef nonnull align 8 dereferenceable(16)) #1 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZN2rw7Texture8fromDictEPNS_6LLLinkE(ptr noundef) #1 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN2rw13TexDictionary11streamWriteEPNS_6StreamE(ptr noundef nonnull align 8 dereferenceable(48) %0, ptr noundef %1) #2 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  %10 = load ptr, ptr %3, align 8
  %11 = load ptr, ptr %4, align 8, !tbaa !5
  %12 = call noundef i32 @_ZN2rw13TexDictionary13streamGetSizeEv(ptr noundef nonnull align 8 dereferenceable(48) %10)
  %13 = call noundef zeroext i1 @_ZN2rw16writeChunkHeaderEPNS_6StreamEii(ptr noundef %11, i32 noundef 22, i32 noundef %12)
  %14 = load ptr, ptr %4, align 8, !tbaa !5
  %15 = call noundef zeroext i1 @_ZN2rw16writeChunkHeaderEPNS_6StreamEii(ptr noundef %14, i32 noundef 1, i32 noundef 4)
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  %16 = call noundef i32 @_ZN2rw13TexDictionary5countEv(ptr noundef nonnull align 8 dereferenceable(48) %10)
  store i32 %16, ptr %5, align 4, !tbaa !9
  %17 = load ptr, ptr %4, align 8, !tbaa !5
  %18 = load i32, ptr %5, align 4, !tbaa !9
  %19 = trunc i32 %18 to i16
  %20 = call noundef i32 @_ZN2rw6Stream8writeI16Es(ptr noundef nonnull align 8 dereferenceable(8) %17, i16 noundef signext %19)
  %21 = load ptr, ptr %4, align 8, !tbaa !5
  %22 = call noundef i32 @_ZN2rw6Stream8writeI16Es(ptr noundef nonnull align 8 dereferenceable(8) %21, i16 noundef signext 0)
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  store ptr null, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  %23 = getelementptr inbounds %"struct.rw::TexDictionary", ptr %10, i32 0, i32 1
  %24 = getelementptr inbounds %"struct.rw::LinkList", ptr %23, i32 0, i32 0
  %25 = getelementptr inbounds %"struct.rw::LLLink", ptr %24, i32 0, i32 0
  %26 = load ptr, ptr %25, align 8, !tbaa !11
  store ptr %26, ptr %7, align 8, !tbaa !5
  br label %27

27:                                               ; preds = %53, %2
  %28 = load ptr, ptr %7, align 8, !tbaa !5
  %29 = getelementptr inbounds %"struct.rw::LLLink", ptr %28, i32 0, i32 0
  %30 = load ptr, ptr %29, align 8, !tbaa !16
  store ptr %30, ptr %6, align 8, !tbaa !5
  %31 = load ptr, ptr %7, align 8, !tbaa !5
  %32 = getelementptr inbounds %"struct.rw::TexDictionary", ptr %10, i32 0, i32 1
  %33 = call noundef ptr @_ZN2rw8LinkList3endEv(ptr noundef nonnull align 8 dereferenceable(16) %32)
  %34 = icmp ne ptr %31, %33
  br i1 %34, label %36, label %35

35:                                               ; preds = %27
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  br label %55

36:                                               ; preds = %27
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  %37 = load ptr, ptr %7, align 8, !tbaa !5
  %38 = call noundef ptr @_ZN2rw7Texture8fromDictEPNS_6LLLinkE(ptr noundef %37)
  store ptr %38, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  %39 = load ptr, ptr %8, align 8, !tbaa !5
  %40 = call noundef i32 @_ZN2rw7Texture19streamGetSizeNativeEv(ptr noundef nonnull align 8 dereferenceable(120) %39)
  store i32 %40, ptr %9, align 4, !tbaa !9
  %41 = load ptr, ptr %8, align 8, !tbaa !5
  %42 = call noundef i32 @_ZN2rw10PluginList13streamGetSizeEPv(ptr noundef nonnull align 8 dereferenceable(24) @_ZN2rw7Texture9s_plglistE, ptr noundef %41)
  %43 = add nsw i32 12, %42
  %44 = load i32, ptr %9, align 4, !tbaa !9
  %45 = add i32 %44, %43
  store i32 %45, ptr %9, align 4, !tbaa !9
  %46 = load ptr, ptr %4, align 8, !tbaa !5
  %47 = load i32, ptr %9, align 4, !tbaa !9
  %48 = call noundef zeroext i1 @_ZN2rw16writeChunkHeaderEPNS_6StreamEii(ptr noundef %46, i32 noundef 21, i32 noundef %47)
  %49 = load ptr, ptr %8, align 8, !tbaa !5
  %50 = load ptr, ptr %4, align 8, !tbaa !5
  call void @_ZN2rw7Texture17streamWriteNativeEPNS_6StreamE(ptr noundef nonnull align 8 dereferenceable(120) %49, ptr noundef %50)
  %51 = load ptr, ptr %4, align 8, !tbaa !5
  %52 = load ptr, ptr %8, align 8, !tbaa !5
  call void @_ZN2rw10PluginList11streamWriteEPNS_6StreamEPv(ptr noundef nonnull align 8 dereferenceable(24) @_ZN2rw7Texture9s_plglistE, ptr noundef %51, ptr noundef %52)
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  br label %53

53:                                               ; preds = %36
  %54 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %54, ptr %7, align 8, !tbaa !5
  br label %27, !llvm.loop !17

55:                                               ; preds = %35
  %56 = load ptr, ptr %4, align 8, !tbaa !5
  call void @_ZN2rw10PluginList11streamWriteEPNS_6StreamEPv(ptr noundef nonnull align 8 dereferenceable(24) @_ZN2rw13TexDictionary9s_plglistE, ptr noundef %56, ptr noundef %10)
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  ret void
}

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

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_ZN2rw13TexDictionary13streamGetSizeEv(ptr noundef nonnull align 8 dereferenceable(48)) #2 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_ZN2rw13TexDictionary5countEv(ptr noundef nonnull align 8 dereferenceable(48)) #2 align 2

declare noundef i32 @_ZN2rw6Stream8writeI16Es(ptr noundef nonnull align 8 dereferenceable(8), i16 noundef signext) #3

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_ZN2rw7Texture19streamGetSizeNativeEv(ptr noundef nonnull align 8 dereferenceable(120)) #2 align 2

declare noundef i32 @_ZN2rw10PluginList13streamGetSizeEPv(ptr noundef nonnull align 8 dereferenceable(24), ptr noundef) #3

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN2rw7Texture17streamWriteNativeEPNS_6StreamE(ptr noundef nonnull align 8 dereferenceable(120), ptr noundef) #2 align 2

declare void @_ZN2rw10PluginList11streamWriteEPNS_6StreamEPv(ptr noundef nonnull align 8 dereferenceable(24), ptr noundef, ptr noundef) #3

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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" }
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 = { 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 16}
!12 = !{!"_ZTSN2rw13TexDictionaryE", !13, i64 0, !14, i64 16, !15, i64 32}
!13 = !{!"_ZTSN2rw6ObjectE", !7, i64 0, !7, i64 1, !7, i64 2, !7, i64 3, !6, i64 8}
!14 = !{!"_ZTSN2rw8LinkListE", !15, i64 0}
!15 = !{!"_ZTSN2rw6LLLinkE", !6, i64 0, !6, i64 8}
!16 = !{!15, !6, i64 0}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}


; 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::PluginList" = type { i32, i32, %"struct.rw::LinkList" }
%"struct.rw::LinkList" = type { %"struct.rw::LLLink" }
%"struct.rw::LLLink" = type { ptr, ptr }

@_ZN2rw13TexDictionary9s_plglistE = external dso_local global %"struct.rw::PluginList", align 8
@_ZN2rw7Texture9s_plglistE = external dso_local global %"struct.rw::PluginList", align 8

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZN2rw7Texture8fromDictEPNS_6LLLinkE(ptr noundef) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN2rw13TexDictionary11streamWriteEPNS_6StreamE(ptr noundef nonnull align 8 dereferenceable(48) %0, ptr noundef %1) local_unnamed_addr #1 align 2 {
  %3 = tail call noundef i32 @_ZN2rw13TexDictionary13streamGetSizeEv(ptr noundef nonnull align 8 dereferenceable(48) %0)
  %4 = tail call noundef zeroext i1 @_ZN2rw16writeChunkHeaderEPNS_6StreamEii(ptr noundef %1, i32 noundef 22, i32 noundef %3)
  %5 = tail call noundef zeroext i1 @_ZN2rw16writeChunkHeaderEPNS_6StreamEii(ptr noundef %1, i32 noundef 1, i32 noundef 4)
  %6 = tail call noundef i32 @_ZN2rw13TexDictionary5countEv(ptr noundef nonnull align 8 dereferenceable(48) %0)
  %7 = trunc i32 %6 to i16
  %8 = tail call noundef i32 @_ZN2rw6Stream8writeI16Es(ptr noundef nonnull align 8 dereferenceable(8) %1, i16 noundef signext %7)
  %9 = tail call noundef i32 @_ZN2rw6Stream8writeI16Es(ptr noundef nonnull align 8 dereferenceable(8) %1, i16 noundef signext 0)
  %10 = getelementptr inbounds i8, ptr %0, i64 16
  %11 = load ptr, ptr %10, align 8, !tbaa !5
  %12 = load ptr, ptr %11, align 8, !tbaa !13
  %13 = tail call noundef ptr @_ZN2rw8LinkList3endEv(ptr noundef nonnull align 8 dereferenceable(16) %10)
  %.not19 = icmp eq ptr %11, %13
  br i1 %.not19, label %._crit_edge, label %.lr.ph

._crit_edge:                                      ; preds = %.lr.ph, %2
  tail call void @_ZN2rw10PluginList11streamWriteEPNS_6StreamEPv(ptr noundef nonnull align 8 dereferenceable(24) @_ZN2rw13TexDictionary9s_plglistE, ptr noundef nonnull %1, ptr noundef nonnull %0)
  ret void

.lr.ph:                                           ; preds = %2, %.lr.ph
  %14 = phi ptr [ %21, %.lr.ph ], [ %12, %2 ]
  %.020 = phi ptr [ %14, %.lr.ph ], [ %11, %2 ]
  %15 = tail call noundef ptr @_ZN2rw7Texture8fromDictEPNS_6LLLinkE(ptr noundef nonnull %.020)
  %16 = tail call noundef i32 @_ZN2rw7Texture19streamGetSizeNativeEv(ptr noundef nonnull align 8 dereferenceable(120) %15)
  %17 = tail call noundef i32 @_ZN2rw10PluginList13streamGetSizeEPv(ptr noundef nonnull align 8 dereferenceable(24) @_ZN2rw7Texture9s_plglistE, ptr noundef nonnull %15)
  %18 = add i32 %16, 12
  %19 = add i32 %18, %17
  %20 = tail call noundef zeroext i1 @_ZN2rw16writeChunkHeaderEPNS_6StreamEii(ptr noundef nonnull %1, i32 noundef 21, i32 noundef %19)
  tail call void @_ZN2rw7Texture17streamWriteNativeEPNS_6StreamE(ptr noundef nonnull align 8 dereferenceable(120) %15, ptr noundef nonnull %1)
  tail call void @_ZN2rw10PluginList11streamWriteEPNS_6StreamEPv(ptr noundef nonnull align 8 dereferenceable(24) @_ZN2rw7Texture9s_plglistE, ptr noundef nonnull %1, ptr noundef nonnull %15)
  %21 = load ptr, ptr %14, align 8, !tbaa !13
  %22 = tail call noundef ptr @_ZN2rw8LinkList3endEv(ptr noundef nonnull align 8 dereferenceable(16) %10)
  %.not = icmp eq ptr %14, %22
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !14
}

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

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_ZN2rw13TexDictionary13streamGetSizeEv(ptr noundef nonnull align 8 dereferenceable(48)) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_ZN2rw13TexDictionary5countEv(ptr noundef nonnull align 8 dereferenceable(48)) local_unnamed_addr #1 align 2

declare noundef i32 @_ZN2rw6Stream8writeI16Es(ptr noundef nonnull align 8 dereferenceable(8), i16 noundef signext) local_unnamed_addr #2

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_ZN2rw7Texture19streamGetSizeNativeEv(ptr noundef nonnull align 8 dereferenceable(120)) local_unnamed_addr #1 align 2

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN2rw7Texture17streamWriteNativeEPNS_6StreamE(ptr noundef nonnull align 8 dereferenceable(120), ptr noundef) local_unnamed_addr #1 align 2

declare void @_ZN2rw10PluginList11streamWriteEPNS_6StreamEPv(ptr noundef nonnull align 8 dereferenceable(24), ptr noundef, ptr noundef) local_unnamed_addr #2

attributes #0 = { 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 #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" }

!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 16}
!6 = !{!"_ZTSN2rw13TexDictionaryE", !7, i64 0, !11, i64 16, !12, i64 32}
!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 = !{!"_ZTSN2rw8LinkListE", !12, i64 0}
!12 = !{!"_ZTSN2rw6LLLinkE", !10, i64 0, !10, i64 8}
!13 = !{!12, !10, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}


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