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

; 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

; Function Attrs: nounwind uwtable
define dso_local void @WAIT_RESOURCE(i32 noundef %0, i32 noundef %1, ptr noundef %2, i64 noundef %3, ptr noundef %4) #0 {
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca i64, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca ptr, align 8
  %14 = alloca i32, align 4
  store i32 %0, ptr %6, align 4, !tbaa !5
  store i32 %1, ptr %7, align 4, !tbaa !5
  store ptr %2, ptr %8, align 8, !tbaa !9
  store i64 %3, ptr %9, align 8, !tbaa !11
  store ptr %4, ptr %10, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #3
  call void @ENTER_CORE()
  %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 %11, align 8, !tbaa !9
  %18 = load i32, ptr %6, align 4, !tbaa !5
  %19 = load ptr, ptr %11, align 8, !tbaa !9
  %20 = getelementptr inbounds %struct._MODULE_INFORMATION_TYPE, ptr %19, i32 0, i32 6
  %21 = load i32, ptr %20, align 8, !tbaa !13
  %22 = icmp uge i32 %18, %21
  br i1 %22, label %23, label %25

23:                                               ; preds = %5
  %24 = load ptr, ptr %10, align 8, !tbaa !9
  store i32 4, ptr %24, align 4, !tbaa !5
  call void @EXIT_CORE()
  store i32 1, ptr %14, align 4
  br label %147

25:                                               ; preds = %5
  %26 = load ptr, ptr %11, align 8, !tbaa !9
  %27 = getelementptr inbounds %struct._MODULE_INFORMATION_TYPE, ptr %26, i32 0, i32 7
  %28 = load ptr, ptr %27, align 8, !tbaa !19
  %29 = load i32, ptr %6, align 4, !tbaa !5
  %30 = zext i32 %29 to i64
  %31 = getelementptr inbounds %struct._PARTITION_INFORMATION_TYPE, ptr %28, i64 %30
  store ptr %31, ptr %12, align 8, !tbaa !9
  %32 = load i32, ptr %7, align 4, !tbaa !5
  %33 = load ptr, ptr %12, align 8, !tbaa !9
  %34 = getelementptr inbounds %struct._PARTITION_INFORMATION_TYPE, ptr %33, i32 0, i32 10
  %35 = load i32, ptr %34, align 8, !tbaa !20
  %36 = icmp uge i32 %32, %35
  br i1 %36, label %37, label %39

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

39:                                               ; preds = %25
  %40 = load ptr, ptr %12, align 8, !tbaa !9
  %41 = getelementptr inbounds %struct._PARTITION_INFORMATION_TYPE, ptr %40, i32 0, i32 11
  %42 = load ptr, ptr %41, align 8, !tbaa !24
  %43 = load i32, ptr %7, align 4, !tbaa !5
  %44 = zext i32 %43 to i64
  %45 = getelementptr inbounds %struct._PROCESS_INFORMATION_TYPE, ptr %42, i64 %44
  store ptr %45, ptr %13, align 8, !tbaa !9
  %46 = load i64, ptr %9, align 8, !tbaa !11
  %47 = icmp slt i64 %46, 0
  br i1 %47, label %48, label %53

48:                                               ; preds = %39
  %49 = load i64, ptr %9, align 8, !tbaa !11
  %50 = icmp ne i64 %49, -1
  br i1 %50, label %51, label %53

51:                                               ; preds = %48
  %52 = load ptr, ptr %10, align 8, !tbaa !9
  store i32 4, ptr %52, align 4, !tbaa !5
  call void @EXIT_CORE()
  store i32 1, ptr %14, align 4
  br label %147

53:                                               ; preds = %48, %39
  %54 = load i64, ptr %9, align 8, !tbaa !11
  %55 = icmp eq i64 %54, 0
  br i1 %55, label %56, label %58

56:                                               ; preds = %53
  %57 = load ptr, ptr %10, align 8, !tbaa !9
  store i32 3, ptr %57, align 4, !tbaa !5
  call void @EXIT_CORE()
  store i32 1, ptr %14, align 4
  br label %147

58:                                               ; preds = %53
  %59 = load ptr, ptr %12, align 8, !tbaa !9
  %60 = getelementptr inbounds %struct._PARTITION_INFORMATION_TYPE, ptr %59, i32 0, i32 6
  %61 = load i32, ptr %60, align 4, !tbaa !25
  %62 = icmp ugt i32 %61, 0
  br i1 %62, label %70, label %63

63:                                               ; preds = %58
  %64 = load ptr, ptr %12, align 8, !tbaa !9
  %65 = getelementptr inbounds %struct._PARTITION_INFORMATION_TYPE, ptr %64, i32 0, i32 13
  %66 = getelementptr inbounds %struct._ERRORHANDLER_INFORMATION_TYPE, ptr %65, i32 0, i32 7
  %67 = load i8, ptr %66, align 1, !tbaa !26
  %68 = zext i8 %67 to i32
  %69 = icmp ne i32 %68, 0
  br i1 %69, label %70, label %72

70:                                               ; preds = %63, %58
  %71 = load ptr, ptr %10, align 8, !tbaa !9
  store i32 6, ptr %71, align 4, !tbaa !5
  call void @EXIT_CORE()
  store i32 1, ptr %14, align 4
  br label %147

72:                                               ; preds = %63
  %73 = load ptr, ptr %13, align 8, !tbaa !9
  %74 = getelementptr inbounds %struct._PROCESS_INFORMATION_TYPE, ptr %73, i32 0, i32 11
  call void @PRIORITYQUEUE_REMOVE(ptr noundef %74)
  %75 = load ptr, ptr %13, align 8, !tbaa !9
  %76 = getelementptr inbounds %struct._PROCESS_INFORMATION_TYPE, ptr %75, i32 0, i32 4
  store i32 4, ptr %76, align 8, !tbaa !27
  %77 = load ptr, ptr %13, align 8, !tbaa !9
  %78 = getelementptr inbounds %struct._PROCESS_INFORMATION_TYPE, ptr %77, i32 0, i32 3
  %79 = load i32, ptr %78, align 4, !tbaa !29
  %80 = zext i32 %79 to i64
  %81 = load ptr, ptr %13, align 8, !tbaa !9
  %82 = getelementptr inbounds %struct._PROCESS_INFORMATION_TYPE, ptr %81, i32 0, i32 14
  %83 = getelementptr inbounds %struct._priorityqueueENTRY, ptr %82, i32 0, i32 0
  store i64 %80, ptr %83, align 8, !tbaa !30
  %84 = load ptr, ptr %13, align 8, !tbaa !9
  %85 = getelementptr inbounds %struct._PROCESS_INFORMATION_TYPE, ptr %84, i32 0, i32 2
  %86 = load i32, ptr %85, align 8, !tbaa !31
  %87 = zext i32 %86 to i64
  %88 = load ptr, ptr %13, align 8, !tbaa !9
  %89 = getelementptr inbounds %struct._PROCESS_INFORMATION_TYPE, ptr %88, i32 0, i32 14
  %90 = getelementptr inbounds %struct._priorityqueueENTRY, ptr %89, i32 0, i32 1
  store i64 %87, ptr %90, align 8, !tbaa !32
  %91 = load ptr, ptr %8, align 8, !tbaa !9
  %92 = load ptr, ptr %13, align 8, !tbaa !9
  %93 = getelementptr inbounds %struct._PROCESS_INFORMATION_TYPE, ptr %92, i32 0, i32 14
  call void @PRIORITYQUEUE_ENQUEUE(ptr noundef %91, ptr noundef %93)
  %94 = load i64, ptr %9, align 8, !tbaa !11
  %95 = icmp ne i64 %94, -1
  br i1 %95, label %96, label %144

96:                                               ; preds = %72
  %97 = load ptr, ptr %11, align 8, !tbaa !9
  %98 = getelementptr inbounds %struct._MODULE_INFORMATION_TYPE, ptr %97, i32 0, i32 10
  %99 = load i64, ptr %98, align 8, !tbaa !33
  %100 = load ptr, ptr %11, align 8, !tbaa !9
  %101 = getelementptr inbounds %struct._MODULE_INFORMATION_TYPE, ptr %100, i32 0, i32 11
  %102 = load i64, ptr %101, align 8, !tbaa !34
  %103 = add nsw i64 %99, %102
  %104 = load ptr, ptr %13, align 8, !tbaa !9
  %105 = getelementptr inbounds %struct._PROCESS_INFORMATION_TYPE, ptr %104, i32 0, i32 8
  store i64 %103, ptr %105, align 8, !tbaa !35
  %106 = load ptr, ptr %13, align 8, !tbaa !9
  %107 = getelementptr inbounds %struct._PROCESS_INFORMATION_TYPE, ptr %106, i32 0, i32 9
  store i64 -1, ptr %107, align 8, !tbaa !36
  %108 = load ptr, ptr %11, align 8, !tbaa !9
  %109 = getelementptr inbounds %struct._MODULE_INFORMATION_TYPE, ptr %108, i32 0, i32 10
  %110 = load i64, ptr %109, align 8, !tbaa !33
  %111 = load ptr, ptr %11, align 8, !tbaa !9
  %112 = getelementptr inbounds %struct._MODULE_INFORMATION_TYPE, ptr %111, i32 0, i32 11
  %113 = load i64, ptr %112, align 8, !tbaa !34
  %114 = add nsw i64 %110, %113
  %115 = load i64, ptr %9, align 8, !tbaa !11
  %116 = add nsw i64 %114, %115
  %117 = load ptr, ptr %13, align 8, !tbaa !9
  %118 = getelementptr inbounds %struct._PROCESS_INFORMATION_TYPE, ptr %117, i32 0, i32 13
  %119 = getelementptr inbounds %struct._priorityqueueENTRY, ptr %118, i32 0, i32 0
  store i64 %116, ptr %119, align 8, !tbaa !37
  %120 = load ptr, ptr %13, align 8, !tbaa !9
  %121 = getelementptr inbounds %struct._PROCESS_INFORMATION_TYPE, ptr %120, i32 0, i32 2
  %122 = load i32, ptr %121, align 8, !tbaa !31
  %123 = zext i32 %122 to i64
  %124 = load ptr, ptr %13, align 8, !tbaa !9
  %125 = getelementptr inbounds %struct._PROCESS_INFORMATION_TYPE, ptr %124, i32 0, i32 13
  %126 = getelementptr inbounds %struct._priorityqueueENTRY, ptr %125, i32 0, i32 1
  store i64 %123, ptr %126, align 8, !tbaa !38
  %127 = load ptr, ptr %12, align 8, !tbaa !9
  %128 = getelementptr inbounds %struct._PARTITION_INFORMATION_TYPE, ptr %127, i32 0, i32 19
  %129 = load ptr, ptr %13, align 8, !tbaa !9
  %130 = getelementptr inbounds %struct._PROCESS_INFORMATION_TYPE, ptr %129, i32 0, i32 13
  call void @PRIORITYQUEUE_ENQUEUE(ptr noundef %128, ptr noundef %130)
  call void @PORT_YIELD()
  %131 = load ptr, ptr %13, align 8, !tbaa !9
  %132 = getelementptr inbounds %struct._PROCESS_INFORMATION_TYPE, ptr %131, i32 0, i32 13
  call void @PRIORITYQUEUE_REMOVE(ptr noundef %132)
  %133 = load ptr, ptr %13, align 8, !tbaa !9
  %134 = getelementptr inbounds %struct._PROCESS_INFORMATION_TYPE, ptr %133, i32 0, i32 14
  call void @PRIORITYQUEUE_REMOVE(ptr noundef %134)
  %135 = load ptr, ptr %13, align 8, !tbaa !9
  %136 = getelementptr inbounds %struct._PROCESS_INFORMATION_TYPE, ptr %135, i32 0, i32 9
  %137 = load i64, ptr %136, align 8, !tbaa !36
  %138 = icmp ne i64 %137, -1
  br i1 %138, label %139, label %141

139:                                              ; preds = %96
  %140 = load ptr, ptr %10, align 8, !tbaa !9
  store i32 7, ptr %140, align 4, !tbaa !5
  br label %143

141:                                              ; preds = %96
  %142 = load ptr, ptr %10, align 8, !tbaa !9
  store i32 1, ptr %142, align 4, !tbaa !5
  br label %143

143:                                              ; preds = %141, %139
  br label %146

144:                                              ; preds = %72
  call void @PORT_YIELD()
  %145 = load ptr, ptr %10, align 8, !tbaa !9
  store i32 1, ptr %145, align 4, !tbaa !5
  br label %146

146:                                              ; preds = %144, %143
  call void @EXIT_CORE()
  store i32 0, ptr %14, align 4
  br label %147

147:                                              ; preds = %146, %70, %56, %51, %37, %23
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  %148 = load i32, ptr %14, align 4
  switch i32 %148, label %150 [
    i32 0, label %149
    i32 1, label %149
  ]

149:                                              ; preds = %147, %147
  ret void

150:                                              ; preds = %147
  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 void @PRIORITYQUEUE_REMOVE(ptr noundef) #2

declare void @PRIORITYQUEUE_ENQUEUE(ptr noundef, ptr noundef) #2

declare void @PORT_YIELD() #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, !12, i64 0}
!12 = !{!"long long", !7, i64 0}
!13 = !{!14, !6, i64 120}
!14 = !{!"_MODULE_INFORMATION_TYPE", !10, i64 0, !15, i64 8, !6, i64 32, !6, i64 36, !6, i64 40, !16, i64 48, !6, i64 120, !10, i64 128, !10, i64 136, !17, i64 144, !12, i64 256, !12, i64 264, !12, i64 272, !18, i64 280}
!15 = !{!"_heapRECORD", !10, i64 0, !6, i64 8, !6, i64 12, !6, i64 16}
!16 = !{!"_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}
!17 = !{!"_HEALTHMONITORINGCALLBACK_INFORMATION_TYPE", !7, i64 0, !10, i64 8, !6, i64 16, !16, i64 24, !7, i64 96, !7, i64 97, !7, i64 98, !7, i64 99, !6, i64 100, !6, i64 104}
!18 = !{!"_priorityqueueRECORD", !10, i64 0, !6, i64 8, !7, i64 12, !7, i64 13}
!19 = !{!14, !10, i64 128}
!20 = !{!21, !6, i64 144}
!21 = !{!"_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, !15, i64 48, !16, i64 72, !6, i64 144, !10, i64 152, !10, i64 160, !22, i64 168, !17, i64 272, !6, i64 384, !23, 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}
!22 = !{!"_ERRORHANDLER_INFORMATION_TYPE", !7, i64 0, !10, i64 8, !6, i64 16, !16, i64 24, !7, i64 96, !7, i64 97, !7, i64 98, !7, i64 99, !6, i64 100}
!23 = !{!"_priorityqueueENTRY", !12, i64 0, !12, i64 8, !10, i64 16, !10, i64 24, !10, i64 32}
!24 = !{!21, !10, i64 152}
!25 = !{!21, !6, i64 36}
!26 = !{!21, !7, i64 267}
!27 = !{!28, !6, i64 24}
!28 = !{!"_PROCESS_INFORMATION_TYPE", !10, i64 0, !10, i64 8, !6, i64 16, !6, i64 20, !6, i64 24, !12, i64 32, !12, i64 40, !12, i64 48, !12, i64 56, !12, i64 64, !16, i64 72, !23, i64 144, !23, i64 184, !23, i64 224, !23, i64 264, !7, i64 304, !7, i64 305, !10, i64 312, !6, i64 320, !10, i64 328, !10, i64 336}
!29 = !{!28, !6, i64 20}
!30 = !{!28, !12, i64 264}
!31 = !{!28, !6, i64 16}
!32 = !{!28, !12, i64 272}
!33 = !{!14, !12, i64 256}
!34 = !{!14, !12, i64 264}
!35 = !{!28, !12, i64 56}
!36 = !{!28, !12, i64 64}
!37 = !{!28, !12, i64 224}
!38 = !{!28, !12, i64 232}


; 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._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 local_unnamed_addr global [2 x %struct._MODULE_INFORMATION_TYPE], align 16

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

11:                                               ; preds = %5
  %12 = getelementptr inbounds i8, ptr %8, i64 128
  %13 = load ptr, ptr %12, align 8, !tbaa !16
  %14 = zext i32 %0 to i64
  %15 = getelementptr inbounds %struct._PARTITION_INFORMATION_TYPE, ptr %13, i64 %14
  %16 = getelementptr inbounds i8, ptr %15, i64 144
  %17 = load i32, ptr %16, align 8, !tbaa !17
  %.not47 = icmp ugt i32 %17, %1
  br i1 %.not47, label %18, label %58

18:                                               ; preds = %11
  %19 = getelementptr inbounds i8, ptr %15, i64 152
  %20 = load ptr, ptr %19, align 8, !tbaa !21
  %21 = zext i32 %1 to i64
  %22 = getelementptr inbounds %struct._PROCESS_INFORMATION_TYPE, ptr %20, i64 %21
  %.not48 = icmp eq i64 %3, -1
  %or.cond = icmp slt i64 %3, -1
  br i1 %or.cond, label %58, label %23

23:                                               ; preds = %18
  %24 = icmp eq i64 %3, 0
  br i1 %24, label %58, label %25

25:                                               ; preds = %23
  %26 = getelementptr inbounds i8, ptr %15, i64 36
  %27 = load i32, ptr %26, align 4, !tbaa !22
  %.not49 = icmp eq i32 %27, 0
  br i1 %.not49, label %28, label %58

28:                                               ; preds = %25
  %29 = getelementptr inbounds i8, ptr %15, i64 267
  %30 = load i8, ptr %29, align 1, !tbaa !23
  %.not50 = icmp eq i8 %30, 0
  br i1 %.not50, label %31, label %58

31:                                               ; preds = %28
  %32 = getelementptr inbounds i8, ptr %22, i64 144
  tail call void @PRIORITYQUEUE_REMOVE(ptr noundef nonnull %32) #2
  %33 = getelementptr inbounds i8, ptr %22, i64 24
  store i32 4, ptr %33, align 8, !tbaa !24
  %34 = getelementptr inbounds i8, ptr %22, i64 20
  %35 = load i32, ptr %34, align 4, !tbaa !26
  %36 = zext i32 %35 to i64
  %37 = getelementptr inbounds i8, ptr %22, i64 264
  store i64 %36, ptr %37, align 8, !tbaa !27
  %38 = getelementptr inbounds i8, ptr %22, i64 16
  %39 = load i32, ptr %38, align 8, !tbaa !28
  %40 = zext i32 %39 to i64
  %41 = getelementptr inbounds i8, ptr %22, i64 272
  store i64 %40, ptr %41, align 8, !tbaa !29
  tail call void @PRIORITYQUEUE_ENQUEUE(ptr noundef %2, ptr noundef nonnull %37) #2
  br i1 %.not48, label %57, label %42

42:                                               ; preds = %31
  %43 = getelementptr inbounds i8, ptr %8, i64 256
  %44 = load i64, ptr %43, align 8, !tbaa !30
  %45 = getelementptr inbounds i8, ptr %8, i64 264
  %46 = load i64, ptr %45, align 8, !tbaa !31
  %47 = add nsw i64 %46, %44
  %48 = getelementptr inbounds i8, ptr %22, i64 56
  store i64 %47, ptr %48, align 8, !tbaa !32
  %49 = getelementptr inbounds i8, ptr %22, i64 64
  store i64 -1, ptr %49, align 8, !tbaa !33
  %50 = add nsw i64 %47, %3
  %51 = getelementptr inbounds i8, ptr %22, i64 224
  store i64 %50, ptr %51, align 8, !tbaa !34
  %52 = load i32, ptr %38, align 8, !tbaa !28
  %53 = zext i32 %52 to i64
  %54 = getelementptr inbounds i8, ptr %22, i64 232
  store i64 %53, ptr %54, align 8, !tbaa !35
  %55 = getelementptr inbounds i8, ptr %15, i64 464
  tail call void @PRIORITYQUEUE_ENQUEUE(ptr noundef nonnull %55, ptr noundef nonnull %51) #2
  tail call void @PORT_YIELD() #2
  tail call void @PRIORITYQUEUE_REMOVE(ptr noundef nonnull %51) #2
  tail call void @PRIORITYQUEUE_REMOVE(ptr noundef nonnull %37) #2
  %56 = load i64, ptr %49, align 8, !tbaa !33
  %.not51 = icmp eq i64 %56, -1
  %. = select i1 %.not51, i32 1, i32 7
  br label %58

57:                                               ; preds = %31
  tail call void @PORT_YIELD() #2
  br label %58

58:                                               ; preds = %57, %42, %25, %28, %23, %18, %11, %5
  %.sink.sink = phi i32 [ 4, %5 ], [ 4, %11 ], [ 4, %18 ], [ 3, %23 ], [ 6, %28 ], [ 6, %25 ], [ 1, %57 ], [ %., %42 ]
  store i32 %.sink.sink, ptr %4, align 4, !tbaa !36
  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 void @PRIORITYQUEUE_REMOVE(ptr noundef) local_unnamed_addr #1

declare void @PRIORITYQUEUE_ENQUEUE(ptr noundef, ptr noundef) local_unnamed_addr #1

declare void @PORT_YIELD() 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 144}
!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 152}
!22 = !{!18, !11, i64 36}
!23 = !{!18, !8, i64 267}
!24 = !{!25, !11, i64 24}
!25 = !{!"_PROCESS_INFORMATION_TYPE", !7, i64 0, !7, i64 8, !11, i64 16, !11, i64 20, !11, i64 24, !14, i64 32, !14, i64 40, !14, i64 48, !14, i64 56, !14, i64 64, !12, i64 72, !20, i64 144, !20, i64 184, !20, i64 224, !20, i64 264, !8, i64 304, !8, i64 305, !7, i64 312, !11, i64 320, !7, i64 328, !7, i64 336}
!26 = !{!25, !11, i64 20}
!27 = !{!25, !14, i64 264}
!28 = !{!25, !11, i64 16}
!29 = !{!25, !14, i64 272}
!30 = !{!6, !14, i64 256}
!31 = !{!6, !14, i64 264}
!32 = !{!25, !14, i64 56}
!33 = !{!25, !14, i64 64}
!34 = !{!25, !14, i64 224}
!35 = !{!25, !14, i64 232}
!36 = !{!11, !11, i64 0}


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