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

/* Variables and functions */
int /*<<< orphan*/ _mm_loadu_si128(int /*<<< orphan*/ *);
int /*<<< orphan*/ _mm_store_si128(int /*<<< orphan*/ *, int /*<<< orphan*/);
void fastcopy_sse2_16(uint8_t *__restrict dest, const uint8_t *__restrict src,
                      int n) {
  for (; ((intptr_t)dest & 15) && (n > 0); n--) {
    *dest++ = *src++;
  }
  for (; n >= 16; n -= 16) {
    _mm_store_si128((__m128i *)dest, _mm_loadu_si128((__m128i *)src));
    src += 16;
    dest += 16;
  }
  for (; n > 0; n--) {
    *dest++ = *src++;
  }
}


x86 assembly (clang, -O0):
<fastcopy_sse2_16>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x8(%rbp),%rcx
and    $0xf,%rcx
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x15(%rbp)
je     1154 <fastcopy_sse2_16+0x34>
cmpl   $0x0,-0x14(%rbp)
setg   %al
mov    %al,-0x15(%rbp)
mov    -0x15(%rbp),%al
test   $0x1,%al
jne    1164 <fastcopy_sse2_16+0x44>
jmp    1194 <fastcopy_sse2_16+0x74>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x4,%rcx
mov    %rcx,-0x10(%rbp)
mov    (%rax),%ecx
mov    -0x8(%rbp),%rax
mov    %rax,%rdx
add    $0x4,%rdx
mov    %rdx,-0x8(%rbp)
mov    %ecx,(%rax)
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
jmp    1133 <fastcopy_sse2_16+0x13>
jmp    1199 <fastcopy_sse2_16+0x79>
cmpl   $0x10,-0x14(%rbp)
jl     11e5 <fastcopy_sse2_16+0xc5>
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <_mm_loadu_si128@plt>
mov    -0x20(%rbp),%rdi
mov    %eax,%esi
call   1030 <_mm_store_si128@plt>
mov    -0x10(%rbp),%rax
add    $0x40,%rax
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rax
mov    %rax,-0x8(%rbp)
mov    -0x14(%rbp),%eax
sub    $0x10,%eax
mov    %eax,-0x14(%rbp)
jmp    1199 <fastcopy_sse2_16+0x79>
jmp    11ea <fastcopy_sse2_16+0xca>
cmpl   $0x0,-0x14(%rbp)
jle    1224 <fastcopy_sse2_16+0x104>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x4,%rcx
mov    %rcx,-0x10(%rbp)
mov    (%rax),%ecx
mov    -0x8(%rbp),%rax
mov    %rax,%rdx
add    $0x4,%rdx
mov    %rdx,-0x8(%rbp)
mov    %ecx,(%rax)
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
jmp    11ea <fastcopy_sse2_16+0xca>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fastcopy_sse2_16>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
test   $0xf,%r15b
je     1177 <fastcopy_sse2_16+0x47>
test   %edx,%edx
jle    1177 <fastcopy_sse2_16+0x47>
lea    0x4(%r15),%rax
nopl   0x0(%rax)
mov    (%r14),%ecx
add    $0x4,%r14
mov    %ecx,(%r15)
add    $0x4,%r15
lea    -0x1(%rdx),%ebx
test   $0xf,%al
je     1170 <fastcopy_sse2_16+0x40>
add    $0x4,%rax
cmp    $0x1,%edx
mov    %ebx,%edx
ja     1150 <fastcopy_sse2_16+0x20>
cmp    $0x10,%ebx
jge    1180 <fastcopy_sse2_16+0x50>
jmp    11bf <fastcopy_sse2_16+0x8f>
mov    %edx,%ebx
cmp    $0x10,%ebx
jl     11bf <fastcopy_sse2_16+0x8f>
xchg   %ax,%ax
mov    %r14,%rdi
call   1050 <_mm_loadu_si128@plt>
mov    %r15,%rdi
mov    %eax,%esi
call   1030 <_mm_store_si128@plt>
add    $0x40,%r14
add    $0x40,%r15
lea    -0x10(%rbx),%eax
cmp    $0x1f,%ebx
mov    %eax,%ebx
ja     1180 <fastcopy_sse2_16+0x50>
test   %eax,%eax
jle    11b9 <fastcopy_sse2_16+0x89>
mov    %eax,%edx
shl    $0x2,%rdx
mov    %r15,%rdi
mov    %r14,%rsi
call   1040 <memcpy@plt>
pop    %rbx
pop    %r14
pop    %r15
ret
mov    %ebx,%eax
test   %eax,%eax
jg     11a8 <fastcopy_sse2_16+0x78>
jmp    11b9 <fastcopy_sse2_16+0x89>

LLVM IR (-O0):
define void @fastcopy_sse2_16(i32* noalias %0, i32* noalias %1, i32 %2) {
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca i32
store i32* %0, i32** %4
store i32* %1, i32** %5
store i32 %2, i32* %6
br label %7
7: ; preds = %23, %3
%8 = load i32*, i32** %4
%9 = ptrtoint i32* %8 to i64
%10 = and i64 %9, 15
%11 = icmp ne i64 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %7
%13 = load i32, i32* %6
%14 = icmp sgt i32 %13, 0
br label %15
15: ; preds = %12, %7
%16 = phi i1 [ false, %7 ], [ %14, %12 ]
br i1 %16, label %17, label %26
17: ; preds = %15
%18 = load i32*, i32** %5
%19 = getelementptr inbounds i32, i32* %18, i32 1
store i32* %19, i32** %5
%20 = load i32, i32* %18
%21 = load i32*, i32** %4
%22 = getelementptr inbounds i32, i32* %21, i32 1
store i32* %22, i32** %4
store i32 %20, i32* %21
br label %23
23: ; preds = %17
%24 = load i32, i32* %6
%25 = add nsw i32 %24, -1
store i32 %25, i32* %6
br label %7
26: ; preds = %15
br label %27
27: ; preds = %39, %26
%28 = load i32, i32* %6
%29 = icmp sge i32 %28, 16
br i1 %29, label %30, label %42
30: ; preds = %27
%31 = load i32*, i32** %4
%32 = load i32*, i32** %5
%33 = call i32 @_mm_loadu_si128(i32* %32)
%34 = call i32 @_mm_store_si128(i32* %31, i32 %33)
%35 = load i32*, i32** %5
%36 = getelementptr inbounds i32, i32* %35, i64 16
store i32* %36, i32** %5
%37 = load i32*, i32** %4
%38 = getelementptr inbounds i32, i32* %37, i64 16
store i32* %38, i32** %4
br label %39
39: ; preds = %30
%40 = load i32, i32* %6
%41 = sub nsw i32 %40, 16
store i32 %41, i32* %6
br label %27
42: ; preds = %27
br label %43
43: ; preds = %52, %42
%44 = load i32, i32* %6
%45 = icmp sgt i32 %44, 0
br i1 %45, label %46, label %55
46: ; preds = %43
%47 = load i32*, i32** %5
%48 = getelementptr inbounds i32, i32* %47, i32 1
store i32* %48, i32** %5
%49 = load i32, i32* %47
%50 = load i32*, i32** %4
%51 = getelementptr inbounds i32, i32* %50, i32 1
store i32* %51, i32** %4
store i32 %49, i32* %50
br label %52
52: ; preds = %46
%53 = load i32, i32* %6
%54 = add nsw i32 %53, -1
store i32 %54, i32* %6
br label %43
55: ; preds = %43
ret void
}

LLVM IR (-O2):
define void @fastcopy_sse2_16(i32* noalias %0, i32* noalias %1, i32 %2) {
%4 = ptrtoint i32* %0 to i64
%5 = and i64 %4, 15
%6 = icmp ne i64 %5, 0
%7 = icmp sgt i32 %2, 0
%8 = and i1 %6, %7
br i1 %8, label %14, label %9
9: ; preds = %14, %3
%10 = phi i32* [ %0, %3 ], [ %20, %14 ]
%11 = phi i32* [ %1, %3 ], [ %18, %14 ]
%12 = phi i32 [ %2, %3 ], [ %21, %14 ]
%13 = icmp sgt i32 %12, 15
br i1 %13, label %37, label %27
14: ; preds = %3, %14
%15 = phi i32 [ %21, %14 ], [ %2, %3 ]
%16 = phi i32* [ %18, %14 ], [ %1, %3 ]
%17 = phi i32* [ %20, %14 ], [ %0, %3 ]
%18 = getelementptr inbounds i32, i32* %16, i64 1
%19 = load i32, i32* %16
%20 = getelementptr inbounds i32, i32* %17, i64 1
store i32 %19, i32* %17
%21 = add nsw i32 %15, -1
%22 = ptrtoint i32* %20 to i64
%23 = and i64 %22, 15
%24 = icmp ne i64 %23, 0
%25 = icmp ugt i32 %15, 1
%26 = select i1 %24, i1 %25, i1 false
br i1 %26, label %14, label %9
27: ; preds = %37, %9
%28 = phi i32* [ %10, %9 ], [ %44, %37 ]
%29 = phi i32* [ %11, %9 ], [ %43, %37 ]
%30 = phi i32 [ %12, %9 ], [ %45, %37 ]
%31 = icmp sgt i32 %30, 0
br i1 %31, label %32, label %47
32: ; preds = %27
%33 = bitcast i32* %29 to i8*
%34 = bitcast i32* %28 to i8*
%35 = zext i32 %30 to i64
%36 = shl nuw nsw i64 %35, 2
br label %47
37: ; preds = %9, %37
%38 = phi i32 [ %45, %37 ], [ %12, %9 ]
%39 = phi i32* [ %43, %37 ], [ %11, %9 ]
%40 = phi i32* [ %44, %37 ], [ %10, %9 ]
%41 = tail call i32 @_mm_loadu_si128(i32* %39)
%42 = tail call i32 @_mm_store_si128(i32* %40, i32 %41)
%43 = getelementptr inbounds i32, i32* %39, i64 16
%44 = getelementptr inbounds i32, i32* %40, i64 16
%45 = add nsw i32 %38, -16
%46 = icmp ugt i32 %38, 31
br i1 %46, label %37, label %27
47: ; preds = %32, %27
ret void
}