; LLVM IR from casensiom/fast-image-processing :: src (perspective)

; 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.STextureTriangle = type { [3 x %struct.STextureVector], i32 }
%struct.STextureVector = type { i32, i32, float, float }

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #0

; Function Attrs: nounwind uwtable
define dso_local void @get_cartesian(ptr noundef %0, double noundef %1, double noundef %2, double noundef %3, ptr noundef %4, ptr noundef %5) #1 {
  %7 = alloca ptr, align 8
  %8 = alloca double, align 8
  %9 = alloca double, align 8
  %10 = alloca double, align 8
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  store ptr %0, ptr %7, align 8, !tbaa !5
  store double %1, ptr %8, align 8, !tbaa !9
  store double %2, ptr %9, align 8, !tbaa !9
  store double %3, ptr %10, align 8, !tbaa !9
  store ptr %4, ptr %11, align 8, !tbaa !5
  store ptr %5, ptr %12, align 8, !tbaa !5
  %13 = load double, ptr %8, align 8, !tbaa !9
  %14 = load ptr, ptr %7, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.STextureTriangle, ptr %14, i32 0, i32 0
  %16 = getelementptr inbounds [3 x %struct.STextureVector], ptr %15, i64 0, i64 0
  %17 = getelementptr inbounds %struct.STextureVector, ptr %16, i32 0, i32 2
  %18 = load float, ptr %17, align 4, !tbaa !11
  %19 = fpext float %18 to double
  %20 = load double, ptr %9, align 8, !tbaa !9
  %21 = load ptr, ptr %7, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.STextureTriangle, ptr %21, i32 0, i32 0
  %23 = getelementptr inbounds [3 x %struct.STextureVector], ptr %22, i64 0, i64 1
  %24 = getelementptr inbounds %struct.STextureVector, ptr %23, i32 0, i32 2
  %25 = load float, ptr %24, align 4, !tbaa !11
  %26 = fpext float %25 to double
  %27 = fmul double %20, %26
  %28 = call double @llvm.fmuladd.f64(double %13, double %19, double %27)
  %29 = load double, ptr %10, align 8, !tbaa !9
  %30 = load ptr, ptr %7, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.STextureTriangle, ptr %30, i32 0, i32 0
  %32 = getelementptr inbounds [3 x %struct.STextureVector], ptr %31, i64 0, i64 2
  %33 = getelementptr inbounds %struct.STextureVector, ptr %32, i32 0, i32 2
  %34 = load float, ptr %33, align 4, !tbaa !11
  %35 = fpext float %34 to double
  %36 = call double @llvm.fmuladd.f64(double %29, double %35, double %28)
  %37 = fptrunc double %36 to float
  %38 = load ptr, ptr %11, align 8, !tbaa !5
  store float %37, ptr %38, align 4, !tbaa !15
  %39 = load double, ptr %8, align 8, !tbaa !9
  %40 = load ptr, ptr %7, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.STextureTriangle, ptr %40, i32 0, i32 0
  %42 = getelementptr inbounds [3 x %struct.STextureVector], ptr %41, i64 0, i64 0
  %43 = getelementptr inbounds %struct.STextureVector, ptr %42, i32 0, i32 3
  %44 = load float, ptr %43, align 4, !tbaa !16
  %45 = fpext float %44 to double
  %46 = load double, ptr %9, align 8, !tbaa !9
  %47 = load ptr, ptr %7, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.STextureTriangle, ptr %47, i32 0, i32 0
  %49 = getelementptr inbounds [3 x %struct.STextureVector], ptr %48, i64 0, i64 1
  %50 = getelementptr inbounds %struct.STextureVector, ptr %49, i32 0, i32 3
  %51 = load float, ptr %50, align 4, !tbaa !16
  %52 = fpext float %51 to double
  %53 = fmul double %46, %52
  %54 = call double @llvm.fmuladd.f64(double %39, double %45, double %53)
  %55 = load double, ptr %10, align 8, !tbaa !9
  %56 = load ptr, ptr %7, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.STextureTriangle, ptr %56, i32 0, i32 0
  %58 = getelementptr inbounds [3 x %struct.STextureVector], ptr %57, i64 0, i64 2
  %59 = getelementptr inbounds %struct.STextureVector, ptr %58, i32 0, i32 3
  %60 = load float, ptr %59, align 4, !tbaa !16
  %61 = fpext float %60 to double
  %62 = call double @llvm.fmuladd.f64(double %55, double %61, double %54)
  %63 = fptrunc double %62 to float
  %64 = load ptr, ptr %12, align 8, !tbaa !5
  store float %63, ptr %64, align 4, !tbaa !15
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #1 = { 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" }

!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/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"double", !7, i64 0}
!11 = !{!12, !14, i64 8}
!12 = !{!"STextureVector", !13, i64 0, !13, i64 4, !14, i64 8, !14, i64 12}
!13 = !{!"int", !7, i64 0}
!14 = !{!"float", !7, i64 0}
!15 = !{!14, !14, i64 0}
!16 = !{!12, !14, i64 12}


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

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #0

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: readwrite) uwtable
define dso_local void @get_cartesian(ptr nocapture noundef readonly %0, double noundef %1, double noundef %2, double noundef %3, ptr nocapture noundef writeonly %4, ptr nocapture noundef writeonly %5) local_unnamed_addr #1 {
  %7 = getelementptr inbounds i8, ptr %0, i64 8
  %8 = load float, ptr %7, align 4, !tbaa !5
  %9 = fpext float %8 to double
  %10 = getelementptr inbounds i8, ptr %0, i64 24
  %11 = load float, ptr %10, align 4, !tbaa !5
  %12 = fpext float %11 to double
  %13 = fmul double %12, %2
  %14 = tail call double @llvm.fmuladd.f64(double %1, double %9, double %13)
  %15 = getelementptr inbounds i8, ptr %0, i64 40
  %16 = load float, ptr %15, align 4, !tbaa !5
  %17 = fpext float %16 to double
  %18 = tail call double @llvm.fmuladd.f64(double %3, double %17, double %14)
  %19 = fptrunc double %18 to float
  store float %19, ptr %4, align 4, !tbaa !11
  %20 = getelementptr inbounds i8, ptr %0, i64 12
  %21 = load float, ptr %20, align 4, !tbaa !12
  %22 = fpext float %21 to double
  %23 = getelementptr inbounds i8, ptr %0, i64 28
  %24 = load float, ptr %23, align 4, !tbaa !12
  %25 = fpext float %24 to double
  %26 = fmul double %25, %2
  %27 = tail call double @llvm.fmuladd.f64(double %1, double %22, double %26)
  %28 = getelementptr inbounds i8, ptr %0, i64 44
  %29 = load float, ptr %28, align 4, !tbaa !12
  %30 = fpext float %29 to double
  %31 = tail call double @llvm.fmuladd.f64(double %3, double %30, double %27)
  %32 = fptrunc double %31 to float
  store float %32, ptr %5, align 4, !tbaa !11
  ret void
}

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

!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 8}
!6 = !{!"STextureVector", !7, i64 0, !7, i64 4, !10, i64 8, !10, i64 12}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"float", !8, i64 0}
!11 = !{!10, !10, i64 0}
!12 = !{!6, !10, i64 12}


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