#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*/ puts(char *);
scalar_t__ test_ram(unsigned char *, unsigned char, unsigned int);
scalar_t__ test_ram_alea(unsigned char *, unsigned int);
int LocalRamTester() {
  int y;
  unsigned char *ptr = (unsigned char *)0x10000000;
  unsigned char pattern[] = {0x00, 0xFF, 0xF0, 0x0F};
  unsigned int RAM_SPACE = 64 * 1024;
  unsigned int TEST_LENGTH = 4 * 1024;
  puts("- TESTING INTERNAL RAM BEHAVIOR\n");
  int error = 0;
  for (y = 0; y < (RAM_SPACE / TEST_LENGTH); y++) {
    error += test_ram(ptr, pattern[0], TEST_LENGTH);
    error += test_ram(ptr, pattern[1], TEST_LENGTH);
    error += test_ram(ptr, pattern[2], TEST_LENGTH);
    error += test_ram(ptr, pattern[3], TEST_LENGTH);
    error += test_ram_alea(ptr, TEST_LENGTH);
    ptr += TEST_LENGTH;
  }
  if (error == 0) {
    puts("  + 64kbyte memory is OK\n");
  } else {
    puts("  + ERROR with the 64kbyte memory\n");
  }
  return 0;
}


x86 assembly (clang, -O0):
<LocalRamTester>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    $0x10000000,%eax
mov    %rax,-0x10(%rbp)
mov    0xeb9(%rip),%eax
mov    %eax,-0x14(%rbp)
movl   $0x10000,-0x18(%rbp)
movl   $0x1000,-0x1c(%rbp)
lea    0xea5(%rip),%rdi
call   1030 <puts@plt>
movl   $0x0,-0x20(%rbp)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x18(%rbp),%eax
xor    %edx,%edx
divl   -0x1c(%rbp)
mov    %eax,%ecx
mov    -0x24(%rbp),%eax
cmp    %ecx,%eax
jae    1240 <LocalRamTester+0x110>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%al
mov    -0x1c(%rbp),%edx
movzbl %al,%esi
call   1040 <test_ram@plt>
mov    %rax,%rcx
movslq -0x20(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x13(%rbp),%al
mov    -0x1c(%rbp),%edx
movzbl %al,%esi
call   1040 <test_ram@plt>
mov    %rax,%rcx
movslq -0x20(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x12(%rbp),%al
mov    -0x1c(%rbp),%edx
movzbl %al,%esi
call   1040 <test_ram@plt>
mov    %rax,%rcx
movslq -0x20(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x11(%rbp),%al
mov    -0x1c(%rbp),%edx
movzbl %al,%esi
call   1040 <test_ram@plt>
mov    %rax,%rcx
movslq -0x20(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   1050 <test_ram_alea@plt>
mov    %rax,%rcx
movslq -0x20(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x20(%rbp)
mov    -0x1c(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,%ecx
add    %rcx,%rax
mov    %rax,-0x10(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    1172 <LocalRamTester+0x42>
cmpl   $0x0,-0x20(%rbp)
jne    125b <LocalRamTester+0x12b>
lea    0xdd4(%rip),%rdi
call   1030 <puts@plt>
jmp    1267 <LocalRamTester+0x137>
lea    0xddd(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<LocalRamTester>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
lea    0xec0(%rip),%rdi
call   1030 <puts@plt>
xor    %r13d,%r13d
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
lea    0x10000000(%r13),%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x1000,%edx
call   1040 <test_ram@plt>
mov    %rax,%r15
add    %ebx,%r15d
mov    %r14,%rdi
mov    $0xff,%esi
mov    $0x1000,%edx
call   1040 <test_ram@plt>
mov    %rax,%rbx
add    %r15d,%ebx
mov    %r14,%rdi
mov    $0xf0,%esi
mov    $0x1000,%edx
call   1040 <test_ram@plt>
mov    %rax,%r15
add    %ebx,%r15d
mov    %r14,%rdi
mov    $0xf,%esi
mov    $0x1000,%edx
call   1040 <test_ram@plt>
mov    %rax,%r12
add    %r15d,%r12d
mov    %r14,%rdi
mov    $0x1000,%esi
call   1050 <test_ram_alea@plt>
mov    %rax,%rbx
add    %r12d,%ebx
add    $0x1000,%r13
cmp    $0x10000,%r13d
jne    1150 <LocalRamTester+0x20>
test   %ebx,%ebx
lea    0xe3d(%rip),%rax
lea    0xe50(%rip),%rdi
cmove  %rax,%rdi
call   1030 <puts@plt>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@__const.LocalRamTester.pattern = [4 x i8] c"\00\FF\F0\0F"
@.str = [33 x i8] c"- TESTING INTERNAL RAM BEHAVIOR\0A\00"
@.str.1 = [26 x i8] c" + 64kbyte memory is OK\0A\00"
@.str.2 = [35 x i8] c" + ERROR with the 64kbyte memory\0A\00"
define i32 @LocalRamTester() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca [4 x i8]
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i8* inttoptr (i64 268435456 to i8*), i8** %2
%7 = bitcast [4 x i8]* %3 to i8*
store i32 65536, i32* %4
store i32 4096, i32* %5
%8 = call i32 @puts(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %6
store i32 0, i32* %1
br label %9
9: ; preds = %63, %0
%10 = load i32, i32* %1
%11 = load i32, i32* %4
%12 = load i32, i32* %5
%13 = udiv i32 %11, %12
%14 = icmp ult i32 %10, %13
br i1 %14, label %15, label %66
15: ; preds = %9
%16 = load i8*, i8** %2
%17 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 0
%18 = load i8, i8* %17
%19 = load i32, i32* %5
%20 = call i64 @test_ram(i8* %16, i8 zeroext %18, i32 %19)
%21 = load i32, i32* %6
%22 = sext i32 %21 to i64
%23 = add nsw i64 %22, %20
%24 = trunc i64 %23 to i32
store i32 %24, i32* %6
%25 = load i8*, i8** %2
%26 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 1
%27 = load i8, i8* %26
%28 = load i32, i32* %5
%29 = call i64 @test_ram(i8* %25, i8 zeroext %27, i32 %28)
%30 = load i32, i32* %6
%31 = sext i32 %30 to i64
%32 = add nsw i64 %31, %29
%33 = trunc i64 %32 to i32
store i32 %33, i32* %6
%34 = load i8*, i8** %2
%35 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 2
%36 = load i8, i8* %35
%37 = load i32, i32* %5
%38 = call i64 @test_ram(i8* %34, i8 zeroext %36, i32 %37)
%39 = load i32, i32* %6
%40 = sext i32 %39 to i64
%41 = add nsw i64 %40, %38
%42 = trunc i64 %41 to i32
store i32 %42, i32* %6
%43 = load i8*, i8** %2
%44 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 3
%45 = load i8, i8* %44
%46 = load i32, i32* %5
%47 = call i64 @test_ram(i8* %43, i8 zeroext %45, i32 %46)
%48 = load i32, i32* %6
%49 = sext i32 %48 to i64
%50 = add nsw i64 %49, %47
%51 = trunc i64 %50 to i32
store i32 %51, i32* %6
%52 = load i8*, i8** %2
%53 = load i32, i32* %5
%54 = call i64 @test_ram_alea(i8* %52, i32 %53)
%55 = load i32, i32* %6
%56 = sext i32 %55 to i64
%57 = add nsw i64 %56, %54
%58 = trunc i64 %57 to i32
store i32 %58, i32* %6
%59 = load i32, i32* %5
%60 = load i8*, i8** %2
%61 = zext i32 %59 to i64
%62 = getelementptr inbounds i8, i8* %60, i64 %61
store i8* %62, i8** %2
br label %63
63: ; preds = %15
%64 = load i32, i32* %1
%65 = add nsw i32 %64, 1
store i32 %65, i32* %1
br label %9
66: ; preds = %9
%67 = load i32, i32* %6
%68 = icmp eq i32 %67, 0
br i1 %68, label %69, label %71
69: ; preds = %66
%70 = call i32 @puts(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
br label %73
71: ; preds = %66
%72 = call i32 @puts(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0))
br label %73
73: ; preds = %71, %69
ret i32 0
}

LLVM IR (-O2):
@.str = [33 x i8] c"- TESTING INTERNAL RAM BEHAVIOR\0A\00"
@.str.1 = [26 x i8] c" + 64kbyte memory is OK\0A\00"
@.str.2 = [35 x i8] c" + ERROR with the 64kbyte memory\0A\00"
define i32 @LocalRamTester() {
%1 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
br label %2
2: ; preds = %0, %2
%3 = phi i32 [ 0, %0 ], [ %20, %2 ]
%4 = phi i32 [ 0, %0 ], [ %22, %2 ]
%5 = phi i8* [ inttoptr (i64 268435456 to i8*), %0 ], [ %21, %2 ]
%6 = tail call i64 @test_ram(i8* %5, i8 zeroext 0, i32 4096)
%7 = trunc i64 %6 to i32
%8 = add i32 %3, %7
%9 = tail call i64 @test_ram(i8* %5, i8 zeroext -1, i32 4096)
%10 = trunc i64 %9 to i32
%11 = add i32 %8, %10
%12 = tail call i64 @test_ram(i8* %5, i8 zeroext -16, i32 4096)
%13 = trunc i64 %12 to i32
%14 = add i32 %11, %13
%15 = tail call i64 @test_ram(i8* %5, i8 zeroext 15, i32 4096)
%16 = trunc i64 %15 to i32
%17 = add i32 %14, %16
%18 = tail call i64 @test_ram_alea(i8* %5, i32 4096)
%19 = trunc i64 %18 to i32
%20 = add i32 %17, %19
%21 = getelementptr inbounds i8, i8* %5, i64 4096
%22 = add nuw nsw i32 %4, 1
%23 = icmp eq i32 %22, 16
br i1 %23, label %24, label %2
24: ; preds = %2
%25 = icmp eq i32 %20, 0
%26 = select i1 %25, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0)
%27 = tail call i32 @puts(i8* dereferenceable(1) %26)
ret i32 0
}