#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 */
scalar_t__ malloc(int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int rrd(char *, char *);
int /*<<< orphan*/ wrt(char *, char *, int);
int main(int argc, char *argv[]) {
  char *buf = (char *)malloc(16384 * 1024);
  ;
  memset(buf, 0, 16384 * 1024);
  rrd("cmdline", buf);
  rrd("bootstub", buf + 0x1000);
  int klen = rrd("bzImage", buf + 0x1000 + 8192);
  int rlen = rrd("initrd.cpio.gz", buf + 0x1000 + 8192 + klen);
  *(int *)(buf + 0x400) = klen;
  *(int *)(buf + 0x404) = rlen;
  buf[0x40c] = 0xff;
  buf[0x410] = 0xbd;
  buf[0x411] = 0x02;
  buf[0x412] = 0xbd;
  buf[0x413] = 0x02;
  buf[0x414] = 0xbd;
  buf[0x415] = 0x12;
  buf[0x416] = 0xbd;
  buf[0x417] = 0x12;
  wrt("unsigned.bin", buf, 0x1000 + 8192 + klen + rlen);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x1000000,%edi
call   1040 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
xor    %esi,%esi
mov    $0x1000000,%edx
call   1030 <memset@plt>
mov    -0x18(%rbp),%rsi
lea    0xe81(%rip),%rdi
call   1050 <rrd@plt>
mov    -0x18(%rbp),%rsi
add    $0x1000,%rsi
lea    0xe72(%rip),%rdi
call   1050 <rrd@plt>
mov    -0x18(%rbp),%rsi
add    $0x1000,%rsi
add    $0x2000,%rsi
lea    0xe5d(%rip),%rdi
call   1050 <rrd@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rsi
add    $0x1000,%rsi
add    $0x2000,%rsi
movslq -0x1c(%rbp),%rax
add    %rax,%rsi
lea    0xe3d(%rip),%rdi
call   1050 <rrd@plt>
mov    %eax,-0x20(%rbp)
mov    -0x1c(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,0x400(%rax)
mov    -0x20(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,0x404(%rax)
mov    -0x18(%rbp),%rax
movb   $0xff,0x40c(%rax)
mov    -0x18(%rbp),%rax
movb   $0xbd,0x410(%rax)
mov    -0x18(%rbp),%rax
movb   $0x2,0x411(%rax)
mov    -0x18(%rbp),%rax
movb   $0xbd,0x412(%rax)
mov    -0x18(%rbp),%rax
movb   $0x2,0x413(%rax)
mov    -0x18(%rbp),%rax
movb   $0xbd,0x414(%rax)
mov    -0x18(%rbp),%rax
movb   $0x12,0x415(%rax)
mov    -0x18(%rbp),%rax
movb   $0xbd,0x416(%rax)
mov    -0x18(%rbp),%rax
movb   $0x12,0x417(%rax)
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
add    $0x3000,%edx
add    -0x20(%rbp),%edx
lea    0xdb0(%rip),%rdi
call   1060 <wrt@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    $0x1000000,%edi
call   1040 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
xor    %esi,%esi
mov    $0x1000000,%edx
call   1030 <memset@plt>
lea    0xe99(%rip),%rdi
mov    %rbx,%rsi
call   1050 <rrd@plt>
lea    0x1000(%rbx),%rsi
lea    0xe8b(%rip),%rdi
call   1050 <rrd@plt>
lea    0x3000(%rbx),%rsi
lea    0xe81(%rip),%rdi
call   1050 <rrd@plt>
movslq %eax,%r14
lea    (%rbx,%r14,1),%rsi
add    $0x3000,%rsi
lea    0xe6f(%rip),%rdi
call   1050 <rrd@plt>
mov    %r14d,0x400(%rbx)
mov    %eax,0x404(%rbx)
movb   $0xff,0x40c(%rbx)
movabs $0x12bd12bd02bd02bd,%rcx
12 bd 12
mov    %rcx,0x410(%rbx)
lea    (%r14,%rax,1),%edx
add    $0x3000,%edx
lea    0xe43(%rip),%rdi
mov    %rbx,%rsi
call   1060 <wrt@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [8 x i8] c"cmdline\00"
@.str.1 = [9 x i8] c"bootstub\00"
@.str.2 = [8 x i8] c"bzImage\00"
@.str.3 = [15 x i8] c"initrd.cpio.gz\00"
@.str.4 = [13 x i8] c"unsigned.bin\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = call i64 @malloc(i32 16777216)
%10 = inttoptr i64 %9 to i8*
store i8* %10, i8** %6
%11 = load i8*, i8** %6
%12 = call i32 @memset(i8* %11, i32 0, i32 16777216)
%13 = load i8*, i8** %6
%14 = call i32 @rrd(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* %13)
%15 = load i8*, i8** %6
%16 = getelementptr inbounds i8, i8* %15, i64 4096
%17 = call i32 @rrd(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* %16)
%18 = load i8*, i8** %6
%19 = getelementptr inbounds i8, i8* %18, i64 4096
%20 = getelementptr inbounds i8, i8* %19, i64 8192
%21 = call i32 @rrd(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* %20)
store i32 %21, i32* %7
%22 = load i8*, i8** %6
%23 = getelementptr inbounds i8, i8* %22, i64 4096
%24 = getelementptr inbounds i8, i8* %23, i64 8192
%25 = load i32, i32* %7
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i8, i8* %24, i64 %26
%28 = call i32 @rrd(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i8* %27)
store i32 %28, i32* %8
%29 = load i32, i32* %7
%30 = load i8*, i8** %6
%31 = getelementptr inbounds i8, i8* %30, i64 1024
%32 = bitcast i8* %31 to i32*
store i32 %29, i32* %32
%33 = load i32, i32* %8
%34 = load i8*, i8** %6
%35 = getelementptr inbounds i8, i8* %34, i64 1028
%36 = bitcast i8* %35 to i32*
store i32 %33, i32* %36
%37 = load i8*, i8** %6
%38 = getelementptr inbounds i8, i8* %37, i64 1036
store i8 -1, i8* %38
%39 = load i8*, i8** %6
%40 = getelementptr inbounds i8, i8* %39, i64 1040
store i8 -67, i8* %40
%41 = load i8*, i8** %6
%42 = getelementptr inbounds i8, i8* %41, i64 1041
store i8 2, i8* %42
%43 = load i8*, i8** %6
%44 = getelementptr inbounds i8, i8* %43, i64 1042
store i8 -67, i8* %44
%45 = load i8*, i8** %6
%46 = getelementptr inbounds i8, i8* %45, i64 1043
store i8 2, i8* %46
%47 = load i8*, i8** %6
%48 = getelementptr inbounds i8, i8* %47, i64 1044
store i8 -67, i8* %48
%49 = load i8*, i8** %6
%50 = getelementptr inbounds i8, i8* %49, i64 1045
store i8 18, i8* %50
%51 = load i8*, i8** %6
%52 = getelementptr inbounds i8, i8* %51, i64 1046
store i8 -67, i8* %52
%53 = load i8*, i8** %6
%54 = getelementptr inbounds i8, i8* %53, i64 1047
store i8 18, i8* %54
%55 = load i8*, i8** %6
%56 = load i32, i32* %7
%57 = add nsw i32 12288, %56
%58 = load i32, i32* %8
%59 = add nsw i32 %57, %58
%60 = call i32 @wrt(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0), i8* %55, i32 %59)
ret i32 0
}

LLVM IR (-O2):
@.str = [8 x i8] c"cmdline\00"
@.str.1 = [9 x i8] c"bootstub\00"
@.str.2 = [8 x i8] c"bzImage\00"
@.str.3 = [15 x i8] c"initrd.cpio.gz\00"
@.str.4 = [13 x i8] c"unsigned.bin\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i64 @malloc(i32 16777216)
%4 = inttoptr i64 %3 to i8*
%5 = tail call i32 @memset(i8* %4, i32 0, i32 16777216)
%6 = tail call i32 @rrd(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* %4)
%7 = getelementptr inbounds i8, i8* %4, i64 4096
%8 = tail call i32 @rrd(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* %7)
%9 = getelementptr inbounds i8, i8* %4, i64 12288
%10 = tail call i32 @rrd(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* %9)
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds i8, i8* %9, i64 %11
%13 = tail call i32 @rrd(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i8* %12)
%14 = getelementptr inbounds i8, i8* %4, i64 1024
%15 = bitcast i8* %14 to i32*
store i32 %10, i32* %15
%16 = getelementptr inbounds i8, i8* %4, i64 1028
%17 = bitcast i8* %16 to i32*
store i32 %13, i32* %17
%18 = getelementptr inbounds i8, i8* %4, i64 1036
store i8 -1, i8* %18
%19 = getelementptr inbounds i8, i8* %4, i64 1040
store i8 -67, i8* %19
%20 = getelementptr inbounds i8, i8* %4, i64 1041
store i8 2, i8* %20
%21 = getelementptr inbounds i8, i8* %4, i64 1042
store i8 -67, i8* %21
%22 = getelementptr inbounds i8, i8* %4, i64 1043
store i8 2, i8* %22
%23 = getelementptr inbounds i8, i8* %4, i64 1044
store i8 -67, i8* %23
%24 = getelementptr inbounds i8, i8* %4, i64 1045
store i8 18, i8* %24
%25 = getelementptr inbounds i8, i8* %4, i64 1046
store i8 -67, i8* %25
%26 = getelementptr inbounds i8, i8* %4, i64 1047
store i8 18, i8* %26
%27 = add nsw i32 %10, 12288
%28 = add nsw i32 %27, %13
%29 = tail call i32 @wrt(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0), i8* %4, i32 %28)
ret i32 0
}