; LLVM IR from lfarcaro/ARINC653_ARMV7A_Z7000 :: ARINC653_ARMV7A_Z7000.sw/MEASURE/src/Algorithms (algorithm_dijkstra1)

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

@algorithm_dijkstra1_checksum = external dso_local global i32, align 4
@algorithm_dijkstra1_queueNext = external dso_local global i32, align 4
@algorithm_dijkstra1_rgnNodes = external dso_local global [50 x %struct._NODE], 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
declare dso_local i32 @algorithm_dijkstra1_find(i32 noundef, i32 noundef) #1

; Function Attrs: nounwind uwtable
define dso_local void @ALGORITHM_DIJKSTRA1_EXECUTE() #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
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #2
  store i32 0, ptr %1, align 4, !tbaa !5
  store i32 25, ptr %2, align 4, !tbaa !5
  br label %4

4:                                                ; preds = %26, %0
  %5 = load i32, ptr %1, align 4, !tbaa !5
  %6 = icmp slt i32 %5, 20
  br i1 %6, label %7, label %31

7:                                                ; preds = %4
  %8 = load i32, ptr %2, align 4, !tbaa !5
  %9 = srem i32 %8, 50
  store i32 %9, ptr %2, align 4, !tbaa !5
  %10 = load i32, ptr %1, align 4, !tbaa !5
  %11 = load i32, ptr %2, align 4, !tbaa !5
  %12 = call i32 @algorithm_dijkstra1_find(i32 noundef %10, i32 noundef %11)
  %13 = icmp eq i32 %12, -1
  br i1 %13, label %14, label %17

14:                                               ; preds = %7
  %15 = load i32, ptr @algorithm_dijkstra1_checksum, align 4, !tbaa !5
  %16 = add nsw i32 %15, -1
  store i32 %16, ptr @algorithm_dijkstra1_checksum, align 4, !tbaa !5
  store i32 1, ptr %3, align 4
  br label %32

17:                                               ; preds = %7
  %18 = load i32, ptr %2, align 4, !tbaa !5
  %19 = sext i32 %18 to i64
  %20 = getelementptr inbounds [50 x %struct._NODE], ptr @algorithm_dijkstra1_rgnNodes, i64 0, i64 %19
  %21 = getelementptr inbounds %struct._NODE, ptr %20, i32 0, i32 0
  %22 = load i32, ptr %21, align 8, !tbaa !9
  %23 = load i32, ptr @algorithm_dijkstra1_checksum, align 4, !tbaa !5
  %24 = add nsw i32 %23, %22
  store i32 %24, ptr @algorithm_dijkstra1_checksum, align 4, !tbaa !5
  br label %25

25:                                               ; preds = %17
  store i32 0, ptr @algorithm_dijkstra1_queueNext, align 4, !tbaa !5
  br label %26

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

31:                                               ; preds = %4
  store i32 0, ptr %3, align 4
  br label %32

32:                                               ; preds = %31, %14
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %1) #2
  %33 = load i32, ptr %3, align 4
  switch i32 %33, label %35 [
    i32 0, label %34
    i32 1, label %34
  ]

34:                                               ; preds = %32, %32
  ret void

35:                                               ; preds = %32
  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 = !{!"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 = distinct !{!11, !12}
!12 = !{!"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"

%struct._NODE = type { i32, i32 }

@algorithm_dijkstra1_checksum = external dso_local local_unnamed_addr global i32, align 4
@algorithm_dijkstra1_queueNext = external dso_local local_unnamed_addr global i32, align 4
@algorithm_dijkstra1_rgnNodes = external dso_local local_unnamed_addr global [50 x %struct._NODE], align 16

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

; Function Attrs: nounwind uwtable
define dso_local void @ALGORITHM_DIJKSTRA1_EXECUTE() local_unnamed_addr #0 {
  br label %1

1:                                                ; preds = %0, %8
  %.09 = phi i32 [ 25, %0 ], [ %15, %8 ]
  %.078 = phi i32 [ 0, %0 ], [ %14, %8 ]
  %2 = srem i32 %.09, 50
  %3 = tail call i32 @algorithm_dijkstra1_find(i32 noundef %.078, i32 noundef %2)
  %4 = icmp eq i32 %3, -1
  br i1 %4, label %5, label %8

5:                                                ; preds = %1
  %6 = load i32, ptr @algorithm_dijkstra1_checksum, align 4, !tbaa !5
  %7 = add nsw i32 %6, -1
  store i32 %7, ptr @algorithm_dijkstra1_checksum, align 4, !tbaa !5
  br label %.loopexit

8:                                                ; preds = %1
  %9 = sext i32 %2 to i64
  %10 = getelementptr inbounds [50 x %struct._NODE], ptr @algorithm_dijkstra1_rgnNodes, i64 0, i64 %9
  %11 = load i32, ptr %10, align 8, !tbaa !9
  %12 = load i32, ptr @algorithm_dijkstra1_checksum, align 4, !tbaa !5
  %13 = add nsw i32 %12, %11
  store i32 %13, ptr @algorithm_dijkstra1_checksum, align 4, !tbaa !5
  store i32 0, ptr @algorithm_dijkstra1_queueNext, align 4, !tbaa !5
  %14 = add nuw nsw i32 %.078, 1
  %15 = add nsw i32 %2, 1
  %exitcond.not = icmp eq i32 %14, 20
  br i1 %exitcond.not, label %.loopexit, label %1, !llvm.loop !11

.loopexit:                                        ; preds = %8, %5
  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, !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 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}


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