; LLVM IR from aap/librw :: src/texture.ll (ZN2rw7Texture11streamWriteEPNS_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::Texture" = type { ptr, ptr, %"struct.rw::LLLink", [32 x i8], [32 x i8], i32, i32, %"struct.rw::LLLink" }
%"struct.rw::Raster" = type { i32, i32, i32, i32, i32, i32, i32, i32, i32, ptr, ptr, ptr, i32, i32, i32, ptr, i32, i32 }

@_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

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

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

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

; Function Attrs: nounwind
declare ptr @strncpy(ptr noundef, ptr noundef, i64 noundef) #3

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZN2rw7Texture11streamWriteEPNS_6StreamE(ptr noundef nonnull align 8 dereferenceable(120) %0, ptr noundef %1) #4 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca [36 x i8], align 16
  %7 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  %8 = load ptr, ptr %3, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #6
  call void @llvm.lifetime.start.p0(i64 36, ptr %6) #6
  %9 = load ptr, ptr %4, align 8, !tbaa !5
  %10 = call noundef i32 @_ZN2rw7Texture13streamGetSizeEv(ptr noundef nonnull align 8 dereferenceable(120) %8)
  %11 = call noundef zeroext i1 @_ZN2rw16writeChunkHeaderEPNS_6StreamEii(ptr noundef %9, i32 noundef 6, i32 noundef %10)
  %12 = load ptr, ptr %4, align 8, !tbaa !5
  %13 = call noundef zeroext i1 @_ZN2rw16writeChunkHeaderEPNS_6StreamEii(ptr noundef %12, i32 noundef 1, i32 noundef 4)
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #6
  %14 = getelementptr inbounds %"struct.rw::Texture", ptr %8, i32 0, i32 5
  %15 = load i32, ptr %14, align 8, !tbaa !9
  store i32 %15, ptr %7, align 4, !tbaa !13
  %16 = getelementptr inbounds %"struct.rw::Texture", ptr %8, i32 0, i32 0
  %17 = load ptr, ptr %16, align 8, !tbaa !14
  %18 = icmp ne ptr %17, null
  br i1 %18, label %19, label %29

19:                                               ; preds = %2
  %20 = getelementptr inbounds %"struct.rw::Texture", ptr %8, i32 0, i32 0
  %21 = load ptr, ptr %20, align 8, !tbaa !14
  %22 = getelementptr inbounds %"struct.rw::Raster", ptr %21, i32 0, i32 4
  %23 = load i32, ptr %22, align 8, !tbaa !15
  %24 = and i32 %23, 4096
  %25 = icmp eq i32 %24, 0
  br i1 %25, label %26, label %29

26:                                               ; preds = %19
  %27 = load i32, ptr %7, align 4, !tbaa !13
  %28 = or i32 %27, 65536
  store i32 %28, ptr %7, align 4, !tbaa !13
  br label %29

29:                                               ; preds = %26, %19, %2
  %30 = load ptr, ptr %4, align 8, !tbaa !5
  %31 = load i32, ptr %7, align 4, !tbaa !13
  %32 = call noundef i32 @_ZN2rw6Stream8writeU32Ej(ptr noundef nonnull align 8 dereferenceable(8) %30, i32 noundef %31)
  %33 = getelementptr inbounds [36 x i8], ptr %6, i64 0, i64 0
  call void @llvm.memset.p0.i64(ptr align 16 %33, i8 0, i64 36, i1 false)
  %34 = getelementptr inbounds [36 x i8], ptr %6, i64 0, i64 0
  %35 = getelementptr inbounds %"struct.rw::Texture", ptr %8, i32 0, i32 3
  %36 = getelementptr inbounds [32 x i8], ptr %35, i64 0, i64 0
  %37 = call ptr @strncpy(ptr noundef %34, ptr noundef %36, i64 noundef 32) #6
  %38 = getelementptr inbounds [36 x i8], ptr %6, i64 0, i64 0
  %39 = call i64 @strlen(ptr noundef %38) #7
  %40 = add i64 %39, 4
  %41 = and i64 %40, -4
  %42 = trunc i64 %41 to i32
  store i32 %42, ptr %5, align 4, !tbaa !13
  %43 = load ptr, ptr %4, align 8, !tbaa !5
  %44 = load i32, ptr %5, align 4, !tbaa !13
  %45 = call noundef zeroext i1 @_ZN2rw16writeChunkHeaderEPNS_6StreamEii(ptr noundef %43, i32 noundef 2, i32 noundef %44)
  %46 = load ptr, ptr %4, align 8, !tbaa !5
  %47 = getelementptr inbounds [36 x i8], ptr %6, i64 0, i64 0
  %48 = load i32, ptr %5, align 4, !tbaa !13
  %49 = load ptr, ptr %46, align 8, !tbaa !17
  %50 = getelementptr inbounds ptr, ptr %49, i64 3
  %51 = load ptr, ptr %50, align 8
  %52 = call noundef i32 %51(ptr noundef nonnull align 8 dereferenceable(8) %46, ptr noundef %47, i32 noundef %48)
  %53 = getelementptr inbounds [36 x i8], ptr %6, i64 0, i64 0
  call void @llvm.memset.p0.i64(ptr align 16 %53, i8 0, i64 36, i1 false)
  %54 = getelementptr inbounds [36 x i8], ptr %6, i64 0, i64 0
  %55 = getelementptr inbounds %"struct.rw::Texture", ptr %8, i32 0, i32 4
  %56 = getelementptr inbounds [32 x i8], ptr %55, i64 0, i64 0
  %57 = call ptr @strncpy(ptr noundef %54, ptr noundef %56, i64 noundef 32) #6
  %58 = getelementptr inbounds [36 x i8], ptr %6, i64 0, i64 0
  %59 = call i64 @strlen(ptr noundef %58) #7
  %60 = add i64 %59, 4
  %61 = and i64 %60, -4
  %62 = trunc i64 %61 to i32
  store i32 %62, ptr %5, align 4, !tbaa !13
  %63 = load ptr, ptr %4, align 8, !tbaa !5
  %64 = load i32, ptr %5, align 4, !tbaa !13
  %65 = call noundef zeroext i1 @_ZN2rw16writeChunkHeaderEPNS_6StreamEii(ptr noundef %63, i32 noundef 2, i32 noundef %64)
  %66 = load ptr, ptr %4, align 8, !tbaa !5
  %67 = getelementptr inbounds [36 x i8], ptr %6, i64 0, i64 0
  %68 = load i32, ptr %5, align 4, !tbaa !13
  %69 = load ptr, ptr %66, align 8, !tbaa !17
  %70 = getelementptr inbounds ptr, ptr %69, i64 3
  %71 = load ptr, ptr %70, align 8
  %72 = call noundef i32 %71(ptr noundef nonnull align 8 dereferenceable(8) %66, ptr noundef %67, i32 noundef %68)
  %73 = load ptr, ptr %4, align 8, !tbaa !5
  call void @_ZN2rw10PluginList11streamWriteEPNS_6StreamEPv(ptr noundef nonnull align 8 dereferenceable(24) @_ZN2rw7Texture9s_plglistE, ptr noundef %73, ptr noundef %8)
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #6
  call void @llvm.lifetime.end.p0(i64 36, ptr %6) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #6
  ret i1 true
}

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

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

; Function Attrs: nounwind willreturn memory(read)
declare i64 @strlen(ptr noundef) #5

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #3 = { 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 = { 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 #5 = { nounwind willreturn memory(read) "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 #6 = { nounwind }
attributes #7 = { nounwind willreturn memory(read) }

!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, !12, i64 96}
!10 = !{!"_ZTSN2rw7TextureE", !6, i64 0, !6, i64 8, !11, i64 16, !7, i64 32, !7, i64 64, !12, i64 96, !12, i64 100, !11, i64 104}
!11 = !{!"_ZTSN2rw6LLLinkE", !6, i64 0, !6, i64 8}
!12 = !{!"int", !7, i64 0}
!13 = !{!12, !12, i64 0}
!14 = !{!10, !6, i64 0}
!15 = !{!16, !12, i64 16}
!16 = !{!"_ZTSN2rw6RasterE", !12, i64 0, !12, i64 4, !12, i64 8, !12, i64 12, !12, i64 16, !12, i64 20, !12, i64 24, !12, i64 28, !12, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !12, i64 64, !12, i64 68, !12, i64 72, !6, i64 80, !12, i64 88, !12, i64 92}
!17 = !{!18, !18, i64 0}
!18 = !{!"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"

%"struct.rw::PluginList" = type { i32, i32, %"struct.rw::LinkList" }
%"struct.rw::LinkList" = type { %"struct.rw::LLLink" }
%"struct.rw::LLLink" = type { ptr, ptr }

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

; 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

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

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

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: readwrite)
declare ptr @strncpy(ptr noalias noundef returned writeonly, ptr noalias nocapture noundef readonly, i64 noundef) local_unnamed_addr #2

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZN2rw7Texture11streamWriteEPNS_6StreamE(ptr noundef nonnull align 8 dereferenceable(120) %0, ptr noundef %1) local_unnamed_addr #3 align 2 {
  %3 = alloca [36 x i8], align 16
  call void @llvm.lifetime.start.p0(i64 36, ptr nonnull %3) #5
  %4 = tail call noundef i32 @_ZN2rw7Texture13streamGetSizeEv(ptr noundef nonnull align 8 dereferenceable(120) %0)
  %5 = tail call noundef zeroext i1 @_ZN2rw16writeChunkHeaderEPNS_6StreamEii(ptr noundef %1, i32 noundef 6, i32 noundef %4)
  %6 = tail call noundef zeroext i1 @_ZN2rw16writeChunkHeaderEPNS_6StreamEii(ptr noundef %1, i32 noundef 1, i32 noundef 4)
  %7 = getelementptr inbounds i8, ptr %0, i64 96
  %8 = load i32, ptr %7, align 8, !tbaa !5
  %9 = load ptr, ptr %0, align 8, !tbaa !12
  %.not = icmp eq ptr %9, null
  br i1 %.not, label %16, label %10

10:                                               ; preds = %2
  %11 = getelementptr inbounds i8, ptr %9, i64 16
  %12 = load i32, ptr %11, align 8, !tbaa !13
  %13 = shl i32 %12, 4
  %14 = and i32 %13, 65536
  %15 = xor i32 %14, 65536
  %spec.select = or i32 %15, %8
  br label %16

16:                                               ; preds = %10, %2
  %.0 = phi i32 [ %8, %2 ], [ %spec.select, %10 ]
  %17 = tail call noundef i32 @_ZN2rw6Stream8writeU32Ej(ptr noundef nonnull align 8 dereferenceable(8) %1, i32 noundef %.0)
  %18 = getelementptr inbounds i8, ptr %3, i64 32
  store i32 0, ptr %18, align 16
  %19 = getelementptr inbounds i8, ptr %0, i64 32
  %20 = call ptr @strncpy(ptr noundef nonnull dereferenceable(1) %3, ptr noundef nonnull dereferenceable(1) %19, i64 noundef 32) #5
  %21 = call i64 @strlen(ptr noundef nonnull dereferenceable(1) %3) #6
  %22 = trunc i64 %21 to i32
  %23 = and i32 %22, -4
  %24 = add i32 %23, 4
  %25 = call noundef zeroext i1 @_ZN2rw16writeChunkHeaderEPNS_6StreamEii(ptr noundef nonnull %1, i32 noundef 2, i32 noundef %24)
  %26 = load ptr, ptr %1, align 8, !tbaa !15
  %27 = getelementptr inbounds i8, ptr %26, i64 24
  %28 = load ptr, ptr %27, align 8
  %29 = call noundef i32 %28(ptr noundef nonnull align 8 dereferenceable(8) %1, ptr noundef nonnull %3, i32 noundef %24)
  %30 = getelementptr inbounds i8, ptr %3, i64 32
  store i32 0, ptr %30, align 16
  %31 = getelementptr inbounds i8, ptr %0, i64 64
  %32 = call ptr @strncpy(ptr noundef nonnull dereferenceable(1) %3, ptr noundef nonnull dereferenceable(1) %31, i64 noundef 32) #5
  %33 = call i64 @strlen(ptr noundef nonnull dereferenceable(1) %3) #6
  %34 = trunc i64 %33 to i32
  %35 = and i32 %34, -4
  %36 = add i32 %35, 4
  %37 = call noundef zeroext i1 @_ZN2rw16writeChunkHeaderEPNS_6StreamEii(ptr noundef nonnull %1, i32 noundef 2, i32 noundef %36)
  %38 = load ptr, ptr %1, align 8, !tbaa !15
  %39 = getelementptr inbounds i8, ptr %38, i64 24
  %40 = load ptr, ptr %39, align 8
  %41 = call noundef i32 %40(ptr noundef nonnull align 8 dereferenceable(8) %1, ptr noundef nonnull %3, i32 noundef %36)
  call void @_ZN2rw10PluginList11streamWriteEPNS_6StreamEPv(ptr noundef nonnull align 8 dereferenceable(24) @_ZN2rw7Texture9s_plglistE, ptr noundef nonnull %1, ptr noundef nonnull %0)
  call void @llvm.lifetime.end.p0(i64 36, ptr nonnull %3) #5
  ret i1 true
}

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

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

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
declare i64 @strlen(ptr nocapture noundef) local_unnamed_addr #4

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 nofree nounwind willreturn memory(argmem: readwrite) "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 = { mustprogress nofree nounwind willreturn memory(argmem: read) "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 #5 = { nounwind }
attributes #6 = { nounwind willreturn memory(read) }

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


; Effective O3 passes: DSEPass,EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass