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

; 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: nounwind
declare double @sqrt(double noundef) #1

; Function Attrs: nounwind allocsize(0)
declare noalias ptr @malloc(i64 noundef) #2

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

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

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

; Function Attrs: mustprogress uwtable
define dso_local noundef double @_ZN13customEllipse18GetRmsFittingErrorEv(ptr noundef nonnull align 8 dereferenceable(272) %0) #4 align 2 {
  %2 = alloca double, align 8
  %3 = alloca ptr, align 8
  %4 = alloca double, align 8
  %5 = alloca i32, align 4
  %6 = alloca %struct.pix, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  %7 = load ptr, ptr %3, align 8
  %8 = getelementptr inbounds %class.customEllipse, ptr %7, i32 0, i32 25
  %9 = load double, ptr %8, align 8, !tbaa !9
  %10 = fcmp une double %9, 0.000000e+00
  br i1 %10, label %11, label %14

11:                                               ; preds = %1
  %12 = getelementptr inbounds %class.customEllipse, ptr %7, i32 0, i32 25
  %13 = load double, ptr %12, align 8, !tbaa !9
  store double %13, ptr %2, align 8
  br label %86

14:                                               ; preds = %1
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #5
  %15 = getelementptr inbounds %class.customEllipse, ptr %7, i32 0, i32 27
  %16 = load i32, ptr %15, align 8, !tbaa !13
  %17 = sext i32 %16 to i64
  %18 = mul i64 %17, 8
  %19 = call noalias ptr @malloc(i64 noundef %18) #6
  %20 = getelementptr inbounds %class.customEllipse, ptr %7, i32 0, i32 30
  store ptr %19, ptr %20, align 8, !tbaa !14
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #5
  store i32 0, ptr %5, align 4, !tbaa !15
  br label %21

21:                                               ; preds = %72, %14
  %22 = load i32, ptr %5, align 4, !tbaa !15
  %23 = getelementptr inbounds %class.customEllipse, ptr %7, i32 0, i32 27
  %24 = load i32, ptr %23, align 8, !tbaa !13
  %25 = icmp slt i32 %22, %24
  br i1 %25, label %27, label %26

26:                                               ; preds = %21
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #5
  br label %75

27:                                               ; preds = %21
  %28 = getelementptr inbounds %class.customEllipse, ptr %7, i32 0, i32 31
  %29 = load ptr, ptr %28, align 8, !tbaa !16
  %30 = icmp ne ptr %29, null
  br i1 %30, label %31, label %48

31:                                               ; preds = %27
  %32 = getelementptr inbounds %class.customEllipse, ptr %7, i32 0, i32 31
  %33 = load ptr, ptr %32, align 8, !tbaa !16
  %34 = load i32, ptr %5, align 4, !tbaa !15
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds %struct.pix, ptr %33, i64 %35
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %6, ptr align 4 %36, i64 8, i1 false), !tbaa.struct !17
  %37 = load i64, ptr %6, align 4
  %38 = call noundef double @_ZN13customEllipse18GetSquaredDistanceE3pixRd(ptr noundef nonnull align 8 dereferenceable(272) %7, i64 %37, ptr noundef nonnull align 8 dereferenceable(8) %4)
  %39 = getelementptr inbounds %class.customEllipse, ptr %7, i32 0, i32 25
  %40 = load double, ptr %39, align 8, !tbaa !9
  %41 = fadd double %40, %38
  store double %41, ptr %39, align 8, !tbaa !9
  %42 = load double, ptr %4, align 8, !tbaa !18
  %43 = getelementptr inbounds %class.customEllipse, ptr %7, i32 0, i32 30
  %44 = load ptr, ptr %43, align 8, !tbaa !14
  %45 = load i32, ptr %5, align 4, !tbaa !15
  %46 = sext i32 %45 to i64
  %47 = getelementptr inbounds double, ptr %44, i64 %46
  store double %42, ptr %47, align 8, !tbaa !18
  br label %71

48:                                               ; preds = %27
  %49 = getelementptr inbounds %class.customEllipse, ptr %7, i32 0, i32 28
  %50 = load ptr, ptr %49, align 8, !tbaa !19
  %51 = load i32, ptr %5, align 4, !tbaa !15
  %52 = sext i32 %51 to i64
  %53 = getelementptr inbounds double, ptr %50, i64 %52
  %54 = load double, ptr %53, align 8, !tbaa !18
  %55 = getelementptr inbounds %class.customEllipse, ptr %7, i32 0, i32 29
  %56 = load ptr, ptr %55, align 8, !tbaa !20
  %57 = load i32, ptr %5, align 4, !tbaa !15
  %58 = sext i32 %57 to i64
  %59 = getelementptr inbounds double, ptr %56, i64 %58
  %60 = load double, ptr %59, align 8, !tbaa !18
  %61 = call noundef double @_ZN13customEllipse18GetSquaredDistanceEddRd(ptr noundef nonnull align 8 dereferenceable(272) %7, double noundef %54, double noundef %60, ptr noundef nonnull align 8 dereferenceable(8) %4)
  %62 = getelementptr inbounds %class.customEllipse, ptr %7, i32 0, i32 25
  %63 = load double, ptr %62, align 8, !tbaa !9
  %64 = fadd double %63, %61
  store double %64, ptr %62, align 8, !tbaa !9
  %65 = load double, ptr %4, align 8, !tbaa !18
  %66 = getelementptr inbounds %class.customEllipse, ptr %7, i32 0, i32 30
  %67 = load ptr, ptr %66, align 8, !tbaa !14
  %68 = load i32, ptr %5, align 4, !tbaa !15
  %69 = sext i32 %68 to i64
  %70 = getelementptr inbounds double, ptr %67, i64 %69
  store double %65, ptr %70, align 8, !tbaa !18
  br label %71

71:                                               ; preds = %48, %31
  br label %72

72:                                               ; preds = %71
  %73 = load i32, ptr %5, align 4, !tbaa !15
  %74 = add nsw i32 %73, 1
  store i32 %74, ptr %5, align 4, !tbaa !15
  br label %21, !llvm.loop !21

75:                                               ; preds = %26
  %76 = getelementptr inbounds %class.customEllipse, ptr %7, i32 0, i32 25
  %77 = load double, ptr %76, align 8, !tbaa !9
  %78 = getelementptr inbounds %class.customEllipse, ptr %7, i32 0, i32 27
  %79 = load i32, ptr %78, align 8, !tbaa !13
  %80 = sitofp i32 %79 to double
  %81 = fdiv double %77, %80
  %82 = call double @sqrt(double noundef %81) #5
  %83 = getelementptr inbounds %class.customEllipse, ptr %7, i32 0, i32 25
  store double %82, ptr %83, align 8, !tbaa !9
  %84 = getelementptr inbounds %class.customEllipse, ptr %7, i32 0, i32 25
  %85 = load double, ptr %84, align 8, !tbaa !9
  store double %85, ptr %2, align 8
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #5
  br label %86

86:                                               ; preds = %75, %11
  %87 = load double, ptr %2, align 8
  ret double %87
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { nounwind allocsize(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 #3 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 }
attributes #6 = { nounwind allocsize(0) }

!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 200}
!10 = !{!"_ZTS13customEllipse", !11, i64 0, !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, !11, i64 136, !11, i64 144, !11, i64 152, !11, i64 160, !11, i64 168, !11, i64 176, !11, i64 184, !11, i64 192, !11, i64 200, !11, i64 208, !12, i64 216, !6, i64 224, !6, i64 232, !6, i64 240, !6, i64 248, !6, i64 256, !6, i64 264}
!11 = !{!"double", !7, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!10, !12, i64 216}
!14 = !{!10, !6, i64 240}
!15 = !{!12, !12, i64 0}
!16 = !{!10, !6, i64 248}
!17 = !{i64 0, i64 4, !15, i64 4, i64 4, !15}
!18 = !{!11, !11, i64 0}
!19 = !{!10, !6, i64 224}
!20 = !{!10, !6, i64 232}
!21 = distinct !{!21, !22}
!22 = !{!"llvm.loop.mustprogress"}


; 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.pix = type { i32, i32 }

; 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 nofree nounwind willreturn memory(write)
declare double @sqrt(double noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #2

; Function Attrs: mustprogress uwtable
declare dso_local noundef double @_ZN13customEllipse18GetSquaredDistanceE3pixRd(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
declare dso_local noundef double @_ZN13customEllipse18GetSquaredDistanceEddRd(ptr noundef nonnull align 8 dereferenceable(272), double noundef, double noundef, ptr noundef nonnull align 8 dereferenceable(8)) local_unnamed_addr #3 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef double @_ZN13customEllipse18GetRmsFittingErrorEv(ptr noundef nonnull align 8 dereferenceable(272) %0) local_unnamed_addr #3 align 2 {
  %2 = alloca double, align 8
  %3 = getelementptr inbounds i8, ptr %0, i64 200
  %4 = load double, ptr %3, align 8, !tbaa !5
  %5 = fcmp une double %4, 0.000000e+00
  br i1 %5, label %42, label %6

6:                                                ; preds = %1
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %2) #4
  %7 = getelementptr inbounds i8, ptr %0, i64 216
  %8 = load i32, ptr %7, align 8, !tbaa !12
  %9 = sext i32 %8 to i64
  %10 = shl nsw i64 %9, 3
  %11 = tail call noalias ptr @malloc(i64 noundef %10) #5
  %12 = getelementptr inbounds i8, ptr %0, i64 240
  store ptr %11, ptr %12, align 8, !tbaa !13
  %13 = icmp sgt i32 %8, 0
  br i1 %13, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %6
  %14 = getelementptr inbounds i8, ptr %0, i64 248
  %15 = getelementptr inbounds i8, ptr %0, i64 224
  %16 = getelementptr inbounds i8, ptr %0, i64 232
  br label %21

._crit_edge.loopexit:                             ; preds = %34
  %.pre = load double, ptr %3, align 8, !tbaa !5
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %6
  %17 = phi double [ %4, %6 ], [ %.pre, %._crit_edge.loopexit ]
  %.lcssa = phi i32 [ %8, %6 ], [ %39, %._crit_edge.loopexit ]
  %18 = sitofp i32 %.lcssa to double
  %19 = fdiv double %17, %18
  %20 = call double @sqrt(double noundef %19) #4
  store double %20, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #4
  br label %42

21:                                               ; preds = %.lr.ph, %34
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %34 ]
  %22 = load ptr, ptr %14, align 8, !tbaa !14
  %.not = icmp eq ptr %22, null
  br i1 %.not, label %26, label %23

23:                                               ; preds = %21
  %24 = getelementptr inbounds %struct.pix, ptr %22, i64 %indvars.iv
  %.sroa.0.0.copyload = load i64, ptr %24, align 4
  %25 = call noundef double @_ZN13customEllipse18GetSquaredDistanceE3pixRd(ptr noundef nonnull align 8 dereferenceable(272) %0, i64 %.sroa.0.0.copyload, ptr noundef nonnull align 8 dereferenceable(8) %2)
  br label %34

26:                                               ; preds = %21
  %27 = load ptr, ptr %15, align 8, !tbaa !15
  %28 = getelementptr inbounds double, ptr %27, i64 %indvars.iv
  %29 = load double, ptr %28, align 8, !tbaa !16
  %30 = load ptr, ptr %16, align 8, !tbaa !17
  %31 = getelementptr inbounds double, ptr %30, i64 %indvars.iv
  %32 = load double, ptr %31, align 8, !tbaa !16
  %33 = call noundef double @_ZN13customEllipse18GetSquaredDistanceEddRd(ptr noundef nonnull align 8 dereferenceable(272) %0, double noundef %29, double noundef %32, ptr noundef nonnull align 8 dereferenceable(8) %2)
  br label %34

34:                                               ; preds = %23, %26
  %.sink19 = phi double [ %25, %23 ], [ %33, %26 ]
  %35 = load double, ptr %3, align 8, !tbaa !5
  %36 = fadd double %.sink19, %35
  store double %36, ptr %3, align 8, !tbaa !5
  %.sink = load double, ptr %2, align 8, !tbaa !16
  %37 = load ptr, ptr %12, align 8, !tbaa !13
  %38 = getelementptr inbounds double, ptr %37, i64 %indvars.iv
  store double %.sink, ptr %38, align 8, !tbaa !16
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %39 = load i32, ptr %7, align 8, !tbaa !12
  %40 = sext i32 %39 to i64
  %41 = icmp slt i64 %indvars.iv.next, %40
  br i1 %41, label %21, label %._crit_edge.loopexit, !llvm.loop !18

42:                                               ; preds = %1, %._crit_edge
  %.0 = phi double [ %20, %._crit_edge ], [ %4, %1 ]
  ret double %.0
}

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" "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 }
attributes #5 = { nounwind allocsize(0) }

!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 200}
!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 = !{!6, !10, i64 216}
!13 = !{!6, !11, i64 240}
!14 = !{!6, !11, i64 248}
!15 = !{!6, !11, i64 224}
!16 = !{!7, !7, i64 0}
!17 = !{!6, !11, i64 232}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass