#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__ memcpy(char *, char *, int);
int /*<<< orphan*/ printf(char *, char *, char *, char *, char *);
int strlen(char *);
void memcpyTest() {
  char str1[] = "Sample string";
  char str2[40];
  char str3[40];
  char *str4;
  memcpy(str2, str1, strlen(str1) + 1);
  str4 = (char *)memcpy(str3, "copy successful", 4);
  printf("str1: %s\nstr2: %s\nstr3: %s\nstr4: %s\n", str1, str2, str3, str4);
}


x86 assembly (clang, -O0):
<memcpyTest>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    0xebe(%rip),%rax
mov    %rax,-0xe(%rbp)
mov    0xebc(%rip),%eax
mov    %eax,-0x6(%rbp)
mov    0xeb6(%rip),%ax
mov    %ax,-0x2(%rbp)
lea    -0x40(%rbp),%rax
mov    %rax,-0x88(%rbp)
lea    -0xe(%rbp),%rax
mov    %rax,-0x80(%rbp)
lea    -0xe(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x88(%rbp),%rdi
mov    -0x80(%rbp),%rsi
mov    %eax,%edx
add    $0x1,%edx
call   1050 <memcpy@plt>
lea    -0x70(%rbp),%rdi
lea    0xe78(%rip),%rsi
mov    $0x4,%edx
call   1050 <memcpy@plt>
mov    %rax,-0x78(%rbp)
lea    -0xe(%rbp),%rsi
lea    -0x40(%rbp),%rdx
lea    -0x70(%rbp),%rcx
mov    -0x78(%rbp),%r8
lea    0xe63(%rip),%rdi
call   1040 <printf@plt>
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<memcpyTest>:
push   %r15
push   %r14
push   %rbx
sub    $0x70,%rsp
movabs $0x676e6972747320,%rax
mov    %rax,0x6(%rsp)
movabs $0x7320656c706d6153,%rax
65 20 73
mov    %rax,(%rsp)
mov    %rsp,%r15
mov    %r15,%rdi
call   1030 <strlen@plt>
lea    0x1(%rax),%edx
lea    0x40(%rsp),%r14
mov    %r14,%rdi
mov    %r15,%rsi
call   1050 <memcpy@plt>
lea    0xe93(%rip),%rsi
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x4,%edx
call   1050 <memcpy@plt>
lea    0xe8a(%rip),%rdi
mov    %r15,%rsi
mov    %r14,%rdx
mov    %rbx,%rcx
mov    %rax,%r8
call   1040 <printf@plt>
add    $0x70,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@__const.memcpyTest.str1 = [14 x i8] c"Sample string\00"
@.str = [16 x i8] c"copy successful\00"
@.str.1 = [37 x i8] c"str1: %s\0Astr2: %s\0Astr3: %s\0Astr4: %s\0A\00"
define void @memcpyTest() {
%1 = alloca [14 x i8]
%2 = alloca [40 x i8]
%3 = alloca [40 x i8]
%4 = alloca i8*
%5 = bitcast [14 x i8]* %1 to i8*
%6 = getelementptr inbounds [40 x i8], [40 x i8]* %2, i64 0, i64 0
%7 = getelementptr inbounds [14 x i8], [14 x i8]* %1, i64 0, i64 0
%8 = getelementptr inbounds [14 x i8], [14 x i8]* %1, i64 0, i64 0
%9 = call i32 @strlen(i8* %8)
%10 = add nsw i32 %9, 1
%11 = call i64 @memcpy(i8* %6, i8* %7, i32 %10)
%12 = getelementptr inbounds [40 x i8], [40 x i8]* %3, i64 0, i64 0
%13 = call i64 @memcpy(i8* %12, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 4)
%14 = inttoptr i64 %13 to i8*
store i8* %14, i8** %4
%15 = getelementptr inbounds [14 x i8], [14 x i8]* %1, i64 0, i64 0
%16 = getelementptr inbounds [40 x i8], [40 x i8]* %2, i64 0, i64 0
%17 = getelementptr inbounds [40 x i8], [40 x i8]* %3, i64 0, i64 0
%18 = load i8*, i8** %4
%19 = call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), i8* %15, i8* %16, i8* %17, i8* %18)
ret void
}

LLVM IR (-O2):
@__const.memcpyTest.str1 = [14 x i8] c"Sample string\00"
@.str = [16 x i8] c"copy successful\00"
@.str.1 = [37 x i8] c"str1: %s\0Astr2: %s\0Astr3: %s\0Astr4: %s\0A\00"
define void @memcpyTest() {
%1 = alloca [14 x i8]
%2 = alloca [40 x i8]
%3 = alloca [40 x i8]
%4 = getelementptr inbounds [14 x i8], [14 x i8]* %1, i64 0, i64 0
%5 = getelementptr inbounds [40 x i8], [40 x i8]* %2, i64 0, i64 0
%6 = getelementptr inbounds [40 x i8], [40 x i8]* %3, i64 0, i64 0
%7 = call i32 @strlen(i8* %4)
%8 = add nsw i32 %7, 1
%9 = call i64 @memcpy(i8* %5, i8* %4, i32 %8)
%10 = call i64 @memcpy(i8* %6, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 4)
%11 = inttoptr i64 %10 to i8*
%12 = call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), i8* %4, i8* %5, i8* %6, i8* %11)
ret void
}