#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 /*<<< orphan*/ uint32_t;

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ close(int);
int lseek(int, int, int /*<<< orphan*/);
int open(char *, int /*<<< orphan*/);
int read(int, int /*<<< orphan*/ *, int);
uint32_t read_pci_conf(char *path, int off) {
  int fd = open(path, O_RDONLY);
  assert(fd >= 0);
  assert(lseek(fd, off, SEEK_SET) == 0x150);
  uint32_t v = 0;
  assert(read(fd, &v, 4) == 4);
  close(fd);
  return v;
}


x86 assembly (clang, -O0):
<read_pci_conf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
mov    0x2e7e(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
setge  %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
mov    -0x10(%rbp),%edi
mov    -0xc(%rbp),%esi
mov    0x2e46(%rip),%rax
mov    (%rax),%edx
call   1030 <lseek@plt>
cmp    $0x150,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x10(%rbp),%edi
lea    -0x14(%rbp),%rsi
mov    $0x4,%edx
call   1050 <read@plt>
cmp    $0x4,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
mov    -0x10(%rbp),%edi
call   1040 <close@plt>
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_pci_conf>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
mov    0x2e8c(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
mov    %eax,%ebx
mov    %eax,%edi
not    %edi
shr    $0x1f,%edi
call   1060 <assert@plt>
mov    0x2e60(%rip),%rax
mov    (%rax),%edx
mov    %ebx,%edi
mov    %ebp,%esi
call   1030 <lseek@plt>
xor    %edi,%edi
cmp    $0x150,%eax
sete   %dil
call   1060 <assert@plt>
movl   $0x0,0x4(%rsp)
lea    0x4(%rsp),%rsi
mov    %ebx,%edi
mov    $0x4,%edx
call   1050 <read@plt>
xor    %edi,%edi
cmp    $0x4,%eax
sete   %dil
call   1060 <assert@plt>
mov    %ebx,%edi
call   1040 <close@plt>
mov    0x4(%rsp),%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@O_RDONLY = global i32 0
@SEEK_SET = global i32 0
define i32 @read_pci_conf(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
%7 = load i8*, i8** %3
%8 = load i32, i32* @O_RDONLY
%9 = call i32 @open(i8* %7, i32 %8)
store i32 %9, i32* %5
%10 = load i32, i32* %5
%11 = icmp sge i32 %10, 0
%12 = zext i1 %11 to i32
%13 = call i32 @assert(i32 %12)
%14 = load i32, i32* %5
%15 = load i32, i32* %4
%16 = load i32, i32* @SEEK_SET
%17 = call i32 @lseek(i32 %14, i32 %15, i32 %16)
%18 = icmp eq i32 %17, 336
%19 = zext i1 %18 to i32
%20 = call i32 @assert(i32 %19)
store i32 0, i32* %6
%21 = load i32, i32* %5
%22 = call i32 @read(i32 %21, i32* %6, i32 4)
%23 = icmp eq i32 %22, 4
%24 = zext i1 %23 to i32
%25 = call i32 @assert(i32 %24)
%26 = load i32, i32* %5
%27 = call i32 @close(i32 %26)
%28 = load i32, i32* %6
ret i32 %28
}

LLVM IR (-O2):
@O_RDONLY = global i32 0
@SEEK_SET = global i32 0
define i32 @read_pci_conf(i8* nocapture %0, i32 %1) {
%3 = alloca i32
%4 = load i32, i32* @O_RDONLY
%5 = tail call i32 @open(i8* %0, i32 %4)
%6 = xor i32 %5, -1
%7 = lshr i32 %6, 31
%8 = tail call i32 @assert(i32 %7)
%9 = load i32, i32* @SEEK_SET
%10 = tail call i32 @lseek(i32 %5, i32 %1, i32 %9)
%11 = icmp eq i32 %10, 336
%12 = zext i1 %11 to i32
%13 = tail call i32 @assert(i32 %12)
%14 = bitcast i32* %3 to i8*
store i32 0, i32* %3
%15 = call i32 @read(i32 %5, i32* %3, i32 4)
%16 = icmp eq i32 %15, 4
%17 = zext i1 %16 to i32
%18 = tail call i32 @assert(i32 %17)
%19 = tail call i32 @close(i32 %5)
%20 = load i32, i32* %3
ret i32 %20
}