#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);
void memcpy_aligned(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)
      memcpy((uint8_t *)to + offset, (uint8_t *)from + offset, 64);
  }
}


x86 assembly (clang, -O0):
<memcpy_aligned>:
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     1146 <memcpy_aligned+0x36>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    $0x40,%edx
call   1030 <memcpy@plt>
jmp    11d0 <memcpy_aligned+0xc0>
cmpq   $0x80,-0x18(%rbp)
ja     1185 <memcpy_aligned+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    11cb <memcpy_aligned+0xbb>
movq   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    11c6 <memcpy_aligned+0xb6>
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    118d <memcpy_aligned+0x7d>
jmp    11cb <memcpy_aligned+0xbb>
jmp    11d0 <memcpy_aligned+0xc0>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<memcpy_aligned>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r15
cmp    $0x40,%rdx
jbe    1148 <memcpy_aligned+0x38>
mov    %rdx,%r12
cmp    $0x81,%rdx
jae    1163 <memcpy_aligned+0x53>
mov    %r15,%rdi
mov    %r14,%rsi
mov    $0x40,%edx
call   1030 <memcpy@plt>
add    $0x40,%r15
add    $0x40,%r14
mov    %r15,%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
cs nopw 0x0(%rax,%rax,1)
nop
lea    (%r15,%rbx,1),%rdi
lea    (%r14,%rbx,1),%rsi
mov    $0x40,%edx
call   1030 <memcpy@plt>
add    $0x40,%rbx
cmp    %r12,%rbx
jb     1170 <memcpy_aligned+0x60>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @memcpy_aligned(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 %44
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 %43
26: ; preds = %14
store i64 0, i64* %7
br label %27
27: ; preds = %39, %26
%28 = load i64, i64* %7
%29 = load i64, i64* %6
%30 = icmp ult i64 %28, %29
br i1 %30, label %31, label %42
31: ; preds = %27
%32 = load i8*, i8** %4
%33 = load i64, i64* %7
%34 = getelementptr i8, i8* %32, i64 %33
%35 = load i8*, i8** %5
%36 = load i64, i64* %7
%37 = getelementptr i8, i8* %35, i64 %36
%38 = call i32 @memcpy(i8* %34, i8* %37, i32 64)
br label %39
39: ; preds = %31
%40 = load i64, i64* %7
%41 = add i64 %40, 64
store i64 %41, i64* %7
br label %27
42: ; preds = %27
br label %43
43: ; preds = %42, %17
br label %44
44: ; preds = %43, %10
ret void
}

LLVM IR (-O2):
define void @memcpy_aligned(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 %21
7: ; preds = %3
%8 = icmp ult i64 %2, 129
br i1 %8, label %9, label %14
9: ; preds = %7
%10 = tail call i32 @memcpy(i8* %0, i8* %1, i32 64)
%11 = getelementptr i8, i8* %0, i64 64
%12 = getelementptr i8, i8* %1, i64 64
%13 = tail call i32 @memcpy(i8* %11, i8* %12, i32 64)
br label %21
14: ; preds = %7, %14
%15 = phi i64 [ %19, %14 ], [ 0, %7 ]
%16 = getelementptr i8, i8* %0, i64 %15
%17 = getelementptr i8, i8* %1, i64 %15
%18 = tail call i32 @memcpy(i8* %16, i8* %17, i32 64)
%19 = add i64 %15, 64
%20 = icmp ult i64 %19, %2
br i1 %20, label %14, label %21
21: ; preds = %14, %9, %5
ret void
}