#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*/ __byte_memcpy(void *, void const *, size_t);
int /*<<< orphan*/ __int_memcpy(void *, void const *, size_t);
int /*<<< orphan*/ __shrt_int_memcpy(void *, void const *, size_t);
void *memcpy(void *__restrict s1, const void *__restrict s2, size_t n) {
  void *result = s1;
  if (n != 0) {
    unsigned test = (unsigned)s2 | (unsigned)s1 | (unsigned)n;
    if (test & 1)
      __byte_memcpy(s1, s2, n);
    else if (test & 2)
      __shrt_int_memcpy(s1, s2, n >> 1);
    else
      __int_memcpy(s1, s2, n >> 2);
  }
  return result;
}


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    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11d7 <memcpy+0xa7>
mov    -0x10(%rbp),%rax
mov    -0x8(%rbp),%rcx
or     %ecx,%eax
mov    -0x18(%rbp),%rcx
or     %ecx,%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
and    $0x1,%eax
cmp    $0x0,%eax
je     118f <memcpy+0x5f>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1050 <__byte_memcpy@plt>
jmp    11d2 <memcpy+0xa2>
mov    -0x24(%rbp),%eax
and    $0x2,%eax
cmp    $0x0,%eax
je     11b8 <memcpy+0x88>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
shr    $0x1,%rdx
call   1040 <__shrt_int_memcpy@plt>
jmp    11cd <memcpy+0x9d>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
shr    $0x2,%rdx
call   1030 <__int_memcpy@plt>
jmp    11d2 <memcpy+0xa2>
jmp    11d7 <memcpy+0xa7>
mov    -0x20(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<memcpy>:
push   %rbx
mov    %rdi,%rbx
test   %rdx,%rdx
je     116c <memcpy+0x3c>
mov    %esi,%ecx
or     %ebx,%ecx
mov    %edx,%eax
or     %ecx,%eax
test   $0x1,%al
jne    1157 <memcpy+0x27>
test   $0x2,%al
jne    1161 <memcpy+0x31>
shr    $0x2,%rdx
mov    %rbx,%rdi
call   1030 <__int_memcpy@plt>
jmp    116c <memcpy+0x3c>
mov    %rbx,%rdi
call   1050 <__byte_memcpy@plt>
jmp    116c <memcpy+0x3c>
shr    %rdx
mov    %rbx,%rdi
call   1040 <__shrt_int_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 i8*
%8 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i64 %2, i64* %6
%9 = load i8*, i8** %4
store i8* %9, i8** %7
%10 = load i64, i64* %6
%11 = icmp ne i64 %10, 0
br i1 %11, label %12, label %47
12: ; preds = %3
%13 = load i8*, i8** %5
%14 = ptrtoint i8* %13 to i32
%15 = load i8*, i8** %4
%16 = ptrtoint i8* %15 to i32
%17 = or i32 %14, %16
%18 = load i64, i64* %6
%19 = trunc i64 %18 to i32
%20 = or i32 %17, %19
store i32 %20, i32* %8
%21 = load i32, i32* %8
%22 = and i32 %21, 1
%23 = icmp ne i32 %22, 0
br i1 %23, label %24, label %29
24: ; preds = %12
%25 = load i8*, i8** %4
%26 = load i8*, i8** %5
%27 = load i64, i64* %6
%28 = call i32 @__byte_memcpy(i8* %25, i8* %26, i64 %27)
br label %46
29: ; preds = %12
%30 = load i32, i32* %8
%31 = and i32 %30, 2
%32 = icmp ne i32 %31, 0
br i1 %32, label %33, label %39
33: ; preds = %29
%34 = load i8*, i8** %4
%35 = load i8*, i8** %5
%36 = load i64, i64* %6
%37 = lshr i64 %36, 1
%38 = call i32 @__shrt_int_memcpy(i8* %34, i8* %35, i64 %37)
br label %45
39: ; preds = %29
%40 = load i8*, i8** %4
%41 = load i8*, i8** %5
%42 = load i64, i64* %6
%43 = lshr i64 %42, 2
%44 = call i32 @__int_memcpy(i8* %40, i8* %41, i64 %43)
br label %45
45: ; preds = %39, %33
br label %46
46: ; preds = %45, %24
br label %47
47: ; preds = %46, %3
%48 = load i8*, i8** %7
ret i8* %48
}

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