#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_flat(int /*<<< orphan*/ *, unsigned char *, int,
                              char **);
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*/ *);
scalar_t__ memcmp(unsigned char *, char *, int);
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 if (memcmp(buf, "bFLT", 4) == 0)
    chmem_flat(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     11e0 <main+0x50>
cmpl   $0x3,-0x8(%rbp)
je     11e0 <main+0x50>
mov    0x2e1f(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe2f(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
cmpl   $0x2,-0x8(%rbp)
jne    1207 <main+0x77>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe1f(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x18(%rbp)
jmp    121f <main+0x8f>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe04(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1241 <main+0xb1>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10a0 <perror@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
lea    -0x40(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x20,%esi
mov    $0x1,%edx
call   1040 <fread@plt>
cmp    $0x1,%eax
je     1287 <main+0xf7>
mov    0x2d78(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xda5(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
movzbl -0x40(%rbp),%eax
cmp    $0x80,%eax
jne    12be <main+0x12e>
movzbl -0x3f(%rbp),%eax
cmp    $0xa8,%eax
jne    12be <main+0x12e>
mov    -0x18(%rbp),%rdi
lea    -0x40(%rbp),%rsi
mov    -0x8(%rbp),%edx
mov    -0x10(%rbp),%rcx
call   1080 <chmem_fzx2@plt>
jmp    135e <main+0x1ce>
movzbl -0x40(%rbp),%eax
cmp    $0xa8,%eax
jne    12f5 <main+0x165>
movzbl -0x3f(%rbp),%eax
cmp    $0x80,%eax
jne    12f5 <main+0x165>
mov    -0x18(%rbp),%rdi
lea    -0x40(%rbp),%rsi
mov    -0x8(%rbp),%edx
mov    -0x10(%rbp),%rcx
call   1080 <chmem_fzx2@plt>
jmp    1359 <main+0x1c9>
lea    -0x40(%rbp),%rdi
lea    0xd2e(%rip),%rsi
mov    $0x4,%edx
call   1060 <memcmp@plt>
cmp    $0x0,%rax
jne    132d <main+0x19d>
mov    -0x18(%rbp),%rdi
lea    -0x40(%rbp),%rsi
mov    -0x8(%rbp),%edx
mov    -0x10(%rbp),%rcx
call   1030 <chmem_flat@plt>
jmp    1354 <main+0x1c4>
mov    0x2cac(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xcee(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
jmp    1359 <main+0x1c9>
jmp    135e <main+0x1ce>
mov    -0x18(%rbp),%rdi
call   1050 <fclose@plt>
xor    %edi,%edi
call   10b0 <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    11dd <main+0x4d>
mov    %edi,%ebp
cmp    $0x2,%edi
mov    0x8(%rbx),%rdi
lea    0xe63(%rip),%rax
lea    0xe5e(%rip),%rsi
cmove  %rax,%rsi
call   1090 <fopen@plt>
test   %rax,%rax
jne    11ff <main+0x6f>
mov    0x8(%rbx),%rdi
call   10a0 <perror@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    0x2dfc(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xe10(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    %rax,%r14
mov    %rsp,%rdi
mov    $0x20,%esi
mov    $0x1,%edx
mov    %rax,%rcx
call   1040 <fread@plt>
cmp    $0x1,%eax
jne    1254 <main+0xc4>
mov    (%rsp),%cl
mov    0x1(%rsp),%al
cmp    $0x80,%cl
jne    122c <main+0x9c>
cmp    $0xa8,%al
je     1235 <main+0xa5>
cmp    $0xa8,%cl
jne    1269 <main+0xd9>
cmp    $0x80,%al
jne    1269 <main+0xd9>
mov    %rsp,%rsi
mov    %r14,%rdi
mov    %ebp,%edx
mov    %rbx,%rcx
call   1080 <chmem_fzx2@plt>
mov    %r14,%rdi
call   1050 <fclose@plt>
xor    %edi,%edi
call   10b0 <exit@plt>
mov    0x2d85(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xdb6(%rip),%rsi
jmp    11f0 <main+0x60>
lea    0xdbe(%rip),%rsi
mov    %rsp,%rdi
mov    $0x4,%edx
call   1060 <memcmp@plt>
test   %rax,%rax
jne    1294 <main+0x104>
mov    %rsp,%rsi
mov    %r14,%rdi
mov    %ebp,%edx
mov    %rbx,%rcx
call   1030 <chmem_flat@plt>
jmp    1245 <main+0xb5>
mov    0x2d45(%rip),%rax
mov    (%rax),%edi
mov    0x8(%rbx),%rdx
lea    0xd8b(%rip),%rsi
jmp    11f0 <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 = [5 x i8] c"bFLT\00"
@.str.5 = [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 %105
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 %104
86: ; preds = %75, %70
%87 = getelementptr inbounds [32 x i8], [32 x i8]* %7, i64 0, i64 0
%88 = call i64 @memcmp(i8* %87, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 4)
%89 = icmp eq i64 %88, 0
br i1 %89, label %90, label %96
90: ; preds = %86
%91 = load i32*, i32** %6
%92 = getelementptr inbounds [32 x i8], [32 x i8]* %7, i64 0, i64 0
%93 = load i32, i32* %4
%94 = load i8**, i8*** %5
%95 = call i32 @chmem_flat(i32* %91, i8* %92, i32 %93, i8** %94)
br label %103
96: ; preds = %86
%97 = load i32, i32* @stderr
%98 = load i8**, i8*** %5
%99 = getelementptr inbounds i8*, i8** %98, i64 1
%100 = load i8*, i8** %99
%101 = call i32 @fprintf(i32 %97, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.5, i64 0, i64 0), i8* %100)
%102 = call i32 @exit(i32 1)
unreachable
103: ; preds = %90
br label %104
104: ; preds = %103, %80
br label %105
105: ; preds = %104, %64
%106 = load i32*, i32** %6
%107 = call i32 @fclose(i32* %106)
%108 = 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 = [5 x i8] c"bFLT\00"
@.str.5 = [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 %39, label %41
39: ; preds = %32
%40 = call i32 @chmem_fzx2(i32* %17, i8* %4, i32 %0, i8** %1)
br label %58
41: ; preds = %32
%42 = icmp eq i8 %33, -88
%43 = icmp eq i8 %36, -128
%44 = select i1 %42, i1 %43, i1 false
br i1 %44, label %45, label %47
45: ; preds = %41
%46 = call i32 @chmem_fzx2(i32* %17, i8* %4, i32 %0, i8** %1)
br label %58
47: ; preds = %41
%48 = call i64 @memcmp(i8* %4, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 4)
%49 = icmp eq i64 %48, 0
br i1 %49, label %50, label %52
50: ; preds = %47
%51 = call i32 @chmem_flat(i32* %17, i8* %4, i32 %0, i8** %1)
br label %58
52: ; preds = %47
%53 = load i32, i32* @stderr
%54 = getelementptr inbounds i8*, i8** %1, i64 1
%55 = load i8*, i8** %54
%56 = call i32 @fprintf(i32 %53, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.5, i64 0, i64 0), i8* %55)
%57 = call i32 @exit(i32 1)
unreachable
58: ; preds = %45, %50, %39
%59 = call i32 @fclose(i32* %17)
%60 = call i32 @exit(i32 0)
unreachable
}