#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*/ _core_status();
int /*<<< orphan*/ _jump_to_program(unsigned int);
int /*<<< orphan*/ _testpass();
int /*<<< orphan*/ elfsplitter(int, int);
int /*<<< orphan*/ print_help();
int /*<<< orphan*/ print_spaces(int);
int /*<<< orphan*/ printf(char *, ...);
int xmodemReceive(char *, int);
void load_run(int type, unsigned int address) {
  int file_size;
  char *message =
      "Send file w/ 1K Xmodem protocol from terminal emulator now...";
  switch (type) {
  case 1:
    printf("%s\n", message);
    file_size = xmodemReceive((char *)0x01000000, 0x00800000);
    if (file_size < 0 || file_size > 0x00800000) {
      printf("Xmodem error file size 0x%x \n", file_size);
      return;
    }
    printf("\nelf split\n");
    elfsplitter(0x01000000, file_size);
    break;
  case 2:
    print_help();
    _core_status();
    print_spaces(16);
    _testpass();
    break;
  case 3:
    printf("j 0x%08x\n", 0x00080000);
    print_spaces(16);
    printf("\n");
    _jump_to_program(0x00080000);
    _testpass();
    break;
  case 4:
    printf("j 0x%08x\n", 0x00008000);
    print_spaces(16);
    printf("\n");
    _jump_to_program(0x00008000);
    _testpass();
    break;
  case 5:
    printf("%s\n", message);
    file_size = xmodemReceive((char *)address, 0x00800000);
    if (file_size < 0 || file_size > 0x00800000) {
      printf("Xmodem error file size 0x%x \n", file_size);
      return;
    }
    break;
  default:
    printf("j 0x%08x\n", address);
    print_spaces(16);
    printf("\n");
    _jump_to_program(address);
    _testpass();
    break;
  }
}


x86 assembly (clang, -O0):
<load_run>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
lea    0xe7f(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    -0x4(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,%ecx
mov    %rcx,-0x20(%rbp)
sub    $0x4,%eax
ja     132f <load_run+0x1af>
mov    -0x20(%rbp),%rax
lea    0xe47(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x18(%rbp),%rsi
lea    0xe85(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    $0x1000000,%edi
mov    $0x800000,%esi
call   1050 <xmodemReceive@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jl     11fd <load_run+0x7d>
cmpl   $0x800000,-0xc(%rbp)
jle    1213 <load_run+0x93>
mov    -0xc(%rbp),%esi
lea    0xe4f(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
jmp    1367 <load_run+0x1e7>
lea    0xe5a(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0xc(%rbp),%esi
mov    $0x1000000,%edi
call   10a0 <elfsplitter@plt>
jmp    1367 <load_run+0x1e7>
mov    $0x0,%al
call   1080 <print_help@plt>
mov    $0x0,%al
call   1040 <_core_status@plt>
mov    $0x10,%edi
call   1030 <print_spaces@plt>
mov    $0x0,%al
call   1090 <_testpass@plt>
jmp    1367 <load_run+0x1e7>
lea    0xe22(%rip),%rdi
mov    $0x80000,%esi
mov    $0x0,%al
call   1070 <printf@plt>
mov    $0x10,%edi
call   1030 <print_spaces@plt>
lea    0xdf7(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    $0x80000,%edi
call   1060 <_jump_to_program@plt>
mov    $0x0,%al
call   1090 <_testpass@plt>
jmp    1367 <load_run+0x1e7>
lea    0xde1(%rip),%rdi
mov    $0x8000,%esi
mov    $0x0,%al
call   1070 <printf@plt>
mov    $0x10,%edi
call   1030 <print_spaces@plt>
lea    0xdb6(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    $0x8000,%edi
call   1060 <_jump_to_program@plt>
mov    $0x0,%al
call   1090 <_testpass@plt>
jmp    1367 <load_run+0x1e7>
mov    -0x18(%rbp),%rsi
lea    0xd6e(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x8(%rbp),%eax
mov    %eax,%edi
mov    $0x800000,%esi
call   1050 <xmodemReceive@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jl     1314 <load_run+0x194>
cmpl   $0x800000,-0xc(%rbp)
jle    132a <load_run+0x1aa>
mov    -0xc(%rbp),%esi
lea    0xd38(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
jmp    1367 <load_run+0x1e7>
jmp    1367 <load_run+0x1e7>
mov    -0x8(%rbp),%esi
lea    0xd47(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    $0x10,%edi
call   1030 <print_spaces@plt>
lea    0xd21(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x8(%rbp),%edi
call   1060 <_jump_to_program@plt>
mov    $0x0,%al
call   1090 <_testpass@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<load_run>:
push   %rbx
mov    %esi,%ebx
add    $0xffffffff,%edi
cmp    $0x4,%edi
ja     1284 <load_run+0xe4>
lea    0xe4a(%rip),%rax
movslq (%rax,%rdi,4),%rcx
add    %rax,%rcx
jmp    *%rcx
lea    0xe4e(%rip),%rdi
call   1060 <puts@plt>
mov    $0x1000000,%edi
mov    $0x800000,%esi
call   1070 <xmodemReceive@plt>
mov    %eax,%ebx
cmp    $0x800001,%eax
jb     12d1 <load_run+0x131>
lea    0xe64(%rip),%rdi
mov    %ebx,%esi
jmp    127c <load_run+0xdc>
lea    0xe74(%rip),%rdi
mov    $0x80000,%esi
xor    %eax,%eax
call   1090 <printf@plt>
mov    $0x10,%edi
call   1040 <print_spaces@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    $0x80000,%edi
jmp    12aa <load_run+0x10a>
lea    0xe43(%rip),%rdi
mov    $0x8000,%esi
xor    %eax,%eax
call   1090 <printf@plt>
mov    $0x10,%edi
call   1040 <print_spaces@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    $0x8000,%edi
jmp    12aa <load_run+0x10a>
lea    0xdb9(%rip),%rdi
call   1060 <puts@plt>
mov    %ebx,%edi
mov    $0x800000,%esi
call   1070 <xmodemReceive@plt>
cmp    $0x800001,%eax
jb     12ea <load_run+0x14a>
lea    0xdd8(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
pop    %rbx
jmp    1090 <printf@plt>
lea    0xde5(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1090 <printf@plt>
mov    $0x10,%edi
call   1040 <print_spaces@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %ebx,%edi
call   1080 <_jump_to_program@plt>
jmp    12c9 <load_run+0x129>
xor    %eax,%eax
call   10a0 <print_help@plt>
xor    %eax,%eax
call   1050 <_core_status@plt>
mov    $0x10,%edi
call   1040 <print_spaces@plt>
xor    %eax,%eax
pop    %rbx
jmp    10b0 <_testpass@plt>
lea    0xda2(%rip),%rdi
call   1060 <puts@plt>
mov    $0x1000000,%edi
mov    %ebx,%esi
pop    %rbx
jmp    10c0 <elfsplitter@plt>
pop    %rbx
ret

LLVM IR (-O0):
@.str = [62 x i8] c"Send file w/ 1K Xmodem protocol from terminal emulator now...\00"
@.str.1 = [4 x i8] c"%s\0A\00"
@.str.2 = [30 x i8] c"Xmodem error file size 0x%x \0A\00"
@.str.3 = [12 x i8] c"\0Aelf split\0A\00"
@.str.4 = [10 x i8] c"j 0x%08x\0A\00"
@.str.5 = [2 x i8] c"\0A\00"
define void @load_run(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
store i32 %0, i32* %3
store i32 %1, i32* %4
store i8* getelementptr inbounds ([62 x i8], [62 x i8]* @.str, i64 0, i64 0), i8** %6
%7 = load i32, i32* %3
switch i32 %7, label %57 [
i32 1, label %8
i32 2, label %24
i32 3, label %29
i32 4, label %35
i32 5, label %41
]
8: ; preds = %2
%9 = load i8*, i8** %6
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %9)
%11 = call i32 @xmodemReceive(i8* inttoptr (i64 16777216 to i8*), i32 8388608)
store i32 %11, i32* %5
%12 = load i32, i32* %5
%13 = icmp slt i32 %12, 0
br i1 %13, label %17, label %14
14: ; preds = %8
%15 = load i32, i32* %5
%16 = icmp sgt i32 %15, 8388608
br i1 %16, label %17, label %20
17: ; preds = %14, %8
%18 = load i32, i32* %5
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i32 %18)
br label %65
20: ; preds = %14
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0))
%22 = load i32, i32* %5
%23 = call i32 @elfsplitter(i32 16777216, i32 %22)
br label %65
24: ; preds = %2
%25 = call i32 (...) @print_help()
%26 = call i32 (...) @_core_status()
%27 = call i32 @print_spaces(i32 16)
%28 = call i32 (...) @_testpass()
br label %65
29: ; preds = %2
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i32 524288)
%31 = call i32 @print_spaces(i32 16)
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%33 = call i32 @_jump_to_program(i32 524288)
%34 = call i32 (...) @_testpass()
br label %65
35: ; preds = %2
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i32 32768)
%37 = call i32 @print_spaces(i32 16)
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%39 = call i32 @_jump_to_program(i32 32768)
%40 = call i32 (...) @_testpass()
br label %65
41: ; preds = %2
%42 = load i8*, i8** %6
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %42)
%44 = load i32, i32* %4
%45 = zext i32 %44 to i64
%46 = inttoptr i64 %45 to i8*
%47 = call i32 @xmodemReceive(i8* %46, i32 8388608)
store i32 %47, i32* %5
%48 = load i32, i32* %5
%49 = icmp slt i32 %48, 0
br i1 %49, label %53, label %50
50: ; preds = %41
%51 = load i32, i32* %5
%52 = icmp sgt i32 %51, 8388608
br i1 %52, label %53, label %56
53: ; preds = %50, %41
%54 = load i32, i32* %5
%55 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i32 %54)
br label %65
56: ; preds = %50
br label %65
57: ; preds = %2
%58 = load i32, i32* %4
%59 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i32 %58)
%60 = call i32 @print_spaces(i32 16)
%61 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%62 = load i32, i32* %4
%63 = call i32 @_jump_to_program(i32 %62)
%64 = call i32 (...) @_testpass()
br label %65
65: ; preds = %17, %53, %57, %56, %35, %29, %24, %20
ret void
}

LLVM IR (-O2):
@.str = [62 x i8] c"Send file w/ 1K Xmodem protocol from terminal emulator now...\00"
@.str.2 = [30 x i8] c"Xmodem error file size 0x%x \0A\00"
@.str.4 = [10 x i8] c"j 0x%08x\0A\00"
@str = [11 x i8] c"\0Aelf split\00"
define void @load_run(i32 %0, i32 %1) {
switch i32 %0, label %37 [
i32 1, label %3
i32 2, label %12
i32 3, label %17
i32 4, label %23
i32 5, label %29
]
3: ; preds = %2
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([62 x i8], [62 x i8]* @.str, i64 0, i64 0))
%5 = tail call i32 @xmodemReceive(i8* inttoptr (i64 16777216 to i8*), i32 8388608)
%6 = icmp ugt i32 %5, 8388608
br i1 %6, label %7, label %9
7: ; preds = %3
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i32 %5)
br label %43
9: ; preds = %3
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @str, i64 0, i64 0))
%11 = tail call i32 @elfsplitter(i32 16777216, i32 %5)
br label %43
12: ; preds = %2
%13 = tail call i32 (...) @print_help()
%14 = tail call i32 (...) @_core_status()
%15 = tail call i32 @print_spaces(i32 16)
%16 = tail call i32 (...) @_testpass()
br label %43
17: ; preds = %2
%18 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i32 524288)
%19 = tail call i32 @print_spaces(i32 16)
%20 = tail call i32 @putchar(i32 10)
%21 = tail call i32 @_jump_to_program(i32 524288)
%22 = tail call i32 (...) @_testpass()
br label %43
23: ; preds = %2
%24 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i32 32768)
%25 = tail call i32 @print_spaces(i32 16)
%26 = tail call i32 @putchar(i32 10)
%27 = tail call i32 @_jump_to_program(i32 32768)
%28 = tail call i32 (...) @_testpass()
br label %43
29: ; preds = %2
%30 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([62 x i8], [62 x i8]* @.str, i64 0, i64 0))
%31 = zext i32 %1 to i64
%32 = inttoptr i64 %31 to i8*
%33 = tail call i32 @xmodemReceive(i8* %32, i32 8388608)
%34 = icmp ugt i32 %33, 8388608
br i1 %34, label %35, label %43
35: ; preds = %29
%36 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i32 %33)
br label %43
37: ; preds = %2
%38 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i32 %1)
%39 = tail call i32 @print_spaces(i32 16)
%40 = tail call i32 @putchar(i32 10)
%41 = tail call i32 @_jump_to_program(i32 %1)
%42 = tail call i32 (...) @_testpass()
br label %43
43: ; preds = %9, %12, %17, %23, %37, %29, %35, %7
ret void
}