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

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

@V = external dso_local global [10000 x %struct.vertex], align 16
@ivc = external dso_local global i32, align 4
@s = external dso_local global i32, align 4

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z19InitialSingleSourcev() #0 {
  %1 = alloca i32, align 4
  %2 = load i32, ptr @s, align 4, !tbaa !5
  %3 = sext i32 %2 to i64
  %4 = getelementptr inbounds [10000 x %struct.vertex], ptr @V, i64 0, i64 %3
  %5 = getelementptr inbounds %struct.vertex, ptr %4, i32 0, i32 3
  store double 0.000000e+00, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %1) #2
  store i32 1, ptr %1, align 4, !tbaa !5
  br label %6

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

10:                                               ; preds = %6
  call void @llvm.lifetime.end.p0(i64 4, ptr %1) #2
  br label %24

11:                                               ; preds = %6
  %12 = load i32, ptr %1, align 4, !tbaa !5
  %13 = load i32, ptr @s, align 4, !tbaa !5
  %14 = icmp ne i32 %12, %13
  br i1 %14, label %15, label %20

15:                                               ; preds = %11
  %16 = load i32, ptr %1, align 4, !tbaa !5
  %17 = sext i32 %16 to i64
  %18 = getelementptr inbounds [10000 x %struct.vertex], ptr @V, i64 0, i64 %17
  %19 = getelementptr inbounds %struct.vertex, ptr %18, i32 0, i32 3
  store double 1.000000e+09, ptr %19, align 8, !tbaa !9
  br label %20

20:                                               ; preds = %15, %11
  br label %21

21:                                               ; preds = %20
  %22 = load i32, ptr %1, align 4, !tbaa !5
  %23 = add nsw i32 %22, 1
  store i32 %23, ptr %1, align 4, !tbaa !5
  br label %6, !llvm.loop !12

24:                                               ; preds = %10
  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: 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 }

!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, !11, i64 16}
!10 = !{!"_ZTS6vertex", !6, i64 0, !6, i64 4, !6, i64 8, !11, i64 16}
!11 = !{!"double", !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}


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

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

; Function Attrs: mustprogress nofree norecurse nosync nounwind memory(readwrite, argmem: none, inaccessiblemem: none) uwtable
define dso_local void @_Z19InitialSingleSourcev() local_unnamed_addr #0 {
  %1 = load i32, ptr @s, align 4, !tbaa !5
  %2 = sext i32 %1 to i64
  %3 = getelementptr inbounds [10000 x %struct.vertex], ptr @V, i64 0, i64 %2, i32 3
  store double 0.000000e+00, ptr %3, align 8, !tbaa !9
  %4 = load i32, ptr @ivc, align 4, !tbaa !5
  %.not5 = icmp slt i32 %4, 1
  br i1 %.not5, label %._crit_edge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %0
  %5 = zext i32 %1 to i64
  %6 = zext nneg i32 %4 to i64
  %xtraiter = and i64 %6, 1
  %7 = icmp eq i32 %4, 1
  br i1 %7, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph.preheader.new

.lr.ph.preheader.new:                             ; preds = %.lr.ph.preheader
  %unroll_iter = and i64 %6, 2147483646
  br label %.lr.ph

._crit_edge.loopexit.unr-lcssa:                   ; preds = %14, %.lr.ph.preheader
  %indvars.iv.unr = phi i64 [ 1, %.lr.ph.preheader ], [ %indvars.iv.next.1, %14 ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  %.not4.epil = icmp eq i64 %indvars.iv.unr, %5
  %or.cond = select i1 %lcmp.mod.not, i1 true, i1 %.not4.epil
  br i1 %or.cond, label %._crit_edge, label %8

8:                                                ; preds = %._crit_edge.loopexit.unr-lcssa
  %9 = getelementptr inbounds [10000 x %struct.vertex], ptr @V, i64 0, i64 %indvars.iv.unr, i32 3
  store double 1.000000e+09, ptr %9, align 8, !tbaa !9
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit.unr-lcssa, %8, %0
  ret void

.lr.ph:                                           ; preds = %14, %.lr.ph.preheader.new
  %indvars.iv = phi i64 [ 1, %.lr.ph.preheader.new ], [ %indvars.iv.next.1, %14 ]
  %niter = phi i64 [ 0, %.lr.ph.preheader.new ], [ %niter.next.1, %14 ]
  %.not4 = icmp eq i64 %indvars.iv, %5
  br i1 %.not4, label %.lr.ph.1, label %10

10:                                               ; preds = %.lr.ph
  %11 = getelementptr inbounds [10000 x %struct.vertex], ptr @V, i64 0, i64 %indvars.iv, i32 3
  store double 1.000000e+09, ptr %11, align 8, !tbaa !9
  br label %.lr.ph.1

.lr.ph.1:                                         ; preds = %.lr.ph, %10
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %.not4.1 = icmp eq i64 %indvars.iv.next, %5
  br i1 %.not4.1, label %14, label %12

12:                                               ; preds = %.lr.ph.1
  %13 = getelementptr inbounds [10000 x %struct.vertex], ptr @V, i64 0, i64 %indvars.iv.next, i32 3
  store double 1.000000e+09, ptr %13, align 8, !tbaa !9
  br label %14

14:                                               ; preds = %12, %.lr.ph.1
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 2
  %niter.next.1 = add i64 %niter, 2
  %niter.ncmp.1 = icmp eq i64 %niter.next.1, %unroll_iter
  br i1 %niter.ncmp.1, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph, !llvm.loop !12
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind 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" }

!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, !11, i64 16}
!10 = !{!"_ZTS6vertex", !6, i64 0, !6, i64 4, !6, i64 8, !11, i64 16}
!11 = !{!"double", !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}


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