PnpBootDeviceWait

__int64 __fastcall PnpBootDeviceWait(
        __int64 a1,
        int a2,
        __int64 (__fastcall *a3)(__int64, __int64, struct _UNICODE_STRING *),
        __int64 a4){
  int v4; 
  unsigned int v8; 
  int RegistryValue; 
  int v10; 
  PVOID P; 
  struct _UNICODE_STRING UnicodeString; 
  UNICODE_STRING KeyName; 
  HANDLE Handle; 
  v4 = 0;
  *(_QWORD *)&KeyName.Length = 7209068i64;
  P = 0i64;
  Handle = 0i64;
  *(_QWORD *)&UnicodeString.Length = 0i64;
  UnicodeString.Buffer = 0i64;
  KeyName.Buffer = L"\\Registry\\Machine\\System\\CurrentControlSet\\Control\\PnP";
  v8 = 0;
  RegistryValue = IopOpenRegistryKeyEx(&Handle, 0i64, &KeyName, 0x20019ui64);
  if( RegistryValue >= 0 )
  {
    RegistryValue = IopGetRegistryValue(
                      Handle,
                      (PWCHAR)L"PollBootPartitionTimeout",
                      0i64,
                      (KEY_VALUE_FULL_INFORMATION **)&P);
    if( RegistryValue >= 0 )
    {
      if( *((_DWORD *)P + 3) == 4 )
      {
        v8 = *(_DWORD *)((char *)P + *((unsigned int *)P + 2));
        if( v8 >= 0xC8 )
        {
          if( v8 > 0x2BF20 )
            v8 = 180000;
        }
        else
        {
          v8 = 0;
        }
      }
      else
      {
        RegistryValue = -1073741823;
      }
      ExFreePoolWithTag(P, 0);
    }
    ZwClose(Handle);
  }
  P = (PVOID)-2000000i64;
  RtlFreeAnsiString(&UnicodeString);
  v10 = a3(a1, a4, &UnicodeString);
  if( v10 < 0 )
  {
    if( RegistryValue >= 0 )
      v4 = v8;
    do
    {
      if( v4 <= 0 )
        break;
      KeDelayExecutionThread(0, 0, (PLARGE_INTEGER)&P);
      v4 -= 200;
      RtlFreeAnsiString(&UnicodeString);
      v10 = a3(a1, a4, &UnicodeString);
    }
    while( v10 < 0 );
    if( v10 < 0 )
    {
      HeadlessKernelAddLogEntry(0x15ui64, 0i64);
      KeBugCheckEx(0x7Bu, (ULONG_PTR)&UnicodeString, v10, 0i64, a2);
    }
  }
  RtlFreeAnsiString(&UnicodeString);
  return 0i64;
}

Referenced by:

IopInitializeBootDrivers
VhdInitialize