#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 */
struct stat {
  int st_size;
};

/* Variables and functions */
int /*<<< orphan*/ B9600;
int EXIT_FAILURE;
int EXIT_SUCCESS;
int O_CREAT;
int O_NOCTTY;
int O_RDONLY;
int O_RDWR;
int O_SYNC;
int O_TRUNC;
int O_WRONLY;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, ...);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/);
scalar_t__ fstat(int, struct stat *);
scalar_t__ memcmp(unsigned char *, unsigned char *, int);
int /*<<< orphan*/ memset(unsigned char *, int /*<<< orphan*/, int);
int open(char *, int, ...);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ read(int, ...);
int /*<<< orphan*/ set_interface_attribs(int, int /*<<< orphan*/,
                                         int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcmp(char *, char *);
char *strerror(int /*<<< orphan*/);
int /*<<< orphan*/ usage();
int /*<<< orphan*/ write(int, ...);
int main(int argc, char **argv) {
  unsigned char data[1024], indata[1024];
  int i, fd, dumpfile, writerom = 0;
  struct stat sb;
  char hex[2];
  if (argc != 4) {
    usage();
    return EXIT_SUCCESS;
  }
  if (!strcmp(argv[2], "-r")) {
    writerom = 0;
  } else if (!strcmp(argv[2], "-w")) {
    writerom = 1;
  } else {
    usage();
    return EXIT_SUCCESS;
  }
  fd = open(argv[1], O_RDWR | O_NOCTTY | O_SYNC);
  if (fd < 0) {
    fprintf(stderr, "Error opening %s: %s\n", argv[1], strerror(errno));
    return EXIT_FAILURE;
  }
  if (!set_interface_attribs(fd, B9600, 0)) {
    fprintf(stderr, "Error setting baud rate: %s\n", strerror(errno));
    close(fd);
    return EXIT_FAILURE;
  }
  dumpfile =
      open(argv[3], writerom ? (O_WRONLY | O_CREAT | O_TRUNC) : O_RDONLY, 0775);
  if (dumpfile < 0) {
    fprintf(stderr, "Error opening %s: %s", argv[3], strerror(errno));
    close(fd);
    return EXIT_FAILURE;
  }
  if (writerom && fstat(dumpfile, &sb) != 0) {
    fprintf(stderr, "Failed reading ROM dump size: %s\n", strerror(errno));
    close(fd);
    close(dumpfile);
    return EXIT_FAILURE;
  }
  memset(data, 0, 1024);
  memset(indata, 0, 1024);
  if (writerom) {
    read(dumpfile, data, sb.st_size < 1024 ? sb.st_size : 1024);
    puts("WRITING...");
    write(fd, "WRITE\n", 6);
    for (i = 0; i < 1024; ++i) {
      hex[0] = (data[i] >> 8) & 0x0F;
      hex[1] = data[i] & 0x0F;
      hex[0] = hex[0] < 10 ? (hex[0] + '0') : (hex[0] - 10 + 'A');
      hex[1] = hex[1] < 10 ? (hex[1] + '0') : (hex[1] - 10 + 'A');
      write(fd, hex, 2);
    }
  }
  puts("READING...");
  write(fd, "READ\n", 5);
  for (i = 0; i < 1024; ++i) {
    read(fd, hex, 2);
    if (hex[0] >= '0' && hex[0] <= '9')
      indata[i] |= (hex[0] - '0') << 4;
    else if (hex[0] >= 'A' && hex[0] <= 'F')
      indata[i] |= (hex[0] - 'A') << 4;
    if (hex[1] >= '0' && hex[1] <= '9')
      indata[i] |= (hex[1] - '0');
    else if (hex[0] >= 'A' && hex[0] <= 'F')
      indata[i] |= (hex[1] - 'A');
  }
  if (writerom) {
    if (memcmp(indata, data, 1024) != 0) {
      fputs("VERIFY FAILED", stderr);
    } else {
      puts("VERIFIED");
    }
  } else {
    write(dumpfile, indata, 1024);
  }
  close(fd);
  close(dumpfile);
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x880,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x820(%rbp)
cmpl   $0x4,-0x8(%rbp)
je     1225 <main+0x45>
mov    $0x0,%al
call   10d0 <usage@plt>
mov    0x2d75(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    18f4 <main+0x714>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xdcc(%rip),%rsi
call   10b0 <strcmp@plt>
cmp    $0x0,%eax
jne    1251 <main+0x71>
movl   $0x0,-0x820(%rbp)
jmp    129a <main+0xba>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xda3(%rip),%rsi
call   10b0 <strcmp@plt>
cmp    $0x0,%eax
jne    127d <main+0x9d>
movl   $0x1,-0x820(%rbp)
jmp    1295 <main+0xb5>
mov    $0x0,%al
call   10d0 <usage@plt>
mov    0x2d05(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    18f4 <main+0x714>
jmp    129a <main+0xba>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2d2f(%rip),%rax
mov    (%rax),%esi
mov    0x2cfe(%rip),%rax
or     (%rax),%esi
mov    0x2d15(%rip),%rax
or     (%rax),%esi
mov    $0x0,%al
call   10e0 <open@plt>
mov    %eax,-0x818(%rbp)
cmpl   $0x0,-0x818(%rbp)
jge    1332 <main+0x152>
mov    0x2cca(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x83c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x838(%rbp)
mov    0x2ca4(%rip),%rax
mov    (%rax),%edi
call   10f0 <strerror@plt>
mov    -0x83c(%rbp),%edi
mov    -0x838(%rbp),%rdx
mov    %rax,%rcx
lea    0xcec(%rip),%rsi
mov    $0x0,%al
call   10c0 <fprintf@plt>
mov    0x2c70(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    18f4 <main+0x714>
mov    -0x818(%rbp),%edi
mov    0x2c81(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1050 <set_interface_attribs@plt>
cmp    $0x0,%eax
jne    13a1 <main+0x1c1>
mov    0x2c50(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x840(%rbp)
mov    0x2c39(%rip),%rax
mov    (%rax),%edi
call   10f0 <strerror@plt>
mov    -0x840(%rbp),%edi
mov    %rax,%rdx
lea    0xc9e(%rip),%rsi
mov    $0x0,%al
call   10c0 <fprintf@plt>
mov    -0x818(%rbp),%edi
call   1080 <close@plt>
mov    0x2c01(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    18f4 <main+0x714>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rax
mov    %rax,-0x848(%rbp)
cmpl   $0x0,-0x820(%rbp)
je     13e3 <main+0x203>
mov    0x2bbc(%rip),%rax
mov    (%rax),%eax
mov    0x2c2b(%rip),%rcx
or     (%rcx),%eax
mov    0x2c1a(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x84c(%rbp)
jmp    13f2 <main+0x212>
mov    0x2bde(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x84c(%rbp)
mov    -0x848(%rbp),%rdi
mov    -0x84c(%rbp),%esi
mov    $0x1fd,%edx
mov    $0x0,%al
call   10e0 <open@plt>
mov    %eax,-0x81c(%rbp)
cmpl   $0x0,-0x81c(%rbp)
jge    1484 <main+0x2a4>
mov    0x2b83(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x85c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rax
mov    %rax,-0x858(%rbp)
mov    0x2b5d(%rip),%rax
mov    (%rax),%edi
call   10f0 <strerror@plt>
mov    -0x85c(%rbp),%edi
mov    -0x858(%rbp),%rdx
mov    %rax,%rcx
lea    0xbd8(%rip),%rsi
mov    $0x0,%al
call   10c0 <fprintf@plt>
mov    -0x818(%rbp),%edi
call   1080 <close@plt>
mov    0x2b1e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    18f4 <main+0x714>
cmpl   $0x0,-0x820(%rbp)
je     1508 <main+0x328>
mov    -0x81c(%rbp),%edi
lea    -0x828(%rbp),%rsi
call   1100 <fstat@plt>
cmp    $0x0,%rax
je     1508 <main+0x328>
mov    0x2af4(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x860(%rbp)
mov    0x2add(%rip),%rax
mov    (%rax),%edi
call   10f0 <strerror@plt>
mov    -0x860(%rbp),%edi
mov    %rax,%rdx
lea    0xb74(%rip),%rsi
mov    $0x0,%al
call   10c0 <fprintf@plt>
mov    -0x818(%rbp),%edi
call   1080 <close@plt>
mov    -0x81c(%rbp),%edi
call   1080 <close@plt>
mov    0x2a9a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    18f4 <main+0x714>
lea    -0x410(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1070 <memset@plt>
lea    -0x810(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1070 <memset@plt>
cmpl   $0x0,-0x820(%rbp)
je     16cc <main+0x4ec>
mov    -0x81c(%rbp),%eax
mov    %eax,-0x86c(%rbp)
lea    -0x410(%rbp),%rax
mov    %rax,-0x868(%rbp)
cmpl   $0x400,-0x828(%rbp)
jge    1576 <main+0x396>
mov    -0x828(%rbp),%eax
mov    %eax,-0x870(%rbp)
jmp    1586 <main+0x3a6>
mov    $0x400,%eax
mov    %eax,-0x870(%rbp)
jmp    1586 <main+0x3a6>
mov    -0x868(%rbp),%rsi
mov    -0x86c(%rbp),%edi
mov    -0x870(%rbp),%edx
mov    $0x0,%al
call   1090 <read@plt>
lea    0xac9(%rip),%rdi
call   1030 <puts@plt>
mov    -0x818(%rbp),%edi
lea    0xac2(%rip),%rsi
mov    $0x6,%edx
mov    $0x0,%al
call   1040 <write@plt>
movl   $0x0,-0x814(%rbp)
cmpl   $0x400,-0x814(%rbp)
jge    16c7 <main+0x4e7>
movslq -0x814(%rbp),%rax
movzbl -0x410(%rbp,%rax,1),%eax
ff
sar    $0x8,%eax
and    $0xf,%eax
mov    %al,-0x82a(%rbp)
movslq -0x814(%rbp),%rax
movzbl -0x410(%rbp,%rax,1),%eax
ff
and    $0xf,%eax
mov    %al,-0x829(%rbp)
movsbl -0x82a(%rbp),%eax
cmp    $0xa,%eax
jge    1637 <main+0x457>
movsbl -0x82a(%rbp),%eax
add    $0x30,%eax
mov    %eax,-0x874(%rbp)
jmp    164a <main+0x46a>
movsbl -0x82a(%rbp),%eax
sub    $0xa,%eax
add    $0x41,%eax
mov    %eax,-0x874(%rbp)
mov    -0x874(%rbp),%eax
mov    %al,-0x82a(%rbp)
movsbl -0x829(%rbp),%eax
cmp    $0xa,%eax
jge    167b <main+0x49b>
movsbl -0x829(%rbp),%eax
add    $0x30,%eax
mov    %eax,-0x878(%rbp)
jmp    168e <main+0x4ae>
movsbl -0x829(%rbp),%eax
sub    $0xa,%eax
add    $0x41,%eax
mov    %eax,-0x878(%rbp)
mov    -0x878(%rbp),%eax
mov    %al,-0x829(%rbp)
mov    -0x818(%rbp),%edi
lea    -0x82a(%rbp),%rsi
mov    $0x2,%edx
mov    $0x0,%al
call   1040 <write@plt>
mov    -0x814(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x814(%rbp)
jmp    15cf <main+0x3ef>
jmp    16cc <main+0x4ec>
lea    0x9af(%rip),%rdi
call   1030 <puts@plt>
mov    -0x818(%rbp),%edi
lea    0x9a8(%rip),%rsi
mov    $0x5,%edx
mov    $0x0,%al
call   1040 <write@plt>
movl   $0x0,-0x814(%rbp)
cmpl   $0x400,-0x814(%rbp)
jge    185f <main+0x67f>
mov    -0x818(%rbp),%edi
lea    -0x82a(%rbp),%rsi
mov    $0x2,%edx
mov    $0x0,%al
call   1090 <read@plt>
movsbl -0x82a(%rbp),%eax
cmp    $0x30,%eax
jl     176e <main+0x58e>
movsbl -0x82a(%rbp),%eax
cmp    $0x39,%eax
jg     176e <main+0x58e>
movsbl -0x82a(%rbp),%edx
sub    $0x30,%edx
shl    $0x4,%edx
movslq -0x814(%rbp),%rax
movzbl -0x810(%rbp,%rax,1),%ecx
ff
or     %edx,%ecx
mov    %cl,-0x810(%rbp,%rax,1)
jmp    17b8 <main+0x5d8>
movsbl -0x82a(%rbp),%eax
cmp    $0x41,%eax
jl     17b3 <main+0x5d3>
movsbl -0x82a(%rbp),%eax
cmp    $0x46,%eax
jg     17b3 <main+0x5d3>
movsbl -0x82a(%rbp),%edx
sub    $0x41,%edx
shl    $0x4,%edx
movslq -0x814(%rbp),%rax
movzbl -0x810(%rbp,%rax,1),%ecx
ff
or     %edx,%ecx
mov    %cl,-0x810(%rbp,%rax,1)
jmp    17b8 <main+0x5d8>
movsbl -0x829(%rbp),%eax
cmp    $0x30,%eax
jl     17ff <main+0x61f>
movsbl -0x829(%rbp),%eax
cmp    $0x39,%eax
jg     17ff <main+0x61f>
movsbl -0x829(%rbp),%edx
sub    $0x30,%edx
movslq -0x814(%rbp),%rax
movzbl -0x810(%rbp,%rax,1),%ecx
ff
or     %edx,%ecx
mov    %cl,-0x810(%rbp,%rax,1)
jmp    1846 <main+0x666>
movsbl -0x82a(%rbp),%eax
cmp    $0x41,%eax
jl     1841 <main+0x661>
movsbl -0x82a(%rbp),%eax
cmp    $0x46,%eax
jg     1841 <main+0x661>
movsbl -0x829(%rbp),%edx
sub    $0x41,%edx
movslq -0x814(%rbp),%rax
movzbl -0x810(%rbp,%rax,1),%ecx
ff
or     %edx,%ecx
mov    %cl,-0x810(%rbp,%rax,1)
jmp    1846 <main+0x666>
jmp    184b <main+0x66b>
mov    -0x814(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x814(%rbp)
jmp    16fb <main+0x51b>
cmpl   $0x0,-0x820(%rbp)
je     18b9 <main+0x6d9>
lea    -0x810(%rbp),%rdi
lea    -0x410(%rbp),%rsi
mov    $0x400,%edx
call   10a0 <memcmp@plt>
cmp    $0x0,%rax
je     18a8 <main+0x6c8>
mov    0x2713(%rip),%rax
mov    (%rax),%esi
lea    0x7f5(%rip),%rdi
call   1060 <fputs@plt>
jmp    18b4 <main+0x6d4>
lea    0x7f2(%rip),%rdi
call   1030 <puts@plt>
jmp    18d2 <main+0x6f2>
mov    -0x81c(%rbp),%edi
lea    -0x810(%rbp),%rsi
mov    $0x400,%edx
mov    $0x0,%al
call   1040 <write@plt>
mov    -0x818(%rbp),%edi
call   1080 <close@plt>
mov    -0x81c(%rbp),%edi
call   1080 <close@plt>
mov    0x26a1(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x880,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x810,%rsp
cmp    $0x4,%edi
jne    1224 <main+0x44>
mov    %rsi,%rbp
mov    0x10(%rsi),%rbx
lea    0xdfe(%rip),%rsi
mov    %rbx,%rdi
call   10b0 <strcmp@plt>
mov    %eax,%r15d
test   %eax,%eax
je     1244 <main+0x64>
lea    0xdeb(%rip),%rsi
mov    %rbx,%rdi
call   10b0 <strcmp@plt>
test   %eax,%eax
je     1244 <main+0x64>
xor    %eax,%eax
call   10d0 <usage@plt>
mov    0x2d5e(%rip),%rax
mov    (%rax),%eax
add    $0x810,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d8d(%rip),%rax
mov    0x2d5e(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x8(%rbp),%rdi
mov    0x2d6f(%rip),%rax
or     (%rax),%esi
xor    %eax,%eax
call   10e0 <open@plt>
test   %eax,%eax
js     131b <main+0x13b>
mov    %eax,%ebx
mov    0x2d45(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
xor    %edx,%edx
call   1050 <set_interface_attribs@plt>
test   %eax,%eax
je     1358 <main+0x178>
mov    0x18(%rbp),%rdi
test   %r15d,%r15d
je     1387 <main+0x1a7>
mov    0x2cde(%rip),%rax
mov    0x2d4f(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2d3c(%rip),%rax
or     (%rax),%esi
mov    $0x1fd,%edx
xor    %eax,%eax
call   10e0 <open@plt>
test   %eax,%eax
js     1546 <main+0x366>
mov    %eax,%r14d
lea    0x8(%rsp),%rsi
mov    %eax,%edi
call   1100 <fstat@plt>
test   %rax,%rax
je     13a7 <main+0x1c7>
mov    0x2cbf(%rip),%rax
mov    (%rax),%ebp
mov    0x2cae(%rip),%rax
mov    (%rax),%edi
call   10f0 <strerror@plt>
lea    0xd4e(%rip),%rsi
mov    %ebp,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   10c0 <fprintf@plt>
mov    %ebx,%edi
call   1080 <close@plt>
mov    %r14d,%edi
jmp    157b <main+0x39b>
mov    0x2c86(%rip),%rax
mov    (%rax),%ebx
mov    0x8(%rbp),%rbp
mov    0x2c71(%rip),%rax
mov    (%rax),%edi
call   10f0 <strerror@plt>
lea    0xcc9(%rip),%rsi
mov    %ebx,%edi
mov    %rbp,%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   10c0 <fprintf@plt>
mov    0x2c45(%rip),%rax
jmp    1232 <main+0x52>
mov    0x2c49(%rip),%rax
mov    (%rax),%ebp
mov    0x2c38(%rip),%rax
mov    (%rax),%edi
call   10f0 <strerror@plt>
lea    0xca6(%rip),%rsi
mov    %ebp,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   10c0 <fprintf@plt>
jmp    1579 <main+0x399>
mov    0x2c3a(%rip),%rax
mov    (%rax),%esi
mov    $0x1fd,%edx
xor    %eax,%eax
call   10e0 <open@plt>
mov    %eax,%r14d
test   %eax,%eax
js     1546 <main+0x366>
lea    0x410(%rsp),%rdi
mov    $0x400,%ebp
xor    %esi,%esi
mov    $0x400,%edx
call   1070 <memset@plt>
lea    0x10(%rsp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1070 <memset@plt>
test   %r15d,%r15d
je     1472 <main+0x292>
mov    0x8(%rsp),%eax
cmp    $0x400,%eax
cmovl  %eax,%ebp
lea    0x410(%rsp),%rsi
mov    %r14d,%edi
mov    %ebp,%edx
xor    %eax,%eax
call   1090 <read@plt>
lea    0xc6f(%rip),%rdi
call   1030 <puts@plt>
lea    0xc6e(%rip),%rsi
mov    %ebx,%edi
mov    $0x6,%edx
xor    %eax,%eax
call   1040 <write@plt>
lea    0x6(%rsp),%r12
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movzbl 0x410(%rsp,%rbp,1),%eax
and    $0xf,%al
movb   $0x30,0x6(%rsp)
lea    0x30(%rax),%ecx
lea    0x37(%rax),%edx
cmp    $0xa,%al
movzbl %cl,%eax
movzbl %dl,%ecx
cmovb  %eax,%ecx
mov    %cl,0x7(%rsp)
mov    %ebx,%edi
mov    %r12,%rsi
mov    $0x2,%edx
xor    %eax,%eax
call   1040 <write@plt>
add    $0x1,%rbp
cmp    $0x400,%rbp
jne    1430 <main+0x250>
lea    0xc09(%rip),%rdi
call   1030 <puts@plt>
lea    0xc08(%rip),%rsi
mov    %ebx,%edi
mov    $0x5,%edx
xor    %eax,%eax
call   1040 <write@plt>
lea    0x6(%rsp),%r12
xor    %ebp,%ebp
jmp    14b1 <main+0x2d1>
nopl   0x0(%rax)
or     %dl,0x10(%rsp,%rbp,1)
add    $0x1,%rbp
cmp    $0x400,%rbp
je     150e <main+0x32e>
mov    %ebx,%edi
mov    %r12,%rsi
mov    $0x2,%edx
xor    %eax,%eax
call   1090 <read@plt>
movzbl 0x6(%rsp),%eax
lea    -0x30(%rax),%ecx
cmp    $0x9,%cl
ja     14e0 <main+0x300>
mov    %eax,%ecx
shl    $0x4,%cl
jmp    14f0 <main+0x310>
cs nopw 0x0(%rax,%rax,1)
lea    -0x41(%rax),%ecx
cmp    $0x5,%cl
ja     14f4 <main+0x314>
mov    %eax,%ecx
shl    $0x4,%cl
add    $0xf0,%cl
or     %cl,0x10(%rsp,%rbp,1)
movzbl 0x7(%rsp),%ecx
lea    -0x30(%rcx),%edx
cmp    $0xa,%dl
jb     14a0 <main+0x2c0>
add    $0xbf,%al
cmp    $0x5,%al
ja     14a4 <main+0x2c4>
add    $0xbf,%cl
mov    %ecx,%edx
jmp    14a0 <main+0x2c0>
test   %r15d,%r15d
je     158c <main+0x3ac>
lea    0x10(%rsp),%rdi
lea    0x410(%rsp),%rsi
mov    $0x400,%edx
call   10a0 <memcmp@plt>
test   %rax,%rax
je     15a2 <main+0x3c2>
mov    0x2a72(%rip),%rax
mov    (%rax),%esi
lea    0xb54(%rip),%rdi
call   1060 <fputs@plt>
jmp    15ae <main+0x3ce>
mov    0x2a5b(%rip),%rax
mov    (%rax),%r14d
mov    0x18(%rbp),%rbp
mov    0x2a45(%rip),%rax
mov    (%rax),%edi
call   10f0 <strerror@plt>
lea    0xad0(%rip),%rsi
mov    %r14d,%edi
mov    %rbp,%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   10c0 <fprintf@plt>
mov    %ebx,%edi
call   1080 <close@plt>
mov    0x2a11(%rip),%rax
jmp    1232 <main+0x52>
lea    0x10(%rsp),%rsi
mov    %r14d,%edi
mov    $0x400,%edx
xor    %eax,%eax
call   1040 <write@plt>
jmp    15ae <main+0x3ce>
lea    0xaf8(%rip),%rdi
call   1030 <puts@plt>
mov    %ebx,%edi
call   1080 <close@plt>
mov    %r14d,%edi
call   1080 <close@plt>
jmp    122b <main+0x4b>

LLVM IR (-O0):
%struct.stat = type { i32 }
@EXIT_SUCCESS = global i32 0
@.str = [3 x i8] c"-r\00"
@.str.1 = [3 x i8] c"-w\00"
@O_RDWR = global i32 0
@O_NOCTTY = global i32 0
@O_SYNC = global i32 0
@stderr = global i32 0
@.str.2 = [22 x i8] c"Error opening %s: %s\0A\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
@B9600 = global i32 0
@.str.3 = [29 x i8] c"Error setting baud rate: %s\0A\00"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@O_RDONLY = global i32 0
@.str.4 = [21 x i8] c"Error opening %s: %s\00"
@.str.5 = [34 x i8] c"Failed reading ROM dump size: %s\0A\00"
@.str.6 = [11 x i8] c"WRITING...\00"
@.str.7 = [7 x i8] c"WRITE\0A\00"
@.str.8 = [11 x i8] c"READING...\00"
@.str.9 = [6 x i8] c"READ\0A\00"
@.str.10 = [14 x i8] c"VERIFY FAILED\00"
@.str.11 = [9 x i8] c"VERIFIED\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [1024 x i8]
%7 = alloca [1024 x i8]
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca %struct.stat
%13 = alloca [2 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %11
%14 = load i32, i32* %4
%15 = icmp ne i32 %14, 4
br i1 %15, label %16, label %19
16: ; preds = %2
%17 = call i32 (...) @usage()
%18 = load i32, i32* @EXIT_SUCCESS
store i32 %18, i32* %3
br label %337
19: ; preds = %2
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 2
%22 = load i8*, i8** %21
%23 = call i32 @strcmp(i8* %22, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%24 = icmp ne i32 %23, 0
br i1 %24, label %26, label %25
25: ; preds = %19
store i32 0, i32* %11
br label %37
26: ; preds = %19
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 2
%29 = load i8*, i8** %28
%30 = call i32 @strcmp(i8* %29, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%31 = icmp ne i32 %30, 0
br i1 %31, label %33, label %32
32: ; preds = %26
store i32 1, i32* %11
br label %36
33: ; preds = %26
%34 = call i32 (...) @usage()
%35 = load i32, i32* @EXIT_SUCCESS
store i32 %35, i32* %3
br label %337
36: ; preds = %32
br label %37
37: ; preds = %36, %25
%38 = load i8**, i8*** %5
%39 = getelementptr inbounds i8*, i8** %38, i64 1
%40 = load i8*, i8** %39
%41 = load i32, i32* @O_RDWR
%42 = load i32, i32* @O_NOCTTY
%43 = or i32 %41, %42
%44 = load i32, i32* @O_SYNC
%45 = or i32 %43, %44
%46 = call i32 (i8*, i32, ...) @open(i8* %40, i32 %45)
store i32 %46, i32* %9
%47 = load i32, i32* %9
%48 = icmp slt i32 %47, 0
br i1 %48, label %49, label %58
49: ; preds = %37
%50 = load i32, i32* @stderr
%51 = load i8**, i8*** %5
%52 = getelementptr inbounds i8*, i8** %51, i64 1
%53 = load i8*, i8** %52
%54 = load i32, i32* @errno
%55 = call i8* @strerror(i32 %54)
%56 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %50, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i8* %53, i8* %55)
%57 = load i32, i32* @EXIT_FAILURE
store i32 %57, i32* %3
br label %337
58: ; preds = %37
%59 = load i32, i32* %9
%60 = load i32, i32* @B9600
%61 = call i32 @set_interface_attribs(i32 %59, i32 %60, i32 0)
%62 = icmp ne i32 %61, 0
br i1 %62, label %71, label %63
63: ; preds = %58
%64 = load i32, i32* @stderr
%65 = load i32, i32* @errno
%66 = call i8* @strerror(i32 %65)
%67 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %64, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0), i8* %66)
%68 = load i32, i32* %9
%69 = call i32 @close(i32 %68)
%70 = load i32, i32* @EXIT_FAILURE
store i32 %70, i32* %3
br label %337
71: ; preds = %58
%72 = load i8**, i8*** %5
%73 = getelementptr inbounds i8*, i8** %72, i64 3
%74 = load i8*, i8** %73
%75 = load i32, i32* %11
%76 = icmp ne i32 %75, 0
br i1 %76, label %77, label %83
77: ; preds = %71
%78 = load i32, i32* @O_WRONLY
%79 = load i32, i32* @O_CREAT
%80 = or i32 %78, %79
%81 = load i32, i32* @O_TRUNC
%82 = or i32 %80, %81
br label %85
83: ; preds = %71
%84 = load i32, i32* @O_RDONLY
br label %85
85: ; preds = %83, %77
%86 = phi i32 [ %82, %77 ], [ %84, %83 ]
%87 = call i32 (i8*, i32, ...) @open(i8* %74, i32 %86, i32 509)
store i32 %87, i32* %10
%88 = load i32, i32* %10
%89 = icmp slt i32 %88, 0
br i1 %89, label %90, label %101
90: ; preds = %85
%91 = load i32, i32* @stderr
%92 = load i8**, i8*** %5
%93 = getelementptr inbounds i8*, i8** %92, i64 3
%94 = load i8*, i8** %93
%95 = load i32, i32* @errno
%96 = call i8* @strerror(i32 %95)
%97 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %91, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0), i8* %94, i8* %96)
%98 = load i32, i32* %9
%99 = call i32 @close(i32 %98)
%100 = load i32, i32* @EXIT_FAILURE
store i32 %100, i32* %3
br label %337
101: ; preds = %85
%102 = load i32, i32* %11
%103 = icmp ne i32 %102, 0
br i1 %103, label %104, label %118
104: ; preds = %101
%105 = load i32, i32* %10
%106 = call i64 @fstat(i32 %105, %struct.stat* %12)
%107 = icmp ne i64 %106, 0
br i1 %107, label %108, label %118
108: ; preds = %104
%109 = load i32, i32* @stderr
%110 = load i32, i32* @errno
%111 = call i8* @strerror(i32 %110)
%112 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %109, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.5, i64 0, i64 0), i8* %111)
%113 = load i32, i32* %9
%114 = call i32 @close(i32 %113)
%115 = load i32, i32* %10
%116 = call i32 @close(i32 %115)
%117 = load i32, i32* @EXIT_FAILURE
store i32 %117, i32* %3
br label %337
118: ; preds = %104, %101
%119 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%120 = call i32 @memset(i8* %119, i32 0, i32 1024)
%121 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%122 = call i32 @memset(i8* %121, i32 0, i32 1024)
%123 = load i32, i32* %11
%124 = icmp ne i32 %123, 0
br i1 %124, label %125, label %207
125: ; preds = %118
%126 = load i32, i32* %10
%127 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%128 = getelementptr inbounds %struct.stat, %struct.stat* %12, i32 0, i32 0
%129 = load i32, i32* %128
%130 = icmp slt i32 %129, 1024
br i1 %130, label %131, label %134
131: ; preds = %125
%132 = getelementptr inbounds %struct.stat, %struct.stat* %12, i32 0, i32 0
%133 = load i32, i32* %132
br label %135
134: ; preds = %125
br label %135
135: ; preds = %134, %131
%136 = phi i32 [ %133, %131 ], [ 1024, %134 ]
%137 = call i32 (i32, ...) @read(i32 %126, i8* %127, i32 %136)
%138 = call i32 @puts(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0))
%139 = load i32, i32* %9
%140 = call i32 (i32, ...) @write(i32 %139, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.7, i64 0, i64 0), i32 6)
store i32 0, i32* %8
br label %141
141: ; preds = %203, %135
%142 = load i32, i32* %8
%143 = icmp slt i32 %142, 1024
br i1 %143, label %144, label %206
144: ; preds = %141
%145 = load i32, i32* %8
%146 = sext i32 %145 to i64
%147 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 %146
%148 = load i8, i8* %147
%149 = zext i8 %148 to i32
%150 = ashr i32 %149, 8
%151 = and i32 %150, 15
%152 = trunc i32 %151 to i8
%153 = getelementptr inbounds [2 x i8], [2 x i8]* %13, i64 0, i64 0
store i8 %152, i8* %153
%154 = load i32, i32* %8
%155 = sext i32 %154 to i64
%156 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 %155
%157 = load i8, i8* %156
%158 = zext i8 %157 to i32
%159 = and i32 %158, 15
%160 = trunc i32 %159 to i8
%161 = getelementptr inbounds [2 x i8], [2 x i8]* %13, i64 0, i64 1
store i8 %160, i8* %161
%162 = getelementptr inbounds [2 x i8], [2 x i8]* %13, i64 0, i64 0
%163 = load i8, i8* %162
%164 = sext i8 %163 to i32
%165 = icmp slt i32 %164, 10
br i1 %165, label %166, label %171
166: ; preds = %144
%167 = getelementptr inbounds [2 x i8], [2 x i8]* %13, i64 0, i64 0
%168 = load i8, i8* %167
%169 = sext i8 %168 to i32
%170 = add nsw i32 %169, 48
br label %177
171: ; preds = %144
%172 = getelementptr inbounds [2 x i8], [2 x i8]* %13, i64 0, i64 0
%173 = load i8, i8* %172
%174 = sext i8 %173 to i32
%175 = sub nsw i32 %174, 10
%176 = add nsw i32 %175, 65
br label %177
177: ; preds = %171, %166
%178 = phi i32 [ %170, %166 ], [ %176, %171 ]
%179 = trunc i32 %178 to i8
%180 = getelementptr inbounds [2 x i8], [2 x i8]* %13, i64 0, i64 0
store i8 %179, i8* %180
%181 = getelementptr inbounds [2 x i8], [2 x i8]* %13, i64 0, i64 1
%182 = load i8, i8* %181
%183 = sext i8 %182 to i32
%184 = icmp slt i32 %183, 10
br i1 %184, label %185, label %190
185: ; preds = %177
%186 = getelementptr inbounds [2 x i8], [2 x i8]* %13, i64 0, i64 1
%187 = load i8, i8* %186
%188 = sext i8 %187 to i32
%189 = add nsw i32 %188, 48
br label %196
190: ; preds = %177
%191 = getelementptr inbounds [2 x i8], [2 x i8]* %13, i64 0, i64 1
%192 = load i8, i8* %191
%193 = sext i8 %192 to i32
%194 = sub nsw i32 %193, 10
%195 = add nsw i32 %194, 65
br label %196
196: ; preds = %190, %185
%197 = phi i32 [ %189, %185 ], [ %195, %190 ]
%198 = trunc i32 %197 to i8
%199 = getelementptr inbounds [2 x i8], [2 x i8]* %13, i64 0, i64 1
store i8 %198, i8* %199
%200 = load i32, i32* %9
%201 = getelementptr inbounds [2 x i8], [2 x i8]* %13, i64 0, i64 0
%202 = call i32 (i32, ...) @write(i32 %200, i8* %201, i32 2)
br label %203
203: ; preds = %196
%204 = load i32, i32* %8
%205 = add nsw i32 %204, 1
store i32 %205, i32* %8
br label %141
206: ; preds = %141
br label %207
207: ; preds = %206, %118
%208 = call i32 @puts(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.8, i64 0, i64 0))
%209 = load i32, i32* %9
%210 = call i32 (i32, ...) @write(i32 %209, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.9, i64 0, i64 0), i32 5)
store i32 0, i32* %8
br label %211
211: ; preds = %310, %207
%212 = load i32, i32* %8
%213 = icmp slt i32 %212, 1024
br i1 %213, label %214, label %313
214: ; preds = %211
%215 = load i32, i32* %9
%216 = getelementptr inbounds [2 x i8], [2 x i8]* %13, i64 0, i64 0
%217 = call i32 (i32, ...) @read(i32 %215, i8* %216, i32 2)
%218 = getelementptr inbounds [2 x i8], [2 x i8]* %13, i64 0, i64 0
%219 = load i8, i8* %218
%220 = sext i8 %219 to i32
%221 = icmp sge i32 %220, 48
br i1 %221, label %222, label %240
222: ; preds = %214
%223 = getelementptr inbounds [2 x i8], [2 x i8]* %13, i64 0, i64 0
%224 = load i8, i8* %223
%225 = sext i8 %224 to i32
%226 = icmp sle i32 %225, 57
br i1 %226, label %227, label %240
227: ; preds = %222
%228 = getelementptr inbounds [2 x i8], [2 x i8]* %13, i64 0, i64 0
%229 = load i8, i8* %228
%230 = sext i8 %229 to i32
%231 = sub nsw i32 %230, 48
%232 = shl i32 %231, 4
%233 = load i32, i32* %8
%234 = sext i32 %233 to i64
%235 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 %234
%236 = load i8, i8* %235
%237 = zext i8 %236 to i32
%238 = or i32 %237, %232
%239 = trunc i32 %238 to i8
store i8 %239, i8* %235
br label %264
240: ; preds = %222, %214
%241 = getelementptr inbounds [2 x i8], [2 x i8]* %13, i64 0, i64 0
%242 = load i8, i8* %241
%243 = sext i8 %242 to i32
%244 = icmp sge i32 %243, 65
br i1 %244, label %245, label %263
245: ; preds = %240
%246 = getelementptr inbounds [2 x i8], [2 x i8]* %13, i64 0, i64 0
%247 = load i8, i8* %246
%248 = sext i8 %247 to i32
%249 = icmp sle i32 %248, 70
br i1 %249, label %250, label %263
250: ; preds = %245
%251 = getelementptr inbounds [2 x i8], [2 x i8]* %13, i64 0, i64 0
%252 = load i8, i8* %251
%253 = sext i8 %252 to i32
%254 = sub nsw i32 %253, 65
%255 = shl i32 %254, 4
%256 = load i32, i32* %8
%257 = sext i32 %256 to i64
%258 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 %257
%259 = load i8, i8* %258
%260 = zext i8 %259 to i32
%261 = or i32 %260, %255
%262 = trunc i32 %261 to i8
store i8 %262, i8* %258
br label %263
263: ; preds = %250, %245, %240
br label %264
264: ; preds = %263, %227
%265 = getelementptr inbounds [2 x i8], [2 x i8]* %13, i64 0, i64 1
%266 = load i8, i8* %265
%267 = sext i8 %266 to i32
%268 = icmp sge i32 %267, 48
br i1 %268, label %269, label %286
269: ; preds = %264
%270 = getelementptr inbounds [2 x i8], [2 x i8]* %13, i64 0, i64 1
%271 = load i8, i8* %270
%272 = sext i8 %271 to i32
%273 = icmp sle i32 %272, 57
br i1 %273, label %274, label %286
274: ; preds = %269
%275 = getelementptr inbounds [2 x i8], [2 x i8]* %13, i64 0, i64 1
%276 = load i8, i8* %275
%277 = sext i8 %276 to i32
%278 = sub nsw i32 %277, 48
%279 = load i32, i32* %8
%280 = sext i32 %279 to i64
%281 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 %280
%282 = load i8, i8* %281
%283 = zext i8 %282 to i32
%284 = or i32 %283, %278
%285 = trunc i32 %284 to i8
store i8 %285, i8* %281
br label %309
286: ; preds = %269, %264
%287 = getelementptr inbounds [2 x i8], [2 x i8]* %13, i64 0, i64 0
%288 = load i8, i8* %287
%289 = sext i8 %288 to i32
%290 = icmp sge i32 %289, 65
br i1 %290, label %291, label %308
291: ; preds = %286
%292 = getelementptr inbounds [2 x i8], [2 x i8]* %13, i64 0, i64 0
%293 = load i8, i8* %292
%294 = sext i8 %293 to i32
%295 = icmp sle i32 %294, 70
br i1 %295, label %296, label %308
296: ; preds = %291
%297 = getelementptr inbounds [2 x i8], [2 x i8]* %13, i64 0, i64 1
%298 = load i8, i8* %297
%299 = sext i8 %298 to i32
%300 = sub nsw i32 %299, 65
%301 = load i32, i32* %8
%302 = sext i32 %301 to i64
%303 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 %302
%304 = load i8, i8* %303
%305 = zext i8 %304 to i32
%306 = or i32 %305, %300
%307 = trunc i32 %306 to i8
store i8 %307, i8* %303
br label %308
308: ; preds = %296, %291, %286
br label %309
309: ; preds = %308, %274
br label %310
310: ; preds = %309
%311 = load i32, i32* %8
%312 = add nsw i32 %311, 1
store i32 %312, i32* %8
br label %211
313: ; preds = %211
%314 = load i32, i32* %11
%315 = icmp ne i32 %314, 0
br i1 %315, label %316, label %327
316: ; preds = %313
%317 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%318 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%319 = call i64 @memcmp(i8* %317, i8* %318, i32 1024)
%320 = icmp ne i64 %319, 0
br i1 %320, label %321, label %324
321: ; preds = %316
%322 = load i32, i32* @stderr
%323 = call i32 @fputs(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.10, i64 0, i64 0), i32 %322)
br label %326
324: ; preds = %316
%325 = call i32 @puts(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.11, i64 0, i64 0))
br label %326
326: ; preds = %324, %321
br label %331
327: ; preds = %313
%328 = load i32, i32* %10
%329 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%330 = call i32 (i32, ...) @write(i32 %328, i8* %329, i32 1024)
br label %331
331: ; preds = %327, %326
%332 = load i32, i32* %9
%333 = call i32 @close(i32 %332)
%334 = load i32, i32* %10
%335 = call i32 @close(i32 %334)
%336 = load i32, i32* @EXIT_SUCCESS
store i32 %336, i32* %3
br label %337
337: ; preds = %331, %108, %90, %63, %49, %33, %16
%338 = load i32, i32* %3
ret i32 %338
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@EXIT_SUCCESS = global i32 0
@.str = [3 x i8] c"-r\00"
@.str.1 = [3 x i8] c"-w\00"
@O_RDWR = global i32 0
@O_NOCTTY = global i32 0
@O_SYNC = global i32 0
@stderr = global i32 0
@.str.2 = [22 x i8] c"Error opening %s: %s\0A\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
@B9600 = global i32 0
@.str.3 = [29 x i8] c"Error setting baud rate: %s\0A\00"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@O_RDONLY = global i32 0
@.str.4 = [21 x i8] c"Error opening %s: %s\00"
@.str.5 = [34 x i8] c"Failed reading ROM dump size: %s\0A\00"
@.str.6 = [11 x i8] c"WRITING...\00"
@.str.7 = [7 x i8] c"WRITE\0A\00"
@.str.8 = [11 x i8] c"READING...\00"
@.str.9 = [6 x i8] c"READ\0A\00"
@.str.10 = [14 x i8] c"VERIFY FAILED\00"
@.str.11 = [9 x i8] c"VERIFIED\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [1024 x i8]
%4 = alloca [1024 x i8]
%5 = alloca %struct.stat
%6 = alloca [2 x i8]
%7 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%8 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%9 = bitcast %struct.stat* %5 to i8*
%10 = getelementptr inbounds [2 x i8], [2 x i8]* %6, i64 0, i64 0
%11 = icmp eq i32 %0, 4
br i1 %11, label %14, label %12
12: ; preds = %2
%13 = tail call i32 (...) @usage()
br label %161
14: ; preds = %2
%15 = getelementptr inbounds i8*, i8** %1, i64 2
%16 = load i8*, i8** %15
%17 = tail call i32 @strcmp(i8* dereferenceable(1) %16, i8* dereferenceable(3) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%18 = icmp eq i32 %17, 0
br i1 %18, label %24, label %19
19: ; preds = %14
%20 = tail call i32 @strcmp(i8* dereferenceable(1) %16, i8* dereferenceable(3) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%21 = icmp eq i32 %20, 0
br i1 %21, label %24, label %22
22: ; preds = %19
%23 = tail call i32 (...) @usage()
br label %161
24: ; preds = %19, %14
%25 = getelementptr inbounds i8*, i8** %1, i64 1
%26 = load i8*, i8** %25
%27 = load i32, i32* @O_RDWR
%28 = load i32, i32* @O_NOCTTY
%29 = or i32 %28, %27
%30 = load i32, i32* @O_SYNC
%31 = or i32 %29, %30
%32 = tail call i32 (i8*, i32, ...) @open(i8* %26, i32 %31)
%33 = icmp slt i32 %32, 0
br i1 %33, label %34, label %40
34: ; preds = %24
%35 = load i32, i32* @stderr
%36 = load i8*, i8** %25
%37 = load i32, i32* @errno
%38 = tail call i8* @strerror(i32 %37)
%39 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %35, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i8* %36, i8* %38)
br label %161
40: ; preds = %24
%41 = load i32, i32* @B9600
%42 = tail call i32 @set_interface_attribs(i32 %32, i32 %41, i32 0)
%43 = icmp eq i32 %42, 0
br i1 %43, label %44, label %50
44: ; preds = %40
%45 = load i32, i32* @stderr
%46 = load i32, i32* @errno
%47 = tail call i8* @strerror(i32 %46)
%48 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %45, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0), i8* %47)
%49 = tail call i32 @close(i32 %32)
br label %161
50: ; preds = %40
%51 = getelementptr inbounds i8*, i8** %1, i64 3
%52 = load i8*, i8** %51
br i1 %18, label %53, label %57
53: ; preds = %50
%54 = load i32, i32* @O_RDONLY
%55 = tail call i32 (i8*, i32, ...) @open(i8* %52, i32 %54, i32 509)
%56 = icmp slt i32 %55, 0
br i1 %56, label %65, label %82
57: ; preds = %50
%58 = load i32, i32* @O_WRONLY
%59 = load i32, i32* @O_CREAT
%60 = or i32 %59, %58
%61 = load i32, i32* @O_TRUNC
%62 = or i32 %60, %61
%63 = tail call i32 (i8*, i32, ...) @open(i8* %52, i32 %62, i32 509)
%64 = icmp slt i32 %63, 0
br i1 %64, label %65, label %72
65: ; preds = %57, %53
%66 = load i32, i32* @stderr
%67 = load i8*, i8** %51
%68 = load i32, i32* @errno
%69 = tail call i8* @strerror(i32 %68)
%70 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %66, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0), i8* %67, i8* %69)
%71 = tail call i32 @close(i32 %32)
br label %161
72: ; preds = %57
%73 = call i64 @fstat(i32 %63, %struct.stat* %5)
%74 = icmp eq i64 %73, 0
br i1 %74, label %82, label %75
75: ; preds = %72
%76 = load i32, i32* @stderr
%77 = load i32, i32* @errno
%78 = tail call i8* @strerror(i32 %77)
%79 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %76, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.5, i64 0, i64 0), i8* %78)
%80 = tail call i32 @close(i32 %32)
%81 = tail call i32 @close(i32 %63)
br label %161
82: ; preds = %53, %72
%83 = phi i32 [ %63, %72 ], [ %55, %53 ]
%84 = call i32 @memset(i8* %7, i32 0, i32 1024)
%85 = call i32 @memset(i8* %8, i32 0, i32 1024)
br i1 %18, label %107, label %86
86: ; preds = %82
%87 = getelementptr inbounds %struct.stat, %struct.stat* %5, i64 0, i32 0
%88 = load i32, i32* %87
%89 = icmp slt i32 %88, 1024
%90 = select i1 %89, i32 %88, i32 1024
%91 = call i32 (i32, ...) @read(i32 %83, i8* %7, i32 %90)
%92 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0))
%93 = call i32 (i32, ...) @write(i32 %32, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.7, i64 0, i64 0), i32 6)
%94 = getelementptr inbounds [2 x i8], [2 x i8]* %6, i64 0, i64 1
br label %95
95: ; preds = %86, %95
%96 = phi i64 [ 0, %86 ], [ %105, %95 ]
%97 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 %96
%98 = load i8, i8* %97
%99 = and i8 %98, 15
store i8 48, i8* %10
%100 = icmp ult i8 %99, 10
%101 = or i8 %99, 48
%102 = add nuw nsw i8 %99, 55
%103 = select i1 %100, i8 %101, i8 %102
store i8 %103, i8* %94
%104 = call i32 (i32, ...) @write(i32 %32, i8* %10, i32 2)
%105 = add nuw nsw i64 %96, 1
%106 = icmp eq i64 %105, 1024
br i1 %106, label %107, label %95
107: ; preds = %95, %82
%108 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.8, i64 0, i64 0))
%109 = call i32 (i32, ...) @write(i32 %32, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.9, i64 0, i64 0), i32 5)
%110 = getelementptr inbounds [2 x i8], [2 x i8]* %6, i64 0, i64 1
br label %111
111: ; preds = %107, %144
%112 = phi i64 [ 0, %107 ], [ %145, %144 ]
%113 = call i32 (i32, ...) @read(i32 %32, i8* %10, i32 2)
%114 = load i8, i8* %10
%115 = add i8 %114, -48
%116 = icmp ult i8 %115, 10
br i1 %116, label %117, label %119
117: ; preds = %111
%118 = shl i8 %114, 4
br label %125
119: ; preds = %111
%120 = add i8 %114, -65
%121 = icmp ult i8 %120, 6
br i1 %121, label %122, label %130
122: ; preds = %119
%123 = shl i8 %114, 4
%124 = add nsw i8 %123, -16
br label %125
125: ; preds = %117, %122
%126 = phi i8 [ %124, %122 ], [ %118, %117 ]
%127 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 %112
%128 = load i8, i8* %127
%129 = or i8 %128, %126
store i8 %129, i8* %127
br label %130
130: ; preds = %125, %119
%131 = load i8, i8* %110
%132 = add i8 %131, -48
%133 = icmp ult i8 %132, 10
br i1 %133, label %139, label %134
134: ; preds = %130
%135 = add i8 %114, -65
%136 = icmp ult i8 %135, 6
br i1 %136, label %137, label %144
137: ; preds = %134
%138 = add i8 %131, -65
br label %139
139: ; preds = %130, %137
%140 = phi i8 [ %138, %137 ], [ %132, %130 ]
%141 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 %112
%142 = load i8, i8* %141
%143 = or i8 %142, %140
store i8 %143, i8* %141
br label %144
144: ; preds = %139, %134
%145 = add nuw nsw i64 %112, 1
%146 = icmp eq i64 %145, 1024
br i1 %146, label %147, label %111
147: ; preds = %144
br i1 %18, label %156, label %148
148: ; preds = %147
%149 = call i64 @memcmp(i8* %8, i8* %7, i32 1024)
%150 = icmp eq i64 %149, 0
br i1 %150, label %154, label %151
151: ; preds = %148
%152 = load i32, i32* @stderr
%153 = call i32 @fputs(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.10, i64 0, i64 0), i32 %152)
br label %158
154: ; preds = %148
%155 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.11, i64 0, i64 0))
br label %158
156: ; preds = %147
%157 = call i32 (i32, ...) @write(i32 %83, i8* %8, i32 1024)
br label %158
158: ; preds = %151, %154, %156
%159 = call i32 @close(i32 %32)
%160 = call i32 @close(i32 %83)
br label %161
161: ; preds = %158, %75, %65, %44, %34, %22, %12
%162 = phi i32* [ @EXIT_SUCCESS, %12 ], [ @EXIT_SUCCESS, %22 ], [ @EXIT_FAILURE, %34 ], [ @EXIT_FAILURE, %65 ], [ @EXIT_FAILURE, %75 ], [ @EXIT_SUCCESS, %158 ], [ @EXIT_FAILURE, %44 ]
%163 = load i32, i32* %162
ret i32 %163
}