#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 */
typedef int uint8_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, ...);
int fread(unsigned char *, int, int, int /*<<< orphan*/ *);
int fwrite(unsigned char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ rewind(int /*<<< orphan*/ *);
int sscanf(char *, char *, int *);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  int v;
  FILE *fp;
  unsigned char buf[10];
  unsigned short top;
  uint8_t be;
  if (argc != 2 && argc != 3) {
    fprintf(stderr, "%s [executable] {size}\n", argv[0]);
    exit(1);
  }
  if (argc == 2)
    fp = fopen(argv[1], "r");
  else
    fp = fopen(argv[1], "r+");
  if (fp == NULL) {
    perror(argv[1]);
    exit(1);
  }
  if (fread(buf, 10, 1, fp) != 1) {
    fprintf(stderr, "%s: too short ?\n", argv[0]);
    exit(1);
  }
  if (buf[3] != 'F' || buf[4] != 'Z' || buf[5] != 'X' || buf[6] != '1') {
    fprintf(stderr, "%s: not a Fuzix binary format.\n", argv[1]);
    exit(1);
  }
  if (buf[0] == 0x7E || buf[0] == 0x20)
    be = 1;
  else if (buf[0] == 0x4C || buf[0] == 0x38)
    be = 0;
  else if (buf[0] == 0xC3 || buf[0] == 0x18)
    be = 0;
  else {
    fprintf(stderr, "%s: unknown Fuzix binary type.\n", argv[1]);
    exit(1);
  }
  if (argc == 2) {
    if (be)
      top = buf[9] | (buf[8] << 8);
    else
      top = buf[8] | (buf[9] << 8);
    if (top)
      printf("Fuzix binary set at %d bytes.\n", top);
    else
      printf("Fuzix binary, set to allocate all available.\n");
    exit(0);
  }
  if (sscanf(argv[2], "%d", &v) != 1 || v < 0 || v > 65536) {
    fprintf(stderr, "%s: invalid chmem value '%s'.\n", argv[0], argv[2]);
    exit(1);
  }
  if (be) {
    buf[8] = v >> 8;
    buf[9] = v & 0xFF;
  } else {
    buf[8] = v & 0xFF;
    buf[9] = v >> 8;
  }
  rewind(fp);
  if (fwrite(buf, 10, 1, fp) != 1) {
    fprintf(stderr, "%s: write error.\n", argv[0]);
    exit(1);
  }
  fclose(fp);
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11f2 <main+0x52>
cmpl   $0x3,-0x8(%rbp)
je     11f2 <main+0x52>
mov    0x2e0f(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe1f(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
cmpl   $0x2,-0x8(%rbp)
jne    1219 <main+0x79>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe0d(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x20(%rbp)
jmp    1231 <main+0x91>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xdf2(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1253 <main+0xb3>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10a0 <perror@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
lea    -0x2a(%rbp),%rdi
mov    -0x20(%rbp),%rcx
mov    $0xa,%esi
mov    $0x1,%edx
call   1030 <fread@plt>
cmp    $0x1,%eax
je     129b <main+0xfb>
mov    0x2d66(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xd93(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
movzbl -0x27(%rbp),%eax
cmp    $0x46,%eax
jne    12cf <main+0x12f>
movzbl -0x26(%rbp),%eax
cmp    $0x5a,%eax
jne    12cf <main+0x12f>
movzbl -0x25(%rbp),%eax
cmp    $0x58,%eax
jne    12cf <main+0x12f>
movzbl -0x24(%rbp),%eax
cmp    $0x31,%eax
je     12f8 <main+0x158>
mov    0x2d0a(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xd47(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
movzbl -0x2a(%rbp),%eax
cmp    $0x7e,%eax
je     1312 <main+0x172>
movzbl -0x2a(%rbp),%eax
cmp    $0x20,%eax
jne    131e <main+0x17e>
movl   $0x1,-0x30(%rbp)
jmp    139f <main+0x1ff>
movzbl -0x2a(%rbp),%eax
cmp    $0x4c,%eax
je     1338 <main+0x198>
movzbl -0x2a(%rbp),%eax
cmp    $0x38,%eax
jne    1344 <main+0x1a4>
movl   $0x0,-0x30(%rbp)
jmp    139a <main+0x1fa>
movzbl -0x2a(%rbp),%eax
cmp    $0xc3,%eax
je     1360 <main+0x1c0>
movzbl -0x2a(%rbp),%eax
cmp    $0x18,%eax
jne    136c <main+0x1cc>
movl   $0x0,-0x30(%rbp)
jmp    1395 <main+0x1f5>
mov    0x2c6d(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xcca(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
jmp    139a <main+0x1fa>
jmp    139f <main+0x1ff>
cmpl   $0x2,-0x8(%rbp)
jne    1411 <main+0x271>
cmpl   $0x0,-0x30(%rbp)
je     13c9 <main+0x229>
movzbl -0x21(%rbp),%eax
movzbl -0x22(%rbp),%ecx
shl    $0x8,%ecx
or     %ecx,%eax
mov    %ax,-0x2c(%rbp)
jmp    13da <main+0x23a>
movzbl -0x22(%rbp),%eax
movzbl -0x21(%rbp),%ecx
shl    $0x8,%ecx
or     %ecx,%eax
mov    %ax,-0x2c(%rbp)
cmpw   $0x0,-0x2c(%rbp)
je     13fc <main+0x25c>
movzwl -0x2c(%rbp),%esi
lea    0xc7e(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    140a <main+0x26a>
lea    0xc8a(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
xor    %edi,%edi
call   10b0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xc9b(%rip),%rsi
lea    -0x14(%rbp),%rdx
call   1080 <sscanf@plt>
cmp    $0x1,%eax
jne    1449 <main+0x2a9>
cmpl   $0x0,-0x14(%rbp)
jl     1449 <main+0x2a9>
cmpl   $0x10000,-0x14(%rbp)
jle    1479 <main+0x2d9>
mov    0x2b90(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rcx
lea    0xc56(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
cmpl   $0x0,-0x30(%rbp)
je     149c <main+0x2fc>
mov    -0x14(%rbp),%eax
sar    $0x8,%eax
mov    %al,-0x22(%rbp)
mov    -0x14(%rbp),%eax
and    $0xff,%eax
mov    %al,-0x21(%rbp)
jmp    14b0 <main+0x310>
mov    -0x14(%rbp),%eax
and    $0xff,%eax
mov    %al,-0x22(%rbp)
mov    -0x14(%rbp),%eax
sar    $0x8,%eax
mov    %al,-0x21(%rbp)
mov    -0x20(%rbp),%rdi
call   1060 <rewind@plt>
lea    -0x2a(%rbp),%rdi
mov    -0x20(%rbp),%rcx
mov    $0xa,%esi
mov    $0x1,%edx
call   10c0 <fwrite@plt>
cmp    $0x1,%eax
je     1501 <main+0x361>
mov    0x2b00(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xbed(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
xor    %edi,%edi
call   10b0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
mov    %edi,%eax
and    $0xfffffffe,%eax
cmp    $0x2,%eax
jne    1201 <main+0x51>
mov    %edi,%ebp
cmp    $0x2,%edi
mov    0x8(%rbx),%rdi
lea    0xe3f(%rip),%rax
lea    0xe3a(%rip),%rsi
cmove  %rax,%rsi
call   10a0 <fopen@plt>
test   %rax,%rax
jne    1216 <main+0x66>
mov    0x8(%rbx),%rdi
call   10b0 <perror@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    0x2dd8(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xdec(%rip),%rsi
jmp    128b <main+0xdb>
mov    %rax,%r14
lea    0x2(%rsp),%r15
mov    %r15,%rdi
mov    $0xa,%esi
mov    $0x1,%edx
mov    %rax,%rcx
call   1040 <fread@plt>
cmp    $0x1,%eax
jne    1262 <main+0xb2>
movd   0x5(%rsp),%xmm0
movd   %xmm0,%eax
cmp    $0x31585a46,%eax
jne    1277 <main+0xc7>
xor    %r12d,%r12d
mov    0x2(%rsp),%al
cmp    $0x37,%al
jg     129c <main+0xec>
cmp    $0xc3,%al
je     12be <main+0x10e>
cmp    $0x18,%al
je     12be <main+0x10e>
cmp    $0x20,%al
je     12c1 <main+0x111>
jmp    12a8 <main+0xf8>
mov    0x2d77(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xda8(%rip),%rsi
jmp    128b <main+0xdb>
mov    0x2d62(%rip),%rax
mov    (%rax),%edi
mov    0x8(%rbx),%rdx
lea    0xda3(%rip),%rsi
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
cmp    $0x38,%al
je     12be <main+0x10e>
cmp    $0x4c,%al
je     12be <main+0x10e>
cmp    $0x7e,%al
je     12c1 <main+0x111>
mov    0x2d31(%rip),%rax
mov    (%rax),%edi
mov    0x8(%rbx),%rdx
lea    0xd92(%rip),%rsi
jmp    128b <main+0xdb>
mov    $0x1,%r12b
cmp    $0x2,%ebp
jne    12f8 <main+0x148>
movzbl %r12b,%eax
mov    %r15,%rcx
sub    %rax,%rcx
movzbl 0x9(%rcx),%ecx
movzbl 0x8(%rax,%r15,1),%esi
shl    $0x8,%esi
or     %ecx,%esi
jne    136c <main+0x1bc>
lea    0xdd5(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   10c0 <exit@plt>
mov    0x10(%rbx),%rdi
lea    0xd8a(%rip),%rsi
lea    0xc(%rsp),%rdx
call   1090 <sscanf@plt>
cmp    $0x1,%eax
jne    1381 <main+0x1d1>
mov    0xc(%rsp),%eax
test   %eax,%eax
js     1381 <main+0x1d1>
cmp    $0x10001,%eax
jge    1381 <main+0x1d1>
mov    %eax,%ecx
shr    $0x8,%ecx
test   %r12b,%r12b
mov    %eax,%edx
cmovne %ecx,%edx
cmovne %eax,%ecx
mov    %cl,0xa(%rsp)
mov    %dl,0xb(%rsp)
mov    %r14,%rdi
call   1070 <rewind@plt>
lea    0x2(%rsp),%rdi
mov    $0xa,%esi
mov    $0x1,%edx
mov    %r14,%rcx
call   10d0 <fwrite@plt>
cmp    $0x1,%eax
jne    13a9 <main+0x1f9>
mov    %r14,%rdi
call   1050 <fclose@plt>
xor    %edi,%edi
call   10c0 <exit@plt>
lea    0xcfb(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
xor    %edi,%edi
call   10c0 <exit@plt>
mov    0x2c58(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
mov    0x10(%rbx),%rcx
lea    0xcf8(%rip),%rsi
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    0x2c30(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xcf3(%rip),%rsi
jmp    128b <main+0xdb>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [24 x i8] c"%s [executable] {size}\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [3 x i8] c"r+\00"
@.str.3 = [17 x i8] c"%s: too short ?\0A\00"
@.str.4 = [32 x i8] c"%s: not a Fuzix binary format.\0A\00"
@.str.5 = [32 x i8] c"%s: unknown Fuzix binary type.\0A\00"
@.str.6 = [31 x i8] c"Fuzix binary set at %d bytes.\0A\00"
@.str.7 = [46 x i8] c"Fuzix binary, set to allocate all available.\0A\00"
@.str.8 = [3 x i8] c"%d\00"
@.str.9 = [31 x i8] c"%s: invalid chmem value '%s'.\0A\00"
@.str.10 = [18 x i8] c"%s: write error.\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32*
%8 = alloca [10 x i8]
%9 = alloca i16
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* %4
%12 = icmp ne i32 %11, 2
br i1 %12, label %13, label %23
13: ; preds = %2
%14 = load i32, i32* %4
%15 = icmp ne i32 %14, 3
br i1 %15, label %16, label %23
16: ; preds = %13
%17 = load i32, i32* @stderr
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 0
%20 = load i8*, i8** %19
%21 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* %20)
%22 = call i32 @exit(i32 1)
unreachable
23: ; preds = %13, %2
%24 = load i32, i32* %4
%25 = icmp eq i32 %24, 2
br i1 %25, label %26, label %31
26: ; preds = %23
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 1
%29 = load i8*, i8** %28
%30 = call i32* @fopen(i8* %29, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %30, i32** %7
br label %36
31: ; preds = %23
%32 = load i8**, i8*** %5
%33 = getelementptr inbounds i8*, i8** %32, i64 1
%34 = load i8*, i8** %33
%35 = call i32* @fopen(i8* %34, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
store i32* %35, i32** %7
br label %36
36: ; preds = %31, %26
%37 = load i32*, i32** %7
%38 = icmp eq i32* %37, null
br i1 %38, label %39, label %45
39: ; preds = %36
%40 = load i8**, i8*** %5
%41 = getelementptr inbounds i8*, i8** %40, i64 1
%42 = load i8*, i8** %41
%43 = call i32 @perror(i8* %42)
%44 = call i32 @exit(i32 1)
unreachable
45: ; preds = %36
%46 = getelementptr inbounds [10 x i8], [10 x i8]* %8, i64 0, i64 0
%47 = load i32*, i32** %7
%48 = call i32 @fread(i8* %46, i32 10, i32 1, i32* %47)
%49 = icmp ne i32 %48, 1
br i1 %49, label %50, label %57
50: ; preds = %45
%51 = load i32, i32* @stderr
%52 = load i8**, i8*** %5
%53 = getelementptr inbounds i8*, i8** %52, i64 0
%54 = load i8*, i8** %53
%55 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %51, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0), i8* %54)
%56 = call i32 @exit(i32 1)
unreachable
57: ; preds = %45
%58 = getelementptr inbounds [10 x i8], [10 x i8]* %8, i64 0, i64 3
%59 = load i8, i8* %58
%60 = zext i8 %59 to i32
%61 = icmp ne i32 %60, 70
br i1 %61, label %77, label %62
62: ; preds = %57
%63 = getelementptr inbounds [10 x i8], [10 x i8]* %8, i64 0, i64 4
%64 = load i8, i8* %63
%65 = zext i8 %64 to i32
%66 = icmp ne i32 %65, 90
br i1 %66, label %77, label %67
67: ; preds = %62
%68 = getelementptr inbounds [10 x i8], [10 x i8]* %8, i64 0, i64 5
%69 = load i8, i8* %68
%70 = zext i8 %69 to i32
%71 = icmp ne i32 %70, 88
br i1 %71, label %77, label %72
72: ; preds = %67
%73 = getelementptr inbounds [10 x i8], [10 x i8]* %8, i64 0, i64 6
%74 = load i8, i8* %73
%75 = zext i8 %74 to i32
%76 = icmp ne i32 %75, 49
br i1 %76, label %77, label %84
77: ; preds = %72, %67, %62, %57
%78 = load i32, i32* @stderr
%79 = load i8**, i8*** %5
%80 = getelementptr inbounds i8*, i8** %79, i64 1
%81 = load i8*, i8** %80
%82 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %78, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.4, i64 0, i64 0), i8* %81)
%83 = call i32 @exit(i32 1)
unreachable
84: ; preds = %72
%85 = getelementptr inbounds [10 x i8], [10 x i8]* %8, i64 0, i64 0
%86 = load i8, i8* %85
%87 = zext i8 %86 to i32
%88 = icmp eq i32 %87, 126
br i1 %88, label %94, label %89
89: ; preds = %84
%90 = getelementptr inbounds [10 x i8], [10 x i8]* %8, i64 0, i64 0
%91 = load i8, i8* %90
%92 = zext i8 %91 to i32
%93 = icmp eq i32 %92, 32
br i1 %93, label %94, label %95
94: ; preds = %89, %84
store i32 1, i32* %10
br label %126
95: ; preds = %89
%96 = getelementptr inbounds [10 x i8], [10 x i8]* %8, i64 0, i64 0
%97 = load i8, i8* %96
%98 = zext i8 %97 to i32
%99 = icmp eq i32 %98, 76
br i1 %99, label %105, label %100
100: ; preds = %95
%101 = getelementptr inbounds [10 x i8], [10 x i8]* %8, i64 0, i64 0
%102 = load i8, i8* %101
%103 = zext i8 %102 to i32
%104 = icmp eq i32 %103, 56
br i1 %104, label %105, label %106
105: ; preds = %100, %95
store i32 0, i32* %10
br label %125
106: ; preds = %100
%107 = getelementptr inbounds [10 x i8], [10 x i8]* %8, i64 0, i64 0
%108 = load i8, i8* %107
%109 = zext i8 %108 to i32
%110 = icmp eq i32 %109, 195
br i1 %110, label %116, label %111
111: ; preds = %106
%112 = getelementptr inbounds [10 x i8], [10 x i8]* %8, i64 0, i64 0
%113 = load i8, i8* %112
%114 = zext i8 %113 to i32
%115 = icmp eq i32 %114, 24
br i1 %115, label %116, label %117
116: ; preds = %111, %106
store i32 0, i32* %10
br label %124
117: ; preds = %111
%118 = load i32, i32* @stderr
%119 = load i8**, i8*** %5
%120 = getelementptr inbounds i8*, i8** %119, i64 1
%121 = load i8*, i8** %120
%122 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %118, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.5, i64 0, i64 0), i8* %121)
%123 = call i32 @exit(i32 1)
unreachable
124: ; preds = %116
br label %125
125: ; preds = %124, %105
br label %126
126: ; preds = %125, %94
%127 = load i32, i32* %4
%128 = icmp eq i32 %127, 2
br i1 %128, label %129, label %163
129: ; preds = %126
%130 = load i32, i32* %10
%131 = icmp ne i32 %130, 0
br i1 %131, label %132, label %142
132: ; preds = %129
%133 = getelementptr inbounds [10 x i8], [10 x i8]* %8, i64 0, i64 9
%134 = load i8, i8* %133
%135 = zext i8 %134 to i32
%136 = getelementptr inbounds [10 x i8], [10 x i8]* %8, i64 0, i64 8
%137 = load i8, i8* %136
%138 = zext i8 %137 to i32
%139 = shl i32 %138, 8
%140 = or i32 %135, %139
%141 = trunc i32 %140 to i16
store i16 %141, i16* %9
br label %152
142: ; preds = %129
%143 = getelementptr inbounds [10 x i8], [10 x i8]* %8, i64 0, i64 8
%144 = load i8, i8* %143
%145 = zext i8 %144 to i32
%146 = getelementptr inbounds [10 x i8], [10 x i8]* %8, i64 0, i64 9
%147 = load i8, i8* %146
%148 = zext i8 %147 to i32
%149 = shl i32 %148, 8
%150 = or i32 %145, %149
%151 = trunc i32 %150 to i16
store i16 %151, i16* %9
br label %152
152: ; preds = %142, %132
%153 = load i16, i16* %9
%154 = icmp ne i16 %153, 0
br i1 %154, label %155, label %159
155: ; preds = %152
%156 = load i16, i16* %9
%157 = zext i16 %156 to i32
%158 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.6, i64 0, i64 0), i32 %157)
br label %161
159: ; preds = %152
%160 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.7, i64 0, i64 0))
br label %161
161: ; preds = %159, %155
%162 = call i32 @exit(i32 0)
unreachable
163: ; preds = %126
%164 = load i8**, i8*** %5
%165 = getelementptr inbounds i8*, i8** %164, i64 2
%166 = load i8*, i8** %165
%167 = call i32 @sscanf(i8* %166, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0), i32* %6)
%168 = icmp ne i32 %167, 1
br i1 %168, label %175, label %169
169: ; preds = %163
%170 = load i32, i32* %6
%171 = icmp slt i32 %170, 0
br i1 %171, label %175, label %172
172: ; preds = %169
%173 = load i32, i32* %6
%174 = icmp sgt i32 %173, 65536
br i1 %174, label %175, label %185
175: ; preds = %172, %169, %163
%176 = load i32, i32* @stderr
%177 = load i8**, i8*** %5
%178 = getelementptr inbounds i8*, i8** %177, i64 0
%179 = load i8*, i8** %178
%180 = load i8**, i8*** %5
%181 = getelementptr inbounds i8*, i8** %180, i64 2
%182 = load i8*, i8** %181
%183 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %176, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.9, i64 0, i64 0), i8* %179, i8* %182)
%184 = call i32 @exit(i32 1)
unreachable
185: ; preds = %172
%186 = load i32, i32* %10
%187 = icmp ne i32 %186, 0
br i1 %187, label %188, label %197
188: ; preds = %185
%189 = load i32, i32* %6
%190 = ashr i32 %189, 8
%191 = trunc i32 %190 to i8
%192 = getelementptr inbounds [10 x i8], [10 x i8]* %8, i64 0, i64 8
store i8 %191, i8* %192
%193 = load i32, i32* %6
%194 = and i32 %193, 255
%195 = trunc i32 %194 to i8
%196 = getelementptr inbounds [10 x i8], [10 x i8]* %8, i64 0, i64 9
store i8 %195, i8* %196
br label %206
197: ; preds = %185
%198 = load i32, i32* %6
%199 = and i32 %198, 255
%200 = trunc i32 %199 to i8
%201 = getelementptr inbounds [10 x i8], [10 x i8]* %8, i64 0, i64 8
store i8 %200, i8* %201
%202 = load i32, i32* %6
%203 = ashr i32 %202, 8
%204 = trunc i32 %203 to i8
%205 = getelementptr inbounds [10 x i8], [10 x i8]* %8, i64 0, i64 9
store i8 %204, i8* %205
br label %206
206: ; preds = %197, %188
%207 = load i32*, i32** %7
%208 = call i32 @rewind(i32* %207)
%209 = getelementptr inbounds [10 x i8], [10 x i8]* %8, i64 0, i64 0
%210 = load i32*, i32** %7
%211 = call i32 @fwrite(i8* %209, i32 10, i32 1, i32* %210)
%212 = icmp ne i32 %211, 1
br i1 %212, label %213, label %220
213: ; preds = %206
%214 = load i32, i32* @stderr
%215 = load i8**, i8*** %5
%216 = getelementptr inbounds i8*, i8** %215, i64 0
%217 = load i8*, i8** %216
%218 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %214, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.10, i64 0, i64 0), i8* %217)
%219 = call i32 @exit(i32 1)
unreachable
220: ; preds = %206
%221 = load i32*, i32** %7
%222 = call i32 @fclose(i32* %221)
%223 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [24 x i8] c"%s [executable] {size}\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [3 x i8] c"r+\00"
@.str.3 = [17 x i8] c"%s: too short ?\0A\00"
@.str.4 = [32 x i8] c"%s: not a Fuzix binary format.\0A\00"
@.str.5 = [32 x i8] c"%s: unknown Fuzix binary type.\0A\00"
@.str.6 = [31 x i8] c"Fuzix binary set at %d bytes.\0A\00"
@.str.8 = [3 x i8] c"%d\00"
@.str.9 = [31 x i8] c"%s: invalid chmem value '%s'.\0A\00"
@.str.10 = [18 x i8] c"%s: write error.\0A\00"
@str = [45 x i8] c"Fuzix binary, set to allocate all available.\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca [10 x i8]
%5 = bitcast i32* %3 to i8*
%6 = getelementptr inbounds [10 x i8], [10 x i8]* %4, i64 0, i64 0
%7 = and i32 %0, -2
%8 = icmp eq i32 %7, 2
br i1 %8, label %14, label %9
9: ; preds = %2
%10 = load i32, i32* @stderr
%11 = load i8*, i8** %1
%12 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %10, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* %11)
%13 = tail call i32 @exit(i32 1)
unreachable
14: ; preds = %2
%15 = icmp eq i32 %0, 2
%16 = getelementptr inbounds i8*, i8** %1, i64 1
%17 = load i8*, i8** %16
%18 = select i1 %15, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0)
%19 = tail call i32* @fopen(i8* %17, i8* %18)
%20 = icmp eq i32* %19, null
br i1 %20, label %21, label %26
21: ; preds = %14
%22 = getelementptr inbounds i8*, i8** %1, i64 1
%23 = load i8*, i8** %22
%24 = tail call i32 @perror(i8* %23)
%25 = tail call i32 @exit(i32 1)
unreachable
26: ; preds = %14
%27 = call i32 @fread(i8* %6, i32 10, i32 1, i32* %19)
%28 = icmp eq i32 %27, 1
br i1 %28, label %34, label %29
29: ; preds = %26
%30 = load i32, i32* @stderr
%31 = load i8*, i8** %1
%32 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %30, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0), i8* %31)
%33 = tail call i32 @exit(i32 1)
unreachable
34: ; preds = %26
%35 = getelementptr inbounds [10 x i8], [10 x i8]* %4, i64 0, i64 3
%36 = bitcast i8* %35 to <4 x i8>*
%37 = load <4 x i8>, <4 x i8>* %36
%38 = freeze <4 x i8> %37
%39 = bitcast <4 x i8> %38 to i32
%40 = icmp eq i32 %39, 827873862
br i1 %40, label %47, label %41
41: ; preds = %34
%42 = load i32, i32* @stderr
%43 = getelementptr inbounds i8*, i8** %1, i64 1
%44 = load i8*, i8** %43
%45 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %42, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.4, i64 0, i64 0), i8* %44)
%46 = tail call i32 @exit(i32 1)
unreachable
47: ; preds = %34
%48 = load i8, i8* %6
switch i8 %48, label %49 [
i8 126, label %57
i8 32, label %57
i8 76, label %55
i8 56, label %55
i8 -61, label %56
i8 24, label %56
]
49: ; preds = %47
%50 = load i32, i32* @stderr
%51 = getelementptr inbounds i8*, i8** %1, i64 1
%52 = load i8*, i8** %51
%53 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %50, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.5, i64 0, i64 0), i8* %52)
%54 = tail call i32 @exit(i32 1)
unreachable
55: ; preds = %47, %47
br label %57
56: ; preds = %47, %47
br label %57
57: ; preds = %47, %47, %56, %55
%58 = phi i1 [ false, %47 ], [ false, %47 ], [ true, %55 ], [ true, %56 ]
br i1 %15, label %59, label %78
59: ; preds = %57
%60 = select i1 %58, i64 8, i64 9
%61 = select i1 %58, i64 9, i64 8
%62 = getelementptr inbounds [10 x i8], [10 x i8]* %4, i64 0, i64 %60
%63 = load i8, i8* %62
%64 = zext i8 %63 to i16
%65 = getelementptr inbounds [10 x i8], [10 x i8]* %4, i64 0, i64 %61
%66 = load i8, i8* %65
%67 = zext i8 %66 to i16
%68 = shl nuw i16 %67, 8
%69 = or i16 %68, %64
%70 = icmp eq i16 %69, 0
br i1 %70, label %74, label %71
71: ; preds = %59
%72 = zext i16 %69 to i32
%73 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.6, i64 0, i64 0), i32 %72)
br label %76
74: ; preds = %59
%75 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @str, i64 0, i64 0))
br label %76
76: ; preds = %74, %71
%77 = tail call i32 @exit(i32 0)
unreachable
78: ; preds = %57
%79 = getelementptr inbounds i8*, i8** %1, i64 2
%80 = load i8*, i8** %79
%81 = call i32 @sscanf(i8* %80, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0), i32* %3)
%82 = icmp ne i32 %81, 1
%83 = load i32, i32* %3
%84 = icmp slt i32 %83, 0
%85 = select i1 %82, i1 true, i1 %84
%86 = icmp sgt i32 %83, 65536
%87 = select i1 %85, i1 true, i1 %86
br i1 %87, label %88, label %94
88: ; preds = %78
%89 = load i32, i32* @stderr
%90 = load i8*, i8** %1
%91 = load i8*, i8** %79
%92 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %89, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.9, i64 0, i64 0), i8* %90, i8* %91)
%93 = call i32 @exit(i32 1)
unreachable
94: ; preds = %78
%95 = lshr i32 %83, 8
%96 = select i1 %58, i32 %83, i32 %95
%97 = select i1 %58, i32 %95, i32 %83
%98 = trunc i32 %97 to i8
%99 = trunc i32 %96 to i8
%100 = getelementptr inbounds [10 x i8], [10 x i8]* %4, i64 0, i64 8
store i8 %99, i8* %100
%101 = getelementptr inbounds [10 x i8], [10 x i8]* %4, i64 0, i64 9
store i8 %98, i8* %101
%102 = call i32 @rewind(i32* %19)
%103 = call i32 @fwrite(i8* %6, i32 10, i32 1, i32* %19)
%104 = icmp eq i32 %103, 1
br i1 %104, label %110, label %105
105: ; preds = %94
%106 = load i32, i32* @stderr
%107 = load i8*, i8** %1
%108 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %106, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.10, i64 0, i64 0), i8* %107)
%109 = call i32 @exit(i32 1)
unreachable
110: ; preds = %94
%111 = call i32 @fclose(i32* %19)
%112 = call i32 @exit(i32 0)
unreachable
}