; 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
@source = external dso_local global i32, align 4
@parent = external dso_local global [100 x i32], align 16
@n = external dso_local global i32, align 4
@cost = external dso_local global [100 x [100 x i32]], align 16
@distance = external dso_local global [100 x i32], align 16

; Function Attrs: nounwind uwtable
define dso_local void @initialize() #0 {
  %1 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %1) #2
  %2 = load i32, ptr @source, align 4, !tbaa !5
  %3 = sext i32 %2 to i64
  %4 = getelementptr inbounds [100 x i32], ptr @visited, i64 0, i64 %3
  store i32 1, ptr %4, align 4, !tbaa !5
  %5 = load i32, ptr @source, align 4, !tbaa !5
  %6 = load i32, ptr @source, align 4, !tbaa !5
  %7 = sext i32 %6 to i64
  %8 = getelementptr inbounds [100 x i32], ptr @parent, i64 0, i64 %7
  store i32 %5, ptr %8, align 4, !tbaa !5
  store i32 0, ptr %1, align 4, !tbaa !5
  br label %9

9:                                                ; preds = %38, %0
  %10 = load i32, ptr %1, align 4, !tbaa !5
  %11 = load i32, ptr @n, align 4, !tbaa !5
  %12 = icmp slt i32 %10, %11
  br i1 %12, label %13, label %41

13:                                               ; preds = %9
  %14 = load i32, ptr @source, align 4, !tbaa !5
  %15 = sext i32 %14 to i64
  %16 = getelementptr inbounds [100 x [100 x i32]], ptr @cost, i64 0, i64 %15
  %17 = load i32, ptr %1, align 4, !tbaa !5
  %18 = sext i32 %17 to i64
  %19 = getelementptr inbounds [100 x i32], ptr %16, i64 0, i64 %18
  %20 = load i32, ptr %19, align 4, !tbaa !5
  %21 = load i32, ptr %1, align 4, !tbaa !5
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds [100 x i32], ptr @distance, i64 0, i64 %22
  store i32 %20, ptr %23, align 4, !tbaa !5
  %24 = load i32, ptr @source, align 4, !tbaa !5
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds [100 x [100 x i32]], ptr @cost, i64 0, i64 %25
  %27 = load i32, ptr %1, align 4, !tbaa !5
  %28 = sext i32 %27 to i64
  %29 = getelementptr inbounds [100 x i32], ptr %26, i64 0, i64 %28
  %30 = load i32, ptr %29, align 4, !tbaa !5
  %31 = icmp ne i32 %30, 999
  br i1 %31, label %32, label %37

32:                                               ; preds = %13
  %33 = load i32, ptr @source, align 4, !tbaa !5
  %34 = load i32, ptr %1, align 4, !tbaa !5
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds [100 x i32], ptr @parent, i64 0, i64 %35
  store i32 %33, ptr %36, align 4, !tbaa !5
  br label %37

37:                                               ; preds = %32, %13
  br label %38

38:                                               ; preds = %37
  %39 = load i32, ptr %1, align 4, !tbaa !5
  %40 = add nsw i32 %39, 1
  store i32 %40, ptr %1, align 4, !tbaa !5
  br label %9, !llvm.loop !9

41:                                               ; preds = %9
  call void @llvm.lifetime.end.p0(i64 4, ptr %1) #2
  ret void
}

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

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

; Function Attrs: nofree norecurse nosync nounwind memory(readwrite, argmem: none, inaccessiblemem: none) uwtable
define dso_local void @initialize() local_unnamed_addr #0 {
  %1 = load i32, ptr @source, align 4, !tbaa !5
  %2 = sext i32 %1 to i64
  %3 = getelementptr inbounds [100 x i32], ptr @visited, i64 0, i64 %2
  store i32 1, ptr %3, align 4, !tbaa !5
  %4 = getelementptr inbounds [100 x i32], ptr @parent, i64 0, i64 %2
  store i32 %1, ptr %4, align 4, !tbaa !5
  %5 = load i32, ptr @n, align 4, !tbaa !5
  %6 = icmp sgt i32 %5, 0
  br i1 %6, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %0
  %7 = mul nsw i64 %2, 400
  %scevgep = getelementptr i8, ptr @cost, i64 %7
  %8 = zext nneg i32 %5 to i64
  %9 = shl nuw nsw i64 %8, 2
  tail call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 16 @distance, ptr align 16 %scevgep, i64 %9, i1 false), !tbaa !5
  %min.iters.check = icmp ult i32 %5, 8
  br i1 %min.iters.check, label %.lr.ph.preheader23, label %vector.ph

vector.ph:                                        ; preds = %.lr.ph.preheader
  %n.vec = and i64 %8, 2147483640
  br label %vector.body

vector.body:                                      ; preds = %pred.store.continue22, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %pred.store.continue22 ]
  %10 = or disjoint i64 %index, 4
  %11 = getelementptr inbounds [100 x [100 x i32]], ptr @cost, i64 0, i64 %2, i64 %index
  %12 = getelementptr inbounds i8, ptr %11, i64 16
  %wide.load = load <4 x i32>, ptr %11, align 16, !tbaa !5
  %wide.load8 = load <4 x i32>, ptr %12, align 16, !tbaa !5
  %13 = icmp ne <4 x i32> %wide.load, <i32 999, i32 999, i32 999, i32 999>
  %14 = icmp ne <4 x i32> %wide.load8, <i32 999, i32 999, i32 999, i32 999>
  %15 = extractelement <4 x i1> %13, i64 0
  br i1 %15, label %pred.store.if, label %pred.store.continue

pred.store.if:                                    ; preds = %vector.body
  %16 = getelementptr inbounds [100 x i32], ptr @parent, i64 0, i64 %index
  store i32 %1, ptr %16, align 16, !tbaa !5
  br label %pred.store.continue

pred.store.continue:                              ; preds = %pred.store.if, %vector.body
  %17 = extractelement <4 x i1> %13, i64 1
  br i1 %17, label %pred.store.if9, label %pred.store.continue10

pred.store.if9:                                   ; preds = %pred.store.continue
  %18 = or disjoint i64 %index, 1
  %19 = getelementptr inbounds [100 x i32], ptr @parent, i64 0, i64 %18
  store i32 %1, ptr %19, align 4, !tbaa !5
  br label %pred.store.continue10

pred.store.continue10:                            ; preds = %pred.store.if9, %pred.store.continue
  %20 = extractelement <4 x i1> %13, i64 2
  br i1 %20, label %pred.store.if11, label %pred.store.continue12

pred.store.if11:                                  ; preds = %pred.store.continue10
  %21 = or disjoint i64 %index, 2
  %22 = getelementptr inbounds [100 x i32], ptr @parent, i64 0, i64 %21
  store i32 %1, ptr %22, align 8, !tbaa !5
  br label %pred.store.continue12

pred.store.continue12:                            ; preds = %pred.store.if11, %pred.store.continue10
  %23 = extractelement <4 x i1> %13, i64 3
  br i1 %23, label %pred.store.if13, label %pred.store.continue14

pred.store.if13:                                  ; preds = %pred.store.continue12
  %24 = or disjoint i64 %index, 3
  %25 = getelementptr inbounds [100 x i32], ptr @parent, i64 0, i64 %24
  store i32 %1, ptr %25, align 4, !tbaa !5
  br label %pred.store.continue14

pred.store.continue14:                            ; preds = %pred.store.if13, %pred.store.continue12
  %26 = extractelement <4 x i1> %14, i64 0
  br i1 %26, label %pred.store.if15, label %pred.store.continue16

pred.store.if15:                                  ; preds = %pred.store.continue14
  %27 = getelementptr inbounds [100 x i32], ptr @parent, i64 0, i64 %10
  store i32 %1, ptr %27, align 16, !tbaa !5
  br label %pred.store.continue16

pred.store.continue16:                            ; preds = %pred.store.if15, %pred.store.continue14
  %28 = extractelement <4 x i1> %14, i64 1
  br i1 %28, label %pred.store.if17, label %pred.store.continue18

pred.store.if17:                                  ; preds = %pred.store.continue16
  %29 = or disjoint i64 %index, 5
  %30 = getelementptr inbounds [100 x i32], ptr @parent, i64 0, i64 %29
  store i32 %1, ptr %30, align 4, !tbaa !5
  br label %pred.store.continue18

pred.store.continue18:                            ; preds = %pred.store.if17, %pred.store.continue16
  %31 = extractelement <4 x i1> %14, i64 2
  br i1 %31, label %pred.store.if19, label %pred.store.continue20

pred.store.if19:                                  ; preds = %pred.store.continue18
  %32 = or disjoint i64 %index, 6
  %33 = getelementptr inbounds [100 x i32], ptr @parent, i64 0, i64 %32
  store i32 %1, ptr %33, align 8, !tbaa !5
  br label %pred.store.continue20

pred.store.continue20:                            ; preds = %pred.store.if19, %pred.store.continue18
  %34 = extractelement <4 x i1> %14, i64 3
  br i1 %34, label %pred.store.if21, label %pred.store.continue22

pred.store.if21:                                  ; preds = %pred.store.continue20
  %35 = or disjoint i64 %index, 7
  %36 = getelementptr inbounds [100 x i32], ptr @parent, i64 0, i64 %35
  store i32 %1, ptr %36, align 4, !tbaa !5
  br label %pred.store.continue22

pred.store.continue22:                            ; preds = %pred.store.if21, %pred.store.continue20
  %index.next = add nuw i64 %index, 8
  %37 = icmp eq i64 %index.next, %n.vec
  br i1 %37, label %middle.block, label %vector.body, !llvm.loop !9

middle.block:                                     ; preds = %pred.store.continue22
  %cmp.n = icmp eq i64 %n.vec, %8
  br i1 %cmp.n, label %._crit_edge, label %.lr.ph.preheader23

.lr.ph.preheader23:                               ; preds = %middle.block, %.lr.ph.preheader
  %indvars.iv.ph = phi i64 [ 0, %.lr.ph.preheader ], [ %n.vec, %middle.block ]
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader23, %42
  %indvars.iv = phi i64 [ %indvars.iv.next, %42 ], [ %indvars.iv.ph, %.lr.ph.preheader23 ]
  %38 = getelementptr inbounds [100 x [100 x i32]], ptr @cost, i64 0, i64 %2, i64 %indvars.iv
  %39 = load i32, ptr %38, align 4, !tbaa !5
  %.not = icmp eq i32 %39, 999
  br i1 %.not, label %42, label %40

40:                                               ; preds = %.lr.ph
  %41 = getelementptr inbounds [100 x i32], ptr @parent, i64 0, i64 %indvars.iv
  store i32 %1, ptr %41, align 4, !tbaa !5
  br label %42

42:                                               ; preds = %.lr.ph, %40
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %8
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph, !llvm.loop !13

._crit_edge:                                      ; preds = %42, %middle.block, %0
  ret void
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #1

attributes #0 = { nofree norecurse nosync nounwind memory(readwrite, 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 nounwind willreturn memory(argmem: readwrite) }

!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, !11, !12}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!"llvm.loop.isvectorized", i32 1}
!12 = !{!"llvm.loop.unroll.runtime.disable"}
!13 = distinct !{!13, !10, !12, !11}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopIdiomRecognizePass,LoopLoadEliminationPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,LoopVectorizePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass