#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*/ check_malloc(char *);
int /*<<< orphan*/ free(char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ memcpy(char *, char *, int);
int /*<<< orphan*/ memset(char *, char, int);
int /*<<< orphan*/ print_array(char *, int);
int /*<<< orphan*/ printf(char *);
int main() {
  char *sp = (char *)malloc(sizeof(char) * 10);
  check_malloc(sp);
  char *dp = (char *)malloc(10);
  check_malloc(dp);
  memset(sp, '*', 10);
  memcpy(dp, sp, 5);
  printf("Source array\n");
  print_array(sp, 10);
  printf("Destination array\n");
  print_array(dp, 10);
  free(sp);
  free(dp);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0xa,%edi
call   1090 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1080 <check_malloc@plt>
mov    $0xa,%edi
call   1090 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1080 <check_malloc@plt>
mov    -0x10(%rbp),%rdi
mov    $0x2a,%esi
mov    $0xa,%edx
call   1060 <memset@plt>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    $0x5,%edx
call   1070 <memcpy@plt>
lea    0xe27(%rip),%rdi
call   1050 <printf@plt>
mov    -0x10(%rbp),%rdi
mov    $0xa,%esi
call   1040 <print_array@plt>
lea    0xe1b(%rip),%rdi
call   1050 <printf@plt>
mov    -0x18(%rbp),%rdi
mov    $0xa,%esi
call   1040 <print_array@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    $0xa,%edi
call   1090 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1080 <check_malloc@plt>
mov    $0xa,%edi
call   1090 <malloc@plt>
mov    %rax,%r14
mov    %rax,%rdi
call   1080 <check_malloc@plt>
mov    %rbx,%rdi
mov    $0x2a,%esi
mov    $0xa,%edx
call   1060 <memset@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    $0x5,%edx
call   1070 <memcpy@plt>
lea    0xe39(%rip),%rdi
call   1040 <puts@plt>
mov    %rbx,%rdi
mov    $0xa,%esi
call   1050 <print_array@plt>
lea    0xe2d(%rip),%rdi
call   1040 <puts@plt>
mov    %r14,%rdi
mov    $0xa,%esi
call   1050 <print_array@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r14,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [14 x i8] c"Source array\0A\00"
@.str.1 = [19 x i8] c"Destination array\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i8*
store i32 0, i32* %1
%4 = call i64 @malloc(i32 10)
%5 = inttoptr i64 %4 to i8*
store i8* %5, i8** %2
%6 = load i8*, i8** %2
%7 = call i32 @check_malloc(i8* %6)
%8 = call i64 @malloc(i32 10)
%9 = inttoptr i64 %8 to i8*
store i8* %9, i8** %3
%10 = load i8*, i8** %3
%11 = call i32 @check_malloc(i8* %10)
%12 = load i8*, i8** %2
%13 = call i32 @memset(i8* %12, i8 signext 42, i32 10)
%14 = load i8*, i8** %3
%15 = load i8*, i8** %2
%16 = call i32 @memcpy(i8* %14, i8* %15, i32 5)
%17 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%18 = load i8*, i8** %2
%19 = call i32 @print_array(i8* %18, i32 10)
%20 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
%21 = load i8*, i8** %3
%22 = call i32 @print_array(i8* %21, i32 10)
%23 = load i8*, i8** %2
%24 = call i32 @free(i8* %23)
%25 = load i8*, i8** %3
%26 = call i32 @free(i8* %25)
ret i32 0
}

LLVM IR (-O2):
@str = [13 x i8] c"Source array\00"
@str.2 = [18 x i8] c"Destination array\00"
define i32 @main() {
%1 = tail call i64 @malloc(i32 10)
%2 = inttoptr i64 %1 to i8*
%3 = tail call i32 @check_malloc(i8* %2)
%4 = tail call i64 @malloc(i32 10)
%5 = inttoptr i64 %4 to i8*
%6 = tail call i32 @check_malloc(i8* %5)
%7 = tail call i32 @memset(i8* %2, i8 signext 42, i32 10)
%8 = tail call i32 @memcpy(i8* %5, i8* %2, i32 5)
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str, i64 0, i64 0))
%10 = tail call i32 @print_array(i8* %2, i32 10)
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str.2, i64 0, i64 0))
%12 = tail call i32 @print_array(i8* %5, i32 10)
%13 = tail call i32 @free(i8* %2)
%14 = tail call i32 @free(i8* %5)
ret i32 0
}