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

@algorithm_dijkstra1_queueCount = external dso_local global i32, align 4
@algorithm_dijkstra1_queueNext = external dso_local global i32, align 4
@algorithm_dijkstra1_queueHead = external dso_local global ptr, align 8
@algorithm_dijkstra1_queueItems = external dso_local global [1000 x %struct._QITEM], 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 @algorithm_dijkstra1_enqueue(i32 noundef %0, i32 noundef %1, i32 noundef %2) #1 {
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  store i32 %0, ptr %5, align 4, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !5
  store i32 %2, ptr %7, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #2
  %11 = load i32, ptr @algorithm_dijkstra1_queueNext, align 4, !tbaa !5
  %12 = sext i32 %11 to i64
  %13 = getelementptr inbounds [1000 x %struct._QITEM], ptr @algorithm_dijkstra1_queueItems, i64 0, i64 %12
  store ptr %13, ptr %8, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #2
  %14 = load ptr, ptr @algorithm_dijkstra1_queueHead, align 8, !tbaa !9
  store ptr %14, ptr %9, align 8, !tbaa !9
  %15 = load i32, ptr @algorithm_dijkstra1_queueNext, align 4, !tbaa !5
  %16 = add nsw i32 %15, 1
  store i32 %16, ptr @algorithm_dijkstra1_queueNext, align 4, !tbaa !5
  %17 = icmp sge i32 %16, 1000
  br i1 %17, label %18, label %19

18:                                               ; preds = %3
  store i32 -1, ptr %4, align 4
  store i32 1, ptr %10, align 4
  br label %52

19:                                               ; preds = %3
  %20 = load i32, ptr %5, align 4, !tbaa !5
  %21 = load ptr, ptr %8, align 8, !tbaa !9
  %22 = getelementptr inbounds %struct._QITEM, ptr %21, i32 0, i32 0
  store i32 %20, ptr %22, align 8, !tbaa !11
  %23 = load i32, ptr %6, align 4, !tbaa !5
  %24 = load ptr, ptr %8, align 8, !tbaa !9
  %25 = getelementptr inbounds %struct._QITEM, ptr %24, i32 0, i32 1
  store i32 %23, ptr %25, align 4, !tbaa !13
  %26 = load i32, ptr %7, align 4, !tbaa !5
  %27 = load ptr, ptr %8, align 8, !tbaa !9
  %28 = getelementptr inbounds %struct._QITEM, ptr %27, i32 0, i32 2
  store i32 %26, ptr %28, align 8, !tbaa !14
  %29 = load ptr, ptr %8, align 8, !tbaa !9
  %30 = getelementptr inbounds %struct._QITEM, ptr %29, i32 0, i32 3
  store ptr null, ptr %30, align 8, !tbaa !15
  %31 = load ptr, ptr %9, align 8, !tbaa !9
  %32 = icmp ne ptr %31, null
  br i1 %32, label %35, label %33

33:                                               ; preds = %19
  %34 = load ptr, ptr %8, align 8, !tbaa !9
  store ptr %34, ptr @algorithm_dijkstra1_queueHead, align 8, !tbaa !9
  br label %49

35:                                               ; preds = %19
  br label %36

36:                                               ; preds = %41, %35
  %37 = load ptr, ptr %9, align 8, !tbaa !9
  %38 = getelementptr inbounds %struct._QITEM, ptr %37, i32 0, i32 3
  %39 = load ptr, ptr %38, align 8, !tbaa !15
  %40 = icmp ne ptr %39, null
  br i1 %40, label %41, label %45

41:                                               ; preds = %36
  %42 = load ptr, ptr %9, align 8, !tbaa !9
  %43 = getelementptr inbounds %struct._QITEM, ptr %42, i32 0, i32 3
  %44 = load ptr, ptr %43, align 8, !tbaa !15
  store ptr %44, ptr %9, align 8, !tbaa !9
  br label %36, !llvm.loop !16

45:                                               ; preds = %36
  %46 = load ptr, ptr %8, align 8, !tbaa !9
  %47 = load ptr, ptr %9, align 8, !tbaa !9
  %48 = getelementptr inbounds %struct._QITEM, ptr %47, i32 0, i32 3
  store ptr %46, ptr %48, align 8, !tbaa !15
  br label %49

49:                                               ; preds = %45, %33
  %50 = load i32, ptr @algorithm_dijkstra1_queueCount, align 4, !tbaa !5
  %51 = add nsw i32 %50, 1
  store i32 %51, ptr @algorithm_dijkstra1_queueCount, align 4, !tbaa !5
  store i32 0, ptr %4, align 4
  store i32 1, ptr %10, align 4
  br label %52

52:                                               ; preds = %49, %18
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #2
  %53 = load i32, ptr %4, align 4
  ret i32 %53
}

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, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !6, i64 0}
!12 = !{!"_QITEM", !6, i64 0, !6, i64 4, !6, i64 8, !10, i64 16}
!13 = !{!12, !6, i64 4}
!14 = !{!12, !6, i64 8}
!15 = !{!12, !10, i64 16}
!16 = distinct !{!16, !17}
!17 = !{!"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._QITEM = type { i32, i32, i32, ptr }

@algorithm_dijkstra1_queueCount = 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_queueHead = external dso_local local_unnamed_addr global ptr, align 8
@algorithm_dijkstra1_queueItems = external dso_local global [1000 x %struct._QITEM], align 16

; Function Attrs: nofree norecurse nosync nounwind memory(readwrite, inaccessiblemem: none) uwtable
define dso_local range(i32 -1, 1) i32 @algorithm_dijkstra1_enqueue(i32 noundef %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #0 {
  %4 = load i32, ptr @algorithm_dijkstra1_queueNext, align 4, !tbaa !5
  %5 = sext i32 %4 to i64
  %6 = getelementptr inbounds [1000 x %struct._QITEM], ptr @algorithm_dijkstra1_queueItems, i64 0, i64 %5
  %7 = load ptr, ptr @algorithm_dijkstra1_queueHead, align 8, !tbaa !9
  %8 = add nsw i32 %4, 1
  store i32 %8, ptr @algorithm_dijkstra1_queueNext, align 4, !tbaa !5
  %9 = icmp sgt i32 %4, 998
  br i1 %9, label %21, label %10

10:                                               ; preds = %3
  store i32 %0, ptr %6, align 8, !tbaa !11
  %11 = getelementptr inbounds i8, ptr %6, i64 4
  store i32 %1, ptr %11, align 4, !tbaa !13
  %12 = getelementptr inbounds i8, ptr %6, i64 8
  store i32 %2, ptr %12, align 8, !tbaa !14
  %13 = getelementptr inbounds i8, ptr %6, i64 16
  store ptr null, ptr %13, align 8, !tbaa !15
  %.not = icmp eq ptr %7, null
  br i1 %.not, label %18, label %.preheader

.preheader:                                       ; preds = %10, %.preheader
  %.0 = phi ptr [ %15, %.preheader ], [ %7, %10 ]
  %14 = getelementptr inbounds i8, ptr %.0, i64 16
  %15 = load ptr, ptr %14, align 8, !tbaa !15
  %.not16 = icmp eq ptr %15, null
  br i1 %.not16, label %16, label %.preheader, !llvm.loop !16

16:                                               ; preds = %.preheader
  %17 = getelementptr inbounds i8, ptr %.0, i64 16
  br label %18

18:                                               ; preds = %10, %16
  %.sink = phi ptr [ %17, %16 ], [ @algorithm_dijkstra1_queueHead, %10 ]
  store ptr %6, ptr %.sink, align 8, !tbaa !9
  %19 = load i32, ptr @algorithm_dijkstra1_queueCount, align 4, !tbaa !5
  %20 = add nsw i32 %19, 1
  store i32 %20, ptr @algorithm_dijkstra1_queueCount, align 4, !tbaa !5
  br label %21

21:                                               ; preds = %3, %18
  %.013 = phi i32 [ 0, %18 ], [ -1, %3 ]
  ret i32 %.013
}

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

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


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LICMPass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass