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

/* Variables and functions */
int /*<<< orphan*/ chmem_fzx2(int /*<<< orphan*/ *, unsigned char *, int,
                              char **);
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 /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  FILE *fp;
  unsigned char buf[32];
  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, 32, 1, fp) != 1) {
    fprintf(stderr, "%s: too short ?\n", argv[0]);
    exit(1);
  }
  if (*buf == 0x80 && buf[1] == 0xA8)
    chmem_fzx2(fp, buf, argc, argv);
  else if (*buf == 0xA8 && buf[1] == 0x80)
    chmem_fzx2(fp, buf, argc, argv);
  else {
    fprintf(stderr, "%s: not a Fuzix binary format.\n", argv[1]);
    exit(1);
  }
  fclose(fp);
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11c0 <main+0x50>
cmpl   $0x3,-0x8(%rbp)
je     11c0 <main+0x50>
mov    0x2e3f(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe4f(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
cmpl   $0x2,-0x8(%rbp)
jne    11e7 <main+0x77>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe3f(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
jmp    11ff <main+0x8f>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe24(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1221 <main+0xb1>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
lea    -0x40(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x20,%esi
mov    $0x1,%edx
call   1030 <fread@plt>
cmp    $0x1,%eax
je     1267 <main+0xf7>
mov    0x2d98(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xdc5(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
movzbl -0x40(%rbp),%eax
cmp    $0x80,%eax
jne    129e <main+0x12e>
movzbl -0x3f(%rbp),%eax
cmp    $0xa8,%eax
jne    129e <main+0x12e>
mov    -0x18(%rbp),%rdi
lea    -0x40(%rbp),%rsi
mov    -0x8(%rbp),%edx
mov    -0x10(%rbp),%rcx
call   1060 <chmem_fzx2@plt>
jmp    1301 <main+0x191>
movzbl -0x40(%rbp),%eax
cmp    $0xa8,%eax
jne    12d5 <main+0x165>
movzbl -0x3f(%rbp),%eax
cmp    $0x80,%eax
jne    12d5 <main+0x165>
mov    -0x18(%rbp),%rdi
lea    -0x40(%rbp),%rsi
mov    -0x8(%rbp),%edx
mov    -0x10(%rbp),%rcx
call   1060 <chmem_fzx2@plt>
jmp    12fc <main+0x18c>
mov    0x2d04(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xd41(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
jmp    1301 <main+0x191>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
xor    %edi,%edi
call   1090 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    %rsi,%rbx
mov    %edi,%eax
and    $0xfffffffe,%eax
cmp    $0x2,%eax
jne    11bd <main+0x4d>
mov    %edi,%ebp
cmp    $0x2,%edi
mov    0x8(%rbx),%rdi
lea    0xe83(%rip),%rax
lea    0xe7e(%rip),%rsi
cmove  %rax,%rsi
call   1070 <fopen@plt>
test   %rax,%rax
jne    11df <main+0x6f>
mov    0x8(%rbx),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    0x2e1c(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xe30(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    %rax,%r14
mov    %rsp,%rdi
mov    $0x20,%esi
mov    $0x1,%edx
mov    %rax,%rcx
call   1030 <fread@plt>
cmp    $0x1,%eax
jne    1234 <main+0xc4>
mov    (%rsp),%cl
mov    0x1(%rsp),%al
cmp    $0x80,%cl
jne    120c <main+0x9c>
cmp    $0xa8,%al
je     1215 <main+0xa5>
cmp    $0xa8,%cl
jne    1249 <main+0xd9>
cmp    $0x80,%al
jne    1249 <main+0xd9>
mov    %rsp,%rsi
mov    %r14,%rdi
mov    %ebp,%edx
mov    %rbx,%rcx
call   1060 <chmem_fzx2@plt>
mov    %r14,%rdi
call   1040 <fclose@plt>
xor    %edi,%edi
call   1090 <exit@plt>
mov    0x2da5(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xdd6(%rip),%rsi
jmp    11d0 <main+0x60>
mov    0x2d90(%rip),%rax
mov    (%rax),%edi
mov    0x8(%rbx),%rdx
lea    0xdd1(%rip),%rsi
jmp    11d0 <main+0x60>

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"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca [32 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* %4
%9 = icmp ne i32 %8, 2
br i1 %9, label %10, label %20
10: ; preds = %2
%11 = load i32, i32* %4
%12 = icmp ne i32 %11, 3
br i1 %12, label %13, label %20
13: ; preds = %10
%14 = load i32, i32* @stderr
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 0
%17 = load i8*, i8** %16
%18 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* %17)
%19 = call i32 @exit(i32 1)
unreachable
20: ; preds = %10, %2
%21 = load i32, i32* %4
%22 = icmp eq i32 %21, 2
br i1 %22, label %23, label %28
23: ; preds = %20
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 1
%26 = load i8*, i8** %25
%27 = call i32* @fopen(i8* %26, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %27, i32** %6
br label %33
28: ; preds = %20
%29 = load i8**, i8*** %5
%30 = getelementptr inbounds i8*, i8** %29, i64 1
%31 = load i8*, i8** %30
%32 = call i32* @fopen(i8* %31, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
store i32* %32, i32** %6
br label %33
33: ; preds = %28, %23
%34 = load i32*, i32** %6
%35 = icmp eq i32* %34, null
br i1 %35, label %36, label %42
36: ; preds = %33
%37 = load i8**, i8*** %5
%38 = getelementptr inbounds i8*, i8** %37, i64 1
%39 = load i8*, i8** %38
%40 = call i32 @perror(i8* %39)
%41 = call i32 @exit(i32 1)
unreachable
42: ; preds = %33
%43 = getelementptr inbounds [32 x i8], [32 x i8]* %7, i64 0, i64 0
%44 = load i32*, i32** %6
%45 = call i32 @fread(i8* %43, i32 32, i32 1, i32* %44)
%46 = icmp ne i32 %45, 1
br i1 %46, label %47, label %54
47: ; preds = %42
%48 = load i32, i32* @stderr
%49 = load i8**, i8*** %5
%50 = getelementptr inbounds i8*, i8** %49, i64 0
%51 = load i8*, i8** %50
%52 = call i32 @fprintf(i32 %48, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0), i8* %51)
%53 = call i32 @exit(i32 1)
unreachable
54: ; preds = %42
%55 = getelementptr inbounds [32 x i8], [32 x i8]* %7, i64 0, i64 0
%56 = load i8, i8* %55
%57 = zext i8 %56 to i32
%58 = icmp eq i32 %57, 128
br i1 %58, label %59, label %70
59: ; preds = %54
%60 = getelementptr inbounds [32 x i8], [32 x i8]* %7, i64 0, i64 1
%61 = load i8, i8* %60
%62 = zext i8 %61 to i32
%63 = icmp eq i32 %62, 168
br i1 %63, label %64, label %70
64: ; preds = %59
%65 = load i32*, i32** %6
%66 = getelementptr inbounds [32 x i8], [32 x i8]* %7, i64 0, i64 0
%67 = load i32, i32* %4
%68 = load i8**, i8*** %5
%69 = call i32 @chmem_fzx2(i32* %65, i8* %66, i32 %67, i8** %68)
br label %94
70: ; preds = %59, %54
%71 = getelementptr inbounds [32 x i8], [32 x i8]* %7, i64 0, i64 0
%72 = load i8, i8* %71
%73 = zext i8 %72 to i32
%74 = icmp eq i32 %73, 168
br i1 %74, label %75, label %86
75: ; preds = %70
%76 = getelementptr inbounds [32 x i8], [32 x i8]* %7, i64 0, i64 1
%77 = load i8, i8* %76
%78 = zext i8 %77 to i32
%79 = icmp eq i32 %78, 128
br i1 %79, label %80, label %86
80: ; preds = %75
%81 = load i32*, i32** %6
%82 = getelementptr inbounds [32 x i8], [32 x i8]* %7, i64 0, i64 0
%83 = load i32, i32* %4
%84 = load i8**, i8*** %5
%85 = call i32 @chmem_fzx2(i32* %81, i8* %82, i32 %83, i8** %84)
br label %93
86: ; preds = %75, %70
%87 = load i32, i32* @stderr
%88 = load i8**, i8*** %5
%89 = getelementptr inbounds i8*, i8** %88, i64 1
%90 = load i8*, i8** %89
%91 = call i32 @fprintf(i32 %87, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.4, i64 0, i64 0), i8* %90)
%92 = call i32 @exit(i32 1)
unreachable
93: ; preds = %80
br label %94
94: ; preds = %93, %64
%95 = load i32*, i32** %6
%96 = call i32 @fclose(i32* %95)
%97 = 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"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca [32 x i8]
%4 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 0
%5 = and i32 %0, -2
%6 = icmp eq i32 %5, 2
br i1 %6, label %12, label %7
7: ; preds = %2
%8 = load i32, i32* @stderr
%9 = load i8*, i8** %1
%10 = tail call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* %9)
%11 = tail call i32 @exit(i32 1)
unreachable
12: ; preds = %2
%13 = icmp eq i32 %0, 2
%14 = getelementptr inbounds i8*, i8** %1, i64 1
%15 = load i8*, i8** %14
%16 = select i1 %13, 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)
%17 = tail call i32* @fopen(i8* %15, i8* %16)
%18 = icmp eq i32* %17, null
br i1 %18, label %19, label %24
19: ; preds = %12
%20 = getelementptr inbounds i8*, i8** %1, i64 1
%21 = load i8*, i8** %20
%22 = tail call i32 @perror(i8* %21)
%23 = tail call i32 @exit(i32 1)
unreachable
24: ; preds = %12
%25 = call i32 @fread(i8* %4, i32 32, i32 1, i32* %17)
%26 = icmp eq i32 %25, 1
br i1 %26, label %32, label %27
27: ; preds = %24
%28 = load i32, i32* @stderr
%29 = load i8*, i8** %1
%30 = tail call i32 @fprintf(i32 %28, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0), i8* %29)
%31 = tail call i32 @exit(i32 1)
unreachable
32: ; preds = %24
%33 = load i8, i8* %4
%34 = icmp eq i8 %33, -128
%35 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 1
%36 = load i8, i8* %35
%37 = icmp eq i8 %36, -88
%38 = select i1 %34, i1 %37, i1 false
br i1 %38, label %49, label %39
39: ; preds = %32
%40 = icmp eq i8 %33, -88
%41 = icmp eq i8 %36, -128
%42 = select i1 %40, i1 %41, i1 false
br i1 %42, label %49, label %43
43: ; preds = %39
%44 = load i32, i32* @stderr
%45 = getelementptr inbounds i8*, i8** %1, i64 1
%46 = load i8*, i8** %45
%47 = tail call i32 @fprintf(i32 %44, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.4, i64 0, i64 0), i8* %46)
%48 = tail call i32 @exit(i32 1)
unreachable
49: ; preds = %39, %32
%50 = call i32 @chmem_fzx2(i32* %17, i8* %4, i32 %0, i8** %1)
%51 = call i32 @fclose(i32* %17)
%52 = call i32 @exit(i32 0)
unreachable
}