; LLVM IR from git-akshat/NP-Lab :: A1 (Link State Routing) (lsr)

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

@visited = external dso_local global [100 x i32], align 16
@n = external dso_local global i32, align 4
@distance = external dso_local global [100 x i32], align 16

; 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
define dso_local i32 @GetMin() #1 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %1) #2
  store i32 -1, ptr %1, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #2
  store i32 999, ptr %2, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #2
  store i32 0, ptr %3, align 4, !tbaa !5
  br label %4

4:                                                ; preds = %28, %0
  %5 = load i32, ptr %3, align 4, !tbaa !5
  %6 = load i32, ptr @n, align 4, !tbaa !5
  %7 = icmp slt i32 %5, %6
  br i1 %7, label %8, label %31

8:                                                ; preds = %4
  %9 = load i32, ptr %3, align 4, !tbaa !5
  %10 = sext i32 %9 to i64
  %11 = getelementptr inbounds [100 x i32], ptr @visited, i64 0, i64 %10
  %12 = load i32, ptr %11, align 4, !tbaa !5
  %13 = icmp ne i32 %12, 0
  br i1 %13, label %27, label %14

14:                                               ; preds = %8
  %15 = load i32, ptr %2, align 4, !tbaa !5
  %16 = load i32, ptr %3, align 4, !tbaa !5
  %17 = sext i32 %16 to i64
  %18 = getelementptr inbounds [100 x i32], ptr @distance, i64 0, i64 %17
  %19 = load i32, ptr %18, align 4, !tbaa !5
  %20 = icmp sge i32 %15, %19
  br i1 %20, label %21, label %27

21:                                               ; preds = %14
  %22 = load i32, ptr %3, align 4, !tbaa !5
  store i32 %22, ptr %1, align 4, !tbaa !5
  %23 = load i32, ptr %3, align 4, !tbaa !5
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds [100 x i32], ptr @distance, i64 0, i64 %24
  %26 = load i32, ptr %25, align 4, !tbaa !5
  store i32 %26, ptr %2, align 4, !tbaa !5
  br label %27

27:                                               ; preds = %21, %14, %8
  br label %28

28:                                               ; preds = %27
  %29 = load i32, ptr %3, align 4, !tbaa !5
  %30 = add nsw i32 %29, 1
  store i32 %30, ptr %3, align 4, !tbaa !5
  br label %4, !llvm.loop !9

31:                                               ; preds = %4
  %32 = load i32, ptr %1, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %1) #2
  ret i32 %32
}

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 = !{!"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"

@visited = external dso_local local_unnamed_addr global [100 x i32], align 16
@n = external dso_local local_unnamed_addr global i32, align 4
@distance = external dso_local local_unnamed_addr global [100 x i32], align 16

; Function Attrs: nofree norecurse nosync nounwind memory(read, argmem: none, inaccessiblemem: none) uwtable
define dso_local i32 @GetMin() local_unnamed_addr #0 {
  %1 = load i32, ptr @n, align 4, !tbaa !5
  %2 = icmp sgt i32 %1, 0
  br i1 %2, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %0
  %wide.trip.count = zext nneg i32 %1 to i64
  %xtraiter = and i64 %wide.trip.count, 1
  %3 = icmp eq i32 %1, 1
  br i1 %3, 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

.lr.ph:                                           ; preds = %16, %.lr.ph.preheader.new
  %indvars.iv = phi i64 [ 0, %.lr.ph.preheader.new ], [ %indvars.iv.next.1, %16 ]
  %.0815 = phi i32 [ 999, %.lr.ph.preheader.new ], [ %.1.1, %16 ]
  %.0914 = phi i32 [ -1, %.lr.ph.preheader.new ], [ %.110.1, %16 ]
  %niter = phi i64 [ 0, %.lr.ph.preheader.new ], [ %niter.next.1, %16 ]
  %4 = getelementptr inbounds [100 x i32], ptr @visited, i64 0, i64 %indvars.iv
  %5 = load i32, ptr %4, align 8, !tbaa !5
  %.not = icmp eq i32 %5, 0
  br i1 %.not, label %6, label %.lr.ph.1

6:                                                ; preds = %.lr.ph
  %7 = getelementptr inbounds [100 x i32], ptr @distance, i64 0, i64 %indvars.iv
  %8 = load i32, ptr %7, align 8, !tbaa !5
  %.not12 = icmp slt i32 %.0815, %8
  %9 = trunc nuw nsw i64 %indvars.iv to i32
  %spec.select = select i1 %.not12, i32 %.0914, i32 %9
  %spec.select13 = tail call i32 @llvm.smin.i32(i32 %.0815, i32 %8)
  br label %.lr.ph.1

.lr.ph.1:                                         ; preds = %6, %.lr.ph
  %.110 = phi i32 [ %.0914, %.lr.ph ], [ %spec.select, %6 ]
  %.1 = phi i32 [ %.0815, %.lr.ph ], [ %spec.select13, %6 ]
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %10 = getelementptr inbounds [100 x i32], ptr @visited, i64 0, i64 %indvars.iv.next
  %11 = load i32, ptr %10, align 4, !tbaa !5
  %.not.1 = icmp eq i32 %11, 0
  br i1 %.not.1, label %12, label %16

12:                                               ; preds = %.lr.ph.1
  %13 = getelementptr inbounds [100 x i32], ptr @distance, i64 0, i64 %indvars.iv.next
  %14 = load i32, ptr %13, align 4, !tbaa !5
  %.not12.1 = icmp slt i32 %.1, %14
  %15 = trunc nuw nsw i64 %indvars.iv.next to i32
  %spec.select.1 = select i1 %.not12.1, i32 %.110, i32 %15
  %spec.select13.1 = tail call i32 @llvm.smin.i32(i32 %.1, i32 %14)
  br label %16

16:                                               ; preds = %12, %.lr.ph.1
  %.110.1 = phi i32 [ %.110, %.lr.ph.1 ], [ %spec.select.1, %12 ]
  %.1.1 = phi i32 [ %.1, %.lr.ph.1 ], [ %spec.select13.1, %12 ]
  %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

._crit_edge.loopexit.unr-lcssa:                   ; preds = %16, %.lr.ph.preheader
  %.110.lcssa.ph = phi i32 [ poison, %.lr.ph.preheader ], [ %.110.1, %16 ]
  %indvars.iv.unr = phi i64 [ 0, %.lr.ph.preheader ], [ %indvars.iv.next.1, %16 ]
  %.0815.unr = phi i32 [ 999, %.lr.ph.preheader ], [ %.1.1, %16 ]
  %.0914.unr = phi i32 [ -1, %.lr.ph.preheader ], [ %.110.1, %16 ]
  %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
  %17 = getelementptr inbounds [100 x i32], ptr @visited, i64 0, i64 %indvars.iv.unr
  %18 = load i32, ptr %17, align 4, !tbaa !5
  %.not.epil = icmp eq i32 %18, 0
  br i1 %.not.epil, label %19, label %._crit_edge

19:                                               ; preds = %.lr.ph.epil
  %20 = getelementptr inbounds [100 x i32], ptr @distance, i64 0, i64 %indvars.iv.unr
  %21 = load i32, ptr %20, align 4, !tbaa !5
  %.not12.epil = icmp slt i32 %.0815.unr, %21
  %22 = trunc nuw nsw i64 %indvars.iv.unr to i32
  %spec.select.epil = select i1 %.not12.epil, i32 %.0914.unr, i32 %22
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit.unr-lcssa, %19, %.lr.ph.epil, %0
  %.09.lcssa = phi i32 [ -1, %0 ], [ %.110.lcssa.ph, %._crit_edge.loopexit.unr-lcssa ], [ %.0914.unr, %.lr.ph.epil ], [ %spec.select.epil, %19 ]
  ret i32 %.09.lcssa
}

; 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,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass