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

; 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 @_ZN10TSPFitness19evaluateATTDistanceEPii(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 double, align 8
  %11 = alloca double, align 8
  %12 = 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
  %13 = 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 8, ptr %10) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #4
  store i32 0, ptr %12, align 4, !tbaa !9
  br label %14

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

19:                                               ; preds = %14
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #4
  br label %104

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

91:                                               ; preds = %20
  %92 = load double, ptr %11, align 8, !tbaa !11
  %93 = fadd double %92, 1.000000e+00
  %94 = load double, ptr %7, align 8, !tbaa !11
  %95 = fadd double %94, %93
  store double %95, ptr %7, align 8, !tbaa !11
  br label %100

96:                                               ; preds = %20
  %97 = load double, ptr %11, align 8, !tbaa !11
  %98 = load double, ptr %7, align 8, !tbaa !11
  %99 = fadd double %98, %97
  store double %99, ptr %7, align 8, !tbaa !11
  br label %100

100:                                              ; preds = %96, %91
  br label %101

101:                                              ; preds = %100
  %102 = load i32, ptr %12, align 4, !tbaa !9
  %103 = add nsw i32 %102, 1
  store i32 %103, ptr %12, align 4, !tbaa !9
  br label %14, !llvm.loop !17

104:                                              ; preds = %19
  %105 = getelementptr inbounds %class.TSPFitness, ptr %13, i32 0, i32 2
  %106 = load ptr, ptr %105, align 8, !tbaa !13
  %107 = load ptr, ptr %5, align 8, !tbaa !5
  %108 = load i32, ptr %6, align 4, !tbaa !9
  %109 = sub nsw i32 %108, 1
  %110 = sext i32 %109 to i64
  %111 = getelementptr inbounds i32, ptr %107, i64 %110
  %112 = load i32, ptr %111, align 4, !tbaa !9
  %113 = sub nsw i32 %112, 1
  %114 = sext i32 %113 to i64
  %115 = getelementptr inbounds ptr, ptr %106, i64 %114
  %116 = load ptr, ptr %115, align 8, !tbaa !5
  %117 = getelementptr inbounds double, ptr %116, i64 0
  %118 = load double, ptr %117, align 8, !tbaa !11
  %119 = getelementptr inbounds %class.TSPFitness, ptr %13, i32 0, i32 2
  %120 = load ptr, ptr %119, align 8, !tbaa !13
  %121 = load ptr, ptr %5, align 8, !tbaa !5
  %122 = getelementptr inbounds i32, ptr %121, i64 0
  %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 %120, i64 %125
  %127 = load ptr, ptr %126, align 8, !tbaa !5
  %128 = getelementptr inbounds double, ptr %127, i64 0
  %129 = load double, ptr %128, align 8, !tbaa !11
  %130 = fsub double %118, %129
  store double %130, ptr %8, align 8, !tbaa !11
  %131 = getelementptr inbounds %class.TSPFitness, ptr %13, i32 0, i32 2
  %132 = load ptr, ptr %131, align 8, !tbaa !13
  %133 = load ptr, ptr %5, align 8, !tbaa !5
  %134 = load i32, ptr %6, align 4, !tbaa !9
  %135 = sub nsw i32 %134, 1
  %136 = sext i32 %135 to i64
  %137 = getelementptr inbounds i32, ptr %133, i64 %136
  %138 = load i32, ptr %137, align 4, !tbaa !9
  %139 = sub nsw i32 %138, 1
  %140 = sext i32 %139 to i64
  %141 = getelementptr inbounds ptr, ptr %132, i64 %140
  %142 = load ptr, ptr %141, align 8, !tbaa !5
  %143 = getelementptr inbounds double, ptr %142, i64 1
  %144 = load double, ptr %143, align 8, !tbaa !11
  %145 = getelementptr inbounds %class.TSPFitness, ptr %13, i32 0, i32 2
  %146 = load ptr, ptr %145, align 8, !tbaa !13
  %147 = load ptr, ptr %5, align 8, !tbaa !5
  %148 = getelementptr inbounds i32, ptr %147, i64 0
  %149 = load i32, ptr %148, align 4, !tbaa !9
  %150 = sub nsw i32 %149, 1
  %151 = sext i32 %150 to i64
  %152 = getelementptr inbounds ptr, ptr %146, i64 %151
  %153 = load ptr, ptr %152, align 8, !tbaa !5
  %154 = getelementptr inbounds double, ptr %153, i64 1
  %155 = load double, ptr %154, align 8, !tbaa !11
  %156 = fsub double %144, %155
  store double %156, ptr %9, align 8, !tbaa !11
  %157 = load double, ptr %8, align 8, !tbaa !11
  %158 = load double, ptr %8, align 8, !tbaa !11
  %159 = load double, ptr %9, align 8, !tbaa !11
  %160 = load double, ptr %9, align 8, !tbaa !11
  %161 = fmul double %159, %160
  %162 = call double @llvm.fmuladd.f64(double %157, double %158, double %161)
  %163 = fdiv double %162, 1.000000e+01
  %164 = call double @sqrt(double noundef %163) #4
  store double %164, ptr %10, align 8, !tbaa !11
  %165 = load double, ptr %10, align 8, !tbaa !11
  %166 = fptosi double %165 to i32
  %167 = sitofp i32 %166 to double
  store double %167, ptr %11, align 8, !tbaa !11
  %168 = load double, ptr %11, align 8, !tbaa !11
  %169 = load double, ptr %10, align 8, !tbaa !11
  %170 = fcmp olt double %168, %169
  br i1 %170, label %171, label %176

171:                                              ; preds = %104
  %172 = load double, ptr %11, align 8, !tbaa !11
  %173 = fadd double %172, 1.000000e+00
  %174 = load double, ptr %7, align 8, !tbaa !11
  %175 = fadd double %174, %173
  store double %175, ptr %7, align 8, !tbaa !11
  br label %180

176:                                              ; preds = %104
  %177 = load double, ptr %11, align 8, !tbaa !11
  %178 = load double, ptr %7, align 8, !tbaa !11
  %179 = fadd double %178, %177
  store double %179, ptr %7, align 8, !tbaa !11
  br label %180

180:                                              ; preds = %176, %171
  %181 = load double, ptr %7, align 8, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  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 %181
}

; 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 @_ZN10TSPFitness19evaluateATTDistanceEPii(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
  %.pre60 = load i32, ptr %1, align 4, !tbaa !12
  %.pre61 = sext i32 %.pre60 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
  %.pre54 = load ptr, ptr %gep.phi.trans.insert, align 8, !tbaa !14
  %.pre55 = load double, ptr %.pre54, align 8, !tbaa !15
  %.phi.trans.insert56 = getelementptr inbounds i8, ptr %.pre54, i64 8
  %.pre57 = load double, ptr %.phi.trans.insert56, align 8, !tbaa !15
  br label %33

._crit_edge:                                      ; preds = %33, %.._crit_edge_crit_edge
  %.pre-phi = phi i64 [ %.pre61, %.._crit_edge_crit_edge ], [ %.phi.trans.insert, %33 ]
  %.040.lcssa = phi double [ 0.000000e+00, %.._crit_edge_crit_edge ], [ %.1, %33 ]
  %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)
  %28 = fdiv double %27, 1.000000e+01
  %sqrt = tail call double @llvm.sqrt.f64(double %28)
  %29 = fptosi double %sqrt to i32
  %30 = sitofp i32 %29 to double
  %31 = fcmp ogt double %sqrt, %30
  %32 = fadd double %30, 1.000000e+00
  %.pn = select i1 %31, double %32, double %30
  %.2 = fadd double %.040.lcssa, %.pn
  ret double %.2

33:                                               ; preds = %.lr.ph, %33
  %34 = phi double [ %.pre57, %.lr.ph ], [ %43, %33 ]
  %35 = phi double [ %.pre55, %.lr.ph ], [ %40, %33 ]
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %33 ]
  %.04048 = phi double [ 0.000000e+00, %.lr.ph ], [ %.1, %33 ]
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %36 = getelementptr inbounds i32, ptr %1, i64 %indvars.iv.next
  %37 = load i32, ptr %36, align 4, !tbaa !12
  %38 = sext i32 %37 to i64
  %gep52 = getelementptr ptr, ptr %invariant.gep, i64 %38
  %39 = load ptr, ptr %gep52, align 8, !tbaa !14
  %40 = load double, ptr %39, align 8, !tbaa !15
  %41 = fsub double %35, %40
  %42 = getelementptr inbounds i8, ptr %39, i64 8
  %43 = load double, ptr %42, align 8, !tbaa !15
  %44 = fsub double %34, %43
  %45 = fmul double %44, %44
  %46 = tail call double @llvm.fmuladd.f64(double %41, double %41, double %45)
  %47 = fdiv double %46, 1.000000e+01
  %sqrt47 = tail call double @llvm.sqrt.f64(double %47)
  %48 = fptosi double %sqrt47 to i32
  %49 = sitofp i32 %48 to double
  %50 = fcmp ogt double %sqrt47, %49
  %51 = fadd double %49, 1.000000e+00
  %.pn46 = select i1 %50, double %51, double %49
  %.1 = fadd double %.04048, %.pn46
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge, label %33, !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