#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);
uint32_t findDevice(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) {
    if (ven == 0x8086 && (dev == 0x1e00 || dev == 0x1e08)) {
      outl(0x80000000 | (bus << 16) | (device << 11) | (function << 8) |
               0x18 & 0xfc,
           0xCF8);
      ret = inl(0xCFC);
    } else
      ret = 0xFFFFFFFF;
  }
  return ret;
}


x86 assembly (clang, -O0):
<findDevice>:
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   1030 <outl@plt>
mov    $0xcfc,%edi
call   1040 <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     11fb <findDevice+0xdb>
cmpl   $0x8086,-0x10(%rbp)
jne    11ef <findDevice+0xcf>
cmpl   $0x1e00,-0x14(%rbp)
je     11b4 <findDevice+0x94>
cmpl   $0x1e08,-0x14(%rbp)
jne    11ef <findDevice+0xcf>
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     $0x18,%edi
mov    $0xcf8,%esi
call   1030 <outl@plt>
mov    $0xcfc,%edi
call   1040 <inl@plt>
mov    %eax,-0x18(%rbp)
jmp    11f6 <findDevice+0xd6>
movl   $0xffffffff,-0x18(%rbp)
jmp    11fb <findDevice+0xdb>
mov    -0x18(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<findDevice>:
push   %rbx
mov    %edx,%ebx
shl    $0x10,%edi
shl    $0xb,%esi
or     %edi,%esi
shl    $0x8,%ebx
or     %esi,%ebx
mov    %ebx,%edi
or     $0x80000000,%edi
mov    $0xcf8,%esi
call   1030 <outl@plt>
mov    $0xcfc,%edi
call   1040 <inl@plt>
cmp    $0xffffffff,%eax
je     117a <findDevice+0x5a>
and    $0xfff7ffff,%eax
cmp    $0x1e008086,%eax
jne    117a <findDevice+0x5a>
or     $0x80000018,%ebx
mov    %ebx,%edi
mov    $0xcf8,%esi
call   1030 <outl@plt>
mov    $0xcfc,%edi
pop    %rbx
jmp    1040 <inl@plt>
mov    $0xffffffff,%eax
pop    %rbx
ret

LLVM IR (-O0):
define i32 @findDevice(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 %54
30: ; preds = %3
%31 = load i32, i32* %7
%32 = icmp eq i32 %31, 32902
br i1 %32, label %33, label %52
33: ; preds = %30
%34 = load i32, i32* %8
%35 = icmp eq i32 %34, 7680
br i1 %35, label %39, label %36
36: ; preds = %33
%37 = load i32, i32* %8
%38 = icmp eq i32 %37, 7688
br i1 %38, label %39, label %52
39: ; preds = %36, %33
%40 = load i32, i32* %4
%41 = shl i32 %40, 16
%42 = or i32 -2147483648, %41
%43 = load i32, i32* %5
%44 = shl i32 %43, 11
%45 = or i32 %42, %44
%46 = load i32, i32* %6
%47 = shl i32 %46, 8
%48 = or i32 %45, %47
%49 = or i32 %48, 24
%50 = call i32 @outl(i32 %49, i32 3320)
%51 = call i32 @inl(i32 3324)
store i32 %51, i32* %9
br label %53
52: ; preds = %36, %30
store i32 -1, i32* %9
br label %53
53: ; preds = %52, %39
br label %54
54: ; preds = %53, %3
%55 = load i32, i32* %9
ret i32 %55
}

LLVM IR (-O2):
define i32 @findDevice(i32 %0, i32 %1, i32 %2) {
%4 = shl i32 %0, 16
%5 = shl i32 %1, 11
%6 = or i32 %5, %4
%7 = shl i32 %2, 8
%8 = or i32 %6, %7
%9 = or i32 %8, -2147483648
%10 = tail call i32 @outl(i32 %9, i32 3320)
%11 = tail call i32 @inl(i32 3324)
%12 = icmp ne i32 %11, -1
%13 = and i32 %11, -524289
%14 = icmp eq i32 %13, 503349382
%15 = and i1 %12, %14
br i1 %15, label %16, label %20
16: ; preds = %3
%17 = or i32 %8, -2147483624
%18 = tail call i32 @outl(i32 %17, i32 3320)
%19 = tail call i32 @inl(i32 3324)
br label %20
20: ; preds = %16, %3
%21 = phi i32 [ %19, %16 ], [ -1, %3 ]
ret i32 %21
}