#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 O_CREAT;
int /*<<< orphan*/ O_RDONLY;
int O_TRUNC;
int O_WRONLY;
int /*<<< orphan*/ close(int);
int open(char *, int, ...);
int /*<<< orphan*/ read(int, char *, int);
int /*<<< orphan*/ write(int, char *, int);
int main(int argc, char *argv[]) {
  char buf[0x200000];
  int fd = open("wma11b.rom", O_RDONLY);
  read(fd, buf, 0x200000);
  close(fd);
  int out = open("boot.rom", O_CREAT | O_WRONLY | O_TRUNC, 0666);
  write(out, buf, 0xE000);
  close(out);
  out = open("settings.rom", O_CREAT | O_WRONLY | O_TRUNC, 0666);
  write(out, buf + 0xE000, 0x1000);
  close(out);
  out = open("kernel.rom", O_CREAT | O_WRONLY | O_TRUNC, 0666);
  write(out, buf + 0x10000, 0x200000 - 0x10000);
  close(out);
  out = open("kernelloader.rom", O_CREAT | O_WRONLY | O_TRUNC, 0666);
  write(out, buf + 0x10000, 0x2990);
  close(out);
  out = open("kernel.gz", O_CREAT | O_WRONLY | O_TRUNC, 0666);
  write(out, buf + 0x10000 + 0x2990, 0x9c000 - 0x10000 - 0x2990);
  close(out);
  out = open("ramdisc.gz", O_CREAT | O_WRONLY | O_TRUNC, 0666);
  write(out, buf + 0x9C000 + 0x14, 0x200000 - 0x9C014);
  close(out);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x200020,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e7f(%rip),%rax
mov    (%rax),%esi
lea    0xe9e(%rip),%rdi
mov    $0x0,%al
call   1060 <open@plt>
mov    %eax,-0x200014(%rbp)
mov    -0x200014(%rbp),%edi
lea    -0x200010(%rbp),%rsi
mov    $0x200000,%edx
call   1050 <read@plt>
mov    -0x200014(%rbp),%edi
call   1040 <close@plt>
mov    0x2e60(%rip),%rax
mov    (%rax),%esi
mov    0x2e1f(%rip),%rax
or     (%rax),%esi
mov    0x2e46(%rip),%rax
or     (%rax),%esi
lea    0xe58(%rip),%rdi
mov    $0x1b6,%edx
mov    $0x0,%al
call   1060 <open@plt>
mov    %eax,-0x200018(%rbp)
mov    -0x200018(%rbp),%edi
lea    -0x200010(%rbp),%rsi
mov    $0xe000,%edx
call   1030 <write@plt>
mov    -0x200018(%rbp),%edi
call   1040 <close@plt>
mov    0x2e0a(%rip),%rax
mov    (%rax),%esi
mov    0x2dc9(%rip),%rax
or     (%rax),%esi
mov    0x2df0(%rip),%rax
or     (%rax),%esi
lea    0xe0b(%rip),%rdi
mov    $0x1b6,%edx
mov    $0x0,%al
call   1060 <open@plt>
mov    %eax,-0x200018(%rbp)
mov    -0x200018(%rbp),%edi
lea    -0x200010(%rbp),%rsi
add    $0xe000,%rsi
mov    $0x1000,%edx
call   1030 <write@plt>
mov    -0x200018(%rbp),%edi
call   1040 <close@plt>
mov    0x2dad(%rip),%rax
mov    (%rax),%esi
mov    0x2d6c(%rip),%rax
or     (%rax),%esi
mov    0x2d93(%rip),%rax
or     (%rax),%esi
lea    0xdbb(%rip),%rdi
mov    $0x1b6,%edx
mov    $0x0,%al
call   1060 <open@plt>
mov    %eax,-0x200018(%rbp)
mov    -0x200018(%rbp),%edi
lea    -0x200010(%rbp),%rsi
add    $0x10000,%rsi
mov    $0x1f0000,%edx
call   1030 <write@plt>
mov    -0x200018(%rbp),%edi
call   1040 <close@plt>
mov    0x2d50(%rip),%rax
mov    (%rax),%esi
mov    0x2d0f(%rip),%rax
or     (%rax),%esi
mov    0x2d36(%rip),%rax
or     (%rax),%esi
lea    0xd69(%rip),%rdi
mov    $0x1b6,%edx
mov    $0x0,%al
call   1060 <open@plt>
mov    %eax,-0x200018(%rbp)
mov    -0x200018(%rbp),%edi
lea    -0x200010(%rbp),%rsi
add    $0x10000,%rsi
mov    $0x2990,%edx
call   1030 <write@plt>
mov    -0x200018(%rbp),%edi
call   1040 <close@plt>
mov    0x2cf3(%rip),%rax
mov    (%rax),%esi
mov    0x2cb2(%rip),%rax
or     (%rax),%esi
mov    0x2cd9(%rip),%rax
or     (%rax),%esi
lea    0xd1d(%rip),%rdi
mov    $0x1b6,%edx
mov    $0x0,%al
call   1060 <open@plt>
mov    %eax,-0x200018(%rbp)
mov    -0x200018(%rbp),%edi
lea    -0x200010(%rbp),%rsi
add    $0x10000,%rsi
add    $0x2990,%rsi
mov    $0x89670,%edx
call   1030 <write@plt>
mov    -0x200018(%rbp),%edi
call   1040 <close@plt>
mov    0x2c8f(%rip),%rax
mov    (%rax),%esi
mov    0x2c4e(%rip),%rax
or     (%rax),%esi
mov    0x2c75(%rip),%rax
or     (%rax),%esi
lea    0xcc3(%rip),%rdi
mov    $0x1b6,%edx
mov    $0x0,%al
call   1060 <open@plt>
mov    %eax,-0x200018(%rbp)
mov    -0x200018(%rbp),%edi
lea    -0x200010(%rbp),%rsi
add    $0x9c000,%rsi
add    $0x14,%rsi
mov    $0x163fec,%edx
call   1030 <write@plt>
mov    -0x200018(%rbp),%edi
call   1040 <close@plt>
xor    %eax,%eax
add    $0x200020,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x200000,%rsp
mov    0x2e82(%rip),%rax
mov    (%rax),%esi
lea    0xea1(%rip),%rdi
xor    %eax,%eax
call   1060 <open@plt>
mov    %eax,%ebp
mov    %rsp,%rbx
mov    %eax,%edi
mov    %rbx,%rsi
mov    $0x200000,%edx
call   1050 <read@plt>
mov    %ebp,%edi
call   1040 <close@plt>
mov    0x2e70(%rip),%r14
mov    0x2e31(%rip),%r15
mov    (%r15),%esi
or     (%r14),%esi
mov    0x2e54(%rip),%r12
or     (%r12),%esi
lea    0xe64(%rip),%rdi
mov    $0x1b6,%edx
xor    %eax,%eax
call   1060 <open@plt>
mov    %eax,%ebp
mov    %eax,%edi
mov    %rbx,%rsi
mov    $0xe000,%edx
call   1030 <write@plt>
mov    %ebp,%edi
call   1040 <close@plt>
mov    (%r15),%esi
or     (%r14),%esi
or     (%r12),%esi
lea    0xe38(%rip),%rdi
mov    $0x1b6,%edx
xor    %eax,%eax
call   1060 <open@plt>
mov    %eax,%ebx
lea    0xe000(%rsp),%rsi
mov    %eax,%edi
mov    $0x1000,%edx
call   1030 <write@plt>
mov    %ebx,%edi
call   1040 <close@plt>
mov    (%r15),%esi
or     (%r14),%esi
or     (%r12),%esi
lea    0xe0b(%rip),%rdi
mov    $0x1b6,%edx
xor    %eax,%eax
call   1060 <open@plt>
mov    %eax,%ebx
lea    0x10000(%rsp),%rbp
mov    %eax,%edi
mov    %rbp,%rsi
mov    $0x1f0000,%edx
call   1030 <write@plt>
mov    %ebx,%edi
call   1040 <close@plt>
mov    (%r15),%esi
or     (%r14),%esi
or     (%r12),%esi
lea    0xdd9(%rip),%rdi
mov    $0x1b6,%edx
xor    %eax,%eax
call   1060 <open@plt>
mov    %eax,%ebx
mov    %eax,%edi
mov    %rbp,%rsi
mov    $0x2990,%edx
call   1030 <write@plt>
mov    %ebx,%edi
call   1040 <close@plt>
mov    (%r15),%esi
or     (%r14),%esi
or     (%r12),%esi
lea    0xdb5(%rip),%rdi
mov    $0x1b6,%edx
xor    %eax,%eax
call   1060 <open@plt>
mov    %eax,%ebx
lea    0x12990(%rsp),%rsi
mov    %eax,%edi
mov    $0x89670,%edx
call   1030 <write@plt>
mov    %ebx,%edi
call   1040 <close@plt>
mov    (%r15),%esi
or     (%r14),%esi
or     (%r12),%esi
lea    0xd85(%rip),%rdi
mov    $0x1b6,%edx
xor    %eax,%eax
call   1060 <open@plt>
mov    %eax,%ebx
lea    0x9c014(%rsp),%rsi
mov    %eax,%edi
mov    $0x163fec,%edx
call   1030 <write@plt>
mov    %ebx,%edi
call   1040 <close@plt>
xor    %eax,%eax
add    $0x200000,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [11 x i8] c"wma11b.rom\00"
@O_RDONLY = global i32 0
@.str.1 = [9 x i8] c"boot.rom\00"
@O_CREAT = global i32 0
@O_WRONLY = global i32 0
@O_TRUNC = global i32 0
@.str.2 = [13 x i8] c"settings.rom\00"
@.str.3 = [11 x i8] c"kernel.rom\00"
@.str.4 = [17 x i8] c"kernelloader.rom\00"
@.str.5 = [10 x i8] c"kernel.gz\00"
@.str.6 = [11 x i8] c"ramdisc.gz\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca [2097152 x i8]
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %3
store i8** %1, i8*** %4
%8 = load i32, i32* @O_RDONLY
%9 = call i32 (i8*, i32, ...) @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %8)
store i32 %9, i32* %6
%10 = load i32, i32* %6
%11 = getelementptr inbounds [2097152 x i8], [2097152 x i8]* %5, i64 0, i64 0
%12 = call i32 @read(i32 %10, i8* %11, i32 2097152)
%13 = load i32, i32* %6
%14 = call i32 @close(i32 %13)
%15 = load i32, i32* @O_CREAT
%16 = load i32, i32* @O_WRONLY
%17 = or i32 %15, %16
%18 = load i32, i32* @O_TRUNC
%19 = or i32 %17, %18
%20 = call i32 (i8*, i32, ...) @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 %19, i32 438)
store i32 %20, i32* %7
%21 = load i32, i32* %7
%22 = getelementptr inbounds [2097152 x i8], [2097152 x i8]* %5, i64 0, i64 0
%23 = call i32 @write(i32 %21, i8* %22, i32 57344)
%24 = load i32, i32* %7
%25 = call i32 @close(i32 %24)
%26 = load i32, i32* @O_CREAT
%27 = load i32, i32* @O_WRONLY
%28 = or i32 %26, %27
%29 = load i32, i32* @O_TRUNC
%30 = or i32 %28, %29
%31 = call i32 (i8*, i32, ...) @open(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i32 %30, i32 438)
store i32 %31, i32* %7
%32 = load i32, i32* %7
%33 = getelementptr inbounds [2097152 x i8], [2097152 x i8]* %5, i64 0, i64 0
%34 = getelementptr inbounds i8, i8* %33, i64 57344
%35 = call i32 @write(i32 %32, i8* %34, i32 4096)
%36 = load i32, i32* %7
%37 = call i32 @close(i32 %36)
%38 = load i32, i32* @O_CREAT
%39 = load i32, i32* @O_WRONLY
%40 = or i32 %38, %39
%41 = load i32, i32* @O_TRUNC
%42 = or i32 %40, %41
%43 = call i32 (i8*, i32, ...) @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i32 %42, i32 438)
store i32 %43, i32* %7
%44 = load i32, i32* %7
%45 = getelementptr inbounds [2097152 x i8], [2097152 x i8]* %5, i64 0, i64 0
%46 = getelementptr inbounds i8, i8* %45, i64 65536
%47 = call i32 @write(i32 %44, i8* %46, i32 2031616)
%48 = load i32, i32* %7
%49 = call i32 @close(i32 %48)
%50 = load i32, i32* @O_CREAT
%51 = load i32, i32* @O_WRONLY
%52 = or i32 %50, %51
%53 = load i32, i32* @O_TRUNC
%54 = or i32 %52, %53
%55 = call i32 (i8*, i32, ...) @open(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0), i32 %54, i32 438)
store i32 %55, i32* %7
%56 = load i32, i32* %7
%57 = getelementptr inbounds [2097152 x i8], [2097152 x i8]* %5, i64 0, i64 0
%58 = getelementptr inbounds i8, i8* %57, i64 65536
%59 = call i32 @write(i32 %56, i8* %58, i32 10640)
%60 = load i32, i32* %7
%61 = call i32 @close(i32 %60)
%62 = load i32, i32* @O_CREAT
%63 = load i32, i32* @O_WRONLY
%64 = or i32 %62, %63
%65 = load i32, i32* @O_TRUNC
%66 = or i32 %64, %65
%67 = call i32 (i8*, i32, ...) @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i64 0, i64 0), i32 %66, i32 438)
store i32 %67, i32* %7
%68 = load i32, i32* %7
%69 = getelementptr inbounds [2097152 x i8], [2097152 x i8]* %5, i64 0, i64 0
%70 = getelementptr inbounds i8, i8* %69, i64 65536
%71 = getelementptr inbounds i8, i8* %70, i64 10640
%72 = call i32 @write(i32 %68, i8* %71, i32 562800)
%73 = load i32, i32* %7
%74 = call i32 @close(i32 %73)
%75 = load i32, i32* @O_CREAT
%76 = load i32, i32* @O_WRONLY
%77 = or i32 %75, %76
%78 = load i32, i32* @O_TRUNC
%79 = or i32 %77, %78
%80 = call i32 (i8*, i32, ...) @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0), i32 %79, i32 438)
store i32 %80, i32* %7
%81 = load i32, i32* %7
%82 = getelementptr inbounds [2097152 x i8], [2097152 x i8]* %5, i64 0, i64 0
%83 = getelementptr inbounds i8, i8* %82, i64 638976
%84 = getelementptr inbounds i8, i8* %83, i64 20
%85 = call i32 @write(i32 %81, i8* %84, i32 1458156)
%86 = load i32, i32* %7
%87 = call i32 @close(i32 %86)
ret i32 0
}

LLVM IR (-O2):
@.str = [11 x i8] c"wma11b.rom\00"
@O_RDONLY = global i32 0
@.str.1 = [9 x i8] c"boot.rom\00"
@O_CREAT = global i32 0
@O_WRONLY = global i32 0
@O_TRUNC = global i32 0
@.str.2 = [13 x i8] c"settings.rom\00"
@.str.3 = [11 x i8] c"kernel.rom\00"
@.str.4 = [17 x i8] c"kernelloader.rom\00"
@.str.5 = [10 x i8] c"kernel.gz\00"
@.str.6 = [11 x i8] c"ramdisc.gz\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [2097152 x i8]
%4 = getelementptr inbounds [2097152 x i8], [2097152 x i8]* %3, i64 0, i64 0
%5 = load i32, i32* @O_RDONLY
%6 = tail call i32 (i8*, i32, ...) @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %5)
%7 = call i32 @read(i32 %6, i8* %4, i32 2097152)
%8 = tail call i32 @close(i32 %6)
%9 = load i32, i32* @O_CREAT
%10 = load i32, i32* @O_WRONLY
%11 = or i32 %10, %9
%12 = load i32, i32* @O_TRUNC
%13 = or i32 %11, %12
%14 = tail call i32 (i8*, i32, ...) @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 %13, i32 438)
%15 = call i32 @write(i32 %14, i8* %4, i32 57344)
%16 = tail call i32 @close(i32 %14)
%17 = load i32, i32* @O_CREAT
%18 = load i32, i32* @O_WRONLY
%19 = or i32 %18, %17
%20 = load i32, i32* @O_TRUNC
%21 = or i32 %19, %20
%22 = tail call i32 (i8*, i32, ...) @open(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i32 %21, i32 438)
%23 = getelementptr inbounds [2097152 x i8], [2097152 x i8]* %3, i64 0, i64 57344
%24 = call i32 @write(i32 %22, i8* %23, i32 4096)
%25 = tail call i32 @close(i32 %22)
%26 = load i32, i32* @O_CREAT
%27 = load i32, i32* @O_WRONLY
%28 = or i32 %27, %26
%29 = load i32, i32* @O_TRUNC
%30 = or i32 %28, %29
%31 = tail call i32 (i8*, i32, ...) @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i32 %30, i32 438)
%32 = getelementptr inbounds [2097152 x i8], [2097152 x i8]* %3, i64 0, i64 65536
%33 = call i32 @write(i32 %31, i8* %32, i32 2031616)
%34 = tail call i32 @close(i32 %31)
%35 = load i32, i32* @O_CREAT
%36 = load i32, i32* @O_WRONLY
%37 = or i32 %36, %35
%38 = load i32, i32* @O_TRUNC
%39 = or i32 %37, %38
%40 = tail call i32 (i8*, i32, ...) @open(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0), i32 %39, i32 438)
%41 = call i32 @write(i32 %40, i8* %32, i32 10640)
%42 = tail call i32 @close(i32 %40)
%43 = load i32, i32* @O_CREAT
%44 = load i32, i32* @O_WRONLY
%45 = or i32 %44, %43
%46 = load i32, i32* @O_TRUNC
%47 = or i32 %45, %46
%48 = tail call i32 (i8*, i32, ...) @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i64 0, i64 0), i32 %47, i32 438)
%49 = getelementptr inbounds [2097152 x i8], [2097152 x i8]* %3, i64 0, i64 76176
%50 = call i32 @write(i32 %48, i8* %49, i32 562800)
%51 = tail call i32 @close(i32 %48)
%52 = load i32, i32* @O_CREAT
%53 = load i32, i32* @O_WRONLY
%54 = or i32 %53, %52
%55 = load i32, i32* @O_TRUNC
%56 = or i32 %54, %55
%57 = tail call i32 (i8*, i32, ...) @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0), i32 %56, i32 438)
%58 = getelementptr inbounds [2097152 x i8], [2097152 x i8]* %3, i64 0, i64 638996
%59 = call i32 @write(i32 %57, i8* %58, i32 1458156)
%60 = tail call i32 @close(i32 %57)
ret i32 0
}