#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_32(uint8_t *__restrict dest, const uint8_t *__restrict src,
                      int n) {
  for (; ((long)dest & 15) && (n > 0); n--) {
    *dest++ = *src++;
  }
  for (; n >= 32; n -= 32) {
    _mm_store_si128((__m128i *)dest, _mm_loadu_si128((__m128i *)src));
    _mm_store_si128((__m128i *)(dest + 16),
                    _mm_loadu_si128((__m128i *)(src + 16)));
    src += 32;
    dest += 32;
  }
  if (n >= 16) {
    _mm_store_si128((__m128i *)dest, _mm_loadu_si128((__m128i *)src));
    src += 16;
    dest += 16;
    n -= 16;
  }
  for (; n > 0; n--) {
    *dest++ = *src++;
  }
}


x86 assembly (clang, -O0):
<fastcopy_sse2_32>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%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_32+0x34>
cmpl   $0x0,-0x14(%rbp)
setg   %al
mov    %al,-0x15(%rbp)
mov    -0x15(%rbp),%al
test   $0x1,%al
jne    1164 <fastcopy_sse2_32+0x44>
jmp    1194 <fastcopy_sse2_32+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_32+0x13>
jmp    1199 <fastcopy_sse2_32+0x79>
cmpl   $0x20,-0x14(%rbp)
jl     120d <fastcopy_sse2_32+0xed>
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <_mm_loadu_si128@plt>
mov    -0x28(%rbp),%rdi
mov    %eax,%esi
call   1030 <_mm_store_si128@plt>
mov    -0x8(%rbp),%rax
add    $0x40,%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
add    $0x40,%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    $0x80,%rax
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
add    $0x80,%rax
mov    %rax,-0x8(%rbp)
mov    -0x14(%rbp),%eax
sub    $0x20,%eax
mov    %eax,-0x14(%rbp)
jmp    1199 <fastcopy_sse2_32+0x79>
cmpl   $0x10,-0x14(%rbp)
jl     1254 <fastcopy_sse2_32+0x134>
mov    -0x8(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <_mm_loadu_si128@plt>
mov    -0x30(%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    1259 <fastcopy_sse2_32+0x139>
cmpl   $0x0,-0x14(%rbp)
jle    1293 <fastcopy_sse2_32+0x173>
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    1259 <fastcopy_sse2_32+0x139>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fastcopy_sse2_32>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
test   $0xf,%bl
je     1171 <fastcopy_sse2_32+0x41>
test   %edx,%edx
jle    1171 <fastcopy_sse2_32+0x41>
lea    0x4(%rbx),%rax
nopw   0x0(%rax,%rax,1)
mov    (%r14),%ecx
add    $0x4,%r14
mov    %ecx,(%rbx)
add    $0x4,%rbx
lea    -0x1(%rdx),%ebp
test   $0xf,%al
je     1173 <fastcopy_sse2_32+0x43>
add    $0x4,%rax
cmp    $0x1,%edx
mov    %ebp,%edx
ja     1150 <fastcopy_sse2_32+0x20>
jmp    1173 <fastcopy_sse2_32+0x43>
mov    %edx,%ebp
cmp    $0x20,%ebp
jl     11bb <fastcopy_sse2_32+0x8b>
nopl   0x0(%rax,%rax,1)
mov    %ebp,%r15d
mov    %r14,%rdi
call   1050 <_mm_loadu_si128@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1030 <_mm_store_si128@plt>
lea    0x40(%r14),%rdi
call   1050 <_mm_loadu_si128@plt>
lea    0x40(%rbx),%rdi
mov    %eax,%esi
call   1030 <_mm_store_si128@plt>
sub    $0xffffffffffffff80,%r14
sub    $0xffffffffffffff80,%rbx
lea    -0x20(%r15),%ebp
cmp    $0x3f,%r15d
ja     1180 <fastcopy_sse2_32+0x50>
cmp    $0x10,%ebp
jl     11dd <fastcopy_sse2_32+0xad>
mov    %r14,%rdi
call   1050 <_mm_loadu_si128@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1030 <_mm_store_si128@plt>
add    $0x40,%r14
add    $0x40,%rbx
add    $0xfffffff0,%ebp
test   %ebp,%ebp
jle    11f2 <fastcopy_sse2_32+0xc2>
mov    %ebp,%edx
shl    $0x2,%rdx
mov    %rbx,%rdi
mov    %r14,%rsi
call   1040 <memcpy@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @fastcopy_sse2_32(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 = %45, %26
%28 = load i32, i32* %6
%29 = icmp sge i32 %28, 32
br i1 %29, label %30, label %48
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** %4
%36 = getelementptr inbounds i32, i32* %35, i64 16
%37 = load i32*, i32** %5
%38 = getelementptr inbounds i32, i32* %37, i64 16
%39 = call i32 @_mm_loadu_si128(i32* %38)
%40 = call i32 @_mm_store_si128(i32* %36, i32 %39)
%41 = load i32*, i32** %5
%42 = getelementptr inbounds i32, i32* %41, i64 32
store i32* %42, i32** %5
%43 = load i32*, i32** %4
%44 = getelementptr inbounds i32, i32* %43, i64 32
store i32* %44, i32** %4
br label %45
45: ; preds = %30
%46 = load i32, i32* %6
%47 = sub nsw i32 %46, 32
store i32 %47, i32* %6
br label %27
48: ; preds = %27
%49 = load i32, i32* %6
%50 = icmp sge i32 %49, 16
br i1 %50, label %51, label %62
51: ; preds = %48
%52 = load i32*, i32** %4
%53 = load i32*, i32** %5
%54 = call i32 @_mm_loadu_si128(i32* %53)
%55 = call i32 @_mm_store_si128(i32* %52, i32 %54)
%56 = load i32*, i32** %5
%57 = getelementptr inbounds i32, i32* %56, i64 16
store i32* %57, i32** %5
%58 = load i32*, i32** %4
%59 = getelementptr inbounds i32, i32* %58, i64 16
store i32* %59, i32** %4
%60 = load i32, i32* %6
%61 = sub nsw i32 %60, 16
store i32 %61, i32* %6
br label %62
62: ; preds = %51, %48
br label %63
63: ; preds = %72, %62
%64 = load i32, i32* %6
%65 = icmp sgt i32 %64, 0
br i1 %65, label %66, label %75
66: ; preds = %63
%67 = load i32*, i32** %5
%68 = getelementptr inbounds i32, i32* %67, i32 1
store i32* %68, i32** %5
%69 = load i32, i32* %67
%70 = load i32*, i32** %4
%71 = getelementptr inbounds i32, i32* %70, i32 1
store i32* %71, i32** %4
store i32 %69, i32* %70
br label %72
72: ; preds = %66
%73 = load i32, i32* %6
%74 = add nsw i32 %73, -1
store i32 %74, i32* %6
br label %63
75: ; preds = %63
ret void
}

LLVM IR (-O2):
define void @fastcopy_sse2_32(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, 31
br i1 %13, label %27, label %41
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 = %9, %27
%28 = phi i32 [ %39, %27 ], [ %12, %9 ]
%29 = phi i32* [ %37, %27 ], [ %11, %9 ]
%30 = phi i32* [ %38, %27 ], [ %10, %9 ]
%31 = tail call i32 @_mm_loadu_si128(i32* %29)
%32 = tail call i32 @_mm_store_si128(i32* %30, i32 %31)
%33 = getelementptr inbounds i32, i32* %30, i64 16
%34 = getelementptr inbounds i32, i32* %29, i64 16
%35 = tail call i32 @_mm_loadu_si128(i32* %34)
%36 = tail call i32 @_mm_store_si128(i32* %33, i32 %35)
%37 = getelementptr inbounds i32, i32* %29, i64 32
%38 = getelementptr inbounds i32, i32* %30, i64 32
%39 = add nsw i32 %28, -32
%40 = icmp ugt i32 %28, 63
br i1 %40, label %27, label %41
41: ; preds = %27, %9
%42 = phi i32* [ %10, %9 ], [ %38, %27 ]
%43 = phi i32* [ %11, %9 ], [ %37, %27 ]
%44 = phi i32 [ %12, %9 ], [ %39, %27 ]
%45 = icmp sgt i32 %44, 15
br i1 %45, label %46, label %52
46: ; preds = %41
%47 = tail call i32 @_mm_loadu_si128(i32* %43)
%48 = tail call i32 @_mm_store_si128(i32* %42, i32 %47)
%49 = getelementptr inbounds i32, i32* %43, i64 16
%50 = getelementptr inbounds i32, i32* %42, i64 16
%51 = add nsw i32 %44, -16
br label %52
52: ; preds = %46, %41
%53 = phi i32* [ %50, %46 ], [ %42, %41 ]
%54 = phi i32* [ %49, %46 ], [ %43, %41 ]
%55 = phi i32 [ %51, %46 ], [ %44, %41 ]
%56 = icmp sgt i32 %55, 0
br i1 %56, label %57, label %62
57: ; preds = %52
%58 = bitcast i32* %54 to i8*
%59 = bitcast i32* %53 to i8*
%60 = zext i32 %55 to i64
%61 = shl nuw nsw i64 %60, 2
br label %62
62: ; preds = %57, %52
ret void
}