; 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: nounwind uwtable
define dso_local void @get_barycentric(ptr noundef %0, i32 noundef %1, i32 noundef %2, ptr noundef %3, ptr noundef %4, ptr noundef %5) #0 {
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  store ptr %0, ptr %7, align 8, !tbaa !5
  store i32 %1, ptr %8, align 4, !tbaa !9
  store i32 %2, ptr %9, align 4, !tbaa !9
  store ptr %3, ptr %10, align 8, !tbaa !5
  store ptr %4, ptr %11, align 8, !tbaa !5
  store ptr %5, ptr %12, align 8, !tbaa !5
  %13 = load ptr, ptr %7, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.STextureTriangle, ptr %13, i32 0, i32 0
  %15 = getelementptr inbounds [3 x %struct.STextureVector], ptr %14, i64 0, i64 1
  %16 = getelementptr inbounds %struct.STextureVector, ptr %15, i32 0, i32 1
  %17 = load i32, ptr %16, align 4, !tbaa !11
  %18 = load ptr, ptr %7, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.STextureTriangle, ptr %18, i32 0, i32 0
  %20 = getelementptr inbounds [3 x %struct.STextureVector], ptr %19, i64 0, i64 2
  %21 = getelementptr inbounds %struct.STextureVector, ptr %20, i32 0, i32 1
  %22 = load i32, ptr %21, align 4, !tbaa !11
  %23 = sub nsw i32 %17, %22
  %24 = sitofp i32 %23 to double
  %25 = load i32, ptr %8, align 4, !tbaa !9
  %26 = sitofp i32 %25 to double
  %27 = load ptr, ptr %7, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.STextureTriangle, ptr %27, i32 0, i32 0
  %29 = getelementptr inbounds [3 x %struct.STextureVector], ptr %28, i64 0, i64 2
  %30 = getelementptr inbounds %struct.STextureVector, ptr %29, i32 0, i32 0
  %31 = load i32, ptr %30, align 4, !tbaa !14
  %32 = sitofp i32 %31 to double
  %33 = fsub double %26, %32
  %34 = load ptr, ptr %7, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.STextureTriangle, ptr %34, i32 0, i32 0
  %36 = getelementptr inbounds [3 x %struct.STextureVector], ptr %35, i64 0, i64 2
  %37 = getelementptr inbounds %struct.STextureVector, ptr %36, i32 0, i32 0
  %38 = load i32, ptr %37, align 4, !tbaa !14
  %39 = load ptr, ptr %7, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.STextureTriangle, ptr %39, i32 0, i32 0
  %41 = getelementptr inbounds [3 x %struct.STextureVector], ptr %40, i64 0, i64 1
  %42 = getelementptr inbounds %struct.STextureVector, ptr %41, i32 0, i32 0
  %43 = load i32, ptr %42, align 4, !tbaa !14
  %44 = sub nsw i32 %38, %43
  %45 = sitofp i32 %44 to double
  %46 = load i32, ptr %9, align 4, !tbaa !9
  %47 = sitofp i32 %46 to double
  %48 = load ptr, ptr %7, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.STextureTriangle, ptr %48, i32 0, i32 0
  %50 = getelementptr inbounds [3 x %struct.STextureVector], ptr %49, i64 0, i64 2
  %51 = getelementptr inbounds %struct.STextureVector, ptr %50, i32 0, i32 1
  %52 = load i32, ptr %51, align 4, !tbaa !11
  %53 = sitofp i32 %52 to double
  %54 = fsub double %47, %53
  %55 = fmul double %45, %54
  %56 = call double @llvm.fmuladd.f64(double %24, double %33, double %55)
  %57 = load ptr, ptr %7, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.STextureTriangle, ptr %57, i32 0, i32 1
  %59 = load i32, ptr %58, align 4, !tbaa !15
  %60 = sitofp i32 %59 to double
  %61 = fdiv double %56, %60
  %62 = load ptr, ptr %10, align 8, !tbaa !5
  store double %61, ptr %62, align 8, !tbaa !17
  %63 = load ptr, ptr %7, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.STextureTriangle, ptr %63, i32 0, i32 0
  %65 = getelementptr inbounds [3 x %struct.STextureVector], ptr %64, i64 0, i64 2
  %66 = getelementptr inbounds %struct.STextureVector, ptr %65, i32 0, i32 1
  %67 = load i32, ptr %66, align 4, !tbaa !11
  %68 = load ptr, ptr %7, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct.STextureTriangle, ptr %68, i32 0, i32 0
  %70 = getelementptr inbounds [3 x %struct.STextureVector], ptr %69, i64 0, i64 0
  %71 = getelementptr inbounds %struct.STextureVector, ptr %70, i32 0, i32 1
  %72 = load i32, ptr %71, align 4, !tbaa !11
  %73 = sub nsw i32 %67, %72
  %74 = sitofp i32 %73 to double
  %75 = load i32, ptr %8, align 4, !tbaa !9
  %76 = sitofp i32 %75 to double
  %77 = load ptr, ptr %7, align 8, !tbaa !5
  %78 = getelementptr inbounds %struct.STextureTriangle, ptr %77, i32 0, i32 0
  %79 = getelementptr inbounds [3 x %struct.STextureVector], ptr %78, i64 0, i64 2
  %80 = getelementptr inbounds %struct.STextureVector, ptr %79, i32 0, i32 0
  %81 = load i32, ptr %80, align 4, !tbaa !14
  %82 = sitofp i32 %81 to double
  %83 = fsub double %76, %82
  %84 = load ptr, ptr %7, align 8, !tbaa !5
  %85 = getelementptr inbounds %struct.STextureTriangle, ptr %84, i32 0, i32 0
  %86 = getelementptr inbounds [3 x %struct.STextureVector], ptr %85, i64 0, i64 0
  %87 = getelementptr inbounds %struct.STextureVector, ptr %86, i32 0, i32 0
  %88 = load i32, ptr %87, align 4, !tbaa !14
  %89 = load ptr, ptr %7, align 8, !tbaa !5
  %90 = getelementptr inbounds %struct.STextureTriangle, ptr %89, i32 0, i32 0
  %91 = getelementptr inbounds [3 x %struct.STextureVector], ptr %90, i64 0, i64 2
  %92 = getelementptr inbounds %struct.STextureVector, ptr %91, i32 0, i32 0
  %93 = load i32, ptr %92, align 4, !tbaa !14
  %94 = sub nsw i32 %88, %93
  %95 = sitofp i32 %94 to double
  %96 = load i32, ptr %9, align 4, !tbaa !9
  %97 = sitofp i32 %96 to double
  %98 = load ptr, ptr %7, align 8, !tbaa !5
  %99 = getelementptr inbounds %struct.STextureTriangle, ptr %98, i32 0, i32 0
  %100 = getelementptr inbounds [3 x %struct.STextureVector], ptr %99, i64 0, i64 2
  %101 = getelementptr inbounds %struct.STextureVector, ptr %100, i32 0, i32 1
  %102 = load i32, ptr %101, align 4, !tbaa !11
  %103 = sitofp i32 %102 to double
  %104 = fsub double %97, %103
  %105 = fmul double %95, %104
  %106 = call double @llvm.fmuladd.f64(double %74, double %83, double %105)
  %107 = load ptr, ptr %7, align 8, !tbaa !5
  %108 = getelementptr inbounds %struct.STextureTriangle, ptr %107, i32 0, i32 1
  %109 = load i32, ptr %108, align 4, !tbaa !15
  %110 = sitofp i32 %109 to double
  %111 = fdiv double %106, %110
  %112 = load ptr, ptr %11, align 8, !tbaa !5
  store double %111, ptr %112, align 8, !tbaa !17
  %113 = load ptr, ptr %10, align 8, !tbaa !5
  %114 = load double, ptr %113, align 8, !tbaa !17
  %115 = fsub double 1.000000e+00, %114
  %116 = load ptr, ptr %11, align 8, !tbaa !5
  %117 = load double, ptr %116, align 8, !tbaa !17
  %118 = fsub double %115, %117
  %119 = load ptr, ptr %12, align 8, !tbaa !5
  store double %118, ptr %119, align 8, !tbaa !17
  ret void
}

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

attributes #0 = { 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 #1 = { 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, !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 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 4}
!12 = !{!"STextureVector", !10, i64 0, !10, i64 4, !13, i64 8, !13, i64 12}
!13 = !{!"float", !7, i64 0}
!14 = !{!12, !10, i64 0}
!15 = !{!16, !10, i64 48}
!16 = !{!"STextureTriangle", !7, i64 0, !10, i64 48}
!17 = !{!18, !18, i64 0}
!18 = !{!"double", !7, 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"

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: readwrite) uwtable
define dso_local void @get_barycentric(ptr nocapture noundef readonly %0, i32 noundef %1, i32 noundef %2, ptr nocapture noundef %3, ptr nocapture noundef writeonly %4, ptr nocapture noundef writeonly %5) local_unnamed_addr #0 {
  %7 = getelementptr inbounds i8, ptr %0, i64 16
  %8 = getelementptr inbounds i8, ptr %0, i64 20
  %9 = load i32, ptr %8, align 4, !tbaa !5
  %10 = getelementptr inbounds i8, ptr %0, i64 32
  %11 = getelementptr inbounds i8, ptr %0, i64 36
  %12 = load i32, ptr %11, align 4, !tbaa !5
  %13 = sub nsw i32 %9, %12
  %14 = sitofp i32 %13 to double
  %15 = sitofp i32 %1 to double
  %16 = load i32, ptr %10, align 4, !tbaa !11
  %17 = sitofp i32 %16 to double
  %18 = fsub double %15, %17
  %19 = load i32, ptr %7, align 4, !tbaa !11
  %20 = sub nsw i32 %16, %19
  %21 = sitofp i32 %20 to double
  %22 = sitofp i32 %2 to double
  %23 = sitofp i32 %12 to double
  %24 = fsub double %22, %23
  %25 = fmul double %24, %21
  %26 = tail call double @llvm.fmuladd.f64(double %14, double %18, double %25)
  %27 = getelementptr inbounds i8, ptr %0, i64 48
  %28 = load i32, ptr %27, align 4, !tbaa !12
  %29 = sitofp i32 %28 to double
  %30 = fdiv double %26, %29
  store double %30, ptr %3, align 8, !tbaa !14
  %31 = getelementptr inbounds i8, ptr %0, i64 4
  %32 = load i32, ptr %31, align 4, !tbaa !5
  %33 = sub nsw i32 %12, %32
  %34 = sitofp i32 %33 to double
  %35 = load i32, ptr %0, align 4, !tbaa !11
  %36 = sub nsw i32 %35, %16
  %37 = sitofp i32 %36 to double
  %38 = fmul double %24, %37
  %39 = tail call double @llvm.fmuladd.f64(double %34, double %18, double %38)
  %40 = fdiv double %39, %29
  store double %40, ptr %4, align 8, !tbaa !14
  %41 = load double, ptr %3, align 8, !tbaa !14
  %42 = fsub double 1.000000e+00, %41
  %43 = fsub double %42, %40
  store double %43, ptr %5, align 8, !tbaa !14
  ret void
}

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

attributes #0 = { 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" }
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, !7, i64 4}
!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 = !{!6, !7, i64 0}
!12 = !{!13, !7, i64 48}
!13 = !{!"STextureTriangle", !8, i64 0, !7, i64 48}
!14 = !{!15, !15, i64 0}
!15 = !{!"double", !8, i64 0}


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