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

; 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
@ivc = external dso_local global i32, align 4

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z19InitialSingleSourcev() #0

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

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z5Relaxiid(i32 noundef, i32 noundef, double noundef) #0

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z12Bellman_Fordv() #0 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  call void @_Z19InitialSingleSourcev()
  call void @llvm.lifetime.start.p0(i64 4, ptr %1) #2
  store i32 0, ptr %1, align 4, !tbaa !5
  br label %5

5:                                                ; preds = %50, %0
  %6 = load i32, ptr %1, align 4, !tbaa !5
  %7 = load i32, ptr @ivc, align 4, !tbaa !5
  %8 = sub nsw i32 %7, 1
  %9 = icmp slt i32 %6, %8
  br i1 %9, label %11, label %10

10:                                               ; preds = %5
  store i32 2, ptr %2, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %1) #2
  br label %53

11:                                               ; preds = %5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #2
  store i32 1, ptr %3, align 4, !tbaa !5
  br label %12

12:                                               ; preds = %46, %11
  %13 = load i32, ptr %3, align 4, !tbaa !5
  %14 = load i32, ptr @ivc, align 4, !tbaa !5
  %15 = icmp sle i32 %13, %14
  br i1 %15, label %17, label %16

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

17:                                               ; preds = %12
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #2
  %18 = load i32, ptr %3, align 4, !tbaa !5
  %19 = sext i32 %18 to i64
  %20 = getelementptr inbounds [10000 x %struct.vertex], ptr @V, i64 0, i64 %19
  %21 = getelementptr inbounds %struct.vertex, ptr %20, i32 0, i32 0
  %22 = load i32, ptr %21, align 8, !tbaa !9
  store i32 %22, ptr %4, align 4, !tbaa !5
  br label %23

23:                                               ; preds = %39, %17
  %24 = load i32, ptr %4, align 4, !tbaa !5
  %25 = icmp ne i32 %24, 0
  br i1 %25, label %27, label %26

26:                                               ; preds = %23
  store i32 8, ptr %2, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #2
  br label %45

27:                                               ; preds = %23
  %28 = load i32, ptr %3, align 4, !tbaa !5
  %29 = load i32, ptr %4, align 4, !tbaa !5
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds [10000 x %struct.edge], ptr @E, i64 0, i64 %30
  %32 = getelementptr inbounds %struct.edge, ptr %31, i32 0, i32 0
  %33 = load i32, ptr %32, align 16, !tbaa !12
  %34 = load i32, ptr %4, align 4, !tbaa !5
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds [10000 x %struct.edge], ptr @E, i64 0, i64 %35
  %37 = getelementptr inbounds %struct.edge, ptr %36, i32 0, i32 2
  %38 = load double, ptr %37, align 8, !tbaa !14
  call void @_Z5Relaxiid(i32 noundef %28, i32 noundef %33, double noundef %38)
  br label %39

39:                                               ; preds = %27
  %40 = load i32, ptr %4, align 4, !tbaa !5
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds [10000 x %struct.edge], ptr @E, i64 0, i64 %41
  %43 = getelementptr inbounds %struct.edge, ptr %42, i32 0, i32 1
  %44 = load i32, ptr %43, align 4, !tbaa !15
  store i32 %44, ptr %4, align 4, !tbaa !5
  br label %23, !llvm.loop !16

45:                                               ; preds = %26
  br label %46

46:                                               ; preds = %45
  %47 = load i32, ptr %3, align 4, !tbaa !5
  %48 = add nsw i32 %47, 1
  store i32 %48, ptr %3, align 4, !tbaa !5
  br label %12, !llvm.loop !18

49:                                               ; preds = %16
  br label %50

50:                                               ; preds = %49
  %51 = load i32, ptr %1, align 4, !tbaa !5
  %52 = add nsw i32 %51, 1
  store i32 %52, ptr %1, align 4, !tbaa !5
  br label %5, !llvm.loop !19

53:                                               ; preds = %10
  ret void
}

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 }

!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 0}
!13 = !{!"_ZTS4edge", !6, i64 0, !6, i64 4, !11, i64 8}
!14 = !{!13, !11, i64 8}
!15 = !{!13, !6, i64 4}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}
!18 = distinct !{!18, !17}
!19 = distinct !{!19, !17}


; 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
@ivc = external dso_local local_unnamed_addr global i32, align 4

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z19InitialSingleSourcev() local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z5Relaxiid(i32 noundef, i32 noundef, double noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z12Bellman_Fordv() local_unnamed_addr #0 {
  tail call void @_Z19InitialSingleSourcev()
  %1 = load i32, ptr @ivc, align 4, !tbaa !5
  %2 = icmp sgt i32 %1, 1
  br i1 %2, label %.preheader, label %._crit_edge21

.preheader:                                       ; preds = %0, %._crit_edge19
  %3 = phi i32 [ %4, %._crit_edge19 ], [ %1, %0 ]
  %.01120 = phi i32 [ %5, %._crit_edge19 ], [ 0, %0 ]
  %.not16 = icmp slt i32 %3, 1
  br i1 %.not16, label %._crit_edge19, label %.lr.ph18

._crit_edge21:                                    ; preds = %._crit_edge19, %0
  ret void

._crit_edge19:                                    ; preds = %._crit_edge, %.preheader
  %4 = phi i32 [ %3, %.preheader ], [ %12, %._crit_edge ]
  %5 = add nuw nsw i32 %.01120, 1
  %6 = add nsw i32 %4, -1
  %7 = icmp slt i32 %5, %6
  br i1 %7, label %.preheader, label %._crit_edge21, !llvm.loop !9

.lr.ph18:                                         ; preds = %.preheader, %._crit_edge
  %8 = phi i32 [ %12, %._crit_edge ], [ %3, %.preheader ]
  %9 = phi i32 [ %13, %._crit_edge ], [ %3, %.preheader ]
  %indvars.iv = phi i64 [ %indvars.iv.next, %._crit_edge ], [ 1, %.preheader ]
  %10 = getelementptr inbounds [10000 x %struct.vertex], ptr @V, i64 0, i64 %indvars.iv
  %.013 = load i32, ptr %10, align 8, !tbaa !5
  %.not1214 = icmp eq i32 %.013, 0
  br i1 %.not1214, label %._crit_edge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %.lr.ph18
  %11 = trunc nuw nsw i64 %indvars.iv to i32
  br label %.lr.ph

._crit_edge.loopexit:                             ; preds = %.lr.ph
  %.pre = load i32, ptr @ivc, align 4, !tbaa !5
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %.lr.ph18
  %12 = phi i32 [ %.pre, %._crit_edge.loopexit ], [ %8, %.lr.ph18 ]
  %13 = phi i32 [ %.pre, %._crit_edge.loopexit ], [ %9, %.lr.ph18 ]
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %14 = sext i32 %13 to i64
  %.not.not = icmp slt i64 %indvars.iv, %14
  br i1 %.not.not, label %.lr.ph18, label %._crit_edge19, !llvm.loop !12

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %.015 = phi i32 [ %.0, %.lr.ph ], [ %.013, %.lr.ph.preheader ]
  %15 = sext i32 %.015 to i64
  %16 = getelementptr inbounds [10000 x %struct.edge], ptr @E, i64 0, i64 %15
  %17 = load i32, ptr %16, align 16, !tbaa !13
  %18 = getelementptr inbounds i8, ptr %16, i64 8
  %19 = load double, ptr %18, align 8, !tbaa !16
  tail call void @_Z5Relaxiid(i32 noundef %11, i32 noundef %17, double noundef %19)
  %20 = getelementptr inbounds i8, ptr %16, i64 4
  %.0 = load i32, ptr %20, align 4, !tbaa !5
  %.not12 = icmp eq i32 %.0, 0
  br i1 %.not12, label %._crit_edge.loopexit, label %.lr.ph, !llvm.loop !17
}

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

!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 = distinct !{!9, !10, !11}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!"llvm.loop.unswitch.partial.disable"}
!12 = distinct !{!12, !10}
!13 = !{!14, !6, i64 0}
!14 = !{!"_ZTS4edge", !6, i64 0, !6, i64 4, !15, i64 8}
!15 = !{!"double", !7, i64 0}
!16 = !{!14, !15, i64 8}
!17 = distinct !{!17, !10}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,SCCPPass,SROAPass,SimpleLoopUnswitchPass,SimplifyCFGPass,TailCallElimPass