; LLVM IR from AllAlgorithms/c :: algorithms/graphs (Dijkstra)

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

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

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

; Function Attrs: nounwind uwtable
declare dso_local ptr @FindSmallest() #1

; Function Attrs: nounwind uwtable
define dso_local void @Dijks(ptr noundef %0) #1 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #2
  %7 = load ptr, ptr %2, align 8, !tbaa !5
  %8 = getelementptr inbounds %struct.Node, ptr %7, i32 0, i32 1
  %9 = load ptr, ptr %8, align 8, !tbaa !9
  store ptr %9, ptr %3, align 8, !tbaa !5
  %10 = load ptr, ptr %2, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct.Node, ptr %10, i32 0, i32 5
  store i32 1, ptr %11, align 8, !tbaa !12
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #2
  store i32 0, ptr %4, align 4, !tbaa !13
  br label %12

12:                                               ; preds = %82, %1
  %13 = load i32, ptr %4, align 4, !tbaa !13
  %14 = load ptr, ptr %2, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.Node, ptr %14, i32 0, i32 3
  %16 = load i32, ptr %15, align 8, !tbaa !14
  %17 = icmp slt i32 %13, %16
  br i1 %17, label %19, label %18

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

19:                                               ; preds = %12
  %20 = load ptr, ptr %3, align 8, !tbaa !5
  %21 = load i32, ptr %4, align 4, !tbaa !13
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds ptr, ptr %20, i64 %22
  %24 = load ptr, ptr %23, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.Edge, ptr %24, i32 0, i32 0
  %26 = load ptr, ptr %25, align 8, !tbaa !15
  %27 = getelementptr inbounds %struct.Node, ptr %26, i32 0, i32 4
  %28 = load i32, ptr %27, align 4, !tbaa !17
  %29 = icmp eq i32 %28, -1
  br i1 %29, label %52, label %30

30:                                               ; preds = %19
  %31 = load ptr, ptr %2, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.Node, ptr %31, i32 0, i32 4
  %33 = load i32, ptr %32, align 4, !tbaa !17
  %34 = load ptr, ptr %3, align 8, !tbaa !5
  %35 = load i32, ptr %4, align 4, !tbaa !13
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds ptr, ptr %34, i64 %36
  %38 = load ptr, ptr %37, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.Edge, ptr %38, i32 0, i32 1
  %40 = load i32, ptr %39, align 8, !tbaa !18
  %41 = add nsw i32 %33, %40
  %42 = load ptr, ptr %3, align 8, !tbaa !5
  %43 = load i32, ptr %4, align 4, !tbaa !13
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds ptr, ptr %42, i64 %44
  %46 = load ptr, ptr %45, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.Edge, ptr %46, i32 0, i32 0
  %48 = load ptr, ptr %47, align 8, !tbaa !15
  %49 = getelementptr inbounds %struct.Node, ptr %48, i32 0, i32 4
  %50 = load i32, ptr %49, align 4, !tbaa !17
  %51 = icmp slt i32 %41, %50
  br i1 %51, label %52, label %81

52:                                               ; preds = %30, %19
  %53 = load ptr, ptr %2, align 8, !tbaa !5
  %54 = load ptr, ptr %3, align 8, !tbaa !5
  %55 = load i32, ptr %4, align 4, !tbaa !13
  %56 = sext i32 %55 to i64
  %57 = getelementptr inbounds ptr, ptr %54, i64 %56
  %58 = load ptr, ptr %57, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.Edge, ptr %58, i32 0, i32 0
  %60 = load ptr, ptr %59, align 8, !tbaa !15
  %61 = getelementptr inbounds %struct.Node, ptr %60, i32 0, i32 2
  store ptr %53, ptr %61, align 8, !tbaa !19
  %62 = load ptr, ptr %2, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.Node, ptr %62, i32 0, i32 4
  %64 = load i32, ptr %63, align 4, !tbaa !17
  %65 = load ptr, ptr %3, align 8, !tbaa !5
  %66 = load i32, ptr %4, align 4, !tbaa !13
  %67 = sext i32 %66 to i64
  %68 = getelementptr inbounds ptr, ptr %65, i64 %67
  %69 = load ptr, ptr %68, align 8, !tbaa !5
  %70 = getelementptr inbounds %struct.Edge, ptr %69, i32 0, i32 1
  %71 = load i32, ptr %70, align 8, !tbaa !18
  %72 = add nsw i32 %64, %71
  %73 = load ptr, ptr %3, align 8, !tbaa !5
  %74 = load i32, ptr %4, align 4, !tbaa !13
  %75 = sext i32 %74 to i64
  %76 = getelementptr inbounds ptr, ptr %73, i64 %75
  %77 = load ptr, ptr %76, align 8, !tbaa !5
  %78 = getelementptr inbounds %struct.Edge, ptr %77, i32 0, i32 0
  %79 = load ptr, ptr %78, align 8, !tbaa !15
  %80 = getelementptr inbounds %struct.Node, ptr %79, i32 0, i32 4
  store i32 %72, ptr %80, align 4, !tbaa !17
  br label %81

81:                                               ; preds = %52, %30
  br label %82

82:                                               ; preds = %81
  %83 = load i32, ptr %4, align 4, !tbaa !13
  %84 = add nsw i32 %83, 1
  store i32 %84, ptr %4, align 4, !tbaa !13
  br label %12, !llvm.loop !20

85:                                               ; preds = %18
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #2
  %86 = load ptr, ptr %2, align 8, !tbaa !5
  %87 = call ptr (ptr, ...) @FindSmallest(ptr noundef %86)
  store ptr %87, ptr %5, align 8, !tbaa !5
  %88 = load ptr, ptr %5, align 8, !tbaa !5
  %89 = icmp eq ptr %88, null
  br i1 %89, label %90, label %91

90:                                               ; preds = %85
  store i32 1, ptr %6, align 4
  br label %93

91:                                               ; preds = %85
  %92 = load ptr, ptr %5, align 8, !tbaa !5
  call void @Dijks(ptr noundef %92)
  store i32 0, ptr %6, align 4
  br label %93

93:                                               ; preds = %91, %90
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #2
  %94 = load i32, ptr %6, align 4
  switch i32 %94, label %96 [
    i32 0, label %95
    i32 1, label %95
  ]

95:                                               ; preds = %93, %93
  ret void

96:                                               ; preds = %93
  unreachable
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !6, i64 8}
!10 = !{!"Node", !11, i64 0, !6, i64 8, !6, i64 16, !11, i64 24, !11, i64 28, !11, i64 32}
!11 = !{!"int", !7, i64 0}
!12 = !{!10, !11, i64 32}
!13 = !{!11, !11, i64 0}
!14 = !{!10, !11, i64 24}
!15 = !{!16, !6, i64 0}
!16 = !{!"Edge", !6, i64 0, !11, i64 8}
!17 = !{!10, !11, i64 28}
!18 = !{!16, !11, i64 8}
!19 = !{!10, !6, i64 16}
!20 = distinct !{!20, !21}
!21 = !{!"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"

; Function Attrs: nounwind uwtable
declare dso_local ptr @FindSmallest() local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @Dijks(ptr noundef %0) local_unnamed_addr #0 {
  br label %tailrecurse

tailrecurse:                                      ; preds = %._crit_edge, %1
  %.tr = phi ptr [ %0, %1 ], [ %9, %._crit_edge ]
  %2 = getelementptr inbounds i8, ptr %.tr, i64 8
  %3 = load ptr, ptr %2, align 8, !tbaa !5
  %4 = getelementptr inbounds i8, ptr %.tr, i64 32
  store i32 1, ptr %4, align 8, !tbaa !11
  %5 = getelementptr inbounds i8, ptr %.tr, i64 24
  %6 = load i32, ptr %5, align 8, !tbaa !12
  %7 = icmp sgt i32 %6, 0
  br i1 %7, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %tailrecurse
  %8 = getelementptr inbounds i8, ptr %.tr, i64 28
  %wide.trip.count = zext nneg i32 %6 to i64
  br label %11

._crit_edge:                                      ; preds = %31, %tailrecurse
  %9 = tail call ptr (ptr, ...) @FindSmallest(ptr noundef nonnull %.tr)
  %10 = icmp eq ptr %9, null
  br i1 %10, label %32, label %tailrecurse

11:                                               ; preds = %.lr.ph, %31
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %31 ]
  %12 = getelementptr inbounds ptr, ptr %3, i64 %indvars.iv
  %13 = load ptr, ptr %12, align 8, !tbaa !13
  %14 = load ptr, ptr %13, align 8, !tbaa !14
  %15 = getelementptr inbounds i8, ptr %14, i64 28
  %16 = load i32, ptr %15, align 4, !tbaa !16
  %17 = icmp eq i32 %16, -1
  %.pre = load i32, ptr %8, align 4, !tbaa !16
  br i1 %17, label %23, label %18

18:                                               ; preds = %11
  %19 = getelementptr inbounds i8, ptr %13, i64 8
  %20 = load i32, ptr %19, align 8, !tbaa !17
  %21 = add nsw i32 %20, %.pre
  %22 = icmp slt i32 %21, %16
  br i1 %22, label %23, label %31

23:                                               ; preds = %18, %11
  %24 = getelementptr inbounds i8, ptr %14, i64 16
  store ptr %.tr, ptr %24, align 8, !tbaa !18
  %25 = load ptr, ptr %12, align 8, !tbaa !13
  %26 = getelementptr inbounds i8, ptr %25, i64 8
  %27 = load i32, ptr %26, align 8, !tbaa !17
  %28 = add nsw i32 %27, %.pre
  %29 = load ptr, ptr %25, align 8, !tbaa !14
  %30 = getelementptr inbounds i8, ptr %29, i64 28
  store i32 %28, ptr %30, align 4, !tbaa !16
  br label %31

31:                                               ; preds = %18, %23
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge, label %11, !llvm.loop !19

32:                                               ; preds = %._crit_edge
  ret void
}

attributes #0 = { 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, !10, i64 8}
!6 = !{!"Node", !7, i64 0, !10, i64 8, !10, i64 16, !7, i64 24, !7, i64 28, !7, i64 32}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!6, !7, i64 32}
!12 = !{!6, !7, i64 24}
!13 = !{!10, !10, i64 0}
!14 = !{!15, !10, i64 0}
!15 = !{!"Edge", !10, i64 0, !7, i64 8}
!16 = !{!6, !7, i64 28}
!17 = !{!15, !7, i64 8}
!18 = !{!6, !10, i64 16}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}


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