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

/* Variables and functions */
int EOF;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ fputc(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int sscanf(char *, char *, unsigned int *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ *stdin;
int /*<<< orphan*/ *stdout;
scalar_t__ strncmp(char *, char *, int);
int main(int argc, char *argv[]) {
  FILE *fin = stdin, *fout = stdout;
  uint16_t org = 0xC000;
  for (int arg = 1; arg < argc; arg++) {
    if (strncmp(argv[arg], "--org=", 6) == 0) {
      if (sscanf(argv[arg] + 6, "%u", (unsigned int *)&org) != 1) {
        fprintf(stderr, "maketap: --org without integer: %s\n", argv[arg] + 6);
        return (1);
      }
    } else if (argv[arg][0] == '<') {
      FILE *fp = fopen(argv[arg] + 1, "rb");
      if (fp)
        fin = fp;
      else {
        fprintf(stderr, "maketap: failed to open input file: %s\n",
                argv[arg] + 1);
        perror("fopen");
        return (1);
      }
    } else if (argv[arg][0] == '>') {
      FILE *fp = fopen(argv[arg] + 1, "wb");
      if (fp)
        fout = fp;
      else {
        fprintf(stderr, "maketap: failed to open output file: %s\n",
                argv[arg] + 1);
        perror("fopen");
        return (1);
      }
    } else {
      fprintf(stderr, "maketap: unrecognised argument (ignoring): %s\n",
              argv[arg]);
    }
  }
  uint8_t data[0x10000 - org];
  uint16_t pos = 0;
  int i;
  while ((i = fgetc(fin)) != EOF)
    data[pos++] = (unsigned char)i;
  uint16_t len = pos;
  fprintf(stderr, "maketap: org=%04x len=%04x\n", org, len);
  fputc(0x13, fout);
  fputc(0, fout);
  fputc(0, fout);
  fputc(3, fout);
  fputs("bin       ", fout);
  uint8_t cksum = 0x23 ^ 'b' ^ 'i' ^ 'n';
  fputc(len, fout);
  cksum ^= len;
  fputc(len >> 8, fout);
  cksum ^= (len >> 8);
  fputc(org, fout);
  cksum ^= org;
  fputc(org >> 8, fout);
  cksum ^= (org >> 8);
  fputc(0, fout);
  fputc(0x80, fout);
  cksum ^= 0x80;
  fputc(cksum, fout);
  fputc(len + 2, fout);
  fputc((len + 2) >> 8, fout);
  fputc(0xff, fout);
  cksum = 0xff;
  for (pos = 0; pos < len; pos++) {
    fputc(data[pos], fout);
    cksum ^= data[pos];
  }
  fputc(cksum, fout);
  fclose(fin);
  fclose(fout);
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e3b(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
mov    0x2e0d(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
movl   $0xc000,-0x24(%rbp)
movl   $0x1,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    13cc <main+0x23c>
mov    -0x10(%rbp),%rax
movslq -0x28(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xe11(%rip),%rsi
mov    $0x6,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    1264 <main+0xd4>
mov    -0x10(%rbp),%rax
movslq -0x28(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
add    $0x6,%rdi
lea    0xded(%rip),%rsi
lea    -0x24(%rbp),%rdx
call   1090 <sscanf@plt>
cmp    $0x1,%eax
je     125f <main+0xcf>
mov    0x2d9d(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
movslq -0x28(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
add    $0x6,%rdx
lea    0xdbe(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    15e0 <main+0x450>
jmp    13b9 <main+0x229>
mov    -0x10(%rbp),%rax
movslq -0x28(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movsbl (%rax),%eax
cmp    $0x3c,%eax
jne    12f8 <main+0x168>
mov    -0x10(%rbp),%rax
movslq -0x28(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
add    $0x1,%rdi
lea    0xd9b(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     12b4 <main+0x124>
mov    -0x30(%rbp),%rax
mov    %rax,-0x18(%rbp)
jmp    12f3 <main+0x163>
mov    0x2d15(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
movslq -0x28(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
add    $0x1,%rdx
lea    0xd5d(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
lea    0xd77(%rip),%rdi
call   10b0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    15e0 <main+0x450>
jmp    13b4 <main+0x224>
mov    -0x10(%rbp),%rax
movslq -0x28(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movsbl (%rax),%eax
cmp    $0x3e,%eax
jne    138c <main+0x1fc>
mov    -0x10(%rbp),%rax
movslq -0x28(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
add    $0x1,%rdi
lea    0xd38(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
je     1348 <main+0x1b8>
mov    -0x38(%rbp),%rax
mov    %rax,-0x20(%rbp)
jmp    1387 <main+0x1f7>
mov    0x2c81(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
movslq -0x28(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
add    $0x1,%rdx
lea    0xcfa(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
lea    0xce3(%rip),%rdi
call   10b0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    15e0 <main+0x450>
jmp    13af <main+0x21f>
mov    0x2c3d(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
movslq -0x28(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
lea    0xce3(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
jmp    13b4 <main+0x224>
jmp    13b9 <main+0x229>
jmp    13be <main+0x22e>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    11d0 <main+0x40>
mov    -0x24(%rbp),%ecx
mov    $0x10000,%eax
sub    %ecx,%eax
mov    %rsp,%rcx
mov    %rcx,-0x40(%rbp)
lea    0xf(,%rax,4),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x60(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x48(%rbp)
movl   $0x0,-0x4c(%rbp)
mov    -0x18(%rbp),%rdi
call   1060 <fgetc@plt>
mov    %eax,-0x50(%rbp)
mov    0x2bcc(%rip),%rcx
cmp    (%rcx),%eax
je     143c <main+0x2ac>
mov    -0x60(%rbp),%rax
mov    -0x50(%rbp),%ecx
movzbl %cl,%edx
mov    -0x4c(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x4c(%rbp)
movslq %ecx,%rcx
mov    %edx,(%rax,%rcx,4)
jmp    1401 <main+0x271>
mov    -0x4c(%rbp),%eax
mov    %eax,-0x54(%rbp)
mov    0x2b87(%rip),%rax
mov    (%rax),%edi
mov    -0x24(%rbp),%edx
mov    -0x54(%rbp),%ecx
lea    0xc62(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    -0x20(%rbp),%rsi
mov    $0x13,%edi
call   1070 <fputc@plt>
mov    -0x20(%rbp),%rsi
xor    %edi,%edi
call   1070 <fputc@plt>
mov    -0x20(%rbp),%rsi
xor    %edi,%edi
call   1070 <fputc@plt>
mov    -0x20(%rbp),%rsi
mov    $0x3,%edi
call   1070 <fputc@plt>
mov    -0x20(%rbp),%rsi
lea    0xc3a(%rip),%rdi
call   1050 <fputs@plt>
movl   $0x46,-0x58(%rbp)
mov    -0x54(%rbp),%edi
mov    -0x20(%rbp),%rsi
call   1070 <fputc@plt>
mov    -0x54(%rbp),%eax
xor    -0x58(%rbp),%eax
mov    %eax,-0x58(%rbp)
mov    -0x54(%rbp),%edi
sar    $0x8,%edi
mov    -0x20(%rbp),%rsi
call   1070 <fputc@plt>
mov    -0x54(%rbp),%eax
sar    $0x8,%eax
xor    -0x58(%rbp),%eax
mov    %eax,-0x58(%rbp)
mov    -0x24(%rbp),%edi
mov    -0x20(%rbp),%rsi
call   1070 <fputc@plt>
mov    -0x24(%rbp),%eax
xor    -0x58(%rbp),%eax
mov    %eax,-0x58(%rbp)
mov    -0x24(%rbp),%edi
sar    $0x8,%edi
mov    -0x20(%rbp),%rsi
call   1070 <fputc@plt>
mov    -0x24(%rbp),%eax
sar    $0x8,%eax
xor    -0x58(%rbp),%eax
mov    %eax,-0x58(%rbp)
mov    -0x20(%rbp),%rsi
xor    %edi,%edi
call   1070 <fputc@plt>
mov    -0x20(%rbp),%rsi
mov    $0x80,%edi
call   1070 <fputc@plt>
mov    -0x58(%rbp),%eax
xor    $0x80,%eax
mov    %eax,-0x58(%rbp)
mov    -0x58(%rbp),%edi
mov    -0x20(%rbp),%rsi
call   1070 <fputc@plt>
mov    -0x54(%rbp),%edi
add    $0x2,%edi
mov    -0x20(%rbp),%rsi
call   1070 <fputc@plt>
mov    -0x54(%rbp),%edi
add    $0x2,%edi
sar    $0x8,%edi
mov    -0x20(%rbp),%rsi
call   1070 <fputc@plt>
mov    -0x20(%rbp),%rsi
mov    $0xff,%edi
call   1070 <fputc@plt>
movl   $0xff,-0x58(%rbp)
movl   $0x0,-0x4c(%rbp)
mov    -0x4c(%rbp),%eax
cmp    -0x54(%rbp),%eax
jge    15b4 <main+0x424>
mov    -0x60(%rbp),%rax
movslq -0x4c(%rbp),%rcx
mov    (%rax,%rcx,4),%edi
mov    -0x20(%rbp),%rsi
call   1070 <fputc@plt>
mov    -0x60(%rbp),%rax
movslq -0x4c(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
xor    -0x58(%rbp),%eax
mov    %eax,-0x58(%rbp)
mov    -0x4c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4c(%rbp)
jmp    1575 <main+0x3e5>
mov    -0x58(%rbp),%edi
mov    -0x20(%rbp),%rsi
call   1070 <fputc@plt>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x40(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    0x2e40(%rip),%rax
mov    (%rax),%rbx
mov    0x2e16(%rip),%rax
mov    (%rax),%r12
movl   $0xc000,-0x2c(%rbp)
mov    $0x4000,%eax
cmp    $0x2,%edi
jl     12a7 <main+0x117>
mov    %rsi,%r14
mov    %rbx,%r15
mov    %edi,%r13d
mov    $0x1,%ebx
jmp    120d <main+0x7d>
nopw   0x0(%rax,%rax,1)
add    $0x6,%rdx
mov    %rdx,%rdi
lea    0xe19(%rip),%rsi
lea    -0x2c(%rbp),%rdx
call   1080 <sscanf@plt>
cmp    $0x1,%eax
jne    146a <main+0x2da>
add    $0x1,%rbx
cmp    %rbx,%r13
je     129c <main+0x10c>
mov    (%r14,%rbx,8),%rdi
lea    0xde8(%rip),%rsi
mov    $0x6,%edx
call   1030 <strncmp@plt>
mov    (%r14,%rbx,8),%rdx
test   %rax,%rax
je     11e0 <main+0x50>
movzbl (%rdx),%eax
cmp    $0x3e,%al
je     1260 <main+0xd0>
cmp    $0x3c,%al
jne    1280 <main+0xf0>
add    $0x1,%rdx
mov    %rdx,%rdi
lea    0xdea(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,%r15
test   %rax,%rax
jne    1200 <main+0x70>
jmp    1490 <main+0x300>
cs nopw 0x0(%rax,%rax,1)
add    $0x1,%rdx
mov    %rdx,%rdi
lea    0xdf1(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,%r12
test   %rax,%rax
jne    1200 <main+0x70>
jmp    14aa <main+0x31a>
mov    0x2d49(%rip),%rax
mov    (%rax),%edi
lea    0xdfb(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
jmp    1200 <main+0x70>
mov    $0x10000,%eax
sub    -0x2c(%rbp),%eax
mov    %r15,%rbx
mov    %rsp,-0x38(%rbp)
mov    %rsp,%r14
lea    0xf(,%rax,4),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r14
mov    %r14,%rsp
mov    %rbx,%rdi
call   1050 <fgetc@plt>
mov    0x2d11(%rip),%r13
xor    %r15d,%r15d
cmp    0x0(%r13),%eax
je     12f9 <main+0x169>
xor    %r15d,%r15d
nopl   0x0(%rax,%rax,1)
movzbl %al,%eax
mov    %eax,(%r14,%r15,4)
add    $0x1,%r15
mov    %rbx,%rdi
call   1050 <fgetc@plt>
cmp    0x0(%r13),%eax
jne    12e0 <main+0x150>
mov    %rbx,-0x40(%rbp)
mov    0x2ccc(%rip),%rax
mov    (%rax),%edi
mov    -0x2c(%rbp),%edx
lea    0xdaa(%rip),%rsi
mov    %r15d,%ecx
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    $0x13,%edi
mov    %r12,%rsi
call   1060 <fputc@plt>
xor    %edi,%edi
mov    %r12,%rsi
call   1060 <fputc@plt>
xor    %edi,%edi
mov    %r12,%rsi
call   1060 <fputc@plt>
mov    $0x3,%edi
mov    %r12,%rsi
call   1060 <fputc@plt>
lea    0xd87(%rip),%rdi
mov    $0xa,%esi
mov    $0x1,%edx
mov    %r12,%rcx
call   10b0 <fwrite@plt>
mov    %r15d,%edi
mov    %r12,%rsi
call   1060 <fputc@plt>
mov    %r15d,%r13d
shr    $0x8,%r13d
mov    %r13d,%edi
mov    %r12,%rsi
call   1060 <fputc@plt>
mov    -0x2c(%rbp),%edi
mov    %r12,%rsi
call   1060 <fputc@plt>
mov    -0x2c(%rbp),%edi
mov    %edi,-0x30(%rbp)
sar    $0x8,%edi
mov    %r12,%rsi
call   1060 <fputc@plt>
mov    -0x2c(%rbp),%ebx
sar    $0x8,%ebx
xor    %edi,%edi
mov    %r12,%rsi
call   1060 <fputc@plt>
mov    $0x80,%edi
mov    %r12,%rsi
call   1060 <fputc@plt>
xor    %r15d,%r13d
xor    -0x30(%rbp),%r13d
xor    %ebx,%r13d
xor    $0xc6,%r13d
mov    %r13d,%edi
mov    %r12,%rsi
call   1060 <fputc@plt>
lea    0x2(%r15),%ebx
mov    %ebx,%edi
mov    %r12,%rsi
call   1060 <fputc@plt>
shr    $0x8,%ebx
mov    %ebx,%edi
mov    %r12,%rsi
call   1060 <fputc@plt>
mov    $0xff,%r13d
mov    $0xff,%edi
mov    %r12,%rsi
call   1060 <fputc@plt>
test   %r15d,%r15d
je     1439 <main+0x2a9>
mov    %r15d,%r15d
mov    $0xff,%r13d
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    (%r14,%rbx,4),%edi
mov    %r12,%rsi
call   1060 <fputc@plt>
xor    (%r14,%rbx,4),%r13d
add    $0x1,%rbx
cmp    %rbx,%r15
jne    1420 <main+0x290>
mov    %r13d,%edi
mov    %r12,%rsi
call   1060 <fputc@plt>
mov    -0x40(%rbp),%rdi
call   1040 <fclose@plt>
mov    %r12,%rdi
call   1040 <fclose@plt>
mov    -0x38(%rbp),%rsp
xor    %eax,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2b5f(%rip),%rax
mov    (%rax),%edi
mov    (%r14,%rbx,8),%rdx
add    $0x6,%rdx
lea    0xb88(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    $0x1,%eax
jmp    145b <main+0x2cb>
mov    0x2b39(%rip),%rax
mov    (%rax),%edi
mov    (%r14,%rbx,8),%rdx
add    $0x1,%rdx
lea    0xb89(%rip),%rsi
jmp    14c2 <main+0x332>
mov    0x2b1f(%rip),%rax
mov    (%rax),%edi
mov    (%r14,%rbx,8),%rdx
add    $0x1,%rdx
lea    0xba0(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
lea    0xb89(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x1,%eax
jmp    145b <main+0x2cb>

LLVM IR (-O0):
@stdin = global i32* null
@stdout = global i32* null
@.str = [7 x i8] c"--org=\00"
@.str.1 = [3 x i8] c"%u\00"
@stderr = global i32 0
@.str.2 = [36 x i8] c"maketap: --org without integer: %s\0A\00"
@.str.3 = [3 x i8] c"rb\00"
@.str.4 = [40 x i8] c"maketap: failed to open input file: %s\0A\00"
@.str.5 = [6 x i8] c"fopen\00"
@.str.6 = [3 x i8] c"wb\00"
@.str.7 = [41 x i8] c"maketap: failed to open output file: %s\0A\00"
@.str.8 = [47 x i8] c"maketap: unrecognised argument (ignoring): %s\0A\00"
@EOF = global i32 0
@.str.9 = [28 x i8] c"maketap: org=%04x len=%04x\0A\00"
@.str.10 = [11 x i8] c"bin \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 i32
%9 = alloca i32
%10 = alloca i32*
%11 = alloca i32*
%12 = alloca i8*
%13 = alloca i64
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%18 = load i32*, i32** @stdin
store i32* %18, i32** %6
%19 = load i32*, i32** @stdout
store i32* %19, i32** %7
store i32 49152, i32* %8
store i32 1, i32* %9
br label %20
20: ; preds = %128, %2
%21 = load i32, i32* %9
%22 = load i32, i32* %4
%23 = icmp slt i32 %21, %22
br i1 %23, label %24, label %131
24: ; preds = %20
%25 = load i8**, i8*** %5
%26 = load i32, i32* %9
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i8*, i8** %25, i64 %27
%29 = load i8*, i8** %28
%30 = call i64 @strncmp(i8* %29, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 6)
%31 = icmp eq i64 %30, 0
br i1 %31, label %32, label %51
32: ; preds = %24
%33 = load i8**, i8*** %5
%34 = load i32, i32* %9
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i8*, i8** %33, i64 %35
%37 = load i8*, i8** %36
%38 = getelementptr inbounds i8, i8* %37, i64 6
%39 = call i32 @sscanf(i8* %38, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %8)
%40 = icmp ne i32 %39, 1
br i1 %40, label %41, label %50
41: ; preds = %32
%42 = load i32, i32* @stderr
%43 = load i8**, i8*** %5
%44 = load i32, i32* %9
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds i8*, i8** %43, i64 %45
%47 = load i8*, i8** %46
%48 = getelementptr inbounds i8, i8* %47, i64 6
%49 = call i32 (i32, i8*, ...) @fprintf(i32 %42, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0), i8* %48)
store i32 1, i32* %3
br label %243
50: ; preds = %32
br label %127
51: ; preds = %24
%52 = load i8**, i8*** %5
%53 = load i32, i32* %9
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds i8*, i8** %52, i64 %54
%56 = load i8*, i8** %55
%57 = getelementptr inbounds i8, i8* %56, i64 0
%58 = load i8, i8* %57
%59 = sext i8 %58 to i32
%60 = icmp eq i32 %59, 60
br i1 %60, label %61, label %84
61: ; preds = %51
%62 = load i8**, i8*** %5
%63 = load i32, i32* %9
%64 = sext i32 %63 to i64
%65 = getelementptr inbounds i8*, i8** %62, i64 %64
%66 = load i8*, i8** %65
%67 = getelementptr inbounds i8, i8* %66, i64 1
%68 = call i32* @fopen(i8* %67, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
store i32* %68, i32** %10
%69 = load i32*, i32** %10
%70 = icmp ne i32* %69, null
br i1 %70, label %71, label %73
71: ; preds = %61
%72 = load i32*, i32** %10
store i32* %72, i32** %6
br label %83
73: ; preds = %61
%74 = load i32, i32* @stderr
%75 = load i8**, i8*** %5
%76 = load i32, i32* %9
%77 = sext i32 %76 to i64
%78 = getelementptr inbounds i8*, i8** %75, i64 %77
%79 = load i8*, i8** %78
%80 = getelementptr inbounds i8, i8* %79, i64 1
%81 = call i32 (i32, i8*, ...) @fprintf(i32 %74, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.4, i64 0, i64 0), i8* %80)
%82 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
store i32 1, i32* %3
br label %243
83: ; preds = %71
br label %126
84: ; preds = %51
%85 = load i8**, i8*** %5
%86 = load i32, i32* %9
%87 = sext i32 %86 to i64
%88 = getelementptr inbounds i8*, i8** %85, i64 %87
%89 = load i8*, i8** %88
%90 = getelementptr inbounds i8, i8* %89, i64 0
%91 = load i8, i8* %90
%92 = sext i8 %91 to i32
%93 = icmp eq i32 %92, 62
br i1 %93, label %94, label %117
94: ; preds = %84
%95 = load i8**, i8*** %5
%96 = load i32, i32* %9
%97 = sext i32 %96 to i64
%98 = getelementptr inbounds i8*, i8** %95, i64 %97
%99 = load i8*, i8** %98
%100 = getelementptr inbounds i8, i8* %99, i64 1
%101 = call i32* @fopen(i8* %100, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0))
store i32* %101, i32** %11
%102 = load i32*, i32** %11
%103 = icmp ne i32* %102, null
br i1 %103, label %104, label %106
104: ; preds = %94
%105 = load i32*, i32** %11
store i32* %105, i32** %7
br label %116
106: ; preds = %94
%107 = load i32, i32* @stderr
%108 = load i8**, i8*** %5
%109 = load i32, i32* %9
%110 = sext i32 %109 to i64
%111 = getelementptr inbounds i8*, i8** %108, i64 %110
%112 = load i8*, i8** %111
%113 = getelementptr inbounds i8, i8* %112, i64 1
%114 = call i32 (i32, i8*, ...) @fprintf(i32 %107, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.7, i64 0, i64 0), i8* %113)
%115 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
store i32 1, i32* %3
br label %243
116: ; preds = %104
br label %125
117: ; preds = %84
%118 = load i32, i32* @stderr
%119 = load i8**, i8*** %5
%120 = load i32, i32* %9
%121 = sext i32 %120 to i64
%122 = getelementptr inbounds i8*, i8** %119, i64 %121
%123 = load i8*, i8** %122
%124 = call i32 (i32, i8*, ...) @fprintf(i32 %118, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.8, i64 0, i64 0), i8* %123)
br label %125
125: ; preds = %117, %116
br label %126
126: ; preds = %125, %83
br label %127
127: ; preds = %126, %50
br label %128
128: ; preds = %127
%129 = load i32, i32* %9
%130 = add nsw i32 %129, 1
store i32 %130, i32* %9
br label %20
131: ; preds = %20
%132 = load i32, i32* %8
%133 = sub nsw i32 65536, %132
%134 = zext i32 %133 to i64
%135 = call i8* @llvm.stacksave()
store i8* %135, i8** %12
%136 = alloca i32, i64 %134
store i64 %134, i64* %13
store i32 0, i32* %14
br label %137
137: ; preds = %142, %131
%138 = load i32*, i32** %6
%139 = call i32 @fgetc(i32* %138)
store i32 %139, i32* %15
%140 = load i32, i32* @EOF
%141 = icmp ne i32 %139, %140
br i1 %141, label %142, label %150
142: ; preds = %137
%143 = load i32, i32* %15
%144 = trunc i32 %143 to i8
%145 = zext i8 %144 to i32
%146 = load i32, i32* %14
%147 = add nsw i32 %146, 1
store i32 %147, i32* %14
%148 = sext i32 %146 to i64
%149 = getelementptr inbounds i32, i32* %136, i64 %148
store i32 %145, i32* %149
br label %137
150: ; preds = %137
%151 = load i32, i32* %14
store i32 %151, i32* %16
%152 = load i32, i32* @stderr
%153 = load i32, i32* %8
%154 = load i32, i32* %16
%155 = call i32 (i32, i8*, ...) @fprintf(i32 %152, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.9, i64 0, i64 0), i32 %153, i32 %154)
%156 = load i32*, i32** %7
%157 = call i32 @fputc(i32 19, i32* %156)
%158 = load i32*, i32** %7
%159 = call i32 @fputc(i32 0, i32* %158)
%160 = load i32*, i32** %7
%161 = call i32 @fputc(i32 0, i32* %160)
%162 = load i32*, i32** %7
%163 = call i32 @fputc(i32 3, i32* %162)
%164 = load i32*, i32** %7
%165 = call i32 @fputs(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.10, i64 0, i64 0), i32* %164)
store i32 70, i32* %17
%166 = load i32, i32* %16
%167 = load i32*, i32** %7
%168 = call i32 @fputc(i32 %166, i32* %167)
%169 = load i32, i32* %16
%170 = load i32, i32* %17
%171 = xor i32 %170, %169
store i32 %171, i32* %17
%172 = load i32, i32* %16
%173 = ashr i32 %172, 8
%174 = load i32*, i32** %7
%175 = call i32 @fputc(i32 %173, i32* %174)
%176 = load i32, i32* %16
%177 = ashr i32 %176, 8
%178 = load i32, i32* %17
%179 = xor i32 %178, %177
store i32 %179, i32* %17
%180 = load i32, i32* %8
%181 = load i32*, i32** %7
%182 = call i32 @fputc(i32 %180, i32* %181)
%183 = load i32, i32* %8
%184 = load i32, i32* %17
%185 = xor i32 %184, %183
store i32 %185, i32* %17
%186 = load i32, i32* %8
%187 = ashr i32 %186, 8
%188 = load i32*, i32** %7
%189 = call i32 @fputc(i32 %187, i32* %188)
%190 = load i32, i32* %8
%191 = ashr i32 %190, 8
%192 = load i32, i32* %17
%193 = xor i32 %192, %191
store i32 %193, i32* %17
%194 = load i32*, i32** %7
%195 = call i32 @fputc(i32 0, i32* %194)
%196 = load i32*, i32** %7
%197 = call i32 @fputc(i32 128, i32* %196)
%198 = load i32, i32* %17
%199 = xor i32 %198, 128
store i32 %199, i32* %17
%200 = load i32, i32* %17
%201 = load i32*, i32** %7
%202 = call i32 @fputc(i32 %200, i32* %201)
%203 = load i32, i32* %16
%204 = add nsw i32 %203, 2
%205 = load i32*, i32** %7
%206 = call i32 @fputc(i32 %204, i32* %205)
%207 = load i32, i32* %16
%208 = add nsw i32 %207, 2
%209 = ashr i32 %208, 8
%210 = load i32*, i32** %7
%211 = call i32 @fputc(i32 %209, i32* %210)
%212 = load i32*, i32** %7
%213 = call i32 @fputc(i32 255, i32* %212)
store i32 255, i32* %17
store i32 0, i32* %14
br label %214
214: ; preds = %231, %150
%215 = load i32, i32* %14
%216 = load i32, i32* %16
%217 = icmp slt i32 %215, %216
br i1 %217, label %218, label %234
218: ; preds = %214
%219 = load i32, i32* %14
%220 = sext i32 %219 to i64
%221 = getelementptr inbounds i32, i32* %136, i64 %220
%222 = load i32, i32* %221
%223 = load i32*, i32** %7
%224 = call i32 @fputc(i32 %222, i32* %223)
%225 = load i32, i32* %14
%226 = sext i32 %225 to i64
%227 = getelementptr inbounds i32, i32* %136, i64 %226
%228 = load i32, i32* %227
%229 = load i32, i32* %17
%230 = xor i32 %229, %228
store i32 %230, i32* %17
br label %231
231: ; preds = %218
%232 = load i32, i32* %14
%233 = add nsw i32 %232, 1
store i32 %233, i32* %14
br label %214
234: ; preds = %214
%235 = load i32, i32* %17
%236 = load i32*, i32** %7
%237 = call i32 @fputc(i32 %235, i32* %236)
%238 = load i32*, i32** %6
%239 = call i32 @fclose(i32* %238)
%240 = load i32*, i32** %7
%241 = call i32 @fclose(i32* %240)
store i32 0, i32* %3
%242 = load i8*, i8** %12
br label %243
243: ; preds = %234, %106, %73, %41
%244 = load i32, i32* %3
ret i32 %244
}

LLVM IR (-O2):
@stdin = global i32* null
@stdout = global i32* null
@.str = [7 x i8] c"--org=\00"
@.str.1 = [3 x i8] c"%u\00"
@stderr = global i32 0
@.str.2 = [36 x i8] c"maketap: --org without integer: %s\0A\00"
@.str.3 = [3 x i8] c"rb\00"
@.str.4 = [40 x i8] c"maketap: failed to open input file: %s\0A\00"
@.str.5 = [6 x i8] c"fopen\00"
@.str.6 = [3 x i8] c"wb\00"
@.str.7 = [41 x i8] c"maketap: failed to open output file: %s\0A\00"
@.str.8 = [47 x i8] c"maketap: unrecognised argument (ignoring): %s\0A\00"
@EOF = global i32 0
@.str.9 = [28 x i8] c"maketap: org=%04x len=%04x\0A\00"
@.str.10 = [11 x i8] c"bin \00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = load i32*, i32** @stdin
%5 = load i32*, i32** @stdout
%6 = bitcast i32* %3 to i8*
store i32 49152, i32* %3
%7 = icmp sgt i32 %0, 1
br i1 %7, label %8, label %65
8: ; preds = %2
%9 = zext i32 %0 to i64
br label %10
10: ; preds = %8, %56
%11 = phi i64 [ 1, %8 ], [ %59, %56 ]
%12 = phi i32* [ %4, %8 ], [ %58, %56 ]
%13 = phi i32* [ %5, %8 ], [ %57, %56 ]
%14 = getelementptr inbounds i8*, i8** %1, i64 %11
%15 = load i8*, i8** %14
%16 = call i64 @strncmp(i8* %15, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 6)
%17 = icmp eq i64 %16, 0
%18 = load i8*, i8** %14
br i1 %17, label %19, label %29
19: ; preds = %10
%20 = getelementptr inbounds i8, i8* %18, i64 6
%21 = call i32 @sscanf(i8* %20, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %3)
%22 = icmp eq i32 %21, 1
br i1 %22, label %56, label %23
23: ; preds = %19
%24 = getelementptr inbounds i8*, i8** %1, i64 %11
%25 = load i32, i32* @stderr
%26 = load i8*, i8** %24
%27 = getelementptr inbounds i8, i8* %26, i64 6
%28 = call i32 (i32, i8*, ...) @fprintf(i32 %25, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0), i8* %27)
br label %135
29: ; preds = %10
%30 = load i8, i8* %18
switch i8 %30, label %53 [
i8 60, label %31
i8 62, label %42
]
31: ; preds = %29
%32 = getelementptr inbounds i8, i8* %18, i64 1
%33 = call i32* @fopen(i8* %32, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%34 = icmp eq i32* %33, null
br i1 %34, label %35, label %56
35: ; preds = %31
%36 = getelementptr inbounds i8*, i8** %1, i64 %11
%37 = load i32, i32* @stderr
%38 = load i8*, i8** %36
%39 = getelementptr inbounds i8, i8* %38, i64 1
%40 = call i32 (i32, i8*, ...) @fprintf(i32 %37, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.4, i64 0, i64 0), i8* %39)
%41 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
br label %135
42: ; preds = %29
%43 = getelementptr inbounds i8, i8* %18, i64 1
%44 = call i32* @fopen(i8* %43, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0))
%45 = icmp eq i32* %44, null
br i1 %45, label %46, label %56
46: ; preds = %42
%47 = getelementptr inbounds i8*, i8** %1, i64 %11
%48 = load i32, i32* @stderr
%49 = load i8*, i8** %47
%50 = getelementptr inbounds i8, i8* %49, i64 1
%51 = call i32 (i32, i8*, ...) @fprintf(i32 %48, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.7, i64 0, i64 0), i8* %50)
%52 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
br label %135
53: ; preds = %29
%54 = load i32, i32* @stderr
%55 = call i32 (i32, i8*, ...) @fprintf(i32 %54, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.8, i64 0, i64 0), i8* %18)
br label %56
56: ; preds = %42, %31, %19, %53
%57 = phi i32* [ %13, %19 ], [ %13, %53 ], [ %13, %31 ], [ %44, %42 ]
%58 = phi i32* [ %12, %19 ], [ %12, %53 ], [ %33, %31 ], [ %12, %42 ]
%59 = add nuw nsw i64 %11, 1
%60 = icmp eq i64 %59, %9
br i1 %60, label %61, label %10
61: ; preds = %56
%62 = load i32, i32* %3
%63 = sub i32 65536, %62
%64 = zext i32 %63 to i64
br label %65
65: ; preds = %61, %2
%66 = phi i64 [ 16384, %2 ], [ %64, %61 ]
%67 = phi i32* [ %5, %2 ], [ %57, %61 ]
%68 = phi i32* [ %4, %2 ], [ %58, %61 ]
%69 = call i8* @llvm.stacksave()
%70 = alloca i32, i64 %66
%71 = call i32 @fgetc(i32* %68)
%72 = load i32, i32* @EOF
%73 = icmp eq i32 %71, %72
br i1 %73, label %85, label %74
74: ; preds = %65, %74
%75 = phi i64 [ %78, %74 ], [ 0, %65 ]
%76 = phi i32 [ %80, %74 ], [ %71, %65 ]
%77 = and i32 %76, 255
%78 = add nuw i64 %75, 1
%79 = getelementptr inbounds i32, i32* %70, i64 %75
store i32 %77, i32* %79
%80 = call i32 @fgetc(i32* %68)
%81 = load i32, i32* @EOF
%82 = icmp eq i32 %80, %81
br i1 %82, label %83, label %74
83: ; preds = %74
%84 = trunc i64 %78 to i32
br label %85
85: ; preds = %83, %65
%86 = phi i32 [ 0, %65 ], [ %84, %83 ]
%87 = load i32, i32* @stderr
%88 = load i32, i32* %3
%89 = call i32 (i32, i8*, ...) @fprintf(i32 %87, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.9, i64 0, i64 0), i32 %88, i32 %86)
%90 = call i32 @fputc(i32 19, i32* %67)
%91 = call i32 @fputc(i32 0, i32* %67)
%92 = call i32 @fputc(i32 0, i32* %67)
%93 = call i32 @fputc(i32 3, i32* %67)
%94 = call i64 @fwrite(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.10, i64 0, i64 0), i64 10, i64 1, i32* %67)
%95 = call i32 @fputc(i32 %86, i32* %67)
%96 = lshr i32 %86, 8
%97 = call i32 @fputc(i32 %96, i32* %67)
%98 = load i32, i32* %3
%99 = call i32 @fputc(i32 %98, i32* %67)
%100 = load i32, i32* %3
%101 = ashr i32 %100, 8
%102 = call i32 @fputc(i32 %101, i32* %67)
%103 = load i32, i32* %3
%104 = ashr i32 %103, 8
%105 = call i32 @fputc(i32 0, i32* %67)
%106 = call i32 @fputc(i32 128, i32* %67)
%107 = xor i32 %86, %96
%108 = xor i32 %107, %100
%109 = xor i32 %108, %104
%110 = xor i32 %109, 198
%111 = call i32 @fputc(i32 %110, i32* %67)
%112 = add nuw nsw i32 %86, 2
%113 = call i32 @fputc(i32 %112, i32* %67)
%114 = lshr i32 %112, 8
%115 = call i32 @fputc(i32 %114, i32* %67)
%116 = call i32 @fputc(i32 255, i32* %67)
%117 = icmp eq i32 %86, 0
br i1 %117, label %130, label %118
118: ; preds = %85
%119 = zext i32 %86 to i64
br label %120
120: ; preds = %118, %120
%121 = phi i64 [ 0, %118 ], [ %128, %120 ]
%122 = phi i32 [ 255, %118 ], [ %127, %120 ]
%123 = getelementptr inbounds i32, i32* %70, i64 %121
%124 = load i32, i32* %123
%125 = call i32 @fputc(i32 %124, i32* %67)
%126 = load i32, i32* %123
%127 = xor i32 %126, %122
%128 = add nuw nsw i64 %121, 1
%129 = icmp eq i64 %128, %119
br i1 %129, label %130, label %120
130: ; preds = %120, %85
%131 = phi i32 [ 255, %85 ], [ %127, %120 ]
%132 = call i32 @fputc(i32 %131, i32* %67)
%133 = call i32 @fclose(i32* %68)
%134 = call i32 @fclose(i32* %67)
br label %135
135: ; preds = %46, %35, %23, %130
%136 = phi i32 [ 0, %130 ], [ 1, %23 ], [ 1, %35 ], [ 1, %46 ]
ret i32 %136
}