#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 */
unsigned int read16(unsigned int);
int /*<<< orphan*/ write16(unsigned int, unsigned int);
void write8(unsigned int addr, unsigned int data) {
  unsigned int content;
  content = read16(addr & (~1));
  if (addr & 1) {
    content &= 0x00FF;
    content |= data << 8;
  } else {
    content &= 0xFF00;
    content |= data & 0x00FF;
  }
  write16(addr & (~1), content & 0xFFFF);
}


x86 assembly (clang, -O0):
<write8>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    -0x4(%rbp),%edi
and    $0xfffffffe,%edi
call   1030 <read16@plt>
mov    %eax,-0xc(%rbp)
mov    -0x4(%rbp),%eax
and    $0x1,%eax
cmp    $0x0,%eax
je     1167 <write8+0x47>
mov    -0xc(%rbp),%eax
and    $0xff,%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%eax
shl    $0x8,%eax
or     -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
jmp    1180 <write8+0x60>
mov    -0xc(%rbp),%eax
and    $0xff00,%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%eax
and    $0xff,%eax
or     -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x4(%rbp),%edi
and    $0xfffffffe,%edi
mov    -0xc(%rbp),%esi
and    $0xffff,%esi
call   1040 <write16@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write8>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%ebx
mov    %edi,%ebp
mov    %edi,%r14d
and    $0xfffffffe,%r14d
mov    %r14d,%edi
call   1030 <read16@plt>
test   $0x1,%bpl
jne    1147 <write8+0x27>
and    $0xff00,%eax
movzbl %bl,%ebx
jmp    114d <write8+0x2d>
movzbl %al,%eax
shl    $0x8,%ebx
or     %eax,%ebx
movzwl %bx,%esi
mov    %r14d,%edi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1040 <write16@plt>

LLVM IR (-O0):
define void @write8(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
%6 = load i32, i32* %3
%7 = and i32 %6, -2
%8 = call i32 @read16(i32 %7)
store i32 %8, i32* %5
%9 = load i32, i32* %3
%10 = and i32 %9, 1
%11 = icmp ne i32 %10, 0
br i1 %11, label %12, label %19
12: ; preds = %2
%13 = load i32, i32* %5
%14 = and i32 %13, 255
store i32 %14, i32* %5
%15 = load i32, i32* %4
%16 = shl i32 %15, 8
%17 = load i32, i32* %5
%18 = or i32 %17, %16
store i32 %18, i32* %5
br label %26
19: ; preds = %2
%20 = load i32, i32* %5
%21 = and i32 %20, 65280
store i32 %21, i32* %5
%22 = load i32, i32* %4
%23 = and i32 %22, 255
%24 = load i32, i32* %5
%25 = or i32 %24, %23
store i32 %25, i32* %5
br label %26
26: ; preds = %19, %12
%27 = load i32, i32* %3
%28 = and i32 %27, -2
%29 = load i32, i32* %5
%30 = and i32 %29, 65535
%31 = call i32 @write16(i32 %28, i32 %30)
ret void
}

LLVM IR (-O2):
define void @write8(i32 %0, i32 %1) {
%3 = and i32 %0, -2
%4 = tail call i32 @read16(i32 %3)
%5 = and i32 %0, 1
%6 = icmp eq i32 %5, 0
br i1 %6, label %11, label %7
7: ; preds = %2
%8 = and i32 %4, 255
%9 = shl i32 %1, 8
%10 = or i32 %8, %9
br label %15
11: ; preds = %2
%12 = and i32 %4, 65280
%13 = and i32 %1, 255
%14 = or i32 %12, %13
br label %15
15: ; preds = %11, %7
%16 = phi i32 [ %10, %7 ], [ %14, %11 ]
%17 = and i32 %16, 65535
%18 = tail call i32 @write16(i32 %3, i32 %17)
ret void
}