; LLVM IR from aap/librw :: src/camera.ll (ZN2rw15calczShiftScaleEPNS_6CameraE)

; 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::Camera" = type { %"struct.rw::ObjectWithFrame", ptr, ptr, %"struct.rw::V2d", %"struct.rw::V2d", float, float, float, i32, %"struct.rw::Matrix", float, float, [6 x %"struct.rw::FrustumPlane"], [8 x %"struct.rw::V3d"], %"struct.rw::BBox", ptr, ptr, %"struct.rw::RawMatrix", %"struct.rw::RawMatrix", ptr, %"struct.rw::LLLink", ptr, ptr, ptr, ptr }
%"struct.rw::ObjectWithFrame" = type { %"struct.rw::Object", %"struct.rw::LLLink", ptr }
%"struct.rw::Object" = type { i8, i8, i8, i8, ptr }
%"struct.rw::V2d" = type { float, float }
%"struct.rw::Matrix" = type { %"struct.rw::V3d", i32, %"struct.rw::V3d", i32, %"struct.rw::V3d", i32, %"struct.rw::V3d", i32 }
%"struct.rw::V3d" = type { float, float, float }
%"struct.rw::FrustumPlane" = type { %"struct.rw::Plane", i8, i8, i8 }
%"struct.rw::Plane" = type { %"struct.rw::V3d", float }
%"struct.rw::BBox" = type { %"struct.rw::V3d", %"struct.rw::V3d" }
%"struct.rw::RawMatrix" = type { %"struct.rw::V3d", float, %"struct.rw::V3d", float, %"struct.rw::V3d", float, %"struct.rw::V3d", float }
%"struct.rw::LLLink" = type { ptr, ptr }
%"struct.rw::Engine" = type { ptr, ptr, %"struct.rw::LinkList", %"struct.rw::FileFunctions", [13 x ptr], %"struct.rw::Device", ptr }
%"struct.rw::LinkList" = type { %"struct.rw::LLLink" }
%"struct.rw::FileFunctions" = type { ptr, ptr, ptr, ptr, ptr, ptr, ptr }
%"struct.rw::Device" = type { float, float, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }

@_ZN2rw6engineE = external global ptr, 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
define dso_local void @_ZN2rw15calczShiftScaleEPNS_6CameraE(ptr noundef %0) #1 {
  %2 = alloca ptr, align 8
  %3 = alloca float, align 4
  %4 = alloca float, align 4
  %5 = alloca float, align 4
  %6 = alloca float, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  %7 = load ptr, ptr %2, align 8, !tbaa !5
  %8 = getelementptr inbounds %"struct.rw::Camera", ptr %7, i32 0, i32 5
  %9 = load float, ptr %8, align 8, !tbaa !9
  store float %9, ptr %3, align 4, !tbaa !21
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  %10 = load ptr, ptr %2, align 8, !tbaa !5
  %11 = getelementptr inbounds %"struct.rw::Camera", ptr %10, i32 0, i32 6
  %12 = load float, ptr %11, align 4, !tbaa !22
  store float %12, ptr %4, align 4, !tbaa !21
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  %13 = load ptr, ptr @_ZN2rw6engineE, align 8, !tbaa !5
  %14 = getelementptr inbounds %"struct.rw::Engine", ptr %13, i32 0, i32 5
  %15 = getelementptr inbounds %"struct.rw::Device", ptr %14, i32 0, i32 0
  %16 = load float, ptr %15, align 8, !tbaa !23
  store float %16, ptr %5, align 4, !tbaa !21
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  %17 = load ptr, ptr @_ZN2rw6engineE, align 8, !tbaa !5
  %18 = getelementptr inbounds %"struct.rw::Engine", ptr %17, i32 0, i32 5
  %19 = getelementptr inbounds %"struct.rw::Device", ptr %18, i32 0, i32 1
  %20 = load float, ptr %19, align 4, !tbaa !28
  store float %20, ptr %6, align 4, !tbaa !21
  %21 = load float, ptr %6, align 4, !tbaa !21
  %22 = load float, ptr %5, align 4, !tbaa !21
  %23 = fsub float %21, %22
  %24 = fdiv float %23, 1.000000e+04
  %25 = load float, ptr %5, align 4, !tbaa !21
  %26 = fadd float %25, %24
  store float %26, ptr %5, align 4, !tbaa !21
  %27 = load float, ptr %6, align 4, !tbaa !21
  %28 = load float, ptr %5, align 4, !tbaa !21
  %29 = fsub float %27, %28
  %30 = fdiv float %29, 1.000000e+04
  %31 = load float, ptr %6, align 4, !tbaa !21
  %32 = fsub float %31, %30
  store float %32, ptr %6, align 4, !tbaa !21
  %33 = load ptr, ptr %2, align 8, !tbaa !5
  %34 = getelementptr inbounds %"struct.rw::Camera", ptr %33, i32 0, i32 8
  %35 = load i32, ptr %34, align 4, !tbaa !29
  %36 = icmp eq i32 %35, 1
  br i1 %36, label %37, label %64

37:                                               ; preds = %1
  %38 = load float, ptr %5, align 4, !tbaa !21
  %39 = load float, ptr %6, align 4, !tbaa !21
  %40 = fsub float %38, %39
  %41 = load float, ptr %3, align 4, !tbaa !21
  %42 = fmul float %40, %41
  %43 = load float, ptr %4, align 4, !tbaa !21
  %44 = fmul float %42, %43
  %45 = load float, ptr %4, align 4, !tbaa !21
  %46 = load float, ptr %3, align 4, !tbaa !21
  %47 = fsub float %45, %46
  %48 = fdiv float %44, %47
  %49 = load ptr, ptr %2, align 8, !tbaa !5
  %50 = getelementptr inbounds %"struct.rw::Camera", ptr %49, i32 0, i32 10
  store float %48, ptr %50, align 8, !tbaa !30
  %51 = load float, ptr %6, align 4, !tbaa !21
  %52 = load float, ptr %4, align 4, !tbaa !21
  %53 = load float, ptr %5, align 4, !tbaa !21
  %54 = load float, ptr %3, align 4, !tbaa !21
  %55 = fmul float %53, %54
  %56 = fneg float %55
  %57 = call float @llvm.fmuladd.f32(float %51, float %52, float %56)
  %58 = load float, ptr %4, align 4, !tbaa !21
  %59 = load float, ptr %3, align 4, !tbaa !21
  %60 = fsub float %58, %59
  %61 = fdiv float %57, %60
  %62 = load ptr, ptr %2, align 8, !tbaa !5
  %63 = getelementptr inbounds %"struct.rw::Camera", ptr %62, i32 0, i32 11
  store float %61, ptr %63, align 4, !tbaa !31
  br label %87

64:                                               ; preds = %1
  %65 = load float, ptr %6, align 4, !tbaa !21
  %66 = load float, ptr %5, align 4, !tbaa !21
  %67 = fsub float %65, %66
  %68 = load float, ptr %4, align 4, !tbaa !21
  %69 = load float, ptr %3, align 4, !tbaa !21
  %70 = fsub float %68, %69
  %71 = fdiv float %67, %70
  %72 = load ptr, ptr %2, align 8, !tbaa !5
  %73 = getelementptr inbounds %"struct.rw::Camera", ptr %72, i32 0, i32 10
  store float %71, ptr %73, align 8, !tbaa !30
  %74 = load float, ptr %5, align 4, !tbaa !21
  %75 = load float, ptr %4, align 4, !tbaa !21
  %76 = load float, ptr %6, align 4, !tbaa !21
  %77 = load float, ptr %3, align 4, !tbaa !21
  %78 = fmul float %76, %77
  %79 = fneg float %78
  %80 = call float @llvm.fmuladd.f32(float %74, float %75, float %79)
  %81 = load float, ptr %4, align 4, !tbaa !21
  %82 = load float, ptr %3, align 4, !tbaa !21
  %83 = fsub float %81, %82
  %84 = fdiv float %80, %83
  %85 = load ptr, ptr %2, align 8, !tbaa !5
  %86 = getelementptr inbounds %"struct.rw::Camera", ptr %85, i32 0, i32 11
  store float %84, ptr %86, align 4, !tbaa !31
  br label %87

87:                                               ; preds = %64, %37
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  ret void
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare float @llvm.fmuladd.f32(float, float, float) #2

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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #3 = { 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, !15, i64 72}
!10 = !{!"_ZTSN2rw6CameraE", !11, i64 0, !6, i64 40, !6, i64 48, !14, i64 56, !14, i64 64, !15, i64 72, !15, i64 76, !15, i64 80, !16, i64 84, !17, i64 88, !15, i64 152, !15, i64 156, !7, i64 160, !7, i64 280, !19, i64 376, !6, i64 400, !6, i64 408, !20, i64 416, !20, i64 480, !6, i64 544, !13, i64 552, !6, i64 568, !6, i64 576, !6, i64 584, !6, i64 592}
!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 = !{!"_ZTSN2rw3V2dE", !15, i64 0, !15, i64 4}
!15 = !{!"float", !7, i64 0}
!16 = !{!"int", !7, i64 0}
!17 = !{!"_ZTSN2rw6MatrixE", !18, i64 0, !16, i64 12, !18, i64 16, !16, i64 28, !18, i64 32, !16, i64 44, !18, i64 48, !16, i64 60}
!18 = !{!"_ZTSN2rw3V3dE", !15, i64 0, !15, i64 4, !15, i64 8}
!19 = !{!"_ZTSN2rw4BBoxE", !18, i64 0, !18, i64 12}
!20 = !{!"_ZTSN2rw9RawMatrixE", !18, i64 0, !15, i64 12, !18, i64 16, !15, i64 28, !18, i64 32, !15, i64 44, !18, i64 48, !15, i64 60}
!21 = !{!15, !15, i64 0}
!22 = !{!10, !15, i64 76}
!23 = !{!24, !15, i64 192}
!24 = !{!"_ZTSN2rw6EngineE", !6, i64 0, !6, i64 8, !25, i64 16, !26, i64 32, !7, i64 88, !27, i64 192, !6, i64 328}
!25 = !{!"_ZTSN2rw8LinkListE", !13, i64 0}
!26 = !{!"_ZTSN2rw13FileFunctionsE", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48}
!27 = !{!"_ZTSN2rw6DeviceE", !15, i64 0, !15, i64 4, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !6, i64 64, !6, i64 72, !6, i64 80, !6, i64 88, !6, i64 96, !6, i64 104, !6, i64 112, !6, i64 120, !6, i64 128}
!28 = !{!24, !15, i64 196}
!29 = !{!10, !16, i64 84}
!30 = !{!10, !15, i64 152}
!31 = !{!10, !15, i64 156}


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

@_ZN2rw6engineE = external local_unnamed_addr global ptr, align 8

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(read, argmem: readwrite, inaccessiblemem: none) uwtable
define dso_local void @_ZN2rw15calczShiftScaleEPNS_6CameraE(ptr nocapture noundef %0) local_unnamed_addr #0 {
  %2 = getelementptr inbounds i8, ptr %0, i64 72
  %3 = load float, ptr %2, align 8, !tbaa !5
  %4 = getelementptr inbounds i8, ptr %0, i64 76
  %5 = load float, ptr %4, align 4, !tbaa !20
  %6 = load ptr, ptr @_ZN2rw6engineE, align 8, !tbaa !21
  %7 = getelementptr inbounds i8, ptr %6, i64 192
  %8 = load float, ptr %7, align 8, !tbaa !22
  %9 = getelementptr inbounds i8, ptr %6, i64 196
  %10 = load float, ptr %9, align 4, !tbaa !27
  %11 = fsub float %10, %8
  %12 = fdiv float %11, 1.000000e+04
  %13 = fadd float %8, %12
  %14 = fsub float %10, %13
  %15 = fdiv float %14, 1.000000e+04
  %16 = fsub float %10, %15
  %17 = getelementptr inbounds i8, ptr %0, i64 84
  %18 = load i32, ptr %17, align 4, !tbaa !28
  %19 = icmp eq i32 %18, 1
  %20 = fsub float %16, %13
  %21 = fsub float %13, %16
  %22 = fmul float %3, %21
  %23 = fmul float %5, %22
  %.sink41 = select i1 %19, float %23, float %20
  %.sink40 = select i1 %19, float %13, float %16
  %.sink = select i1 %19, float %16, float %13
  %24 = fsub float %5, %3
  %25 = fneg float %.sink40
  %26 = fmul float %3, %25
  %27 = tail call float @llvm.fmuladd.f32(float %.sink, float %5, float %26)
  %28 = getelementptr inbounds i8, ptr %0, i64 152
  %29 = insertelement <2 x float> poison, float %.sink41, i64 0
  %30 = insertelement <2 x float> %29, float %27, i64 1
  %31 = insertelement <2 x float> poison, float %24, i64 0
  %32 = shufflevector <2 x float> %31, <2 x float> poison, <2 x i32> zeroinitializer
  %33 = fdiv <2 x float> %30, %32
  store <2 x float> %33, ptr %28, align 8
  ret void
}

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare float @llvm.fmuladd.f32(float, float, float) #1

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(read, argmem: readwrite, inaccessiblemem: none) 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 nocallback nofree nosync nounwind speculatable willreturn memory(none) }

!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, !14, i64 72}
!6 = !{!"_ZTSN2rw6CameraE", !7, i64 0, !11, i64 40, !11, i64 48, !13, i64 56, !13, i64 64, !14, i64 72, !14, i64 76, !14, i64 80, !15, i64 84, !16, i64 88, !14, i64 152, !14, i64 156, !9, i64 160, !9, i64 280, !18, i64 376, !11, i64 400, !11, i64 408, !19, i64 416, !19, i64 480, !11, i64 544, !12, i64 552, !11, i64 568, !11, i64 576, !11, i64 584, !11, i64 592}
!7 = !{!"_ZTSN2rw15ObjectWithFrameE", !8, i64 0, !12, i64 16, !11, i64 32}
!8 = !{!"_ZTSN2rw6ObjectE", !9, i64 0, !9, i64 1, !9, i64 2, !9, i64 3, !11, i64 8}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C++ TBAA"}
!11 = !{!"any pointer", !9, i64 0}
!12 = !{!"_ZTSN2rw6LLLinkE", !11, i64 0, !11, i64 8}
!13 = !{!"_ZTSN2rw3V2dE", !14, i64 0, !14, i64 4}
!14 = !{!"float", !9, i64 0}
!15 = !{!"int", !9, i64 0}
!16 = !{!"_ZTSN2rw6MatrixE", !17, i64 0, !15, i64 12, !17, i64 16, !15, i64 28, !17, i64 32, !15, i64 44, !17, i64 48, !15, i64 60}
!17 = !{!"_ZTSN2rw3V3dE", !14, i64 0, !14, i64 4, !14, i64 8}
!18 = !{!"_ZTSN2rw4BBoxE", !17, i64 0, !17, i64 12}
!19 = !{!"_ZTSN2rw9RawMatrixE", !17, i64 0, !14, i64 12, !17, i64 16, !14, i64 28, !17, i64 32, !14, i64 44, !17, i64 48, !14, i64 60}
!20 = !{!6, !14, i64 76}
!21 = !{!11, !11, i64 0}
!22 = !{!23, !14, i64 192}
!23 = !{!"_ZTSN2rw6EngineE", !11, i64 0, !11, i64 8, !24, i64 16, !25, i64 32, !9, i64 88, !26, i64 192, !11, i64 328}
!24 = !{!"_ZTSN2rw8LinkListE", !12, i64 0}
!25 = !{!"_ZTSN2rw13FileFunctionsE", !11, i64 0, !11, i64 8, !11, i64 16, !11, i64 24, !11, i64 32, !11, i64 40, !11, i64 48}
!26 = !{!"_ZTSN2rw6DeviceE", !14, i64 0, !14, i64 4, !11, i64 8, !11, i64 16, !11, i64 24, !11, i64 32, !11, i64 40, !11, i64 48, !11, i64 56, !11, i64 64, !11, i64 72, !11, i64 80, !11, i64 88, !11, i64 96, !11, i64 104, !11, i64 112, !11, i64 120, !11, i64 128}
!27 = !{!23, !14, i64 196}
!28 = !{!6, !15, i64 84}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,MergedLoadStoreMotionPass,PostOrderFunctionAttrsPass,ReassociatePass,SLPVectorizerPass,SROAPass,SimplifyCFGPass,TailCallElimPass