; LLVM IR from Dev-XYS/Algorithms :: Dijkstra(Heap-Optimised).ll (Z8Dijkstrai)

; 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 }
%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
@pos = external dso_local global [100010 x i32], align 16
@heapsize = external dso_local global i32, align 4

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z21initial_single_sourcei(i32 noundef) #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 @_Z10build_heapi(i32 noundef) #0

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

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_Z11extract_minv() #2

; Function Attrs: mustprogress uwtable
define dso_local void @_Z8Dijkstrai(i32 noundef %0) #2 {
  %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 @_Z10build_heapi(i32 noundef %7)
  br label %8

8:                                                ; preds = %70, %1
  %9 = load i32, ptr @heapsize, align 4, !tbaa !5
  %10 = icmp sgt i32 %9, 0
  br i1 %10, label %11, label %71

11:                                               ; preds = %8
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  %12 = call noundef i32 @_Z11extract_minv()
  store i32 %12, ptr %3, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  %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 4, !tbaa !9
  store i32 %17, ptr %4, align 4, !tbaa !5
  br label %18

18:                                               ; preds = %64, %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) #3
  br label %70

22:                                               ; preds = %18
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  %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 %63

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
  %60 = sext i32 %59 to i64
  %61 = getelementptr inbounds [100010 x i32], ptr @pos, i64 0, i64 %60
  %62 = load i32, ptr %61, align 4, !tbaa !5
  call void @_Z10heap_floati(i32 noundef %62)
  br label %63

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

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

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

71:                                               ; 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 = { mustprogress 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 #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 = !{!"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 = !{!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, 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
@pos = external dso_local local_unnamed_addr global [100010 x i32], align 16
@heapsize = external dso_local local_unnamed_addr global i32, align 4

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

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

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

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_Z11extract_minv() local_unnamed_addr #1

; Function Attrs: mustprogress uwtable
define dso_local void @_Z8Dijkstrai(i32 noundef %0) local_unnamed_addr #1 {
  tail call void @_Z21initial_single_sourcei(i32 noundef %0)
  tail call void @_Z10build_heapi(i32 noundef %0)
  %2 = load i32, ptr @heapsize, align 4, !tbaa !5
  %3 = icmp sgt i32 %2, 0
  br i1 %3, label %.lr.ph16, label %._crit_edge

.loopexit:                                        ; preds = %25, %.lr.ph16
  %4 = load i32, ptr @heapsize, align 4, !tbaa !5
  %5 = icmp sgt i32 %4, 0
  br i1 %5, label %.lr.ph16, label %._crit_edge, !llvm.loop !9

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

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

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

22:                                               ; preds = %10
  store i32 %16, ptr %19, align 4, !tbaa !11
  %23 = getelementptr inbounds [100010 x i32], ptr @pos, i64 0, i64 %18
  %24 = load i32, ptr %23, align 4, !tbaa !5
  tail call void @_Z10heap_floati(i32 noundef %24)
  br label %25

25:                                               ; preds = %22, %10
  %26 = getelementptr inbounds i8, ptr %13, i64 4
  %.0 = load i32, ptr %26, align 4, !tbaa !5
  %.not = icmp eq i32 %.0, 0
  br i1 %.not, label %.loopexit, label %10, !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" }
attributes #1 = { mustprogress 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}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!12, !6, i64 4}
!12 = !{!"_ZTS6vertex", !6, i64 0, !6, i64 4, !6, i64 8}
!13 = !{!14, !6, i64 8}
!14 = !{!"_ZTS4edge", !6, i64 0, !6, i64 4, !6, i64 8}
!15 = !{!14, !6, i64 0}
!16 = distinct !{!16, !10}


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