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

; 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._PROCESS_INFORMATION_TYPE = type { ptr, ptr, i32, i32, i32, i64, i64, i64, i64, i64, %struct._CONTEXT_TYPE, %struct._priorityqueueENTRY, %struct._priorityqueueENTRY, %struct._priorityqueueENTRY, %struct._priorityqueueENTRY, i8, i8, ptr, i32, ptr, ptr }

@CORE_MODULE_INFORMATION = external global [2 x %struct._MODULE_INFORMATION_TYPE], align 16
@CORE_CURRENT_CONTEXT = external global [2 x ptr], 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 void @EXIT_CORE() #1

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

declare i32 @PORT_GETCORE() #1

; Function Attrs: nounwind uwtable
declare dso_local void @RAISE_ERROR(i8 noundef zeroext, i8 noundef zeroext, i8 noundef zeroext, i32 noundef, i32 noundef, i32 noundef, ptr noundef, i32 noundef, i32 noundef, ptr noundef, ptr noundef) #2

; Function Attrs: nounwind uwtable
define dso_local void @RAISE_APPLICATION_ERROR(i32 noundef %0, ptr noundef %1, i32 noundef %2, ptr noundef %3) #2 {
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca i8, align 1
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  store i32 %0, ptr %5, align 4, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !9
  store i32 %2, ptr %7, align 4, !tbaa !5
  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 8, ptr %11) #3
  call void @llvm.lifetime.start.p0(i64 1, ptr %12) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #3
  %15 = call i32 @PORT_GETCORE()
  %16 = zext i32 %15 to i64
  %17 = getelementptr inbounds [2 x %struct._MODULE_INFORMATION_TYPE], ptr @CORE_MODULE_INFORMATION, i64 0, i64 %16
  store ptr %17, ptr %9, align 8, !tbaa !9
  %18 = call i32 @PORT_GETCORE()
  %19 = zext i32 %18 to i64
  %20 = getelementptr inbounds [2 x ptr], ptr @CORE_CURRENT_CONTEXT, i64 0, i64 %19
  %21 = load ptr, ptr %20, align 8, !tbaa !9
  store ptr %21, ptr %10, align 8, !tbaa !9
  call void asm sideeffect "\09STMFD SP!, {LR}", "~{dirflag},~{fpsr},~{flags}"() #3, !srcloc !11
  %22 = call ptr @PORT_GETCALLADDRESS()
  store ptr %22, ptr %11, align 8, !tbaa !9
  call void @ENTER_CORE()
  %23 = load i32, ptr %5, align 4, !tbaa !5
  %24 = icmp ne i32 %23, 2
  br i1 %24, label %25, label %27

25:                                               ; preds = %4
  %26 = load ptr, ptr %8, align 8, !tbaa !9
  store i32 4, ptr %26, align 4, !tbaa !5
  call void @EXIT_CORE()
  store i32 1, ptr %14, align 4
  br label %67

27:                                               ; preds = %4
  %28 = load ptr, ptr %9, align 8, !tbaa !9
  %29 = getelementptr inbounds %struct._MODULE_INFORMATION_TYPE, ptr %28, i32 0, i32 8
  %30 = load ptr, ptr %29, align 8, !tbaa !12
  %31 = icmp ne ptr %30, null
  br i1 %31, label %32, label %55

32:                                               ; preds = %27
  %33 = load ptr, ptr %9, align 8, !tbaa !9
  %34 = getelementptr inbounds %struct._MODULE_INFORMATION_TYPE, ptr %33, i32 0, i32 8
  %35 = load ptr, ptr %34, align 8, !tbaa !12
  %36 = getelementptr inbounds %struct._PARTITION_INFORMATION_TYPE, ptr %35, i32 0, i32 9
  %37 = getelementptr inbounds %struct._CONTEXT_TYPE, ptr %36, i32 0, i32 5
  %38 = load i8, ptr %37, align 4, !tbaa !19
  store i8 %38, ptr %12, align 1, !tbaa !23
  %39 = load ptr, ptr %9, align 8, !tbaa !9
  %40 = getelementptr inbounds %struct._MODULE_INFORMATION_TYPE, ptr %39, i32 0, i32 8
  %41 = load ptr, ptr %40, align 8, !tbaa !12
  %42 = getelementptr inbounds %struct._PARTITION_INFORMATION_TYPE, ptr %41, i32 0, i32 12
  %43 = load ptr, ptr %42, align 8, !tbaa !24
  %44 = icmp ne ptr %43, null
  br i1 %44, label %45, label %53

45:                                               ; preds = %32
  %46 = load ptr, ptr %9, align 8, !tbaa !9
  %47 = getelementptr inbounds %struct._MODULE_INFORMATION_TYPE, ptr %46, i32 0, i32 8
  %48 = load ptr, ptr %47, align 8, !tbaa !12
  %49 = getelementptr inbounds %struct._PARTITION_INFORMATION_TYPE, ptr %48, i32 0, i32 12
  %50 = load ptr, ptr %49, align 8, !tbaa !24
  %51 = getelementptr inbounds %struct._PROCESS_INFORMATION_TYPE, ptr %50, i32 0, i32 2
  %52 = load i32, ptr %51, align 8, !tbaa !25
  store i32 %52, ptr %13, align 4, !tbaa !5
  br label %54

53:                                               ; preds = %32
  store i32 -1, ptr %13, align 4, !tbaa !5
  br label %54

54:                                               ; preds = %53, %45
  br label %56

55:                                               ; preds = %27
  store i8 0, ptr %12, align 1, !tbaa !23
  store i32 -1, ptr %13, align 4, !tbaa !5
  br label %56

56:                                               ; preds = %55, %54
  %57 = load i8, ptr %12, align 1, !tbaa !23
  %58 = load ptr, ptr %10, align 8, !tbaa !9
  %59 = getelementptr inbounds %struct._CONTEXT_TYPE, ptr %58, i32 0, i32 10
  %60 = load i32, ptr %59, align 8, !tbaa !27
  %61 = load i32, ptr %5, align 4, !tbaa !5
  %62 = load ptr, ptr %6, align 8, !tbaa !9
  %63 = load i32, ptr %7, align 4, !tbaa !5
  %64 = load i32, ptr %13, align 4, !tbaa !5
  %65 = load ptr, ptr %11, align 8, !tbaa !9
  %66 = load ptr, ptr %8, align 8, !tbaa !9
  call void @RAISE_ERROR(i8 noundef zeroext 1, i8 noundef zeroext 1, i8 noundef zeroext %57, i32 noundef %60, i32 noundef 2, i32 noundef %61, ptr noundef %62, i32 noundef %63, i32 noundef %64, ptr noundef %65, ptr noundef %66)
  call void @EXIT_CORE()
  store i32 0, ptr %14, align 4
  br label %67

67:                                               ; preds = %56, %25
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #3
  call void @llvm.lifetime.end.p0(i64 1, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 8, 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
  %68 = load i32, ptr %14, 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
}

declare ptr @PORT_GETCALLADDRESS() #1

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 = !{!"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 = !{i64 2148045812}
!12 = !{!13, !10, i64 136}
!13 = !{!"_MODULE_INFORMATION_TYPE", !10, i64 0, !14, i64 8, !6, i64 32, !6, i64 36, !6, i64 40, !15, i64 48, !6, i64 120, !10, i64 128, !10, i64 136, !16, i64 144, !17, i64 256, !17, i64 264, !17, i64 272, !18, i64 280}
!14 = !{!"_heapRECORD", !10, i64 0, !6, i64 8, !6, i64 12, !6, i64 16}
!15 = !{!"_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}
!16 = !{!"_HEALTHMONITORINGCALLBACK_INFORMATION_TYPE", !7, i64 0, !10, i64 8, !6, i64 16, !15, i64 24, !7, i64 96, !7, i64 97, !7, i64 98, !7, i64 99, !6, i64 100, !6, i64 104}
!17 = !{!"long long", !7, i64 0}
!18 = !{!"_priorityqueueRECORD", !10, i64 0, !6, i64 8, !7, i64 12, !7, i64 13}
!19 = !{!20, !7, i64 108}
!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, !14, i64 48, !15, i64 72, !6, i64 144, !10, i64 152, !10, i64 160, !21, i64 168, !16, i64 272, !6, i64 384, !22, i64 392, !18, i64 432, !18, i64 448, !18, 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, !15, i64 24, !7, i64 96, !7, i64 97, !7, i64 98, !7, i64 99, !6, i64 100}
!22 = !{!"_priorityqueueENTRY", !17, i64 0, !17, i64 8, !10, i64 16, !10, i64 24, !10, i64 32}
!23 = !{!7, !7, i64 0}
!24 = !{!20, !10, i64 160}
!25 = !{!26, !6, i64 16}
!26 = !{!"_PROCESS_INFORMATION_TYPE", !10, i64 0, !10, i64 8, !6, i64 16, !6, i64 20, !6, i64 24, !17, i64 32, !17, i64 40, !17, i64 48, !17, i64 56, !17, i64 64, !15, i64 72, !22, i64 144, !22, i64 184, !22, i64 224, !22, i64 264, !7, i64 304, !7, i64 305, !10, i64 312, !6, i64 320, !10, i64 328, !10, i64 336}
!27 = !{!15, !6, i64 64}


; 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
@CORE_CURRENT_CONTEXT = external local_unnamed_addr global [2 x ptr], align 16

declare void @ENTER_CORE() local_unnamed_addr #0

declare void @EXIT_CORE() local_unnamed_addr #0

declare i32 @PORT_GETCORE() local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local void @RAISE_ERROR(i8 noundef zeroext, i8 noundef zeroext, i8 noundef zeroext, i32 noundef, i32 noundef, i32 noundef, ptr noundef, i32 noundef, i32 noundef, ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local void @RAISE_APPLICATION_ERROR(i32 noundef %0, ptr noundef %1, i32 noundef %2, ptr noundef %3) local_unnamed_addr #1 {
  %5 = tail call i32 @PORT_GETCORE() #2
  %6 = tail call i32 @PORT_GETCORE() #2
  %7 = zext i32 %6 to i64
  %8 = getelementptr inbounds [2 x ptr], ptr @CORE_CURRENT_CONTEXT, i64 0, i64 %7
  %9 = load ptr, ptr %8, align 8, !tbaa !5
  tail call void asm sideeffect "\09STMFD SP!, {LR}", "~{dirflag},~{fpsr},~{flags}"() #2, !srcloc !9
  %10 = tail call ptr @PORT_GETCALLADDRESS() #2
  tail call void @ENTER_CORE() #2
  %.not = icmp eq i32 %0, 2
  br i1 %.not, label %12, label %11

11:                                               ; preds = %4
  store i32 4, ptr %3, align 4, !tbaa !10
  br label %27

12:                                               ; preds = %4
  %13 = zext i32 %5 to i64
  %14 = getelementptr inbounds [2 x %struct._MODULE_INFORMATION_TYPE], ptr @CORE_MODULE_INFORMATION, i64 0, i64 %13, i32 8
  %15 = load ptr, ptr %14, align 8, !tbaa !12
  %.not17 = icmp eq ptr %15, null
  br i1 %.not17, label %24, label %16

16:                                               ; preds = %12
  %17 = getelementptr inbounds i8, ptr %15, i64 108
  %18 = load i8, ptr %17, align 4, !tbaa !19
  %19 = getelementptr inbounds i8, ptr %15, i64 160
  %20 = load ptr, ptr %19, align 8, !tbaa !23
  %.not18 = icmp eq ptr %20, null
  br i1 %.not18, label %24, label %21

21:                                               ; preds = %16
  %22 = getelementptr inbounds i8, ptr %20, i64 16
  %23 = load i32, ptr %22, align 8, !tbaa !24
  br label %24

24:                                               ; preds = %12, %16, %21
  %.013 = phi i8 [ %18, %21 ], [ %18, %16 ], [ 0, %12 ]
  %.0 = phi i32 [ %23, %21 ], [ -1, %16 ], [ -1, %12 ]
  %25 = getelementptr inbounds i8, ptr %9, i64 64
  %26 = load i32, ptr %25, align 8, !tbaa !26
  tail call void @RAISE_ERROR(i8 noundef zeroext 1, i8 noundef zeroext 1, i8 noundef zeroext %.013, i32 noundef %26, i32 noundef 2, i32 noundef 2, ptr noundef %1, i32 noundef %2, i32 noundef %.0, ptr noundef %10, ptr noundef %3)
  br label %27

27:                                               ; preds = %24, %11
  tail call void @EXIT_CORE() #2
  ret void
}

declare ptr @PORT_GETCALLADDRESS() local_unnamed_addr #0

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, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{i64 2148045812}
!10 = !{!11, !11, i64 0}
!11 = !{!"int", !7, i64 0}
!12 = !{!13, !6, i64 136}
!13 = !{!"_MODULE_INFORMATION_TYPE", !6, i64 0, !14, i64 8, !11, i64 32, !11, i64 36, !11, i64 40, !15, i64 48, !11, i64 120, !6, i64 128, !6, i64 136, !16, i64 144, !17, i64 256, !17, i64 264, !17, i64 272, !18, i64 280}
!14 = !{!"_heapRECORD", !6, i64 0, !11, i64 8, !11, i64 12, !11, i64 16}
!15 = !{!"_CONTEXT_TYPE", !11, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !11, i64 32, !7, i64 36, !6, i64 40, !6, i64 48, !11, i64 56, !11, i64 60, !11, i64 64, !11, i64 68}
!16 = !{!"_HEALTHMONITORINGCALLBACK_INFORMATION_TYPE", !7, i64 0, !6, i64 8, !11, i64 16, !15, i64 24, !7, i64 96, !7, i64 97, !7, i64 98, !7, i64 99, !11, i64 100, !11, i64 104}
!17 = !{!"long long", !7, i64 0}
!18 = !{!"_priorityqueueRECORD", !6, i64 0, !11, i64 8, !7, i64 12, !7, i64 13}
!19 = !{!20, !7, i64 108}
!20 = !{!"_PARTITION_INFORMATION_TYPE", !7, i64 0, !6, i64 8, !6, i64 16, !11, i64 24, !11, i64 28, !11, i64 32, !11, i64 36, !7, i64 40, !14, i64 48, !15, i64 72, !11, i64 144, !6, i64 152, !6, i64 160, !21, i64 168, !16, i64 272, !11, i64 384, !22, i64 392, !18, i64 432, !18, i64 448, !18, i64 464, !11, i64 480, !11, i64 484, !6, i64 488, !11, i64 496, !6, i64 504, !11, i64 512, !6, i64 520, !11, i64 528, !6, i64 536, !11, i64 544, !6, i64 552, !11, i64 560, !6, i64 568, !11, i64 576, !6, i64 584}
!21 = !{!"_ERRORHANDLER_INFORMATION_TYPE", !7, i64 0, !6, i64 8, !11, i64 16, !15, i64 24, !7, i64 96, !7, i64 97, !7, i64 98, !7, i64 99, !11, i64 100}
!22 = !{!"_priorityqueueENTRY", !17, i64 0, !17, i64 8, !6, i64 16, !6, i64 24, !6, i64 32}
!23 = !{!20, !6, i64 160}
!24 = !{!25, !11, i64 16}
!25 = !{!"_PROCESS_INFORMATION_TYPE", !6, i64 0, !6, i64 8, !11, i64 16, !11, i64 20, !11, i64 24, !17, i64 32, !17, i64 40, !17, i64 48, !17, i64 56, !17, i64 64, !15, i64 72, !22, i64 144, !22, i64 184, !22, i64 224, !22, i64 264, !7, i64 304, !7, i64 305, !6, i64 312, !11, i64 320, !6, i64 328, !6, i64 336}
!26 = !{!15, !11, i64 64}


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