#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__ memmove(char *, char *, int);
int /*<<< orphan*/ printf(char *, char *, char *);
void fig08_29() {
  char x[] = "Home Sweet Home";
  printf("%s%s\n", "The string in array x before memmove is: ", x);
  printf("%s%s\n", "The string in array x after memmove is: ",
         (char *)memmove(x, &x[5], 10));
}


x86 assembly (clang, -O0):
<fig08_29>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    0xed1(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    0xece(%rip),%rax
mov    %rax,-0x8(%rbp)
lea    -0x10(%rbp),%rdx
lea    0xec7(%rip),%rdi
lea    0xec6(%rip),%rsi
call   1030 <printf@plt>
lea    -0x10(%rbp),%rdi
lea    -0x10(%rbp),%rsi
add    $0x5,%rsi
mov    $0xa,%edx
call   1040 <memmove@plt>
mov    %rax,%rdx
lea    0xe9b(%rip),%rdi
lea    0xec4(%rip),%rsi
call   1030 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fig08_29>:
push   %r14
push   %rbx
sub    $0x18,%rsp
movaps 0xed2(%rip),%xmm0
movaps %xmm0,(%rsp)
lea    0xed7(%rip),%r14
lea    0xed6(%rip),%rsi
mov    %rsp,%rbx
mov    %r14,%rdi
mov    %rbx,%rdx
call   1030 <printf@plt>
lea    0x5(%rsp),%rsi
mov    %rbx,%rdi
mov    $0xa,%edx
call   1040 <memmove@plt>
lea    0xed9(%rip),%rsi
mov    %r14,%rdi
mov    %rax,%rdx
call   1030 <printf@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@__const.fig08_29.x = [16 x i8] c"Home Sweet Home\00"
@.str = [6 x i8] c"%s%s\0A\00"
@.str.1 = [42 x i8] c"The string in array x before memmove is: \00"
@.str.2 = [41 x i8] c"The string in array x after memmove is: \00"
define void @fig08_29() {
%1 = alloca [16 x i8]
%2 = bitcast [16 x i8]* %1 to i8*
%3 = getelementptr inbounds [16 x i8], [16 x i8]* %1, i64 0, i64 0
%4 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0), i8* %3)
%5 = getelementptr inbounds [16 x i8], [16 x i8]* %1, i64 0, i64 0
%6 = getelementptr inbounds [16 x i8], [16 x i8]* %1, i64 0, i64 5
%7 = call i64 @memmove(i8* %5, i8* %6, i32 10)
%8 = inttoptr i64 %7 to i8*
%9 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.2, i64 0, i64 0), i8* %8)
ret void
}

LLVM IR (-O2):
@__const.fig08_29.x = [16 x i8] c"Home Sweet Home\00"
@.str = [6 x i8] c"%s%s\0A\00"
@.str.1 = [42 x i8] c"The string in array x before memmove is: \00"
@.str.2 = [41 x i8] c"The string in array x after memmove is: \00"
define void @fig08_29() {
%1 = alloca [16 x i8]
%2 = getelementptr inbounds [16 x i8], [16 x i8]* %1, i64 0, i64 0
%3 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0), i8* %2)
%4 = getelementptr inbounds [16 x i8], [16 x i8]* %1, i64 0, i64 5
%5 = call i64 @memmove(i8* %2, i8* %4, i32 10)
%6 = inttoptr i64 %5 to i8*
%7 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.2, i64 0, i64 0), i8* %6)
ret void
}