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

/* Variables and functions */
int /*<<< orphan*/ SEEK_CUR;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int fread(unsigned char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int, int /*<<< orphan*/);
int /*<<< orphan*/ fwrite(unsigned char *, int, int, int /*<<< orphan*/ *);
int getopt(int, char **, char const *);
char *optarg;
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sprintf(char *, char *, char *);
int /*<<< orphan*/ stderr;
int strtoul(char *, int /*<<< orphan*/ *, int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  char szRomName[128];
  FILE *fpRom;
  unsigned char sector[0x8000];
  uint32_t cksum = 0, rom_cksum = 0, rom_delta = 0;
  uint32_t rc, i, test_cksum = 0, adj_cksum;
  uint32_t subst_found = 0;
  uint32_t update = 0, test_delta = 0, desired_ver = 0;
  int c;
  const char *options = "f:uhs:v:";
  int screwup = 0;
  int disable_cksum = 0;
  while ((c = getopt(argc, argv, options)) != -1) {
    switch (c) {
    case 'f':
      sprintf(szRomName, "%s", optarg);
      break;
    case 'u':
      update = 1;
      printf("Autoupdate enabled\n");
      break;
    case 'h':
      printf("FreeWPC Checksum Utility\n");
      printf("-f <filename>     Sets input filename\n");
      printf("-v <version>      Sets desired version number\n");
      printf("-u                Update mode (default: read-only)\n");
      printf("-d                Disable existing checksum verification\n");
      printf("-s <delta>        Screw up the ROM so checksum will fail\n");
      exit(0);
      break;
    case 's':
      printf("screwup enabled\n");
      screwup = strtoul(optarg, NULL, 0);
      break;
    case 'v':
      desired_ver = strtoul(optarg, NULL, 0);
      break;
    case 'd':
      disable_cksum = 1;
      break;
    }
  }
  fpRom = fopen(szRomName, "r+b");
  if (!fpRom) {
    fprintf(stderr, "Cannot open %s\n", szRomName);
    exit(1);
  }
  for (;;) {
    rc = fread(sector, 1, 0x8000, fpRom);
    if (feof(fpRom))
      break;
    if (rc < 0x8000) {
    }
    if (screwup)
      sector[1] = (sector[1] + screwup) & 0xFF;
    for (i = 0; i < 0x8000; i++)
      cksum += sector[i];
  }
  rom_cksum = sector[0xFFEE - 0x8000] * 256 + sector[0xFFEE - 0x8000 + 1];
  rom_delta = sector[0xFFEC - 0x8000] * 256 + sector[0xFFEC - 0x8000 + 1];
  cksum &= 0xFFFF;
  rom_cksum &= 0xFFFF;
  printf("Calculated checksum: %04XH (version %02XH)\n", cksum,
         ((cksum) % 256));
  printf("Stored checksum: %04XH (version %02XH)\n", rom_cksum,
         ((rom_cksum) % 256));
  printf("Store delta: %04XH\n", rom_delta);
  if (disable_cksum && (rom_delta != 0x00FF)) {
    printf("Disable checksum requested, modification required.\n");
    if (update == 1) {
      sector[0xFFEC - 0x8000] = ((0x00FF) / 256);
      sector[0xFFEC - 0x8000 + 1] = ((0x00FF) % 256);
      printf("ROM modified to disable checksum.\n");
    }
  } else if ((cksum != rom_cksum) ||
             (desired_ver && (desired_ver != ((rom_cksum) % 256)))) {
    printf("Figuring out how to correct checksum...\n");
    cksum -= (((rom_cksum) / 256) + ((rom_cksum) % 256));
    cksum &= 0xFFFF;
    cksum -= (((rom_delta) / 256) + ((rom_delta) % 256));
    cksum &= 0xFFFF;
    for (test_delta = 0; test_delta <= 0xFFFF; test_delta++) {
      if (test_delta == 0x00FF)
        continue;
      for (test_cksum = desired_ver; test_cksum <= 0xFFFF;
           test_cksum += 0x0100) {
        adj_cksum = (cksum + ((test_cksum) / 256) + ((test_cksum) % 256) +
                     ((test_delta) / 256) + ((test_delta) % 256)) &
                    0xFFFF;
        if (adj_cksum == test_cksum) {
          printf("Solution: use checksum = %04XH, delta = %04XH\n", test_cksum,
                 test_delta);
          subst_found = 1;
          if (update == 1) {
            sector[0xFFEC - 0x8000] = ((test_delta) / 256);
            sector[0xFFEC - 0x8000 + 1] = ((test_delta) % 256);
            sector[0xFFEE - 0x8000] = ((test_cksum) / 256);
            sector[0xFFEE - 0x8000 + 1] = ((test_cksum) % 256);
            fseek(fpRom, -0x8000, SEEK_CUR);
            printf("Writing changes to ROM file...\n");
            fwrite(sector, 1, 0x8000, fpRom);
            printf("ROM file updated.\n");
          }
          break;
        }
      }
      if (subst_found)
        break;
    }
    if (subst_found == 0)
      printf("Error: can't figure out how to update checksum\n");
  } else {
    printf("Checksums match; no action required.\n");
  }
  fclose(fpRom);
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x8100,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x80a4(%rbp)
movl   $0x0,-0x80a8(%rbp)
movl   $0x0,-0x80ac(%rbp)
movl   $0x0,-0x80b8(%rbp)
movl   $0x0,-0x80c0(%rbp)
movl   $0x0,-0x80c4(%rbp)
movl   $0x0,-0x80c8(%rbp)
movl   $0x0,-0x80cc(%rbp)
lea    0xe1c(%rip),%rax
mov    %rax,-0x80d8(%rbp)
movl   $0x0,-0x80dc(%rbp)
movl   $0x0,-0x80e0(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x80d8(%rbp),%rdx
call   10a0 <getopt@plt>
mov    %eax,-0x80d0(%rbp)
cmp    $0xffffffff,%eax
je     1396 <main+0x1d6>
mov    -0x80d0(%rbp),%eax
add    $0xffffff9c,%eax
mov    %eax,%ecx
mov    %rcx,-0x80e8(%rbp)
sub    $0x12,%eax
ja     1391 <main+0x1d1>
mov    -0x80e8(%rbp),%rax
lea    0xd6a(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    -0x90(%rbp),%rdi
mov    0x2d4b(%rip),%rax
mov    (%rax),%rdx
lea    0xd9e(%rip),%rsi
call   10c0 <sprintf@plt>
jmp    1391 <main+0x1d1>
movl   $0x1,-0x80c4(%rbp)
lea    0xd86(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1391 <main+0x1d1>
lea    0xd87(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xd93(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xdac(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xdcd(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xdf3(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe1f(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
xor    %edi,%edi
call   10d0 <exit@plt>
lea    0xe44(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    0x2caa(%rip),%rax
mov    (%rax),%rdi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   10b0 <strtoul@plt>
mov    %eax,-0x80dc(%rbp)
jmp    1391 <main+0x1d1>
mov    0x2c8a(%rip),%rax
mov    (%rax),%rdi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   10b0 <strtoul@plt>
mov    %eax,-0x80cc(%rbp)
jmp    1391 <main+0x1d1>
movl   $0x1,-0x80e0(%rbp)
jmp    124b <main+0x8b>
lea    -0x90(%rbp),%rdi
lea    0xdf1(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x98(%rbp)
cmpq   $0x0,-0x98(%rbp)
jne    13e4 <main+0x224>
mov    0x2c0b(%rip),%rax
mov    (%rax),%edi
lea    -0x90(%rbp),%rdx
lea    0xdc4(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
jmp    13e9 <main+0x229>
lea    -0x80a0(%rbp),%rdi
mov    -0x98(%rbp),%rcx
mov    $0x1,%esi
mov    $0x8000,%edx
call   1030 <fread@plt>
mov    %eax,-0x80b0(%rbp)
mov    -0x98(%rbp),%rdi
call   1070 <feof@plt>
cmp    $0x0,%rax
je     1427 <main+0x267>
jmp    14af <main+0x2ef>
cmpl   $0x8000,-0x80b0(%rbp)
jge    143c <main+0x27c>
jmp    143c <main+0x27c>
cmpl   $0x0,-0x80dc(%rbp)
je     1461 <main+0x2a1>
movzbl -0x809f(%rbp),%eax
add    -0x80dc(%rbp),%eax
and    $0xff,%eax
mov    %al,-0x809f(%rbp)
movl   $0x0,-0x80b4(%rbp)
cmpl   $0x8000,-0x80b4(%rbp)
jge    14aa <main+0x2ea>
movslq -0x80b4(%rbp),%rax
movzbl -0x80a0(%rbp,%rax,1),%eax
ff
add    -0x80a4(%rbp),%eax
mov    %eax,-0x80a4(%rbp)
mov    -0x80b4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x80b4(%rbp)
jmp    146b <main+0x2ab>
jmp    13e9 <main+0x229>
movzbl -0xb2(%rbp),%eax
shl    $0x8,%eax
movzbl -0xb1(%rbp),%ecx
add    %ecx,%eax
mov    %eax,-0x80a8(%rbp)
movzbl -0xb4(%rbp),%eax
shl    $0x8,%eax
movzbl -0xb3(%rbp),%ecx
add    %ecx,%eax
mov    %eax,-0x80ac(%rbp)
mov    -0x80a4(%rbp),%eax
and    $0xffff,%eax
mov    %eax,-0x80a4(%rbp)
mov    -0x80a8(%rbp),%eax
and    $0xffff,%eax
mov    %eax,-0x80a8(%rbp)
mov    -0x80a4(%rbp),%esi
mov    -0x80a4(%rbp),%eax
mov    $0x100,%ecx
cltd
idiv   %ecx
lea    0xc8b(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x80a8(%rbp),%esi
mov    -0x80a8(%rbp),%eax
mov    $0x100,%ecx
cltd
idiv   %ecx
lea    0xc95(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x80ac(%rbp),%esi
lea    0xca9(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
cmpl   $0x0,-0x80e0(%rbp)
je     15b4 <main+0x3f4>
cmpl   $0xff,-0x80ac(%rbp)
je     15b4 <main+0x3f4>
lea    0xc92(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
cmpl   $0x1,-0x80c4(%rbp)
jne    15af <main+0x3ef>
movb   $0x0,-0xb4(%rbp)
movb   $0xff,-0xb3(%rbp)
lea    0xc9d(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    18bf <main+0x6ff>
mov    -0x80a4(%rbp),%eax
cmp    -0x80a8(%rbp),%eax
jne    15fb <main+0x43b>
cmpl   $0x0,-0x80cc(%rbp)
je     18ac <main+0x6ec>
mov    -0x80cc(%rbp),%eax
mov    %eax,-0x80ec(%rbp)
mov    -0x80a8(%rbp),%eax
mov    $0x100,%ecx
cltd
idiv   %ecx
mov    -0x80ec(%rbp),%eax
cmp    %edx,%eax
je     18ac <main+0x6ec>
lea    0xc66(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x80a8(%rbp),%eax
mov    $0x100,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x80a8(%rbp),%eax
mov    $0x100,%esi
cltd
idiv   %esi
add    %edx,%ecx
mov    -0x80a4(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x80a4(%rbp)
mov    -0x80a4(%rbp),%eax
and    $0xffff,%eax
mov    %eax,-0x80a4(%rbp)
mov    -0x80ac(%rbp),%eax
mov    $0x100,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x80ac(%rbp),%eax
mov    $0x100,%esi
cltd
idiv   %esi
add    %edx,%ecx
mov    -0x80a4(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x80a4(%rbp)
mov    -0x80a4(%rbp),%eax
and    $0xffff,%eax
mov    %eax,-0x80a4(%rbp)
movl   $0x0,-0x80c8(%rbp)
cmpl   $0xffff,-0x80c8(%rbp)
jg     188c <main+0x6cc>
cmpl   $0xff,-0x80c8(%rbp)
jne    16b6 <main+0x4f6>
jmp    1878 <main+0x6b8>
mov    -0x80cc(%rbp),%eax
mov    %eax,-0x80b8(%rbp)
cmpl   $0xffff,-0x80b8(%rbp)
jg     1861 <main+0x6a1>
mov    -0x80a4(%rbp),%eax
mov    %eax,-0x80fc(%rbp)
mov    -0x80b8(%rbp),%eax
mov    $0x100,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x80fc(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x80f8(%rbp)
mov    -0x80b8(%rbp),%eax
mov    $0x100,%ecx
cltd
idiv   %ecx
mov    -0x80f8(%rbp),%eax
add    %edx,%eax
mov    %eax,-0x80f4(%rbp)
mov    -0x80c8(%rbp),%eax
mov    $0x100,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x80f4(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x80f0(%rbp)
mov    -0x80c8(%rbp),%eax
mov    $0x100,%ecx
cltd
idiv   %ecx
mov    -0x80f0(%rbp),%eax
add    %edx,%eax
and    $0xffff,%eax
mov    %eax,-0x80bc(%rbp)
mov    -0x80bc(%rbp),%eax
cmp    -0x80b8(%rbp),%eax
jne    1846 <main+0x686>
mov    -0x80b8(%rbp),%esi
mov    -0x80c8(%rbp),%edx
lea    0xb15(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x1,-0x80c0(%rbp)
cmpl   $0x1,-0x80c4(%rbp)
jne    1841 <main+0x681>
mov    -0x80c8(%rbp),%eax
mov    $0x100,%ecx
cltd
idiv   %ecx
mov    %al,-0xb4(%rbp)
mov    -0x80c8(%rbp),%eax
mov    $0x100,%ecx
cltd
idiv   %ecx
mov    %dl,%al
mov    %al,-0xb3(%rbp)
mov    -0x80b8(%rbp),%eax
mov    $0x100,%ecx
cltd
idiv   %ecx
mov    %al,-0xb2(%rbp)
mov    -0x80b8(%rbp),%eax
mov    $0x100,%ecx
cltd
idiv   %ecx
mov    %dl,%al
mov    %al,-0xb1(%rbp)
mov    -0x98(%rbp),%rdi
mov    0x27e4(%rip),%rax
mov    (%rax),%edx
mov    $0xffff8000,%esi
call   1080 <fseek@plt>
lea    0xab1(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x80a0(%rbp),%rdi
mov    -0x98(%rbp),%rcx
mov    $0x1,%esi
mov    $0x8000,%edx
call   10e0 <fwrite@plt>
lea    0xaa6(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1861 <main+0x6a1>
jmp    184b <main+0x68b>
mov    -0x80b8(%rbp),%eax
add    $0x100,%eax
mov    %eax,-0x80b8(%rbp)
jmp    16c2 <main+0x502>
cmpl   $0x0,-0x80c0(%rbp)
je     1873 <main+0x6b3>
jmp    188c <main+0x6cc>
jmp    1878 <main+0x6b8>
mov    -0x80c8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x80c8(%rbp)
jmp    1691 <main+0x4d1>
cmpl   $0x0,-0x80c0(%rbp)
jne    18a7 <main+0x6e7>
lea    0xa53(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    18ba <main+0x6fa>
lea    0xa70(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    18bf <main+0x6ff>
mov    -0x98(%rbp),%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x8100,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x80b8,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
xor    %eax,%eax
mov    %rax,0x18(%rsp)
lea    0xe58(%rip),%r12
lea    0xe05(%rip),%r14
mov    0x2df6(%rip),%r15
lea    0x30(%rsp),%r13
movl   $0x0,0x10(%rsp)
movl   $0x0,0xc(%rsp)
movl   $0x0,0x14(%rsp)
jmp    1235 <main+0x65>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
cmp    $0xffffffff,%eax
je     12af <main+0xdf>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r12,%rdx
call   10c0 <getopt@plt>
lea    -0x64(%rax),%ecx
cmp    $0x12,%ecx
ja     1230 <main+0x60>
movslq (%r14,%rcx,4),%rax
add    %r14,%rax
jmp    *%rax
mov    (%r15),%rsi
mov    %r13,%rdi
call   1030 <strcpy@plt>
jmp    1235 <main+0x65>
movl   $0x1,0x14(%rsp)
jmp    1235 <main+0x65>
lea    0xf91(%rip),%rdi
call   1040 <puts@plt>
mov    (%r15),%rdi
xor    %esi,%esi
xor    %edx,%edx
call   10d0 <strtoul@plt>
mov    %eax,0xc(%rsp)
jmp    1235 <main+0x65>
lea    0x1095(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%al
mov    %rax,0x18(%rsp)
jmp    1235 <main+0x65>
mov    (%r15),%rdi
xor    %esi,%esi
xor    %edx,%edx
call   10d0 <strtoul@plt>
mov    %eax,0x10(%rsp)
jmp    1235 <main+0x65>
lea    0xd9f(%rip),%rsi
lea    0x30(%rsp),%rdi
call   10b0 <fopen@plt>
test   %rax,%rax
je     1642 <main+0x472>
mov    %rax,%r12
lea    0xb0(%rsp),%rdi
mov    $0x1,%esi
mov    $0x8000,%edx
mov    %rax,%rcx
call   1050 <fread@plt>
mov    %r12,%rdi
call   1090 <feof@plt>
xor    %r14d,%r14d
test   %rax,%rax
mov    0xc(%rsp),%ebx
jne    13d5 <main+0x205>
xor    %r14d,%r14d
pxor   %xmm4,%xmm4
lea    0xb0(%rsp),%rbp
nopl   (%rax)
test   %ebx,%ebx
je     131b <main+0x14b>
add    %bl,0xb1(%rsp)
movd   %r14d,%xmm1
pxor   %xmm0,%xmm0
xor    %eax,%eax
cs nopw 0x0(%rax,%rax,1)
movdqa 0xb0(%rsp,%rax,1),%xmm2
movd   0xb4(%rsp,%rax,1),%xmm3
punpcklbw %xmm4,%xmm2
punpcklwd %xmm4,%xmm2
paddd  %xmm1,%xmm2
punpcklbw %xmm4,%xmm3
punpcklwd %xmm4,%xmm3
paddd  %xmm0,%xmm3
movq   0xb8(%rsp,%rax,1),%xmm1
movd   0xbc(%rsp,%rax,1),%xmm0
punpcklbw %xmm4,%xmm1
punpcklwd %xmm4,%xmm1
paddd  %xmm2,%xmm1
punpcklbw %xmm4,%xmm0
punpcklwd %xmm4,%xmm0
paddd  %xmm3,%xmm0
add    $0x10,%rax
cmp    $0x8000,%rax
jne    1330 <main+0x160>
paddd  %xmm1,%xmm0
pshufd $0xee,%xmm0,%xmm1
paddd  %xmm0,%xmm1
pshufd $0x55,%xmm1,%xmm0
paddd  %xmm1,%xmm0
movd   %xmm0,%r14d
mov    %rbp,%rdi
mov    $0x1,%esi
mov    $0x8000,%edx
mov    %r12,%rcx
call   1050 <fread@plt>
mov    %r12,%rdi
call   1090 <feof@plt>
pxor   %xmm4,%xmm4
test   %rax,%rax
je     1310 <main+0x140>
movzbl 0x809e(%rsp),%r15d
mov    %r15d,%ebp
shl    $0x8,%ebp
movzbl 0x809f(%rsp),%r13d
or     %r13d,%ebp
movzbl 0x809c(%rsp),%ebx
mov    %ebx,0x28(%rsp)
shl    $0x8,%ebx
movzbl 0x809d(%rsp),%eax
mov    %eax,0x24(%rsp)
or     %eax,%ebx
movzwl %r14w,%esi
movzbl %r14b,%edx
lea    0xc4d(%rip),%rdi
mov    %esi,0x2c(%rsp)
xor    %eax,%eax
call   1070 <printf@plt>
lea    0xc67(%rip),%rdi
mov    %ebp,%esi
mov    %r13d,0xc(%rsp)
mov    %r13d,%edx
xor    %eax,%eax
call   1070 <printf@plt>
lea    0xc77(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1070 <printf@plt>
cmpl   $0x0,0x14(%rsp)
je     1489 <main+0x2b9>
cmp    $0xff,%ebx
je     1489 <main+0x2b9>
lea    0xd48(%rip),%rdi
call   1040 <puts@plt>
testb  $0x1,0x18(%rsp)
je     15d7 <main+0x407>
movb   $0x0,0x809c(%rsp)
lea    0xd5c(%rip),%rdi
jmp    15d2 <main+0x402>
cmp    %ebp,0x2c(%rsp)
jne    14af <main+0x2df>
lea    0xc6a(%rip),%rdi
mov    0x10(%rsp),%eax
test   %eax,%eax
mov    0xc(%rsp),%ebx
je     15d2 <main+0x402>
cmp    %ebx,%eax
jne    14b3 <main+0x2e3>
jmp    15d2 <main+0x402>
mov    0xc(%rsp),%ebx
lea    0xc6b(%rip),%rdi
call   1040 <puts@plt>
add    %ebx,%r15d
add    0x28(%rsp),%r15d
add    0x24(%rsp),%r15d
sub    %r15d,%r14d
xor    %r13d,%r13d
lea    0xc74(%rip),%rdi
mov    0x10(%rsp),%edx
jmp    14f1 <main+0x321>
nop
add    $0x1,%r13d
cmp    $0x10000,%r13d
je     15d2 <main+0x402>
cmp    $0xff,%r13d
je     14e0 <main+0x310>
cmp    $0xffff,%edx
jg     14e0 <main+0x310>
mov    %r13d,%r15d
shr    $0x8,%r15d
movzbl %r13b,%eax
add    %r14d,%eax
add    %r15d,%eax
mov    %edx,%esi
cs nopw 0x0(%rax,%rax,1)
nop
lea    0xff(%rsi),%ecx
test   %esi,%esi
cmovns %esi,%ecx
mov    %ecx,%ebx
sar    $0x8,%ebx
and    $0xffffff00,%ecx
mov    %esi,%ebp
sub    %ecx,%ebp
lea    (%rax,%rbx,1),%ecx
add    %ebp,%ecx
movzwl %cx,%ecx
cmp    %ecx,%esi
je     1558 <main+0x388>
lea    0x100(%rsi),%ecx
cmp    $0xff00,%esi
mov    %ecx,%esi
jl     1520 <main+0x350>
jmp    14e0 <main+0x310>
lea    0xb72(%rip),%rdi
mov    %r13d,%edx
xor    %eax,%eax
call   1070 <printf@plt>
testb  $0x1,0x18(%rsp)
je     15d7 <main+0x407>
mov    %r15b,0x809c(%rsp)
mov    %r13b,0x809d(%rsp)
mov    %bl,0x809e(%rsp)
mov    %bpl,0x809f(%rsp)
mov    0x2a4a(%rip),%rax
mov    (%rax),%edx
mov    %r12,%rdi
mov    $0xffff8000,%esi
call   10a0 <fseek@plt>
lea    0xbd0(%rip),%rdi
call   1040 <puts@plt>
lea    0xb0(%rsp),%rdi
mov    $0x1,%esi
mov    $0x8000,%edx
mov    %r12,%rcx
call   10f0 <fwrite@plt>
lea    0xbc9(%rip),%rdi
call   1040 <puts@plt>
mov    %r12,%rdi
call   1060 <fclose@plt>
xor    %eax,%eax
add    $0x80b8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xc18(%rip),%rdi
call   1040 <puts@plt>
lea    0xc25(%rip),%rdi
call   1040 <puts@plt>
lea    0xc3f(%rip),%rdi
call   1040 <puts@plt>
lea    0xc61(%rip),%rdi
call   1040 <puts@plt>
lea    0xc88(%rip),%rdi
call   1040 <puts@plt>
lea    0xcb5(%rip),%rdi
call   1040 <puts@plt>
xor    %edi,%edi
call   10e0 <exit@plt>
mov    0x2987(%rip),%rax
mov    (%rax),%edi
lea    0xa07(%rip),%rsi
lea    0x30(%rsp),%rdx
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>

LLVM IR (-O0):
@.str = [9 x i8] c"f:uhs:v:\00"
@.str.1 = [3 x i8] c"%s\00"
@optarg = global i8* null
@.str.2 = [20 x i8] c"Autoupdate enabled\0A\00"
@.str.3 = [26 x i8] c"FreeWPC Checksum Utility\0A\00"
@.str.4 = [39 x i8] c"-f <filename> Sets input filename\0A\00"
@.str.5 = [47 x i8] c"-v <version> Sets desired version number\0A\00"
@.str.6 = [52 x i8] c"-u Update mode (default: read-only)\0A\00"
@.str.7 = [58 x i8] c"-d Disable existing checksum verification\0A\00"
@.str.8 = [58 x i8] c"-s <delta> Screw up the ROM so checksum will fail\0A\00"
@.str.9 = [17 x i8] c"screwup enabled\0A\00"
@.str.10 = [4 x i8] c"r+b\00"
@stderr = global i32 0
@.str.11 = [16 x i8] c"Cannot open %s\0A\00"
@.str.12 = [44 x i8] c"Calculated checksum: %04XH (version %02XH)\0A\00"
@.str.13 = [40 x i8] c"Stored checksum: %04XH (version %02XH)\0A\00"
@.str.14 = [20 x i8] c"Store delta: %04XH\0A\00"
@.str.15 = [52 x i8] c"Disable checksum requested, modification required.\0A\00"
@.str.16 = [35 x i8] c"ROM modified to disable checksum.\0A\00"
@.str.17 = [41 x i8] c"Figuring out how to correct checksum...\0A\00"
@.str.18 = [47 x i8] c"Solution: use checksum = %04XH, delta = %04XH\0A\00"
@SEEK_CUR = global i32 0
@.str.19 = [32 x i8] c"Writing changes to ROM file...\0A\00"
@.str.20 = [19 x i8] c"ROM file updated.\0A\00"
@.str.21 = [48 x i8] c"Error: can't figure out how to update checksum\0A\00"
@.str.22 = [38 x i8] c"Checksums match; no action required.\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [128 x i8]
%7 = alloca i32*
%8 = alloca [32768 x i8]
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
%18 = alloca i32
%19 = alloca i32
%20 = alloca i32
%21 = alloca i8*
%22 = alloca i32
%23 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %9
store i32 0, i32* %10
store i32 0, i32* %11
store i32 0, i32* %14
store i32 0, i32* %16
store i32 0, i32* %17
store i32 0, i32* %18
store i32 0, i32* %19
store i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8** %21
store i32 0, i32* %22
store i32 0, i32* %23
br label %24
24: ; preds = %54, %2
%25 = load i32, i32* %4
%26 = load i8**, i8*** %5
%27 = load i8*, i8** %21
%28 = call i32 @getopt(i32 %25, i8** %26, i8* %27)
store i32 %28, i32* %20
%29 = icmp ne i32 %28, -1
br i1 %29, label %30, label %55
30: ; preds = %24
%31 = load i32, i32* %20
switch i32 %31, label %54 [
i32 102, label %32
i32 117, label %36
i32 104, label %38
i32 115, label %46
i32 118, label %50
i32 100, label %53
]
32: ; preds = %30
%33 = getelementptr inbounds [128 x i8], [128 x i8]* %6, i64 0, i64 0
%34 = load i8*, i8** @optarg
%35 = call i32 @sprintf(i8* %33, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %34)
br label %54
36: ; preds = %30
store i32 1, i32* %17
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
br label %54
38: ; preds = %30
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0))
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.4, i64 0, i64 0))
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.5, i64 0, i64 0))
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.6, i64 0, i64 0))
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.7, i64 0, i64 0))
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.8, i64 0, i64 0))
%45 = call i32 @exit(i32 0)
unreachable
46: ; preds = %30
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.9, i64 0, i64 0))
%48 = load i8*, i8** @optarg
%49 = call i32 @strtoul(i8* %48, i32* null, i32 0)
store i32 %49, i32* %22
br label %54
50: ; preds = %30
%51 = load i8*, i8** @optarg
%52 = call i32 @strtoul(i8* %51, i32* null, i32 0)
store i32 %52, i32* %19
br label %54
53: ; preds = %30
store i32 1, i32* %23
br label %54
54: ; preds = %30, %53, %50, %46, %36, %32
br label %24
55: ; preds = %24
%56 = getelementptr inbounds [128 x i8], [128 x i8]* %6, i64 0, i64 0
%57 = call i32* @fopen(i8* %56, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.10, i64 0, i64 0))
store i32* %57, i32** %7
%58 = load i32*, i32** %7
%59 = icmp ne i32* %58, null
br i1 %59, label %65, label %60
60: ; preds = %55
%61 = load i32, i32* @stderr
%62 = getelementptr inbounds [128 x i8], [128 x i8]* %6, i64 0, i64 0
%63 = call i32 @fprintf(i32 %61, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.11, i64 0, i64 0), i8* %62)
%64 = call i32 @exit(i32 1)
unreachable
65: ; preds = %55
br label %66
66: ; preds = %105, %65
%67 = getelementptr inbounds [32768 x i8], [32768 x i8]* %8, i64 0, i64 0
%68 = load i32*, i32** %7
%69 = call i32 @fread(i8* %67, i32 1, i32 32768, i32* %68)
store i32 %69, i32* %12
%70 = load i32*, i32** %7
%71 = call i64 @feof(i32* %70)
%72 = icmp ne i64 %71, 0
br i1 %72, label %73, label %74
73: ; preds = %66
br label %106
74: ; preds = %66
%75 = load i32, i32* %12
%76 = icmp slt i32 %75, 32768
br i1 %76, label %77, label %78
77: ; preds = %74
br label %78
78: ; preds = %77, %74
%79 = load i32, i32* %22
%80 = icmp ne i32 %79, 0
br i1 %80, label %81, label %90
81: ; preds = %78
%82 = getelementptr inbounds [32768 x i8], [32768 x i8]* %8, i64 0, i64 1
%83 = load i8, i8* %82
%84 = zext i8 %83 to i32
%85 = load i32, i32* %22
%86 = add nsw i32 %84, %85
%87 = and i32 %86, 255
%88 = trunc i32 %87 to i8
%89 = getelementptr inbounds [32768 x i8], [32768 x i8]* %8, i64 0, i64 1
store i8 %88, i8* %89
br label %90
90: ; preds = %81, %78
store i32 0, i32* %13
br label %91
91: ; preds = %102, %90
%92 = load i32, i32* %13
%93 = icmp slt i32 %92, 32768
br i1 %93, label %94, label %105
94: ; preds = %91
%95 = load i32, i32* %13
%96 = sext i32 %95 to i64
%97 = getelementptr inbounds [32768 x i8], [32768 x i8]* %8, i64 0, i64 %96
%98 = load i8, i8* %97
%99 = zext i8 %98 to i32
%100 = load i32, i32* %9
%101 = add nsw i32 %100, %99
store i32 %101, i32* %9
br label %102
102: ; preds = %94
%103 = load i32, i32* %13
%104 = add nsw i32 %103, 1
store i32 %104, i32* %13
br label %91
105: ; preds = %91
br label %66
106: ; preds = %73
%107 = getelementptr inbounds [32768 x i8], [32768 x i8]* %8, i64 0, i64 32750
%108 = load i8, i8* %107
%109 = zext i8 %108 to i32
%110 = mul nsw i32 %109, 256
%111 = getelementptr inbounds [32768 x i8], [32768 x i8]* %8, i64 0, i64 32751
%112 = load i8, i8* %111
%113 = zext i8 %112 to i32
%114 = add nsw i32 %110, %113
store i32 %114, i32* %10
%115 = getelementptr inbounds [32768 x i8], [32768 x i8]* %8, i64 0, i64 32748
%116 = load i8, i8* %115
%117 = zext i8 %116 to i32
%118 = mul nsw i32 %117, 256
%119 = getelementptr inbounds [32768 x i8], [32768 x i8]* %8, i64 0, i64 32749
%120 = load i8, i8* %119
%121 = zext i8 %120 to i32
%122 = add nsw i32 %118, %121
store i32 %122, i32* %11
%123 = load i32, i32* %9
%124 = and i32 %123, 65535
store i32 %124, i32* %9
%125 = load i32, i32* %10
%126 = and i32 %125, 65535
store i32 %126, i32* %10
%127 = load i32, i32* %9
%128 = load i32, i32* %9
%129 = srem i32 %128, 256
%130 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.12, i64 0, i64 0), i32 %127, i32 %129)
%131 = load i32, i32* %10
%132 = load i32, i32* %10
%133 = srem i32 %132, 256
%134 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.13, i64 0, i64 0), i32 %131, i32 %133)
%135 = load i32, i32* %11
%136 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.14, i64 0, i64 0), i32 %135)
%137 = load i32, i32* %23
%138 = icmp ne i32 %137, 0
br i1 %138, label %139, label %151
139: ; preds = %106
%140 = load i32, i32* %11
%141 = icmp ne i32 %140, 255
br i1 %141, label %142, label %151
142: ; preds = %139
%143 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.15, i64 0, i64 0))
%144 = load i32, i32* %17
%145 = icmp eq i32 %144, 1
br i1 %145, label %146, label %150
146: ; preds = %142
%147 = getelementptr inbounds [32768 x i8], [32768 x i8]* %8, i64 0, i64 32748
store i8 0, i8* %147
%148 = getelementptr inbounds [32768 x i8], [32768 x i8]* %8, i64 0, i64 32749
store i8 -1, i8* %148
%149 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.16, i64 0, i64 0))
br label %150
150: ; preds = %146, %142
br label %266
151: ; preds = %139, %106
%152 = load i32, i32* %9
%153 = load i32, i32* %10
%154 = icmp ne i32 %152, %153
br i1 %154, label %163, label %155
155: ; preds = %151
%156 = load i32, i32* %19
%157 = icmp ne i32 %156, 0
br i1 %157, label %158, label %263
158: ; preds = %155
%159 = load i32, i32* %19
%160 = load i32, i32* %10
%161 = srem i32 %160, 256
%162 = icmp ne i32 %159, %161
br i1 %162, label %163, label %263
163: ; preds = %158, %151
%164 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.17, i64 0, i64 0))
%165 = load i32, i32* %10
%166 = sdiv i32 %165, 256
%167 = load i32, i32* %10
%168 = srem i32 %167, 256
%169 = add nsw i32 %166, %168
%170 = load i32, i32* %9
%171 = sub nsw i32 %170, %169
store i32 %171, i32* %9
%172 = load i32, i32* %9
%173 = and i32 %172, 65535
store i32 %173, i32* %9
%174 = load i32, i32* %11
%175 = sdiv i32 %174, 256
%176 = load i32, i32* %11
%177 = srem i32 %176, 256
%178 = add nsw i32 %175, %177
%179 = load i32, i32* %9
%180 = sub nsw i32 %179, %178
store i32 %180, i32* %9
%181 = load i32, i32* %9
%182 = and i32 %181, 65535
store i32 %182, i32* %9
store i32 0, i32* %18
br label %183
183: ; preds = %254, %163
%184 = load i32, i32* %18
%185 = icmp sle i32 %184, 65535
br i1 %185, label %186, label %257
186: ; preds = %183
%187 = load i32, i32* %18
%188 = icmp eq i32 %187, 255
br i1 %188, label %189, label %190
189: ; preds = %186
br label %254
190: ; preds = %186
%191 = load i32, i32* %19
store i32 %191, i32* %14
br label %192
192: ; preds = %246, %190
%193 = load i32, i32* %14
%194 = icmp sle i32 %193, 65535
br i1 %194, label %195, label %249
195: ; preds = %192
%196 = load i32, i32* %9
%197 = load i32, i32* %14
%198 = sdiv i32 %197, 256
%199 = add nsw i32 %196, %198
%200 = load i32, i32* %14
%201 = srem i32 %200, 256
%202 = add nsw i32 %199, %201
%203 = load i32, i32* %18
%204 = sdiv i32 %203, 256
%205 = add nsw i32 %202, %204
%206 = load i32, i32* %18
%207 = srem i32 %206, 256
%208 = add nsw i32 %205, %207
%209 = and i32 %208, 65535
store i32 %209, i32* %15
%210 = load i32, i32* %15
%211 = load i32, i32* %14
%212 = icmp eq i32 %210, %211
br i1 %212, label %213, label %245
213: ; preds = %195
%214 = load i32, i32* %14
%215 = load i32, i32* %18
%216 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.18, i64 0, i64 0), i32 %214, i32 %215)
store i32 1, i32* %16
%217 = load i32, i32* %17
%218 = icmp eq i32 %217, 1
br i1 %218, label %219, label %244
219: ; preds = %213
%220 = load i32, i32* %18
%221 = sdiv i32 %220, 256
%222 = trunc i32 %221 to i8
%223 = getelementptr inbounds [32768 x i8], [32768 x i8]* %8, i64 0, i64 32748
store i8 %222, i8* %223
%224 = load i32, i32* %18
%225 = srem i32 %224, 256
%226 = trunc i32 %225 to i8
%227 = getelementptr inbounds [32768 x i8], [32768 x i8]* %8, i64 0, i64 32749
store i8 %226, i8* %227
%228 = load i32, i32* %14
%229 = sdiv i32 %228, 256
%230 = trunc i32 %229 to i8
%231 = getelementptr inbounds [32768 x i8], [32768 x i8]* %8, i64 0, i64 32750
store i8 %230, i8* %231
%232 = load i32, i32* %14
%233 = srem i32 %232, 256
%234 = trunc i32 %233 to i8
%235 = getelementptr inbounds [32768 x i8], [32768 x i8]* %8, i64 0, i64 32751
store i8 %234, i8* %235
%236 = load i32*, i32** %7
%237 = load i32, i32* @SEEK_CUR
%238 = call i32 @fseek(i32* %236, i32 -32768, i32 %237)
%239 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.19, i64 0, i64 0))
%240 = getelementptr inbounds [32768 x i8], [32768 x i8]* %8, i64 0, i64 0
%241 = load i32*, i32** %7
%242 = call i32 @fwrite(i8* %240, i32 1, i32 32768, i32* %241)
%243 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.20, i64 0, i64 0))
br label %244
244: ; preds = %219, %213
br label %249
245: ; preds = %195
br label %246
246: ; preds = %245
%247 = load i32, i32* %14
%248 = add nsw i32 %247, 256
store i32 %248, i32* %14
br label %192
249: ; preds = %244, %192
%250 = load i32, i32* %16
%251 = icmp ne i32 %250, 0
br i1 %251, label %252, label %253
252: ; preds = %249
br label %257
253: ; preds = %249
br label %254
254: ; preds = %253, %189
%255 = load i32, i32* %18
%256 = add nsw i32 %255, 1
store i32 %256, i32* %18
br label %183
257: ; preds = %252, %183
%258 = load i32, i32* %16
%259 = icmp eq i32 %258, 0
br i1 %259, label %260, label %262
260: ; preds = %257
%261 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.21, i64 0, i64 0))
br label %262
262: ; preds = %260, %257
br label %265
263: ; preds = %158, %155
%264 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.22, i64 0, i64 0))
br label %265
265: ; preds = %263, %262
br label %266
266: ; preds = %265, %150
%267 = load i32*, i32** %7
%268 = call i32 @fclose(i32* %267)
ret i32 0
}

LLVM IR (-O2):
@.str = [9 x i8] c"f:uhs:v:\00"
@optarg = global i8* null
@.str.10 = [4 x i8] c"r+b\00"
@stderr = global i32 0
@.str.11 = [16 x i8] c"Cannot open %s\0A\00"
@.str.12 = [44 x i8] c"Calculated checksum: %04XH (version %02XH)\0A\00"
@.str.13 = [40 x i8] c"Stored checksum: %04XH (version %02XH)\0A\00"
@.str.14 = [20 x i8] c"Store delta: %04XH\0A\00"
@.str.18 = [47 x i8] c"Solution: use checksum = %04XH, delta = %04XH\0A\00"
@SEEK_CUR = global i32 0
@str = [37 x i8] c"Checksums match; no action required.\00"
@str.23 = [40 x i8] c"Figuring out how to correct checksum...\00"
@str.24 = [47 x i8] c"Error: can't figure out how to update checksum\00"
@str.25 = [31 x i8] c"Writing changes to ROM file...\00"
@str.26 = [18 x i8] c"ROM file updated.\00"
@str.27 = [51 x i8] c"Disable checksum requested, modification required.\00"
@str.28 = [34 x i8] c"ROM modified to disable checksum.\00"
@str.29 = [16 x i8] c"screwup enabled\00"
@str.30 = [25 x i8] c"FreeWPC Checksum Utility\00"
@str.31 = [38 x i8] c"-f <filename> Sets input filename\00"
@str.32 = [46 x i8] c"-v <version> Sets desired version number\00"
@str.33 = [51 x i8] c"-u Update mode (default: read-only)\00"
@str.34 = [57 x i8] c"-d Disable existing checksum verification\00"
@str.35 = [57 x i8] c"-s <delta> Screw up the ROM so checksum will fail\00"
@str.36 = [19 x i8] c"Autoupdate enabled\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca [128 x i8]
%4 = alloca [32768 x i8]
%5 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [32768 x i8], [32768 x i8]* %4, i64 0, i64 0
br label %7
7: ; preds = %27, %2
%8 = phi i1 [ true, %27 ], [ false, %2 ]
%9 = phi i32 [ %13, %27 ], [ 0, %2 ]
%10 = phi i32 [ %17, %27 ], [ 0, %2 ]
%11 = phi i32 [ %20, %27 ], [ 0, %2 ]
br label %12
12: ; preds = %7, %41
%13 = phi i32 [ %9, %7 ], [ %43, %41 ]
%14 = phi i32 [ %10, %7 ], [ %17, %41 ]
%15 = phi i32 [ %11, %7 ], [ %20, %41 ]
br label %16
16: ; preds = %12, %37
%17 = phi i32 [ %14, %12 ], [ %40, %37 ]
%18 = phi i32 [ %15, %12 ], [ %20, %37 ]
br label %19
19: ; preds = %21, %16
%20 = phi i32 [ %18, %16 ], [ 1, %21 ]
br label %21
21: ; preds = %23, %19
%22 = call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
switch i32 %22, label %23 [
i32 -1, label %44
i32 102, label %24
i32 117, label %27
i32 104, label %29
i32 115, label %37
i32 118, label %41
i32 100, label %19
]
23: ; preds = %21, %24
br label %21
24: ; preds = %21
%25 = load i8*, i8** @optarg
%26 = call i8* @strcpy(i8* %5, i8* dereferenceable(1) %25)
br label %23
27: ; preds = %21
%28 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str.36, i64 0, i64 0))
br label %7
29: ; preds = %21
%30 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str.30, i64 0, i64 0))
%31 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @str.31, i64 0, i64 0))
%32 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([46 x i8], [46 x i8]* @str.32, i64 0, i64 0))
%33 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([51 x i8], [51 x i8]* @str.33, i64 0, i64 0))
%34 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([57 x i8], [57 x i8]* @str.34, i64 0, i64 0))
%35 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([57 x i8], [57 x i8]* @str.35, i64 0, i64 0))
%36 = call i32 @exit(i32 0)
unreachable
37: ; preds = %21
%38 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str.29, i64 0, i64 0))
%39 = load i8*, i8** @optarg
%40 = call i32 @strtoul(i8* nocapture %39, i32* null, i32 0)
br label %16
41: ; preds = %21
%42 = load i8*, i8** @optarg
%43 = call i32 @strtoul(i8* nocapture %42, i32* null, i32 0)
br label %12
44: ; preds = %21
%45 = call i32* @fopen(i8* %5, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.10, i64 0, i64 0))
%46 = icmp eq i32* %45, null
br i1 %46, label %55, label %47
47: ; preds = %44
%48 = call i32 @fread(i8* %6, i32 1, i32 32768, i32* %45)
%49 = call i64 @feof(i32* %45)
%50 = icmp eq i64 %49, 0
br i1 %50, label %51, label %99
51: ; preds = %47
%52 = icmp eq i32 %17, 0
%53 = getelementptr inbounds [32768 x i8], [32768 x i8]* %4, i64 0, i64 1
%54 = trunc i32 %17 to i8
br label %59
55: ; preds = %44
%56 = load i32, i32* @stderr
%57 = call i32 @fprintf(i32 %56, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.11, i64 0, i64 0), i8* %5)
%58 = call i32 @exit(i32 1)
unreachable
59: ; preds = %51, %93
%60 = phi i32 [ 0, %51 ], [ %95, %93 ]
br i1 %52, label %64, label %61
61: ; preds = %59
%62 = load i8, i8* %53
%63 = add i8 %62, %54
store i8 %63, i8* %53
br label %64
64: ; preds = %59, %61
%65 = insertelement <4 x i32> <i32 poison, i32 0, i32 0, i32 0>, i32 %60, i64 0
br label %66
66: ; preds = %66, %64
%67 = phi i64 [ 0, %64 ], [ %91, %66 ]
%68 = phi <4 x i32> [ %65, %64 ], [ %89, %66 ]
%69 = phi <4 x i32> [ zeroinitializer, %64 ], [ %90, %66 ]
%70 = getelementptr inbounds [32768 x i8], [32768 x i8]* %4, i64 0, i64 %67
%71 = bitcast i8* %70 to <4 x i8>*
%72 = load <4 x i8>, <4 x i8>* %71
%73 = getelementptr inbounds i8, i8* %70, i64 4
%74 = bitcast i8* %73 to <4 x i8>*
%75 = load <4 x i8>, <4 x i8>* %74
%76 = zext <4 x i8> %72 to <4 x i32>
%77 = zext <4 x i8> %75 to <4 x i32>
%78 = add <4 x i32> %68, %76
%79 = add <4 x i32> %69, %77
%80 = or i64 %67, 8
%81 = getelementptr inbounds [32768 x i8], [32768 x i8]* %4, i64 0, i64 %80
%82 = bitcast i8* %81 to <4 x i8>*
%83 = load <4 x i8>, <4 x i8>* %82
%84 = getelementptr inbounds i8, i8* %81, i64 4
%85 = bitcast i8* %84 to <4 x i8>*
%86 = load <4 x i8>, <4 x i8>* %85
%87 = zext <4 x i8> %83 to <4 x i32>
%88 = zext <4 x i8> %86 to <4 x i32>
%89 = add <4 x i32> %78, %87
%90 = add <4 x i32> %79, %88
%91 = add nuw nsw i64 %67, 16
%92 = icmp eq i64 %91, 32768
br i1 %92, label %93, label %66
93: ; preds = %66
%94 = add <4 x i32> %90, %89
%95 = call i32 @llvm.vector.reduce.add.v4i32(<4 x i32> %94)
%96 = call i32 @fread(i8* %6, i32 1, i32 32768, i32* %45)
%97 = call i64 @feof(i32* %45)
%98 = icmp eq i64 %97, 0
br i1 %98, label %59, label %99
99: ; preds = %93, %47
%100 = phi i32 [ 0, %47 ], [ %95, %93 ]
%101 = getelementptr inbounds [32768 x i8], [32768 x i8]* %4, i64 0, i64 32750
%102 = load i8, i8* %101
%103 = zext i8 %102 to i32
%104 = shl nuw nsw i32 %103, 8
%105 = getelementptr inbounds [32768 x i8], [32768 x i8]* %4, i64 0, i64 32751
%106 = load i8, i8* %105
%107 = zext i8 %106 to i32
%108 = or i32 %104, %107
%109 = getelementptr inbounds [32768 x i8], [32768 x i8]* %4, i64 0, i64 32748
%110 = load i8, i8* %109
%111 = zext i8 %110 to i32
%112 = shl nuw nsw i32 %111, 8
%113 = getelementptr inbounds [32768 x i8], [32768 x i8]* %4, i64 0, i64 32749
%114 = load i8, i8* %113
%115 = zext i8 %114 to i32
%116 = or i32 %112, %115
%117 = and i32 %100, 65535
%118 = and i32 %100, 255
%119 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 x i8]* @.str.12, i64 0, i64 0), i32 %117, i32 %118)
%120 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str.13, i64 0, i64 0), i32 %108, i32 %107)
%121 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.14, i64 0, i64 0), i32 %116)
%122 = icmp ne i32 %20, 0
%123 = icmp ne i32 %116, 255
%124 = select i1 %122, i1 %123, i1 false
br i1 %124, label %125, label %128
125: ; preds = %99
%126 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([51 x i8], [51 x i8]* @str.27, i64 0, i64 0))
br i1 %8, label %127, label %178
127: ; preds = %125
store i8 0, i8* %109
br label %175
128: ; preds = %99
%129 = icmp eq i32 %117, %108
br i1 %129, label %130, label %134
130: ; preds = %128
%131 = icmp eq i32 %13, 0
%132 = icmp eq i32 %13, %107
%133 = select i1 %131, i1 true, i1 %132
br i1 %133, label %175, label %134
134: ; preds = %130, %128
%135 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @str.23, i64 0, i64 0))
%136 = icmp sgt i32 %13, 65535
%137 = add nuw nsw i32 %103, %107
%138 = add nuw nsw i32 %137, %111
%139 = add nuw nsw i32 %138, %115
%140 = sub i32 %100, %139
br label %141
141: ; preds = %134, %172
%142 = phi i32 [ 0, %134 ], [ %173, %172 ]
%143 = icmp eq i32 %142, 255
%144 = select i1 %143, i1 true, i1 %136
br i1 %144, label %172, label %145
145: ; preds = %141
%146 = lshr i32 %142, 8
%147 = and i32 %142, 255
%148 = add i32 %140, %146
%149 = add i32 %148, %147
br label %150
150: ; preds = %145, %169
%151 = phi i32 [ %13, %145 ], [ %170, %169 ]
%152 = sdiv i32 %151, 256
%153 = srem i32 %151, 256
%154 = add i32 %149, %152
%155 = add i32 %154, %153
%156 = and i32 %155, 65535
%157 = icmp eq i32 %156, %151
br i1 %157, label %158, label %169
158: ; preds = %150
%159 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([47 x i8], [47 x i8]* @.str.18, i64 0, i64 0), i32 %151, i32 %142)
br i1 %8, label %160, label %178
160: ; preds = %158
%161 = trunc i32 %146 to i8
store i8 %161, i8* %109
%162 = trunc i32 %142 to i8
store i8 %162, i8* %113
%163 = trunc i32 %152 to i8
store i8 %163, i8* %101
%164 = trunc i32 %153 to i8
store i8 %164, i8* %105
%165 = load i32, i32* @SEEK_CUR
%166 = call i32 @fseek(i32* %45, i32 -32768, i32 %165)
%167 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @str.25, i64 0, i64 0))
%168 = call i32 @fwrite(i8* %6, i32 1, i32 32768, i32* %45)
br label %175
169: ; preds = %150
%170 = add nsw i32 %151, 256
%171 = icmp slt i32 %151, 65280
br i1 %171, label %150, label %172
172: ; preds = %169, %141
%173 = add nuw nsw i32 %142, 1
%174 = icmp eq i32 %173, 65536
br i1 %174, label %175, label %141
175: ; preds = %172, %130, %127, %160
%176 = phi i8* [ getelementptr inbounds ([18 x i8], [18 x i8]* @str.26, i64 0, i64 0), %160 ], [ getelementptr inbounds ([34 x i8], [34 x i8]* @str.28, i64 0, i64 0), %127 ], [ getelementptr inbounds ([37 x i8], [37 x i8]* @str, i64 0, i64 0), %130 ], [ getelementptr inbounds ([47 x i8], [47 x i8]* @str.24, i64 0, i64 0), %172 ]
%177 = call i32 @puts(i8* dereferenceable(1) %176)
br label %178
178: ; preds = %175, %158, %125
%179 = call i32 @fclose(i32* %45)
ret i32 0
}