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


x86 assembly (clang, -O0):
<test1>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x1,-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    1188 <test1+0x78>
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    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1142 <test1+0x32>
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test1>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
test   %rdx,%rdx
je     114e <test1+0x3e>
mov    %rdx,%r15
mov    %rsi,%r12
mov    %r14,%rbx
nopl   0x0(%rax)
mov    %rbx,%rdi
mov    %r12,%rsi
mov    $0x1,%edx
call   1030 <memcpy@plt>
add    $0x1,%r12
add    $0x1,%rbx
add    $0xffffffffffffffff,%r15
jne    1130 <test1+0x20>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8* @test1(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 1, 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 = %26, %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 %29
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
br label %26
26: ; preds = %18
%27 = load i32, i32* %10
%28 = add nsw i32 %27, 1
store i32 %28, i32* %10
br label %13
29: ; preds = %13
%30 = load i8*, i8** %4
ret i8* %30
}

LLVM IR (-O2):
define i8* @test1(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 [ %13, %6 ], [ 0, %3 ]
%8 = phi i8* [ %12, %6 ], [ %0, %3 ]
%9 = phi i8* [ %11, %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 = add nuw i64 %7, 1
%14 = icmp eq i64 %13, %2
br i1 %14, label %5, label %6
}