; LLVM IR from bbenligiray/stag :: src/Ellipse.ll (ZN13customEllipse26GetClosestPointAndDistanceE3pixRS0_)

; 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.pix = type { i32, i32 }
%class.customEllipse = type { double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, i32, ptr, ptr, ptr, ptr, ptr, ptr }

; 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: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #1

; 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) #2

; Function Attrs: nounwind
declare double @cos(double noundef) #3

; Function Attrs: nounwind
declare double @sin(double noundef) #3

; Function Attrs: mustprogress uwtable
declare dso_local noundef double @_ZN13customEllipse11GetDistanceE3pixRd(ptr noundef nonnull align 8 dereferenceable(272), i64, ptr noundef nonnull align 8 dereferenceable(8)) #4 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef double @_ZN13customEllipse26GetClosestPointAndDistanceE3pixRS0_(ptr noundef nonnull align 8 dereferenceable(272) %0, i64 %1, ptr noundef nonnull align 4 dereferenceable(8) %2) #4 align 2 {
  %4 = alloca %struct.pix, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca double, align 8
  %8 = alloca double, align 8
  %9 = alloca %struct.pix, align 4
  %10 = alloca double, align 8
  %11 = alloca double, align 8
  store i64 %1, ptr %4, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %2, ptr %6, align 8, !tbaa !5
  %12 = load ptr, ptr %5, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #5
  %13 = getelementptr inbounds %struct.pix, ptr %4, i32 0, i32 1
  %14 = load i32, ptr %13, align 4, !tbaa !9
  %15 = sub nsw i32 0, %14
  %16 = getelementptr inbounds %struct.pix, ptr %4, i32 0, i32 1
  store i32 %15, ptr %16, align 4, !tbaa !9
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %9, ptr align 4 %4, i64 8, i1 false), !tbaa.struct !12
  %17 = load i64, ptr %9, align 4
  %18 = call noundef double @_ZN13customEllipse11GetDistanceE3pixRd(ptr noundef nonnull align 8 dereferenceable(272) %12, i64 %17, ptr noundef nonnull align 8 dereferenceable(8) %8)
  store double %18, ptr %7, align 8, !tbaa !14
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #5
  %19 = getelementptr inbounds %class.customEllipse, ptr %12, i32 0, i32 20
  %20 = load double, ptr %19, align 8, !tbaa !16
  %21 = load double, ptr %8, align 8, !tbaa !14
  %22 = call double @cos(double noundef %21) #5
  %23 = fmul double %20, %22
  store double %23, ptr %10, align 8, !tbaa !14
  %24 = getelementptr inbounds %class.customEllipse, ptr %12, i32 0, i32 21
  %25 = load double, ptr %24, align 8, !tbaa !18
  %26 = load double, ptr %8, align 8, !tbaa !14
  %27 = call double @sin(double noundef %26) #5
  %28 = fmul double %25, %27
  store double %28, ptr %11, align 8, !tbaa !14
  %29 = load double, ptr %10, align 8, !tbaa !14
  %30 = getelementptr inbounds %class.customEllipse, ptr %12, i32 0, i32 23
  %31 = load double, ptr %30, align 8, !tbaa !19
  %32 = call double @cos(double noundef %31) #5
  %33 = load double, ptr %11, align 8, !tbaa !14
  %34 = getelementptr inbounds %class.customEllipse, ptr %12, i32 0, i32 23
  %35 = load double, ptr %34, align 8, !tbaa !19
  %36 = call double @sin(double noundef %35) #5
  %37 = fmul double %33, %36
  %38 = fneg double %37
  %39 = call double @llvm.fmuladd.f64(double %29, double %32, double %38)
  %40 = getelementptr inbounds %class.customEllipse, ptr %12, i32 0, i32 18
  %41 = load double, ptr %40, align 8, !tbaa !20
  %42 = fadd double %39, %41
  %43 = fptosi double %42 to i32
  %44 = load ptr, ptr %6, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.pix, ptr %44, i32 0, i32 0
  store i32 %43, ptr %45, align 4, !tbaa !21
  %46 = load double, ptr %10, align 8, !tbaa !14
  %47 = getelementptr inbounds %class.customEllipse, ptr %12, i32 0, i32 23
  %48 = load double, ptr %47, align 8, !tbaa !19
  %49 = call double @sin(double noundef %48) #5
  %50 = load double, ptr %11, align 8, !tbaa !14
  %51 = getelementptr inbounds %class.customEllipse, ptr %12, i32 0, i32 23
  %52 = load double, ptr %51, align 8, !tbaa !19
  %53 = call double @cos(double noundef %52) #5
  %54 = fmul double %50, %53
  %55 = call double @llvm.fmuladd.f64(double %46, double %49, double %54)
  %56 = getelementptr inbounds %class.customEllipse, ptr %12, i32 0, i32 19
  %57 = load double, ptr %56, align 8, !tbaa !22
  %58 = fadd double %55, %57
  %59 = fptosi double %58 to i32
  %60 = sub nsw i32 0, %59
  %61 = load ptr, ptr %6, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.pix, ptr %61, i32 0, i32 1
  store i32 %60, ptr %62, align 4, !tbaa !9
  %63 = load double, ptr %7, align 8, !tbaa !14
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #5
  ret double %63
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #2 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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 #4 = { 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 #5 = { 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, !11, i64 4}
!10 = !{!"_ZTS3pix", !11, i64 0, !11, i64 4}
!11 = !{!"int", !7, i64 0}
!12 = !{i64 0, i64 4, !13, i64 4, i64 4, !13}
!13 = !{!11, !11, i64 0}
!14 = !{!15, !15, i64 0}
!15 = !{!"double", !7, i64 0}
!16 = !{!17, !15, i64 160}
!17 = !{!"_ZTS13customEllipse", !15, i64 0, !15, i64 8, !15, i64 16, !15, i64 24, !15, i64 32, !15, i64 40, !15, i64 48, !15, i64 56, !15, i64 64, !15, i64 72, !15, i64 80, !15, i64 88, !15, i64 96, !15, i64 104, !15, i64 112, !15, i64 120, !15, i64 128, !15, i64 136, !15, i64 144, !15, i64 152, !15, i64 160, !15, i64 168, !15, i64 176, !15, i64 184, !15, i64 192, !15, i64 200, !15, i64 208, !11, i64 216, !6, i64 224, !6, i64 232, !6, i64 240, !6, i64 248, !6, i64 256, !6, i64 264}
!18 = !{!17, !15, i64 168}
!19 = !{!17, !15, i64 184}
!20 = !{!17, !15, i64 144}
!21 = !{!10, !11, i64 0}
!22 = !{!17, !15, i64 152}


; 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 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 nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #1

; Function Attrs: mustprogress nofree nounwind willreturn memory(write)
declare double @cos(double noundef) local_unnamed_addr #2

; Function Attrs: mustprogress nofree nounwind willreturn memory(write)
declare double @sin(double noundef) local_unnamed_addr #2

; Function Attrs: mustprogress uwtable
declare dso_local noundef double @_ZN13customEllipse11GetDistanceE3pixRd(ptr noundef nonnull align 8 dereferenceable(272), i64, ptr noundef nonnull align 8 dereferenceable(8)) local_unnamed_addr #3 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef double @_ZN13customEllipse26GetClosestPointAndDistanceE3pixRS0_(ptr noundef nonnull align 8 dereferenceable(272) %0, i64 %1, ptr nocapture noundef nonnull writeonly align 4 dereferenceable(8) %2) local_unnamed_addr #3 align 2 {
  %4 = alloca double, align 8
  %.sroa.2.0.extract.shift = and i64 %1, -4294967296
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %4) #4
  %.sroa.08.0.insert.ext = and i64 %1, 4294967295
  %.sroa.08.0.insert.insert = sub i64 %.sroa.08.0.insert.ext, %.sroa.2.0.extract.shift
  %5 = call noundef double @_ZN13customEllipse11GetDistanceE3pixRd(ptr noundef nonnull align 8 dereferenceable(272) %0, i64 %.sroa.08.0.insert.insert, ptr noundef nonnull align 8 dereferenceable(8) %4)
  %6 = getelementptr inbounds i8, ptr %0, i64 160
  %7 = load double, ptr %6, align 8, !tbaa !5
  %8 = load double, ptr %4, align 8, !tbaa !12
  %9 = call double @cos(double noundef %8) #4
  %10 = fmul double %7, %9
  %11 = getelementptr inbounds i8, ptr %0, i64 168
  %12 = load double, ptr %11, align 8, !tbaa !13
  %13 = load double, ptr %4, align 8, !tbaa !12
  %14 = call double @sin(double noundef %13) #4
  %15 = fmul double %12, %14
  %16 = getelementptr inbounds i8, ptr %0, i64 184
  %17 = load double, ptr %16, align 8, !tbaa !14
  %18 = call double @cos(double noundef %17) #4
  %19 = load double, ptr %16, align 8, !tbaa !14
  %20 = call double @sin(double noundef %19) #4
  %21 = fneg double %15
  %22 = fmul double %20, %21
  %23 = call double @llvm.fmuladd.f64(double %10, double %18, double %22)
  %24 = getelementptr inbounds i8, ptr %0, i64 144
  %25 = load double, ptr %24, align 8, !tbaa !15
  %26 = fadd double %25, %23
  %27 = fptosi double %26 to i32
  store i32 %27, ptr %2, align 4, !tbaa !16
  %28 = load double, ptr %16, align 8, !tbaa !14
  %29 = call double @sin(double noundef %28) #4
  %30 = load double, ptr %16, align 8, !tbaa !14
  %31 = call double @cos(double noundef %30) #4
  %32 = fmul double %15, %31
  %33 = call double @llvm.fmuladd.f64(double %10, double %29, double %32)
  %34 = getelementptr inbounds i8, ptr %0, i64 152
  %35 = load double, ptr %34, align 8, !tbaa !18
  %36 = fadd double %35, %33
  %37 = fptosi double %36 to i32
  %38 = sub nsw i32 0, %37
  %39 = getelementptr inbounds i8, ptr %2, i64 4
  store i32 %38, ptr %39, align 4, !tbaa !19
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #4
  ret double %5
}

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #2 = { 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 #3 = { 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 #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, !7, i64 160}
!6 = !{!"_ZTS13customEllipse", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !7, i64 32, !7, i64 40, !7, i64 48, !7, i64 56, !7, i64 64, !7, i64 72, !7, i64 80, !7, i64 88, !7, i64 96, !7, i64 104, !7, i64 112, !7, i64 120, !7, i64 128, !7, i64 136, !7, i64 144, !7, i64 152, !7, i64 160, !7, i64 168, !7, i64 176, !7, i64 184, !7, i64 192, !7, i64 200, !7, i64 208, !10, i64 216, !11, i64 224, !11, i64 232, !11, i64 240, !11, i64 248, !11, i64 256, !11, i64 264}
!7 = !{!"double", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"any pointer", !8, i64 0}
!12 = !{!7, !7, i64 0}
!13 = !{!6, !7, i64 168}
!14 = !{!6, !7, i64 184}
!15 = !{!6, !7, i64 144}
!16 = !{!17, !10, i64 0}
!17 = !{!"_ZTS3pix", !10, i64 0, !10, i64 4}
!18 = !{!6, !7, i64 152}
!19 = !{!17, !10, i64 4}


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