#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*/ uint8_t;
typedef int /*<<< orphan*/ uint16_t;

/* Variables and functions */
int /*<<< orphan*/ __byte_memcpy(int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                                 size_t);
int /*<<< orphan*/ __word_memcpy(int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                                 size_t);
void *memcpy(void *restrict dest, const void *restrict src, size_t n) {
#pragma GCC diagnostic ignored "-Wpointer-to-int-cast"
  size_t src_as_num = (size_t)src, dest_as_num = (size_t)dest;
#pragma GCC diagnostic pop
  if (0b1 & (src_as_num | dest_as_num | n))
    __byte_memcpy((uint8_t *)dest, (uint8_t *)src, n);
  else
    __word_memcpy((uint16_t *)dest, (uint16_t *)src, n >> 1);
  return dest;
}


x86 assembly (clang, -O0):
<memcpy>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rax
or     -0x28(%rbp),%rax
or     -0x18(%rbp),%rax
and    $0x1,%rax
cmp    $0x0,%rax
je     1174 <memcpy+0x54>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1030 <__byte_memcpy@plt>
jmp    1189 <memcpy+0x69>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
shr    $0x1,%rdx
call   1040 <__word_memcpy@plt>
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<memcpy>:
push   %rbx
mov    %rdi,%rbx
mov    %esi,%eax
or     %ebx,%eax
mov    %edx,%ecx
or     %eax,%ecx
test   $0x1,%cl
jne    113e <memcpy+0x1e>
shr    %rdx
mov    %rbx,%rdi
call   1040 <__word_memcpy@plt>
jmp    1146 <memcpy+0x26>
mov    %rbx,%rdi
call   1030 <__byte_memcpy@plt>
mov    %rbx,%rax
pop    %rbx
ret

LLVM IR (-O0):
define i8* @memcpy(i8* noalias %0, i8* noalias %1, i64 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i64
%8 = alloca i64
store i8* %0, i8** %4
store i8* %1, i8** %5
store i64 %2, i64* %6
%9 = load i8*, i8** %5
%10 = ptrtoint i8* %9 to i64
store i64 %10, i64* %7
%11 = load i8*, i8** %4
%12 = ptrtoint i8* %11 to i64
store i64 %12, i64* %8
%13 = load i64, i64* %7
%14 = load i64, i64* %8
%15 = or i64 %13, %14
%16 = load i64, i64* %6
%17 = or i64 %15, %16
%18 = and i64 1, %17
%19 = icmp ne i64 %18, 0
br i1 %19, label %20, label %27
20: ; preds = %3
%21 = load i8*, i8** %4
%22 = bitcast i8* %21 to i32*
%23 = load i8*, i8** %5
%24 = bitcast i8* %23 to i32*
%25 = load i64, i64* %6
%26 = call i32 @__byte_memcpy(i32* %22, i32* %24, i64 %25)
br label %35
27: ; preds = %3
%28 = load i8*, i8** %4
%29 = bitcast i8* %28 to i32*
%30 = load i8*, i8** %5
%31 = bitcast i8* %30 to i32*
%32 = load i64, i64* %6
%33 = lshr i64 %32, 1
%34 = call i32 @__word_memcpy(i32* %29, i32* %31, i64 %33)
br label %35
35: ; preds = %27, %20
%36 = load i8*, i8** %4
ret i8* %36
}

LLVM IR (-O2):
define i8* @memcpy(i8* noalias returned %0, i8* noalias %1, i64 %2) {
%4 = ptrtoint i8* %1 to i64
%5 = ptrtoint i8* %0 to i64
%6 = or i64 %4, %5
%7 = or i64 %6, %2
%8 = and i64 %7, 1
%9 = icmp eq i64 %8, 0
%10 = bitcast i8* %0 to i32*
%11 = bitcast i8* %1 to i32*
br i1 %9, label %14, label %12
12: ; preds = %3
%13 = tail call i32 @__byte_memcpy(i32* %10, i32* %11, i64 %2)
br label %17
14: ; preds = %3
%15 = lshr i64 %2, 1
%16 = tail call i32 @__word_memcpy(i32* %10, i32* %11, i64 %15)
br label %17
17: ; preds = %14, %12
ret i8* %0
}