; LLVM IR from aap/librw :: src/light.ll (ZN2rw5Light11streamWriteEPNS_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::LightChunkData" = type { float, float, float, float, float, i32 }
%"struct.rw::Light" = type { %"struct.rw::ObjectWithFrame", float, %"struct.rw::RGBAf", float, %"struct.rw::LLLink", ptr, %"struct.rw::LLLink", ptr, ptr }
%"struct.rw::ObjectWithFrame" = type { %"struct.rw::Object", %"struct.rw::LLLink", ptr }
%"struct.rw::Object" = type { i8, i8, i8, i8, ptr }
%"struct.rw::RGBAf" = type { float, float, float, float }

@_ZN2rw5Light9s_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: nounwind
declare float @acosf(float noundef) #1

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZN2rw5Light11streamWriteEPNS_6StreamE(ptr noundef nonnull align 8 dereferenceable(120) %0, ptr noundef %1) #2 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca %"struct.rw::LightChunkData", align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  %6 = load ptr, ptr %3, align 8
  call void @llvm.lifetime.start.p0(i64 24, ptr %5) #4
  %7 = load ptr, ptr %4, align 8, !tbaa !5
  %8 = call noundef i32 @_ZN2rw5Light13streamGetSizeEv(ptr noundef nonnull align 8 dereferenceable(120) %6)
  %9 = call noundef zeroext i1 @_ZN2rw16writeChunkHeaderEPNS_6StreamEii(ptr noundef %7, i32 noundef 18, i32 noundef %8)
  %10 = load ptr, ptr %4, align 8, !tbaa !5
  %11 = call noundef zeroext i1 @_ZN2rw16writeChunkHeaderEPNS_6StreamEii(ptr noundef %10, i32 noundef 1, i32 noundef 24)
  %12 = getelementptr inbounds %"struct.rw::Light", ptr %6, i32 0, i32 1
  %13 = load float, ptr %12, align 8, !tbaa !9
  %14 = getelementptr inbounds %"struct.rw::LightChunkData", ptr %5, i32 0, i32 0
  store float %13, ptr %14, align 4, !tbaa !16
  %15 = getelementptr inbounds %"struct.rw::Light", ptr %6, i32 0, i32 2
  %16 = getelementptr inbounds %"struct.rw::RGBAf", ptr %15, i32 0, i32 0
  %17 = load float, ptr %16, align 4, !tbaa !19
  %18 = getelementptr inbounds %"struct.rw::LightChunkData", ptr %5, i32 0, i32 1
  store float %17, ptr %18, align 4, !tbaa !20
  %19 = getelementptr inbounds %"struct.rw::Light", ptr %6, i32 0, i32 2
  %20 = getelementptr inbounds %"struct.rw::RGBAf", ptr %19, i32 0, i32 1
  %21 = load float, ptr %20, align 4, !tbaa !21
  %22 = getelementptr inbounds %"struct.rw::LightChunkData", ptr %5, i32 0, i32 2
  store float %21, ptr %22, align 4, !tbaa !22
  %23 = getelementptr inbounds %"struct.rw::Light", ptr %6, i32 0, i32 2
  %24 = getelementptr inbounds %"struct.rw::RGBAf", ptr %23, i32 0, i32 2
  %25 = load float, ptr %24, align 4, !tbaa !23
  %26 = getelementptr inbounds %"struct.rw::LightChunkData", ptr %5, i32 0, i32 3
  store float %25, ptr %26, align 4, !tbaa !24
  %27 = load i32, ptr @_ZN2rw7versionE, align 4, !tbaa !25
  %28 = icmp sge i32 %27, 197376
  br i1 %28, label %29, label %33

29:                                               ; preds = %2
  %30 = getelementptr inbounds %"struct.rw::Light", ptr %6, i32 0, i32 3
  %31 = load float, ptr %30, align 4, !tbaa !26
  %32 = getelementptr inbounds %"struct.rw::LightChunkData", ptr %5, i32 0, i32 4
  store float %31, ptr %32, align 4, !tbaa !27
  br label %40

33:                                               ; preds = %2
  %34 = getelementptr inbounds %"struct.rw::Light", ptr %6, i32 0, i32 3
  %35 = load float, ptr %34, align 4, !tbaa !26
  %36 = fneg float %35
  %37 = call float @acosf(float noundef %36) #4
  %38 = call float @tanf(float noundef %37) #4
  %39 = getelementptr inbounds %"struct.rw::LightChunkData", ptr %5, i32 0, i32 4
  store float %38, ptr %39, align 4, !tbaa !27
  br label %40

40:                                               ; preds = %33, %29
  %41 = getelementptr inbounds %"struct.rw::Light", ptr %6, i32 0, i32 0
  %42 = getelementptr inbounds %"struct.rw::ObjectWithFrame", ptr %41, i32 0, i32 0
  %43 = getelementptr inbounds %"struct.rw::Object", ptr %42, i32 0, i32 2
  %44 = load i8, ptr %43, align 2, !tbaa !28
  %45 = zext i8 %44 to i32
  %46 = getelementptr inbounds %"struct.rw::Light", ptr %6, i32 0, i32 0
  %47 = getelementptr inbounds %"struct.rw::ObjectWithFrame", ptr %46, i32 0, i32 0
  %48 = getelementptr inbounds %"struct.rw::Object", ptr %47, i32 0, i32 1
  %49 = load i8, ptr %48, align 1, !tbaa !29
  %50 = zext i8 %49 to i32
  %51 = shl i32 %50, 16
  %52 = or i32 %45, %51
  %53 = getelementptr inbounds %"struct.rw::LightChunkData", ptr %5, i32 0, i32 5
  store i32 %52, ptr %53, align 4, !tbaa !30
  %54 = load ptr, ptr %4, align 8, !tbaa !5
  %55 = call noundef i32 @_ZN2rw6Stream7write32EPKvj(ptr noundef nonnull align 8 dereferenceable(8) %54, ptr noundef %5, i32 noundef 24)
  %56 = load ptr, ptr %4, align 8, !tbaa !5
  call void @_ZN2rw10PluginList11streamWriteEPNS_6StreamEPv(ptr noundef nonnull align 8 dereferenceable(24) @_ZN2rw5Light9s_plglistE, ptr noundef %56, ptr noundef %6)
  call void @llvm.lifetime.end.p0(i64 24, ptr %5) #4
  ret i1 true
}

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

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

; Function Attrs: nounwind
declare float @tanf(float noundef) #1

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

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 = { 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 #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, !14, i64 40}
!10 = !{!"_ZTSN2rw5LightE", !11, i64 0, !14, i64 40, !15, i64 44, !14, i64 60, !13, i64 64, !6, i64 80, !13, i64 88, !6, i64 104, !6, i64 112}
!11 = !{!"_ZTSN2rw15ObjectWithFrameE", !12, i64 0, !13, i64 16, !6, i64 32}
!12 = !{!"_ZTSN2rw6ObjectE", !7, i64 0, !7, i64 1, !7, i64 2, !7, i64 3, !6, i64 8}
!13 = !{!"_ZTSN2rw6LLLinkE", !6, i64 0, !6, i64 8}
!14 = !{!"float", !7, i64 0}
!15 = !{!"_ZTSN2rw5RGBAfE", !14, i64 0, !14, i64 4, !14, i64 8, !14, i64 12}
!16 = !{!17, !14, i64 0}
!17 = !{!"_ZTSN2rw14LightChunkDataE", !14, i64 0, !14, i64 4, !14, i64 8, !14, i64 12, !14, i64 16, !18, i64 20}
!18 = !{!"int", !7, i64 0}
!19 = !{!10, !14, i64 44}
!20 = !{!17, !14, i64 4}
!21 = !{!10, !14, i64 48}
!22 = !{!17, !14, i64 8}
!23 = !{!10, !14, i64 52}
!24 = !{!17, !14, i64 12}
!25 = !{!18, !18, i64 0}
!26 = !{!10, !14, i64 60}
!27 = !{!17, !14, i64 16}
!28 = !{!10, !7, i64 2}
!29 = !{!10, !7, i64 1}
!30 = !{!17, !18, 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::LightChunkData" = type { float, float, float, float, float, i32 }

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

; Function Attrs: mustprogress nofree nounwind willreturn memory(write)
declare float @acosf(float noundef) local_unnamed_addr #1

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZN2rw5Light11streamWriteEPNS_6StreamE(ptr noundef nonnull align 8 dereferenceable(120) %0, ptr noundef %1) local_unnamed_addr #2 align 2 {
  %3 = alloca %"struct.rw::LightChunkData", align 16
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %3) #4
  %4 = tail call noundef i32 @_ZN2rw5Light13streamGetSizeEv(ptr noundef nonnull align 8 dereferenceable(120) %0)
  %5 = tail call noundef zeroext i1 @_ZN2rw16writeChunkHeaderEPNS_6StreamEii(ptr noundef %1, i32 noundef 18, i32 noundef %4)
  %6 = tail call noundef zeroext i1 @_ZN2rw16writeChunkHeaderEPNS_6StreamEii(ptr noundef %1, i32 noundef 1, i32 noundef 24)
  %7 = getelementptr inbounds i8, ptr %0, i64 40
  %8 = load <4 x float>, ptr %7, align 8, !tbaa !5
  store <4 x float> %8, ptr %3, align 16, !tbaa !5
  %9 = load i32, ptr @_ZN2rw7versionE, align 4, !tbaa !9
  %10 = icmp sgt i32 %9, 197375
  %11 = getelementptr inbounds i8, ptr %0, i64 60
  %12 = load float, ptr %11, align 4, !tbaa !11
  br i1 %10, label %17, label %13

13:                                               ; preds = %2
  %14 = fneg float %12
  %15 = tail call float @acosf(float noundef %14) #4
  %16 = tail call float @tanf(float noundef %15) #4
  br label %17

17:                                               ; preds = %2, %13
  %.sink = phi float [ %16, %13 ], [ %12, %2 ]
  %18 = getelementptr inbounds i8, ptr %3, i64 16
  store float %.sink, ptr %18, align 16
  %19 = getelementptr inbounds i8, ptr %0, i64 2
  %20 = load i8, ptr %19, align 2, !tbaa !18
  %21 = zext i8 %20 to i32
  %22 = getelementptr inbounds i8, ptr %0, i64 1
  %23 = load i8, ptr %22, align 1, !tbaa !19
  %24 = zext i8 %23 to i32
  %25 = shl nuw nsw i32 %24, 16
  %26 = or disjoint i32 %25, %21
  %27 = getelementptr inbounds i8, ptr %3, i64 20
  store i32 %26, ptr %27, align 4, !tbaa !20
  %28 = call noundef i32 @_ZN2rw6Stream7write32EPKvj(ptr noundef nonnull align 8 dereferenceable(8) %1, ptr noundef nonnull %3, i32 noundef 24)
  call void @_ZN2rw10PluginList11streamWriteEPNS_6StreamEPv(ptr noundef nonnull align 8 dereferenceable(24) @_ZN2rw5Light9s_plglistE, ptr noundef nonnull %1, ptr noundef nonnull %0)
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %3) #4
  ret i1 true
}

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

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

; Function Attrs: mustprogress nofree nounwind willreturn memory(write)
declare float @tanf(float noundef) local_unnamed_addr #1

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

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

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress nofree nounwind willreturn memory(write) "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 = !{!"float", !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 60}
!12 = !{!"_ZTSN2rw5LightE", !13, i64 0, !6, i64 40, !17, i64 44, !6, i64 60, !16, i64 64, !15, i64 80, !16, i64 88, !15, i64 104, !15, i64 112}
!13 = !{!"_ZTSN2rw15ObjectWithFrameE", !14, i64 0, !16, i64 16, !15, i64 32}
!14 = !{!"_ZTSN2rw6ObjectE", !7, i64 0, !7, i64 1, !7, i64 2, !7, i64 3, !15, i64 8}
!15 = !{!"any pointer", !7, i64 0}
!16 = !{!"_ZTSN2rw6LLLinkE", !15, i64 0, !15, i64 8}
!17 = !{!"_ZTSN2rw5RGBAfE", !6, i64 0, !6, i64 4, !6, i64 8, !6, i64 12}
!18 = !{!12, !7, i64 2}
!19 = !{!12, !7, i64 1}
!20 = !{!21, !10, i64 20}
!21 = !{!"_ZTSN2rw14LightChunkDataE", !6, i64 0, !6, i64 4, !6, i64 8, !6, i64 12, !6, i64 16, !10, i64 20}


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