#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*/ memcpy(char *, char *, int);
void *test2(void *dest, const void *src, size_t n) {
  const int ADD = 8;
  char *rbuf = (char *)src;
  char *wbuf = (char *)dest;
  for (int i = 0; i < n; i += ADD) {
    memcpy(wbuf, rbuf, 1);
    rbuf += 1;
    wbuf += 1;
    memcpy(wbuf, rbuf, 1);
    rbuf += 1;
    wbuf += 1;
    memcpy(wbuf, rbuf, 1);
    rbuf += 1;
    wbuf += 1;
    memcpy(wbuf, rbuf, 1);
    rbuf += 1;
    wbuf += 1;
    memcpy(wbuf, rbuf, 1);
    rbuf += 1;
    wbuf += 1;
    memcpy(wbuf, rbuf, 1);
    rbuf += 1;
    wbuf += 1;
    memcpy(wbuf, rbuf, 1);
    rbuf += 1;
    wbuf += 1;
    memcpy(wbuf, rbuf, 1);
    rbuf += 1;
    wbuf += 1;
  }
  return dest;
}


x86 assembly (clang, -O0):
<test2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x8,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
movslq -0x34(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    12ae <test2+0x19e>
mov    -0x30(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    $0x1,%edx
call   1030 <memcpy@plt>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    $0x1,%edx
call   1030 <memcpy@plt>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    $0x1,%edx
call   1030 <memcpy@plt>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    $0x1,%edx
call   1030 <memcpy@plt>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    $0x1,%edx
call   1030 <memcpy@plt>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    $0x1,%edx
call   1030 <memcpy@plt>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    $0x1,%edx
call   1030 <memcpy@plt>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    $0x1,%edx
call   1030 <memcpy@plt>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
mov    -0x34(%rbp),%eax
add    $0x8,%eax
mov    %eax,-0x34(%rbp)
jmp    1142 <test2+0x32>
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test2>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r12
test   %rdx,%rdx
je     1205 <test2+0xf5>
mov    %rdx,%r14
mov    %rsi,%r15
xor    %ebx,%ebx
nopl   0x0(%rax)
lea    (%r12,%rbx,1),%rdi
lea    (%r15,%rbx,1),%rsi
mov    $0x1,%edx
call   1030 <memcpy@plt>
lea    (%r12,%rbx,1),%rdi
add    $0x1,%rdi
lea    (%r15,%rbx,1),%rsi
add    $0x1,%rsi
mov    $0x1,%edx
call   1030 <memcpy@plt>
lea    (%r12,%rbx,1),%rdi
add    $0x2,%rdi
lea    (%r15,%rbx,1),%rsi
add    $0x2,%rsi
mov    $0x1,%edx
call   1030 <memcpy@plt>
lea    (%r12,%rbx,1),%rdi
add    $0x3,%rdi
lea    (%r15,%rbx,1),%rsi
add    $0x3,%rsi
mov    $0x1,%edx
call   1030 <memcpy@plt>
lea    (%r12,%rbx,1),%rdi
add    $0x4,%rdi
lea    (%r15,%rbx,1),%rsi
add    $0x4,%rsi
mov    $0x1,%edx
call   1030 <memcpy@plt>
lea    (%r12,%rbx,1),%rdi
add    $0x5,%rdi
lea    (%r15,%rbx,1),%rsi
add    $0x5,%rsi
mov    $0x1,%edx
call   1030 <memcpy@plt>
lea    (%r12,%rbx,1),%rdi
add    $0x6,%rdi
lea    (%r15,%rbx,1),%rsi
add    $0x6,%rsi
mov    $0x1,%edx
call   1030 <memcpy@plt>
lea    (%r12,%rbx,1),%rdi
add    $0x7,%rdi
lea    (%r15,%rbx,1),%rsi
add    $0x7,%rsi
mov    $0x1,%edx
call   1030 <memcpy@plt>
add    $0x8,%rbx
cmp    %r14,%rbx
jb     1130 <test2+0x20>
mov    %r12,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8* @test2(i8* %0, i8* %1, i64 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i64 %2, i64* %6
store i32 8, i32* %7
%11 = load i8*, i8** %5
store i8* %11, i8** %8
%12 = load i8*, i8** %4
store i8* %12, i8** %9
store i32 0, i32* %10
br label %13
13: ; preds = %75, %3
%14 = load i32, i32* %10
%15 = sext i32 %14 to i64
%16 = load i64, i64* %6
%17 = icmp ult i64 %15, %16
br i1 %17, label %18, label %78
18: ; preds = %13
%19 = load i8*, i8** %9
%20 = load i8*, i8** %8
%21 = call i32 @memcpy(i8* %19, i8* %20, i32 1)
%22 = load i8*, i8** %8
%23 = getelementptr inbounds i8, i8* %22, i64 1
store i8* %23, i8** %8
%24 = load i8*, i8** %9
%25 = getelementptr inbounds i8, i8* %24, i64 1
store i8* %25, i8** %9
%26 = load i8*, i8** %9
%27 = load i8*, i8** %8
%28 = call i32 @memcpy(i8* %26, i8* %27, i32 1)
%29 = load i8*, i8** %8
%30 = getelementptr inbounds i8, i8* %29, i64 1
store i8* %30, i8** %8
%31 = load i8*, i8** %9
%32 = getelementptr inbounds i8, i8* %31, i64 1
store i8* %32, i8** %9
%33 = load i8*, i8** %9
%34 = load i8*, i8** %8
%35 = call i32 @memcpy(i8* %33, i8* %34, i32 1)
%36 = load i8*, i8** %8
%37 = getelementptr inbounds i8, i8* %36, i64 1
store i8* %37, i8** %8
%38 = load i8*, i8** %9
%39 = getelementptr inbounds i8, i8* %38, i64 1
store i8* %39, i8** %9
%40 = load i8*, i8** %9
%41 = load i8*, i8** %8
%42 = call i32 @memcpy(i8* %40, i8* %41, i32 1)
%43 = load i8*, i8** %8
%44 = getelementptr inbounds i8, i8* %43, i64 1
store i8* %44, i8** %8
%45 = load i8*, i8** %9
%46 = getelementptr inbounds i8, i8* %45, i64 1
store i8* %46, i8** %9
%47 = load i8*, i8** %9
%48 = load i8*, i8** %8
%49 = call i32 @memcpy(i8* %47, i8* %48, i32 1)
%50 = load i8*, i8** %8
%51 = getelementptr inbounds i8, i8* %50, i64 1
store i8* %51, i8** %8
%52 = load i8*, i8** %9
%53 = getelementptr inbounds i8, i8* %52, i64 1
store i8* %53, i8** %9
%54 = load i8*, i8** %9
%55 = load i8*, i8** %8
%56 = call i32 @memcpy(i8* %54, i8* %55, i32 1)
%57 = load i8*, i8** %8
%58 = getelementptr inbounds i8, i8* %57, i64 1
store i8* %58, i8** %8
%59 = load i8*, i8** %9
%60 = getelementptr inbounds i8, i8* %59, i64 1
store i8* %60, i8** %9
%61 = load i8*, i8** %9
%62 = load i8*, i8** %8
%63 = call i32 @memcpy(i8* %61, i8* %62, i32 1)
%64 = load i8*, i8** %8
%65 = getelementptr inbounds i8, i8* %64, i64 1
store i8* %65, i8** %8
%66 = load i8*, i8** %9
%67 = getelementptr inbounds i8, i8* %66, i64 1
store i8* %67, i8** %9
%68 = load i8*, i8** %9
%69 = load i8*, i8** %8
%70 = call i32 @memcpy(i8* %68, i8* %69, i32 1)
%71 = load i8*, i8** %8
%72 = getelementptr inbounds i8, i8* %71, i64 1
store i8* %72, i8** %8
%73 = load i8*, i8** %9
%74 = getelementptr inbounds i8, i8* %73, i64 1
store i8* %74, i8** %9
br label %75
75: ; preds = %18
%76 = load i32, i32* %10
%77 = add nsw i32 %76, 8
store i32 %77, i32* %10
br label %13
78: ; preds = %13
%79 = load i8*, i8** %4
ret i8* %79
}

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