#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 */

/* Variables and functions */
int /*<<< orphan*/ pci_read_config_dword(unsigned char, unsigned char,
                                         unsigned char, unsigned char,
                                         unsigned int *);
int pci_write_config_dword(unsigned char, unsigned char, unsigned char,
                           unsigned char, unsigned int);
int pci_write_config_word(unsigned char bus, unsigned char slot,
                          unsigned char function, unsigned char offset,
                          unsigned short val) {
  unsigned int v;
  if (offset & 1)
    return 0x87;
  pci_read_config_dword(bus, slot, function, offset & ~3, &v);
  v = (v & ~(0xffff << (8 * (offset & 3)))) |
      ((0xffff & val) << (8 * (offset & 3)));
  return pci_write_config_dword(bus, slot, function, offset & ~3, v);
}


x86 assembly (clang, -O0):
<pci_write_config_word>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %r8w,%ax
mov    %dil,-0x5(%rbp)
mov    %sil,-0x6(%rbp)
mov    %dl,-0x7(%rbp)
mov    %cl,-0x8(%rbp)
mov    %ax,-0xa(%rbp)
movzbl -0x8(%rbp),%eax
and    $0x1,%eax
cmp    $0x0,%eax
je     115a <pci_write_config_word+0x3a>
movl   $0x87,-0x4(%rbp)
jmp    11e3 <pci_write_config_word+0xc3>
mov    -0x5(%rbp),%sil
mov    -0x6(%rbp),%dl
mov    -0x7(%rbp),%cl
movzbl -0x8(%rbp),%eax
and    $0xfffffffc,%eax
lea    -0x10(%rbp),%r8
movzbl %sil,%edi
movzbl %dl,%esi
movzbl %cl,%edx
movzbl %al,%ecx
call   1030 <pci_read_config_dword@plt>
mov    -0x10(%rbp),%eax
movzbl -0x8(%rbp),%ecx
and    $0x3,%ecx
shl    $0x3,%ecx
mov    $0xffff,%edx
shl    %cl,%edx
mov    %edx,%ecx
xor    $0xffffffff,%ecx
and    %ecx,%eax
movzwl -0xa(%rbp),%edx
and    $0xffff,%edx
movzbl -0x8(%rbp),%ecx
and    $0x3,%ecx
shl    $0x3,%ecx
shl    %cl,%edx
mov    %edx,%ecx
or     %ecx,%eax
mov    %eax,-0x10(%rbp)
mov    -0x5(%rbp),%sil
mov    -0x6(%rbp),%dl
mov    -0x7(%rbp),%cl
movzbl -0x8(%rbp),%eax
and    $0xfffffffc,%eax
mov    -0x10(%rbp),%r8d
movzbl %sil,%edi
movzbl %dl,%esi
movzbl %cl,%edx
movzbl %al,%ecx
call   1040 <pci_write_config_dword@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pci_write_config_word>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %ecx,%ebp
mov    $0x87,%eax
test   $0x1,%bpl
jne    1195 <pci_write_config_word+0x75>
mov    %r8d,%r14d
mov    %ebp,%eax
and    $0xfc,%al
movzbl %dil,%ebx
movzbl %sil,%r15d
movzbl %dl,%r12d
movzbl %al,%r13d
lea    0x4(%rsp),%r8
mov    %ebx,%edi
mov    %r15d,%esi
mov    %r12d,%edx
mov    %r13d,%ecx
call   1030 <pci_read_config_dword@plt>
shl    $0x3,%ebp
mov    $0xffff,%eax
mov    %ebp,%ecx
shl    %cl,%eax
not    %eax
movzwl %r14w,%r8d
shl    %cl,%r8d
and    0x4(%rsp),%eax
or     %eax,%r8d
mov    %r8d,0x4(%rsp)
mov    %ebx,%edi
mov    %r15d,%esi
mov    %r12d,%edx
mov    %r13d,%ecx
call   1040 <pci_write_config_dword@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @pci_write_config_word(i8 zeroext %0, i8 zeroext %1, i8 zeroext %2, i8 zeroext %3, i16 zeroext %4) {
%6 = alloca i32
%7 = alloca i8
%8 = alloca i8
%9 = alloca i8
%10 = alloca i8
%11 = alloca i16
%12 = alloca i32
store i8 %0, i8* %7
store i8 %1, i8* %8
store i8 %2, i8* %9
store i8 %3, i8* %10
store i16 %4, i16* %11
%13 = load i8, i8* %10
%14 = zext i8 %13 to i32
%15 = and i32 %14, 1
%16 = icmp ne i32 %15, 0
br i1 %16, label %17, label %18
17: ; preds = %5
store i32 135, i32* %6
br label %53
18: ; preds = %5
%19 = load i8, i8* %7
%20 = load i8, i8* %8
%21 = load i8, i8* %9
%22 = load i8, i8* %10
%23 = zext i8 %22 to i32
%24 = and i32 %23, -4
%25 = trunc i32 %24 to i8
%26 = call i32 @pci_read_config_dword(i8 zeroext %19, i8 zeroext %20, i8 zeroext %21, i8 zeroext %25, i32* %12)
%27 = load i32, i32* %12
%28 = load i8, i8* %10
%29 = zext i8 %28 to i32
%30 = and i32 %29, 3
%31 = mul nsw i32 8, %30
%32 = shl i32 65535, %31
%33 = xor i32 %32, -1
%34 = and i32 %27, %33
%35 = load i16, i16* %11
%36 = zext i16 %35 to i32
%37 = and i32 65535, %36
%38 = load i8, i8* %10
%39 = zext i8 %38 to i32
%40 = and i32 %39, 3
%41 = mul nsw i32 8, %40
%42 = shl i32 %37, %41
%43 = or i32 %34, %42
store i32 %43, i32* %12
%44 = load i8, i8* %7
%45 = load i8, i8* %8
%46 = load i8, i8* %9
%47 = load i8, i8* %10
%48 = zext i8 %47 to i32
%49 = and i32 %48, -4
%50 = trunc i32 %49 to i8
%51 = load i32, i32* %12
%52 = call i32 @pci_write_config_dword(i8 zeroext %44, i8 zeroext %45, i8 zeroext %46, i8 zeroext %50, i32 %51)
store i32 %52, i32* %6
br label %53
53: ; preds = %18, %17
%54 = load i32, i32* %6
ret i32 %54
}

LLVM IR (-O2):
define i32 @pci_write_config_word(i8 zeroext %0, i8 zeroext %1, i8 zeroext %2, i8 zeroext %3, i16 zeroext %4) {
%6 = alloca i32
%7 = bitcast i32* %6 to i8*
%8 = zext i8 %3 to i32
%9 = and i32 %8, 1
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %24
11: ; preds = %5
%12 = and i8 %3, -4
%13 = call i32 @pci_read_config_dword(i8 zeroext %0, i8 zeroext %1, i8 zeroext %2, i8 zeroext %12, i32* %6)
%14 = load i32, i32* %6
%15 = shl nuw nsw i32 %8, 3
%16 = and i32 %15, 24
%17 = shl i32 65535, %16
%18 = xor i32 %17, -1
%19 = and i32 %14, %18
%20 = zext i16 %4 to i32
%21 = shl i32 %20, %16
%22 = or i32 %19, %21
store i32 %22, i32* %6
%23 = call i32 @pci_write_config_dword(i8 zeroext %0, i8 zeroext %1, i8 zeroext %2, i8 zeroext %12, i32 %22)
br label %24
24: ; preds = %5, %11
%25 = phi i32 [ %23, %11 ], [ 135, %5 ]
ret i32 %25
}