; LLVM IR from CactiLab/Sherloc-Cortex-M-CFVD :: Sherloc_runtime/evaluation/src/dijkstra (dijkstra_small)

; 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, i32 }

@AdjMatrix = external dso_local global [10 x [10 x i32]], align 16
@ch = external dso_local global i32, align 4
@rgnNodes = external dso_local global [10 x %struct._NODE], align 16
@iNode = external dso_local global i32, align 4
@iDist = external dso_local global i32, align 4
@iPrev = external dso_local global i32, align 4
@i = external dso_local global i32, align 4
@iCost = external dso_local global i32, align 4

; Function Attrs: nounwind uwtable
declare dso_local void @enqueue(i32 noundef, i32 noundef, 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: nounwind uwtable
declare dso_local ptr @dequeue(ptr noundef, ptr noundef, ptr noundef) #0

; Function Attrs: nounwind uwtable
declare dso_local i32 @qcount() #0

; Function Attrs: nounwind uwtable
define dso_local i32 @dijkstra(i32 noundef %0, i32 noundef %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  store i32 %0, ptr %4, align 4, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !5
  store i32 0, ptr @ch, align 4, !tbaa !5
  br label %7

7:                                                ; preds = %19, %2
  %8 = load i32, ptr @ch, align 4, !tbaa !5
  %9 = icmp slt i32 %8, 10
  br i1 %9, label %10, label %22

10:                                               ; preds = %7
  %11 = load i32, ptr @ch, align 4, !tbaa !5
  %12 = sext i32 %11 to i64
  %13 = getelementptr inbounds [10 x %struct._NODE], ptr @rgnNodes, i64 0, i64 %12
  %14 = getelementptr inbounds %struct._NODE, ptr %13, i32 0, i32 0
  store i32 9999, ptr %14, align 8, !tbaa !9
  %15 = load i32, ptr @ch, align 4, !tbaa !5
  %16 = sext i32 %15 to i64
  %17 = getelementptr inbounds [10 x %struct._NODE], ptr @rgnNodes, i64 0, i64 %16
  %18 = getelementptr inbounds %struct._NODE, ptr %17, i32 0, i32 1
  store i32 9999, ptr %18, align 4, !tbaa !11
  br label %19

19:                                               ; preds = %10
  %20 = load i32, ptr @ch, align 4, !tbaa !5
  %21 = add nsw i32 %20, 1
  store i32 %21, ptr @ch, align 4, !tbaa !5
  br label %7, !llvm.loop !12

22:                                               ; preds = %7
  %23 = load i32, ptr %4, align 4, !tbaa !5
  %24 = load i32, ptr %5, align 4, !tbaa !5
  %25 = icmp eq i32 %23, %24
  br i1 %25, label %26, label %27

26:                                               ; preds = %22
  store i32 0, ptr %3, align 4
  br label %108

27:                                               ; preds = %22
  %28 = load i32, ptr %4, align 4, !tbaa !5
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds [10 x %struct._NODE], ptr @rgnNodes, i64 0, i64 %29
  %31 = getelementptr inbounds %struct._NODE, ptr %30, i32 0, i32 0
  store i32 0, ptr %31, align 8, !tbaa !9
  %32 = load i32, ptr %4, align 4, !tbaa !5
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds [10 x %struct._NODE], ptr @rgnNodes, i64 0, i64 %33
  %35 = getelementptr inbounds %struct._NODE, ptr %34, i32 0, i32 1
  store i32 9999, ptr %35, align 4, !tbaa !11
  %36 = load i32, ptr %4, align 4, !tbaa !5
  call void @enqueue(i32 noundef %36, i32 noundef 0, i32 noundef 9999)
  br label %37

37:                                               ; preds = %100, %27
  %38 = call i32 @qcount()
  %39 = icmp sgt i32 %38, 0
  br i1 %39, label %40, label %101

40:                                               ; preds = %37
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #2
  %41 = call ptr @dequeue(ptr noundef @iNode, ptr noundef @iDist, ptr noundef @iPrev)
  store ptr %41, ptr %6, align 8, !tbaa !14
  %42 = load ptr, ptr %6, align 8, !tbaa !14
  %43 = icmp ne ptr %42, null
  br i1 %43, label %44, label %46

44:                                               ; preds = %40
  %45 = load ptr, ptr %6, align 8, !tbaa !14
  call void @qfree_beebs(ptr noundef %45)
  br label %46

46:                                               ; preds = %44, %40
  store i32 0, ptr @i, align 4, !tbaa !5
  br label %47

47:                                               ; preds = %97, %46
  %48 = load i32, ptr @i, align 4, !tbaa !5
  %49 = icmp slt i32 %48, 10
  br i1 %49, label %50, label %100

50:                                               ; preds = %47
  %51 = load i32, ptr @iNode, align 4, !tbaa !5
  %52 = sext i32 %51 to i64
  %53 = getelementptr inbounds [10 x [10 x i32]], ptr @AdjMatrix, i64 0, i64 %52
  %54 = load i32, ptr @i, align 4, !tbaa !5
  %55 = sext i32 %54 to i64
  %56 = getelementptr inbounds [10 x i32], ptr %53, i64 0, i64 %55
  %57 = load i32, ptr %56, align 4, !tbaa !5
  store i32 %57, ptr @iCost, align 4, !tbaa !5
  %58 = load i32, ptr @iCost, align 4, !tbaa !5
  %59 = icmp ne i32 %58, 9999
  br i1 %59, label %60, label %96

60:                                               ; preds = %50
  %61 = load i32, ptr @i, align 4, !tbaa !5
  %62 = sext i32 %61 to i64
  %63 = getelementptr inbounds [10 x %struct._NODE], ptr @rgnNodes, i64 0, i64 %62
  %64 = getelementptr inbounds %struct._NODE, ptr %63, i32 0, i32 0
  %65 = load i32, ptr %64, align 8, !tbaa !9
  %66 = icmp eq i32 9999, %65
  br i1 %66, label %77, label %67

67:                                               ; preds = %60
  %68 = load i32, ptr @i, align 4, !tbaa !5
  %69 = sext i32 %68 to i64
  %70 = getelementptr inbounds [10 x %struct._NODE], ptr @rgnNodes, i64 0, i64 %69
  %71 = getelementptr inbounds %struct._NODE, ptr %70, i32 0, i32 0
  %72 = load i32, ptr %71, align 8, !tbaa !9
  %73 = load i32, ptr @iCost, align 4, !tbaa !5
  %74 = load i32, ptr @iDist, align 4, !tbaa !5
  %75 = add nsw i32 %73, %74
  %76 = icmp sgt i32 %72, %75
  br i1 %76, label %77, label %95

77:                                               ; preds = %67, %60
  %78 = load i32, ptr @iDist, align 4, !tbaa !5
  %79 = load i32, ptr @iCost, align 4, !tbaa !5
  %80 = add nsw i32 %78, %79
  %81 = load i32, ptr @i, align 4, !tbaa !5
  %82 = sext i32 %81 to i64
  %83 = getelementptr inbounds [10 x %struct._NODE], ptr @rgnNodes, i64 0, i64 %82
  %84 = getelementptr inbounds %struct._NODE, ptr %83, i32 0, i32 0
  store i32 %80, ptr %84, align 8, !tbaa !9
  %85 = load i32, ptr @iNode, align 4, !tbaa !5
  %86 = load i32, ptr @i, align 4, !tbaa !5
  %87 = sext i32 %86 to i64
  %88 = getelementptr inbounds [10 x %struct._NODE], ptr @rgnNodes, i64 0, i64 %87
  %89 = getelementptr inbounds %struct._NODE, ptr %88, i32 0, i32 1
  store i32 %85, ptr %89, align 4, !tbaa !11
  %90 = load i32, ptr @i, align 4, !tbaa !5
  %91 = load i32, ptr @iDist, align 4, !tbaa !5
  %92 = load i32, ptr @iCost, align 4, !tbaa !5
  %93 = add nsw i32 %91, %92
  %94 = load i32, ptr @iNode, align 4, !tbaa !5
  call void @enqueue(i32 noundef %90, i32 noundef %93, i32 noundef %94)
  br label %95

95:                                               ; preds = %77, %67
  br label %96

96:                                               ; preds = %95, %50
  br label %97

97:                                               ; preds = %96
  %98 = load i32, ptr @i, align 4, !tbaa !5
  %99 = add nsw i32 %98, 1
  store i32 %99, ptr @i, align 4, !tbaa !5
  br label %47, !llvm.loop !16

100:                                              ; preds = %47
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #2
  br label %37, !llvm.loop !17

101:                                              ; preds = %37
  br label %102

102:                                              ; preds = %101
  %103 = load i32, ptr %5, align 4, !tbaa !5
  %104 = sext i32 %103 to i64
  %105 = getelementptr inbounds [10 x %struct._NODE], ptr @rgnNodes, i64 0, i64 %104
  %106 = getelementptr inbounds %struct._NODE, ptr %105, i32 0, i32 0
  %107 = load i32, ptr %106, align 8, !tbaa !9
  store i32 %107, ptr %3, align 4
  br label %108

108:                                              ; preds = %102, %26
  %109 = load i32, ptr %3, align 4
  ret i32 %109
}

; Function Attrs: nounwind uwtable
declare hidden void @qfree_beebs(ptr noundef) #0

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 = !{!10, !6, i64 0}
!10 = !{!"_NODE", !6, i64 0, !6, i64 4}
!11 = !{!10, !6, i64 4}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = !{!15, !15, i64 0}
!15 = !{!"any pointer", !7, i64 0}
!16 = distinct !{!16, !13}
!17 = distinct !{!17, !13}


; 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._NODE = type { i32, i32 }

@AdjMatrix = external dso_local local_unnamed_addr global [10 x [10 x i32]], align 16
@ch = external dso_local local_unnamed_addr global i32, align 4
@rgnNodes = external dso_local local_unnamed_addr global [10 x %struct._NODE], align 16
@iNode = external dso_local global i32, align 4
@iDist = external dso_local global i32, align 4
@iPrev = external dso_local global i32, align 4
@i = external dso_local local_unnamed_addr global i32, align 4
@iCost = external dso_local local_unnamed_addr global i32, align 4

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

; Function Attrs: nounwind uwtable
declare dso_local ptr @dequeue(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local i32 @qcount() local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local i32 @dijkstra(i32 noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  store <4 x i32> <i32 9999, i32 9999, i32 9999, i32 9999>, ptr @rgnNodes, align 16, !tbaa !5
  store <4 x i32> <i32 9999, i32 9999, i32 9999, i32 9999>, ptr getelementptr inbounds (i8, ptr @rgnNodes, i64 16), align 16, !tbaa !5
  store <4 x i32> <i32 9999, i32 9999, i32 9999, i32 9999>, ptr getelementptr inbounds (i8, ptr @rgnNodes, i64 32), align 16, !tbaa !5
  store <4 x i32> <i32 9999, i32 9999, i32 9999, i32 9999>, ptr getelementptr inbounds (i8, ptr @rgnNodes, i64 48), align 16, !tbaa !5
  store <4 x i32> <i32 9999, i32 9999, i32 9999, i32 9999>, ptr getelementptr inbounds (i8, ptr @rgnNodes, i64 64), align 16, !tbaa !5
  store i32 10, ptr @ch, align 4, !tbaa !5
  %3 = icmp eq i32 %0, %1
  br i1 %3, label %35, label %4

4:                                                ; preds = %2
  %5 = sext i32 %0 to i64
  %6 = getelementptr inbounds [10 x %struct._NODE], ptr @rgnNodes, i64 0, i64 %5
  store i32 0, ptr %6, align 8, !tbaa !9
  %7 = getelementptr inbounds i8, ptr %6, i64 4
  store i32 9999, ptr %7, align 4, !tbaa !11
  tail call void @enqueue(i32 noundef %0, i32 noundef 0, i32 noundef 9999)
  %8 = tail call i32 @qcount()
  %9 = icmp sgt i32 %8, 0
  br i1 %9, label %.lr.ph, label %._crit_edge

.loopexit:                                        ; preds = %27
  %10 = tail call i32 @qcount()
  %11 = icmp sgt i32 %10, 0
  br i1 %11, label %.lr.ph, label %._crit_edge, !llvm.loop !12

.lr.ph:                                           ; preds = %4, %.loopexit
  %12 = tail call ptr @dequeue(ptr noundef nonnull @iNode, ptr noundef nonnull @iDist, ptr noundef nonnull @iPrev)
  %.not = icmp eq ptr %12, null
  br i1 %.not, label %14, label %13

13:                                               ; preds = %.lr.ph
  tail call void @qfree_beebs(ptr noundef nonnull %12)
  br label %14

14:                                               ; preds = %13, %.lr.ph
  store i32 0, ptr @i, align 4, !tbaa !5
  %.pre20 = load i32, ptr @iNode, align 4, !tbaa !5
  br label %15

15:                                               ; preds = %14, %27
  %16 = phi i32 [ %.pre20, %14 ], [ %29, %27 ]
  %storemerge1518 = phi i32 [ 0, %14 ], [ %30, %27 ]
  %17 = sext i32 %16 to i64
  %18 = sext i32 %storemerge1518 to i64
  %19 = getelementptr inbounds [10 x [10 x i32]], ptr @AdjMatrix, i64 0, i64 %17, i64 %18
  %20 = load i32, ptr %19, align 4, !tbaa !5
  store i32 %20, ptr @iCost, align 4, !tbaa !5
  %.not16 = icmp eq i32 %20, 9999
  br i1 %.not16, label %27, label %21

21:                                               ; preds = %15
  %22 = getelementptr inbounds [10 x %struct._NODE], ptr @rgnNodes, i64 0, i64 %18
  %23 = load i32, ptr %22, align 8, !tbaa !9
  %24 = icmp eq i32 %23, 9999
  %.pre21 = load i32, ptr @iDist, align 4, !tbaa !5
  %.pre24 = add nsw i32 %.pre21, %20
  %25 = icmp sgt i32 %23, %.pre24
  %or.cond = select i1 %24, i1 true, i1 %25
  br i1 %or.cond, label %._crit_edge23, label %27

._crit_edge23:                                    ; preds = %21
  store i32 %.pre24, ptr %22, align 8, !tbaa !9
  %26 = getelementptr inbounds [10 x %struct._NODE], ptr @rgnNodes, i64 0, i64 %18, i32 1
  store i32 %16, ptr %26, align 4, !tbaa !11
  tail call void @enqueue(i32 noundef %storemerge1518, i32 noundef %.pre24, i32 noundef %16)
  %.pre = load i32, ptr @iNode, align 4, !tbaa !5
  %.pre22 = load i32, ptr @i, align 4, !tbaa !5
  br label %27

27:                                               ; preds = %21, %15, %._crit_edge23
  %28 = phi i32 [ %storemerge1518, %15 ], [ %.pre22, %._crit_edge23 ], [ %storemerge1518, %21 ]
  %29 = phi i32 [ %16, %15 ], [ %.pre, %._crit_edge23 ], [ %16, %21 ]
  %30 = add nsw i32 %28, 1
  store i32 %30, ptr @i, align 4, !tbaa !5
  %31 = icmp slt i32 %28, 9
  br i1 %31, label %15, label %.loopexit, !llvm.loop !14

._crit_edge:                                      ; preds = %.loopexit, %4
  %32 = sext i32 %1 to i64
  %33 = getelementptr inbounds [10 x %struct._NODE], ptr @rgnNodes, i64 0, i64 %32
  %34 = load i32, ptr %33, align 8, !tbaa !9
  br label %35

35:                                               ; preds = %2, %._crit_edge
  %.0 = phi i32 [ %34, %._crit_edge ], [ 0, %2 ]
  ret i32 %.0
}

; Function Attrs: nounwind uwtable
declare hidden void @qfree_beebs(ptr noundef) local_unnamed_addr #0

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, !6, i64 0}
!6 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !6, i64 0}
!10 = !{!"_NODE", !6, i64 0, !6, i64 4}
!11 = !{!10, !6, i64 4}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = distinct !{!14, !13}


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