#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;

/* Variables and functions */
scalar_t__ pci_read_cfgw(int, int, int);
uint32_t pci_read_config_dword(uint8_t bus, uint8_t dev_fn, uint8_t reg) {
  return pci_read_cfgw((0xb1 << 8) | 0x09, (bus << 8) | dev_fn, reg) ||
         ((uint32_t)pci_read_cfgw((0xb1 << 8) | 0x09, (bus << 8) | dev_fn,
                                  reg + 2)
          << 16);
}


x86 assembly (clang, -O0):
<pci_read_config_dword>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    -0x4(%rbp),%esi
shl    $0x8,%esi
or     -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
mov    $0xb109,%edi
call   1030 <pci_read_cfgw@plt>
mov    %rax,%rcx
mov    $0x1,%al
cmp    $0x0,%rcx
mov    %al,-0xd(%rbp)
jne    116e <pci_read_config_dword+0x5e>
mov    -0x4(%rbp),%esi
shl    $0x8,%esi
or     -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
add    $0x2,%edx
mov    $0xb109,%edi
call   1030 <pci_read_cfgw@plt>
shl    $0x10,%eax
cmp    $0x0,%eax
setne  %al
mov    %al,-0xd(%rbp)
mov    -0xd(%rbp),%al
and    $0x1,%al
movzbl %al,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pci_read_config_dword>:
push   %rbp
push   %rbx
push   %rax
mov    %edx,%ebx
mov    %esi,%ebp
shl    $0x8,%edi
or     %edi,%ebp
mov    $0xb109,%edi
mov    %ebp,%esi
call   1030 <pci_read_cfgw@plt>
mov    %rax,%rcx
mov    $0x1,%eax
test   %rcx,%rcx
jne    1151 <pci_read_config_dword+0x41>
add    $0x2,%ebx
mov    $0xb109,%edi
mov    %ebp,%esi
mov    %ebx,%edx
call   1030 <pci_read_cfgw@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %cx,%cx
setne  %al
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i32 @pci_read_config_dword(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%7 = load i32, i32* %4
%8 = shl i32 %7, 8
%9 = load i32, i32* %5
%10 = or i32 %8, %9
%11 = load i32, i32* %6
%12 = call i64 @pci_read_cfgw(i32 45321, i32 %10, i32 %11)
%13 = icmp ne i64 %12, 0
br i1 %13, label %25, label %14
14: ; preds = %3
%15 = load i32, i32* %4
%16 = shl i32 %15, 8
%17 = load i32, i32* %5
%18 = or i32 %16, %17
%19 = load i32, i32* %6
%20 = add nsw i32 %19, 2
%21 = call i64 @pci_read_cfgw(i32 45321, i32 %18, i32 %20)
%22 = trunc i64 %21 to i32
%23 = shl i32 %22, 16
%24 = icmp ne i32 %23, 0
br label %25
25: ; preds = %14, %3
%26 = phi i1 [ true, %3 ], [ %24, %14 ]
%27 = zext i1 %26 to i32
ret i32 %27
}

LLVM IR (-O2):
define i32 @pci_read_config_dword(i32 %0, i32 %1, i32 %2) {
%4 = shl i32 %0, 8
%5 = or i32 %4, %1
%6 = tail call i64 @pci_read_cfgw(i32 45321, i32 %5, i32 %2)
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %14
8: ; preds = %3
%9 = add nsw i32 %2, 2
%10 = tail call i64 @pci_read_cfgw(i32 45321, i32 %5, i32 %9)
%11 = and i64 %10, 65535
%12 = icmp ne i64 %11, 0
%13 = zext i1 %12 to i32
br label %14
14: ; preds = %8, %3
%15 = phi i32 [ 1, %3 ], [ %13, %8 ]
ret i32 %15
}