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

; 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.TSPIndividual = type { %class.Individual.base, i32, ptr }
%class.Individual.base = type <{ ptr, i8, [7 x i8], double, i32, [4 x i8], double, ptr, i32 }>
%class.TSPIndividual2 = type { %class.TSPIndividual, 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: mustprogress uwtable
define dso_local noundef ptr @_ZN14TSPIndividual214getCitiesRouteEv(ptr noundef nonnull align 8 dereferenceable(80) %0) unnamed_addr #1 align 2 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  %6 = load ptr, ptr %2, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  store i32 0, ptr %3, align 4, !tbaa !9
  br label %7

7:                                                ; preds = %25, %1
  %8 = load i32, ptr %3, align 4, !tbaa !9
  %9 = getelementptr inbounds %class.TSPIndividual, ptr %6, i32 0, i32 1
  %10 = load i32, ptr %9, align 4, !tbaa !11
  %11 = icmp slt i32 %8, %10
  br i1 %11, label %13, label %12

12:                                               ; preds = %7
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  br label %28

13:                                               ; preds = %7
  %14 = getelementptr inbounds %class.TSPIndividual2, ptr %6, i32 0, i32 1
  %15 = load ptr, ptr %14, align 8, !tbaa !16
  %16 = load i32, ptr %3, align 4, !tbaa !9
  %17 = sext i32 %16 to i64
  %18 = getelementptr inbounds double, ptr %15, i64 %17
  %19 = load double, ptr %18, align 8, !tbaa !18
  %20 = getelementptr inbounds %class.TSPIndividual2, ptr %6, i32 0, i32 2
  %21 = load ptr, ptr %20, align 8, !tbaa !19
  %22 = load i32, ptr %3, align 4, !tbaa !9
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds double, ptr %21, i64 %23
  store double %19, ptr %24, align 8, !tbaa !18
  br label %25

25:                                               ; preds = %13
  %26 = load i32, ptr %3, align 4, !tbaa !9
  %27 = add nsw i32 %26, 1
  store i32 %27, ptr %3, align 4, !tbaa !9
  br label %7, !llvm.loop !20

28:                                               ; preds = %12
  %29 = getelementptr inbounds %class.TSPIndividual2, ptr %6, i32 0, i32 2
  %30 = load ptr, ptr %29, align 8, !tbaa !19
  %31 = getelementptr inbounds %class.TSPIndividual, ptr %6, i32 0, i32 1
  %32 = load i32, ptr %31, align 4, !tbaa !11
  %33 = sub nsw i32 %32, 1
  call void @_ZN14TSPIndividual29quickSortEPdii(ptr noundef nonnull align 8 dereferenceable(80) %6, ptr noundef %30, i32 noundef 0, i32 noundef %33)
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  store i32 0, ptr %4, align 4, !tbaa !9
  br label %34

34:                                               ; preds = %60, %28
  %35 = load i32, ptr %4, align 4, !tbaa !9
  %36 = getelementptr inbounds %class.TSPIndividual, ptr %6, i32 0, i32 1
  %37 = load i32, ptr %36, align 4, !tbaa !11
  %38 = icmp slt i32 %35, %37
  br i1 %38, label %40, label %39

39:                                               ; preds = %34
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  br label %63

40:                                               ; preds = %34
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  %41 = getelementptr inbounds %class.TSPIndividual2, ptr %6, i32 0, i32 2
  %42 = load ptr, ptr %41, align 8, !tbaa !19
  %43 = getelementptr inbounds %class.TSPIndividual2, ptr %6, i32 0, i32 1
  %44 = load ptr, ptr %43, align 8, !tbaa !16
  %45 = load i32, ptr %4, align 4, !tbaa !9
  %46 = sext i32 %45 to i64
  %47 = getelementptr inbounds double, ptr %44, i64 %46
  %48 = load double, ptr %47, align 8, !tbaa !18
  %49 = getelementptr inbounds %class.TSPIndividual, ptr %6, i32 0, i32 1
  %50 = load i32, ptr %49, align 4, !tbaa !11
  %51 = sub nsw i32 %50, 1
  %52 = call noundef i32 @_ZN14TSPIndividual212binarySearchEPddii(ptr noundef nonnull align 8 dereferenceable(80) %6, ptr noundef %42, double noundef %48, i32 noundef 0, i32 noundef %51)
  store i32 %52, ptr %5, align 4, !tbaa !9
  %53 = load i32, ptr %5, align 4, !tbaa !9
  %54 = add nsw i32 %53, 1
  %55 = getelementptr inbounds %class.TSPIndividual, ptr %6, i32 0, i32 2
  %56 = load ptr, ptr %55, align 8, !tbaa !22
  %57 = load i32, ptr %4, align 4, !tbaa !9
  %58 = sext i32 %57 to i64
  %59 = getelementptr inbounds i32, ptr %56, i64 %58
  store i32 %54, ptr %59, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  br label %60

60:                                               ; preds = %40
  %61 = load i32, ptr %4, align 4, !tbaa !9
  %62 = add nsw i32 %61, 1
  store i32 %62, ptr %4, align 4, !tbaa !9
  br label %34, !llvm.loop !23

63:                                               ; preds = %39
  %64 = getelementptr inbounds %class.TSPIndividual, ptr %6, i32 0, i32 2
  %65 = load ptr, ptr %64, align 8, !tbaa !22
  ret ptr %65
}

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN14TSPIndividual29quickSortEPdii(ptr noundef nonnull align 8 dereferenceable(80), ptr noundef, i32 noundef, i32 noundef) #1 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZN14TSPIndividual212binarySearchEPddii(ptr noundef nonnull align 8 dereferenceable(80), ptr noundef, double noundef, i32 noundef, i32 noundef) #2 align 2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { 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 #3 = { 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, !10, i64 52}
!12 = !{!"_ZTS13TSPIndividual", !13, i64 0, !10, i64 52, !6, i64 56}
!13 = !{!"_ZTS10Individual", !14, i64 8, !15, i64 16, !10, i64 24, !15, i64 32, !6, i64 40, !10, i64 48}
!14 = !{!"bool", !7, i64 0}
!15 = !{!"double", !7, i64 0}
!16 = !{!17, !6, i64 64}
!17 = !{!"_ZTS14TSPIndividual2", !12, i64 0, !6, i64 64, !6, i64 72}
!18 = !{!15, !15, i64 0}
!19 = !{!17, !6, i64 72}
!20 = distinct !{!20, !21}
!21 = !{!"llvm.loop.mustprogress"}
!22 = !{!12, !6, i64 56}
!23 = distinct !{!23, !21}


; 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 uwtable
define dso_local noundef ptr @_ZN14TSPIndividual214getCitiesRouteEv(ptr noundef nonnull align 8 dereferenceable(80) %0) unnamed_addr #0 align 2 {
  %2 = getelementptr inbounds i8, ptr %0, i64 52
  %3 = load i32, ptr %2, align 4, !tbaa !5
  %4 = icmp sgt i32 %3, 0
  br i1 %4, label %.lr.ph, label %.._crit_edge_crit_edge

.._crit_edge_crit_edge:                           ; preds = %1
  %.phi.trans.insert = getelementptr inbounds i8, ptr %0, i64 72
  %.pre = load ptr, ptr %.phi.trans.insert, align 8, !tbaa !14
  br label %._crit_edge

.lr.ph:                                           ; preds = %1
  %5 = getelementptr inbounds i8, ptr %0, i64 64
  %6 = load ptr, ptr %5, align 8, !tbaa !16
  %7 = getelementptr inbounds i8, ptr %0, i64 72
  %8 = load ptr, ptr %7, align 8, !tbaa !14
  %wide.trip.count = zext nneg i32 %3 to i64
  %min.iters.check = icmp ult i32 %3, 6
  %9 = ptrtoint ptr %8 to i64
  %10 = ptrtoint ptr %6 to i64
  %11 = sub i64 %9, %10
  %diff.check = icmp ult i64 %11, 32
  %or.cond = select i1 %min.iters.check, i1 true, i1 %diff.check
  br i1 %or.cond, label %scalar.ph.preheader, label %vector.ph

scalar.ph.preheader:                              ; preds = %middle.block, %.lr.ph
  %indvars.iv.ph = phi i64 [ 0, %.lr.ph ], [ %n.vec, %middle.block ]
  %xtraiter = and i64 %wide.trip.count, 3
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %scalar.ph.prol.loopexit, label %scalar.ph.prol

scalar.ph.prol:                                   ; preds = %scalar.ph.preheader, %scalar.ph.prol
  %indvars.iv.prol = phi i64 [ %indvars.iv.next.prol, %scalar.ph.prol ], [ %indvars.iv.ph, %scalar.ph.preheader ]
  %prol.iter = phi i64 [ %prol.iter.next, %scalar.ph.prol ], [ 0, %scalar.ph.preheader ]
  %12 = getelementptr inbounds double, ptr %6, i64 %indvars.iv.prol
  %13 = load double, ptr %12, align 8, !tbaa !17
  %14 = getelementptr inbounds double, ptr %8, i64 %indvars.iv.prol
  store double %13, ptr %14, align 8, !tbaa !17
  %indvars.iv.next.prol = add nuw nsw i64 %indvars.iv.prol, 1
  %prol.iter.next = add i64 %prol.iter, 1
  %prol.iter.cmp.not = icmp eq i64 %prol.iter.next, %xtraiter
  br i1 %prol.iter.cmp.not, label %scalar.ph.prol.loopexit, label %scalar.ph.prol, !llvm.loop !18

scalar.ph.prol.loopexit:                          ; preds = %scalar.ph.prol, %scalar.ph.preheader
  %indvars.iv.unr = phi i64 [ %indvars.iv.ph, %scalar.ph.preheader ], [ %indvars.iv.next.prol, %scalar.ph.prol ]
  %15 = sub nsw i64 %indvars.iv.ph, %wide.trip.count
  %16 = icmp ugt i64 %15, -4
  br i1 %16, label %._crit_edge, label %scalar.ph

vector.ph:                                        ; preds = %.lr.ph
  %n.vec = and i64 %wide.trip.count, 2147483644
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %17 = getelementptr inbounds double, ptr %6, i64 %index
  %18 = getelementptr inbounds i8, ptr %17, i64 16
  %wide.load = load <2 x double>, ptr %17, align 8, !tbaa !17
  %wide.load24 = load <2 x double>, ptr %18, align 8, !tbaa !17
  %19 = getelementptr inbounds double, ptr %8, i64 %index
  %20 = getelementptr inbounds i8, ptr %19, i64 16
  store <2 x double> %wide.load, ptr %19, align 8, !tbaa !17
  store <2 x double> %wide.load24, ptr %20, align 8, !tbaa !17
  %index.next = add nuw i64 %index, 4
  %21 = icmp eq i64 %index.next, %n.vec
  br i1 %21, label %middle.block, label %vector.body, !llvm.loop !20

middle.block:                                     ; preds = %vector.body
  %cmp.n = icmp eq i64 %n.vec, %wide.trip.count
  br i1 %cmp.n, label %._crit_edge, label %scalar.ph.preheader

._crit_edge:                                      ; preds = %scalar.ph.prol.loopexit, %scalar.ph, %middle.block, %.._crit_edge_crit_edge
  %22 = phi ptr [ %.pre, %.._crit_edge_crit_edge ], [ %8, %middle.block ], [ %8, %scalar.ph ], [ %8, %scalar.ph.prol.loopexit ]
  %23 = getelementptr inbounds i8, ptr %0, i64 72
  %24 = add nsw i32 %3, -1
  tail call void @_ZN14TSPIndividual29quickSortEPdii(ptr noundef nonnull align 8 dereferenceable(80) %0, ptr noundef %22, i32 noundef 0, i32 noundef %24)
  %25 = load i32, ptr %2, align 4, !tbaa !5
  %26 = icmp sgt i32 %25, 0
  br i1 %26, label %.lr.ph16, label %._crit_edge.._crit_edge17_crit_edge

._crit_edge.._crit_edge17_crit_edge:              ; preds = %._crit_edge
  %.phi.trans.insert22 = getelementptr inbounds i8, ptr %0, i64 56
  %.pre23 = load ptr, ptr %.phi.trans.insert22, align 8, !tbaa !24
  br label %._crit_edge17

.lr.ph16:                                         ; preds = %._crit_edge
  %27 = getelementptr inbounds i8, ptr %0, i64 64
  %28 = getelementptr inbounds i8, ptr %0, i64 56
  br label %42

scalar.ph:                                        ; preds = %scalar.ph.prol.loopexit, %scalar.ph
  %indvars.iv = phi i64 [ %indvars.iv.next.3, %scalar.ph ], [ %indvars.iv.unr, %scalar.ph.prol.loopexit ]
  %29 = getelementptr inbounds double, ptr %6, i64 %indvars.iv
  %30 = load double, ptr %29, align 8, !tbaa !17
  %31 = getelementptr inbounds double, ptr %8, i64 %indvars.iv
  store double %30, ptr %31, align 8, !tbaa !17
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %32 = getelementptr inbounds double, ptr %6, i64 %indvars.iv.next
  %33 = load double, ptr %32, align 8, !tbaa !17
  %34 = getelementptr inbounds double, ptr %8, i64 %indvars.iv.next
  store double %33, ptr %34, align 8, !tbaa !17
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 2
  %35 = getelementptr inbounds double, ptr %6, i64 %indvars.iv.next.1
  %36 = load double, ptr %35, align 8, !tbaa !17
  %37 = getelementptr inbounds double, ptr %8, i64 %indvars.iv.next.1
  store double %36, ptr %37, align 8, !tbaa !17
  %indvars.iv.next.2 = add nuw nsw i64 %indvars.iv, 3
  %38 = getelementptr inbounds double, ptr %6, i64 %indvars.iv.next.2
  %39 = load double, ptr %38, align 8, !tbaa !17
  %40 = getelementptr inbounds double, ptr %8, i64 %indvars.iv.next.2
  store double %39, ptr %40, align 8, !tbaa !17
  %indvars.iv.next.3 = add nuw nsw i64 %indvars.iv, 4
  %exitcond.not.3 = icmp eq i64 %indvars.iv.next.3, %wide.trip.count
  br i1 %exitcond.not.3, label %._crit_edge, label %scalar.ph, !llvm.loop !25

._crit_edge17:                                    ; preds = %42, %._crit_edge.._crit_edge17_crit_edge
  %41 = phi ptr [ %.pre23, %._crit_edge.._crit_edge17_crit_edge ], [ %51, %42 ]
  ret ptr %41

42:                                               ; preds = %.lr.ph16, %42
  %indvars.iv19 = phi i64 [ 0, %.lr.ph16 ], [ %indvars.iv.next20, %42 ]
  %43 = phi i32 [ %25, %.lr.ph16 ], [ %53, %42 ]
  %44 = load ptr, ptr %23, align 8, !tbaa !14
  %45 = load ptr, ptr %27, align 8, !tbaa !16
  %46 = getelementptr inbounds double, ptr %45, i64 %indvars.iv19
  %47 = load double, ptr %46, align 8, !tbaa !17
  %48 = add nsw i32 %43, -1
  %49 = tail call noundef i32 @_ZN14TSPIndividual212binarySearchEPddii(ptr noundef nonnull align 8 dereferenceable(80) %0, ptr noundef %44, double noundef %47, i32 noundef 0, i32 noundef %48)
  %50 = add nsw i32 %49, 1
  %51 = load ptr, ptr %28, align 8, !tbaa !24
  %52 = getelementptr inbounds i32, ptr %51, i64 %indvars.iv19
  store i32 %50, ptr %52, align 4, !tbaa !26
  %indvars.iv.next20 = add nuw nsw i64 %indvars.iv19, 1
  %53 = load i32, ptr %2, align 4, !tbaa !5
  %54 = sext i32 %53 to i64
  %55 = icmp slt i64 %indvars.iv.next20, %54
  br i1 %55, label %42, label %._crit_edge17, !llvm.loop !27
}

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN14TSPIndividual29quickSortEPdii(ptr noundef nonnull align 8 dereferenceable(80), ptr noundef, i32 noundef, i32 noundef) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZN14TSPIndividual212binarySearchEPddii(ptr noundef nonnull align 8 dereferenceable(80), ptr noundef, double noundef, i32 noundef, i32 noundef) local_unnamed_addr #1 align 2

attributes #0 = { 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 #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" }

!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, !12, i64 52}
!6 = !{!"_ZTS13TSPIndividual", !7, i64 0, !12, i64 52, !13, i64 56}
!7 = !{!"_ZTS10Individual", !8, i64 8, !11, i64 16, !12, i64 24, !11, i64 32, !13, i64 40, !12, i64 48}
!8 = !{!"bool", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C++ TBAA"}
!11 = !{!"double", !9, i64 0}
!12 = !{!"int", !9, i64 0}
!13 = !{!"any pointer", !9, i64 0}
!14 = !{!15, !13, i64 72}
!15 = !{!"_ZTS14TSPIndividual2", !6, i64 0, !13, i64 64, !13, i64 72}
!16 = !{!15, !13, i64 64}
!17 = !{!11, !11, i64 0}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.unroll.disable"}
!20 = distinct !{!20, !21, !22, !23}
!21 = !{!"llvm.loop.mustprogress"}
!22 = !{!"llvm.loop.isvectorized", i32 1}
!23 = !{!"llvm.loop.unroll.runtime.disable"}
!24 = !{!6, !13, i64 56}
!25 = distinct !{!25, !21, !22}
!26 = !{!12, !12, i64 0}
!27 = distinct !{!27, !21}


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