; LLVM IR from aap/librw :: src/geometry.ll (ZN2rw8Material11streamWriteEPNS_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::MatStreamData" = type { i32, %"struct.rw::RGBA", i32, i32 }
%"struct.rw::RGBA" = type { i8, i8, i8, i8 }
%"struct.rw::Material" = type { ptr, %"struct.rw::RGBA", %"struct.rw::SurfaceProperties", ptr, i32 }
%"struct.rw::SurfaceProperties" = type { float, float, float }

@_ZN2rw8Material9s_plglistE = external dso_local global %"struct.rw::PluginList", align 8
@_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: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #1

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

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

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

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZN2rw8Material11streamWriteEPNS_6StreamE(ptr noundef nonnull align 8 dereferenceable(40) %0, ptr noundef %1) #3 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca %"struct.rw::MatStreamData", align 4
  %6 = alloca [3 x float], align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  %7 = load ptr, ptr %3, align 8
  call void @llvm.lifetime.start.p0(i64 16, ptr %5) #5
  %8 = load ptr, ptr %4, align 8, !tbaa !5
  %9 = call noundef i32 @_ZN2rw8Material13streamGetSizeEv(ptr noundef nonnull align 8 dereferenceable(40) %7)
  %10 = call noundef zeroext i1 @_ZN2rw16writeChunkHeaderEPNS_6StreamEii(ptr noundef %8, i32 noundef 7, i32 noundef %9)
  %11 = load ptr, ptr %4, align 8, !tbaa !5
  %12 = load i32, ptr @_ZN2rw7versionE, align 4, !tbaa !9
  %13 = icmp sge i32 %12, 197632
  %14 = zext i1 %13 to i64
  %15 = select i1 %13, i32 12, i32 0
  %16 = sext i32 %15 to i64
  %17 = add i64 16, %16
  %18 = trunc i64 %17 to i32
  %19 = call noundef zeroext i1 @_ZN2rw16writeChunkHeaderEPNS_6StreamEii(ptr noundef %11, i32 noundef 1, i32 noundef %18)
  %20 = getelementptr inbounds %"struct.rw::Material", ptr %7, i32 0, i32 1
  %21 = getelementptr inbounds %"struct.rw::MatStreamData", ptr %5, i32 0, i32 1
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %21, ptr align 8 %20, i64 4, i1 false), !tbaa.struct !11
  %22 = getelementptr inbounds %"struct.rw::MatStreamData", ptr %5, i32 0, i32 0
  store i32 0, ptr %22, align 4, !tbaa !13
  %23 = getelementptr inbounds %"struct.rw::MatStreamData", ptr %5, i32 0, i32 2
  store i32 0, ptr %23, align 4, !tbaa !16
  %24 = getelementptr inbounds %"struct.rw::Material", ptr %7, i32 0, i32 0
  %25 = load ptr, ptr %24, align 8, !tbaa !17
  %26 = icmp ne ptr %25, null
  %27 = zext i1 %26 to i32
  %28 = getelementptr inbounds %"struct.rw::MatStreamData", ptr %5, i32 0, i32 3
  store i32 %27, ptr %28, align 4, !tbaa !21
  call void @_ZN2rw11memLittle32EPvj(ptr noundef %5, i32 noundef 16)
  %29 = getelementptr inbounds %"struct.rw::Material", ptr %7, i32 0, i32 1
  %30 = getelementptr inbounds %"struct.rw::MatStreamData", ptr %5, i32 0, i32 1
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %30, ptr align 8 %29, i64 4, i1 false), !tbaa.struct !11
  %31 = load ptr, ptr %4, align 8, !tbaa !5
  %32 = load ptr, ptr %31, align 8, !tbaa !22
  %33 = getelementptr inbounds ptr, ptr %32, i64 3
  %34 = load ptr, ptr %33, align 8
  %35 = call noundef i32 %34(ptr noundef nonnull align 8 dereferenceable(8) %31, ptr noundef %5, i32 noundef 16)
  %36 = load i32, ptr @_ZN2rw7versionE, align 4, !tbaa !9
  %37 = icmp sge i32 %36, 197632
  br i1 %37, label %38, label %54

38:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 12, ptr %6) #5
  %39 = getelementptr inbounds %"struct.rw::Material", ptr %7, i32 0, i32 2
  %40 = getelementptr inbounds %"struct.rw::SurfaceProperties", ptr %39, i32 0, i32 0
  %41 = load float, ptr %40, align 4, !tbaa !24
  %42 = getelementptr inbounds [3 x float], ptr %6, i64 0, i64 0
  store float %41, ptr %42, align 4, !tbaa !25
  %43 = getelementptr inbounds %"struct.rw::Material", ptr %7, i32 0, i32 2
  %44 = getelementptr inbounds %"struct.rw::SurfaceProperties", ptr %43, i32 0, i32 1
  %45 = load float, ptr %44, align 4, !tbaa !26
  %46 = getelementptr inbounds [3 x float], ptr %6, i64 0, i64 1
  store float %45, ptr %46, align 4, !tbaa !25
  %47 = getelementptr inbounds %"struct.rw::Material", ptr %7, i32 0, i32 2
  %48 = getelementptr inbounds %"struct.rw::SurfaceProperties", ptr %47, i32 0, i32 2
  %49 = load float, ptr %48, align 4, !tbaa !27
  %50 = getelementptr inbounds [3 x float], ptr %6, i64 0, i64 2
  store float %49, ptr %50, align 4, !tbaa !25
  %51 = load ptr, ptr %4, align 8, !tbaa !5
  %52 = getelementptr inbounds [3 x float], ptr %6, i64 0, i64 0
  %53 = call noundef i32 @_ZN2rw6Stream7write32EPKvj(ptr noundef nonnull align 8 dereferenceable(8) %51, ptr noundef %52, i32 noundef 12)
  call void @llvm.lifetime.end.p0(i64 12, ptr %6) #5
  br label %54

54:                                               ; preds = %38, %2
  %55 = getelementptr inbounds %"struct.rw::Material", ptr %7, i32 0, i32 0
  %56 = load ptr, ptr %55, align 8, !tbaa !17
  %57 = icmp ne ptr %56, null
  br i1 %57, label %58, label %63

58:                                               ; preds = %54
  %59 = getelementptr inbounds %"struct.rw::Material", ptr %7, i32 0, i32 0
  %60 = load ptr, ptr %59, align 8, !tbaa !17
  %61 = load ptr, ptr %4, align 8, !tbaa !5
  %62 = call noundef zeroext i1 @_ZN2rw7Texture11streamWriteEPNS_6StreamE(ptr noundef nonnull align 8 dereferenceable(120) %60, ptr noundef %61)
  br label %63

63:                                               ; preds = %58, %54
  %64 = load ptr, ptr %4, align 8, !tbaa !5
  call void @_ZN2rw10PluginList11streamWriteEPNS_6StreamEPv(ptr noundef nonnull align 8 dereferenceable(24) @_ZN2rw8Material9s_plglistE, ptr noundef %64, ptr noundef %7)
  call void @llvm.lifetime.end.p0(i64 16, ptr %5) #5
  ret i1 true
}

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_ZN2rw11memLittle32EPvj(ptr noundef, i32 noundef) #4

declare noundef zeroext i1 @_ZN2rw7Texture11streamWriteEPNS_6StreamE(ptr noundef nonnull align 8 dereferenceable(120), ptr noundef) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 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 = { inlinehint 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 #5 = { 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 = !{i64 0, i64 1, !12, i64 1, i64 1, !12, i64 2, i64 1, !12, i64 3, i64 1, !12}
!12 = !{!7, !7, i64 0}
!13 = !{!14, !10, i64 0}
!14 = !{!"_ZTSN2rw13MatStreamDataE", !10, i64 0, !15, i64 4, !10, i64 8, !10, i64 12}
!15 = !{!"_ZTSN2rw4RGBAE", !7, i64 0, !7, i64 1, !7, i64 2, !7, i64 3}
!16 = !{!14, !10, i64 8}
!17 = !{!18, !6, i64 0}
!18 = !{!"_ZTSN2rw8MaterialE", !6, i64 0, !15, i64 8, !19, i64 12, !6, i64 24, !10, i64 32}
!19 = !{!"_ZTSN2rw17SurfacePropertiesE", !20, i64 0, !20, i64 4, !20, i64 8}
!20 = !{!"float", !7, i64 0}
!21 = !{!14, !10, i64 12}
!22 = !{!23, !23, i64 0}
!23 = !{!"vtable pointer", !8, i64 0}
!24 = !{!18, !20, i64 12}
!25 = !{!20, !20, i64 0}
!26 = !{!18, !20, i64 16}
!27 = !{!18, !20, i64 20}


; 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 }
%"struct.rw::MatStreamData" = type { i32, %"struct.rw::RGBA", i32, i32 }
%"struct.rw::RGBA" = type { i8, i8, i8, i8 }

@_ZN2rw8Material9s_plglistE = external dso_local global %"struct.rw::PluginList", align 8
@_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

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

declare noundef i32 @_ZN2rw6Stream7write32EPKvj(ptr noundef nonnull align 8 dereferenceable(8), ptr 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 uwtable
define dso_local noundef zeroext i1 @_ZN2rw8Material11streamWriteEPNS_6StreamE(ptr noundef nonnull align 8 dereferenceable(40) %0, ptr noundef %1) local_unnamed_addr #2 align 2 {
  %3 = alloca %"struct.rw::MatStreamData", align 4
  %4 = alloca [3 x float], align 8
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %3) #4
  %5 = tail call noundef i32 @_ZN2rw8Material13streamGetSizeEv(ptr noundef nonnull align 8 dereferenceable(40) %0)
  %6 = tail call noundef zeroext i1 @_ZN2rw16writeChunkHeaderEPNS_6StreamEii(ptr noundef %1, i32 noundef 7, i32 noundef %5)
  %7 = load i32, ptr @_ZN2rw7versionE, align 4, !tbaa !5
  %8 = icmp sgt i32 %7, 197631
  %9 = select i1 %8, i32 28, i32 16
  %10 = tail call noundef zeroext i1 @_ZN2rw16writeChunkHeaderEPNS_6StreamEii(ptr noundef %1, i32 noundef 1, i32 noundef %9)
  %11 = getelementptr inbounds i8, ptr %0, i64 8
  %12 = getelementptr inbounds i8, ptr %3, i64 4
  %13 = load i32, ptr %11, align 8
  store i32 %13, ptr %12, align 4
  store i32 0, ptr %3, align 4, !tbaa !9
  %14 = getelementptr inbounds i8, ptr %3, i64 8
  store i32 0, ptr %14, align 4, !tbaa !12
  %15 = load ptr, ptr %0, align 8, !tbaa !13
  %16 = icmp ne ptr %15, null
  %17 = zext i1 %16 to i32
  %18 = getelementptr inbounds i8, ptr %3, i64 12
  store i32 %17, ptr %18, align 4, !tbaa !18
  call void @_ZN2rw11memLittle32EPvj(ptr noundef nonnull %3, i32 noundef 16)
  %19 = load i32, ptr %11, align 8
  store i32 %19, ptr %12, align 4
  %20 = load ptr, ptr %1, align 8, !tbaa !19
  %21 = getelementptr inbounds i8, ptr %20, i64 24
  %22 = load ptr, ptr %21, align 8
  %23 = call noundef i32 %22(ptr noundef nonnull align 8 dereferenceable(8) %1, ptr noundef nonnull %3, i32 noundef 16)
  %24 = load i32, ptr @_ZN2rw7versionE, align 4, !tbaa !5
  %25 = icmp sgt i32 %24, 197631
  br i1 %25, label %26, label %33

26:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 12, ptr nonnull %4) #4
  %27 = getelementptr inbounds i8, ptr %0, i64 12
  %28 = load <2 x float>, ptr %27, align 4, !tbaa !21
  store <2 x float> %28, ptr %4, align 8, !tbaa !21
  %29 = getelementptr inbounds i8, ptr %0, i64 20
  %30 = load float, ptr %29, align 4, !tbaa !22
  %31 = getelementptr inbounds i8, ptr %4, i64 8
  store float %30, ptr %31, align 8, !tbaa !21
  %32 = call noundef i32 @_ZN2rw6Stream7write32EPKvj(ptr noundef nonnull align 8 dereferenceable(8) %1, ptr noundef nonnull %4, i32 noundef 12)
  call void @llvm.lifetime.end.p0(i64 12, ptr nonnull %4) #4
  br label %33

33:                                               ; preds = %26, %2
  %34 = load ptr, ptr %0, align 8, !tbaa !13
  %.not = icmp eq ptr %34, null
  br i1 %.not, label %37, label %35

35:                                               ; preds = %33
  %36 = call noundef zeroext i1 @_ZN2rw7Texture11streamWriteEPNS_6StreamE(ptr noundef nonnull align 8 dereferenceable(120) %34, ptr noundef nonnull %1)
  br label %37

37:                                               ; preds = %35, %33
  call void @_ZN2rw10PluginList11streamWriteEPNS_6StreamEPv(ptr noundef nonnull align 8 dereferenceable(24) @_ZN2rw8Material9s_plglistE, ptr noundef nonnull %1, ptr noundef nonnull %0)
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %3) #4
  ret i1 true
}

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_ZN2rw11memLittle32EPvj(ptr noundef, i32 noundef) local_unnamed_addr #3

declare noundef zeroext i1 @_ZN2rw7Texture11streamWriteEPNS_6StreamE(ptr noundef nonnull align 8 dereferenceable(120), ptr noundef) local_unnamed_addr #1

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 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 = { inlinehint 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 #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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !6, i64 0}
!10 = !{!"_ZTSN2rw13MatStreamDataE", !6, i64 0, !11, i64 4, !6, i64 8, !6, i64 12}
!11 = !{!"_ZTSN2rw4RGBAE", !7, i64 0, !7, i64 1, !7, i64 2, !7, i64 3}
!12 = !{!10, !6, i64 8}
!13 = !{!14, !15, i64 0}
!14 = !{!"_ZTSN2rw8MaterialE", !15, i64 0, !11, i64 8, !16, i64 12, !15, i64 24, !6, i64 32}
!15 = !{!"any pointer", !7, i64 0}
!16 = !{!"_ZTSN2rw17SurfacePropertiesE", !17, i64 0, !17, i64 4, !17, i64 8}
!17 = !{!"float", !7, i64 0}
!18 = !{!10, !6, i64 12}
!19 = !{!20, !20, i64 0}
!20 = !{!"vtable pointer", !8, i64 0}
!21 = !{!17, !17, i64 0}
!22 = !{!14, !17, i64 20}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,SLPVectorizerPass,SROAPass,TailCallElimPass