#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 */
typedef int /*<<< orphan*/ s2;

/* Variables and functions */
int /*<<< orphan*/ memcopy(char *, char *, int);
int /*<<< orphan*/ printf(char *, char *, char *);
int main() {
  char s1[] = "abcdefg";
  char s2[] = "lmnop";
  printf("Before memcopy:\n\ts1 = [%s]\n\ts2 = [%s]\n", s1, s2);
  memcopy(s1, s2, sizeof(s2) - 1);
  printf("After memcopy:\n\ts1 = [%s]\n\ts2 = [%s]\n", s1, s2);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    0xeca(%rip),%rax
mov    %rax,-0xc(%rbp)
mov    0xec8(%rip),%eax
mov    %eax,-0x12(%rbp)
mov    0xec2(%rip),%ax
mov    %ax,-0xe(%rbp)
lea    -0xc(%rbp),%rsi
lea    -0x12(%rbp),%rdx
lea    0xeb1(%rip),%rdi
call   1030 <printf@plt>
lea    -0xc(%rbp),%rdi
lea    -0x12(%rbp),%rsi
mov    $0x5,%edx
call   1040 <memcopy@plt>
lea    -0xc(%rbp),%rsi
lea    -0x12(%rbp),%rdx
lea    0xeb2(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x18,%rsp
movabs $0x67666564636261,%rax
mov    %rax,0x10(%rsp)
movw   $0x70,0xc(%rsp)
movl   $0x6f6e6d6c,0x8(%rsp)
6f
lea    0xeba(%rip),%rdi
lea    0x10(%rsp),%rbx
lea    0x8(%rsp),%r14
mov    %rbx,%rsi
mov    %r14,%rdx
call   1030 <printf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x5,%edx
call   1040 <memcopy@plt>
lea    0xeb5(%rip),%rdi
mov    %rbx,%rsi
mov    %r14,%rdx
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@__const.main.s1 = [8 x i8] c"abcdefg\00"
@__const.main.s2 = [6 x i8] c"lmnop\00"
@.str = [39 x i8] c"Before memcopy:\0A\09s1 = [%s]\0A\09s2 = [%s]\0A\00"
@.str.1 = [38 x i8] c"After memcopy:\0A\09s1 = [%s]\0A\09s2 = [%s]\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [8 x i8]
%3 = alloca [6 x i8]
store i32 0, i32* %1
%4 = bitcast [8 x i8]* %2 to i8*
%5 = bitcast [6 x i8]* %3 to i8*
%6 = getelementptr inbounds [8 x i8], [8 x i8]* %2, i64 0, i64 0
%7 = getelementptr inbounds [6 x i8], [6 x i8]* %3, i64 0, i64 0
%8 = call i32 @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), i8* %6, i8* %7)
%9 = getelementptr inbounds [8 x i8], [8 x i8]* %2, i64 0, i64 0
%10 = getelementptr inbounds [6 x i8], [6 x i8]* %3, i64 0, i64 0
%11 = call i32 @memcopy(i8* %9, i8* %10, i32 5)
%12 = getelementptr inbounds [8 x i8], [8 x i8]* %2, i64 0, i64 0
%13 = getelementptr inbounds [6 x i8], [6 x i8]* %3, i64 0, i64 0
%14 = call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i8* %12, i8* %13)
ret i32 0
}

LLVM IR (-O2):
@__const.main.s2 = [6 x i8] c"lmnop\00"
@.str = [39 x i8] c"Before memcopy:\0A\09s1 = [%s]\0A\09s2 = [%s]\0A\00"
@.str.1 = [38 x i8] c"After memcopy:\0A\09s1 = [%s]\0A\09s2 = [%s]\0A\00"
define i32 @main() {
%1 = alloca i64
%2 = alloca [6 x i8]
%3 = bitcast i64* %1 to i8*
store i64 29104508263162465, i64* %1
%4 = getelementptr inbounds [6 x i8], [6 x i8]* %2, i64 0, i64 0
%5 = call i32 @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), i8* %3, i8* %4)
%6 = call i32 @memcopy(i8* %3, i8* %4, i32 5)
%7 = call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i8* %3, i8* %4)
ret i32 0
}