#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 timeval {
  int tv_sec;
  scalar_t__ tv_usec;
};
typedef int /*<<< orphan*/ fd_set;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int EAGAIN;
int EINTR;
int /*<<< orphan*/ FD_SET(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ FD_ZERO(int /*<<< orphan*/ *);
int /*<<< orphan*/ close(int);
int errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ fflush(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int fread(char *, int, int, int /*<<< orphan*/ *);
int fwrite(char *, int, int, int /*<<< orphan*/ *);
int open_dev(char *);
int read(int, char *, int);
int select(int, int /*<<< orphan*/ *, int /*<<< orphan*/ *,
           int /*<<< orphan*/ *, struct timeval *);
int set_parity(int, int, int, char);
int /*<<< orphan*/ set_speed(int, int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
scalar_t__ strcmp(char *, char *);
int write(int, char *, int);
int main(int argc, char **argv) {
  int fd;
  int nread = 0;
  int count = 0;
  char buf[512 * 2];
  char *sdir[] = {"tx", "rx", "loop"};
  char *dev = "/dev/ttyS0";
  char *filename = NULL;
  FILE *fp = NULL;
  int dir = 1;
  int i;
  int ret;
  if (argc < 2) {
    fprintf(stderr, "Usage: uart <-s/-r/-l> <-d devicenode> <-f filename>\n");
    exit(0);
  }
  for (i = 0; i < argc; i++) {
    if (strcmp(argv[i], "-s") == 0) {
      dir = 0;
    }
    if (strcmp(argv[i], "-r") == 0) {
      dir = 1;
    }
    if (strcmp(argv[i], "-l") == 0) {
      dir = 2;
    }
    if (strcmp(argv[i], "-d") == 0) {
      dev = argv[i + 1];
    }
    if (strcmp(argv[i], "-f") == 0) {
      filename = argv[i + 1];
    }
  }
  fprintf(stdout, "==>direction=%s(%d), filename=%s\n", sdir[dir], dir,
          filename);
  fd = open_dev(dev);
  if (fd < 0) {
    fprintf(stderr, "Can't Open Serial Port!\n");
    exit(1);
  }
  set_speed(fd, 115200);
  if (set_parity(fd, 8, 1, 'N') == (-1)) {
    fprintf(stderr, "Set Parity Error\n");
    exit(1);
  }
  fprintf(stdout, "==>%s are ready ^_^\n", dev);
  if (1 == dir) {
    fp = fopen(filename, "wb");
    if (!fp) {
      fprintf(stderr, "can't open/create file %s!\n", filename);
      exit(2);
    }
    while (1) {
      fd_set rset;
      struct timeval tv;
      FD_ZERO(&rset);
      FD_SET(fd, &rset);
      tv.tv_sec = 10;
      tv.tv_usec = 0;
      ret = select(fd + 1, &rset, NULL, NULL, &tv);
      if (-1 == ret) {
        if (EINTR == errno)
          continue;
        else {
          fprintf(stderr, "fail to select(errno=%d)\n", errno);
          goto out;
        }
      }
      if (0 == ret) {
        fprintf(stderr, "select timeout\n");
        break;
      }
      nread = read(fd, buf, 512);
      if (nread > 0) {
        ret = fwrite(buf, nread, 1, fp);
        if (ret != 1) {
          fprintf(stderr, "fail to fwrite(ret=%d, errno=%d)\n", ret, errno);
          goto out;
        }
      } else if (errno == EAGAIN) {
        continue;
      } else if (nread < 0) {
        fprintf(stderr, "fail to read (nread=%d, errno=%d)\n", nread, errno);
        goto out;
      } else {
        fprintf(stderr, "EOF or Timeout (nread=%d, errno=%d)\n", nread, errno);
        break;
      }
      count += nread;
      fflush(fp);
    }
  } else if (0 == dir) {
    fp = fopen(filename, "rb");
    if (!fp) {
      fprintf(stderr, "can't open file %s!\n", filename);
      exit(2);
    }
    while (1) {
      nread = fread(buf, 1, 512, fp);
      if (nread > 0) {
        fd_set wset;
        struct timeval tv;
        FD_ZERO(&wset);
        FD_SET(fd, &wset);
        tv.tv_sec = 10;
        tv.tv_usec = 0;
        ret = select(fd + 1, NULL, &wset, NULL, &tv);
        if (-1 == ret) {
          if (EINTR == errno)
            continue;
          else {
            fprintf(stderr, "fail to select(errno=%d)\n", errno);
            goto out;
          }
        }
        if (0 == ret) {
          fprintf(stderr, "select timeout\n");
          break;
        }
        ret = write(fd, buf, nread);
        if (ret != nread) {
          fprintf(stderr, "fail to write (nread=%d, ret=%d, errno=%d)\n", nread,
                  ret, errno);
          goto out;
        }
      } else if (feof(fp)) {
        break;
      } else {
        fprintf(stderr, "fail to fread (nread=%d, errno=%d)\n", nread, errno);
        goto out;
      }
      count += nread;
    }
  } else if (2 == dir) {
    while (1) {
      if ((nread = read(fd, buf, 512)) > 0) {
        buf[nread + 1] = '\0';
        ret = write(fd, buf, nread);
        if (ret != nread) {
          fprintf(stderr, "fail to write (nread=%d, ret=%d, errno=%d)\n", nread,
                  ret, errno);
          goto out;
        }
      } else if (errno == EAGAIN) {
        continue;
      } else {
        fprintf(stderr, "fail to read (nread=%d, errno=%d)\n", nread, errno);
      }
    }
  } else {
    fprintf(stderr, "invalid direction %s\n", sdir[dir]);
  }
  fprintf(stdout, "==>count=%d\n", count);
out:
  close(fd);
  fclose(fp);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x490,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    0x2b92(%rip),%rax
mov    %rax,-0x440(%rbp)
mov    0x2b8c(%rip),%rax
mov    %rax,-0x438(%rbp)
mov    0x2b86(%rip),%rax
mov    %rax,-0x430(%rbp)
lea    0xd93(%rip),%rax
mov    %rax,-0x448(%rbp)
movq   $0x0,-0x450(%rbp)
movq   $0x0,-0x458(%rbp)
movl   $0x1,-0x45c(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    12c7 <main+0xa7>
mov    0x2d30(%rip),%rax
mov    (%rax),%edi
lea    0xd5d(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
xor    %edi,%edi
call   1120 <exit@plt>
movl   $0x0,-0x460(%rbp)
mov    -0x460(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1406 <main+0x1e6>
mov    -0x10(%rbp),%rax
movslq -0x460(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xd56(%rip),%rsi
call   1090 <strcmp@plt>
cmp    $0x0,%rax
jne    130f <main+0xef>
movl   $0x0,-0x45c(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x460(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xd2a(%rip),%rsi
call   1090 <strcmp@plt>
cmp    $0x0,%rax
jne    133e <main+0x11e>
movl   $0x1,-0x45c(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x460(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xcfe(%rip),%rsi
call   1090 <strcmp@plt>
cmp    $0x0,%rax
jne    136d <main+0x14d>
movl   $0x2,-0x45c(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x460(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xcd2(%rip),%rsi
call   1090 <strcmp@plt>
cmp    $0x0,%rax
jne    13ad <main+0x18d>
mov    -0x10(%rbp),%rax
mov    -0x460(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x448(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x460(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xc95(%rip),%rsi
call   1090 <strcmp@plt>
cmp    $0x0,%rax
jne    13ed <main+0x1cd>
mov    -0x10(%rbp),%rax
mov    -0x460(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x450(%rbp)
jmp    13f2 <main+0x1d2>
mov    -0x460(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x460(%rbp)
jmp    12d1 <main+0xb1>
mov    0x2bbb(%rip),%rax
mov    (%rax),%edi
movslq -0x45c(%rbp),%rax
mov    -0x440(%rbp,%rax,8),%rdx
ff
mov    -0x45c(%rbp),%ecx
mov    -0x450(%rbp),%r8
lea    0xc29(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
mov    -0x448(%rbp),%rdi
call   1060 <open_dev@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    1473 <main+0x253>
mov    0x2b87(%rip),%rax
mov    (%rax),%edi
lea    0xc1b(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
mov    $0x1,%edi
call   1120 <exit@plt>
mov    -0x14(%rbp),%edi
mov    $0x1c200,%esi
call   1110 <set_speed@plt>
mov    -0x14(%rbp),%edi
mov    $0x8,%esi
mov    $0x1,%edx
mov    $0x4e,%ecx
call   10f0 <set_parity@plt>
cmp    $0xffffffff,%eax
jne    14c1 <main+0x2a1>
mov    0x2b39(%rip),%rax
mov    (%rax),%edi
lea    0xbe6(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
mov    $0x1,%edi
call   1120 <exit@plt>
mov    0x2b00(%rip),%rax
mov    (%rax),%edi
mov    -0x448(%rbp),%rdx
lea    0xbd0(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
mov    $0x1,%eax
cmp    -0x45c(%rbp),%eax
jne    172d <main+0x50d>
mov    -0x450(%rbp),%rdi
lea    0xbbf(%rip),%rsi
call   1100 <fopen@plt>
mov    %rax,-0x458(%rbp)
cmpq   $0x0,-0x458(%rbp)
jne    1540 <main+0x320>
mov    0x2ac1(%rip),%rax
mov    (%rax),%edi
mov    -0x450(%rbp),%rdx
lea    0xb91(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
mov    $0x2,%edi
call   1120 <exit@plt>
jmp    1545 <main+0x325>
lea    -0x468(%rbp),%rdi
call   10c0 <FD_ZERO@plt>
mov    -0x14(%rbp),%edi
lea    -0x468(%rbp),%rsi
call   1140 <FD_SET@plt>
movl   $0xa,-0x478(%rbp)
movq   $0x0,-0x470(%rbp)
mov    -0x14(%rbp),%edi
add    $0x1,%edi
lea    -0x468(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%ecx
lea    -0x478(%rbp),%r8
mov    %rcx,%rdx
call   10d0 <select@plt>
mov    %eax,-0x464(%rbp)
mov    $0xffffffff,%eax
cmp    -0x464(%rbp),%eax
jne    15ee <main+0x3ce>
mov    0x2a1d(%rip),%rax
mov    (%rax),%eax
mov    0x2a1c(%rip),%rcx
cmp    (%rcx),%eax
jne    15c9 <main+0x3a9>
jmp    1545 <main+0x325>
mov    0x2a10(%rip),%rax
mov    (%rax),%edi
mov    0x29ff(%rip),%rax
mov    (%rax),%edx
lea    0xafa(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
jmp    1a73 <main+0x853>
xor    %eax,%eax
cmp    -0x464(%rbp),%eax
jne    1618 <main+0x3f8>
mov    0x29dd(%rip),%rax
mov    (%rax),%edi
lea    0xaea(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
jmp    1728 <main+0x508>
mov    -0x14(%rbp),%edi
lea    -0x420(%rbp),%rsi
mov    $0x200,%edx
call   1080 <read@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jle    1697 <main+0x477>
lea    -0x420(%rbp),%rdi
mov    -0x18(%rbp),%esi
mov    -0x458(%rbp),%rcx
mov    $0x1,%edx
call   1130 <fwrite@plt>
mov    %eax,-0x464(%rbp)
cmpl   $0x1,-0x464(%rbp)
je     1692 <main+0x472>
mov    0x2972(%rip),%rax
mov    (%rax),%edi
mov    -0x464(%rbp),%edx
mov    0x295b(%rip),%rax
mov    (%rax),%ecx
lea    0xa80(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
jmp    1a73 <main+0x853>
jmp    170e <main+0x4ee>
mov    0x293a(%rip),%rax
mov    (%rax),%eax
mov    0x2911(%rip),%rcx
cmp    (%rcx),%eax
jne    16b4 <main+0x494>
jmp    1545 <main+0x325>
cmpl   $0x0,-0x18(%rbp)
jge    16e6 <main+0x4c6>
mov    0x291b(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%edx
mov    0x2907(%rip),%rax
mov    (%rax),%ecx
lea    0xa4e(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
jmp    1a73 <main+0x853>
mov    0x28f3(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%edx
mov    0x28df(%rip),%rax
mov    (%rax),%ecx
lea    0xa49(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
jmp    1728 <main+0x508>
mov    -0x18(%rbp),%eax
add    -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x458(%rbp),%rdi
call   10e0 <fflush@plt>
jmp    1545 <main+0x325>
jmp    1a59 <main+0x839>
xor    %eax,%eax
cmp    -0x45c(%rbp),%eax
jne    193e <main+0x71e>
mov    -0x450(%rbp),%rdi
lea    0xa27(%rip),%rsi
call   1100 <fopen@plt>
mov    %rax,-0x458(%rbp)
cmpq   $0x0,-0x458(%rbp)
jne    178b <main+0x56b>
mov    0x2876(%rip),%rax
mov    (%rax),%edi
mov    -0x450(%rbp),%rdx
lea    0x9f9(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
mov    $0x2,%edi
call   1120 <exit@plt>
jmp    1790 <main+0x570>
lea    -0x420(%rbp),%rdi
mov    -0x458(%rbp),%rcx
mov    $0x1,%esi
mov    $0x200,%edx
call   1030 <fread@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jle    18e8 <main+0x6c8>
lea    -0x47c(%rbp),%rdi
call   10c0 <FD_ZERO@plt>
mov    -0x14(%rbp),%edi
lea    -0x47c(%rbp),%rsi
call   1140 <FD_SET@plt>
movl   $0xa,-0x490(%rbp)
movq   $0x0,-0x488(%rbp)
mov    -0x14(%rbp),%edi
add    $0x1,%edi
xor    %eax,%eax
mov    %eax,%ecx
lea    -0x47c(%rbp),%rdx
lea    -0x490(%rbp),%r8
mov    %rcx,%rsi
call   10d0 <select@plt>
mov    %eax,-0x464(%rbp)
mov    $0xffffffff,%eax
cmp    -0x464(%rbp),%eax
jne    1863 <main+0x643>
mov    0x27a8(%rip),%rax
mov    (%rax),%eax
mov    0x27a7(%rip),%rcx
cmp    (%rcx),%eax
jne    183e <main+0x61e>
jmp    1790 <main+0x570>
mov    0x279b(%rip),%rax
mov    (%rax),%edi
mov    0x278a(%rip),%rax
mov    (%rax),%edx
lea    0x885(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
jmp    1a73 <main+0x853>
xor    %eax,%eax
cmp    -0x464(%rbp),%eax
jne    188d <main+0x66d>
mov    0x2768(%rip),%rax
mov    (%rax),%edi
lea    0x875(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
jmp    1939 <main+0x719>
mov    -0x14(%rbp),%edi
lea    -0x420(%rbp),%rsi
mov    -0x18(%rbp),%edx
call   1040 <write@plt>
mov    %eax,-0x464(%rbp)
mov    -0x464(%rbp),%eax
cmp    -0x18(%rbp),%eax
je     18e3 <main+0x6c3>
mov    0x2725(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%edx
mov    -0x464(%rbp),%ecx
mov    0x270b(%rip),%rax
mov    (%rax),%r8d
lea    0x8b1(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
jmp    1a73 <main+0x853>
jmp    192b <main+0x70b>
mov    -0x458(%rbp),%rdi
call   10b0 <feof@plt>
cmp    $0x0,%rax
je     1903 <main+0x6e3>
jmp    1939 <main+0x719>
mov    0x26d6(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%edx
mov    0x26c2(%rip),%rax
mov    (%rax),%ecx
lea    0x895(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
jmp    1a73 <main+0x853>
mov    -0x18(%rbp),%eax
add    -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
jmp    1790 <main+0x570>
jmp    1a54 <main+0x834>
mov    $0x2,%eax
cmp    -0x45c(%rbp),%eax
jne    1a29 <main+0x809>
jmp    1954 <main+0x734>
mov    -0x14(%rbp),%edi
lea    -0x420(%rbp),%rsi
mov    $0x200,%edx
call   1080 <read@plt>
mov    %eax,-0x18(%rbp)
cmp    $0x0,%eax
jle    19df <main+0x7bf>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
cltq
movb   $0x0,-0x420(%rbp,%rax,1)
mov    -0x14(%rbp),%edi
lea    -0x420(%rbp),%rsi
mov    -0x18(%rbp),%edx
call   1040 <write@plt>
mov    %eax,-0x464(%rbp)
mov    -0x464(%rbp),%eax
cmp    -0x18(%rbp),%eax
je     19da <main+0x7ba>
mov    0x262e(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%edx
mov    -0x464(%rbp),%ecx
mov    0x2614(%rip),%rax
mov    (%rax),%r8d
lea    0x7ba(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
jmp    1a73 <main+0x853>
jmp    1a24 <main+0x804>
mov    0x25f2(%rip),%rax
mov    (%rax),%eax
mov    0x25c9(%rip),%rcx
cmp    (%rcx),%eax
jne    19fc <main+0x7dc>
jmp    1954 <main+0x734>
mov    0x25dd(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%edx
mov    0x25c9(%rip),%rax
mov    (%rax),%ecx
lea    0x710(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
jmp    1a24 <main+0x804>
jmp    1954 <main+0x734>
mov    0x25b0(%rip),%rax
mov    (%rax),%edi
movslq -0x45c(%rbp),%rax
mov    -0x440(%rbp,%rax,8),%rdx
ff
lea    0x790(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
jmp    1a54 <main+0x834>
jmp    1a59 <main+0x839>
mov    0x2568(%rip),%rax
mov    (%rax),%edi
mov    -0x1c(%rbp),%edx
lea    0x782(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
mov    -0x14(%rbp),%edi
call   1070 <close@plt>
mov    -0x458(%rbp),%rdi
call   1050 <fclose@plt>
xor    %eax,%eax
add    $0x490,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x438,%rsp
cmp    $0x2,%edi
jl     1804 <main+0x5e4>
mov    %rsi,%rbx
mov    %edi,%r13d
lea    0xdc4(%rip),%rax
mov    %rax,0x10(%rsp)
lea    0xe02(%rip),%r14
lea    0xdfe(%rip),%r12
xor    %r15d,%r15d
mov    $0x1,%ebp
xor    %eax,%eax
mov    %rax,0x8(%rsp)
jmp    127c <main+0x5c>
nopl   0x0(%rax,%rax,1)
mov    %rcx,%r15
cmp    %rcx,%r13
je     1310 <main+0xf0>
mov    (%rbx,%r15,8),%rdi
lea    0xdc5(%rip),%rsi
call   1090 <strcmp@plt>
test   %rax,%rax
mov    $0x0,%eax
cmove  %eax,%ebp
mov    (%rbx,%r15,8),%rdi
lea    0xdad(%rip),%rsi
call   1090 <strcmp@plt>
test   %rax,%rax
mov    $0x1,%eax
cmove  %eax,%ebp
mov    (%rbx,%r15,8),%rdi
lea    0xd95(%rip),%rsi
call   1090 <strcmp@plt>
test   %rax,%rax
mov    $0x2,%eax
cmove  %eax,%ebp
mov    (%rbx,%r15,8),%rdi
mov    %r14,%rsi
call   1090 <strcmp@plt>
test   %rax,%rax
jne    12e8 <main+0xc8>
mov    0x8(%rbx,%r15,8),%rax
mov    %rax,0x10(%rsp)
mov    (%rbx,%r15,8),%rdi
mov    %r12,%rsi
call   1090 <strcmp@plt>
lea    0x1(%r15),%rcx
test   %rax,%rax
jne    1270 <main+0x50>
mov    0x8(%rbx,%r15,8),%rax
mov    %rax,0x8(%rsp)
jmp    1270 <main+0x50>
mov    0x2cb1(%rip),%r12
mov    (%r12),%edi
mov    %ebp,%eax
lea    0x2abc(%rip),%rcx
mov    (%rcx,%rax,8),%r14
lea    0xd2c(%rip),%rsi
mov    %r14,%rdx
mov    %ebp,%ecx
mov    0x8(%rsp),%r15
mov    %r15,%r8
xor    %eax,%eax
call   10a0 <fprintf@plt>
mov    0x10(%rsp),%r13
mov    %r13,%rdi
call   1060 <open_dev@plt>
mov    %eax,0x4(%rsp)
test   %eax,%eax
js     1822 <main+0x602>
mov    0x4(%rsp),%ebx
mov    %ebx,%edi
mov    $0x1c200,%esi
call   1110 <set_speed@plt>
mov    %ebx,%edi
mov    $0x8,%esi
mov    $0x1,%edx
mov    $0x4e,%ecx
call   10f0 <set_parity@plt>
cmp    $0xffffffff,%eax
je     1834 <main+0x614>
mov    (%r12),%edi
lea    0xd12(%rip),%rsi
mov    %r13,%rdx
xor    %eax,%eax
call   10a0 <fprintf@plt>
test   %ebp,%ebp
je     157b <main+0x35b>
cmp    $0x1,%ebp
je     142e <main+0x20e>
cmp    $0x2,%ebp
jne    1685 <main+0x465>
lea    0x30(%rsp),%rbx
mov    0x2c12(%rip),%r15
mov    0x2beb(%rip),%r14
mov    0x2c0c(%rip),%r12
lea    0xd4d(%rip),%r13
jmp    13fd <main+0x1dd>
nopl   (%rax)
mov    %ebp,%eax
movb   $0x0,0x1(%rax,%rbx,1)
mov    0x4(%rsp),%edi
mov    %rbx,%rsi
mov    %ebp,%edx
call   1040 <write@plt>
cmp    %ebp,%eax
jne    16a9 <main+0x489>
mov    0x4(%rsp),%edi
mov    %rbx,%rsi
mov    $0x200,%edx
call   1080 <read@plt>
mov    %eax,%ebp
test   %eax,%eax
jg     13e0 <main+0x1c0>
mov    (%r15),%ecx
cmp    (%r14),%ecx
je     13fd <main+0x1dd>
mov    (%r12),%edi
mov    %r13,%rsi
mov    %ebp,%edx
xor    %eax,%eax
call   10a0 <fprintf@plt>
jmp    13fd <main+0x1dd>
lea    0xc88(%rip),%rsi
mov    %r15,%rdi
call   1100 <fopen@plt>
mov    %rax,0x10(%rsp)
test   %rax,%rax
je     1855 <main+0x635>
mov    0x4(%rsp),%r12d
add    $0x1,%r12d
xor    %eax,%eax
mov    %rax,0x8(%rsp)
lea    0x1c(%rsp),%rbp
lea    0x20(%rsp),%r14
mov    0x2b6c(%rip),%r13
lea    0x30(%rsp),%r15
jmp    1493 <main+0x273>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    0x0(%r13),%edx
mov    0x2b45(%rip),%rax
cmp    %edx,(%rax)
jne    171c <main+0x4fc>
mov    %rbp,%rdi
call   10c0 <FD_ZERO@plt>
mov    0x4(%rsp),%edi
mov    %rbp,%rsi
call   1140 <FD_SET@plt>
movl   $0xa,0x20(%rsp)
movq   $0x0,0x28(%rsp)
mov    %r12d,%edi
mov    %rbp,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
mov    %r14,%r8
call   10d0 <select@plt>
cmp    $0xffffffff,%eax
je     1480 <main+0x260>
test   %eax,%eax
je     16fe <main+0x4de>
mov    0x4(%rsp),%edi
mov    %r15,%rsi
mov    $0x200,%edx
call   1080 <read@plt>
mov    %eax,%ebx
test   %eax,%eax
jle    153d <main+0x31d>
mov    %r15,%rdi
mov    %rbp,%r13
mov    %r14,%rbp
mov    %ebx,%esi
mov    $0x1,%edx
mov    0x10(%rsp),%r14
mov    %r14,%rcx
call   1130 <fwrite@plt>
cmp    $0x1,%eax
jne    1796 <main+0x576>
mov    0x8(%rsp),%rax
add    %ebx,%eax
mov    %rax,0x8(%rsp)
mov    %r14,%rdi
call   10e0 <fflush@plt>
mov    0x2aa9(%rip),%rax
mov    %rbp,%r14
mov    %r13,%rbp
mov    %rax,%r13
jmp    1493 <main+0x273>
mov    0x0(%r13),%ecx
mov    0x2a70(%rip),%rax
cmp    (%rax),%ecx
je     1493 <main+0x273>
mov    0x2a89(%rip),%rax
mov    (%rax),%edi
test   %ebx,%ebx
js     17cc <main+0x5ac>
lea    0xbe3(%rip),%rsi
xor    %edx,%edx
xor    %eax,%eax
call   10a0 <fprintf@plt>
mov    0x10(%rsp),%r14
jmp    1751 <main+0x531>
lea    0xbee(%rip),%rsi
mov    %r15,%rdi
call   1100 <fopen@plt>
test   %rax,%rax
je     1867 <main+0x647>
lea    0x30(%rsp),%rdi
mov    $0x1,%esi
mov    $0x200,%edx
mov    %rax,%r14
mov    %rax,%rcx
call   1030 <fread@plt>
mov    %eax,%ebx
test   %eax,%eax
jle    16ca <main+0x4aa>
mov    0x4(%rsp),%r12d
add    $0x1,%r12d
xor    %eax,%eax
mov    %rax,0x8(%rsp)
lea    0x1c(%rsp),%rbp
lea    0x30(%rsp),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %rbp,%rdi
call   10c0 <FD_ZERO@plt>
mov    0x4(%rsp),%edi
mov    %rbp,%rsi
call   1140 <FD_SET@plt>
movl   $0xa,0x20(%rsp)
movq   $0x0,0x28(%rsp)
mov    %r12d,%edi
xor    %esi,%esi
mov    %rbp,%rdx
xor    %ecx,%ecx
lea    0x20(%rsp),%r8
call   10d0 <select@plt>
cmp    $0xffffffff,%eax
jne    1653 <main+0x433>
mov    0x29b3(%rip),%rax
mov    (%rax),%edx
mov    0x29a2(%rip),%rax
cmp    %edx,(%rax)
jne    17ba <main+0x59a>
mov    %r15,%rdi
mov    $0x1,%esi
mov    $0x200,%edx
mov    %r14,%rcx
call   1030 <fread@plt>
mov    %eax,%ebx
test   %eax,%eax
jg     15e0 <main+0x3c0>
jmp    16d1 <main+0x4b1>
test   %eax,%eax
je     173a <main+0x51a>
mov    %r15,%r13
mov    0x4(%rsp),%edi
mov    %r15,%rsi
mov    %ebx,%edx
call   1040 <write@plt>
cmp    %ebx,%eax
jne    17e3 <main+0x5c3>
mov    0x8(%rsp),%rax
add    %ebx,%eax
mov    %rax,0x8(%rsp)
mov    %r13,%rdi
jmp    1639 <main+0x419>
mov    0x2954(%rip),%rax
mov    (%rax),%edi
lea    0xb43(%rip),%rsi
xor    %ebp,%ebp
mov    %r14,%rdx
xor    %eax,%eax
call   10a0 <fprintf@plt>
xor    %r14d,%r14d
jmp    175d <main+0x53d>
mov    (%r12),%edi
mov    (%r15),%r8d
lea    0xad1(%rip),%rsi
xor    %r14d,%r14d
mov    %ebp,%edx
mov    %eax,%ecx
xor    %eax,%eax
call   10a0 <fprintf@plt>
jmp    1771 <main+0x551>
xor    %eax,%eax
mov    %rax,0x8(%rsp)
mov    %r14,%rdi
call   10b0 <feof@plt>
test   %rax,%rax
jne    1751 <main+0x531>
mov    0x28fb(%rip),%rax
mov    (%rax),%edi
mov    0x28ea(%rip),%rax
mov    (%rax),%ecx
lea    0xabd(%rip),%rsi
mov    %ebx,%edx
jmp    17b1 <main+0x591>
mov    0x28db(%rip),%rax
mov    (%rax),%edi
lea    0x9e8(%rip),%rsi
xor    %eax,%eax
call   10a0 <fprintf@plt>
mov    0x10(%rsp),%r14
jmp    1751 <main+0x531>
mov    0x28bd(%rip),%rax
mov    (%rax),%edi
lea    0x9b0(%rip),%rsi
xor    %eax,%eax
call   10a0 <fprintf@plt>
mov    0x10(%rsp),%r14
jmp    1771 <main+0x551>
mov    0x289f(%rip),%rax
mov    (%rax),%edi
lea    0x9ac(%rip),%rsi
xor    %eax,%eax
call   10a0 <fprintf@plt>
mov    0x2870(%rip),%r12
mov    0x8(%rsp),%rbp
mov    (%r12),%edi
lea    0xa86(%rip),%rsi
mov    %ebp,%edx
xor    %eax,%eax
call   10a0 <fprintf@plt>
mov    0x4(%rsp),%edi
call   1070 <close@plt>
mov    %r14,%rdi
call   1050 <fclose@plt>
xor    %eax,%eax
add    $0x438,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2843(%rip),%rcx
mov    (%rcx),%edi
mov    0x2832(%rip),%rcx
mov    (%rcx),%ecx
lea    0x957(%rip),%rsi
mov    %eax,%edx
xor    %eax,%eax
call   10a0 <fprintf@plt>
jmp    1771 <main+0x551>
mov    0x281f(%rip),%rax
mov    (%rax),%edi
lea    0x912(%rip),%rsi
jmp    176a <main+0x54a>
lea    0x955(%rip),%rsi
mov    %ebx,%edx
xor    %eax,%eax
call   10a0 <fprintf@plt>
mov    0x10(%rsp),%r14
jmp    1771 <main+0x551>
mov    0x27f6(%rip),%rcx
mov    (%rcx),%edi
mov    0x27e5(%rip),%rcx
mov    (%rcx),%r8d
lea    0x98b(%rip),%rsi
mov    %ebx,%edx
jmp    16bc <main+0x49c>
mov    0x27d5(%rip),%rax
mov    (%rax),%edi
lea    0x802(%rip),%rsi
xor    %eax,%eax
call   10a0 <fprintf@plt>
xor    %edi,%edi
call   1120 <exit@plt>
mov    0x27b7(%rip),%rax
mov    (%rax),%edi
lea    0x84b(%rip),%rsi
jmp    1844 <main+0x624>
mov    0x27a5(%rip),%rax
mov    (%rax),%edi
lea    0x852(%rip),%rsi
xor    %eax,%eax
call   10a0 <fprintf@plt>
mov    $0x1,%edi
call   1120 <exit@plt>
mov    0x2784(%rip),%rax
mov    (%rax),%edi
lea    0x85b(%rip),%rsi
jmp    1877 <main+0x657>
mov    0x2772(%rip),%rax
mov    (%rax),%edi
lea    0x8fc(%rip),%rsi
mov    %r15,%rdx
xor    %eax,%eax
call   10a0 <fprintf@plt>
mov    $0x2,%edi
call   1120 <exit@plt>

LLVM IR (-O0):
%struct.timeval = type { i32, i64 }
@.str = [3 x i8] c"tx\00"
@.str.1 = [3 x i8] c"rx\00"
@.str.2 = [5 x i8] c"loop\00"
@__const.main.sdir = [3 x i8*] [i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i32 0, i32 0)]
@.str.3 = [11 x i8] c"/dev/ttyS0\00"
@stderr = global i32 0
@.str.4 = [54 x i8] c"Usage: uart <-s/-r/-l> <-d devicenode> <-f filename>\0A\00"
@.str.5 = [3 x i8] c"-s\00"
@.str.6 = [3 x i8] c"-r\00"
@.str.7 = [3 x i8] c"-l\00"
@.str.8 = [3 x i8] c"-d\00"
@.str.9 = [3 x i8] c"-f\00"
@stdout = global i32 0
@.str.10 = [34 x i8] c"==>direction=%s(%d), filename=%s\0A\00"
@.str.11 = [25 x i8] c"Can't Open Serial Port!\0A\00"
@.str.12 = [18 x i8] c"Set Parity Error\0A\00"
@.str.13 = [21 x i8] c"==>%s are ready ^_^\0A\00"
@.str.14 = [3 x i8] c"wb\00"
@.str.15 = [28 x i8] c"can't open/create file %s!\0A\00"
@EINTR = global i32 0
@errno = global i32 0
@.str.16 = [26 x i8] c"fail to select(errno=%d)\0A\00"
@.str.17 = [16 x i8] c"select timeout\0A\00"
@.str.18 = [34 x i8] c"fail to fwrite(ret=%d, errno=%d)\0A\00"
@EAGAIN = global i32 0
@.str.19 = [35 x i8] c"fail to read (nread=%d, errno=%d)\0A\00"
@.str.20 = [37 x i8] c"EOF or Timeout (nread=%d, errno=%d)\0A\00"
@.str.21 = [3 x i8] c"rb\00"
@.str.22 = [21 x i8] c"can't open file %s!\0A\00"
@.str.23 = [44 x i8] c"fail to write (nread=%d, ret=%d, errno=%d)\0A\00"
@.str.24 = [36 x i8] c"fail to fread (nread=%d, errno=%d)\0A\00"
@.str.25 = [22 x i8] c"invalid direction %s\0A\00"
@.str.26 = [13 x i8] c"==>count=%d\0A\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 [1024 x i8]
%10 = alloca [3 x i8*]
%11 = alloca i8*
%12 = alloca i8*
%13 = alloca i32*
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
%18 = alloca %struct.timeval
%19 = alloca i32
%20 = alloca %struct.timeval
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %7
store i32 0, i32* %8
%21 = bitcast [3 x i8*]* %10 to i8*
store i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i8** %11
store i8* null, i8** %12
store i32* null, i32** %13
store i32 1, i32* %14
%22 = load i32, i32* %4
%23 = icmp slt i32 %22, 2
br i1 %23, label %24, label %28
24: ; preds = %2
%25 = load i32, i32* @stderr
%26 = call i32 (i32, i8*, ...) @fprintf(i32 %25, i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.4, i64 0, i64 0))
%27 = call i32 @exit(i32 0)
unreachable
28: ; preds = %2
store i32 0, i32* %15
br label %29
29: ; preds = %91, %28
%30 = load i32, i32* %15
%31 = load i32, i32* %4
%32 = icmp slt i32 %30, %31
br i1 %32, label %33, label %94
33: ; preds = %29
%34 = load i8**, i8*** %5
%35 = load i32, i32* %15
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i8*, i8** %34, i64 %36
%38 = load i8*, i8** %37
%39 = call i64 @strcmp(i8* %38, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
%40 = icmp eq i64 %39, 0
br i1 %40, label %41, label %42
41: ; preds = %33
store i32 0, i32* %14
br label %42
42: ; preds = %41, %33
%43 = load i8**, i8*** %5
%44 = load i32, i32* %15
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds i8*, i8** %43, i64 %45
%47 = load i8*, i8** %46
%48 = call i64 @strcmp(i8* %47, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0))
%49 = icmp eq i64 %48, 0
br i1 %49, label %50, label %51
50: ; preds = %42
store i32 1, i32* %14
br label %51
51: ; preds = %50, %42
%52 = load i8**, i8*** %5
%53 = load i32, i32* %15
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds i8*, i8** %52, i64 %54
%56 = load i8*, i8** %55
%57 = call i64 @strcmp(i8* %56, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0))
%58 = icmp eq i64 %57, 0
br i1 %58, label %59, label %60
59: ; preds = %51
store i32 2, i32* %14
br label %60
60: ; preds = %59, %51
%61 = load i8**, i8*** %5
%62 = load i32, i32* %15
%63 = sext i32 %62 to i64
%64 = getelementptr inbounds i8*, i8** %61, i64 %63
%65 = load i8*, i8** %64
%66 = call i64 @strcmp(i8* %65, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0))
%67 = icmp eq i64 %66, 0
br i1 %67, label %68, label %75
68: ; preds = %60
%69 = load i8**, i8*** %5
%70 = load i32, i32* %15
%71 = add nsw i32 %70, 1
%72 = sext i32 %71 to i64
%73 = getelementptr inbounds i8*, i8** %69, i64 %72
%74 = load i8*, i8** %73
store i8* %74, i8** %11
br label %75
75: ; preds = %68, %60
%76 = load i8**, i8*** %5
%77 = load i32, i32* %15
%78 = sext i32 %77 to i64
%79 = getelementptr inbounds i8*, i8** %76, i64 %78
%80 = load i8*, i8** %79
%81 = call i64 @strcmp(i8* %80, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.9, i64 0, i64 0))
%82 = icmp eq i64 %81, 0
br i1 %82, label %83, label %90
83: ; preds = %75
%84 = load i8**, i8*** %5
%85 = load i32, i32* %15
%86 = add nsw i32 %85, 1
%87 = sext i32 %86 to i64
%88 = getelementptr inbounds i8*, i8** %84, i64 %87
%89 = load i8*, i8** %88
store i8* %89, i8** %12
br label %90
90: ; preds = %83, %75
br label %91
91: ; preds = %90
%92 = load i32, i32* %15
%93 = add nsw i32 %92, 1
store i32 %93, i32* %15
br label %29
94: ; preds = %29
%95 = load i32, i32* @stdout
%96 = load i32, i32* %14
%97 = sext i32 %96 to i64
%98 = getelementptr inbounds [3 x i8*], [3 x i8*]* %10, i64 0, i64 %97
%99 = load i8*, i8** %98
%100 = load i32, i32* %14
%101 = load i8*, i8** %12
%102 = call i32 (i32, i8*, ...) @fprintf(i32 %95, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.10, i64 0, i64 0), i8* %99, i32 %100, i8* %101)
%103 = load i8*, i8** %11
%104 = call i32 @open_dev(i8* %103)
store i32 %104, i32* %6
%105 = load i32, i32* %6
%106 = icmp slt i32 %105, 0
br i1 %106, label %107, label %111
107: ; preds = %94
%108 = load i32, i32* @stderr
%109 = call i32 (i32, i8*, ...) @fprintf(i32 %108, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.11, i64 0, i64 0))
%110 = call i32 @exit(i32 1)
unreachable
111: ; preds = %94
%112 = load i32, i32* %6
%113 = call i32 @set_speed(i32 %112, i32 115200)
%114 = load i32, i32* %6
%115 = call i32 @set_parity(i32 %114, i32 8, i32 1, i8 signext 78)
%116 = icmp eq i32 %115, -1
br i1 %116, label %117, label %121
117: ; preds = %111
%118 = load i32, i32* @stderr
%119 = call i32 (i32, i8*, ...) @fprintf(i32 %118, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.12, i64 0, i64 0))
%120 = call i32 @exit(i32 1)
unreachable
121: ; preds = %111
%122 = load i32, i32* @stdout
%123 = load i8*, i8** %11
%124 = call i32 (i32, i8*, ...) @fprintf(i32 %122, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.13, i64 0, i64 0), i8* %123)
%125 = load i32, i32* %14
%126 = icmp eq i32 1, %125
br i1 %126, label %127, label %208
127: ; preds = %121
%128 = load i8*, i8** %12
%129 = call i32* @fopen(i8* %128, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.14, i64 0, i64 0))
store i32* %129, i32** %13
%130 = load i32*, i32** %13
%131 = icmp ne i32* %130, null
br i1 %131, label %137, label %132
132: ; preds = %127
%133 = load i32, i32* @stderr
%134 = load i8*, i8** %12
%135 = call i32 (i32, i8*, ...) @fprintf(i32 %133, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.15, i64 0, i64 0), i8* %134)
%136 = call i32 @exit(i32 2)
unreachable
137: ; preds = %127
br label %138
138: ; preds = %137, %153, %187, %201
%139 = call i32 @FD_ZERO(i32* %17)
%140 = load i32, i32* %6
%141 = call i32 @FD_SET(i32 %140, i32* %17)
%142 = getelementptr inbounds %struct.timeval, %struct.timeval* %18, i32 0, i32 0
store i32 10, i32* %142
%143 = getelementptr inbounds %struct.timeval, %struct.timeval* %18, i32 0, i32 1
store i64 0, i64* %143
%144 = load i32, i32* %6
%145 = add nsw i32 %144, 1
%146 = call i32 @select(i32 %145, i32* %17, i32* null, i32* null, %struct.timeval* %18)
store i32 %146, i32* %16
%147 = load i32, i32* %16
%148 = icmp eq i32 -1, %147
br i1 %148, label %149, label %158
149: ; preds = %138
%150 = load i32, i32* @EINTR
%151 = load i32, i32* @errno
%152 = icmp eq i32 %150, %151
br i1 %152, label %153, label %154
153: ; preds = %149
br label %138
154: ; preds = %149
%155 = load i32, i32* @stderr
%156 = load i32, i32* @errno
%157 = call i32 (i32, i8*, ...) @fprintf(i32 %155, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.16, i64 0, i64 0), i32 %156)
br label %337
158: ; preds = %138
%159 = load i32, i32* %16
%160 = icmp eq i32 0, %159
br i1 %160, label %161, label %164
161: ; preds = %158
%162 = load i32, i32* @stderr
%163 = call i32 (i32, i8*, ...) @fprintf(i32 %162, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.17, i64 0, i64 0))
br label %207
164: ; preds = %158
%165 = load i32, i32* %6
%166 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%167 = call i32 @read(i32 %165, i8* %166, i32 512)
store i32 %167, i32* %7
%168 = load i32, i32* %7
%169 = icmp sgt i32 %168, 0
br i1 %169, label %170, label %183
170: ; preds = %164
%171 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%172 = load i32, i32* %7
%173 = load i32*, i32** %13
%174 = call i32 @fwrite(i8* %171, i32 %172, i32 1, i32* %173)
store i32 %174, i32* %16
%175 = load i32, i32* %16
%176 = icmp ne i32 %175, 1
br i1 %176, label %177, label %182
177: ; preds = %170
%178 = load i32, i32* @stderr
%179 = load i32, i32* %16
%180 = load i32, i32* @errno
%181 = call i32 (i32, i8*, ...) @fprintf(i32 %178, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.18, i64 0, i64 0), i32 %179, i32 %180)
br label %337
182: ; preds = %170
br label %201
183: ; preds = %164
%184 = load i32, i32* @errno
%185 = load i32, i32* @EAGAIN
%186 = icmp eq i32 %184, %185
br i1 %186, label %187, label %188
187: ; preds = %183
br label %138
188: ; preds = %183
%189 = load i32, i32* %7
%190 = icmp slt i32 %189, 0
br i1 %190, label %191, label %196
191: ; preds = %188
%192 = load i32, i32* @stderr
%193 = load i32, i32* %7
%194 = load i32, i32* @errno
%195 = call i32 (i32, i8*, ...) @fprintf(i32 %192, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.19, i64 0, i64 0), i32 %193, i32 %194)
br label %337
196: ; preds = %188
%197 = load i32, i32* @stderr
%198 = load i32, i32* %7
%199 = load i32, i32* @errno
%200 = call i32 (i32, i8*, ...) @fprintf(i32 %197, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.20, i64 0, i64 0), i32 %198, i32 %199)
br label %207
201: ; preds = %182
%202 = load i32, i32* %7
%203 = load i32, i32* %8
%204 = add nsw i32 %203, %202
store i32 %204, i32* %8
%205 = load i32*, i32** %13
%206 = call i32 @fflush(i32* %205)
br label %138
207: ; preds = %196, %161
br label %333
208: ; preds = %121
%209 = load i32, i32* %14
%210 = icmp eq i32 0, %209
br i1 %210, label %211, label %284
211: ; preds = %208
%212 = load i8*, i8** %12
%213 = call i32* @fopen(i8* %212, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.21, i64 0, i64 0))
store i32* %213, i32** %13
%214 = load i32*, i32** %13
%215 = icmp ne i32* %214, null
br i1 %215, label %221, label %216
216: ; preds = %211
%217 = load i32, i32* @stderr
%218 = load i8*, i8** %12
%219 = call i32 (i32, i8*, ...) @fprintf(i32 %217, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.22, i64 0, i64 0), i8* %218)
%220 = call i32 @exit(i32 2)
unreachable
221: ; preds = %211
br label %222
222: ; preds = %221, %243, %279
%223 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%224 = load i32*, i32** %13
%225 = call i32 @fread(i8* %223, i32 1, i32 512, i32* %224)
store i32 %225, i32* %7
%226 = load i32, i32* %7
%227 = icmp sgt i32 %226, 0
br i1 %227, label %228, label %269
228: ; preds = %222
%229 = call i32 @FD_ZERO(i32* %19)
%230 = load i32, i32* %6
%231 = call i32 @FD_SET(i32 %230, i32* %19)
%232 = getelementptr inbounds %struct.timeval, %struct.timeval* %20, i32 0, i32 0
store i32 10, i32* %232
%233 = getelementptr inbounds %struct.timeval, %struct.timeval* %20, i32 0, i32 1
store i64 0, i64* %233
%234 = load i32, i32* %6
%235 = add nsw i32 %234, 1
%236 = call i32 @select(i32 %235, i32* null, i32* %19, i32* null, %struct.timeval* %20)
store i32 %236, i32* %16
%237 = load i32, i32* %16
%238 = icmp eq i32 -1, %237
br i1 %238, label %239, label %248
239: ; preds = %228
%240 = load i32, i32* @EINTR
%241 = load i32, i32* @errno
%242 = icmp eq i32 %240, %241
br i1 %242, label %243, label %244
243: ; preds = %239
br label %222
244: ; preds = %239
%245 = load i32, i32* @stderr
%246 = load i32, i32* @errno
%247 = call i32 (i32, i8*, ...) @fprintf(i32 %245, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.16, i64 0, i64 0), i32 %246)
br label %337
248: ; preds = %228
%249 = load i32, i32* %16
%250 = icmp eq i32 0, %249
br i1 %250, label %251, label %254
251: ; preds = %248
%252 = load i32, i32* @stderr
%253 = call i32 (i32, i8*, ...) @fprintf(i32 %252, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.17, i64 0, i64 0))
br label %283
254: ; preds = %248
%255 = load i32, i32* %6
%256 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%257 = load i32, i32* %7
%258 = call i32 @write(i32 %255, i8* %256, i32 %257)
store i32 %258, i32* %16
%259 = load i32, i32* %16
%260 = load i32, i32* %7
%261 = icmp ne i32 %259, %260
br i1 %261, label %262, label %268
262: ; preds = %254
%263 = load i32, i32* @stderr
%264 = load i32, i32* %7
%265 = load i32, i32* %16
%266 = load i32, i32* @errno
%267 = call i32 (i32, i8*, ...) @fprintf(i32 %263, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.23, i64 0, i64 0), i32 %264, i32 %265, i32 %266)
br label %337
268: ; preds = %254
br label %279
269: ; preds = %222
%270 = load i32*, i32** %13
%271 = call i64 @feof(i32* %270)
%272 = icmp ne i64 %271, 0
br i1 %272, label %273, label %274
273: ; preds = %269
br label %283
274: ; preds = %269
%275 = load i32, i32* @stderr
%276 = load i32, i32* %7
%277 = load i32, i32* @errno
%278 = call i32 (i32, i8*, ...) @fprintf(i32 %275, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.24, i64 0, i64 0), i32 %276, i32 %277)
br label %337
279: ; preds = %268
%280 = load i32, i32* %7
%281 = load i32, i32* %8
%282 = add nsw i32 %281, %280
store i32 %282, i32* %8
br label %222
283: ; preds = %273, %251
br label %332
284: ; preds = %208
%285 = load i32, i32* %14
%286 = icmp eq i32 2, %285
br i1 %286, label %287, label %324
287: ; preds = %284
br label %288
288: ; preds = %287, %316, %323
%289 = load i32, i32* %6
%290 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%291 = call i32 @read(i32 %289, i8* %290, i32 512)
store i32 %291, i32* %7
%292 = icmp sgt i32 %291, 0
br i1 %292, label %293, label %312
293: ; preds = %288
%294 = load i32, i32* %7
%295 = add nsw i32 %294, 1
%296 = sext i32 %295 to i64
%297 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 %296
store i8 0, i8* %297
%298 = load i32, i32* %6
%299 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%300 = load i32, i32* %7
%301 = call i32 @write(i32 %298, i8* %299, i32 %300)
store i32 %301, i32* %16
%302 = load i32, i32* %16
%303 = load i32, i32* %7
%304 = icmp ne i32 %302, %303
br i1 %304, label %305, label %311
305: ; preds = %293
%306 = load i32, i32* @stderr
%307 = load i32, i32* %7
%308 = load i32, i32* %16
%309 = load i32, i32* @errno
%310 = call i32 (i32, i8*, ...) @fprintf(i32 %306, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.23, i64 0, i64 0), i32 %307, i32 %308, i32 %309)
br label %337
311: ; preds = %293
br label %323
312: ; preds = %288
%313 = load i32, i32* @errno
%314 = load i32, i32* @EAGAIN
%315 = icmp eq i32 %313, %314
br i1 %315, label %316, label %317
316: ; preds = %312
br label %288
317: ; preds = %312
%318 = load i32, i32* @stderr
%319 = load i32, i32* %7
%320 = load i32, i32* @errno
%321 = call i32 (i32, i8*, ...) @fprintf(i32 %318, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.19, i64 0, i64 0), i32 %319, i32 %320)
br label %322
322: ; preds = %317
br label %323
323: ; preds = %322, %311
br label %288
324: ; preds = %284
%325 = load i32, i32* @stderr
%326 = load i32, i32* %14
%327 = sext i32 %326 to i64
%328 = getelementptr inbounds [3 x i8*], [3 x i8*]* %10, i64 0, i64 %327
%329 = load i8*, i8** %328
%330 = call i32 (i32, i8*, ...) @fprintf(i32 %325, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.25, i64 0, i64 0), i8* %329)
br label %331
331: ; preds = %324
br label %332
332: ; preds = %331, %283
br label %333
333: ; preds = %332, %207
%334 = load i32, i32* @stdout
%335 = load i32, i32* %8
%336 = call i32 (i32, i8*, ...) @fprintf(i32 %334, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.26, i64 0, i64 0), i32 %335)
br label %337
337: ; preds = %333, %305, %274, %262, %244, %191, %177, %154
%338 = load i32, i32* %6
%339 = call i32 @close(i32 %338)
%340 = load i32*, i32** %13
%341 = call i32 @fclose(i32* %340)
ret i32 0
}

LLVM IR (-O2):
%struct.timeval = type { i32, i64 }
@.str = [3 x i8] c"tx\00"
@.str.1 = [3 x i8] c"rx\00"
@.str.2 = [5 x i8] c"loop\00"
@__const.main.sdir = [3 x i8*] [i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i32 0, i32 0)]
@.str.3 = [11 x i8] c"/dev/ttyS0\00"
@stderr = global i32 0
@.str.4 = [54 x i8] c"Usage: uart <-s/-r/-l> <-d devicenode> <-f filename>\0A\00"
@.str.5 = [3 x i8] c"-s\00"
@.str.6 = [3 x i8] c"-r\00"
@.str.7 = [3 x i8] c"-l\00"
@.str.8 = [3 x i8] c"-d\00"
@.str.9 = [3 x i8] c"-f\00"
@stdout = global i32 0
@.str.10 = [34 x i8] c"==>direction=%s(%d), filename=%s\0A\00"
@.str.11 = [25 x i8] c"Can't Open Serial Port!\0A\00"
@.str.12 = [18 x i8] c"Set Parity Error\0A\00"
@.str.13 = [21 x i8] c"==>%s are ready ^_^\0A\00"
@.str.14 = [3 x i8] c"wb\00"
@.str.15 = [28 x i8] c"can't open/create file %s!\0A\00"
@EINTR = global i32 0
@errno = global i32 0
@.str.16 = [26 x i8] c"fail to select(errno=%d)\0A\00"
@.str.17 = [16 x i8] c"select timeout\0A\00"
@.str.18 = [34 x i8] c"fail to fwrite(ret=%d, errno=%d)\0A\00"
@EAGAIN = global i32 0
@.str.19 = [35 x i8] c"fail to read (nread=%d, errno=%d)\0A\00"
@.str.20 = [37 x i8] c"EOF or Timeout (nread=%d, errno=%d)\0A\00"
@.str.21 = [3 x i8] c"rb\00"
@.str.22 = [21 x i8] c"can't open file %s!\0A\00"
@.str.23 = [44 x i8] c"fail to write (nread=%d, ret=%d, errno=%d)\0A\00"
@.str.24 = [36 x i8] c"fail to fread (nread=%d, errno=%d)\0A\00"
@.str.25 = [22 x i8] c"invalid direction %s\0A\00"
@.str.26 = [13 x i8] c"==>count=%d\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [1024 x i8]
%4 = alloca i32
%5 = alloca %struct.timeval
%6 = alloca i32
%7 = alloca %struct.timeval
%8 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%9 = icmp slt i32 %0, 2
br i1 %9, label %12, label %10
10: ; preds = %2
%11 = zext i32 %0 to i64
br label %16
12: ; preds = %2
%13 = load i32, i32* @stderr
%14 = tail call i32 (i32, i8*, ...) @fprintf(i32 %13, i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.4, i64 0, i64 0))
%15 = tail call i32 @exit(i32 0)
unreachable
16: ; preds = %10, %50
%17 = phi i64 [ 0, %10 ], [ %46, %50 ]
%18 = phi i32 [ 1, %10 ], [ %33, %50 ]
%19 = phi i8* [ null, %10 ], [ %51, %50 ]
%20 = phi i8* [ getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), %10 ], [ %42, %50 ]
%21 = getelementptr inbounds i8*, i8** %1, i64 %17
%22 = load i8*, i8** %21
%23 = tail call i64 @strcmp(i8* %22, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
%24 = icmp eq i64 %23, 0
%25 = select i1 %24, i32 0, i32 %18
%26 = load i8*, i8** %21
%27 = tail call i64 @strcmp(i8* %26, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0))
%28 = icmp eq i64 %27, 0
%29 = select i1 %28, i32 1, i32 %25
%30 = load i8*, i8** %21
%31 = tail call i64 @strcmp(i8* %30, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0))
%32 = icmp eq i64 %31, 0
%33 = select i1 %32, i32 2, i32 %29
%34 = load i8*, i8** %21
%35 = tail call i64 @strcmp(i8* %34, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0))
%36 = icmp eq i64 %35, 0
br i1 %36, label %37, label %41
37: ; preds = %16
%38 = add nuw nsw i64 %17, 1
%39 = getelementptr inbounds i8*, i8** %1, i64 %38
%40 = load i8*, i8** %39
br label %41
41: ; preds = %37, %16
%42 = phi i8* [ %40, %37 ], [ %20, %16 ]
%43 = load i8*, i8** %21
%44 = tail call i64 @strcmp(i8* %43, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.9, i64 0, i64 0))
%45 = icmp eq i64 %44, 0
%46 = add nuw nsw i64 %17, 1
br i1 %45, label %47, label %50
47: ; preds = %41
%48 = getelementptr inbounds i8*, i8** %1, i64 %46
%49 = load i8*, i8** %48
br label %50
50: ; preds = %41, %47
%51 = phi i8* [ %49, %47 ], [ %19, %41 ]
%52 = icmp eq i64 %46, %11
br i1 %52, label %53, label %16
53: ; preds = %50
%54 = load i32, i32* @stdout
%55 = zext i32 %33 to i64
%56 = getelementptr inbounds [3 x i8*], [3 x i8*]* @__const.main.sdir, i64 0, i64 %55
%57 = load i8*, i8** %56
%58 = tail call i32 (i32, i8*, ...) @fprintf(i32 %54, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.10, i64 0, i64 0), i8* %57, i32 %33, i8* %51)
%59 = tail call i32 @open_dev(i8* %42)
%60 = icmp slt i32 %59, 0
br i1 %60, label %61, label %65
61: ; preds = %53
%62 = load i32, i32* @stderr
%63 = tail call i32 (i32, i8*, ...) @fprintf(i32 %62, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.11, i64 0, i64 0))
%64 = tail call i32 @exit(i32 1)
unreachable
65: ; preds = %53
%66 = tail call i32 @set_speed(i32 %59, i32 115200)
%67 = tail call i32 @set_parity(i32 %59, i32 8, i32 1, i8 signext 78)
%68 = icmp eq i32 %67, -1
br i1 %68, label %69, label %73
69: ; preds = %65
%70 = load i32, i32* @stderr
%71 = tail call i32 (i32, i8*, ...) @fprintf(i32 %70, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.12, i64 0, i64 0))
%72 = tail call i32 @exit(i32 1)
unreachable
73: ; preds = %65
%74 = load i32, i32* @stdout
%75 = tail call i32 (i32, i8*, ...) @fprintf(i32 %74, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.13, i64 0, i64 0), i8* %42)
switch i32 %33, label %211 [
i32 1, label %76
i32 0, label %132
i32 2, label %190
]
76: ; preds = %73
%77 = tail call i32* @fopen(i8* %51, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.14, i64 0, i64 0))
%78 = icmp eq i32* %77, null
br i1 %78, label %85, label %79
79: ; preds = %76
%80 = bitcast i32* %4 to i8*
%81 = bitcast %struct.timeval* %5 to i8*
%82 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i64 0, i32 0
%83 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i64 0, i32 1
%84 = add nuw nsw i32 %59, 1
br label %89
85: ; preds = %76
%86 = load i32, i32* @stderr
%87 = tail call i32 (i32, i8*, ...) @fprintf(i32 %86, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.15, i64 0, i64 0), i8* %51)
%88 = tail call i32 @exit(i32 2)
unreachable
89: ; preds = %79, %130
%90 = phi i32 [ %131, %130 ], [ 0, %79 ]
%91 = call i32 @FD_ZERO(i32* %4)
%92 = call i32 @FD_SET(i32 %59, i32* %4)
store i32 10, i32* %82
store i64 0, i64* %83
%93 = call i32 @select(i32 %84, i32* %4, i32* null, i32* null, %struct.timeval* %5)
switch i32 %93, label %104 [
i32 -1, label %94
i32 0, label %101
]
94: ; preds = %89
%95 = load i32, i32* @EINTR
%96 = load i32, i32* @errno
%97 = icmp eq i32 %95, %96
br i1 %97, label %130, label %98
98: ; preds = %94
%99 = load i32, i32* @stderr
%100 = call i32 (i32, i8*, ...) @fprintf(i32 %99, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.16, i64 0, i64 0), i32 %96)
br label %128
101: ; preds = %89
%102 = load i32, i32* @stderr
%103 = call i32 (i32, i8*, ...) @fprintf(i32 %102, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.17, i64 0, i64 0))
br label %129
104: ; preds = %89
%105 = call i32 @read(i32 %59, i8* %8, i32 512)
%106 = icmp sgt i32 %105, 0
br i1 %106, label %107, label %114
107: ; preds = %104
%108 = call i32 @fwrite(i8* %8, i32 %105, i32 1, i32* %77)
%109 = icmp eq i32 %108, 1
br i1 %109, label %125, label %110
110: ; preds = %107
%111 = load i32, i32* @stderr
%112 = load i32, i32* @errno
%113 = call i32 (i32, i8*, ...) @fprintf(i32 %111, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.18, i64 0, i64 0), i32 %108, i32 %112)
br label %128
114: ; preds = %104
%115 = load i32, i32* @errno
%116 = load i32, i32* @EAGAIN
%117 = icmp eq i32 %115, %116
br i1 %117, label %130, label %118
118: ; preds = %114
%119 = icmp slt i32 %105, 0
%120 = load i32, i32* @stderr
br i1 %119, label %121, label %123
121: ; preds = %118
%122 = call i32 (i32, i8*, ...) @fprintf(i32 %120, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.19, i64 0, i64 0), i32 %105, i32 %115)
br label %128
123: ; preds = %118
%124 = call i32 (i32, i8*, ...) @fprintf(i32 %120, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.20, i64 0, i64 0), i32 0, i32 %115)
br label %129
125: ; preds = %107
%126 = add nsw i32 %105, %90
%127 = call i32 @fflush(i32* %77)
br label %130
128: ; preds = %98, %110, %121
br label %219
129: ; preds = %101, %123
br label %214
130: ; preds = %114, %94, %125
%131 = phi i32 [ %126, %125 ], [ %90, %94 ], [ %90, %114 ]
br label %89
132: ; preds = %73
%133 = tail call i32* @fopen(i8* %51, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.21, i64 0, i64 0))
%134 = icmp eq i32* %133, null
br i1 %134, label %144, label %135
135: ; preds = %132
%136 = call i32 @fread(i8* %8, i32 1, i32 512, i32* %133)
%137 = icmp sgt i32 %136, 0
br i1 %137, label %138, label %174
138: ; preds = %135
%139 = bitcast i32* %6 to i8*
%140 = bitcast %struct.timeval* %7 to i8*
%141 = getelementptr inbounds %struct.timeval, %struct.timeval* %7, i64 0, i32 0
%142 = getelementptr inbounds %struct.timeval, %struct.timeval* %7, i64 0, i32 1
%143 = add nuw nsw i32 %59, 1
br label %187
144: ; preds = %132
%145 = load i32, i32* @stderr
%146 = tail call i32 (i32, i8*, ...) @fprintf(i32 %145, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.22, i64 0, i64 0), i8* %51)
%147 = tail call i32 @exit(i32 2)
unreachable
148: ; preds = %187, %171
%149 = phi i32 [ %188, %187 ], [ %172, %171 ]
%150 = call i32 @FD_ZERO(i32* %6)
%151 = call i32 @FD_SET(i32 %59, i32* %6)
store i32 10, i32* %141
store i64 0, i64* %142
%152 = call i32 @select(i32 %143, i32* null, i32* %6, i32* null, %struct.timeval* %7)
switch i32 %152, label %163 [
i32 -1, label %153
i32 0, label %160
]
153: ; preds = %148
%154 = load i32, i32* @EINTR
%155 = load i32, i32* @errno
%156 = icmp eq i32 %154, %155
br i1 %156, label %171, label %157
157: ; preds = %153
%158 = load i32, i32* @stderr
%159 = call i32 (i32, i8*, ...) @fprintf(i32 %158, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.16, i64 0, i64 0), i32 %155)
br label %170
160: ; preds = %148
%161 = load i32, i32* @stderr
%162 = call i32 (i32, i8*, ...) @fprintf(i32 %161, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.17, i64 0, i64 0))
br label %214
163: ; preds = %148
%164 = call i32 @write(i32 %59, i8* %8, i32 %149)
%165 = icmp eq i32 %164, %149
br i1 %165, label %183, label %166
166: ; preds = %163
%167 = load i32, i32* @stderr
%168 = load i32, i32* @errno
%169 = call i32 (i32, i8*, ...) @fprintf(i32 %167, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.23, i64 0, i64 0), i32 %149, i32 %164, i32 %168)
br label %170
170: ; preds = %157, %166
br label %219
171: ; preds = %153
%172 = call i32 @fread(i8* %8, i32 1, i32 512, i32* %133)
%173 = icmp sgt i32 %172, 0
br i1 %173, label %148, label %174
174: ; preds = %183, %171, %135
%175 = phi i32 [ 0, %135 ], [ %189, %171 ], [ %184, %183 ]
%176 = phi i32 [ %136, %135 ], [ %172, %171 ], [ %185, %183 ]
%177 = call i64 @feof(i32* %133)
%178 = icmp eq i64 %177, 0
br i1 %178, label %179, label %214
179: ; preds = %174
%180 = load i32, i32* @stderr
%181 = load i32, i32* @errno
%182 = call i32 (i32, i8*, ...) @fprintf(i32 %180, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.24, i64 0, i64 0), i32 %176, i32 %181)
br label %219
183: ; preds = %163
%184 = add nsw i32 %149, %189
%185 = call i32 @fread(i8* %8, i32 1, i32 512, i32* %133)
%186 = icmp sgt i32 %185, 0
br i1 %186, label %187, label %174
187: ; preds = %138, %183
%188 = phi i32 [ %136, %138 ], [ %185, %183 ]
%189 = phi i32 [ 0, %138 ], [ %184, %183 ]
br label %148
190: ; preds = %73, %210
%191 = call i32 @read(i32 %59, i8* %8, i32 512)
%192 = icmp sgt i32 %191, 0
br i1 %192, label %193, label %203
193: ; preds = %190
%194 = add nuw nsw i32 %191, 1
%195 = zext i32 %194 to i64
%196 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 %195
store i8 0, i8* %196
%197 = call i32 @write(i32 %59, i8* %8, i32 %191)
%198 = icmp eq i32 %197, %191
br i1 %198, label %210, label %199
199: ; preds = %193
%200 = load i32, i32* @stderr
%201 = load i32, i32* @errno
%202 = tail call i32 (i32, i8*, ...) @fprintf(i32 %200, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.23, i64 0, i64 0), i32 %191, i32 %197, i32 %201)
br label %219
203: ; preds = %190
%204 = load i32, i32* @errno
%205 = load i32, i32* @EAGAIN
%206 = icmp eq i32 %204, %205
br i1 %206, label %210, label %207
207: ; preds = %203
%208 = load i32, i32* @stderr
%209 = tail call i32 (i32, i8*, ...) @fprintf(i32 %208, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.19, i64 0, i64 0), i32 %191, i32 %204)
br label %210
210: ; preds = %207, %193, %203
br label %190
211: ; preds = %73
%212 = load i32, i32* @stderr
%213 = tail call i32 (i32, i8*, ...) @fprintf(i32 %212, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.25, i64 0, i64 0), i8* %57)
br label %214
214: ; preds = %160, %129, %211, %174
%215 = phi i32 [ %175, %174 ], [ 0, %211 ], [ %90, %129 ], [ %189, %160 ]
%216 = phi i32* [ %133, %174 ], [ null, %211 ], [ %77, %129 ], [ %133, %160 ]
%217 = load i32, i32* @stdout
%218 = call i32 (i32, i8*, ...) @fprintf(i32 %217, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.26, i64 0, i64 0), i32 %215)
br label %219
219: ; preds = %179, %199, %214, %128, %170
%220 = phi i32* [ %216, %214 ], [ %133, %179 ], [ null, %199 ], [ %77, %128 ], [ %133, %170 ]
%221 = call i32 @close(i32 %59)
%222 = call i32 @fclose(i32* %220)
ret i32 0
}