#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(int *, ...);
int /*<<< orphan*/ memmove(int *, int *, int);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ show_array(int *, int);
int main(void) {
  int values[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
  int target[10];
  double curious[10 / 2] = {2.0, 2.0e5, 2.0e10, 2.0e20, 5.0e30};
  puts("memcpy() used");
  puts("values (original data): ");
  show_array(values, 10);
  memcpy(target, values, 10 * sizeof(int));
  puts("target (copy of values):");
  show_array(target, 10);
  puts("\nUsing memmove() with overlapping ranges:");
  memmove(values + 2, values, 5 * sizeof(int));
  puts("values -- elements 0-5 copied to 2-7");
  show_array(values, 10);
  puts("Using memcopy to copy double to int:");
  memcpy(target, curious, (10 / 2) * sizeof(double));
  puts("target -- 5 doubles into 10 int positions:");
  show_array(target, 10 / 2);
  show_array(target + 5, 10 / 2);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x30(%rbp),%rdi
lea    0xec3(%rip),%rsi
mov    $0x28,%edx
call   1050 <memcpy@plt>
lea    -0x90(%rbp),%rdi
xor    %esi,%esi
mov    $0x28,%edx
call   1040 <memset@plt>
movsd  0xe8e(%rip),%xmm0
movsd  %xmm0,-0x90(%rbp)
ff
movsd  0xe76(%rip),%xmm0
movsd  %xmm0,-0x88(%rbp)
ff
movsd  0xe5e(%rip),%xmm0
movsd  %xmm0,-0x80(%rbp)
movsd  0xe49(%rip),%xmm0
movsd  %xmm0,-0x78(%rbp)
movsd  0xe34(%rip),%xmm0
movsd  %xmm0,-0x70(%rbp)
lea    0xe80(%rip),%rdi
call   1030 <puts@plt>
lea    0xe82(%rip),%rdi
call   1030 <puts@plt>
lea    -0x30(%rbp),%rdi
mov    $0xa,%esi
call   1070 <show_array@plt>
lea    -0x60(%rbp),%rdi
lea    -0x30(%rbp),%rsi
xor    %eax,%eax
mov    $0x28,%edx
call   1050 <memcpy@plt>
lea    0xe6d(%rip),%rdi
call   1030 <puts@plt>
lea    -0x60(%rbp),%rdi
mov    $0xa,%esi
call   1070 <show_array@plt>
lea    0xe6c(%rip),%rdi
call   1030 <puts@plt>
lea    -0x30(%rbp),%rdi
add    $0x8,%rdi
lea    -0x30(%rbp),%rsi
mov    $0x14,%edx
call   1060 <memmove@plt>
lea    0xe74(%rip),%rdi
call   1030 <puts@plt>
lea    -0x30(%rbp),%rdi
mov    $0xa,%esi
call   1070 <show_array@plt>
lea    0xe7f(%rip),%rdi
call   1030 <puts@plt>
lea    -0x60(%rbp),%rdi
lea    -0x90(%rbp),%rsi
xor    %eax,%eax
mov    $0x28,%edx
call   1050 <memcpy@plt>
lea    0xe81(%rip),%rdi
call   1030 <puts@plt>
lea    -0x60(%rbp),%rdi
mov    $0x5,%esi
call   1070 <show_array@plt>
lea    -0x60(%rbp),%rdi
add    $0x14,%rdi
mov    $0x5,%esi
call   1070 <show_array@plt>
xor    %eax,%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x88,%rsp
mov    0xeef(%rip),%rax
mov    %rax,0x20(%rsp)
movaps 0xed3(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movaps 0xeb7(%rip),%xmm0
movaps %xmm0,(%rsp)
movaps 0xe8c(%rip),%xmm0
movaps %xmm0,0x30(%rsp)
movaps 0xe90(%rip),%xmm0
movaps %xmm0,0x40(%rsp)
movabs $0x464f8def8808b024,%rax
8d 4f 46
mov    %rax,0x50(%rsp)
lea    0xead(%rip),%rdi
call   1030 <puts@plt>
lea    0xeaf(%rip),%rdi
call   1030 <puts@plt>
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0xa,%esi
call   1060 <show_array@plt>
lea    0x60(%rsp),%r14
mov    $0x28,%edx
mov    %r14,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <memcpy@plt>
lea    0xe95(%rip),%rdi
call   1030 <puts@plt>
mov    %r14,%rdi
mov    $0xa,%esi
call   1060 <show_array@plt>
lea    0xe95(%rip),%rdi
call   1030 <puts@plt>
lea    0x8(%rsp),%rdi
mov    %rbx,%rsi
mov    $0x14,%edx
call   1050 <memmove@plt>
lea    0xea1(%rip),%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
mov    $0xa,%esi
call   1060 <show_array@plt>
lea    0xead(%rip),%rdi
call   1030 <puts@plt>
lea    0x30(%rsp),%rsi
mov    $0x28,%edx
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <memcpy@plt>
lea    0xeb2(%rip),%rdi
call   1030 <puts@plt>
mov    %r14,%rdi
mov    $0x5,%esi
call   1060 <show_array@plt>
lea    0x74(%rsp),%rdi
mov    $0x5,%esi
call   1060 <show_array@plt>
xor    %eax,%eax
add    $0x88,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@__const.main.values = [10 x i32] [i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9, i32 10]
@.str = [14 x i8] c"memcpy() used\00"
@.str.1 = [25 x i8] c"values (original data): \00"
@.str.2 = [25 x i8] c"target (copy of values):\00"
@.str.3 = [42 x i8] c"\0AUsing memmove() with overlapping ranges:\00"
@.str.4 = [37 x i8] c"values -- elements 0-5 copied to 2-7\00"
@.str.5 = [37 x i8] c"Using memcopy to copy double to int:\00"
@.str.6 = [43 x i8] c"target -- 5 doubles into 10 int positions:\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [10 x i32]
%3 = alloca [10 x i32]
%4 = alloca [5 x double]
store i32 0, i32* %1
%5 = bitcast [10 x i32]* %2 to i8*
%6 = bitcast [5 x double]* %4 to i8*
%7 = bitcast i8* %6 to [5 x double]*
%8 = getelementptr inbounds [5 x double], [5 x double]* %7, i32 0, i32 0
store double 2.000000e+00, double* %8
%9 = getelementptr inbounds [5 x double], [5 x double]* %7, i32 0, i32 1
store double 2.000000e+05, double* %9
%10 = getelementptr inbounds [5 x double], [5 x double]* %7, i32 0, i32 2
store double 2.000000e+10, double* %10
%11 = getelementptr inbounds [5 x double], [5 x double]* %7, i32 0, i32 3
store double 2.000000e+20, double* %11
%12 = getelementptr inbounds [5 x double], [5 x double]* %7, i32 0, i32 4
store double 5.000000e+30, double* %12
%13 = call i32 @puts(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%14 = call i32 @puts(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
%15 = getelementptr inbounds [10 x i32], [10 x i32]* %2, i64 0, i64 0
%16 = call i32 @show_array(i32* %15, i32 10)
%17 = getelementptr inbounds [10 x i32], [10 x i32]* %3, i64 0, i64 0
%18 = getelementptr inbounds [10 x i32], [10 x i32]* %2, i64 0, i64 0
%19 = call i32 (i32*, ...) @memcpy(i32* %17, i32* %18, i64 40)
%20 = call i32 @puts(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0))
%21 = getelementptr inbounds [10 x i32], [10 x i32]* %3, i64 0, i64 0
%22 = call i32 @show_array(i32* %21, i32 10)
%23 = call i32 @puts(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.3, i64 0, i64 0))
%24 = getelementptr inbounds [10 x i32], [10 x i32]* %2, i64 0, i64 0
%25 = getelementptr inbounds i32, i32* %24, i64 2
%26 = getelementptr inbounds [10 x i32], [10 x i32]* %2, i64 0, i64 0
%27 = call i32 @memmove(i32* %25, i32* %26, i32 20)
%28 = call i32 @puts(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.4, i64 0, i64 0))
%29 = getelementptr inbounds [10 x i32], [10 x i32]* %2, i64 0, i64 0
%30 = call i32 @show_array(i32* %29, i32 10)
%31 = call i32 @puts(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.5, i64 0, i64 0))
%32 = getelementptr inbounds [10 x i32], [10 x i32]* %3, i64 0, i64 0
%33 = getelementptr inbounds [5 x double], [5 x double]* %4, i64 0, i64 0
%34 = call i32 (i32*, ...) @memcpy(i32* %32, double* %33, i64 40)
%35 = call i32 @puts(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.6, i64 0, i64 0))
%36 = getelementptr inbounds [10 x i32], [10 x i32]* %3, i64 0, i64 0
%37 = call i32 @show_array(i32* %36, i32 5)
%38 = getelementptr inbounds [10 x i32], [10 x i32]* %3, i64 0, i64 0
%39 = getelementptr inbounds i32, i32* %38, i64 5
%40 = call i32 @show_array(i32* %39, i32 5)
ret i32 0
}

LLVM IR (-O2):
@__const.main.values = [10 x i32] [i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9, i32 10]
@.str = [14 x i8] c"memcpy() used\00"
@.str.1 = [25 x i8] c"values (original data): \00"
@.str.2 = [25 x i8] c"target (copy of values):\00"
@.str.3 = [42 x i8] c"\0AUsing memmove() with overlapping ranges:\00"
@.str.4 = [37 x i8] c"values -- elements 0-5 copied to 2-7\00"
@.str.5 = [37 x i8] c"Using memcopy to copy double to int:\00"
@.str.6 = [43 x i8] c"target -- 5 doubles into 10 int positions:\00"
define i32 @main() {
%1 = alloca [10 x i32]
%2 = alloca [10 x i32]
%3 = alloca [5 x double]
%4 = bitcast [10 x i32]* %1 to i8*
%5 = bitcast [10 x i32]* %2 to i8*
%6 = bitcast [5 x double]* %3 to i8*
%7 = getelementptr inbounds [5 x double], [5 x double]* %3, i64 0, i64 0
%8 = bitcast [5 x double]* %3 to <2 x double>*
store <2 x double> <double 2.000000e+00, double 2.000000e+05>, <2 x double>* %8
%9 = getelementptr inbounds [5 x double], [5 x double]* %3, i64 0, i64 2
%10 = bitcast double* %9 to <2 x double>*
store <2 x double> <double 2.000000e+10, double 2.000000e+20>, <2 x double>* %10
%11 = getelementptr inbounds [5 x double], [5 x double]* %3, i64 0, i64 4
store double 5.000000e+30, double* %11
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
%14 = getelementptr inbounds [10 x i32], [10 x i32]* %1, i64 0, i64 0
%15 = call i32 @show_array(i32* %14, i32 10)
%16 = getelementptr inbounds [10 x i32], [10 x i32]* %2, i64 0, i64 0
%17 = call i32 (i32*, ...) @memcpy(i32* %16, i32* %14, i64 40)
%18 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0))
%19 = call i32 @show_array(i32* %16, i32 10)
%20 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str.3, i64 0, i64 0))
%21 = getelementptr inbounds [10 x i32], [10 x i32]* %1, i64 0, i64 2
%22 = call i32 @memmove(i32* %21, i32* %14, i32 20)
%23 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str.4, i64 0, i64 0))
%24 = call i32 @show_array(i32* %14, i32 10)
%25 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str.5, i64 0, i64 0))
%26 = call i32 (i32*, ...) @memcpy(i32* %16, double* %7, i64 40)
%27 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @.str.6, i64 0, i64 0))
%28 = call i32 @show_array(i32* %16, i32 5)
%29 = getelementptr inbounds [10 x i32], [10 x i32]* %2, i64 0, i64 5
%30 = call i32 @show_array(i32* %29, i32 5)
ret i32 0
}