#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 void uint8_t;

/* Variables and functions */
int /*<<< orphan*/ memcpy(void *, void *, int);
int /*<<< orphan*/ prefetchnta(void *);
void memcpy_aligned_tx(void *to, const void *from, size_t len) {
  if (len <= 64) {
    memcpy(to, from, 64);
  } else if (len <= 128) {
    memcpy(to, from, 64);
    memcpy((uint8_t *)to + 64, (uint8_t *)from + 64, 64);
  } else {
    size_t offset;
    for (offset = 0; offset < len; offset += 64) {
      if (offset + 128 < len) {
        prefetchnta((uint8_t *)from + offset + 128);
        prefetchnta((uint8_t *)to + offset + 128);
      }
      memcpy((uint8_t *)to + offset, (uint8_t *)from + offset, 64);
    }
  }
}


x86 assembly (clang, -O0):
<memcpy_aligned_tx>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
cmpq   $0x40,-0x18(%rbp)
ja     1156 <memcpy_aligned_tx+0x36>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    $0x40,%edx
call   1030 <memcpy@plt>
jmp    121c <memcpy_aligned_tx+0xfc>
cmpq   $0x80,-0x18(%rbp)
ja     1195 <memcpy_aligned_tx+0x75>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    $0x40,%edx
call   1030 <memcpy@plt>
mov    -0x8(%rbp),%rdi
add    $0x40,%rdi
mov    -0x10(%rbp),%rsi
add    $0x40,%rsi
mov    $0x40,%edx
call   1030 <memcpy@plt>
jmp    1217 <memcpy_aligned_tx+0xf7>
movq   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    1212 <memcpy_aligned_tx+0xf2>
mov    -0x20(%rbp),%rax
add    $0x80,%rax
cmp    -0x18(%rbp),%rax
jae    11e7 <memcpy_aligned_tx+0xc7>
mov    -0x10(%rbp),%rdi
add    -0x20(%rbp),%rdi
add    $0x80,%rdi
call   1040 <prefetchnta@plt>
mov    -0x8(%rbp),%rdi
add    -0x20(%rbp),%rdi
add    $0x80,%rdi
call   1040 <prefetchnta@plt>
mov    -0x8(%rbp),%rdi
add    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
add    -0x20(%rbp),%rsi
mov    $0x40,%edx
call   1030 <memcpy@plt>
mov    -0x20(%rbp),%rax
add    $0x40,%rax
mov    %rax,-0x20(%rbp)
jmp    119d <memcpy_aligned_tx+0x7d>
jmp    1217 <memcpy_aligned_tx+0xf7>
jmp    121c <memcpy_aligned_tx+0xfc>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<memcpy_aligned_tx>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r12
cmp    $0x40,%rdx
jbe    1158 <memcpy_aligned_tx+0x38>
mov    %rdx,%r15
cmp    $0x81,%rdx
jae    1173 <memcpy_aligned_tx+0x53>
mov    %r12,%rdi
mov    %r14,%rsi
mov    $0x40,%edx
call   1030 <memcpy@plt>
add    $0x40,%r12
add    $0x40,%r14
mov    %r12,%rdi
mov    %r14,%rsi
mov    $0x40,%edx
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1030 <memcpy@plt>
xor    %ebx,%ebx
jmp    11a1 <memcpy_aligned_tx+0x81>
nopw   0x0(%rax,%rax,1)
mov    %r12,%rdi
mov    %r14,%rsi
mov    $0x40,%edx
call   1030 <memcpy@plt>
add    $0x40,%rbx
add    $0x40,%r12
add    $0x40,%r14
cmp    %r15,%rbx
jae    11c8 <memcpy_aligned_tx+0xa8>
lea    0x80(%rbx),%rax
cmp    %r15,%rax
jae    1180 <memcpy_aligned_tx+0x60>
lea    0x80(%r14),%rdi
call   1040 <prefetchnta@plt>
lea    0x80(%r12),%rdi
call   1040 <prefetchnta@plt>
jmp    1180 <memcpy_aligned_tx+0x60>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @memcpy_aligned_tx(i8* %0, i8* %1, i64 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i64
store i8* %0, i8** %4
store i8* %1, i8** %5
store i64 %2, i64* %6
%8 = load i64, i64* %6
%9 = icmp ule i64 %8, 64
br i1 %9, label %10, label %14
10: ; preds = %3
%11 = load i8*, i8** %4
%12 = load i8*, i8** %5
%13 = call i32 @memcpy(i8* %11, i8* %12, i32 64)
br label %60
14: ; preds = %3
%15 = load i64, i64* %6
%16 = icmp ule i64 %15, 128
br i1 %16, label %17, label %26
17: ; preds = %14
%18 = load i8*, i8** %4
%19 = load i8*, i8** %5
%20 = call i32 @memcpy(i8* %18, i8* %19, i32 64)
%21 = load i8*, i8** %4
%22 = getelementptr i8, i8* %21, i64 64
%23 = load i8*, i8** %5
%24 = getelementptr i8, i8* %23, i64 64
%25 = call i32 @memcpy(i8* %22, i8* %24, i32 64)
br label %59
26: ; preds = %14
store i64 0, i64* %7
br label %27
27: ; preds = %55, %26
%28 = load i64, i64* %7
%29 = load i64, i64* %6
%30 = icmp ult i64 %28, %29
br i1 %30, label %31, label %58
31: ; preds = %27
%32 = load i64, i64* %7
%33 = add i64 %32, 128
%34 = load i64, i64* %6
%35 = icmp ult i64 %33, %34
br i1 %35, label %36, label %47
36: ; preds = %31
%37 = load i8*, i8** %5
%38 = load i64, i64* %7
%39 = getelementptr i8, i8* %37, i64 %38
%40 = getelementptr i8, i8* %39, i64 128
%41 = call i32 @prefetchnta(i8* %40)
%42 = load i8*, i8** %4
%43 = load i64, i64* %7
%44 = getelementptr i8, i8* %42, i64 %43
%45 = getelementptr i8, i8* %44, i64 128
%46 = call i32 @prefetchnta(i8* %45)
br label %47
47: ; preds = %36, %31
%48 = load i8*, i8** %4
%49 = load i64, i64* %7
%50 = getelementptr i8, i8* %48, i64 %49
%51 = load i8*, i8** %5
%52 = load i64, i64* %7
%53 = getelementptr i8, i8* %51, i64 %52
%54 = call i32 @memcpy(i8* %50, i8* %53, i32 64)
br label %55
55: ; preds = %47
%56 = load i64, i64* %7
%57 = add i64 %56, 64
store i64 %57, i64* %7
br label %27
58: ; preds = %27
br label %59
59: ; preds = %58, %17
br label %60
60: ; preds = %59, %10
ret void
}

LLVM IR (-O2):
define void @memcpy_aligned_tx(i8* %0, i8* %1, i64 %2) {
%4 = icmp ult i64 %2, 65
br i1 %4, label %5, label %7
5: ; preds = %3
%6 = tail call i32 @memcpy(i8* %0, i8* %1, i32 64)
br label %32
7: ; preds = %3
%8 = icmp ult i64 %2, 129
br i1 %8, label %12, label %9
9: ; preds = %7
%10 = getelementptr i8, i8* %1, i64 128
%11 = getelementptr i8, i8* %0, i64 128
br label %17
12: ; preds = %7
%13 = tail call i32 @memcpy(i8* %0, i8* %1, i32 64)
%14 = getelementptr i8, i8* %0, i64 64
%15 = getelementptr i8, i8* %1, i64 64
%16 = tail call i32 @memcpy(i8* %14, i8* %15, i32 64)
br label %32
17: ; preds = %9, %26
%18 = phi i64 [ %30, %26 ], [ 0, %9 ]
%19 = add i64 %18, 128
%20 = icmp ult i64 %19, %2
br i1 %20, label %21, label %26
21: ; preds = %17
%22 = getelementptr i8, i8* %10, i64 %18
%23 = tail call i32 @prefetchnta(i8* %22)
%24 = getelementptr i8, i8* %11, i64 %18
%25 = tail call i32 @prefetchnta(i8* %24)
br label %26
26: ; preds = %21, %17
%27 = getelementptr i8, i8* %0, i64 %18
%28 = getelementptr i8, i8* %1, i64 %18
%29 = tail call i32 @memcpy(i8* %27, i8* %28, i32 64)
%30 = add i64 %18, 64
%31 = icmp ult i64 %30, %2
br i1 %31, label %17, label %32
32: ; preds = %26, %12, %5
ret void
}