; LLVM IR from jorgemf/c-evolutionary-library :: examples/tsp/TSPFitness.ll (ZN10TSPFitness25evaluateEuclideanDistanceEPii)

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

%class.TSPFitness = type <{ %class.FitnessFunction, ptr, ptr, i32, [4 x i8] }>
%class.FitnessFunction = type { 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: mustprogress nounwind uwtable
define dso_local noundef double @_ZN10TSPFitness25evaluateEuclideanDistanceEPii(ptr noundef nonnull align 8 dereferenceable(28) %0, ptr noundef %1, i32 noundef %2) #1 align 2 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca double, align 8
  %8 = alloca double, align 8
  %9 = alloca double, align 8
  %10 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store i32 %2, ptr %6, align 4, !tbaa !9
  %11 = load ptr, ptr %4, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  store double 0.000000e+00, ptr %7, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #4
  store i32 0, ptr %10, align 4, !tbaa !9
  br label %12

12:                                               ; preds = %86, %3
  %13 = load i32, ptr %10, align 4, !tbaa !9
  %14 = load i32, ptr %6, align 4, !tbaa !9
  %15 = sub nsw i32 %14, 1
  %16 = icmp slt i32 %13, %15
  br i1 %16, label %18, label %17

17:                                               ; preds = %12
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #4
  br label %89

18:                                               ; preds = %12
  %19 = getelementptr inbounds %class.TSPFitness, ptr %11, i32 0, i32 2
  %20 = load ptr, ptr %19, align 8, !tbaa !13
  %21 = load ptr, ptr %5, align 8, !tbaa !5
  %22 = load i32, ptr %10, align 4, !tbaa !9
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds i32, ptr %21, i64 %23
  %25 = load i32, ptr %24, align 4, !tbaa !9
  %26 = sub nsw i32 %25, 1
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds ptr, ptr %20, i64 %27
  %29 = load ptr, ptr %28, align 8, !tbaa !5
  %30 = getelementptr inbounds double, ptr %29, i64 0
  %31 = load double, ptr %30, align 8, !tbaa !11
  %32 = getelementptr inbounds %class.TSPFitness, ptr %11, i32 0, i32 2
  %33 = load ptr, ptr %32, align 8, !tbaa !13
  %34 = load ptr, ptr %5, align 8, !tbaa !5
  %35 = load i32, ptr %10, align 4, !tbaa !9
  %36 = add nsw i32 %35, 1
  %37 = sext i32 %36 to i64
  %38 = getelementptr inbounds i32, ptr %34, i64 %37
  %39 = load i32, ptr %38, align 4, !tbaa !9
  %40 = sub nsw i32 %39, 1
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds ptr, ptr %33, i64 %41
  %43 = load ptr, ptr %42, align 8, !tbaa !5
  %44 = getelementptr inbounds double, ptr %43, i64 0
  %45 = load double, ptr %44, align 8, !tbaa !11
  %46 = fsub double %31, %45
  store double %46, ptr %8, align 8, !tbaa !11
  %47 = getelementptr inbounds %class.TSPFitness, ptr %11, i32 0, i32 2
  %48 = load ptr, ptr %47, align 8, !tbaa !13
  %49 = load ptr, ptr %5, align 8, !tbaa !5
  %50 = load i32, ptr %10, align 4, !tbaa !9
  %51 = sext i32 %50 to i64
  %52 = getelementptr inbounds i32, ptr %49, i64 %51
  %53 = load i32, ptr %52, align 4, !tbaa !9
  %54 = sub nsw i32 %53, 1
  %55 = sext i32 %54 to i64
  %56 = getelementptr inbounds ptr, ptr %48, i64 %55
  %57 = load ptr, ptr %56, align 8, !tbaa !5
  %58 = getelementptr inbounds double, ptr %57, i64 1
  %59 = load double, ptr %58, align 8, !tbaa !11
  %60 = getelementptr inbounds %class.TSPFitness, ptr %11, i32 0, i32 2
  %61 = load ptr, ptr %60, align 8, !tbaa !13
  %62 = load ptr, ptr %5, align 8, !tbaa !5
  %63 = load i32, ptr %10, align 4, !tbaa !9
  %64 = add nsw i32 %63, 1
  %65 = sext i32 %64 to i64
  %66 = getelementptr inbounds i32, ptr %62, i64 %65
  %67 = load i32, ptr %66, align 4, !tbaa !9
  %68 = sub nsw i32 %67, 1
  %69 = sext i32 %68 to i64
  %70 = getelementptr inbounds ptr, ptr %61, i64 %69
  %71 = load ptr, ptr %70, align 8, !tbaa !5
  %72 = getelementptr inbounds double, ptr %71, i64 1
  %73 = load double, ptr %72, align 8, !tbaa !11
  %74 = fsub double %59, %73
  store double %74, ptr %9, align 8, !tbaa !11
  %75 = load double, ptr %8, align 8, !tbaa !11
  %76 = load double, ptr %8, align 8, !tbaa !11
  %77 = load double, ptr %9, align 8, !tbaa !11
  %78 = load double, ptr %9, align 8, !tbaa !11
  %79 = fmul double %77, %78
  %80 = call double @llvm.fmuladd.f64(double %75, double %76, double %79)
  %81 = call double @sqrt(double noundef %80) #4
  %82 = fptosi double %81 to i32
  %83 = sitofp i32 %82 to double
  %84 = load double, ptr %7, align 8, !tbaa !11
  %85 = fadd double %84, %83
  store double %85, ptr %7, align 8, !tbaa !11
  br label %86

86:                                               ; preds = %18
  %87 = load i32, ptr %10, align 4, !tbaa !9
  %88 = add nsw i32 %87, 1
  store i32 %88, ptr %10, align 4, !tbaa !9
  br label %12, !llvm.loop !17

89:                                               ; preds = %17
  %90 = getelementptr inbounds %class.TSPFitness, ptr %11, i32 0, i32 2
  %91 = load ptr, ptr %90, align 8, !tbaa !13
  %92 = load ptr, ptr %5, align 8, !tbaa !5
  %93 = load i32, ptr %6, align 4, !tbaa !9
  %94 = sub nsw i32 %93, 1
  %95 = sext i32 %94 to i64
  %96 = getelementptr inbounds i32, ptr %92, i64 %95
  %97 = load i32, ptr %96, align 4, !tbaa !9
  %98 = sub nsw i32 %97, 1
  %99 = sext i32 %98 to i64
  %100 = getelementptr inbounds ptr, ptr %91, i64 %99
  %101 = load ptr, ptr %100, align 8, !tbaa !5
  %102 = getelementptr inbounds double, ptr %101, i64 0
  %103 = load double, ptr %102, align 8, !tbaa !11
  %104 = getelementptr inbounds %class.TSPFitness, ptr %11, i32 0, i32 2
  %105 = load ptr, ptr %104, align 8, !tbaa !13
  %106 = load ptr, ptr %5, align 8, !tbaa !5
  %107 = getelementptr inbounds i32, ptr %106, i64 0
  %108 = load i32, ptr %107, align 4, !tbaa !9
  %109 = sub nsw i32 %108, 1
  %110 = sext i32 %109 to i64
  %111 = getelementptr inbounds ptr, ptr %105, i64 %110
  %112 = load ptr, ptr %111, align 8, !tbaa !5
  %113 = getelementptr inbounds double, ptr %112, i64 0
  %114 = load double, ptr %113, align 8, !tbaa !11
  %115 = fsub double %103, %114
  store double %115, ptr %8, align 8, !tbaa !11
  %116 = getelementptr inbounds %class.TSPFitness, ptr %11, i32 0, i32 2
  %117 = load ptr, ptr %116, align 8, !tbaa !13
  %118 = load ptr, ptr %5, align 8, !tbaa !5
  %119 = load i32, ptr %6, align 4, !tbaa !9
  %120 = sub nsw i32 %119, 1
  %121 = sext i32 %120 to i64
  %122 = getelementptr inbounds i32, ptr %118, i64 %121
  %123 = load i32, ptr %122, align 4, !tbaa !9
  %124 = sub nsw i32 %123, 1
  %125 = sext i32 %124 to i64
  %126 = getelementptr inbounds ptr, ptr %117, i64 %125
  %127 = load ptr, ptr %126, align 8, !tbaa !5
  %128 = getelementptr inbounds double, ptr %127, i64 1
  %129 = load double, ptr %128, align 8, !tbaa !11
  %130 = getelementptr inbounds %class.TSPFitness, ptr %11, i32 0, i32 2
  %131 = load ptr, ptr %130, align 8, !tbaa !13
  %132 = load ptr, ptr %5, align 8, !tbaa !5
  %133 = getelementptr inbounds i32, ptr %132, i64 0
  %134 = load i32, ptr %133, align 4, !tbaa !9
  %135 = sub nsw i32 %134, 1
  %136 = sext i32 %135 to i64
  %137 = getelementptr inbounds ptr, ptr %131, i64 %136
  %138 = load ptr, ptr %137, align 8, !tbaa !5
  %139 = getelementptr inbounds double, ptr %138, i64 1
  %140 = load double, ptr %139, align 8, !tbaa !11
  %141 = fsub double %129, %140
  store double %141, ptr %9, align 8, !tbaa !11
  %142 = load double, ptr %8, align 8, !tbaa !11
  %143 = load double, ptr %8, align 8, !tbaa !11
  %144 = load double, ptr %9, align 8, !tbaa !11
  %145 = load double, ptr %9, align 8, !tbaa !11
  %146 = fmul double %144, %145
  %147 = call double @llvm.fmuladd.f64(double %142, double %143, double %146)
  %148 = call double @sqrt(double noundef %147) #4
  %149 = fptosi double %148 to i32
  %150 = sitofp i32 %149 to double
  %151 = load double, ptr %7, align 8, !tbaa !11
  %152 = fadd double %151, %150
  store double %152, ptr %7, align 8, !tbaa !11
  %153 = load double, ptr %7, align 8, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  ret double %153
}

; Function Attrs: nounwind
declare double @sqrt(double noundef) #2

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress 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 #2 = { 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 #3 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"double", !7, i64 0}
!13 = !{!14, !6, i64 16}
!14 = !{!"_ZTS10TSPFitness", !15, i64 0, !6, i64 8, !6, i64 16, !16, i64 24}
!15 = !{!"_ZTS15FitnessFunction"}
!16 = !{!"_ZTSN12AlgorithmTSP9DATA_TYPEE", !7, i64 0}
!17 = distinct !{!17, !18}
!18 = !{!"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"

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(read, inaccessiblemem: none) uwtable
define dso_local noundef double @_ZN10TSPFitness25evaluateEuclideanDistanceEPii(ptr nocapture noundef nonnull readonly align 8 dereferenceable(28) %0, ptr nocapture noundef readonly %1, i32 noundef %2) local_unnamed_addr #0 align 2 {
  %4 = add i32 %2, -1
  %5 = icmp sgt i32 %2, 1
  %6 = getelementptr inbounds i8, ptr %0, i64 16
  %7 = load ptr, ptr %6, align 8, !tbaa !5
  br i1 %5, label %.lr.ph, label %.._crit_edge_crit_edge

.._crit_edge_crit_edge:                           ; preds = %3
  %.pre43 = load i32, ptr %1, align 4, !tbaa !12
  %.pre44 = sext i32 %.pre43 to i64
  br label %._crit_edge

.lr.ph:                                           ; preds = %3
  %invariant.gep = getelementptr i8, ptr %7, i64 -8
  %wide.trip.count = zext nneg i32 %4 to i64
  %.pre = load i32, ptr %1, align 4, !tbaa !12
  %.phi.trans.insert = sext i32 %.pre to i64
  %gep.phi.trans.insert = getelementptr ptr, ptr %invariant.gep, i64 %.phi.trans.insert
  %.pre37 = load ptr, ptr %gep.phi.trans.insert, align 8, !tbaa !14
  %.pre38 = load double, ptr %.pre37, align 8, !tbaa !15
  %.phi.trans.insert39 = getelementptr inbounds i8, ptr %.pre37, i64 8
  %.pre40 = load double, ptr %.phi.trans.insert39, align 8, !tbaa !15
  br label %31

._crit_edge:                                      ; preds = %31, %.._crit_edge_crit_edge
  %.pre-phi = phi i64 [ %.pre44, %.._crit_edge_crit_edge ], [ %.phi.trans.insert, %31 ]
  %.028.lcssa = phi double [ 0.000000e+00, %.._crit_edge_crit_edge ], [ %47, %31 ]
  %8 = sext i32 %4 to i64
  %9 = getelementptr inbounds i32, ptr %1, i64 %8
  %10 = load i32, ptr %9, align 4, !tbaa !12
  %11 = sext i32 %10 to i64
  %12 = getelementptr ptr, ptr %7, i64 %11
  %13 = getelementptr i8, ptr %12, i64 -8
  %14 = load ptr, ptr %13, align 8, !tbaa !14
  %15 = load double, ptr %14, align 8, !tbaa !15
  %16 = getelementptr ptr, ptr %7, i64 %.pre-phi
  %17 = getelementptr i8, ptr %16, i64 -8
  %18 = load ptr, ptr %17, align 8, !tbaa !14
  %19 = load double, ptr %18, align 8, !tbaa !15
  %20 = fsub double %15, %19
  %21 = getelementptr inbounds i8, ptr %14, i64 8
  %22 = load double, ptr %21, align 8, !tbaa !15
  %23 = getelementptr inbounds i8, ptr %18, i64 8
  %24 = load double, ptr %23, align 8, !tbaa !15
  %25 = fsub double %22, %24
  %26 = fmul double %25, %25
  %27 = tail call double @llvm.fmuladd.f64(double %20, double %20, double %26)
  %sqrt = tail call double @llvm.sqrt.f64(double %27)
  %28 = fptosi double %sqrt to i32
  %29 = sitofp i32 %28 to double
  %30 = fadd double %.028.lcssa, %29
  ret double %30

31:                                               ; preds = %.lr.ph, %31
  %32 = phi double [ %.pre40, %.lr.ph ], [ %41, %31 ]
  %33 = phi double [ %.pre38, %.lr.ph ], [ %38, %31 ]
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %31 ]
  %.02831 = phi double [ 0.000000e+00, %.lr.ph ], [ %47, %31 ]
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %34 = getelementptr inbounds i32, ptr %1, i64 %indvars.iv.next
  %35 = load i32, ptr %34, align 4, !tbaa !12
  %36 = sext i32 %35 to i64
  %gep35 = getelementptr ptr, ptr %invariant.gep, i64 %36
  %37 = load ptr, ptr %gep35, align 8, !tbaa !14
  %38 = load double, ptr %37, align 8, !tbaa !15
  %39 = fsub double %33, %38
  %40 = getelementptr inbounds i8, ptr %37, i64 8
  %41 = load double, ptr %40, align 8, !tbaa !15
  %42 = fsub double %32, %41
  %43 = fmul double %42, %42
  %44 = tail call double @llvm.fmuladd.f64(double %39, double %39, double %43)
  %sqrt30 = tail call double @llvm.sqrt.f64(double %44)
  %45 = fptosi double %sqrt30 to i32
  %46 = sitofp i32 %45 to double
  %47 = fadd double %.02831, %46
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge, label %31, !llvm.loop !17
}

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

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

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(read, inaccessiblemem: none) 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) }
attributes #2 = { 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, !8, i64 16}
!6 = !{!"_ZTS10TSPFitness", !7, i64 0, !8, i64 8, !8, i64 16, !11, i64 24}
!7 = !{!"_ZTS15FitnessFunction"}
!8 = !{!"any pointer", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C++ TBAA"}
!11 = !{!"_ZTSN12AlgorithmTSP9DATA_TYPEE", !9, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"int", !9, i64 0}
!14 = !{!8, !8, i64 0}
!15 = !{!16, !16, i64 0}
!16 = !{!"double", !9, i64 0}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: AggressiveInstCombinePass,BDCEPass,CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass