; LLVM IR from AllAlgorithms/c :: algorithms/dynamic-programming (dijkstras_algorithem)

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

@isvisited = external dso_local global [50 x i32], align 16
@dist = external dso_local global [50 x i32], align 16

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

8:                                                ; preds = %33, %2
  %9 = load i32, ptr %7, align 4, !tbaa !5
  %10 = load i32, ptr %3, align 4, !tbaa !5
  %11 = icmp slt i32 %9, %10
  br i1 %11, label %13, label %12

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

13:                                               ; preds = %8
  %14 = load i32, ptr %7, align 4, !tbaa !5
  %15 = sext i32 %14 to i64
  %16 = getelementptr inbounds [50 x i32], ptr @isvisited, i64 0, i64 %15
  %17 = load i32, ptr %16, align 4, !tbaa !5
  %18 = icmp ne i32 %17, 0
  br i1 %18, label %32, label %19

19:                                               ; preds = %13
  %20 = load i32, ptr %7, align 4, !tbaa !5
  %21 = sext i32 %20 to i64
  %22 = getelementptr inbounds [50 x i32], ptr @dist, i64 0, i64 %21
  %23 = load i32, ptr %22, align 4, !tbaa !5
  %24 = load i32, ptr %5, align 4, !tbaa !5
  %25 = icmp sle i32 %23, %24
  br i1 %25, label %26, label %32

26:                                               ; preds = %19
  %27 = load i32, ptr %7, align 4, !tbaa !5
  %28 = sext i32 %27 to i64
  %29 = getelementptr inbounds [50 x i32], ptr @dist, i64 0, i64 %28
  %30 = load i32, ptr %29, align 4, !tbaa !5
  store i32 %30, ptr %5, align 4, !tbaa !5
  %31 = load i32, ptr %7, align 4, !tbaa !5
  store i32 %31, ptr %6, align 4, !tbaa !5
  br label %32

32:                                               ; preds = %26, %19, %13
  br label %33

33:                                               ; preds = %32
  %34 = load i32, ptr %7, align 4, !tbaa !5
  %35 = add nsw i32 %34, 1
  store i32 %35, ptr %7, align 4, !tbaa !5
  br label %8, !llvm.loop !9

36:                                               ; preds = %12
  %37 = load i32, ptr %6, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  ret i32 %37
}

; 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 = { 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/C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"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"

@isvisited = external dso_local local_unnamed_addr global [50 x i32], align 16
@dist = external dso_local local_unnamed_addr global [50 x i32], align 16

; Function Attrs: nofree norecurse nosync nounwind memory(read, argmem: none, inaccessiblemem: none) uwtable
define dso_local i32 @minDistance(i32 noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = icmp sgt i32 %0, 0
  br i1 %3, label %.lr.ph.preheader, label %._crit_edge

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

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

._crit_edge.loopexit.unr-lcssa:                   ; preds = %23, %.lr.ph.preheader
  %.1.lcssa.ph = phi i32 [ poison, %.lr.ph.preheader ], [ %.1.1, %23 ]
  %indvars.iv.unr = phi i64 [ 0, %.lr.ph.preheader ], [ %indvars.iv.next.1, %23 ]
  %.0916.unr = phi i32 [ undef, %.lr.ph.preheader ], [ %.1.1, %23 ]
  %.01015.unr = phi i32 [ 2147483647, %.lr.ph.preheader ], [ %.111.1, %23 ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge, label %.lr.ph.epil

.lr.ph.epil:                                      ; preds = %._crit_edge.loopexit.unr-lcssa
  %5 = getelementptr inbounds [50 x i32], ptr @isvisited, i64 0, i64 %indvars.iv.unr
  %6 = load i32, ptr %5, align 4, !tbaa !5
  %.not.epil = icmp eq i32 %6, 0
  br i1 %.not.epil, label %7, label %._crit_edge

7:                                                ; preds = %.lr.ph.epil
  %8 = getelementptr inbounds [50 x i32], ptr @dist, i64 0, i64 %indvars.iv.unr
  %9 = load i32, ptr %8, align 4, !tbaa !5
  %.not13.epil = icmp sgt i32 %9, %.01015.unr
  %10 = trunc nuw nsw i64 %indvars.iv.unr to i32
  %spec.select14.epil = select i1 %.not13.epil, i32 %.0916.unr, i32 %10
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit.unr-lcssa, %7, %.lr.ph.epil, %2
  %.09.lcssa = phi i32 [ undef, %2 ], [ %.1.lcssa.ph, %._crit_edge.loopexit.unr-lcssa ], [ %.0916.unr, %.lr.ph.epil ], [ %spec.select14.epil, %7 ]
  ret i32 %.09.lcssa

.lr.ph:                                           ; preds = %23, %.lr.ph.preheader.new
  %indvars.iv = phi i64 [ 0, %.lr.ph.preheader.new ], [ %indvars.iv.next.1, %23 ]
  %.0916 = phi i32 [ undef, %.lr.ph.preheader.new ], [ %.1.1, %23 ]
  %.01015 = phi i32 [ 2147483647, %.lr.ph.preheader.new ], [ %.111.1, %23 ]
  %niter = phi i64 [ 0, %.lr.ph.preheader.new ], [ %niter.next.1, %23 ]
  %11 = getelementptr inbounds [50 x i32], ptr @isvisited, i64 0, i64 %indvars.iv
  %12 = load i32, ptr %11, align 8, !tbaa !5
  %.not = icmp eq i32 %12, 0
  br i1 %.not, label %13, label %.lr.ph.1

13:                                               ; preds = %.lr.ph
  %14 = getelementptr inbounds [50 x i32], ptr @dist, i64 0, i64 %indvars.iv
  %15 = load i32, ptr %14, align 8, !tbaa !5
  %.not13 = icmp sgt i32 %15, %.01015
  %spec.select = tail call i32 @llvm.smin.i32(i32 %15, i32 %.01015)
  %16 = trunc nuw nsw i64 %indvars.iv to i32
  %spec.select14 = select i1 %.not13, i32 %.0916, i32 %16
  br label %.lr.ph.1

.lr.ph.1:                                         ; preds = %13, %.lr.ph
  %.111 = phi i32 [ %.01015, %.lr.ph ], [ %spec.select, %13 ]
  %.1 = phi i32 [ %.0916, %.lr.ph ], [ %spec.select14, %13 ]
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %17 = getelementptr inbounds [50 x i32], ptr @isvisited, i64 0, i64 %indvars.iv.next
  %18 = load i32, ptr %17, align 4, !tbaa !5
  %.not.1 = icmp eq i32 %18, 0
  br i1 %.not.1, label %19, label %23

19:                                               ; preds = %.lr.ph.1
  %20 = getelementptr inbounds [50 x i32], ptr @dist, i64 0, i64 %indvars.iv.next
  %21 = load i32, ptr %20, align 4, !tbaa !5
  %.not13.1 = icmp sgt i32 %21, %.111
  %spec.select.1 = tail call i32 @llvm.smin.i32(i32 %21, i32 %.111)
  %22 = trunc nuw nsw i64 %indvars.iv.next to i32
  %spec.select14.1 = select i1 %.not13.1, i32 %.1, i32 %22
  br label %23

23:                                               ; preds = %19, %.lr.ph.1
  %.111.1 = phi i32 [ %.111, %.lr.ph.1 ], [ %spec.select.1, %19 ]
  %.1.1 = phi i32 [ %.1, %.lr.ph.1 ], [ %spec.select14.1, %19 ]
  %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 !9
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.smin.i32(i32, i32) #1

attributes #0 = { nofree norecurse nosync nounwind memory(read, 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" }
attributes #1 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }

!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/C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


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