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

; 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 uwtable
declare noundef zeroext i1 @_ZNKSt9basic_iosIcSt11char_traitsIcEE3eofEv(ptr noundef nonnull align 8 dereferenceable(264)) #1 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZN12AlgorithmTSP15readUpperMatrixERSt14basic_ifstreamIcSt11char_traitsIcEEiPPd(ptr noundef nonnull align 8 dereferenceable(88) %0, ptr noundef nonnull align 8 dereferenceable(256) %1, i32 noundef %2, ptr noundef %3) #1 align 2 {
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca i8, align 1
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca double, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store i32 %2, ptr %7, align 4, !tbaa !9
  store ptr %3, ptr %8, align 8, !tbaa !5
  %14 = load ptr, ptr %5, align 8
  call void @llvm.lifetime.start.p0(i64 1, ptr %9) #2
  store i8 1, ptr %9, align 1, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #2
  store i32 0, ptr %10, align 4, !tbaa !9
  br label %15

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

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

20:                                               ; preds = %15
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #2
  %21 = load i32, ptr %10, align 4, !tbaa !9
  %22 = add nsw i32 %21, 1
  store i32 %22, ptr %12, align 4, !tbaa !9
  br label %23

23:                                               ; preds = %58, %20
  %24 = load i32, ptr %12, align 4, !tbaa !9
  %25 = load i32, ptr %7, align 4, !tbaa !9
  %26 = icmp slt i32 %24, %25
  br i1 %26, label %28, label %27

27:                                               ; preds = %23
  store i32 5, ptr %11, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #2
  br label %61

28:                                               ; preds = %23
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #2
  store double 0.000000e+00, ptr %13, align 8, !tbaa !13
  %29 = load ptr, ptr %6, align 8, !tbaa !5
  %30 = load ptr, ptr %29, align 8, !tbaa !15
  %31 = getelementptr i8, ptr %30, i64 -24
  %32 = load i64, ptr %31, align 8
  %33 = getelementptr inbounds i8, ptr %29, i64 %32
  %34 = call noundef zeroext i1 @_ZNKSt9basic_iosIcSt11char_traitsIcEE3eofEv(ptr noundef nonnull align 8 dereferenceable(264) %33)
  br i1 %34, label %35, label %36

35:                                               ; preds = %28
  store i8 0, ptr %9, align 1, !tbaa !11
  br label %39

36:                                               ; preds = %28
  %37 = load ptr, ptr %6, align 8, !tbaa !5
  %38 = call noundef double @_ZN12AlgorithmTSP14readNextNumberERSt14basic_ifstreamIcSt11char_traitsIcEE(ptr noundef nonnull align 8 dereferenceable(88) %14, ptr noundef nonnull align 8 dereferenceable(256) %37)
  store double %38, ptr %13, align 8, !tbaa !13
  br label %39

39:                                               ; preds = %36, %35
  %40 = load double, ptr %13, align 8, !tbaa !13
  %41 = load ptr, ptr %8, align 8, !tbaa !5
  %42 = load i32, ptr %10, align 4, !tbaa !9
  %43 = sext i32 %42 to i64
  %44 = getelementptr inbounds ptr, ptr %41, i64 %43
  %45 = load ptr, ptr %44, align 8, !tbaa !5
  %46 = load i32, ptr %12, align 4, !tbaa !9
  %47 = sext i32 %46 to i64
  %48 = getelementptr inbounds double, ptr %45, i64 %47
  store double %40, ptr %48, align 8, !tbaa !13
  %49 = load double, ptr %13, align 8, !tbaa !13
  %50 = load ptr, ptr %8, align 8, !tbaa !5
  %51 = load i32, ptr %12, align 4, !tbaa !9
  %52 = sext i32 %51 to i64
  %53 = getelementptr inbounds ptr, ptr %50, i64 %52
  %54 = load ptr, ptr %53, align 8, !tbaa !5
  %55 = load i32, ptr %10, align 4, !tbaa !9
  %56 = sext i32 %55 to i64
  %57 = getelementptr inbounds double, ptr %54, i64 %56
  store double %49, ptr %57, align 8, !tbaa !13
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #2
  br label %58

58:                                               ; preds = %39
  %59 = load i32, ptr %12, align 4, !tbaa !9
  %60 = add nsw i32 %59, 1
  store i32 %60, ptr %12, align 4, !tbaa !9
  br label %23, !llvm.loop !17

61:                                               ; preds = %27
  br label %62

62:                                               ; preds = %61
  %63 = load i32, ptr %10, align 4, !tbaa !9
  %64 = add nsw i32 %63, 1
  store i32 %64, ptr %10, align 4, !tbaa !9
  br label %15, !llvm.loop !19

65:                                               ; preds = %19
  %66 = load i8, ptr %9, align 1, !tbaa !11, !range !20, !noundef !21
  %67 = trunc i8 %66 to i1
  store i32 1, ptr %11, align 4
  call void @llvm.lifetime.end.p0(i64 1, ptr %9) #2
  ret i1 %67
}

; Function Attrs: mustprogress uwtable
declare dso_local noundef double @_ZN12AlgorithmTSP14readNextNumberERSt14basic_ifstreamIcSt11char_traitsIcEE(ptr noundef nonnull align 8 dereferenceable(88), ptr noundef nonnull align 8 dereferenceable(256)) #1 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 = { 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 = !{!"bool", !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"double", !7, i64 0}
!15 = !{!16, !16, i64 0}
!16 = !{!"vtable pointer", !8, i64 0}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}
!19 = distinct !{!19, !18}
!20 = !{i8 0, i8 2}
!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
declare noundef zeroext i1 @_ZNKSt9basic_iosIcSt11char_traitsIcEE3eofEv(ptr noundef nonnull align 8 dereferenceable(264)) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZN12AlgorithmTSP15readUpperMatrixERSt14basic_ifstreamIcSt11char_traitsIcEEiPPd(ptr noundef nonnull align 8 dereferenceable(88) %0, ptr noundef nonnull align 8 dereferenceable(256) %1, i32 noundef %2, ptr nocapture noundef readonly %3) local_unnamed_addr #0 align 2 {
  %5 = icmp sgt i32 %2, 0
  br i1 %5, label %.lr.ph26.preheader, label %._crit_edge

.lr.ph26.preheader:                               ; preds = %4
  %6 = zext nneg i32 %2 to i64
  %wide.trip.count32 = zext nneg i32 %2 to i64
  br label %.lr.ph26

.loopexit:                                        ; preds = %17, %.lr.ph26
  %.1.lcssa = phi i1 [ %.02024, %.lr.ph26 ], [ %.2, %17 ]
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond33.not = icmp eq i64 %indvars.iv.next31, %wide.trip.count32
  br i1 %exitcond33.not, label %._crit_edge, label %.lr.ph26, !llvm.loop !5

._crit_edge:                                      ; preds = %.loopexit, %4
  %.020.lcssa = phi i1 [ true, %4 ], [ %.1.lcssa, %.loopexit ]
  ret i1 %.020.lcssa

.lr.ph26:                                         ; preds = %.lr.ph26.preheader, %.loopexit
  %indvars.iv30 = phi i64 [ 0, %.lr.ph26.preheader ], [ %indvars.iv.next31, %.loopexit ]
  %indvars.iv = phi i64 [ 1, %.lr.ph26.preheader ], [ %indvars.iv.next, %.loopexit ]
  %.02024 = phi i1 [ true, %.lr.ph26.preheader ], [ %.1.lcssa, %.loopexit ]
  %indvars.iv.next31 = add nuw nsw i64 %indvars.iv30, 1
  %7 = icmp ult i64 %indvars.iv.next31, %6
  br i1 %7, label %.lr.ph, label %.loopexit

.lr.ph:                                           ; preds = %.lr.ph26
  %8 = getelementptr inbounds ptr, ptr %3, i64 %indvars.iv30
  br label %9

9:                                                ; preds = %.lr.ph, %17
  %indvars.iv28 = phi i64 [ %indvars.iv, %.lr.ph ], [ %indvars.iv.next29, %17 ]
  %.122 = phi i1 [ %.02024, %.lr.ph ], [ %.2, %17 ]
  %10 = load ptr, ptr %1, align 8, !tbaa !7
  %11 = getelementptr i8, ptr %10, i64 -24
  %12 = load i64, ptr %11, align 8
  %13 = getelementptr inbounds i8, ptr %1, i64 %12
  %14 = tail call noundef zeroext i1 @_ZNKSt9basic_iosIcSt11char_traitsIcEE3eofEv(ptr noundef nonnull align 8 dereferenceable(264) %13)
  br i1 %14, label %17, label %15

15:                                               ; preds = %9
  %16 = tail call noundef double @_ZN12AlgorithmTSP14readNextNumberERSt14basic_ifstreamIcSt11char_traitsIcEE(ptr noundef nonnull align 8 dereferenceable(88) %0, ptr noundef nonnull align 8 dereferenceable(256) %1)
  br label %17

17:                                               ; preds = %9, %15
  %.2 = phi i1 [ %.122, %15 ], [ false, %9 ]
  %.0 = phi double [ %16, %15 ], [ 0.000000e+00, %9 ]
  %18 = load ptr, ptr %8, align 8, !tbaa !10
  %19 = getelementptr inbounds double, ptr %18, i64 %indvars.iv28
  store double %.0, ptr %19, align 8, !tbaa !13
  %20 = getelementptr inbounds ptr, ptr %3, i64 %indvars.iv28
  %21 = load ptr, ptr %20, align 8, !tbaa !10
  %22 = getelementptr inbounds double, ptr %21, i64 %indvars.iv30
  store double %.0, ptr %22, align 8, !tbaa !13
  %indvars.iv.next29 = add nuw nsw i64 %indvars.iv28, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next29, %wide.trip.count32
  br i1 %exitcond.not, label %.loopexit, label %9, !llvm.loop !15
}

; Function Attrs: mustprogress uwtable
declare dso_local noundef double @_ZN12AlgorithmTSP14readNextNumberERSt14basic_ifstreamIcSt11char_traitsIcEE(ptr noundef nonnull align 8 dereferenceable(88), ptr noundef nonnull align 8 dereferenceable(256)) local_unnamed_addr #0 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" }

!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 = !{!"vtable pointer", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!11, !11, i64 0}
!11 = !{!"any pointer", !12, i64 0}
!12 = !{!"omnipotent char", !9, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"double", !12, i64 0}
!15 = distinct !{!15, !6}


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