#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*/ SEEK_END;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ fputc(int, int /*<<< orphan*/ *);
scalar_t__ fseek(int /*<<< orphan*/ *, long, int /*<<< orphan*/);
int ftell(int /*<<< orphan*/ *);
int getc(int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ writeword(int, int /*<<< orphan*/ *);
int main(int argc, char *argv[]) {
  char name[11];
  FILE *fpin, *fpout;
  int c;
  int i;
  int len;
  if (argc != 3) {
    fprintf(stdout, "Usage: %s [binary file] [Sharp MZ .m12 file]\n", argv[0]);
    exit(1);
  }
  if ((fpin = fopen(argv[1], "rb")) == NULL) {
    printf("Can't open input file\n");
    exit(1);
  }
  if (fseek(fpin, 0, SEEK_END)) {
    printf("Couldn't determine size of file\n");
    fclose(fpin);
    exit(1);
  }
  len = ftell(fpin);
  fseek(fpin, 0L, SEEK_SET);
  if ((fpout = fopen(argv[2], "wb")) == NULL) {
    printf("Can't open output file\n");
    exit(1);
  }
  fputc(1, fpout);
  fputc('P', fpout);
  fputc('R', fpout);
  fputc('G', fpout);
  for (i = 0; i < 14; i++)
    fputc(13, fpout);
  writeword(len, fpout);
  writeword(4608, fpout);
  writeword(4608, fpout);
  for (i = 0; i < 104; i++)
    fputc(0, fpout);
  for (i = 0; i < len; i++) {
    c = getc(fpin);
    fputc(c, fpout);
  }
  fclose(fpin);
  fclose(fpout);
}


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   $0x3,-0x8(%rbp)
je     11e6 <main+0x46>
mov    0x2e09(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe29(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe39(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    121e <main+0x7e>
lea    0xe22(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    -0x28(%rbp),%rdi
mov    0x2dbf(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%esi
call   1090 <fseek@plt>
cmp    $0x0,%rax
je     125d <main+0xbd>
lea    0xe03(%rip),%rdi
call   1040 <printf@plt>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    -0x28(%rbp),%rdi
call   1080 <ftell@plt>
mov    %eax,-0x3c(%rbp)
mov    -0x28(%rbp),%rdi
mov    0x2d64(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%esi
call   1090 <fseek@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xddb(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
jne    12b7 <main+0x117>
lea    0xdc4(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    -0x30(%rbp),%rsi
mov    $0x1,%edi
call   1050 <fputc@plt>
mov    -0x30(%rbp),%rsi
mov    $0x50,%edi
call   1050 <fputc@plt>
mov    -0x30(%rbp),%rsi
mov    $0x52,%edi
call   1050 <fputc@plt>
mov    -0x30(%rbp),%rsi
mov    $0x47,%edi
call   1050 <fputc@plt>
movl   $0x0,-0x38(%rbp)
cmpl   $0xe,-0x38(%rbp)
jge    131c <main+0x17c>
mov    -0x30(%rbp),%rsi
mov    $0xd,%edi
call   1050 <fputc@plt>
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
jmp    12f6 <main+0x156>
mov    -0x3c(%rbp),%edi
mov    -0x30(%rbp),%rsi
call   1060 <writeword@plt>
mov    -0x30(%rbp),%rsi
mov    $0x1200,%edi
call   1060 <writeword@plt>
mov    -0x30(%rbp),%rsi
mov    $0x1200,%edi
call   1060 <writeword@plt>
movl   $0x0,-0x38(%rbp)
cmpl   $0x68,-0x38(%rbp)
jge    136e <main+0x1ce>
mov    -0x30(%rbp),%rsi
xor    %edi,%edi
call   1050 <fputc@plt>
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
jmp    134b <main+0x1ab>
movl   $0x0,-0x38(%rbp)
mov    -0x38(%rbp),%eax
cmp    -0x3c(%rbp),%eax
jge    13a7 <main+0x207>
mov    -0x28(%rbp),%rdi
call   10c0 <getc@plt>
mov    %eax,-0x34(%rbp)
mov    -0x34(%rbp),%edi
mov    -0x30(%rbp),%rsi
call   1050 <fputc@plt>
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
jmp    1375 <main+0x1d5>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x30(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
cmp    $0x3,%edi
jne    1394 <main+0x1f4>
mov    0x8(%rbx),%rdi
lea    0xe70(%rip),%rsi
call   10a0 <fopen@plt>
test   %rax,%rax
je     13b6 <main+0x216>
mov    %rax,%r14
mov    0x2e12(%rip),%rax
mov    (%rax),%edx
mov    %r14,%rdi
xor    %esi,%esi
call   1090 <fseek@plt>
test   %rax,%rax
jne    13bf <main+0x21f>
mov    %r14,%rdi
call   1080 <ftell@plt>
mov    %eax,%ebp
mov    0x2ddc(%rip),%rax
mov    (%rax),%edx
mov    %r14,%rdi
xor    %esi,%esi
call   1090 <fseek@plt>
mov    0x10(%rbx),%rdi
lea    0xe1e(%rip),%rsi
call   10a0 <fopen@plt>
test   %rax,%rax
je     13dd <main+0x23d>
mov    %rax,%r15
mov    $0x1,%edi
mov    %rax,%rsi
call   1050 <fputc@plt>
mov    $0x50,%edi
mov    %r15,%rsi
call   1050 <fputc@plt>
mov    $0x52,%edi
mov    %r15,%rsi
call   1050 <fputc@plt>
mov    $0x47,%edi
mov    %r15,%rsi
call   1050 <fputc@plt>
mov    $0xd,%edi
mov    %r15,%rsi
call   1050 <fputc@plt>
mov    $0xd,%edi
mov    %r15,%rsi
call   1050 <fputc@plt>
mov    $0xd,%edi
mov    %r15,%rsi
call   1050 <fputc@plt>
mov    $0xd,%edi
mov    %r15,%rsi
call   1050 <fputc@plt>
mov    $0xd,%edi
mov    %r15,%rsi
call   1050 <fputc@plt>
mov    $0xd,%edi
mov    %r15,%rsi
call   1050 <fputc@plt>
mov    $0xd,%edi
mov    %r15,%rsi
call   1050 <fputc@plt>
mov    $0xd,%edi
mov    %r15,%rsi
call   1050 <fputc@plt>
mov    $0xd,%edi
mov    %r15,%rsi
call   1050 <fputc@plt>
mov    $0xd,%edi
mov    %r15,%rsi
call   1050 <fputc@plt>
mov    $0xd,%edi
mov    %r15,%rsi
call   1050 <fputc@plt>
mov    $0xd,%edi
mov    %r15,%rsi
call   1050 <fputc@plt>
mov    $0xd,%edi
mov    %r15,%rsi
call   1050 <fputc@plt>
mov    $0xd,%edi
mov    %r15,%rsi
call   1050 <fputc@plt>
mov    %ebp,%edi
mov    %r15,%rsi
call   1060 <writeword@plt>
mov    $0x1200,%edi
mov    %r15,%rsi
call   1060 <writeword@plt>
mov    $0x1200,%edi
mov    %r15,%rsi
call   1060 <writeword@plt>
mov    $0x68,%ebx
nopw   0x0(%rax,%rax,1)
xor    %edi,%edi
mov    %r15,%rsi
call   1050 <fputc@plt>
add    $0xffffffff,%ebx
jne    1340 <main+0x1a0>
test   %ebp,%ebp
jle    1377 <main+0x1d7>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r14,%rdi
call   10c0 <getc@plt>
mov    %eax,%edi
mov    %r15,%rsi
call   1050 <fputc@plt>
add    $0xffffffff,%ebp
jne    1360 <main+0x1c0>
mov    %r14,%rdi
call   1040 <fclose@plt>
mov    %r15,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2c35(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xc59(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
lea    0xcae(%rip),%rdi
jmp    13e4 <main+0x244>
lea    0xc85(%rip),%rdi
call   1030 <puts@plt>
mov    %r14,%rdi
call   1040 <fclose@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
lea    0xc50(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
@stdout = global i32 0
@.str = [46 x i8] c"Usage: %s [binary file] [Sharp MZ .m12 file]\0A\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [23 x i8] c"Can't open input file\0A\00"
@SEEK_END = global i32 0
@.str.3 = [33 x i8] c"Couldn't determine size of file\0A\00"
@SEEK_SET = global i32 0
@.str.4 = [3 x i8] c"wb\00"
@.str.5 = [24 x i8] c"Can't open output file\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [11 x i8]
%7 = alloca i32*
%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
%12 = load i32, i32* %4
%13 = icmp ne i32 %12, 3
br i1 %13, label %14, label %21
14: ; preds = %2
%15 = load i32, i32* @stdout
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 0
%18 = load i8*, i8** %17
%19 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0), i8* %18)
%20 = call i32 @exit(i32 1)
unreachable
21: ; preds = %2
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 1
%24 = load i8*, i8** %23
%25 = call i32* @fopen(i8* %24, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %25, i32** %7
%26 = icmp eq i32* %25, null
br i1 %26, label %27, label %30
27: ; preds = %21
%28 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
%29 = call i32 @exit(i32 1)
unreachable
30: ; preds = %21
%31 = load i32*, i32** %7
%32 = load i32, i32* @SEEK_END
%33 = call i64 @fseek(i32* %31, i64 0, i32 %32)
%34 = icmp ne i64 %33, 0
br i1 %34, label %35, label %40
35: ; preds = %30
%36 = call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0))
%37 = load i32*, i32** %7
%38 = call i32 @fclose(i32* %37)
%39 = call i32 @exit(i32 1)
unreachable
40: ; preds = %30
%41 = load i32*, i32** %7
%42 = call i32 @ftell(i32* %41)
store i32 %42, i32* %11
%43 = load i32*, i32** %7
%44 = load i32, i32* @SEEK_SET
%45 = call i64 @fseek(i32* %43, i64 0, i32 %44)
%46 = load i8**, i8*** %5
%47 = getelementptr inbounds i8*, i8** %46, i64 2
%48 = load i8*, i8** %47
%49 = call i32* @fopen(i8* %48, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
store i32* %49, i32** %8
%50 = icmp eq i32* %49, null
br i1 %50, label %51, label %54
51: ; preds = %40
%52 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0))
%53 = call i32 @exit(i32 1)
unreachable
54: ; preds = %40
%55 = load i32*, i32** %8
%56 = call i32 @fputc(i32 1, i32* %55)
%57 = load i32*, i32** %8
%58 = call i32 @fputc(i32 80, i32* %57)
%59 = load i32*, i32** %8
%60 = call i32 @fputc(i32 82, i32* %59)
%61 = load i32*, i32** %8
%62 = call i32 @fputc(i32 71, i32* %61)
store i32 0, i32* %10
br label %63
63: ; preds = %69, %54
%64 = load i32, i32* %10
%65 = icmp slt i32 %64, 14
br i1 %65, label %66, label %72
66: ; preds = %63
%67 = load i32*, i32** %8
%68 = call i32 @fputc(i32 13, i32* %67)
br label %69
69: ; preds = %66
%70 = load i32, i32* %10
%71 = add nsw i32 %70, 1
store i32 %71, i32* %10
br label %63
72: ; preds = %63
%73 = load i32, i32* %11
%74 = load i32*, i32** %8
%75 = call i32 @writeword(i32 %73, i32* %74)
%76 = load i32*, i32** %8
%77 = call i32 @writeword(i32 4608, i32* %76)
%78 = load i32*, i32** %8
%79 = call i32 @writeword(i32 4608, i32* %78)
store i32 0, i32* %10
br label %80
80: ; preds = %86, %72
%81 = load i32, i32* %10
%82 = icmp slt i32 %81, 104
br i1 %82, label %83, label %89
83: ; preds = %80
%84 = load i32*, i32** %8
%85 = call i32 @fputc(i32 0, i32* %84)
br label %86
86: ; preds = %83
%87 = load i32, i32* %10
%88 = add nsw i32 %87, 1
store i32 %88, i32* %10
br label %80
89: ; preds = %80
store i32 0, i32* %10
br label %90
90: ; preds = %100, %89
%91 = load i32, i32* %10
%92 = load i32, i32* %11
%93 = icmp slt i32 %91, %92
br i1 %93, label %94, label %103
94: ; preds = %90
%95 = load i32*, i32** %7
%96 = call i32 @getc(i32* %95)
store i32 %96, i32* %9
%97 = load i32, i32* %9
%98 = load i32*, i32** %8
%99 = call i32 @fputc(i32 %97, i32* %98)
br label %100
100: ; preds = %94
%101 = load i32, i32* %10
%102 = add nsw i32 %101, 1
store i32 %102, i32* %10
br label %90
103: ; preds = %90
%104 = load i32*, i32** %7
%105 = call i32 @fclose(i32* %104)
%106 = load i32*, i32** %8
%107 = call i32 @fclose(i32* %106)
%108 = load i32, i32* %3
ret i32 %108
}

LLVM IR (-O2):
@stdout = global i32 0
@.str = [46 x i8] c"Usage: %s [binary file] [Sharp MZ .m12 file]\0A\00"
@.str.1 = [3 x i8] c"rb\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
@.str.4 = [3 x i8] c"wb\00"
@str = [23 x i8] c"Can't open output file\00"
@str.6 = [32 x i8] c"Couldn't determine size of file\00"
@str.7 = [22 x i8] c"Can't open input file\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 3
br i1 %3, label %9, label %4
4: ; preds = %2
%5 = load i32, i32* @stdout
%6 = load i8*, i8** %1
%7 = tail call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0), i8* %6)
%8 = tail call i32 @exit(i32 1)
unreachable
9: ; preds = %2
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = tail call i32* @fopen(i8* %11, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%13 = icmp eq i32* %12, null
br i1 %13, label %14, label %17
14: ; preds = %9
%15 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str.7, i64 0, i64 0))
%16 = tail call i32 @exit(i32 1)
unreachable
17: ; preds = %9
%18 = load i32, i32* @SEEK_END
%19 = tail call i64 @fseek(i32* %12, i64 0, i32 %18)
%20 = icmp eq i64 %19, 0
br i1 %20, label %25, label %21
21: ; preds = %17
%22 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @str.6, i64 0, i64 0))
%23 = tail call i32 @fclose(i32* %12)
%24 = tail call i32 @exit(i32 1)
unreachable
25: ; preds = %17
%26 = tail call i32 @ftell(i32* %12)
%27 = load i32, i32* @SEEK_SET
%28 = tail call i64 @fseek(i32* %12, i64 0, i32 %27)
%29 = getelementptr inbounds i8*, i8** %1, i64 2
%30 = load i8*, i8** %29
%31 = tail call i32* @fopen(i8* %30, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%32 = icmp eq i32* %31, null
br i1 %32, label %33, label %36
33: ; preds = %25
%34 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str, i64 0, i64 0))
%35 = tail call i32 @exit(i32 1)
unreachable
36: ; preds = %25
%37 = tail call i32 @fputc(i32 1, i32* %31)
%38 = tail call i32 @fputc(i32 80, i32* %31)
%39 = tail call i32 @fputc(i32 82, i32* %31)
%40 = tail call i32 @fputc(i32 71, i32* %31)
%41 = tail call i32 @fputc(i32 13, i32* %31)
%42 = tail call i32 @fputc(i32 13, i32* %31)
%43 = tail call i32 @fputc(i32 13, i32* %31)
%44 = tail call i32 @fputc(i32 13, i32* %31)
%45 = tail call i32 @fputc(i32 13, i32* %31)
%46 = tail call i32 @fputc(i32 13, i32* %31)
%47 = tail call i32 @fputc(i32 13, i32* %31)
%48 = tail call i32 @fputc(i32 13, i32* %31)
%49 = tail call i32 @fputc(i32 13, i32* %31)
%50 = tail call i32 @fputc(i32 13, i32* %31)
%51 = tail call i32 @fputc(i32 13, i32* %31)
%52 = tail call i32 @fputc(i32 13, i32* %31)
%53 = tail call i32 @fputc(i32 13, i32* %31)
%54 = tail call i32 @fputc(i32 13, i32* %31)
%55 = tail call i32 @writeword(i32 %26, i32* %31)
%56 = tail call i32 @writeword(i32 4608, i32* %31)
%57 = tail call i32 @writeword(i32 4608, i32* %31)
br label %60
58: ; preds = %60
%59 = icmp sgt i32 %26, 0
br i1 %59, label %65, label %71
60: ; preds = %36, %60
%61 = phi i32 [ 0, %36 ], [ %63, %60 ]
%62 = tail call i32 @fputc(i32 0, i32* %31)
%63 = add nuw nsw i32 %61, 1
%64 = icmp eq i32 %63, 104
br i1 %64, label %58, label %60
65: ; preds = %58, %65
%66 = phi i32 [ %69, %65 ], [ 0, %58 ]
%67 = tail call i32 @getc(i32* %12)
%68 = tail call i32 @fputc(i32 %67, i32* %31)
%69 = add nuw nsw i32 %66, 1
%70 = icmp eq i32 %69, %26
br i1 %70, label %71, label %65
71: ; preds = %65, %58
%72 = tail call i32 @fclose(i32* %12)
%73 = tail call i32 @fclose(i32* %31)
ret i32 0
}