#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 uint8_t;
typedef int uint32_t;

/* Variables and functions */
int /*<<< orphan*/ memmove_cpu(int *, int *, int);
int /*<<< orphan*/ memset_cpu(int *, int *, int);
int /*<<< orphan*/ my_memzero(int *, int);
int /*<<< orphan*/ my_reverse(int *, int);
int /*<<< orphan*/ print_memory(int *, int);
int /*<<< orphan*/ printf(char *);
void test_memory(uint8_t *data, uint32_t size) {
  printf("\ntest_memory :\n  ");
  print_memory(data, size);
  printf("\n  ");
  uint8_t *position = data;
  uint32_t length = 12;
  my_reverse(position, length);
  print_memory(data, size);
  printf("\n  ");
  position = data + 16;
  length = 4;
  uint8_t value = 0xEE;
  memset_cpu(position, &value, length);
  print_memory(data, size);
  printf("\n  ");
  uint8_t *source = data + 25;
  uint8_t *destination = data + 19;
  length = 6;
  memmove_cpu(destination, source, length);
  print_memory(data, size);
  printf("\n  ");
  position = data + 11;
  length = 5;
  my_memzero(position, length);
  print_memory(data, size);
  printf("\n  ");
  source = data;
  destination = data + 8;
  length = 8;
  memmove_cpu(destination, source, length);
  print_memory(data, size);
  printf("\n  ");
}


x86 assembly (clang, -O0):
<test_memory>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
lea    0xe8a(%rip),%rdi
call   1040 <printf@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1060 <print_memory@plt>
lea    0xe80(%rip),%rdi
call   1040 <printf@plt>
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
movl   $0xc,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   1080 <my_reverse@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1060 <print_memory@plt>
lea    0xe4d(%rip),%rdi
call   1040 <printf@plt>
mov    -0x8(%rbp),%rax
add    $0x40,%rax
mov    %rax,-0x18(%rbp)
movl   $0x4,-0x1c(%rbp)
movl   $0xee,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%edx
lea    -0x20(%rbp),%rsi
call   1050 <memset_cpu@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1060 <print_memory@plt>
lea    0xe0b(%rip),%rdi
call   1040 <printf@plt>
mov    -0x8(%rbp),%rax
add    $0x64,%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rax
add    $0x4c,%rax
mov    %rax,-0x30(%rbp)
movl   $0x6,-0x1c(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1030 <memmove_cpu@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1060 <print_memory@plt>
lea    0xdc4(%rip),%rdi
call   1040 <printf@plt>
mov    -0x8(%rbp),%rax
add    $0x2c,%rax
mov    %rax,-0x18(%rbp)
movl   $0x5,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   1070 <my_memzero@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1060 <print_memory@plt>
lea    0xd8d(%rip),%rdi
call   1040 <printf@plt>
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rax
mov    %rax,-0x30(%rbp)
movl   $0x8,-0x1c(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1030 <memmove_cpu@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1060 <print_memory@plt>
lea    0xd4a(%rip),%rdi
call   1040 <printf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_memory>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %esi,%ebp
mov    %rdi,%rbx
lea    0xe8c(%rip),%rdi
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    %ebp,%esi
call   1060 <print_memory@plt>
lea    0xe84(%rip),%r14
mov    %r14,%rdi
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    $0xc,%esi
call   1080 <my_reverse@plt>
mov    %rbx,%rdi
mov    %ebp,%esi
call   1060 <print_memory@plt>
mov    %r14,%rdi
call   1040 <printf@plt>
lea    0x40(%rbx),%rdi
movl   $0xee,0xc(%rsp)
lea    0xc(%rsp),%rsi
mov    $0x4,%edx
call   1050 <memset_cpu@plt>
mov    %rbx,%rdi
mov    %ebp,%esi
call   1060 <print_memory@plt>
mov    %r14,%rdi
call   1040 <printf@plt>
lea    0x64(%rbx),%rsi
lea    0x4c(%rbx),%rdi
mov    $0x6,%edx
call   1030 <memmove_cpu@plt>
mov    %rbx,%rdi
mov    %ebp,%esi
call   1060 <print_memory@plt>
mov    %r14,%rdi
call   1040 <printf@plt>
lea    0x2c(%rbx),%rdi
mov    $0x5,%esi
call   1070 <my_memzero@plt>
mov    %rbx,%rdi
mov    %ebp,%esi
call   1060 <print_memory@plt>
mov    %r14,%rdi
call   1040 <printf@plt>
lea    0x20(%rbx),%rdi
mov    %rbx,%rsi
mov    $0x8,%edx
call   1030 <memmove_cpu@plt>
mov    %rbx,%rdi
mov    %ebp,%esi
call   1060 <print_memory@plt>
mov    %r14,%rdi
call   1040 <printf@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [18 x i8] c"\0Atest_memory :\0A \00"
@.str.1 = [4 x i8] c"\0A \00"
define void @test_memory(i32* %0, i32 %1) {
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32*
%9 = alloca i32*
store i32* %0, i32** %3
store i32 %1, i32* %4
%10 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%11 = load i32*, i32** %3
%12 = load i32, i32* %4
%13 = call i32 @print_memory(i32* %11, i32 %12)
%14 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%15 = load i32*, i32** %3
store i32* %15, i32** %5
store i32 12, i32* %6
%16 = load i32*, i32** %5
%17 = load i32, i32* %6
%18 = call i32 @my_reverse(i32* %16, i32 %17)
%19 = load i32*, i32** %3
%20 = load i32, i32* %4
%21 = call i32 @print_memory(i32* %19, i32 %20)
%22 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%23 = load i32*, i32** %3
%24 = getelementptr inbounds i32, i32* %23, i64 16
store i32* %24, i32** %5
store i32 4, i32* %6
store i32 238, i32* %7
%25 = load i32*, i32** %5
%26 = load i32, i32* %6
%27 = call i32 @memset_cpu(i32* %25, i32* %7, i32 %26)
%28 = load i32*, i32** %3
%29 = load i32, i32* %4
%30 = call i32 @print_memory(i32* %28, i32 %29)
%31 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%32 = load i32*, i32** %3
%33 = getelementptr inbounds i32, i32* %32, i64 25
store i32* %33, i32** %8
%34 = load i32*, i32** %3
%35 = getelementptr inbounds i32, i32* %34, i64 19
store i32* %35, i32** %9
store i32 6, i32* %6
%36 = load i32*, i32** %9
%37 = load i32*, i32** %8
%38 = load i32, i32* %6
%39 = call i32 @memmove_cpu(i32* %36, i32* %37, i32 %38)
%40 = load i32*, i32** %3
%41 = load i32, i32* %4
%42 = call i32 @print_memory(i32* %40, i32 %41)
%43 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%44 = load i32*, i32** %3
%45 = getelementptr inbounds i32, i32* %44, i64 11
store i32* %45, i32** %5
store i32 5, i32* %6
%46 = load i32*, i32** %5
%47 = load i32, i32* %6
%48 = call i32 @my_memzero(i32* %46, i32 %47)
%49 = load i32*, i32** %3
%50 = load i32, i32* %4
%51 = call i32 @print_memory(i32* %49, i32 %50)
%52 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%53 = load i32*, i32** %3
store i32* %53, i32** %8
%54 = load i32*, i32** %3
%55 = getelementptr inbounds i32, i32* %54, i64 8
store i32* %55, i32** %9
store i32 8, i32* %6
%56 = load i32*, i32** %9
%57 = load i32*, i32** %8
%58 = load i32, i32* %6
%59 = call i32 @memmove_cpu(i32* %56, i32* %57, i32 %58)
%60 = load i32*, i32** %3
%61 = load i32, i32* %4
%62 = call i32 @print_memory(i32* %60, i32 %61)
%63 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [18 x i8] c"\0Atest_memory :\0A \00"
@.str.1 = [4 x i8] c"\0A \00"
define void @test_memory(i32* %0, i32 %1) {
%3 = alloca i32
%4 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%5 = tail call i32 @print_memory(i32* %0, i32 %1)
%6 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%7 = tail call i32 @my_reverse(i32* %0, i32 12)
%8 = tail call i32 @print_memory(i32* %0, i32 %1)
%9 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%10 = getelementptr inbounds i32, i32* %0, i64 16
%11 = bitcast i32* %3 to i8*
store i32 238, i32* %3
%12 = call i32 @memset_cpu(i32* %10, i32* %3, i32 4)
%13 = call i32 @print_memory(i32* %0, i32 %1)
%14 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%15 = getelementptr inbounds i32, i32* %0, i64 25
%16 = getelementptr inbounds i32, i32* %0, i64 19
%17 = call i32 @memmove_cpu(i32* %16, i32* %15, i32 6)
%18 = call i32 @print_memory(i32* %0, i32 %1)
%19 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%20 = getelementptr inbounds i32, i32* %0, i64 11
%21 = call i32 @my_memzero(i32* %20, i32 5)
%22 = call i32 @print_memory(i32* %0, i32 %1)
%23 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%24 = getelementptr inbounds i32, i32* %0, i64 8
%25 = call i32 @memmove_cpu(i32* %24, i32* %0, i32 8)
%26 = call i32 @print_memory(i32* %0, i32 %1)
%27 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
ret void
}