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

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

; 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 void @_ZN12AlgorithmTSP31calculateEuclideanDistanceCeilsEiPPdS1_(ptr noundef nonnull align 8 dereferenceable(88) %0, i32 noundef %1, ptr noundef %2, ptr noundef %3) #1 align 2 {
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca double, align 8
  %13 = alloca double, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !9
  store ptr %2, ptr %7, align 8, !tbaa !5
  store ptr %3, ptr %8, align 8, !tbaa !5
  %14 = load ptr, ptr %5, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  store i32 0, ptr %9, align 4, !tbaa !9
  br label %15

15:                                               ; preds = %104, %4
  %16 = load i32, ptr %9, align 4, !tbaa !9
  %17 = load i32, ptr %6, align 4, !tbaa !9
  %18 = icmp slt i32 %16, %17
  br i1 %18, label %20, label %19

19:                                               ; preds = %15
  store i32 2, ptr %10, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  br label %107

20:                                               ; preds = %15
  %21 = load ptr, ptr %8, align 8, !tbaa !5
  %22 = load i32, ptr %9, align 4, !tbaa !9
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds ptr, ptr %21, i64 %23
  %25 = load ptr, ptr %24, align 8, !tbaa !5
  %26 = load i32, ptr %9, align 4, !tbaa !9
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds double, ptr %25, i64 %27
  store double 0.000000e+00, ptr %28, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #4
  %29 = load i32, ptr %9, align 4, !tbaa !9
  %30 = add nsw i32 %29, 1
  store i32 %30, ptr %11, align 4, !tbaa !9
  br label %31

31:                                               ; preds = %100, %20
  %32 = load i32, ptr %11, align 4, !tbaa !9
  %33 = load i32, ptr %6, align 4, !tbaa !9
  %34 = icmp slt i32 %32, %33
  br i1 %34, label %36, label %35

35:                                               ; preds = %31
  store i32 5, ptr %10, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #4
  br label %103

36:                                               ; preds = %31
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #4
  %37 = load ptr, ptr %7, align 8, !tbaa !5
  %38 = load i32, ptr %9, align 4, !tbaa !9
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds ptr, ptr %37, i64 %39
  %41 = load ptr, ptr %40, align 8, !tbaa !5
  %42 = getelementptr inbounds double, ptr %41, i64 0
  %43 = load double, ptr %42, align 8, !tbaa !11
  %44 = load ptr, ptr %7, align 8, !tbaa !5
  %45 = load i32, ptr %11, align 4, !tbaa !9
  %46 = sext i32 %45 to i64
  %47 = getelementptr inbounds ptr, ptr %44, i64 %46
  %48 = load ptr, ptr %47, align 8, !tbaa !5
  %49 = getelementptr inbounds double, ptr %48, i64 0
  %50 = load double, ptr %49, align 8, !tbaa !11
  %51 = fsub double %43, %50
  store double %51, ptr %12, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #4
  %52 = load ptr, ptr %7, align 8, !tbaa !5
  %53 = load i32, ptr %9, align 4, !tbaa !9
  %54 = sext i32 %53 to i64
  %55 = getelementptr inbounds ptr, ptr %52, i64 %54
  %56 = load ptr, ptr %55, align 8, !tbaa !5
  %57 = getelementptr inbounds double, ptr %56, i64 1
  %58 = load double, ptr %57, align 8, !tbaa !11
  %59 = load ptr, ptr %7, align 8, !tbaa !5
  %60 = load i32, ptr %11, align 4, !tbaa !9
  %61 = sext i32 %60 to i64
  %62 = getelementptr inbounds ptr, ptr %59, i64 %61
  %63 = load ptr, ptr %62, align 8, !tbaa !5
  %64 = getelementptr inbounds double, ptr %63, i64 1
  %65 = load double, ptr %64, align 8, !tbaa !11
  %66 = fsub double %58, %65
  store double %66, ptr %13, align 8, !tbaa !11
  %67 = load double, ptr %12, align 8, !tbaa !11
  %68 = load double, ptr %12, align 8, !tbaa !11
  %69 = load double, ptr %13, align 8, !tbaa !11
  %70 = load double, ptr %13, align 8, !tbaa !11
  %71 = fmul double %69, %70
  %72 = call double @llvm.fmuladd.f64(double %67, double %68, double %71)
  %73 = call double @sqrt(double noundef %72) #4
  %74 = call double @llvm.ceil.f64(double %73)
  %75 = load ptr, ptr %8, align 8, !tbaa !5
  %76 = load i32, ptr %9, align 4, !tbaa !9
  %77 = sext i32 %76 to i64
  %78 = getelementptr inbounds ptr, ptr %75, i64 %77
  %79 = load ptr, ptr %78, align 8, !tbaa !5
  %80 = load i32, ptr %11, align 4, !tbaa !9
  %81 = sext i32 %80 to i64
  %82 = getelementptr inbounds double, ptr %79, i64 %81
  store double %74, ptr %82, align 8, !tbaa !11
  %83 = load ptr, ptr %8, align 8, !tbaa !5
  %84 = load i32, ptr %9, align 4, !tbaa !9
  %85 = sext i32 %84 to i64
  %86 = getelementptr inbounds ptr, ptr %83, i64 %85
  %87 = load ptr, ptr %86, align 8, !tbaa !5
  %88 = load i32, ptr %11, align 4, !tbaa !9
  %89 = sext i32 %88 to i64
  %90 = getelementptr inbounds double, ptr %87, i64 %89
  %91 = load double, ptr %90, align 8, !tbaa !11
  %92 = load ptr, ptr %8, align 8, !tbaa !5
  %93 = load i32, ptr %11, align 4, !tbaa !9
  %94 = sext i32 %93 to i64
  %95 = getelementptr inbounds ptr, ptr %92, i64 %94
  %96 = load ptr, ptr %95, align 8, !tbaa !5
  %97 = load i32, ptr %9, align 4, !tbaa !9
  %98 = sext i32 %97 to i64
  %99 = getelementptr inbounds double, ptr %96, i64 %98
  store double %91, ptr %99, align 8, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #4
  br label %100

100:                                              ; preds = %36
  %101 = load i32, ptr %11, align 4, !tbaa !9
  %102 = add nsw i32 %101, 1
  store i32 %102, ptr %11, align 4, !tbaa !9
  br label %31, !llvm.loop !13

103:                                              ; preds = %35
  br label %104

104:                                              ; preds = %103
  %105 = load i32, ptr %9, align 4, !tbaa !9
  %106 = add nsw i32 %105, 1
  store i32 %106, ptr %9, align 4, !tbaa !9
  br label %15, !llvm.loop !15

107:                                              ; preds = %19
  ret void
}

; 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

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.ceil.f64(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 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}


; 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 memory(readwrite, inaccessiblemem: none) uwtable
define dso_local void @_ZN12AlgorithmTSP31calculateEuclideanDistanceCeilsEiPPdS1_(ptr nocapture noundef nonnull readnone align 8 dereferenceable(88) %0, i32 noundef %1, ptr nocapture noundef readonly %2, ptr nocapture noundef readonly %3) local_unnamed_addr #0 align 2 {
  %5 = icmp sgt i32 %1, 0
  br i1 %5, label %.lr.ph35.preheader, label %._crit_edge

.lr.ph35.preheader:                               ; preds = %4
  %6 = zext nneg i32 %1 to i64
  %wide.trip.count42 = zext nneg i32 %1 to i64
  br label %.lr.ph35

.loopexit:                                        ; preds = %14, %.lr.ph35
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond43.not = icmp eq i64 %indvars.iv.next40, %wide.trip.count42
  br i1 %exitcond43.not, label %._crit_edge, label %.lr.ph35, !llvm.loop !5

._crit_edge:                                      ; preds = %.loopexit, %4
  ret void

.lr.ph35:                                         ; preds = %.lr.ph35.preheader, %.loopexit
  %indvars.iv39 = phi i64 [ 0, %.lr.ph35.preheader ], [ %indvars.iv.next40, %.loopexit ]
  %indvars.iv = phi i64 [ 1, %.lr.ph35.preheader ], [ %indvars.iv.next, %.loopexit ]
  %7 = getelementptr inbounds ptr, ptr %3, i64 %indvars.iv39
  %8 = load ptr, ptr %7, align 8, !tbaa !7
  %9 = getelementptr inbounds double, ptr %8, i64 %indvars.iv39
  store double 0.000000e+00, ptr %9, align 8, !tbaa !11
  %indvars.iv.next40 = add nuw nsw i64 %indvars.iv39, 1
  %10 = icmp ult i64 %indvars.iv.next40, %6
  br i1 %10, label %.lr.ph, label %.loopexit

.lr.ph:                                           ; preds = %.lr.ph35
  %11 = getelementptr inbounds ptr, ptr %2, i64 %indvars.iv39
  %12 = load ptr, ptr %11, align 8, !tbaa !7
  %13 = getelementptr inbounds i8, ptr %12, i64 8
  br label %14

14:                                               ; preds = %.lr.ph, %14
  %indvars.iv36 = phi i64 [ %indvars.iv, %.lr.ph ], [ %indvars.iv.next37, %14 ]
  %15 = load double, ptr %12, align 8, !tbaa !11
  %16 = getelementptr inbounds ptr, ptr %2, i64 %indvars.iv36
  %17 = load ptr, ptr %16, align 8, !tbaa !7
  %18 = load double, ptr %17, align 8, !tbaa !11
  %19 = fsub double %15, %18
  %20 = load double, ptr %13, align 8, !tbaa !11
  %21 = getelementptr inbounds i8, ptr %17, i64 8
  %22 = load double, ptr %21, align 8, !tbaa !11
  %23 = fsub double %20, %22
  %24 = fmul double %23, %23
  %25 = tail call double @llvm.fmuladd.f64(double %19, double %19, double %24)
  %sqrt = tail call double @llvm.sqrt.f64(double %25)
  %26 = tail call double @llvm.ceil.f64(double %sqrt)
  %27 = getelementptr inbounds double, ptr %8, i64 %indvars.iv36
  store double %26, ptr %27, align 8, !tbaa !11
  %28 = getelementptr inbounds ptr, ptr %3, i64 %indvars.iv36
  %29 = load ptr, ptr %28, align 8, !tbaa !7
  %30 = getelementptr inbounds double, ptr %29, i64 %indvars.iv39
  store double %26, ptr %30, align 8, !tbaa !11
  %indvars.iv.next37 = add nuw nsw i64 %indvars.iv36, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next37, %wide.trip.count42
  br i1 %exitcond.not, label %.loopexit, label %14, !llvm.loop !13
}

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

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.ceil.f64(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 memory(readwrite, 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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}
!7 = !{!8, !8, i64 0}
!8 = !{!"any pointer", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C++ TBAA"}
!11 = !{!12, !12, i64 0}
!12 = !{!"double", !9, i64 0}
!13 = distinct !{!13, !6}


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