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

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

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

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

declare void @ENTER_CORE() #1

declare i32 @PORT_GETCORE() #1

declare void @EXIT_CORE() #1

declare void @PORT_YIELD() #1

; 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 void @UNLOCK_PREEMPTION(ptr noundef %0, ptr noundef %1) #2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  call void @ENTER_CORE()
  %7 = call i32 @PORT_GETCORE()
  %8 = zext i32 %7 to i64
  %9 = getelementptr inbounds [2 x %struct._MODULE_INFORMATION_TYPE], ptr @CORE_MODULE_INFORMATION, i64 0, i64 %8
  store ptr %9, ptr %5, align 8, !tbaa !5
  %10 = load ptr, ptr %5, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct._MODULE_INFORMATION_TYPE, ptr %10, i32 0, i32 8
  %12 = load ptr, ptr %11, align 8, !tbaa !9
  %13 = icmp eq ptr %12, null
  br i1 %13, label %14, label %16

14:                                               ; preds = %2
  %15 = load ptr, ptr %4, align 8, !tbaa !5
  store i32 6, ptr %15, align 4, !tbaa !17
  call void @EXIT_CORE()
  store i32 1, ptr %6, align 4
  br label %67

16:                                               ; preds = %2
  %17 = load ptr, ptr %5, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct._MODULE_INFORMATION_TYPE, ptr %17, i32 0, i32 8
  %19 = load ptr, ptr %18, align 8, !tbaa !9
  %20 = getelementptr inbounds %struct._PARTITION_INFORMATION_TYPE, ptr %19, i32 0, i32 4
  %21 = load i32, ptr %20, align 4, !tbaa !18
  %22 = icmp ne i32 %21, 4
  br i1 %22, label %39, label %23

23:                                               ; preds = %16
  %24 = load ptr, ptr %5, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct._MODULE_INFORMATION_TYPE, ptr %24, i32 0, i32 8
  %26 = load ptr, ptr %25, align 8, !tbaa !9
  %27 = getelementptr inbounds %struct._PARTITION_INFORMATION_TYPE, ptr %26, i32 0, i32 6
  %28 = load i32, ptr %27, align 4, !tbaa !22
  %29 = icmp eq i32 %28, 0
  br i1 %29, label %39, label %30

30:                                               ; preds = %23
  %31 = load ptr, ptr %5, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct._MODULE_INFORMATION_TYPE, ptr %31, i32 0, i32 8
  %33 = load ptr, ptr %32, align 8, !tbaa !9
  %34 = getelementptr inbounds %struct._PARTITION_INFORMATION_TYPE, ptr %33, i32 0, i32 13
  %35 = getelementptr inbounds %struct._ERRORHANDLER_INFORMATION_TYPE, ptr %34, i32 0, i32 7
  %36 = load i8, ptr %35, align 1, !tbaa !23
  %37 = zext i8 %36 to i32
  %38 = icmp ne i32 %37, 0
  br i1 %38, label %39, label %41

39:                                               ; preds = %30, %23, %16
  %40 = load ptr, ptr %4, align 8, !tbaa !5
  store i32 2, ptr %40, align 4, !tbaa !17
  call void @EXIT_CORE()
  store i32 1, ptr %6, align 4
  br label %67

41:                                               ; preds = %30
  %42 = load ptr, ptr %5, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct._MODULE_INFORMATION_TYPE, ptr %42, i32 0, i32 8
  %44 = load ptr, ptr %43, align 8, !tbaa !9
  %45 = getelementptr inbounds %struct._PARTITION_INFORMATION_TYPE, ptr %44, i32 0, i32 6
  %46 = load i32, ptr %45, align 4, !tbaa !22
  %47 = sub i32 %46, 1
  %48 = load ptr, ptr %5, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct._MODULE_INFORMATION_TYPE, ptr %48, i32 0, i32 8
  %50 = load ptr, ptr %49, align 8, !tbaa !9
  %51 = getelementptr inbounds %struct._PARTITION_INFORMATION_TYPE, ptr %50, i32 0, i32 6
  store i32 %47, ptr %51, align 4, !tbaa !22
  %52 = load ptr, ptr %5, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct._MODULE_INFORMATION_TYPE, ptr %52, i32 0, i32 8
  %54 = load ptr, ptr %53, align 8, !tbaa !9
  %55 = getelementptr inbounds %struct._PARTITION_INFORMATION_TYPE, ptr %54, i32 0, i32 6
  %56 = load i32, ptr %55, align 4, !tbaa !22
  %57 = load ptr, ptr %3, align 8, !tbaa !5
  store i32 %56, ptr %57, align 4, !tbaa !17
  %58 = load ptr, ptr %5, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct._MODULE_INFORMATION_TYPE, ptr %58, i32 0, i32 8
  %60 = load ptr, ptr %59, align 8, !tbaa !9
  %61 = getelementptr inbounds %struct._PARTITION_INFORMATION_TYPE, ptr %60, i32 0, i32 6
  %62 = load i32, ptr %61, align 4, !tbaa !22
  %63 = icmp eq i32 %62, 0
  br i1 %63, label %64, label %65

64:                                               ; preds = %41
  call void @PORT_YIELD()
  br label %65

65:                                               ; preds = %64, %41
  %66 = load ptr, ptr %4, align 8, !tbaa !5
  store i32 1, ptr %66, align 4, !tbaa !17
  call void @EXIT_CORE()
  store i32 0, ptr %6, align 4
  br label %67

67:                                               ; preds = %65, %39, %14
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  %68 = load i32, ptr %6, align 4
  switch i32 %68, label %70 [
    i32 0, label %69
    i32 1, label %69
  ]

69:                                               ; preds = %67, %67
  ret void

70:                                               ; preds = %67
  unreachable
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 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 #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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !6, i64 136}
!10 = !{!"_MODULE_INFORMATION_TYPE", !6, i64 0, !11, i64 8, !12, i64 32, !12, i64 36, !12, i64 40, !13, i64 48, !12, i64 120, !6, i64 128, !6, i64 136, !14, i64 144, !15, i64 256, !15, i64 264, !15, i64 272, !16, i64 280}
!11 = !{!"_heapRECORD", !6, i64 0, !12, i64 8, !12, i64 12, !12, i64 16}
!12 = !{!"int", !7, i64 0}
!13 = !{!"_CONTEXT_TYPE", !12, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !12, i64 32, !7, i64 36, !6, i64 40, !6, i64 48, !12, i64 56, !12, i64 60, !12, i64 64, !12, i64 68}
!14 = !{!"_HEALTHMONITORINGCALLBACK_INFORMATION_TYPE", !7, i64 0, !6, i64 8, !12, i64 16, !13, i64 24, !7, i64 96, !7, i64 97, !7, i64 98, !7, i64 99, !12, i64 100, !12, i64 104}
!15 = !{!"long long", !7, i64 0}
!16 = !{!"_priorityqueueRECORD", !6, i64 0, !12, i64 8, !7, i64 12, !7, i64 13}
!17 = !{!12, !12, i64 0}
!18 = !{!19, !12, i64 28}
!19 = !{!"_PARTITION_INFORMATION_TYPE", !7, i64 0, !6, i64 8, !6, i64 16, !12, i64 24, !12, i64 28, !12, i64 32, !12, i64 36, !7, i64 40, !11, i64 48, !13, i64 72, !12, i64 144, !6, i64 152, !6, i64 160, !20, i64 168, !14, i64 272, !12, i64 384, !21, i64 392, !16, i64 432, !16, i64 448, !16, i64 464, !12, i64 480, !12, i64 484, !6, i64 488, !12, i64 496, !6, i64 504, !12, i64 512, !6, i64 520, !12, i64 528, !6, i64 536, !12, i64 544, !6, i64 552, !12, i64 560, !6, i64 568, !12, i64 576, !6, i64 584}
!20 = !{!"_ERRORHANDLER_INFORMATION_TYPE", !7, i64 0, !6, i64 8, !12, i64 16, !13, i64 24, !7, i64 96, !7, i64 97, !7, i64 98, !7, i64 99, !12, i64 100}
!21 = !{!"_priorityqueueENTRY", !15, i64 0, !15, i64 8, !6, i64 16, !6, i64 24, !6, i64 32}
!22 = !{!19, !12, i64 36}
!23 = !{!19, !7, i64 267}


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

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

declare void @ENTER_CORE() local_unnamed_addr #0

declare i32 @PORT_GETCORE() local_unnamed_addr #0

declare void @EXIT_CORE() local_unnamed_addr #0

declare void @PORT_YIELD() local_unnamed_addr #0

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

8:                                                ; preds = %2
  %9 = getelementptr inbounds i8, ptr %6, i64 28
  %10 = load i32, ptr %9, align 4, !tbaa !16
  %.not = icmp eq i32 %10, 4
  br i1 %.not, label %11, label %23

11:                                               ; preds = %8
  %12 = getelementptr inbounds i8, ptr %6, i64 36
  %13 = load i32, ptr %12, align 4, !tbaa !20
  %14 = icmp eq i32 %13, 0
  br i1 %14, label %23, label %15

15:                                               ; preds = %11
  %16 = getelementptr inbounds i8, ptr %6, i64 267
  %17 = load i8, ptr %16, align 1, !tbaa !21
  %.not13 = icmp eq i8 %17, 0
  br i1 %.not13, label %18, label %23

18:                                               ; preds = %15
  %19 = add i32 %13, -1
  store i32 %19, ptr %12, align 4, !tbaa !20
  store i32 %19, ptr %0, align 4, !tbaa !22
  %20 = load i32, ptr %12, align 4, !tbaa !20
  %21 = icmp eq i32 %20, 0
  br i1 %21, label %22, label %23

22:                                               ; preds = %18
  tail call void @PORT_YIELD() #2
  br label %23

23:                                               ; preds = %18, %22, %8, %11, %15, %2
  %.sink = phi i32 [ 6, %2 ], [ 2, %15 ], [ 2, %11 ], [ 2, %8 ], [ 1, %22 ], [ 1, %18 ]
  store i32 %.sink, ptr %1, align 4, !tbaa !22
  tail call void @EXIT_CORE() #2
  ret void
}

attributes #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 = { 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, !7, i64 136}
!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 = !{!17, !11, i64 28}
!17 = !{!"_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, !18, i64 168, !13, i64 272, !11, i64 384, !19, 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}
!18 = !{!"_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}
!19 = !{!"_priorityqueueENTRY", !14, i64 0, !14, i64 8, !7, i64 16, !7, i64 24, !7, i64 32}
!20 = !{!17, !11, i64 36}
!21 = !{!17, !8, i64 267}
!22 = !{!11, !11, i64 0}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass