; LLVM IR from thalium/icebox :: third_party/virtualbox/src/VBox/Devices/EFI/Firmware/MdePkg/Library/UefiLib_ (EfiCreateEventReadyToBootEx)

; 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.GUID = type { i32, i16, i16, [8 x i8] }
%struct.EFI_SYSTEM_TABLE = type { %struct.EFI_TABLE_HEADER, ptr, i32, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, i64, ptr }
%struct.EFI_TABLE_HEADER = type { i64, i32, i32, i32, i32 }
%struct.EFI_BOOT_SERVICES = type { %struct.EFI_TABLE_HEADER, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }

@.str = external hidden unnamed_addr constant [139 x i8], align 1
@gST = external global ptr, align 8
@.str.3 = external hidden unnamed_addr constant [18 x i8], align 1
@gBS = external global ptr, align 8
@.str.4 = external hidden unnamed_addr constant [33 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [39 x i8], align 1
@gEfiEventReadyToBootGuid = external global %struct.GUID, align 4

; Function Attrs: nounwind uwtable
declare dso_local void @InternalEmptyFunction(ptr noundef, ptr noundef) #0

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

declare zeroext i8 @DebugAssertEnabled() #2

declare void @DebugAssert(ptr noundef, i64 noundef, ptr noundef) #2

declare zeroext i8 @DebugPrintEnabled() #2

declare zeroext i8 @DebugPrintLevelEnabled(i64 noundef) #2

declare void @DebugPrint(i64 noundef, ptr noundef, ...) #2

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

; Function Attrs: nounwind uwtable
define dso_local i64 @EfiCreateEventReadyToBootEx(i64 noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3) #0 {
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i64, align 8
  %11 = alloca ptr, align 8
  %12 = alloca i32, align 4
  store i64 %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !9
  store ptr %2, ptr %8, align 8, !tbaa !9
  store ptr %3, ptr %9, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #3
  br label %13

13:                                               ; preds = %4
  %14 = call zeroext i8 @DebugAssertEnabled()
  %15 = icmp ne i8 %14, 0
  br i1 %15, label %16, label %21

16:                                               ; preds = %13
  %17 = load ptr, ptr %9, align 8, !tbaa !9
  %18 = icmp ne ptr %17, null
  br i1 %18, label %20, label %19

19:                                               ; preds = %16
  call void @DebugAssert(ptr noundef @.str, i64 noundef 202, ptr noundef @.str.4)
  br label %20

20:                                               ; preds = %19, %16
  br label %21

21:                                               ; preds = %20, %13
  br label %22

22:                                               ; preds = %21
  br label %23

23:                                               ; preds = %22
  %24 = load ptr, ptr @gST, align 8, !tbaa !9
  %25 = getelementptr inbounds %struct.EFI_SYSTEM_TABLE, ptr %24, i32 0, i32 0
  %26 = getelementptr inbounds %struct.EFI_TABLE_HEADER, ptr %25, i32 0, i32 1
  %27 = load i32, ptr %26, align 8, !tbaa !11
  %28 = icmp ult i32 %27, 131072
  br i1 %28, label %29, label %51

29:                                               ; preds = %23
  br label %30

30:                                               ; preds = %29
  %31 = call zeroext i8 @DebugPrintEnabled()
  %32 = icmp ne i8 %31, 0
  br i1 %32, label %33, label %41

33:                                               ; preds = %30
  br label %34

34:                                               ; preds = %33
  %35 = call zeroext i8 @DebugPrintLevelEnabled(i64 noundef 2147483648)
  %36 = icmp ne i8 %35, 0
  br i1 %36, label %37, label %38

37:                                               ; preds = %34
  call void (i64, ptr, ...) @DebugPrint(i64 noundef 2147483648, ptr noundef @.str.5)
  br label %38

38:                                               ; preds = %37, %34
  br label %39

39:                                               ; preds = %38
  br label %40

40:                                               ; preds = %39
  br label %41

41:                                               ; preds = %40, %30
  br label %42

42:                                               ; preds = %41
  br label %43

43:                                               ; preds = %42
  br label %44

44:                                               ; preds = %43
  %45 = call zeroext i8 @DebugAssertEnabled()
  %46 = icmp ne i8 %45, 0
  br i1 %46, label %47, label %48

47:                                               ; preds = %44
  call void @DebugAssert(ptr noundef @.str, i64 noundef 206, ptr noundef @.str.3)
  br label %48

48:                                               ; preds = %47, %44
  br label %49

49:                                               ; preds = %48
  br label %50

50:                                               ; preds = %49
  store i64 -9223372036854775805, ptr %5, align 8
  store i32 1, ptr %12, align 4
  br label %68

51:                                               ; preds = %23
  %52 = load ptr, ptr %7, align 8, !tbaa !9
  %53 = icmp eq ptr %52, null
  br i1 %53, label %54, label %55

54:                                               ; preds = %51
  store ptr @InternalEmptyFunction, ptr %11, align 8, !tbaa !9
  br label %57

55:                                               ; preds = %51
  %56 = load ptr, ptr %7, align 8, !tbaa !9
  store ptr %56, ptr %11, align 8, !tbaa !9
  br label %57

57:                                               ; preds = %55, %54
  %58 = load ptr, ptr @gBS, align 8, !tbaa !9
  %59 = getelementptr inbounds %struct.EFI_BOOT_SERVICES, ptr %58, i32 0, i32 44
  %60 = load ptr, ptr %59, align 8, !tbaa !15
  %61 = load i64, ptr %6, align 8, !tbaa !5
  %62 = load ptr, ptr %11, align 8, !tbaa !9
  %63 = load ptr, ptr %8, align 8, !tbaa !9
  %64 = load ptr, ptr %9, align 8, !tbaa !9
  %65 = call i64 %60(i32 noundef 512, i64 noundef %61, ptr noundef %62, ptr noundef %63, ptr noundef @gEfiEventReadyToBootGuid, ptr noundef %64)
  store i64 %65, ptr %10, align 8, !tbaa !5
  br label %66

66:                                               ; preds = %57
  %67 = load i64, ptr %10, align 8, !tbaa !5
  store i64 %67, ptr %5, align 8
  store i32 1, ptr %12, align 4
  br label %68

68:                                               ; preds = %66, %50
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  %69 = load i64, ptr %5, align 8
  ret i64 %69
}

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 = !{!"long long", !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, !14, i64 8}
!12 = !{!"", !13, i64 0, !10, i64 24, !14, i64 32, !10, i64 40, !10, i64 48, !10, i64 56, !10, i64 64, !10, i64 72, !10, i64 80, !10, i64 88, !10, i64 96, !6, i64 104, !10, i64 112}
!13 = !{!"", !6, i64 0, !14, i64 8, !14, i64 12, !14, i64 16, !14, i64 20}
!14 = !{!"int", !7, i64 0}
!15 = !{!16, !10, i64 368}
!16 = !{!"", !13, i64 0, !10, i64 24, !10, i64 32, !10, i64 40, !10, i64 48, !10, i64 56, !10, i64 64, !10, i64 72, !10, i64 80, !10, i64 88, !10, i64 96, !10, i64 104, !10, i64 112, !10, i64 120, !10, i64 128, !10, i64 136, !10, i64 144, !10, i64 152, !10, i64 160, !10, i64 168, !10, i64 176, !10, i64 184, !10, i64 192, !10, i64 200, !10, i64 208, !10, i64 216, !10, i64 224, !10, i64 232, !10, i64 240, !10, i64 248, !10, i64 256, !10, i64 264, !10, i64 272, !10, i64 280, !10, i64 288, !10, i64 296, !10, i64 304, !10, i64 312, !10, i64 320, !10, i64 328, !10, i64 336, !10, i64 344, !10, i64 352, !10, i64 360, !10, i64 368}


; 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.GUID = type { i32, i16, i16, [8 x i8] }

@.str = external hidden unnamed_addr constant [139 x i8], align 1
@gST = external local_unnamed_addr global ptr, align 8
@.str.3 = external hidden unnamed_addr constant [18 x i8], align 1
@gBS = external local_unnamed_addr global ptr, align 8
@.str.4 = external hidden unnamed_addr constant [33 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [39 x i8], align 1
@gEfiEventReadyToBootGuid = external global %struct.GUID, align 4

; Function Attrs: nounwind uwtable
declare dso_local void @InternalEmptyFunction(ptr noundef, ptr noundef) #0

declare zeroext i8 @DebugAssertEnabled() local_unnamed_addr #1

declare void @DebugAssert(ptr noundef, i64 noundef, ptr noundef) local_unnamed_addr #1

declare zeroext i8 @DebugPrintEnabled() local_unnamed_addr #1

declare zeroext i8 @DebugPrintLevelEnabled(i64 noundef) local_unnamed_addr #1

declare void @DebugPrint(i64 noundef, ptr noundef, ...) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local i64 @EfiCreateEventReadyToBootEx(i64 noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3) local_unnamed_addr #0 {
  %5 = tail call zeroext i8 @DebugAssertEnabled() #2
  %6 = icmp eq i8 %5, 0
  %7 = icmp ne ptr %3, null
  %or.cond = or i1 %7, %6
  br i1 %or.cond, label %9, label %8

8:                                                ; preds = %4
  tail call void @DebugAssert(ptr noundef nonnull @.str, i64 noundef 202, ptr noundef nonnull @.str.4) #2
  br label %9

9:                                                ; preds = %8, %4
  %10 = load ptr, ptr @gST, align 8, !tbaa !5
  %11 = getelementptr inbounds i8, ptr %10, i64 8
  %12 = load i32, ptr %11, align 8, !tbaa !9
  %13 = icmp ult i32 %12, 131072
  br i1 %13, label %14, label %22

14:                                               ; preds = %9
  %15 = tail call zeroext i8 @DebugPrintEnabled() #2
  %.not = icmp eq i8 %15, 0
  br i1 %.not, label %19, label %16

16:                                               ; preds = %14
  %17 = tail call zeroext i8 @DebugPrintLevelEnabled(i64 noundef 2147483648) #2
  %.not11 = icmp eq i8 %17, 0
  br i1 %.not11, label %19, label %18

18:                                               ; preds = %16
  tail call void (i64, ptr, ...) @DebugPrint(i64 noundef 2147483648, ptr noundef nonnull @.str.5) #2
  br label %19

19:                                               ; preds = %14, %18, %16
  %20 = tail call zeroext i8 @DebugAssertEnabled() #2
  %.not12 = icmp eq i8 %20, 0
  br i1 %.not12, label %28, label %21

21:                                               ; preds = %19
  tail call void @DebugAssert(ptr noundef nonnull @.str, i64 noundef 206, ptr noundef nonnull @.str.3) #2
  br label %28

22:                                               ; preds = %9
  %23 = icmp eq ptr %1, null
  %InternalEmptyFunction. = select i1 %23, ptr @InternalEmptyFunction, ptr %1
  %24 = load ptr, ptr @gBS, align 8, !tbaa !5
  %25 = getelementptr inbounds i8, ptr %24, i64 368
  %26 = load ptr, ptr %25, align 8, !tbaa !14
  %27 = tail call i64 %26(i32 noundef 512, i64 noundef %0, ptr noundef nonnull %InternalEmptyFunction., ptr noundef %2, ptr noundef nonnull @gEfiEventReadyToBootGuid, ptr noundef %3) #2
  br label %28

28:                                               ; preds = %19, %21, %22
  %.09 = phi i64 [ %27, %22 ], [ -9223372036854775805, %21 ], [ -9223372036854775805, %19 ]
  ret i64 %.09
}

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, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !13, i64 8}
!10 = !{!"", !11, i64 0, !6, i64 24, !13, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !6, i64 64, !6, i64 72, !6, i64 80, !6, i64 88, !6, i64 96, !12, i64 104, !6, i64 112}
!11 = !{!"", !12, i64 0, !13, i64 8, !13, i64 12, !13, i64 16, !13, i64 20}
!12 = !{!"long long", !7, i64 0}
!13 = !{!"int", !7, i64 0}
!14 = !{!15, !6, i64 368}
!15 = !{!"", !11, i64 0, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !6, i64 64, !6, i64 72, !6, i64 80, !6, i64 88, !6, i64 96, !6, i64 104, !6, i64 112, !6, i64 120, !6, i64 128, !6, i64 136, !6, i64 144, !6, i64 152, !6, i64 160, !6, i64 168, !6, i64 176, !6, i64 184, !6, i64 192, !6, i64 200, !6, i64 208, !6, i64 216, !6, i64 224, !6, i64 232, !6, i64 240, !6, i64 248, !6, i64 256, !6, i64 264, !6, i64 272, !6, i64 280, !6, i64 288, !6, i64 296, !6, i64 304, !6, i64 312, !6, i64 320, !6, i64 328, !6, i64 336, !6, i64 344, !6, i64 352, !6, i64 360, !6, i64 368}


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