; LLVM IR from Dev-XYS/Algorithms :: Bellman-Ford.ll (Z7AddEdgeii)

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

%struct.vertex = type { i32, i32, i32, double }
%struct.edge = type { i32, i32, double }

@V = external dso_local global [10000 x %struct.vertex], align 16
@E = external dso_local global [10000 x %struct.edge], align 16
@ec = external dso_local global i32, align 4

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z7AddEdgeii(i32 noundef %0, i32 noundef %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  store i32 %0, ptr %3, align 4, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !5
  %5 = load i32, ptr %3, align 4, !tbaa !5
  %6 = sext i32 %5 to i64
  %7 = getelementptr inbounds [10000 x %struct.vertex], ptr @V, i64 0, i64 %6
  %8 = getelementptr inbounds %struct.vertex, ptr %7, i32 0, i32 0
  %9 = load i32, ptr %8, align 8, !tbaa !9
  %10 = load i32, ptr @ec, align 4, !tbaa !5
  %11 = sext i32 %10 to i64
  %12 = getelementptr inbounds [10000 x %struct.edge], ptr @E, i64 0, i64 %11
  %13 = getelementptr inbounds %struct.edge, ptr %12, i32 0, i32 1
  store i32 %9, ptr %13, align 4, !tbaa !12
  %14 = load i32, ptr @ec, align 4, !tbaa !5
  %15 = load i32, ptr %3, align 4, !tbaa !5
  %16 = sext i32 %15 to i64
  %17 = getelementptr inbounds [10000 x %struct.vertex], ptr @V, i64 0, i64 %16
  %18 = getelementptr inbounds %struct.vertex, ptr %17, i32 0, i32 0
  store i32 %14, ptr %18, align 8, !tbaa !9
  %19 = load i32, ptr %4, align 4, !tbaa !5
  %20 = load i32, ptr @ec, align 4, !tbaa !5
  %21 = sext i32 %20 to i64
  %22 = getelementptr inbounds [10000 x %struct.edge], ptr @E, i64 0, i64 %21
  %23 = getelementptr inbounds %struct.edge, ptr %22, i32 0, i32 0
  store i32 %19, ptr %23, align 16, !tbaa !14
  %24 = load i32, ptr %3, align 4, !tbaa !5
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds [10000 x %struct.vertex], ptr @V, i64 0, i64 %25
  %27 = getelementptr inbounds %struct.vertex, ptr %26, i32 0, i32 1
  %28 = load i32, ptr %27, align 4, !tbaa !15
  %29 = load i32, ptr %4, align 4, !tbaa !5
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds [10000 x %struct.vertex], ptr @V, i64 0, i64 %30
  %32 = getelementptr inbounds %struct.vertex, ptr %31, i32 0, i32 1
  %33 = load i32, ptr %32, align 4, !tbaa !15
  %34 = sub nsw i32 %28, %33
  %35 = load i32, ptr %3, align 4, !tbaa !5
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds [10000 x %struct.vertex], ptr @V, i64 0, i64 %36
  %38 = getelementptr inbounds %struct.vertex, ptr %37, i32 0, i32 1
  %39 = load i32, ptr %38, align 4, !tbaa !15
  %40 = load i32, ptr %4, align 4, !tbaa !5
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds [10000 x %struct.vertex], ptr @V, i64 0, i64 %41
  %43 = getelementptr inbounds %struct.vertex, ptr %42, i32 0, i32 1
  %44 = load i32, ptr %43, align 4, !tbaa !15
  %45 = sub nsw i32 %39, %44
  %46 = mul nsw i32 %34, %45
  %47 = load i32, ptr %3, align 4, !tbaa !5
  %48 = sext i32 %47 to i64
  %49 = getelementptr inbounds [10000 x %struct.vertex], ptr @V, i64 0, i64 %48
  %50 = getelementptr inbounds %struct.vertex, ptr %49, i32 0, i32 2
  %51 = load i32, ptr %50, align 8, !tbaa !16
  %52 = load i32, ptr %4, align 4, !tbaa !5
  %53 = sext i32 %52 to i64
  %54 = getelementptr inbounds [10000 x %struct.vertex], ptr @V, i64 0, i64 %53
  %55 = getelementptr inbounds %struct.vertex, ptr %54, i32 0, i32 2
  %56 = load i32, ptr %55, align 8, !tbaa !16
  %57 = sub nsw i32 %51, %56
  %58 = load i32, ptr %3, align 4, !tbaa !5
  %59 = sext i32 %58 to i64
  %60 = getelementptr inbounds [10000 x %struct.vertex], ptr @V, i64 0, i64 %59
  %61 = getelementptr inbounds %struct.vertex, ptr %60, i32 0, i32 2
  %62 = load i32, ptr %61, align 8, !tbaa !16
  %63 = load i32, ptr %4, align 4, !tbaa !5
  %64 = sext i32 %63 to i64
  %65 = getelementptr inbounds [10000 x %struct.vertex], ptr @V, i64 0, i64 %64
  %66 = getelementptr inbounds %struct.vertex, ptr %65, i32 0, i32 2
  %67 = load i32, ptr %66, align 8, !tbaa !16
  %68 = sub nsw i32 %62, %67
  %69 = mul nsw i32 %57, %68
  %70 = add nsw i32 %46, %69
  %71 = sitofp i32 %70 to double
  %72 = call double @sqrt(double noundef %71) #2
  %73 = load i32, ptr @ec, align 4, !tbaa !5
  %74 = sext i32 %73 to i64
  %75 = getelementptr inbounds [10000 x %struct.edge], ptr @E, i64 0, i64 %74
  %76 = getelementptr inbounds %struct.edge, ptr %75, i32 0, i32 2
  store double %72, ptr %76, align 8, !tbaa !17
  %77 = load i32, ptr @ec, align 4, !tbaa !5
  %78 = add nsw i32 %77, 1
  store i32 %78, ptr @ec, align 4, !tbaa !5
  ret void
}

; Function Attrs: nounwind
declare double @sqrt(double noundef) #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 = { 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 #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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !6, i64 0}
!10 = !{!"_ZTS6vertex", !6, i64 0, !6, i64 4, !6, i64 8, !11, i64 16}
!11 = !{!"double", !7, i64 0}
!12 = !{!13, !6, i64 4}
!13 = !{!"_ZTS4edge", !6, i64 0, !6, i64 4, !11, i64 8}
!14 = !{!13, !6, i64 0}
!15 = !{!10, !6, i64 4}
!16 = !{!10, !6, i64 8}
!17 = !{!13, !11, i64 8}


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

%struct.vertex = type { i32, i32, i32, double }
%struct.edge = type { i32, i32, double }

@V = external dso_local local_unnamed_addr global [10000 x %struct.vertex], align 16
@E = external dso_local local_unnamed_addr global [10000 x %struct.edge], align 16
@ec = external dso_local local_unnamed_addr global i32, align 4

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(readwrite, argmem: none, inaccessiblemem: none) uwtable
define dso_local void @_Z7AddEdgeii(i32 noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = sext i32 %0 to i64
  %4 = getelementptr inbounds [10000 x %struct.vertex], ptr @V, i64 0, i64 %3
  %5 = load i32, ptr %4, align 8, !tbaa !5
  %6 = load i32, ptr @ec, align 4, !tbaa !11
  %7 = sext i32 %6 to i64
  %8 = getelementptr inbounds [10000 x %struct.edge], ptr @E, i64 0, i64 %7, i32 1
  store i32 %5, ptr %8, align 4, !tbaa !12
  store i32 %6, ptr %4, align 8, !tbaa !5
  %9 = getelementptr inbounds [10000 x %struct.edge], ptr @E, i64 0, i64 %7
  store i32 %1, ptr %9, align 16, !tbaa !14
  %10 = getelementptr inbounds i8, ptr %4, i64 4
  %11 = load i32, ptr %10, align 4, !tbaa !15
  %12 = sext i32 %1 to i64
  %13 = getelementptr inbounds [10000 x %struct.vertex], ptr @V, i64 0, i64 %12
  %14 = getelementptr inbounds i8, ptr %13, i64 4
  %15 = load i32, ptr %14, align 4, !tbaa !15
  %16 = sub nsw i32 %11, %15
  %17 = mul nsw i32 %16, %16
  %18 = getelementptr inbounds i8, ptr %4, i64 8
  %19 = load i32, ptr %18, align 8, !tbaa !16
  %20 = getelementptr inbounds i8, ptr %13, i64 8
  %21 = load i32, ptr %20, align 8, !tbaa !16
  %22 = sub nsw i32 %19, %21
  %23 = mul nsw i32 %22, %22
  %24 = add nuw nsw i32 %23, %17
  %25 = uitofp nneg i32 %24 to double
  %sqrt = tail call double @llvm.sqrt.f64(double %25)
  %26 = getelementptr inbounds [10000 x %struct.edge], ptr @E, i64 0, i64 %7, i32 2
  store double %sqrt, ptr %26, align 8, !tbaa !17
  %27 = add nsw i32 %6, 1
  store i32 %27, ptr @ec, align 4, !tbaa !11
  ret void
}

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

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(readwrite, argmem: none, 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 0}
!6 = !{!"_ZTS6vertex", !7, i64 0, !7, i64 4, !7, i64 8, !10, i64 16}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"double", !8, i64 0}
!11 = !{!7, !7, i64 0}
!12 = !{!13, !7, i64 4}
!13 = !{!"_ZTS4edge", !7, i64 0, !7, i64 4, !10, i64 8}
!14 = !{!13, !7, i64 0}
!15 = !{!6, !7, i64 4}
!16 = !{!6, !7, i64 8}
!17 = !{!13, !10, i64 8}


; Effective O3 passes: AggressiveInstCombinePass,EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,TailCallElimPass