#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_byte(unsigned char bus, unsigned char slot,
                          unsigned char function, unsigned char offset,
                          unsigned char val) {
  unsigned int v;
  pci_read_config_dword(bus, slot, function, offset & ~3, &v);
  v = (v & ~(0xff << (8 * (offset & 3)))) |
      ((0xff & val) << (8 * (offset & 3)));
  return pci_write_config_dword(bus, slot, function, offset & ~3, v);
}


x86 assembly (clang, -O0):
<pci_write_config_byte>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %r8b,%al
mov    %dil,-0x1(%rbp)
mov    %sil,-0x2(%rbp)
mov    %dl,-0x3(%rbp)
mov    %cl,-0x4(%rbp)
mov    %al,-0x5(%rbp)
mov    -0x1(%rbp),%sil
mov    -0x2(%rbp),%dl
mov    -0x3(%rbp),%cl
movzbl -0x4(%rbp),%eax
and    $0xfffffffc,%eax
lea    -0xc(%rbp),%r8
movzbl %sil,%edi
movzbl %dl,%esi
movzbl %cl,%edx
movzbl %al,%ecx
call   1030 <pci_read_config_dword@plt>
mov    -0xc(%rbp),%eax
movzbl -0x4(%rbp),%ecx
and    $0x3,%ecx
shl    $0x3,%ecx
mov    $0xff,%edx
shl    %cl,%edx
mov    %edx,%ecx
xor    $0xffffffff,%ecx
and    %ecx,%eax
movzbl -0x5(%rbp),%edx
and    $0xff,%edx
movzbl -0x4(%rbp),%ecx
and    $0x3,%ecx
shl    $0x3,%ecx
shl    %cl,%edx
mov    %edx,%ecx
or     %ecx,%eax
mov    %eax,-0xc(%rbp)
mov    -0x1(%rbp),%sil
mov    -0x2(%rbp),%dl
mov    -0x3(%rbp),%cl
movzbl -0x4(%rbp),%eax
and    $0xfffffffc,%eax
mov    -0xc(%rbp),%r8d
movzbl %sil,%edi
movzbl %dl,%esi
movzbl %cl,%edx
movzbl %al,%ecx
call   1040 <pci_write_config_dword@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pci_write_config_byte>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r8d,%ebx
mov    %ecx,%r13d
mov    %edx,%r14d
mov    %esi,%r15d
mov    %edi,%r12d
mov    %ecx,%ebp
and    $0xfffffffc,%ebp
lea    0x4(%rsp),%r8
mov    %ebp,%ecx
call   1030 <pci_read_config_dword@plt>
lea    0x0(,%r13,8),%ecx
mov    $0xff,%eax
shl    %cl,%eax
not    %eax
shl    %cl,%ebx
and    0x4(%rsp),%eax
or     %eax,%ebx
mov    %ebx,0x4(%rsp)
mov    %r12d,%edi
mov    %r15d,%esi
mov    %r14d,%edx
mov    %ebp,%ecx
mov    %ebx,%r8d
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_byte(i8 zeroext %0, i8 zeroext %1, i8 zeroext %2, i8 zeroext %3, i8 zeroext %4) {
%6 = alloca i8
%7 = alloca i8
%8 = alloca i8
%9 = alloca i8
%10 = alloca i8
%11 = alloca i32
store i8 %0, i8* %6
store i8 %1, i8* %7
store i8 %2, i8* %8
store i8 %3, i8* %9
store i8 %4, i8* %10
%12 = load i8, i8* %6
%13 = load i8, i8* %7
%14 = load i8, i8* %8
%15 = load i8, i8* %9
%16 = zext i8 %15 to i32
%17 = and i32 %16, -4
%18 = trunc i32 %17 to i8
%19 = call i32 @pci_read_config_dword(i8 zeroext %12, i8 zeroext %13, i8 zeroext %14, i8 zeroext %18, i32* %11)
%20 = load i32, i32* %11
%21 = load i8, i8* %9
%22 = zext i8 %21 to i32
%23 = and i32 %22, 3
%24 = mul nsw i32 8, %23
%25 = shl i32 255, %24
%26 = xor i32 %25, -1
%27 = and i32 %20, %26
%28 = load i8, i8* %10
%29 = zext i8 %28 to i32
%30 = and i32 255, %29
%31 = load i8, i8* %9
%32 = zext i8 %31 to i32
%33 = and i32 %32, 3
%34 = mul nsw i32 8, %33
%35 = shl i32 %30, %34
%36 = or i32 %27, %35
store i32 %36, i32* %11
%37 = load i8, i8* %6
%38 = load i8, i8* %7
%39 = load i8, i8* %8
%40 = load i8, i8* %9
%41 = zext i8 %40 to i32
%42 = and i32 %41, -4
%43 = trunc i32 %42 to i8
%44 = load i32, i32* %11
%45 = call i32 @pci_write_config_dword(i8 zeroext %37, i8 zeroext %38, i8 zeroext %39, i8 zeroext %43, i32 %44)
ret i32 %45
}

LLVM IR (-O2):
define i32 @pci_write_config_byte(i8 zeroext %0, i8 zeroext %1, i8 zeroext %2, i8 zeroext %3, i8 zeroext %4) {
%6 = alloca i32
%7 = bitcast i32* %6 to i8*
%8 = and i8 %3, -4
%9 = call i32 @pci_read_config_dword(i8 zeroext %0, i8 zeroext %1, i8 zeroext %2, i8 zeroext %8, i32* %6)
%10 = load i32, i32* %6
%11 = shl i8 %3, 3
%12 = and i8 %11, 24
%13 = zext i8 %12 to i32
%14 = shl nuw i32 255, %13
%15 = xor i32 %14, -1
%16 = and i32 %10, %15
%17 = zext i8 %4 to i32
%18 = shl nuw i32 %17, %13
%19 = or i32 %16, %18
store i32 %19, i32* %6
%20 = call i32 @pci_write_config_dword(i8 zeroext %0, i8 zeroext %1, i8 zeroext %2, i8 zeroext %8, i32 %19)
ret i32 %20
}