#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 const *, scalar_t__);
int /*<<< orphan*/ printf(char *, char *);
scalar_t__ strlen(char const *);
int main() {
  const char src[50] = "Linkerist Heracles";
  char dest[50] = {0};
  printf("Before memcpy dest = %s\n", dest);
  memcpy(dest, src, strlen(src) + 1);
  printf("After memcpy dest = %s\n", dest);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x40(%rbp),%rdi
lea    0xea3(%rip),%rsi
mov    $0x32,%edx
call   1060 <memcpy@plt>
lea    -0x80(%rbp),%rdi
xor    %esi,%esi
mov    $0x32,%edx
call   1050 <memset@plt>
lea    -0x80(%rbp),%rsi
lea    0xeb0(%rip),%rdi
call   1040 <printf@plt>
lea    -0x80(%rbp),%rax
mov    %rax,-0x90(%rbp)
lea    -0x40(%rbp),%rax
mov    %rax,-0x88(%rbp)
lea    -0x40(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x90(%rbp),%rdi
mov    -0x88(%rbp),%rsi
mov    %rax,%rdx
add    $0x1,%rdx
call   1060 <memcpy@plt>
lea    -0x80(%rbp),%rsi
lea    0xe80(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x78,%rsp
movaps 0xee2(%rip),%xmm0
movaps %xmm0,0x60(%rsp)
movaps 0xec6(%rip),%xmm0
movaps %xmm0,0x50(%rsp)
movaps 0xeaa(%rip),%xmm0
movaps %xmm0,0x40(%rsp)
movw   $0x0,0x70(%rsp)
xorps  %xmm0,%xmm0
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
movaps %xmm0,(%rsp)
movw   $0x0,0x30(%rsp)
lea    0xeb1(%rip),%rdi
mov    %rsp,%r14
mov    %r14,%rsi
call   1040 <printf@plt>
lea    0x40(%rsp),%rbx
mov    %rbx,%rdi
call   1030 <strlen@plt>
lea    0x1(%rax),%rdx
mov    %r14,%rdi
mov    %rbx,%rsi
call   1050 <memcpy@plt>
lea    0xe9c(%rip),%rdi
mov    %r14,%rsi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x78,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@__const.main.src = [50 x i8] c"Linkerist Heracles\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00"
@.str = [25 x i8] c"Before memcpy dest = %s\0A\00"
@.str.1 = [24 x i8] c"After memcpy dest = %s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [50 x i8]
%3 = alloca [50 x i8]
store i32 0, i32* %1
%4 = bitcast [50 x i8]* %2 to i8*
%5 = bitcast [50 x i8]* %3 to i8*
%6 = getelementptr inbounds [50 x i8], [50 x i8]* %3, i64 0, i64 0
%7 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %6)
%8 = getelementptr inbounds [50 x i8], [50 x i8]* %3, i64 0, i64 0
%9 = getelementptr inbounds [50 x i8], [50 x i8]* %2, i64 0, i64 0
%10 = getelementptr inbounds [50 x i8], [50 x i8]* %2, i64 0, i64 0
%11 = call i64 @strlen(i8* %10)
%12 = add nsw i64 %11, 1
%13 = call i32 @memcpy(i8* %8, i8* %9, i64 %12)
%14 = getelementptr inbounds [50 x i8], [50 x i8]* %3, i64 0, i64 0
%15 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i8* %14)
ret i32 0
}

LLVM IR (-O2):
@__const.main.src = [50 x i8] c"Linkerist Heracles\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00"
@.str = [25 x i8] c"Before memcpy dest = %s\0A\00"
@.str.1 = [24 x i8] c"After memcpy dest = %s\0A\00"
define i32 @main() {
%1 = alloca [50 x i8]
%2 = alloca [50 x i8]
%3 = getelementptr inbounds [50 x i8], [50 x i8]* %1, i64 0, i64 0
%4 = getelementptr inbounds [50 x i8], [50 x i8]* %2, i64 0, i64 0
%5 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %4)
%6 = call i64 @strlen(i8* %3)
%7 = add nsw i64 %6, 1
%8 = call i32 @memcpy(i8* %4, i8* %3, i64 %7)
%9 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i8* %4)
ret i32 0
}