#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */
typedef int uint8_t;
typedef int uint32_t;
typedef int uint16_t;

/* Variables and functions */
int inl(int);
int /*<<< orphan*/ outl(int, int);
int /*<<< orphan*/ printf(char *, int, int);
uint32_t checkDevice(uint8_t bus, uint8_t device, uint8_t function) {
  uint16_t ven, dev;
  uint32_t ret;
  outl(0x80000000 | (bus << 16) | (device << 11) | (function << 8) | 0x00,
       0xCF8);
  ret = inl(0xCFC);
  dev = (uint16_t)((ret >> 16) & 0xffff);
  ven = (uint16_t)((ret >> 0) & 0xffff);
  if (ret != 0xFFFFFFFF)
    printf("VID: 0x%X DID: 0x%X\n", ven, dev);
  return ret;
}


x86 assembly (clang, -O0):
<checkDevice>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    -0x4(%rbp),%edi
shl    $0x10,%edi
or     $0x80000000,%edi
mov    -0x8(%rbp),%eax
shl    $0xb,%eax
or     %eax,%edi
mov    -0xc(%rbp),%eax
shl    $0x8,%eax
or     %eax,%edi
or     $0x0,%edi
mov    $0xcf8,%esi
call   1040 <outl@plt>
mov    $0xcfc,%edi
call   1050 <inl@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
sar    $0x10,%eax
and    $0xffff,%eax
mov    %eax,-0x14(%rbp)
mov    -0x18(%rbp),%eax
sar    $0x0,%eax
and    $0xffff,%eax
mov    %eax,-0x10(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
je     11af <checkDevice+0x7f>
mov    -0x10(%rbp),%esi
mov    -0x14(%rbp),%edx
lea    0xe56(%rip),%rdi
call   1030 <printf@plt>
mov    -0x18(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<checkDevice>:
push   %rbx
shl    $0x10,%edi
shl    $0xb,%esi
or     %esi,%edi
shl    $0x8,%edx
or     %edx,%edi
or     $0x80000000,%edi
mov    $0xcf8,%esi
call   1040 <outl@plt>
mov    $0xcfc,%edi
call   1050 <inl@plt>
mov    %eax,%ebx
cmp    $0xffffffff,%eax
je     1173 <checkDevice+0x43>
movzwl %bx,%esi
mov    %ebx,%edx
shr    $0x10,%edx
lea    0xe92(%rip),%rdi
call   1030 <printf@plt>
mov    %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [21 x i8] c"VID: 0x%X DID: 0x%X\0A\00"
define i32 @checkDevice(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%10 = load i32, i32* %4
%11 = shl i32 %10, 16
%12 = or i32 -2147483648, %11
%13 = load i32, i32* %5
%14 = shl i32 %13, 11
%15 = or i32 %12, %14
%16 = load i32, i32* %6
%17 = shl i32 %16, 8
%18 = or i32 %15, %17
%19 = or i32 %18, 0
%20 = call i32 @outl(i32 %19, i32 3320)
%21 = call i32 @inl(i32 3324)
store i32 %21, i32* %9
%22 = load i32, i32* %9
%23 = ashr i32 %22, 16
%24 = and i32 %23, 65535
store i32 %24, i32* %8
%25 = load i32, i32* %9
%26 = ashr i32 %25, 0
%27 = and i32 %26, 65535
store i32 %27, i32* %7
%28 = load i32, i32* %9
%29 = icmp ne i32 %28, -1
br i1 %29, label %30, label %34
30: ; preds = %3
%31 = load i32, i32* %7
%32 = load i32, i32* %8
%33 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i32 %31, i32 %32)
br label %34
34: ; preds = %30, %3
%35 = load i32, i32* %9
ret i32 %35
}

LLVM IR (-O2):
@.str = [21 x i8] c"VID: 0x%X DID: 0x%X\0A\00"
define i32 @checkDevice(i32 %0, i32 %1, i32 %2) {
%4 = shl i32 %0, 16
%5 = shl i32 %1, 11
%6 = shl i32 %2, 8
%7 = or i32 %4, %5
%8 = or i32 %7, %6
%9 = or i32 %8, -2147483648
%10 = tail call i32 @outl(i32 %9, i32 3320)
%11 = tail call i32 @inl(i32 3324)
%12 = icmp eq i32 %11, -1
br i1 %12, label %17, label %13
13: ; preds = %3
%14 = and i32 %11, 65535
%15 = lshr i32 %11, 16
%16 = tail call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i32 %14, i32 %15)
br label %17
17: ; preds = %13, %3
ret i32 %11
}