#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*/ 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*/ printf(char *, char *, unsigned int, unsigned int,
                          unsigned int, unsigned int, unsigned int);
int /*<<< orphan*/ stderr;
unsigned int z8016(unsigned char *);
int main(int argc, char *argv[]) {
  FILE *f;
  unsigned char buf[16];
  unsigned int cs, ds, bs, cm;
  while (*++argv) {
    f = fopen(*argv, "r");
    if (f == NULL) {
      perror(*argv);
      exit(1);
    }
    if (fread(buf, 16, 1, f) != 1) {
      perror("fread");
      exit(1);
    }
    fclose(f);
    if (buf[0] != 0xC3 || memcmp(buf + 3, "FZX1", 4)) {
      fprintf(stderr, "%s: not a valid Fuzix binary.\n", *argv);
      continue;
    }
    cm = z8016(buf + 7);
    cs = z8016(buf + 9) - 0x100;
    ds = z8016(buf + 11) - cs;
    bs = z8016(buf + 13);
    printf("%s: Code %d, Data %d, BSS %d, Chmem %d, Total %d\n", *argv, cs, ds,
           bs, cm, cs + ds + bs);
  }
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x8,%rcx
mov    %rcx,-0x10(%rbp)
cmpq   $0x0,0x8(%rax)
je     1304 <main+0x174>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
lea    0xe32(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11f8 <main+0x68>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   10a0 <perror@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
lea    -0x30(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x10,%esi
mov    $0x1,%edx
call   1030 <fread@plt>
cmp    $0x1,%eax
je     122e <main+0x9e>
lea    0xde3(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
movzbl -0x30(%rbp),%eax
cmp    $0xc3,%eax
jne    1269 <main+0xd9>
lea    -0x30(%rbp),%rdi
add    $0x3,%rdi
lea    0xdb3(%rip),%rsi
mov    $0x4,%edx
call   1070 <memcmp@plt>
cmp    $0x0,%rax
je     128a <main+0xfa>
mov    0x2d70(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xd8d(%rip),%rsi
call   1080 <fprintf@plt>
jmp    11a6 <main+0x16>
lea    -0x30(%rbp),%rdi
add    $0x7,%rdi
call   1050 <z8016@plt>
mov    %eax,-0x40(%rbp)
lea    -0x30(%rbp),%rdi
add    $0x9,%rdi
call   1050 <z8016@plt>
sub    $0x100,%eax
mov    %eax,-0x34(%rbp)
lea    -0x30(%rbp),%rdi
add    $0xb,%rdi
call   1050 <z8016@plt>
sub    -0x34(%rbp),%eax
mov    %eax,-0x38(%rbp)
lea    -0x30(%rbp),%rdi
add    $0xd,%rdi
call   1050 <z8016@plt>
mov    %eax,-0x3c(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
mov    -0x34(%rbp),%edx
mov    -0x38(%rbp),%ecx
mov    -0x3c(%rbp),%r8d
mov    -0x40(%rbp),%r9d
mov    -0x34(%rbp),%eax
add    -0x38(%rbp),%eax
add    -0x3c(%rbp),%eax
lea    0xd35(%rip),%rdi
mov    %eax,(%rsp)
call   1060 <printf@plt>
jmp    11a6 <main+0x16>
xor    %edi,%edi
call   10b0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    0x8(%rsi),%rdi
test   %rdi,%rdi
jne    11ae <main+0x1e>
xor    %edi,%edi
call   10b0 <exit@plt>
mov    %rsi,%rbx
add    $0x8,%rbx
lea    0x13(%rsp),%r14
lea    0xe3f(%rip),%r15
lea    0x10(%rsp),%r12
lea    0xe3b(%rip),%r13
jmp    11f5 <main+0x65>
nop
mov    0x2e09(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xe2a(%rip),%rsi
call   1080 <fprintf@plt>
mov    0x8(%rbx),%rdi
add    $0x8,%rbx
test   %rdi,%rdi
je     11a7 <main+0x17>
mov    %r15,%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     12c4 <main+0x134>
mov    %rax,%rbp
mov    %r12,%rdi
mov    $0x10,%esi
mov    $0x1,%edx
mov    %rax,%rcx
call   1030 <fread@plt>
cmp    $0x1,%eax
jne    12c9 <main+0x139>
mov    %rbp,%rdi
call   1040 <fclose@plt>
cmpb   $0xc3,0x10(%rsp)
jne    11d0 <main+0x40>
mov    %r14,%rdi
mov    %r13,%rsi
mov    $0x4,%edx
call   1070 <memcmp@plt>
test   %rax,%rax
jne    11d0 <main+0x40>
lea    0x17(%rsp),%rdi
call   1050 <z8016@plt>
mov    %eax,0x24(%rsp)
lea    0x19(%rsp),%rdi
call   1050 <z8016@plt>
lea    -0x100(%rax),%ebp
lea    0x1b(%rsp),%rdi
call   1050 <z8016@plt>
mov    %r13,%r14
mov    %eax,%r13d
mov    %r15,%r12
mov    %eax,%r15d
sub    %ebp,%r15d
lea    0x1d(%rsp),%rdi
call   1050 <z8016@plt>
mov    (%rbx),%rsi
add    %eax,%r13d
mov    %r13d,(%rsp)
mov    %r14,%r13
lea    0xd8c(%rip),%rdi
mov    %ebp,%edx
mov    %r15d,%ecx
mov    %r12,%r15
lea    0x10(%rsp),%r12
mov    %eax,%r8d
mov    0x24(%rsp),%r9d
lea    0x13(%rsp),%r14
call   1060 <printf@plt>
jmp    11e8 <main+0x58>
mov    (%rbx),%rdi
jmp    12d0 <main+0x140>
lea    0xd32(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [6 x i8] c"fread\00"
@.str.2 = [5 x i8] c"FZX1\00"
@stderr = global i32 0
@.str.3 = [31 x i8] c"%s: not a valid Fuzix binary.\0A\00"
@.str.4 = [50 x i8] c"%s: Code %d, Data %d, BSS %d, Chmem %d, Total %d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca [16 x i8]
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
br label %12
12: ; preds = %53, %48, %2
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i32 1
store i8** %14, i8*** %5
%15 = load i8*, i8** %14
%16 = icmp ne i8* %15, null
br i1 %16, label %17, label %81
17: ; preds = %12
%18 = load i8**, i8*** %5
%19 = load i8*, i8** %18
%20 = call i32* @fopen(i8* %19, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %20, i32** %6
%21 = load i32*, i32** %6
%22 = icmp eq i32* %21, null
br i1 %22, label %23, label %28
23: ; preds = %17
%24 = load i8**, i8*** %5
%25 = load i8*, i8** %24
%26 = call i32 @perror(i8* %25)
%27 = call i32 @exit(i32 1)
unreachable
28: ; preds = %17
%29 = getelementptr inbounds [16 x i8], [16 x i8]* %7, i64 0, i64 0
%30 = load i32*, i32** %6
%31 = call i32 @fread(i8* %29, i32 16, i32 1, i32* %30)
%32 = icmp ne i32 %31, 1
br i1 %32, label %33, label %36
33: ; preds = %28
%34 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%35 = call i32 @exit(i32 1)
unreachable
36: ; preds = %28
%37 = load i32*, i32** %6
%38 = call i32 @fclose(i32* %37)
%39 = getelementptr inbounds [16 x i8], [16 x i8]* %7, i64 0, i64 0
%40 = load i8, i8* %39
%41 = zext i8 %40 to i32
%42 = icmp ne i32 %41, 195
br i1 %42, label %48, label %43
43: ; preds = %36
%44 = getelementptr inbounds [16 x i8], [16 x i8]* %7, i64 0, i64 0
%45 = getelementptr inbounds i8, i8* %44, i64 3
%46 = call i64 @memcmp(i8* %45, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 4)
%47 = icmp ne i64 %46, 0
br i1 %47, label %48, label %53
48: ; preds = %43, %36
%49 = load i32, i32* @stderr
%50 = load i8**, i8*** %5
%51 = load i8*, i8** %50
%52 = call i32 @fprintf(i32 %49, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0), i8* %51)
br label %12
53: ; preds = %43
%54 = getelementptr inbounds [16 x i8], [16 x i8]* %7, i64 0, i64 0
%55 = getelementptr inbounds i8, i8* %54, i64 7
%56 = call i32 @z8016(i8* %55)
store i32 %56, i32* %11
%57 = getelementptr inbounds [16 x i8], [16 x i8]* %7, i64 0, i64 0
%58 = getelementptr inbounds i8, i8* %57, i64 9
%59 = call i32 @z8016(i8* %58)
%60 = sub i32 %59, 256
store i32 %60, i32* %8
%61 = getelementptr inbounds [16 x i8], [16 x i8]* %7, i64 0, i64 0
%62 = getelementptr inbounds i8, i8* %61, i64 11
%63 = call i32 @z8016(i8* %62)
%64 = load i32, i32* %8
%65 = sub i32 %63, %64
store i32 %65, i32* %9
%66 = getelementptr inbounds [16 x i8], [16 x i8]* %7, i64 0, i64 0
%67 = getelementptr inbounds i8, i8* %66, i64 13
%68 = call i32 @z8016(i8* %67)
store i32 %68, i32* %10
%69 = load i8**, i8*** %5
%70 = load i8*, i8** %69
%71 = load i32, i32* %8
%72 = load i32, i32* %9
%73 = load i32, i32* %10
%74 = load i32, i32* %11
%75 = load i32, i32* %8
%76 = load i32, i32* %9
%77 = add i32 %75, %76
%78 = load i32, i32* %10
%79 = add i32 %77, %78
%80 = call i32 @printf(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.4, i64 0, i64 0), i8* %70, i32 %71, i32 %72, i32 %73, i32 %74, i32 %79)
br label %12
81: ; preds = %12
%82 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [6 x i8] c"fread\00"
@.str.2 = [5 x i8] c"FZX1\00"
@stderr = global i32 0
@.str.3 = [31 x i8] c"%s: not a valid Fuzix binary.\0A\00"
@.str.4 = [50 x i8] c"%s: Code %d, Data %d, BSS %d, Chmem %d, Total %d\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [16 x i8]
%4 = getelementptr inbounds [16 x i8], [16 x i8]* %3, i64 0, i64 0
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = icmp eq i8* %6, null
br i1 %7, label %54, label %8
8: ; preds = %2
%9 = getelementptr inbounds [16 x i8], [16 x i8]* %3, i64 0, i64 3
%10 = getelementptr inbounds [16 x i8], [16 x i8]* %3, i64 0, i64 7
%11 = getelementptr inbounds [16 x i8], [16 x i8]* %3, i64 0, i64 9
%12 = getelementptr inbounds [16 x i8], [16 x i8]* %3, i64 0, i64 11
%13 = getelementptr inbounds [16 x i8], [16 x i8]* %3, i64 0, i64 13
br label %14
14: ; preds = %8, %40
%15 = phi i8* [ %6, %8 ], [ %42, %40 ]
%16 = phi i8** [ %5, %8 ], [ %41, %40 ]
%17 = call i32* @fopen(i8* %15, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%18 = icmp eq i32* %17, null
br i1 %18, label %19, label %23
19: ; preds = %14
%20 = load i8*, i8** %16
%21 = call i32 @perror(i8* %20)
%22 = call i32 @exit(i32 1)
unreachable
23: ; preds = %14
%24 = call i32 @fread(i8* %4, i32 16, i32 1, i32* %17)
%25 = icmp eq i32 %24, 1
br i1 %25, label %29, label %26
26: ; preds = %23
%27 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%28 = call i32 @exit(i32 1)
unreachable
29: ; preds = %23
%30 = call i32 @fclose(i32* %17)
%31 = load i8, i8* %4
%32 = icmp eq i8 %31, -61
br i1 %32, label %33, label %36
33: ; preds = %29
%34 = call i64 @memcmp(i8* %9, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 4)
%35 = icmp eq i64 %34, 0
br i1 %35, label %44, label %36
36: ; preds = %33, %29
%37 = load i32, i32* @stderr
%38 = load i8*, i8** %16
%39 = call i32 @fprintf(i32 %37, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0), i8* %38)
br label %40
40: ; preds = %36, %44
%41 = getelementptr inbounds i8*, i8** %16, i64 1
%42 = load i8*, i8** %41
%43 = icmp eq i8* %42, null
br i1 %43, label %54, label %14
44: ; preds = %33
%45 = call i32 @z8016(i8* %10)
%46 = call i32 @z8016(i8* %11)
%47 = add i32 %46, -256
%48 = call i32 @z8016(i8* %12)
%49 = sub i32 %48, %47
%50 = call i32 @z8016(i8* %13)
%51 = load i8*, i8** %16
%52 = add i32 %50, %48
%53 = call i32 @printf(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.4, i64 0, i64 0), i8* %51, i32 %47, i32 %49, i32 %50, i32 %45, i32 %52)
br label %40
54: ; preds = %40, %2
%55 = call i32 @exit(i32 0)
unreachable
}