; LLVM IR from Rintarooo/VRPTW_ACO_Routing :: src/graph.ll (ZN5Graph18calc_node_distanceEv)

; 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.Graph = type { ptr, i32, i32, ptr, ptr, ptr }
%class.Node = type { i32, i32, i32, i32, i8, i32, i32, i32 }

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN5Graph18calc_node_distanceEv(ptr noundef nonnull align 8 dereferenceable(40) %0) #0 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 = %81, %1
  %8 = load i32, ptr %3, align 4, !tbaa !9
  %9 = getelementptr inbounds %class.Graph, ptr %6, i32 0, i32 2
  %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
  store i32 2, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  br label %84

13:                                               ; preds = %7
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  %14 = load i32, ptr %3, align 4, !tbaa !9
  %15 = add nsw i32 %14, 1
  store i32 %15, ptr %5, align 4, !tbaa !9
  br label %16

16:                                               ; preds = %77, %13
  %17 = load i32, ptr %5, align 4, !tbaa !9
  %18 = getelementptr inbounds %class.Graph, ptr %6, i32 0, i32 2
  %19 = load i32, ptr %18, align 4, !tbaa !11
  %20 = icmp slt i32 %17, %19
  br i1 %20, label %22, label %21

21:                                               ; preds = %16
  store i32 5, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  br label %80

22:                                               ; preds = %16
  %23 = getelementptr inbounds %class.Graph, ptr %6, i32 0, i32 4
  %24 = load ptr, ptr %23, align 8, !tbaa !13
  %25 = load i32, ptr %3, align 4, !tbaa !9
  %26 = sext i32 %25 to i64
  %27 = getelementptr inbounds %class.Node, ptr %24, i64 %26
  %28 = getelementptr inbounds %class.Node, ptr %27, i32 0, i32 0
  %29 = load i32, ptr %28, align 4, !tbaa !14
  %30 = getelementptr inbounds %class.Graph, ptr %6, i32 0, i32 4
  %31 = load ptr, ptr %30, align 8, !tbaa !13
  %32 = load i32, ptr %5, align 4, !tbaa !9
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds %class.Node, ptr %31, i64 %33
  %35 = getelementptr inbounds %class.Node, ptr %34, i32 0, i32 0
  %36 = load i32, ptr %35, align 4, !tbaa !14
  %37 = sub nsw i32 %29, %36
  %38 = sitofp i32 %37 to double
  %39 = call double @pow(double noundef %38, double noundef 2.000000e+00) #3
  %40 = getelementptr inbounds %class.Graph, ptr %6, i32 0, i32 4
  %41 = load ptr, ptr %40, align 8, !tbaa !13
  %42 = load i32, ptr %3, align 4, !tbaa !9
  %43 = sext i32 %42 to i64
  %44 = getelementptr inbounds %class.Node, ptr %41, i64 %43
  %45 = getelementptr inbounds %class.Node, ptr %44, i32 0, i32 1
  %46 = load i32, ptr %45, align 4, !tbaa !17
  %47 = getelementptr inbounds %class.Graph, ptr %6, i32 0, i32 4
  %48 = load ptr, ptr %47, align 8, !tbaa !13
  %49 = load i32, ptr %5, align 4, !tbaa !9
  %50 = sext i32 %49 to i64
  %51 = getelementptr inbounds %class.Node, ptr %48, i64 %50
  %52 = getelementptr inbounds %class.Node, ptr %51, i32 0, i32 1
  %53 = load i32, ptr %52, align 4, !tbaa !17
  %54 = sub nsw i32 %46, %53
  %55 = sitofp i32 %54 to double
  %56 = call double @pow(double noundef %55, double noundef 2.000000e+00) #3
  %57 = fadd double %39, %56
  %58 = call double @sqrt(double noundef %57) #3
  %59 = getelementptr inbounds %class.Graph, ptr %6, i32 0, i32 5
  %60 = load ptr, ptr %59, align 8, !tbaa !18
  %61 = load i32, ptr %5, align 4, !tbaa !9
  %62 = sext i32 %61 to i64
  %63 = getelementptr inbounds ptr, ptr %60, i64 %62
  %64 = load ptr, ptr %63, align 8, !tbaa !5
  %65 = load i32, ptr %3, align 4, !tbaa !9
  %66 = sext i32 %65 to i64
  %67 = getelementptr inbounds double, ptr %64, i64 %66
  store double %58, ptr %67, align 8, !tbaa !19
  %68 = getelementptr inbounds %class.Graph, ptr %6, i32 0, i32 5
  %69 = load ptr, ptr %68, align 8, !tbaa !18
  %70 = load i32, ptr %3, align 4, !tbaa !9
  %71 = sext i32 %70 to i64
  %72 = getelementptr inbounds ptr, ptr %69, i64 %71
  %73 = load ptr, ptr %72, align 8, !tbaa !5
  %74 = load i32, ptr %5, align 4, !tbaa !9
  %75 = sext i32 %74 to i64
  %76 = getelementptr inbounds double, ptr %73, i64 %75
  store double %58, ptr %76, align 8, !tbaa !19
  br label %77

77:                                               ; preds = %22
  %78 = load i32, ptr %5, align 4, !tbaa !9
  %79 = add nsw i32 %78, 1
  store i32 %79, ptr %5, align 4, !tbaa !9
  br label %16, !llvm.loop !21

80:                                               ; preds = %21
  br label %81

81:                                               ; preds = %80
  %82 = load i32, ptr %3, align 4, !tbaa !9
  %83 = add nsw i32 %82, 1
  store i32 %83, ptr %3, align 4, !tbaa !9
  br label %7, !llvm.loop !23

84:                                               ; preds = %12
  ret void
}

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

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

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

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

attributes #0 = { 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 12}
!12 = !{!"_ZTS5Graph", !10, i64 8, !10, i64 12, !6, i64 16, !6, i64 24, !6, i64 32}
!13 = !{!12, !6, i64 24}
!14 = !{!15, !10, i64 0}
!15 = !{!"_ZTS4Node", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12, !16, i64 16, !10, i64 20, !10, i64 24, !10, i64 28}
!16 = !{!"bool", !7, i64 0}
!17 = !{!15, !10, i64 4}
!18 = !{!12, !6, i64 32}
!19 = !{!20, !20, i64 0}
!20 = !{!"double", !7, i64 0}
!21 = distinct !{!21, !22}
!22 = !{!"llvm.loop.mustprogress"}
!23 = distinct !{!23, !22}


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

%class.Node = type { i32, i32, i32, i32, i8, i32, i32, i32 }

; Function Attrs: mustprogress nofree norecurse nosync nounwind memory(readwrite, inaccessiblemem: none) uwtable
define dso_local void @_ZN5Graph18calc_node_distanceEv(ptr nocapture noundef nonnull readonly align 8 dereferenceable(40) %0) local_unnamed_addr #0 align 2 {
  %2 = getelementptr inbounds i8, ptr %0, i64 12
  %3 = load i32, ptr %2, align 4, !tbaa !5
  %4 = icmp sgt i32 %3, 0
  br i1 %4, label %.lr.ph17, label %._crit_edge

.lr.ph17:                                         ; preds = %1
  %5 = getelementptr inbounds i8, ptr %0, i64 24
  %6 = load ptr, ptr %5, align 8
  %7 = getelementptr inbounds i8, ptr %0, i64 32
  %8 = load ptr, ptr %7, align 8
  %9 = zext nneg i32 %3 to i64
  %wide.trip.count24 = zext nneg i32 %3 to i64
  br label %10

.loopexit:                                        ; preds = %18, %10
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond25.not = icmp eq i64 %indvars.iv.next22, %wide.trip.count24
  br i1 %exitcond25.not, label %._crit_edge, label %10, !llvm.loop !11

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

10:                                               ; preds = %.lr.ph17, %.loopexit
  %indvars.iv21 = phi i64 [ 0, %.lr.ph17 ], [ %indvars.iv.next22, %.loopexit ]
  %indvars.iv = phi i64 [ 1, %.lr.ph17 ], [ %indvars.iv.next, %.loopexit ]
  %indvars.iv.next22 = add nuw nsw i64 %indvars.iv21, 1
  %11 = icmp ult i64 %indvars.iv.next22, %9
  br i1 %11, label %.lr.ph, label %.loopexit

.lr.ph:                                           ; preds = %10
  %12 = getelementptr inbounds %class.Node, ptr %6, i64 %indvars.iv21
  %13 = load i32, ptr %12, align 4, !tbaa !13
  %14 = getelementptr inbounds %class.Node, ptr %6, i64 %indvars.iv21, i32 1
  %15 = load i32, ptr %14, align 4, !tbaa !16
  %16 = getelementptr inbounds ptr, ptr %8, i64 %indvars.iv21
  %17 = load ptr, ptr %16, align 8, !tbaa !17
  br label %18

18:                                               ; preds = %.lr.ph, %18
  %indvars.iv18 = phi i64 [ %indvars.iv, %.lr.ph ], [ %indvars.iv.next19, %18 ]
  %19 = getelementptr inbounds %class.Node, ptr %6, i64 %indvars.iv18
  %20 = load i32, ptr %19, align 4, !tbaa !13
  %21 = sub nsw i32 %13, %20
  %22 = sitofp i32 %21 to double
  %square = fmul double %22, %22
  %23 = getelementptr inbounds %class.Node, ptr %6, i64 %indvars.iv18, i32 1
  %24 = load i32, ptr %23, align 4, !tbaa !16
  %25 = sub nsw i32 %15, %24
  %26 = sitofp i32 %25 to double
  %square14 = fmul double %26, %26
  %27 = fadd double %square, %square14
  %sqrt = tail call double @llvm.sqrt.f64(double %27)
  %28 = getelementptr inbounds ptr, ptr %8, i64 %indvars.iv18
  %29 = load ptr, ptr %28, align 8, !tbaa !17
  %30 = getelementptr inbounds double, ptr %29, i64 %indvars.iv21
  store double %sqrt, ptr %30, align 8, !tbaa !18
  %31 = getelementptr inbounds double, ptr %17, i64 %indvars.iv18
  store double %sqrt, ptr %31, align 8, !tbaa !18
  %indvars.iv.next19 = add nuw nsw i64 %indvars.iv18, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next19, %wide.trip.count24
  br i1 %exitcond.not, label %.loopexit, label %18, !llvm.loop !20
}

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

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 = { 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, !7, i64 12}
!6 = !{!"_ZTS5Graph", !7, i64 8, !7, i64 12, !10, i64 16, !10, i64 24, !10, i64 32}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = !{!14, !7, i64 0}
!14 = !{!"_ZTS4Node", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12, !15, i64 16, !7, i64 20, !7, i64 24, !7, i64 28}
!15 = !{!"bool", !8, i64 0}
!16 = !{!14, !7, i64 4}
!17 = !{!10, !10, i64 0}
!18 = !{!19, !19, i64 0}
!19 = !{!"double", !8, i64 0}
!20 = distinct !{!20, !12}


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