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

; 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 }
%struct.edge = type { i32, i32, i32 }

@V = external dso_local global [100010 x %struct.vertex], align 16
@E = external dso_local global [1000010 x %struct.edge], align 16

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z7dequeuev() #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 noundef zeroext i1 @_Z5emptyv() #0

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z4SPFAi(i32 noundef %0) #0 {
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  store i32 %0, ptr %2, align 4, !tbaa !5
  %6 = load i32, ptr %2, align 4, !tbaa !5
  call void @_Z21initial_single_sourcei(i32 noundef %6)
  %7 = load i32, ptr %2, align 4, !tbaa !5
  call void @_Z7enqueuei(i32 noundef %7)
  br label %8

8:                                                ; preds = %67, %1
  %9 = call noundef zeroext i1 @_Z5emptyv()
  %10 = xor i1 %9, true
  br i1 %10, label %11, label %68

11:                                               ; preds = %8
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #2
  %12 = call noundef i32 @_Z7dequeuev()
  store i32 %12, ptr %3, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #2
  %13 = load i32, ptr %3, align 4, !tbaa !5
  %14 = sext i32 %13 to i64
  %15 = getelementptr inbounds [100010 x %struct.vertex], ptr @V, i64 0, i64 %14
  %16 = getelementptr inbounds %struct.vertex, ptr %15, i32 0, i32 0
  %17 = load i32, ptr %16, align 8, !tbaa !9
  store i32 %17, ptr %4, align 4, !tbaa !5
  br label %18

18:                                               ; preds = %61, %11
  %19 = load i32, ptr %4, align 4, !tbaa !5
  %20 = icmp ne i32 %19, 0
  br i1 %20, label %22, label %21

21:                                               ; preds = %18
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #2
  br label %67

22:                                               ; preds = %18
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #2
  %23 = load i32, ptr %3, align 4, !tbaa !5
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds [100010 x %struct.vertex], ptr @V, i64 0, i64 %24
  %26 = getelementptr inbounds %struct.vertex, ptr %25, i32 0, i32 1
  %27 = load i32, ptr %26, align 4, !tbaa !11
  %28 = load i32, ptr %4, align 4, !tbaa !5
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds [1000010 x %struct.edge], ptr @E, i64 0, i64 %29
  %31 = getelementptr inbounds %struct.edge, ptr %30, i32 0, i32 2
  %32 = load i32, ptr %31, align 4, !tbaa !12
  %33 = add nsw i32 %27, %32
  store i32 %33, ptr %5, align 4, !tbaa !5
  %34 = load i32, ptr %5, align 4, !tbaa !5
  %35 = load i32, ptr %4, align 4, !tbaa !5
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds [1000010 x %struct.edge], ptr @E, i64 0, i64 %36
  %38 = getelementptr inbounds %struct.edge, ptr %37, i32 0, i32 0
  %39 = load i32, ptr %38, align 4, !tbaa !14
  %40 = sext i32 %39 to i64
  %41 = getelementptr inbounds [100010 x %struct.vertex], ptr @V, i64 0, i64 %40
  %42 = getelementptr inbounds %struct.vertex, ptr %41, i32 0, i32 1
  %43 = load i32, ptr %42, align 4, !tbaa !11
  %44 = icmp slt i32 %34, %43
  br i1 %44, label %45, label %60

45:                                               ; preds = %22
  %46 = load i32, ptr %5, align 4, !tbaa !5
  %47 = load i32, ptr %4, align 4, !tbaa !5
  %48 = sext i32 %47 to i64
  %49 = getelementptr inbounds [1000010 x %struct.edge], ptr @E, i64 0, i64 %48
  %50 = getelementptr inbounds %struct.edge, ptr %49, i32 0, i32 0
  %51 = load i32, ptr %50, align 4, !tbaa !14
  %52 = sext i32 %51 to i64
  %53 = getelementptr inbounds [100010 x %struct.vertex], ptr @V, i64 0, i64 %52
  %54 = getelementptr inbounds %struct.vertex, ptr %53, i32 0, i32 1
  store i32 %46, ptr %54, align 4, !tbaa !11
  %55 = load i32, ptr %4, align 4, !tbaa !5
  %56 = sext i32 %55 to i64
  %57 = getelementptr inbounds [1000010 x %struct.edge], ptr @E, i64 0, i64 %56
  %58 = getelementptr inbounds %struct.edge, ptr %57, i32 0, i32 0
  %59 = load i32, ptr %58, align 4, !tbaa !14
  call void @_Z7enqueuei(i32 noundef %59)
  br label %60

60:                                               ; preds = %45, %22
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  br label %61

61:                                               ; preds = %60
  %62 = load i32, ptr %4, align 4, !tbaa !5
  %63 = sext i32 %62 to i64
  %64 = getelementptr inbounds [1000010 x %struct.edge], ptr @E, i64 0, i64 %63
  %65 = getelementptr inbounds %struct.edge, ptr %64, i32 0, i32 1
  %66 = load i32, ptr %65, align 4, !tbaa !15
  store i32 %66, ptr %4, align 4, !tbaa !5
  br label %18, !llvm.loop !16

67:                                               ; preds = %21
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #2
  br label %8, !llvm.loop !18

68:                                               ; preds = %8
  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}
!11 = !{!10, !6, i64 4}
!12 = !{!13, !6, i64 8}
!13 = !{!"_ZTS4edge", !6, i64 0, !6, i64 4, !6, i64 8}
!14 = !{!13, !6, i64 0}
!15 = !{!13, !6, i64 4}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}
!18 = distinct !{!18, !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 }
%struct.edge = type { i32, i32, i32 }

@V = external dso_local local_unnamed_addr global [100010 x %struct.vertex], align 16
@E = external dso_local local_unnamed_addr global [1000010 x %struct.edge], align 16

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z7dequeuev() local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_Z5emptyv() local_unnamed_addr #0

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z4SPFAi(i32 noundef %0) local_unnamed_addr #0 {
  tail call void @_Z21initial_single_sourcei(i32 noundef %0)
  tail call void @_Z7enqueuei(i32 noundef %0)
  %2 = tail call noundef zeroext i1 @_Z5emptyv()
  br i1 %2, label %._crit_edge, label %.lr.ph16

.loopexit:                                        ; preds = %21, %.lr.ph16
  %3 = tail call noundef zeroext i1 @_Z5emptyv()
  br i1 %3, label %._crit_edge, label %.lr.ph16, !llvm.loop !5

.lr.ph16:                                         ; preds = %1, %.loopexit
  %4 = tail call noundef i32 @_Z7dequeuev()
  %5 = sext i32 %4 to i64
  %6 = getelementptr inbounds [100010 x %struct.vertex], ptr @V, i64 0, i64 %5
  %.013 = load i32, ptr %6, align 8, !tbaa !7
  %.not14 = icmp eq i32 %.013, 0
  br i1 %.not14, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph16
  %7 = getelementptr inbounds i8, ptr %6, i64 4
  br label %8

8:                                                ; preds = %.lr.ph, %21
  %.015 = phi i32 [ %.013, %.lr.ph ], [ %.0, %21 ]
  %9 = load i32, ptr %7, align 4, !tbaa !11
  %10 = sext i32 %.015 to i64
  %11 = getelementptr inbounds [1000010 x %struct.edge], ptr @E, i64 0, i64 %10
  %12 = getelementptr inbounds i8, ptr %11, i64 8
  %13 = load i32, ptr %12, align 4, !tbaa !13
  %14 = add nsw i32 %13, %9
  %15 = load i32, ptr %11, align 4, !tbaa !15
  %16 = sext i32 %15 to i64
  %17 = getelementptr inbounds [100010 x %struct.vertex], ptr @V, i64 0, i64 %16, i32 1
  %18 = load i32, ptr %17, align 4, !tbaa !11
  %19 = icmp slt i32 %14, %18
  br i1 %19, label %20, label %21

20:                                               ; preds = %8
  store i32 %14, ptr %17, align 4, !tbaa !11
  tail call void @_Z7enqueuei(i32 noundef %15)
  br label %21

21:                                               ; preds = %20, %8
  %22 = getelementptr inbounds i8, ptr %11, i64 4
  %.0 = load i32, ptr %22, align 4, !tbaa !7
  %.not = icmp eq i32 %.0, 0
  br i1 %.not, label %.loopexit, label %8, !llvm.loop !16

._crit_edge:                                      ; preds = %.loopexit, %1
  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" }

!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 = !{!"int", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C++ TBAA"}
!11 = !{!12, !8, i64 4}
!12 = !{!"_ZTS6vertex", !8, i64 0, !8, i64 4}
!13 = !{!14, !8, i64 8}
!14 = !{!"_ZTS4edge", !8, i64 0, !8, i64 4, !8, i64 8}
!15 = !{!14, !8, i64 0}
!16 = distinct !{!16, !6}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass