#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*/ nand_read(int, unsigned char *, int);
int /*<<< orphan*/ puthex(unsigned int volatile);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ setup_commandline_tag(char *);
int /*<<< orphan*/ setup_end_tag();
int /*<<< orphan*/ setup_memory_tags();
int /*<<< orphan*/ setup_start_tag();
int /*<<< orphan*/ uart0_init();
int main(void) {
  void (*theKernel)(int zero, int arch, unsigned int params);
  volatile unsigned int *p = (volatile unsigned int *)0x30008000;
  uart0_init();
  puts("Copy kernel from nand\n\r");
  nand_read(0x00200000, (unsigned char *)0x30008000, 0x300000);
  puthex(0x1234ABCD);
  puts("\n\r");
  puthex(*p);
  puts("\n\r");
  puts("Set boot params\n\r");
  setup_start_tag();
  setup_memory_tags();
  setup_commandline_tag(
      "noinitrd root=/dev/mtdblock2 init=/linuxrc console=ttySAC0");
  setup_end_tag();
  puts("Boot kernel\n\r");
  theKernel = (void (*)(int, int, unsigned int))0x30008000;
  theKernel(0, 168, 0x30000100);
  puts("Error!\n\r");
  return -1;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x30008000,%eax
mov    %rax,-0x18(%rbp)
mov    $0x0,%al
call   1030 <uart0_init@plt>
lea    0xe5a(%rip),%rdi
call   1040 <puts@plt>
mov    $0x200000,%edi
mov    $0x30008000,%esi
mov    $0x300000,%edx
call   1090 <nand_read@plt>
mov    $0x1234abcd,%edi
call   1070 <puthex@plt>
lea    0xea9(%rip),%rdi
call   1040 <puts@plt>
mov    -0x18(%rbp),%rax
mov    (%rax),%edi
call   1070 <puthex@plt>
lea    0xe92(%rip),%rdi
call   1040 <puts@plt>
lea    0xe25(%rip),%rdi
call   1040 <puts@plt>
mov    $0x0,%al
call   1080 <setup_start_tag@plt>
mov    $0x0,%al
call   1050 <setup_memory_tags@plt>
lea    0xe1d(%rip),%rdi
call   10a0 <setup_commandline_tag@plt>
mov    $0x0,%al
call   1060 <setup_end_tag@plt>
lea    0xe45(%rip),%rdi
call   1040 <puts@plt>
mov    $0x30008000,%eax
mov    %rax,-0x10(%rbp)
xor    %edi,%edi
mov    $0xa8,%esi
mov    $0x30000100,%edx
call   *-0x10(%rbp)
lea    0xe2f(%rip),%rdi
call   1040 <puts@plt>
mov    $0xffffffff,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
xor    %eax,%eax
call   1030 <uart0_init@plt>
lea    0xe6e(%rip),%rdi
call   1040 <puts@plt>
mov    $0x30008000,%r14d
mov    $0x30008000,%esi
mov    $0x200000,%edi
mov    $0x300000,%edx
call   1090 <nand_read@plt>
mov    $0x1234abcd,%edi
call   1070 <puthex@plt>
lea    0xeb7(%rip),%rbx
mov    %rbx,%rdi
call   1040 <puts@plt>
mov    0x30008000,%edi
call   1070 <puthex@plt>
mov    %rbx,%rdi
call   1040 <puts@plt>
lea    0xe33(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
call   1080 <setup_start_tag@plt>
xor    %eax,%eax
call   1050 <setup_memory_tags@plt>
lea    0xe2b(%rip),%rdi
call   10a0 <setup_commandline_tag@plt>
xor    %eax,%eax
call   1060 <setup_end_tag@plt>
lea    0xe53(%rip),%rdi
call   1040 <puts@plt>
xor    %edi,%edi
mov    $0xa8,%esi
mov    $0x30000100,%edx
call   *%r14
lea    0xe46(%rip),%rdi
call   1040 <puts@plt>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [24 x i8] c"Copy kernel from nand\0A\0D\00"
@.str.1 = [3 x i8] c"\0A\0D\00"
@.str.2 = [18 x i8] c"Set boot params\0A\0D\00"
@.str.3 = [59 x i8] c"noinitrd root=/dev/mtdblock2 init=/linuxrc console=ttySAC0\00"
@.str.4 = [14 x i8] c"Boot kernel\0A\0D\00"
@.str.5 = [9 x i8] c"Error!\0A\0D\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca void (i32, i32, i32)*
%3 = alloca i32*
store i32 0, i32* %1
store i32* inttoptr (i64 805339136 to i32*), i32** %3
%4 = call i32 (...) @uart0_init()
%5 = call i32 @puts(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
%6 = call i32 @nand_read(i32 2097152, i8* inttoptr (i64 805339136 to i8*), i32 3145728)
%7 = call i32 @puthex(i32 305441741)
%8 = call i32 @puts(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%9 = load i32*, i32** %3
%10 = load volatile i32, i32* %9
%11 = call i32 @puthex(i32 %10)
%12 = call i32 @puts(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%13 = call i32 @puts(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0))
%14 = call i32 (...) @setup_start_tag()
%15 = call i32 (...) @setup_memory_tags()
%16 = call i32 @setup_commandline_tag(i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str.3, i64 0, i64 0))
%17 = call i32 (...) @setup_end_tag()
%18 = call i32 @puts(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0))
store void (i32, i32, i32)* inttoptr (i64 805339136 to void (i32, i32, i32)*), void (i32, i32, i32)** %2
%19 = load void (i32, i32, i32)*, void (i32, i32, i32)** %2
%20 = call i32 @puts(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0))
ret i32 -1
}

LLVM IR (-O2):
@.str = [24 x i8] c"Copy kernel from nand\0A\0D\00"
@.str.1 = [3 x i8] c"\0A\0D\00"
@.str.2 = [18 x i8] c"Set boot params\0A\0D\00"
@.str.3 = [59 x i8] c"noinitrd root=/dev/mtdblock2 init=/linuxrc console=ttySAC0\00"
@.str.4 = [14 x i8] c"Boot kernel\0A\0D\00"
@.str.5 = [9 x i8] c"Error!\0A\0D\00"
define i32 @main() {
%1 = tail call i32 (...) @uart0_init()
%2 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
%3 = tail call i32 @nand_read(i32 2097152, i8* inttoptr (i64 805339136 to i8*), i32 3145728)
%4 = tail call i32 @puthex(i32 305441741)
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%6 = load volatile i32, i32* inttoptr (i64 805339136 to i32*)
%7 = tail call i32 @puthex(i32 %6)
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0))
%10 = tail call i32 (...) @setup_start_tag()
%11 = tail call i32 (...) @setup_memory_tags()
%12 = tail call i32 @setup_commandline_tag(i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str.3, i64 0, i64 0))
%13 = tail call i32 (...) @setup_end_tag()
%14 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0))
tail call void inttoptr (i64 805339136 to void (i32, i32, i32)*)(i32 0, i32 168, i32 805306624)
%15 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0))
ret i32 -1
}