#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 */
scalar_t__ memcmp(char *, char *, int);
int /*<<< orphan*/ memcpy(char *, char *, int);
int /*<<< orphan*/ printf(char *);
int test_memcpy(void) {
  char value0[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
  char value1[10] = {11, 11, 11, 11, 11, 11, 11, 11, 11, 11};
  printf("\tmemcpy");
  memcpy(value1, value0, 5);
  if (value0[5] == value1[5])
    return 1;
  memcpy(value1, value0, 10);
  if (memcmp(value1, value0, 10))
    return 1;
  printf("\tpassed.\n");
  return 0;
}


x86 assembly (clang, -O0):
<test_memcpy>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    0xec1(%rip),%rax
mov    %rax,-0xe(%rbp)
mov    0xebe(%rip),%ax
mov    %ax,-0x6(%rbp)
mov    0xeb5(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    0xeb2(%rip),%ax
mov    %ax,-0x10(%rbp)
lea    0xea9(%rip),%rdi
call   1030 <printf@plt>
lea    -0x18(%rbp),%rdi
lea    -0xe(%rbp),%rsi
mov    $0x5,%edx
call   1050 <memcpy@plt>
movsbl -0x9(%rbp),%eax
movsbl -0x13(%rbp),%ecx
cmp    %ecx,%eax
jne    119e <test_memcpy+0x6e>
movl   $0x1,-0x4(%rbp)
jmp    11eb <test_memcpy+0xbb>
lea    -0x18(%rbp),%rdi
lea    -0xe(%rbp),%rsi
mov    $0xa,%edx
call   1050 <memcpy@plt>
lea    -0x18(%rbp),%rdi
lea    -0xe(%rbp),%rsi
mov    $0xa,%edx
call   1040 <memcmp@plt>
cmp    $0x0,%rax
je     11d8 <test_memcpy+0xa8>
movl   $0x1,-0x4(%rbp)
jmp    11eb <test_memcpy+0xbb>
lea    0xe3d(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_memcpy>:
push   %r15
push   %r14
push   %rbx
sub    $0x20,%rsp
movabs $0x807060504030201,%rax
06 07 08
mov    %rax,0x10(%rsp)
movw   $0xa09,0x18(%rsp)
movabs $0xb0b0b0b0b0b0b0b,%rax
0b 0b 0b
mov    %rax,(%rsp)
movw   $0xb0b,0x8(%rsp)
lea    0xe8f(%rip),%rdi
call   1040 <printf@plt>
mov    %rsp,%rdi
lea    0x10(%rsp),%rsi
mov    $0x5,%edx
call   1060 <memcpy@plt>
mov    0x15(%rsp),%al
mov    $0x1,%ebx
cmp    0x5(%rsp),%al
je     11dc <test_memcpy+0x9c>
mov    %rsp,%r14
lea    0x10(%rsp),%r15
mov    %r14,%rdi
mov    %r15,%rsi
mov    $0xa,%edx
call   1060 <memcpy@plt>
mov    %r14,%rdi
mov    %r15,%rsi
mov    $0xa,%edx
call   1050 <memcmp@plt>
test   %rax,%rax
jne    11dc <test_memcpy+0x9c>
lea    0xe3d(%rip),%rdi
call   1030 <puts@plt>
xor    %ebx,%ebx
mov    %ebx,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@__const.test_memcpy.value0 = [10 x i8] c"\01\02\03\04\05\06\07\08\09\0A"
@__const.test_memcpy.value1 = [10 x i8] c"\0B\0B\0B\0B\0B\0B\0B\0B\0B\0B"
@.str = [8 x i8] c"\09memcpy\00"
@.str.1 = [10 x i8] c"\09passed.\0A\00"
define i32 @test_memcpy() {
%1 = alloca i32
%2 = alloca [10 x i8]
%3 = alloca [10 x i8]
%4 = bitcast [10 x i8]* %2 to i8*
%5 = bitcast [10 x i8]* %3 to i8*
%6 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%7 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 0
%8 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 0
%9 = call i32 @memcpy(i8* %7, i8* %8, i32 5)
%10 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 5
%11 = load i8, i8* %10
%12 = sext i8 %11 to i32
%13 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 5
%14 = load i8, i8* %13
%15 = sext i8 %14 to i32
%16 = icmp eq i32 %12, %15
br i1 %16, label %17, label %18
17: ; preds = %0
store i32 1, i32* %1
br label %29
18: ; preds = %0
%19 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 0
%20 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 0
%21 = call i32 @memcpy(i8* %19, i8* %20, i32 10)
%22 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 0
%23 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 0
%24 = call i64 @memcmp(i8* %22, i8* %23, i32 10)
%25 = icmp ne i64 %24, 0
br i1 %25, label %26, label %27
26: ; preds = %18
store i32 1, i32* %1
br label %29
27: ; preds = %18
%28 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %1
br label %29
29: ; preds = %27, %26, %17
%30 = load i32, i32* %1
ret i32 %30
}

LLVM IR (-O2):
@__const.test_memcpy.value0 = [10 x i8] c"\01\02\03\04\05\06\07\08\09\0A"
@.str = [8 x i8] c"\09memcpy\00"
@str = [9 x i8] c"\09passed.\00"
define i32 @test_memcpy() {
%1 = alloca [10 x i8]
%2 = alloca [10 x i8]
%3 = getelementptr inbounds [10 x i8], [10 x i8]* %1, i64 0, i64 0
%4 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 0
%5 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%6 = call i32 @memcpy(i8* %4, i8* %3, i32 5)
%7 = getelementptr inbounds [10 x i8], [10 x i8]* %1, i64 0, i64 5
%8 = load i8, i8* %7
%9 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 5
%10 = load i8, i8* %9
%11 = icmp eq i8 %8, %10
br i1 %11, label %18, label %12
12: ; preds = %0
%13 = call i32 @memcpy(i8* %4, i8* %3, i32 10)
%14 = call i64 @memcmp(i8* %4, i8* %3, i32 10)
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %12
%17 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @str, i64 0, i64 0))
br label %18
18: ; preds = %12, %0, %16
%19 = phi i32 [ 0, %16 ], [ 1, %0 ], [ 1, %12 ]
ret i32 %19
}