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

; 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_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 }
%struct.EFI_TABLE_HEADER = type { i64, i32, i32, i32, i32 }

@mInternalRT = external dso_local global ptr, align 8
@gRT = external global ptr, align 8
@.str = external hidden unnamed_addr constant [144 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [20 x i8], align 1
@gBS = external global ptr, align 8
@.str.2 = external hidden unnamed_addr constant [20 x i8], align 1
@gEfiEventVirtualAddressChangeGuid = external global %struct.GUID, align 4
@mEfiVirtualNotifyEvent = external dso_local global ptr, align 8
@.str.3 = external hidden unnamed_addr constant [33 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [20 x i8], align 1
@gEfiEventExitBootServicesGuid = external global %struct.GUID, align 4
@mEfiExitBootServicesEvent = external dso_local global ptr, align 8

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

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

; Function Attrs: nounwind uwtable
define dso_local i64 @RuntimeDriverLibConstruct(ptr noundef %0, ptr noundef %1) #0 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i64, align 8
  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
  br label %6

6:                                                ; preds = %2
  %7 = call zeroext i8 @DebugAssertEnabled()
  %8 = icmp ne i8 %7, 0
  br i1 %8, label %9, label %14

9:                                                ; preds = %6
  %10 = load ptr, ptr @gRT, align 8, !tbaa !5
  %11 = icmp ne ptr %10, null
  br i1 %11, label %13, label %12

12:                                               ; preds = %9
  call void @DebugAssert(ptr noundef @.str, i64 noundef 95, ptr noundef @.str.1)
  br label %13

13:                                               ; preds = %12, %9
  br label %14

14:                                               ; preds = %13, %6
  br label %15

15:                                               ; preds = %14
  br label %16

16:                                               ; preds = %15
  br label %17

17:                                               ; preds = %16
  %18 = call zeroext i8 @DebugAssertEnabled()
  %19 = icmp ne i8 %18, 0
  br i1 %19, label %20, label %25

20:                                               ; preds = %17
  %21 = load ptr, ptr @gBS, align 8, !tbaa !5
  %22 = icmp ne ptr %21, null
  br i1 %22, label %24, label %23

23:                                               ; preds = %20
  call void @DebugAssert(ptr noundef @.str, i64 noundef 96, ptr noundef @.str.2)
  br label %24

24:                                               ; preds = %23, %20
  br label %25

25:                                               ; preds = %24, %17
  br label %26

26:                                               ; preds = %25
  br label %27

27:                                               ; preds = %26
  %28 = load ptr, ptr @gRT, align 8, !tbaa !5
  store ptr %28, ptr @mInternalRT, align 8, !tbaa !5
  %29 = load ptr, ptr @gBS, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.EFI_BOOT_SERVICES, ptr %29, i32 0, i32 44
  %31 = load ptr, ptr %30, align 8, !tbaa !9
  %32 = call i64 %31(i32 noundef 512, i64 noundef 16, ptr noundef @RuntimeLibVirtualNotifyEvent, ptr noundef null, ptr noundef @gEfiEventVirtualAddressChangeGuid, ptr noundef @mEfiVirtualNotifyEvent)
  store i64 %32, ptr %5, align 8, !tbaa !14
  br label %33

33:                                               ; preds = %27
  %34 = call zeroext i8 @DebugAssertEnabled()
  %35 = icmp ne i8 %34, 0
  br i1 %35, label %36, label %56

36:                                               ; preds = %33
  %37 = load i64, ptr %5, align 8, !tbaa !14
  %38 = icmp slt i64 %37, 0
  br i1 %38, label %39, label %55

39:                                               ; preds = %36
  br label %40

40:                                               ; preds = %39
  %41 = call zeroext i8 @DebugPrintEnabled()
  %42 = icmp ne i8 %41, 0
  br i1 %42, label %43, label %52

43:                                               ; preds = %40
  br label %44

44:                                               ; preds = %43
  %45 = call zeroext i8 @DebugPrintLevelEnabled(i64 noundef 2147483648)
  %46 = icmp ne i8 %45, 0
  br i1 %46, label %47, label %49

47:                                               ; preds = %44
  %48 = load i64, ptr %5, align 8, !tbaa !14
  call void (i64, ptr, ...) @DebugPrint(i64 noundef 2147483648, ptr noundef @.str.3, i64 noundef %48)
  br label %49

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

50:                                               ; preds = %49
  br label %51

51:                                               ; preds = %50
  br label %52

52:                                               ; preds = %51, %40
  br label %53

53:                                               ; preds = %52
  br label %54

54:                                               ; preds = %53
  call void @DebugAssert(ptr noundef @.str, i64 noundef 111, ptr noundef @.str.4)
  br label %55

55:                                               ; preds = %54, %36
  br label %56

56:                                               ; preds = %55, %33
  br label %57

57:                                               ; preds = %56
  br label %58

58:                                               ; preds = %57
  %59 = load ptr, ptr @gBS, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.EFI_BOOT_SERVICES, ptr %59, i32 0, i32 44
  %61 = load ptr, ptr %60, align 8, !tbaa !9
  %62 = call i64 %61(i32 noundef 512, i64 noundef 16, ptr noundef @RuntimeLibExitBootServicesEvent, ptr noundef null, ptr noundef @gEfiEventExitBootServicesGuid, ptr noundef @mEfiExitBootServicesEvent)
  store i64 %62, ptr %5, align 8, !tbaa !14
  br label %63

63:                                               ; preds = %58
  %64 = call zeroext i8 @DebugAssertEnabled()
  %65 = icmp ne i8 %64, 0
  br i1 %65, label %66, label %86

66:                                               ; preds = %63
  %67 = load i64, ptr %5, align 8, !tbaa !14
  %68 = icmp slt i64 %67, 0
  br i1 %68, label %69, label %85

69:                                               ; preds = %66
  br label %70

70:                                               ; preds = %69
  %71 = call zeroext i8 @DebugPrintEnabled()
  %72 = icmp ne i8 %71, 0
  br i1 %72, label %73, label %82

73:                                               ; preds = %70
  br label %74

74:                                               ; preds = %73
  %75 = call zeroext i8 @DebugPrintLevelEnabled(i64 noundef 2147483648)
  %76 = icmp ne i8 %75, 0
  br i1 %76, label %77, label %79

77:                                               ; preds = %74
  %78 = load i64, ptr %5, align 8, !tbaa !14
  call void (i64, ptr, ...) @DebugPrint(i64 noundef 2147483648, ptr noundef @.str.3, i64 noundef %78)
  br label %79

79:                                               ; preds = %77, %74
  br label %80

80:                                               ; preds = %79
  br label %81

81:                                               ; preds = %80
  br label %82

82:                                               ; preds = %81, %70
  br label %83

83:                                               ; preds = %82
  br label %84

84:                                               ; preds = %83
  call void @DebugAssert(ptr noundef @.str, i64 noundef 122, ptr noundef @.str.4)
  br label %85

85:                                               ; preds = %84, %66
  br label %86

86:                                               ; preds = %85, %63
  br label %87

87:                                               ; preds = %86
  br label %88

88:                                               ; preds = %87
  %89 = load i64, ptr %5, align 8, !tbaa !14
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  ret i64 %89
}

; 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

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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !6, i64 368}
!10 = !{!"", !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}
!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 = !{!12, !12, i64 0}


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

@mInternalRT = external dso_local local_unnamed_addr global ptr, align 8
@gRT = external local_unnamed_addr global ptr, align 8
@.str = external hidden unnamed_addr constant [144 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [20 x i8], align 1
@gBS = external local_unnamed_addr global ptr, align 8
@.str.2 = external hidden unnamed_addr constant [20 x i8], align 1
@gEfiEventVirtualAddressChangeGuid = external global %struct.GUID, align 4
@mEfiVirtualNotifyEvent = external dso_local global ptr, align 8
@.str.3 = external hidden unnamed_addr constant [33 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [20 x i8], align 1
@gEfiEventExitBootServicesGuid = external global %struct.GUID, align 4
@mEfiExitBootServicesEvent = external dso_local global ptr, align 8

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

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

; Function Attrs: nounwind uwtable
define dso_local i64 @RuntimeDriverLibConstruct(ptr nocapture noundef readnone %0, ptr nocapture noundef readnone %1) local_unnamed_addr #0 {
  %3 = tail call zeroext i8 @DebugAssertEnabled() #2
  %4 = icmp eq i8 %3, 0
  %5 = load ptr, ptr @gRT, align 8
  %6 = icmp ne ptr %5, null
  %or.cond = select i1 %4, i1 true, i1 %6
  br i1 %or.cond, label %8, label %7

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

8:                                                ; preds = %2, %7
  %9 = tail call zeroext i8 @DebugAssertEnabled() #2
  %10 = icmp eq i8 %9, 0
  %11 = load ptr, ptr @gBS, align 8
  %12 = icmp ne ptr %11, null
  %or.cond3 = select i1 %10, i1 true, i1 %12
  br i1 %or.cond3, label %14, label %13

13:                                               ; preds = %8
  tail call void @DebugAssert(ptr noundef nonnull @.str, i64 noundef 96, ptr noundef nonnull @.str.2) #2
  %.pre = load ptr, ptr @gBS, align 8, !tbaa !5
  br label %14

14:                                               ; preds = %13, %8
  %15 = phi ptr [ %.pre, %13 ], [ %11, %8 ]
  %16 = load ptr, ptr @gRT, align 8, !tbaa !5
  store ptr %16, ptr @mInternalRT, align 8, !tbaa !5
  %17 = getelementptr inbounds i8, ptr %15, i64 368
  %18 = load ptr, ptr %17, align 8, !tbaa !9
  %19 = tail call i64 %18(i32 noundef 512, i64 noundef 16, ptr noundef nonnull @RuntimeLibVirtualNotifyEvent, ptr noundef null, ptr noundef nonnull @gEfiEventVirtualAddressChangeGuid, ptr noundef nonnull @mEfiVirtualNotifyEvent) #2
  %20 = tail call zeroext i8 @DebugAssertEnabled() #2
  %21 = icmp ne i8 %20, 0
  %22 = icmp slt i64 %19, 0
  %or.cond5 = select i1 %21, i1 %22, i1 false
  br i1 %or.cond5, label %23, label %29

23:                                               ; preds = %14
  %24 = tail call zeroext i8 @DebugPrintEnabled() #2
  %.not = icmp eq i8 %24, 0
  br i1 %.not, label %28, label %25

25:                                               ; preds = %23
  %26 = tail call zeroext i8 @DebugPrintLevelEnabled(i64 noundef 2147483648) #2
  %.not13 = icmp eq i8 %26, 0
  br i1 %.not13, label %28, label %27

27:                                               ; preds = %25
  tail call void (i64, ptr, ...) @DebugPrint(i64 noundef 2147483648, ptr noundef nonnull @.str.3, i64 noundef %19) #2
  br label %28

28:                                               ; preds = %25, %27, %23
  tail call void @DebugAssert(ptr noundef nonnull @.str, i64 noundef 111, ptr noundef nonnull @.str.4) #2
  br label %29

29:                                               ; preds = %28, %14
  %30 = load ptr, ptr @gBS, align 8, !tbaa !5
  %31 = getelementptr inbounds i8, ptr %30, i64 368
  %32 = load ptr, ptr %31, align 8, !tbaa !9
  %33 = tail call i64 %32(i32 noundef 512, i64 noundef 16, ptr noundef nonnull @RuntimeLibExitBootServicesEvent, ptr noundef null, ptr noundef nonnull @gEfiEventExitBootServicesGuid, ptr noundef nonnull @mEfiExitBootServicesEvent) #2
  %34 = tail call zeroext i8 @DebugAssertEnabled() #2
  %35 = icmp ne i8 %34, 0
  %36 = icmp slt i64 %33, 0
  %or.cond7 = select i1 %35, i1 %36, i1 false
  br i1 %or.cond7, label %37, label %43

37:                                               ; preds = %29
  %38 = tail call zeroext i8 @DebugPrintEnabled() #2
  %.not14 = icmp eq i8 %38, 0
  br i1 %.not14, label %42, label %39

39:                                               ; preds = %37
  %40 = tail call zeroext i8 @DebugPrintLevelEnabled(i64 noundef 2147483648) #2
  %.not15 = icmp eq i8 %40, 0
  br i1 %.not15, label %42, label %41

41:                                               ; preds = %39
  tail call void (i64, ptr, ...) @DebugPrint(i64 noundef 2147483648, ptr noundef nonnull @.str.3, i64 noundef %33) #2
  br label %42

42:                                               ; preds = %39, %41, %37
  tail call void @DebugAssert(ptr noundef nonnull @.str, i64 noundef 122, ptr noundef nonnull @.str.4) #2
  br label %43

43:                                               ; preds = %42, %29
  ret i64 %33
}

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

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, !6, i64 368}
!10 = !{!"", !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}
!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}


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