; LLVM IR from lfarcaro/ARINC653_ARMV7A_Z7000 :: ARINC653_ARMV7A_Z7000.sw/ARINC653_ARMV7A_Z7000/src/ARINC653 (ID)

; 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._MODULE_INFORMATION_TYPE = type { ptr, %struct._heapRECORD, i32, i32, i32, %struct._CONTEXT_TYPE, i32, ptr, ptr, %struct._HEALTHMONITORINGCALLBACK_INFORMATION_TYPE, i64, i64, i64, %struct._priorityqueueRECORD }
%struct._heapRECORD = type { ptr, i32, i32, i32 }
%struct._CONTEXT_TYPE = type { i32, ptr, ptr, ptr, i32, i8, ptr, ptr, i32, i32, i32, i32 }
%struct._HEALTHMONITORINGCALLBACK_INFORMATION_TYPE = type { i8, ptr, i32, %struct._CONTEXT_TYPE, i8, i8, i8, i8, i32, i32 }
%struct._priorityqueueRECORD = type { ptr, i32, i8, i8 }
%struct._PARTITION_INFORMATION_TYPE = type { i8, ptr, ptr, i32, i32, i32, i32, i8, %struct._heapRECORD, %struct._CONTEXT_TYPE, i32, ptr, ptr, %struct._ERRORHANDLER_INFORMATION_TYPE, %struct._HEALTHMONITORINGCALLBACK_INFORMATION_TYPE, i32, %struct._priorityqueueENTRY, %struct._priorityqueueRECORD, %struct._priorityqueueRECORD, %struct._priorityqueueRECORD, i32, i32, ptr, i32, ptr, i32, ptr, i32, ptr, i32, ptr, i32, ptr, i32, ptr }
%struct._ERRORHANDLER_INFORMATION_TYPE = type { i8, ptr, i32, %struct._CONTEXT_TYPE, i8, i8, i8, i8, i32 }
%struct._priorityqueueENTRY = type { i64, i64, ptr, ptr, ptr }
%struct._QUEUINGPORT_INFORMATION_TYPE = type { i32, ptr, i32, i32, i32, i32, i32, i32, i8, ptr, ptr, %struct._priorityqueueRECORD }

@CORE_MODULE_INFORMATION = external global [2 x %struct._MODULE_INFORMATION_TYPE], align 16

; Function Attrs: nounwind uwtable
define dso_local void @GET_PARTITION_QUEUING_PORT_ID(i32 noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3) #0 {
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  store i32 %0, ptr %5, align 4, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !9
  store ptr %2, ptr %7, align 8, !tbaa !9
  store ptr %3, ptr %8, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  call void @ENTER_CORE()
  %13 = call i32 @PORT_GETCORE()
  %14 = zext i32 %13 to i64
  %15 = getelementptr inbounds [2 x %struct._MODULE_INFORMATION_TYPE], ptr @CORE_MODULE_INFORMATION, i64 0, i64 %14
  store ptr %15, ptr %9, align 8, !tbaa !9
  %16 = load i32, ptr %5, align 4, !tbaa !5
  %17 = load ptr, ptr %9, align 8, !tbaa !9
  %18 = getelementptr inbounds %struct._MODULE_INFORMATION_TYPE, ptr %17, i32 0, i32 6
  %19 = load i32, ptr %18, align 8, !tbaa !11
  %20 = icmp uge i32 %16, %19
  br i1 %20, label %21, label %23

21:                                               ; preds = %4
  %22 = load ptr, ptr %8, align 8, !tbaa !9
  store i32 4, ptr %22, align 4, !tbaa !5
  call void @EXIT_CORE()
  store i32 1, ptr %12, align 4
  br label %58

23:                                               ; preds = %4
  %24 = load ptr, ptr %9, align 8, !tbaa !9
  %25 = getelementptr inbounds %struct._MODULE_INFORMATION_TYPE, ptr %24, i32 0, i32 7
  %26 = load ptr, ptr %25, align 8, !tbaa !18
  %27 = load i32, ptr %5, align 4, !tbaa !5
  %28 = zext i32 %27 to i64
  %29 = getelementptr inbounds %struct._PARTITION_INFORMATION_TYPE, ptr %26, i64 %28
  store ptr %29, ptr %10, align 8, !tbaa !9
  store i32 0, ptr %11, align 4, !tbaa !5
  br label %30

30:                                               ; preds = %53, %23
  %31 = load i32, ptr %11, align 4, !tbaa !5
  %32 = load ptr, ptr %10, align 8, !tbaa !9
  %33 = getelementptr inbounds %struct._PARTITION_INFORMATION_TYPE, ptr %32, i32 0, i32 25
  %34 = load i32, ptr %33, align 8, !tbaa !19
  %35 = icmp ult i32 %31, %34
  br i1 %35, label %36, label %56

36:                                               ; preds = %30
  %37 = load ptr, ptr %6, align 8, !tbaa !9
  %38 = load ptr, ptr %10, align 8, !tbaa !9
  %39 = getelementptr inbounds %struct._PARTITION_INFORMATION_TYPE, ptr %38, i32 0, i32 26
  %40 = load ptr, ptr %39, align 8, !tbaa !23
  %41 = load i32, ptr %11, align 4, !tbaa !5
  %42 = zext i32 %41 to i64
  %43 = getelementptr inbounds %struct._QUEUINGPORT_INFORMATION_TYPE, ptr %40, i64 %42
  %44 = getelementptr inbounds %struct._QUEUINGPORT_INFORMATION_TYPE, ptr %43, i32 0, i32 1
  %45 = load ptr, ptr %44, align 8, !tbaa !24
  %46 = call zeroext i8 @COMMON_COMPARESTRINGS(ptr noundef %37, ptr noundef %45, i32 noundef 30)
  %47 = icmp ne i8 %46, 0
  br i1 %47, label %48, label %52

48:                                               ; preds = %36
  %49 = load i32, ptr %11, align 4, !tbaa !5
  %50 = load ptr, ptr %7, align 8, !tbaa !9
  store i32 %49, ptr %50, align 4, !tbaa !5
  %51 = load ptr, ptr %8, align 8, !tbaa !9
  store i32 1, ptr %51, align 4, !tbaa !5
  call void @EXIT_CORE()
  store i32 1, ptr %12, align 4
  br label %58

52:                                               ; preds = %36
  br label %53

53:                                               ; preds = %52
  %54 = load i32, ptr %11, align 4, !tbaa !5
  %55 = add i32 %54, 1
  store i32 %55, ptr %11, align 4, !tbaa !5
  br label %30, !llvm.loop !26

56:                                               ; preds = %30
  %57 = load ptr, ptr %8, align 8, !tbaa !9
  store i32 5, ptr %57, align 4, !tbaa !5
  call void @EXIT_CORE()
  store i32 0, ptr %12, align 4
  br label %58

58:                                               ; preds = %56, %48, %21
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  %59 = load i32, ptr %12, align 4
  switch i32 %59, label %61 [
    i32 0, label %60
    i32 1, label %60
  ]

60:                                               ; preds = %58, %58
  ret void

61:                                               ; preds = %58
  unreachable
}

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

declare void @ENTER_CORE() #2

declare i32 @PORT_GETCORE() #2

declare void @EXIT_CORE() #2

declare zeroext i8 @COMMON_COMPARESTRINGS(ptr noundef, ptr noundef, i32 noundef) #2

; 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 = { "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 #3 = { 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 120}
!12 = !{!"_MODULE_INFORMATION_TYPE", !10, i64 0, !13, i64 8, !6, i64 32, !6, i64 36, !6, i64 40, !14, i64 48, !6, i64 120, !10, i64 128, !10, i64 136, !15, i64 144, !16, i64 256, !16, i64 264, !16, i64 272, !17, i64 280}
!13 = !{!"_heapRECORD", !10, i64 0, !6, i64 8, !6, i64 12, !6, i64 16}
!14 = !{!"_CONTEXT_TYPE", !6, i64 0, !10, i64 8, !10, i64 16, !10, i64 24, !6, i64 32, !7, i64 36, !10, i64 40, !10, i64 48, !6, i64 56, !6, i64 60, !6, i64 64, !6, i64 68}
!15 = !{!"_HEALTHMONITORINGCALLBACK_INFORMATION_TYPE", !7, i64 0, !10, i64 8, !6, i64 16, !14, i64 24, !7, i64 96, !7, i64 97, !7, i64 98, !7, i64 99, !6, i64 100, !6, i64 104}
!16 = !{!"long long", !7, i64 0}
!17 = !{!"_priorityqueueRECORD", !10, i64 0, !6, i64 8, !7, i64 12, !7, i64 13}
!18 = !{!12, !10, i64 128}
!19 = !{!20, !6, i64 512}
!20 = !{!"_PARTITION_INFORMATION_TYPE", !7, i64 0, !10, i64 8, !10, i64 16, !6, i64 24, !6, i64 28, !6, i64 32, !6, i64 36, !7, i64 40, !13, i64 48, !14, i64 72, !6, i64 144, !10, i64 152, !10, i64 160, !21, i64 168, !15, i64 272, !6, i64 384, !22, i64 392, !17, i64 432, !17, i64 448, !17, i64 464, !6, i64 480, !6, i64 484, !10, i64 488, !6, i64 496, !10, i64 504, !6, i64 512, !10, i64 520, !6, i64 528, !10, i64 536, !6, i64 544, !10, i64 552, !6, i64 560, !10, i64 568, !6, i64 576, !10, i64 584}
!21 = !{!"_ERRORHANDLER_INFORMATION_TYPE", !7, i64 0, !10, i64 8, !6, i64 16, !14, i64 24, !7, i64 96, !7, i64 97, !7, i64 98, !7, i64 99, !6, i64 100}
!22 = !{!"_priorityqueueENTRY", !16, i64 0, !16, i64 8, !10, i64 16, !10, i64 24, !10, i64 32}
!23 = !{!20, !10, i64 520}
!24 = !{!25, !10, i64 8}
!25 = !{!"_QUEUINGPORT_INFORMATION_TYPE", !6, i64 0, !10, i64 8, !6, i64 16, !6, i64 20, !6, i64 24, !6, i64 28, !6, i64 32, !6, i64 36, !7, i64 40, !10, i64 48, !10, i64 56, !17, i64 64}
!26 = distinct !{!26, !27}
!27 = !{!"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._MODULE_INFORMATION_TYPE = type { ptr, %struct._heapRECORD, i32, i32, i32, %struct._CONTEXT_TYPE, i32, ptr, ptr, %struct._HEALTHMONITORINGCALLBACK_INFORMATION_TYPE, i64, i64, i64, %struct._priorityqueueRECORD }
%struct._heapRECORD = type { ptr, i32, i32, i32 }
%struct._CONTEXT_TYPE = type { i32, ptr, ptr, ptr, i32, i8, ptr, ptr, i32, i32, i32, i32 }
%struct._HEALTHMONITORINGCALLBACK_INFORMATION_TYPE = type { i8, ptr, i32, %struct._CONTEXT_TYPE, i8, i8, i8, i8, i32, i32 }
%struct._priorityqueueRECORD = type { ptr, i32, i8, i8 }
%struct._PARTITION_INFORMATION_TYPE = type { i8, ptr, ptr, i32, i32, i32, i32, i8, %struct._heapRECORD, %struct._CONTEXT_TYPE, i32, ptr, ptr, %struct._ERRORHANDLER_INFORMATION_TYPE, %struct._HEALTHMONITORINGCALLBACK_INFORMATION_TYPE, i32, %struct._priorityqueueENTRY, %struct._priorityqueueRECORD, %struct._priorityqueueRECORD, %struct._priorityqueueRECORD, i32, i32, ptr, i32, ptr, i32, ptr, i32, ptr, i32, ptr, i32, ptr, i32, ptr }
%struct._ERRORHANDLER_INFORMATION_TYPE = type { i8, ptr, i32, %struct._CONTEXT_TYPE, i8, i8, i8, i8, i32 }
%struct._priorityqueueENTRY = type { i64, i64, ptr, ptr, ptr }
%struct._QUEUINGPORT_INFORMATION_TYPE = type { i32, ptr, i32, i32, i32, i32, i32, i32, i8, ptr, ptr, %struct._priorityqueueRECORD }

@CORE_MODULE_INFORMATION = external local_unnamed_addr global [2 x %struct._MODULE_INFORMATION_TYPE], align 16

; Function Attrs: nounwind uwtable
define dso_local void @GET_PARTITION_QUEUING_PORT_ID(i32 noundef %0, ptr noundef %1, ptr nocapture noundef writeonly %2, ptr nocapture noundef writeonly %3) local_unnamed_addr #0 {
  tail call void @ENTER_CORE() #2
  %5 = tail call i32 @PORT_GETCORE() #2
  %6 = zext i32 %5 to i64
  %7 = getelementptr inbounds [2 x %struct._MODULE_INFORMATION_TYPE], ptr @CORE_MODULE_INFORMATION, i64 0, i64 %6
  %8 = getelementptr inbounds i8, ptr %7, i64 120
  %9 = load i32, ptr %8, align 8, !tbaa !5
  %.not = icmp ugt i32 %9, %0
  br i1 %.not, label %10, label %._crit_edge

10:                                               ; preds = %4
  %11 = getelementptr inbounds i8, ptr %7, i64 128
  %12 = load ptr, ptr %11, align 8, !tbaa !16
  %13 = zext i32 %0 to i64
  %14 = getelementptr inbounds %struct._PARTITION_INFORMATION_TYPE, ptr %12, i64 %13
  %15 = getelementptr inbounds i8, ptr %14, i64 512
  %16 = load i32, ptr %15, align 8, !tbaa !17
  %.not18 = icmp eq i32 %16, 0
  br i1 %.not18, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %10
  %17 = getelementptr inbounds i8, ptr %14, i64 520
  br label %18

18:                                               ; preds = %.lr.ph, %25
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %25 ]
  %19 = load ptr, ptr %17, align 8, !tbaa !21
  %20 = getelementptr inbounds %struct._QUEUINGPORT_INFORMATION_TYPE, ptr %19, i64 %indvars.iv, i32 1
  %21 = load ptr, ptr %20, align 8, !tbaa !22
  %22 = tail call zeroext i8 @COMMON_COMPARESTRINGS(ptr noundef %1, ptr noundef %21, i32 noundef 30) #2
  %.not15 = icmp eq i8 %22, 0
  br i1 %.not15, label %25, label %23

23:                                               ; preds = %18
  %24 = trunc nuw i64 %indvars.iv to i32
  store i32 %24, ptr %2, align 4, !tbaa !24
  br label %._crit_edge

25:                                               ; preds = %18
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %26 = load i32, ptr %15, align 8, !tbaa !17
  %27 = zext i32 %26 to i64
  %28 = icmp ult i64 %indvars.iv.next, %27
  br i1 %28, label %18, label %._crit_edge, !llvm.loop !25

._crit_edge:                                      ; preds = %25, %10, %4, %23
  %.sink = phi i32 [ 1, %23 ], [ 4, %4 ], [ 5, %10 ], [ 5, %25 ]
  store i32 %.sink, ptr %3, align 4, !tbaa !24
  tail call void @EXIT_CORE() #2
  ret void
}

declare void @ENTER_CORE() local_unnamed_addr #1

declare i32 @PORT_GETCORE() local_unnamed_addr #1

declare void @EXIT_CORE() local_unnamed_addr #1

declare zeroext i8 @COMMON_COMPARESTRINGS(ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #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 = { "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, !11, i64 120}
!6 = !{!"_MODULE_INFORMATION_TYPE", !7, i64 0, !10, i64 8, !11, i64 32, !11, i64 36, !11, i64 40, !12, i64 48, !11, i64 120, !7, i64 128, !7, i64 136, !13, i64 144, !14, i64 256, !14, i64 264, !14, i64 272, !15, i64 280}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"_heapRECORD", !7, i64 0, !11, i64 8, !11, i64 12, !11, i64 16}
!11 = !{!"int", !8, i64 0}
!12 = !{!"_CONTEXT_TYPE", !11, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !11, i64 32, !8, i64 36, !7, i64 40, !7, i64 48, !11, i64 56, !11, i64 60, !11, i64 64, !11, i64 68}
!13 = !{!"_HEALTHMONITORINGCALLBACK_INFORMATION_TYPE", !8, i64 0, !7, i64 8, !11, i64 16, !12, i64 24, !8, i64 96, !8, i64 97, !8, i64 98, !8, i64 99, !11, i64 100, !11, i64 104}
!14 = !{!"long long", !8, i64 0}
!15 = !{!"_priorityqueueRECORD", !7, i64 0, !11, i64 8, !8, i64 12, !8, i64 13}
!16 = !{!6, !7, i64 128}
!17 = !{!18, !11, i64 512}
!18 = !{!"_PARTITION_INFORMATION_TYPE", !8, i64 0, !7, i64 8, !7, i64 16, !11, i64 24, !11, i64 28, !11, i64 32, !11, i64 36, !8, i64 40, !10, i64 48, !12, i64 72, !11, i64 144, !7, i64 152, !7, i64 160, !19, i64 168, !13, i64 272, !11, i64 384, !20, i64 392, !15, i64 432, !15, i64 448, !15, i64 464, !11, i64 480, !11, i64 484, !7, i64 488, !11, i64 496, !7, i64 504, !11, i64 512, !7, i64 520, !11, i64 528, !7, i64 536, !11, i64 544, !7, i64 552, !11, i64 560, !7, i64 568, !11, i64 576, !7, i64 584}
!19 = !{!"_ERRORHANDLER_INFORMATION_TYPE", !8, i64 0, !7, i64 8, !11, i64 16, !12, i64 24, !8, i64 96, !8, i64 97, !8, i64 98, !8, i64 99, !11, i64 100}
!20 = !{!"_priorityqueueENTRY", !14, i64 0, !14, i64 8, !7, i64 16, !7, i64 24, !7, i64 32}
!21 = !{!18, !7, i64 520}
!22 = !{!23, !7, i64 8}
!23 = !{!"_QUEUINGPORT_INFORMATION_TYPE", !11, i64 0, !7, i64 8, !11, i64 16, !11, i64 20, !11, i64 24, !11, i64 28, !11, i64 32, !11, i64 36, !8, i64 40, !7, i64 48, !7, i64 56, !15, i64 64}
!24 = !{!11, !11, i64 0}
!25 = distinct !{!25, !26}
!26 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass