#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*/ LocalRamTester();
int /*<<< orphan*/ ProgramExec();
int /*<<< orphan*/ ReceiveProgram();
int getch();
unsigned long getnum();
int /*<<< orphan*/ isStillAlive();
int /*<<< orphan*/ print_hex(unsigned int);
int /*<<< orphan*/ putchar(int);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ show_help();
int /*<<< orphan*/ version();
char *xtoa(unsigned long);
int main() {
  int ch;
  unsigned long address, value;
  puts("\r\n\r\n\r\n\r\n");
  version();
  LocalRamTester();
  show_help();
  for (;;) {
    puts("> ");
    ch = getch();
    address = 0;
    if ('0' <= ch && ch <= '5') {
      putchar(ch);
      puts("\nAddress in hex> ");
      address = getnum();
      puts("Address = ");
      puts(xtoa(address));
      puts("\n");
    }
    switch (ch) {
    case 'h':
    case 'H':
      show_help();
      break;
    case 'V':
    case 'v':
      version();
      break;
    case '1':
      value = (*(volatile int *)(address));
      puts(xtoa(value));
      puts("\n");
      break;
    case '2':
      puts("\nValue in hex> ");
      value = getnum();
      puts(xtoa(value));
      *(volatile int *)(address) = (value);
      break;
    case '3':
      value = *(unsigned char *)address;
      puts(xtoa(value));
      puts("\n");
      break;
    case '4':
      puts("\nValue in hex> ");
      value = getnum();
      puts(xtoa(value));
      *(unsigned char *)address = value;
      break;
    case '7':
      ProgramExec();
      break;
    case '8':
      isStillAlive();
      break;
    case 0xFF:
      ReceiveProgram();
      break;
    default:
      puts("=> ERROR (value = ");
      print_hex((unsigned int)ch);
      puts(")\r\n");
      break;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe2a(%rip),%rdi
call   1060 <puts@plt>
mov    $0x0,%al
call   1090 <version@plt>
mov    $0x0,%al
call   10e0 <LocalRamTester@plt>
mov    $0x0,%al
call   10a0 <show_help@plt>
lea    0xe3c(%rip),%rdi
call   1060 <puts@plt>
mov    $0x0,%al
call   10c0 <getch@plt>
mov    %eax,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
mov    $0x30,%eax
cmp    -0x8(%rbp),%eax
jg     126e <main+0xae>
cmpl   $0x35,-0x8(%rbp)
jg     126e <main+0xae>
mov    -0x8(%rbp),%edi
call   1050 <putchar@plt>
lea    0xdd4(%rip),%rdi
call   1060 <puts@plt>
mov    $0x0,%al
call   1030 <getnum@plt>
mov    %rax,-0x10(%rbp)
lea    0xdcf(%rip),%rdi
call   1060 <puts@plt>
mov    -0x10(%rbp),%rdi
call   10d0 <xtoa@plt>
mov    %rax,%rdi
call   1060 <puts@plt>
lea    0xd9e(%rip),%rdi
call   1060 <puts@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0x1c(%rbp)
sub    $0x31,%eax
je     1346 <main+0x186>
jmp    1282 <main+0xc2>
mov    -0x1c(%rbp),%eax
sub    $0x32,%eax
je     1374 <main+0x1b4>
jmp    1293 <main+0xd3>
mov    -0x1c(%rbp),%eax
sub    $0x33,%eax
je     13ad <main+0x1ed>
jmp    12a4 <main+0xe4>
mov    -0x1c(%rbp),%eax
sub    $0x34,%eax
je     13da <main+0x21a>
jmp    12b5 <main+0xf5>
mov    -0x1c(%rbp),%eax
sub    $0x37,%eax
je     1413 <main+0x253>
jmp    12c6 <main+0x106>
mov    -0x1c(%rbp),%eax
sub    $0x38,%eax
je     141f <main+0x25f>
jmp    12d7 <main+0x117>
mov    -0x1c(%rbp),%eax
sub    $0x48,%eax
je     132e <main+0x16e>
jmp    12e8 <main+0x128>
mov    -0x1c(%rbp),%eax
sub    $0x56,%eax
je     133a <main+0x17a>
jmp    12f9 <main+0x139>
mov    -0x1c(%rbp),%eax
sub    $0x68,%eax
je     132e <main+0x16e>
jmp    130a <main+0x14a>
mov    -0x1c(%rbp),%eax
sub    $0x76,%eax
je     133a <main+0x17a>
jmp    131b <main+0x15b>
mov    -0x1c(%rbp),%eax
sub    $0xff,%eax
je     142b <main+0x26b>
jmp    1437 <main+0x277>
mov    $0x0,%al
call   10a0 <show_help@plt>
jmp    1457 <main+0x297>
mov    $0x0,%al
call   1090 <version@plt>
jmp    1457 <main+0x297>
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
cltq
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   10d0 <xtoa@plt>
mov    %rax,%rdi
call   1060 <puts@plt>
lea    0xc9d(%rip),%rdi
call   1060 <puts@plt>
jmp    1457 <main+0x297>
lea    0xcab(%rip),%rdi
call   1060 <puts@plt>
mov    $0x0,%al
call   1030 <getnum@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   10d0 <xtoa@plt>
mov    %rax,%rdi
call   1060 <puts@plt>
mov    -0x18(%rbp),%rax
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
jmp    1457 <main+0x297>
mov    -0x10(%rbp),%rax
movzbl (%rax),%eax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   10d0 <xtoa@plt>
mov    %rax,%rdi
call   1060 <puts@plt>
lea    0xc37(%rip),%rdi
call   1060 <puts@plt>
jmp    1457 <main+0x297>
lea    0xc45(%rip),%rdi
call   1060 <puts@plt>
mov    $0x0,%al
call   1030 <getnum@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   10d0 <xtoa@plt>
mov    %rax,%rdi
call   1060 <puts@plt>
mov    -0x18(%rbp),%rax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,(%rax)
jmp    1457 <main+0x297>
mov    $0x0,%al
call   1070 <ProgramExec@plt>
jmp    1457 <main+0x297>
mov    $0x0,%al
call   1080 <isStillAlive@plt>
jmp    1457 <main+0x297>
mov    $0x0,%al
call   1040 <ReceiveProgram@plt>
jmp    1457 <main+0x297>
lea    0xbf8(%rip),%rdi
call   1060 <puts@plt>
mov    -0x8(%rbp),%edi
call   10b0 <print_hex@plt>
lea    0xbf7(%rip),%rdi
call   1060 <puts@plt>
jmp    11f0 <main+0x30>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0xf46(%rip),%rdi
call   1060 <puts@plt>
xor    %eax,%eax
call   1090 <version@plt>
xor    %eax,%eax
call   10e0 <LocalRamTester@plt>
xor    %eax,%eax
call   10a0 <show_help@plt>
lea    0xf58(%rip),%r14
lea    0xf27(%rip),%rbx
lea    0xf1e(%rip),%r12
lea    0xdf8(%rip),%r15
jmp    1220 <main+0x60>
xor    %eax,%eax
call   1090 <version@plt>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
call   1060 <puts@plt>
xor    %eax,%eax
call   10c0 <getch@plt>
mov    %eax,%r13d
lea    -0x30(%r13),%eax
cmp    $0x5,%eax
ja     1280 <main+0xc0>
mov    %r13d,%edi
call   1050 <putchar@plt>
mov    %rbx,%rdi
call   1060 <puts@plt>
xor    %eax,%eax
call   1030 <getnum@plt>
mov    %rax,%rbp
lea    0xed7(%rip),%rdi
call   1060 <puts@plt>
mov    %rbp,%rdi
call   10d0 <xtoa@plt>
mov    %rax,%rdi
call   1060 <puts@plt>
mov    %r12,%rdi
call   1060 <puts@plt>
jmp    1282 <main+0xc2>
nopl   0x0(%rax,%rax,1)
xor    %ebp,%ebp
lea    -0x31(%r13),%eax
cmp    $0x45,%eax
ja     129d <main+0xdd>
movslq (%r15,%rax,4),%rax
add    %r15,%rax
jmp    *%rax
xor    %eax,%eax
call   10a0 <show_help@plt>
jmp    1220 <main+0x60>
cmp    $0xff,%r13d
jne    12b2 <main+0xf2>
xor    %eax,%eax
call   1040 <ReceiveProgram@plt>
jmp    1220 <main+0x60>
lea    0xe95(%rip),%rdi
call   1060 <puts@plt>
mov    %r13d,%edi
call   10b0 <print_hex@plt>
lea    0xe94(%rip),%rdi
call   1060 <puts@plt>
jmp    1220 <main+0x60>
movslq 0x0(%rbp),%rdi
jmp    1316 <main+0x156>
lea    0xe5a(%rip),%rdi
call   1060 <puts@plt>
xor    %eax,%eax
call   1030 <getnum@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   10d0 <xtoa@plt>
mov    %rax,%rdi
call   1060 <puts@plt>
mov    %ebx,0x0(%rbp)
lea    0xe14(%rip),%rbx
jmp    1220 <main+0x60>
movzbl 0x0(%rbp),%edi
call   10d0 <xtoa@plt>
mov    %rax,%rdi
call   1060 <puts@plt>
mov    %r12,%rdi
call   1060 <puts@plt>
jmp    1220 <main+0x60>
lea    0xe07(%rip),%rdi
call   1060 <puts@plt>
xor    %eax,%eax
call   1030 <getnum@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   10d0 <xtoa@plt>
mov    %rax,%rdi
call   1060 <puts@plt>
mov    %bl,0x0(%rbp)
lea    0xdc1(%rip),%rbx
jmp    1220 <main+0x60>
xor    %eax,%eax
call   1070 <ProgramExec@plt>
jmp    1220 <main+0x60>
xor    %eax,%eax
call   1080 <isStillAlive@plt>
jmp    1220 <main+0x60>

LLVM IR (-O0):
@.str = [9 x i8] c"\0D\0A\0D\0A\0D\0A\0D\0A\00"
@.str.1 = [3 x i8] c"> \00"
@.str.2 = [18 x i8] c"\0AAddress in hex> \00"
@.str.3 = [11 x i8] c"Address = \00"
@.str.4 = [2 x i8] c"\0A\00"
@.str.5 = [16 x i8] c"\0AValue in hex> \00"
@.str.6 = [19 x i8] c"=> ERROR (value = \00"
@.str.7 = [4 x i8] c")\0D\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i64
%4 = alloca i64
store i32 0, i32* %1
%5 = call i32 @puts(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%6 = call i32 (...) @version()
%7 = call i32 (...) @LocalRamTester()
%8 = call i32 (...) @show_help()
br label %9
9: ; preds = %82, %0
%10 = call i32 @puts(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%11 = call i32 (...) @getch()
store i32 %11, i32* %2
store i64 0, i64* %3
%12 = load i32, i32* %2
%13 = icmp sle i32 48, %12
br i1 %13, label %14, label %27
14: ; preds = %9
%15 = load i32, i32* %2
%16 = icmp sle i32 %15, 53
br i1 %16, label %17, label %27
17: ; preds = %14
%18 = load i32, i32* %2
%19 = call i32 @putchar(i32 %18)
%20 = call i32 @puts(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0))
%21 = call i64 (...) @getnum()
store i64 %21, i64* %3
%22 = call i32 @puts(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0))
%23 = load i64, i64* %3
%24 = call i8* @xtoa(i64 %23)
%25 = call i32 @puts(i8* %24)
%26 = call i32 @puts(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
br label %27
27: ; preds = %17, %14, %9
%28 = load i32, i32* %2
switch i32 %28, label %77 [
i32 104, label %29
i32 72, label %29
i32 86, label %31
i32 118, label %31
i32 49, label %33
i32 50, label %42
i32 51, label %52
i32 52, label %61
i32 55, label %71
i32 56, label %73
i32 255, label %75
]
29: ; preds = %27, %27
%30 = call i32 (...) @show_help()
br label %82
31: ; preds = %27, %27
%32 = call i32 (...) @version()
br label %82
33: ; preds = %27
%34 = load i64, i64* %3
%35 = inttoptr i64 %34 to i32*
%36 = load volatile i32, i32* %35
%37 = sext i32 %36 to i64
store i64 %37, i64* %4
%38 = load i64, i64* %4
%39 = call i8* @xtoa(i64 %38)
%40 = call i32 @puts(i8* %39)
%41 = call i32 @puts(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
br label %82
42: ; preds = %27
%43 = call i32 @puts(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0))
%44 = call i64 (...) @getnum()
store i64 %44, i64* %4
%45 = load i64, i64* %4
%46 = call i8* @xtoa(i64 %45)
%47 = call i32 @puts(i8* %46)
%48 = load i64, i64* %4
%49 = trunc i64 %48 to i32
%50 = load i64, i64* %3
%51 = inttoptr i64 %50 to i32*
store volatile i32 %49, i32* %51
br label %82
52: ; preds = %27
%53 = load i64, i64* %3
%54 = inttoptr i64 %53 to i8*
%55 = load i8, i8* %54
%56 = zext i8 %55 to i64
store i64 %56, i64* %4
%57 = load i64, i64* %4
%58 = call i8* @xtoa(i64 %57)
%59 = call i32 @puts(i8* %58)
%60 = call i32 @puts(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
br label %82
61: ; preds = %27
%62 = call i32 @puts(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0))
%63 = call i64 (...) @getnum()
store i64 %63, i64* %4
%64 = load i64, i64* %4
%65 = call i8* @xtoa(i64 %64)
%66 = call i32 @puts(i8* %65)
%67 = load i64, i64* %4
%68 = trunc i64 %67 to i8
%69 = load i64, i64* %3
%70 = inttoptr i64 %69 to i8*
store i8 %68, i8* %70
br label %82
71: ; preds = %27
%72 = call i32 (...) @ProgramExec()
br label %82
73: ; preds = %27
%74 = call i32 (...) @isStillAlive()
br label %82
75: ; preds = %27
%76 = call i32 (...) @ReceiveProgram()
br label %82
77: ; preds = %27
%78 = call i32 @puts(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.6, i64 0, i64 0))
%79 = load i32, i32* %2
%80 = call i32 @print_hex(i32 %79)
%81 = call i32 @puts(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0))
br label %82
82: ; preds = %77, %75, %73, %71, %61, %52, %42, %33, %31, %29
br label %9
}

LLVM IR (-O2):
@.str = [9 x i8] c"\0D\0A\0D\0A\0D\0A\0D\0A\00"
@.str.1 = [3 x i8] c"> \00"
@.str.2 = [18 x i8] c"\0AAddress in hex> \00"
@.str.3 = [11 x i8] c"Address = \00"
@.str.4 = [2 x i8] c"\0A\00"
@.str.5 = [16 x i8] c"\0AValue in hex> \00"
@.str.6 = [19 x i8] c"=> ERROR (value = \00"
@.str.7 = [4 x i8] c")\0D\0A\00"
define i32 @main() {
%1 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%2 = tail call i32 (...) @version()
%3 = tail call i32 (...) @LocalRamTester()
%4 = tail call i32 (...) @show_help()
br label %5
5: ; preds = %62, %0
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%7 = tail call i32 (...) @getch()
%8 = add i32 %7, -48
%9 = icmp ult i32 %8, 6
br i1 %9, label %10, label %18
10: ; preds = %5
%11 = tail call i32 @putchar(i32 %7)
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0))
%13 = tail call i64 (...) @getnum()
%14 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0))
%15 = tail call i8* @xtoa(i64 %13)
%16 = tail call i32 @puts(i8* dereferenceable(1) %15)
%17 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
br label %18
18: ; preds = %10, %5
%19 = phi i64 [ %13, %10 ], [ 0, %5 ]
switch i32 %7, label %58 [
i32 104, label %20
i32 72, label %20
i32 86, label %22
i32 118, label %22
i32 49, label %24
i32 50, label %31
i32 51, label %38
i32 52, label %45
i32 55, label %52
i32 56, label %54
i32 255, label %56
]
20: ; preds = %18, %18
%21 = tail call i32 (...) @show_help()
br label %62
22: ; preds = %18, %18
%23 = tail call i32 (...) @version()
br label %62
24: ; preds = %18
%25 = inttoptr i64 %19 to i32*
%26 = load volatile i32, i32* %25
%27 = sext i32 %26 to i64
%28 = tail call i8* @xtoa(i64 %27)
%29 = tail call i32 @puts(i8* dereferenceable(1) %28)
%30 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
br label %62
31: ; preds = %18
%32 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0))
%33 = tail call i64 (...) @getnum()
%34 = tail call i8* @xtoa(i64 %33)
%35 = tail call i32 @puts(i8* dereferenceable(1) %34)
%36 = trunc i64 %33 to i32
%37 = inttoptr i64 %19 to i32*
store volatile i32 %36, i32* %37
br label %62
38: ; preds = %18
%39 = inttoptr i64 %19 to i8*
%40 = load i8, i8* %39
%41 = zext i8 %40 to i64
%42 = tail call i8* @xtoa(i64 %41)
%43 = tail call i32 @puts(i8* dereferenceable(1) %42)
%44 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
br label %62
45: ; preds = %18
%46 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0))
%47 = tail call i64 (...) @getnum()
%48 = tail call i8* @xtoa(i64 %47)
%49 = tail call i32 @puts(i8* dereferenceable(1) %48)
%50 = trunc i64 %47 to i8
%51 = inttoptr i64 %19 to i8*
store i8 %50, i8* %51
br label %62
52: ; preds = %18
%53 = tail call i32 (...) @ProgramExec()
br label %62
54: ; preds = %18
%55 = tail call i32 (...) @isStillAlive()
br label %62
56: ; preds = %18
%57 = tail call i32 (...) @ReceiveProgram()
br label %62
58: ; preds = %18
%59 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.6, i64 0, i64 0))
%60 = tail call i32 @print_hex(i32 %7)
%61 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0))
br label %62
62: ; preds = %58, %56, %54, %52, %45, %38, %31, %24, %22, %20
br label %5
}