#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*/ deadloop();
scalar_t__ memcmp(char *, char *, int);
int /*<<< orphan*/ memcpy(char *, char *, int);
int /*<<< orphan*/ memset(char *, int, int);
void simple_memtester(int x) {
  static char buffer1[(1024 * 1024)];
  static char buffer2[(1024 * 1024)];
  memset(buffer1, (x ^ 0x5A) & 0xFF, (1024 * 1024));
  memcpy(buffer2, buffer1, (1024 * 1024));
  if (memcmp(buffer2, buffer1, (1024 * 1024)) != 0)
    deadloop();
}


x86 assembly (clang, -O0):
<simple_memtester>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%esi
xor    $0x5a,%esi
and    $0xff,%esi
lea    0x2ef2(%rip),%rdi
mov    $0x100000,%edx
call   1030 <memset@plt>
lea    0x102ee1(%rip),%rdi
lea    0x2eda(%rip),%rsi
mov    $0x100000,%edx
call   1050 <memcpy@plt>
lea    0x102ec9(%rip),%rdi
lea    0x2ec2(%rip),%rsi
mov    $0x100000,%edx
call   1040 <memcmp@plt>
cmp    $0x0,%rax
je     11a9 <simple_memtester+0x69>
mov    $0x0,%al
call   1060 <deadloop@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<simple_memtester>:
push   %r14
push   %rbx
push   %rax
movzbl %dil,%esi
xor    $0x5a,%esi
lea    0x2efe(%rip),%rbx
mov    %rbx,%rdi
mov    $0x100000,%edx
call   1030 <memset@plt>
lea    0x102eea(%rip),%r14
mov    %r14,%rdi
mov    %rbx,%rsi
mov    $0x100000,%edx
call   1050 <memcpy@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    $0x100000,%edx
call   1040 <memcmp@plt>
test   %rax,%rax
je     1199 <simple_memtester+0x59>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1060 <deadloop@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@simple_memtester.buffer1 = internal global [1048576 x i8] zeroinitializer
@simple_memtester.buffer2 = internal global [1048576 x i8] zeroinitializer
define void @simple_memtester(i32 %0) {
%2 = alloca i32
store i32 %0, i32* %2
%3 = load i32, i32* %2
%4 = xor i32 %3, 90
%5 = and i32 %4, 255
%6 = call i32 @memset(i8* getelementptr inbounds ([1048576 x i8], [1048576 x i8]* @simple_memtester.buffer1, i64 0, i64 0), i32 %5, i32 1048576)
%7 = call i32 @memcpy(i8* getelementptr inbounds ([1048576 x i8], [1048576 x i8]* @simple_memtester.buffer2, i64 0, i64 0), i8* getelementptr inbounds ([1048576 x i8], [1048576 x i8]* @simple_memtester.buffer1, i64 0, i64 0), i32 1048576)
%8 = call i64 @memcmp(i8* getelementptr inbounds ([1048576 x i8], [1048576 x i8]* @simple_memtester.buffer2, i64 0, i64 0), i8* getelementptr inbounds ([1048576 x i8], [1048576 x i8]* @simple_memtester.buffer1, i64 0, i64 0), i32 1048576)
%9 = icmp ne i64 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %1
%11 = call i32 (...) @deadloop()
br label %12
12: ; preds = %10, %1
ret void
}

LLVM IR (-O2):
@simple_memtester.buffer1 = internal global [1048576 x i8] zeroinitializer
@simple_memtester.buffer2 = internal global [1048576 x i8] zeroinitializer
define void @simple_memtester(i32 %0) {
%2 = and i32 %0, 255
%3 = xor i32 %2, 90
%4 = tail call i32 @memset(i8* getelementptr inbounds ([1048576 x i8], [1048576 x i8]* @simple_memtester.buffer1, i64 0, i64 0), i32 %3, i32 1048576)
%5 = tail call i32 @memcpy(i8* getelementptr inbounds ([1048576 x i8], [1048576 x i8]* @simple_memtester.buffer2, i64 0, i64 0), i8* getelementptr inbounds ([1048576 x i8], [1048576 x i8]* @simple_memtester.buffer1, i64 0, i64 0), i32 1048576)
%6 = tail call i64 @memcmp(i8* getelementptr inbounds ([1048576 x i8], [1048576 x i8]* @simple_memtester.buffer2, i64 0, i64 0), i8* getelementptr inbounds ([1048576 x i8], [1048576 x i8]* @simple_memtester.buffer1, i64 0, i64 0), i32 1048576)
%7 = icmp eq i64 %6, 0
br i1 %7, label %10, label %8
8: ; preds = %1
%9 = tail call i32 (...) @deadloop()
br label %10
10: ; preds = %8, %1
ret void
}