#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*/ memmove(char const *, char const *, int);
int /*<<< orphan*/ printf(char *, char const *, char const *);
int main() {
  const char dest[] = "oldstring";
  const char src[] = "newstring";
  printf("Before memmove dest = %s, src = %s\n", dest, src);
  memmove(dest, src, 9);
  printf("After memmove dest = %s, src = %s\n", dest, src);
  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,-0xe(%rbp)
mov    0xec7(%rip),%ax
mov    %ax,-0x6(%rbp)
mov    0xebe(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    0xebb(%rip),%ax
mov    %ax,-0x10(%rbp)
lea    -0xe(%rbp),%rsi
lea    -0x18(%rbp),%rdx
lea    0xeaa(%rip),%rdi
call   1030 <printf@plt>
lea    -0xe(%rbp),%rdi
lea    -0x18(%rbp),%rsi
mov    $0x9,%edx
call   1040 <memmove@plt>
lea    -0xe(%rbp),%rsi
lea    -0x18(%rbp),%rdx
lea    0xea8(%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    $0x28,%rsp
movabs $0x6e69727473646c6f,%rax
72 69 6e
mov    %rax,0x18(%rsp)
movw   $0x67,0x20(%rsp)
movabs $0x6e6972747377656e,%rax
72 69 6e
mov    %rax,0x8(%rsp)
movw   $0x67,0x10(%rsp)
lea    0xeba(%rip),%rdi
lea    0x18(%rsp),%rbx
lea    0x8(%rsp),%r14
mov    %rbx,%rsi
mov    %r14,%rdx
call   1030 <printf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x9,%edx
call   1040 <memmove@plt>
lea    0xeb2(%rip),%rdi
mov    %rbx,%rsi
mov    %r14,%rdx
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@__const.main.dest = [10 x i8] c"oldstring\00"
@__const.main.src = [10 x i8] c"newstring\00"
@.str = [36 x i8] c"Before memmove dest = %s, src = %s\0A\00"
@.str.1 = [35 x i8] c"After memmove dest = %s, src = %s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [10 x i8]
%3 = alloca [10 x i8]
store i32 0, i32* %1
%4 = bitcast [10 x i8]* %2 to i8*
%5 = bitcast [10 x i8]* %3 to i8*
%6 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 0
%7 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 0
%8 = call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), i8* %6, i8* %7)
%9 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 0
%10 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 0
%11 = call i32 @memmove(i8* %9, i8* %10, i32 9)
%12 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 0
%13 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 0
%14 = call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0), i8* %12, i8* %13)
ret i32 0
}

LLVM IR (-O2):
@__const.main.dest = [10 x i8] c"oldstring\00"
@__const.main.src = [10 x i8] c"newstring\00"
@.str = [36 x i8] c"Before memmove dest = %s, src = %s\0A\00"
@.str.1 = [35 x i8] c"After memmove dest = %s, src = %s\0A\00"
define i32 @main() {
%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 = call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), i8* %3, i8* %4)
%6 = call i32 @memmove(i8* %3, i8* %4, i32 9)
%7 = call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0), i8* %3, i8* %4)
ret i32 0
}