; 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 @init_triangle(ptr dead_on_unwind noalias writable sret(%struct.STextureTriangle) align 4 %0, ptr noundef byval(%struct.STextureTriangle) align 8 %1, i32 noundef %2, i32 noundef %3, i32 noundef %4, i32 noundef %5, i32 noundef %6, i32 noundef %7) #0 {
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  store i32 %2, ptr %9, align 4, !tbaa !5
  store i32 %3, ptr %10, align 4, !tbaa !5
  store i32 %4, ptr %11, align 4, !tbaa !5
  store i32 %5, ptr %12, align 4, !tbaa !5
  store i32 %6, ptr %13, align 4, !tbaa !5
  store i32 %7, ptr %14, align 4, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %0, ptr align 8 %1, i64 52, i1 false), !tbaa.struct !9
  %15 = load i32, ptr %9, align 4, !tbaa !5
  %16 = getelementptr inbounds %struct.STextureTriangle, ptr %0, i32 0, i32 0
  %17 = getelementptr inbounds [3 x %struct.STextureVector], ptr %16, i64 0, i64 0
  %18 = getelementptr inbounds %struct.STextureVector, ptr %17, i32 0, i32 0
  store i32 %15, ptr %18, align 4, !tbaa !11
  %19 = load i32, ptr %10, align 4, !tbaa !5
  %20 = getelementptr inbounds %struct.STextureTriangle, ptr %0, i32 0, i32 0
  %21 = getelementptr inbounds [3 x %struct.STextureVector], ptr %20, i64 0, i64 0
  %22 = getelementptr inbounds %struct.STextureVector, ptr %21, i32 0, i32 1
  store i32 %19, ptr %22, align 4, !tbaa !14
  %23 = load i32, ptr %11, align 4, !tbaa !5
  %24 = getelementptr inbounds %struct.STextureTriangle, ptr %0, i32 0, i32 0
  %25 = getelementptr inbounds [3 x %struct.STextureVector], ptr %24, i64 0, i64 1
  %26 = getelementptr inbounds %struct.STextureVector, ptr %25, i32 0, i32 0
  store i32 %23, ptr %26, align 4, !tbaa !11
  %27 = load i32, ptr %12, align 4, !tbaa !5
  %28 = getelementptr inbounds %struct.STextureTriangle, ptr %0, i32 0, i32 0
  %29 = getelementptr inbounds [3 x %struct.STextureVector], ptr %28, i64 0, i64 1
  %30 = getelementptr inbounds %struct.STextureVector, ptr %29, i32 0, i32 1
  store i32 %27, ptr %30, align 4, !tbaa !14
  %31 = load i32, ptr %13, align 4, !tbaa !5
  %32 = getelementptr inbounds %struct.STextureTriangle, ptr %0, i32 0, i32 0
  %33 = getelementptr inbounds [3 x %struct.STextureVector], ptr %32, i64 0, i64 2
  %34 = getelementptr inbounds %struct.STextureVector, ptr %33, i32 0, i32 0
  store i32 %31, ptr %34, align 4, !tbaa !11
  %35 = load i32, ptr %14, align 4, !tbaa !5
  %36 = getelementptr inbounds %struct.STextureTriangle, ptr %0, i32 0, i32 0
  %37 = getelementptr inbounds [3 x %struct.STextureVector], ptr %36, i64 0, i64 2
  %38 = getelementptr inbounds %struct.STextureVector, ptr %37, i32 0, i32 1
  store i32 %35, ptr %38, align 4, !tbaa !14
  %39 = getelementptr inbounds %struct.STextureTriangle, ptr %0, i32 0, i32 0
  %40 = getelementptr inbounds [3 x %struct.STextureVector], ptr %39, i64 0, i64 1
  %41 = getelementptr inbounds %struct.STextureVector, ptr %40, i32 0, i32 1
  %42 = load i32, ptr %41, align 4, !tbaa !14
  %43 = getelementptr inbounds %struct.STextureTriangle, ptr %0, i32 0, i32 0
  %44 = getelementptr inbounds [3 x %struct.STextureVector], ptr %43, i64 0, i64 2
  %45 = getelementptr inbounds %struct.STextureVector, ptr %44, i32 0, i32 1
  %46 = load i32, ptr %45, align 4, !tbaa !14
  %47 = sub nsw i32 %42, %46
  %48 = getelementptr inbounds %struct.STextureTriangle, ptr %0, i32 0, i32 0
  %49 = getelementptr inbounds [3 x %struct.STextureVector], ptr %48, i64 0, i64 0
  %50 = getelementptr inbounds %struct.STextureVector, ptr %49, i32 0, i32 0
  %51 = load i32, ptr %50, align 4, !tbaa !11
  %52 = getelementptr inbounds %struct.STextureTriangle, ptr %0, i32 0, i32 0
  %53 = getelementptr inbounds [3 x %struct.STextureVector], ptr %52, i64 0, i64 2
  %54 = getelementptr inbounds %struct.STextureVector, ptr %53, i32 0, i32 0
  %55 = load i32, ptr %54, align 4, !tbaa !11
  %56 = sub nsw i32 %51, %55
  %57 = mul nsw i32 %47, %56
  %58 = getelementptr inbounds %struct.STextureTriangle, ptr %0, i32 0, i32 0
  %59 = getelementptr inbounds [3 x %struct.STextureVector], ptr %58, i64 0, i64 2
  %60 = getelementptr inbounds %struct.STextureVector, ptr %59, i32 0, i32 0
  %61 = load i32, ptr %60, align 4, !tbaa !11
  %62 = getelementptr inbounds %struct.STextureTriangle, ptr %0, i32 0, i32 0
  %63 = getelementptr inbounds [3 x %struct.STextureVector], ptr %62, i64 0, i64 1
  %64 = getelementptr inbounds %struct.STextureVector, ptr %63, i32 0, i32 0
  %65 = load i32, ptr %64, align 4, !tbaa !11
  %66 = sub nsw i32 %61, %65
  %67 = getelementptr inbounds %struct.STextureTriangle, ptr %0, i32 0, i32 0
  %68 = getelementptr inbounds [3 x %struct.STextureVector], ptr %67, i64 0, i64 0
  %69 = getelementptr inbounds %struct.STextureVector, ptr %68, i32 0, i32 1
  %70 = load i32, ptr %69, align 4, !tbaa !14
  %71 = getelementptr inbounds %struct.STextureTriangle, ptr %0, i32 0, i32 0
  %72 = getelementptr inbounds [3 x %struct.STextureVector], ptr %71, i64 0, i64 2
  %73 = getelementptr inbounds %struct.STextureVector, ptr %72, i32 0, i32 1
  %74 = load i32, ptr %73, align 4, !tbaa !14
  %75 = sub nsw i32 %70, %74
  %76 = mul nsw i32 %66, %75
  %77 = add nsw i32 %57, %76
  %78 = getelementptr inbounds %struct.STextureTriangle, ptr %0, i32 0, i32 1
  store i32 %77, ptr %78, align 4, !tbaa !15
  ret void
}

; 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

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 nounwind willreturn memory(argmem: readwrite) }

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


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

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: readwrite) uwtable
define dso_local void @init_triangle(ptr dead_on_unwind noalias nocapture writable writeonly sret(%struct.STextureTriangle) align 4 %0, ptr nocapture noundef readonly byval(%struct.STextureTriangle) align 8 %1, i32 noundef %2, i32 noundef %3, i32 noundef %4, i32 noundef %5, i32 noundef %6, i32 noundef %7) local_unnamed_addr #0 {
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 4 dereferenceable(52) %0, ptr noundef nonnull align 8 dereferenceable(52) %1, i64 48, i1 false), !tbaa.struct !5
  store i32 %2, ptr %0, align 4, !tbaa !11
  %9 = getelementptr inbounds i8, ptr %0, i64 4
  store i32 %3, ptr %9, align 4, !tbaa !14
  %10 = getelementptr inbounds i8, ptr %0, i64 16
  store i32 %4, ptr %10, align 4, !tbaa !11
  %11 = getelementptr inbounds i8, ptr %0, i64 20
  store i32 %5, ptr %11, align 4, !tbaa !14
  %12 = getelementptr inbounds i8, ptr %0, i64 32
  store i32 %6, ptr %12, align 4, !tbaa !11
  %13 = getelementptr inbounds i8, ptr %0, i64 36
  store i32 %7, ptr %13, align 4, !tbaa !14
  %14 = sub nsw i32 %5, %7
  %15 = sub nsw i32 %2, %6
  %16 = mul nsw i32 %14, %15
  %17 = sub nsw i32 %6, %4
  %18 = sub nsw i32 %3, %7
  %19 = mul nsw i32 %18, %17
  %20 = add nsw i32 %16, %19
  %21 = getelementptr inbounds i8, ptr %0, i64 48
  store i32 %20, ptr %21, align 4, !tbaa !15
  ret void
}

; Function Attrs: mustprogress 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

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 nounwind willreturn memory(argmem: readwrite) }

!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 = !{i64 0, i64 48, !6, i64 48, i64 4, !9}
!6 = !{!7, !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 0}
!12 = !{!"STextureVector", !10, i64 0, !10, i64 4, !13, i64 8, !13, i64 12}
!13 = !{!"float", !7, i64 0}
!14 = !{!12, !10, i64 4}
!15 = !{!16, !10, i64 48}
!16 = !{!"STextureTriangle", !7, i64 0, !10, i64 48}


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