#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 */
typedef struct TYPE_2__ TYPE_1__;

/* Type definitions */
struct stat {
  int st_size;
};
struct sockaddr_in {
  int /*<<< orphan*/ sin_port;
  int /*<<< orphan*/ sin_addr;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
struct TYPE_2__ {
  int fd;
};
struct epoll_event {
  int events;
  TYPE_1__ data;
};
typedef int /*<<< orphan*/ serveraddr;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int ECONNRESET;
int EISCONN;
int EPOLLET;
int EPOLLIN;
int EPOLLOUT;
int /*<<< orphan*/ EPOLL_CTL_ADD;
int /*<<< orphan*/ EPOLL_CTL_MOD;
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ SOCK_STREAM;
int atoi(char *);
int /*<<< orphan*/ bzero(struct sockaddr_in *, int);
int /*<<< orphan*/ close(int);
int connect(int, struct sockaddr *, int);
int epoll_create(int);
int /*<<< orphan*/ epoll_ctl(int, int /*<<< orphan*/, int,
                             struct epoll_event *);
int epoll_wait(int, struct epoll_event *, int, int);
int errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ inet_aton(char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int read(int, char *, int);
int /*<<< orphan*/ setnonblocking(int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stat(char *, struct stat *);
int /*<<< orphan*/ stderr;
int write(int, char *, int);
int main(int argc, char *argv[]) {
  int portnumber;
  if (2 == argc) {
    if ((portnumber = atoi(argv[1])) < 0) {
      fprintf(stderr, "Usage:%s portnumber\a\n", argv[0]);
      return 1;
    }
  } else {
    fprintf(stderr, "Usage:%s portnumber\a\n", argv[0]);
    return 1;
  }
  struct sockaddr_in serveraddr;
  int fd = socket(AF_INET, SOCK_STREAM, 0);
  bzero(&serveraddr, sizeof(serveraddr));
  serveraddr.sin_family = AF_INET;
  char *local_addr = "127.0.0.1";
  inet_aton(local_addr, &(serveraddr.sin_addr));
  serveraddr.sin_port = htons(portnumber);
  if (-1 == connect(fd, (struct sockaddr *)&serveraddr, sizeof(serveraddr))) {
    printf("connect error %d\n", errno);
    printf("EISCONN %d\n", EISCONN);
    perror("connect");
    close(fd);
    exit(EXIT_FAILURE);
  }
  int epfd;
  struct epoll_event event;
  epfd = epoll_create(256);
  setnonblocking(fd);
  event.data.fd = fd;
  event.events = EPOLLIN | EPOLLOUT | EPOLLET;
  epoll_ctl(epfd, EPOLL_CTL_ADD, fd, &event);
  char *filepath = "test.txt";
  FILE *pf = fopen(filepath, "r");
  if (pf == NULL) {
    perror("fopen: ");
    return -1;
  }
  char buffer[(1024 * 16)], read_buffer[(1024 * 16)];
  int write_size = 0, filesize;
  struct stat st;
  stat(filepath, &st);
  filesize = st.st_size;
  int i, n, sockfd, nfds;
  printf("file %s size is %d\n", filepath, filesize);
  for (;;) {
    printf("total write size is %d\n", write_size);
    nfds = epoll_wait(epfd, &event, 1, 500);
    for (i = 0; i < nfds; ++i) {
      if ((sockfd = event.data.fd) < 0)
        continue;
      if (event.events & EPOLLIN) {
        printf("EPOLLIN\t");
        if ((n = read(sockfd, read_buffer, (1024 * 16))) < 0) {
          if (errno == ECONNRESET) {
            close(sockfd);
            event.data.fd = -1;
          } else
            printf("socket %d readline error\n", sockfd);
        } else if (n == 0) {
          close(sockfd);
          event.data.fd = -1;
        }
        printf("read %d bytes from socket %d\n", n, sockfd);
        event.data.fd = sockfd;
        event.events = EPOLLOUT;
        epoll_ctl(epfd, EPOLL_CTL_MOD, sockfd, &event);
      }
      if (event.events & EPOLLOUT) {
        n = fread(buffer, 1, (1024 * 16), pf);
        printf("read %d bytes from file %s\n", n, filepath);
        if (n > 0) {
          write_size += n;
          n = write(sockfd, buffer, n);
          if (n < 0) {
            if (errno == ECONNRESET) {
              close(sockfd);
              event.data.fd = -1;
            } else {
              printf("socket %d write error\n", sockfd);
              write_size = filesize;
              break;
            }
          }
          printf("write %d bytes to socket %d\n", n, sockfd);
        } else {
          write_size = filesize;
        }
        event.data.fd = sockfd;
        event.events = EPOLLIN | EPOLLET;
        epoll_ctl(epfd, EPOLL_CTL_MOD, sockfd, &event);
      }
      if (write_size >= filesize) {
        printf("write whole file, change events\n");
        event.data.fd = sockfd;
        event.events = EPOLLIN | EPOLLET;
        epoll_ctl(epfd, EPOLL_CTL_MOD, sockfd, &event);
      }
    }
    if (write_size >= filesize) {
      printf("write whole file, exit\n");
      break;
    }
  }
  printf("total write size is %d\n", write_size);
  close(epfd);
  fclose(pf);
  close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x8070,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x2,%eax
cmp    -0x8(%rbp),%eax
jne    12bd <main+0x6d>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1130 <atoi@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    12b8 <main+0x68>
mov    0x2d19(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xd59(%rip),%rsi
call   10b0 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1809 <main+0x5b9>
jmp    12e5 <main+0x95>
mov    0x2cec(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xd2c(%rip),%rsi
call   10b0 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1809 <main+0x5b9>
mov    0x2cfc(%rip),%rax
mov    (%rax),%edi
mov    0x2cb3(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1170 <socket@plt>
mov    %eax,-0x24(%rbp)
lea    -0x20(%rbp),%rdi
mov    $0xc,%esi
call   1120 <bzero@plt>
mov    0x2cd2(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
lea    0xcf4(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
lea    -0x20(%rbp),%rsi
add    $0x4,%rsi
call   10d0 <inet_aton@plt>
mov    -0x14(%rbp),%edi
call   1060 <htons@plt>
mov    %eax,-0x20(%rbp)
mov    -0x24(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0xc,%edx
call   1160 <connect@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    %ecx,%eax
jne    13b2 <main+0x162>
mov    0x2c2f(%rip),%rax
mov    (%rax),%esi
lea    0xcae(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    0x2c50(%rip),%rax
mov    (%rax),%esi
lea    0xca9(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    0xca7(%rip),%rdi
call   1110 <perror@plt>
mov    -0x24(%rbp),%edi
call   1080 <close@plt>
mov    0x2be5(%rip),%rax
mov    (%rax),%edi
call   1150 <exit@plt>
mov    $0x100,%edi
call   1140 <epoll_create@plt>
mov    %eax,-0x34(%rbp)
mov    -0x24(%rbp),%edi
call   10f0 <setnonblocking@plt>
mov    -0x24(%rbp),%eax
mov    %eax,-0x3c(%rbp)
mov    0x2c0c(%rip),%rax
mov    (%rax),%eax
mov    0x2bc3(%rip),%rcx
or     (%rcx),%eax
mov    0x2ba2(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x40(%rbp)
mov    -0x34(%rbp),%edi
mov    0x2be3(%rip),%rax
mov    (%rax),%esi
mov    -0x24(%rbp),%edx
lea    -0x40(%rbp),%rcx
call   1090 <epoll_ctl@plt>
lea    0xc3c(%rip),%rax
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rdi
lea    0xc36(%rip),%rsi
call   1100 <fopen@plt>
mov    %rax,-0x50(%rbp)
cmpq   $0x0,-0x50(%rbp)
jne    1445 <main+0x1f5>
lea    0xc1d(%rip),%rdi
call   1110 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1809 <main+0x5b9>
movl   $0x0,-0x8054(%rbp)
mov    -0x48(%rbp),%rdi
lea    -0x8060(%rbp),%rsi
call   10c0 <stat@plt>
mov    -0x8060(%rbp),%eax
mov    %eax,-0x8058(%rbp)
mov    -0x48(%rbp),%rsi
mov    -0x8058(%rbp),%edx
lea    0xbdd(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x8054(%rbp),%esi
lea    0xbdd(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x34(%rbp),%edi
lea    -0x40(%rbp),%rsi
mov    $0x1,%edx
mov    $0x1f4,%ecx
call   10e0 <epoll_wait@plt>
mov    %eax,-0x8070(%rbp)
movl   $0x0,-0x8064(%rbp)
mov    -0x8064(%rbp),%eax
cmp    -0x8070(%rbp),%eax
jge    17ab <main+0x55b>
mov    -0x3c(%rbp),%eax
mov    %eax,-0x806c(%rbp)
cmp    $0x0,%eax
jge    14e6 <main+0x296>
jmp    1797 <main+0x547>
mov    -0x40(%rbp),%eax
mov    0x2af0(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     15e5 <main+0x395>
lea    0xb83(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x806c(%rbp),%edi
lea    -0x8050(%rbp),%rsi
mov    $0x4000,%edx
call   10a0 <read@plt>
mov    %eax,-0x8068(%rbp)
cmp    $0x0,%eax
jge    1577 <main+0x327>
mov    0x2a62(%rip),%rax
mov    (%rax),%eax
mov    0x2a81(%rip),%rcx
cmp    (%rcx),%eax
jne    155e <main+0x30e>
mov    -0x806c(%rbp),%edi
call   1080 <close@plt>
movl   $0xffffffff,-0x3c(%rbp)
jmp    1572 <main+0x322>
mov    -0x806c(%rbp),%esi
lea    0xb23(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
jmp    159b <main+0x34b>
cmpl   $0x0,-0x8068(%rbp)
jne    1596 <main+0x346>
mov    -0x806c(%rbp),%edi
call   1080 <close@plt>
movl   $0xffffffff,-0x3c(%rbp)
jmp    159b <main+0x34b>
mov    -0x8068(%rbp),%esi
mov    -0x806c(%rbp),%edx
lea    0xafa(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x806c(%rbp),%eax
mov    %eax,-0x3c(%rbp)
mov    0x29db(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x40(%rbp)
mov    -0x34(%rbp),%edi
mov    0x29e4(%rip),%rax
mov    (%rax),%esi
mov    -0x806c(%rbp),%edx
lea    -0x40(%rbp),%rcx
call   1090 <epoll_ctl@plt>
mov    -0x40(%rbp),%eax
mov    0x29b1(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     1739 <main+0x4e9>
lea    -0x4050(%rbp),%rdi
mov    -0x50(%rbp),%rcx
mov    $0x1,%esi
mov    $0x4000,%edx
call   1030 <fread@plt>
mov    %eax,-0x8068(%rbp)
mov    -0x8068(%rbp),%esi
mov    -0x48(%rbp),%rdx
lea    0xa9b(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
cmpl   $0x0,-0x8068(%rbp)
jle    16f4 <main+0x4a4>
mov    -0x8068(%rbp),%eax
add    -0x8054(%rbp),%eax
mov    %eax,-0x8054(%rbp)
mov    -0x806c(%rbp),%edi
lea    -0x4050(%rbp),%rsi
mov    -0x8068(%rbp),%edx
call   1040 <write@plt>
mov    %eax,-0x8068(%rbp)
cmpl   $0x0,-0x8068(%rbp)
jge    16d5 <main+0x485>
mov    0x2915(%rip),%rax
mov    (%rax),%eax
mov    0x2934(%rip),%rcx
cmp    (%rcx),%eax
jne    16ab <main+0x45b>
mov    -0x806c(%rbp),%edi
call   1080 <close@plt>
movl   $0xffffffff,-0x3c(%rbp)
jmp    16d0 <main+0x480>
mov    -0x806c(%rbp),%esi
lea    0xa2a(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x8058(%rbp),%eax
mov    %eax,-0x8054(%rbp)
jmp    17ab <main+0x55b>
jmp    16d5 <main+0x485>
mov    -0x8068(%rbp),%esi
mov    -0x806c(%rbp),%edx
lea    0xa11(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
jmp    1700 <main+0x4b0>
mov    -0x8058(%rbp),%eax
mov    %eax,-0x8054(%rbp)
mov    -0x806c(%rbp),%eax
mov    %eax,-0x3c(%rbp)
mov    0x28d0(%rip),%rax
mov    (%rax),%eax
mov    0x286f(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x40(%rbp)
mov    -0x34(%rbp),%edi
mov    0x2890(%rip),%rax
mov    (%rax),%esi
mov    -0x806c(%rbp),%edx
lea    -0x40(%rbp),%rcx
call   1090 <epoll_ctl@plt>
mov    -0x8054(%rbp),%eax
cmp    -0x8058(%rbp),%eax
jl     1792 <main+0x542>
lea    0x9c4(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x806c(%rbp),%eax
mov    %eax,-0x3c(%rbp)
mov    0x2877(%rip),%rax
mov    (%rax),%eax
mov    0x2816(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x40(%rbp)
mov    -0x34(%rbp),%edi
mov    0x2837(%rip),%rax
mov    (%rax),%esi
mov    -0x806c(%rbp),%edx
lea    -0x40(%rbp),%rcx
call   1090 <epoll_ctl@plt>
jmp    1797 <main+0x547>
mov    -0x8064(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8064(%rbp)
jmp    14bd <main+0x26d>
mov    -0x8054(%rbp),%eax
cmp    -0x8058(%rbp),%eax
jl     17d0 <main+0x580>
lea    0x973(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
jmp    17d5 <main+0x585>
jmp    1483 <main+0x233>
mov    -0x8054(%rbp),%esi
lea    0x88b(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x34(%rbp),%edi
call   1080 <close@plt>
mov    -0x50(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x24(%rbp),%edi
call   1080 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x8070,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x8038,%rsp
mov    %rsi,%rbp
cmp    $0x2,%edi
jne    15cb <main+0x36b>
mov    0x8(%rbp),%rdi
call   1140 <atoi@plt>
test   %eax,%eax
js     15cb <main+0x36b>
mov    %eax,%ebx
mov    0x2d51(%rip),%r15
mov    (%r15),%edi
mov    0x2d07(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1180 <socket@plt>
mov    %eax,%r12d
lea    0x20(%rsp),%r14
mov    %r14,%rdi
mov    $0xc,%esi
call   1130 <bzero@plt>
mov    (%r15),%eax
mov    %eax,0x28(%rsp)
lea    0x24(%rsp),%rsi
lea    0xd44(%rip),%rdi
call   10e0 <inet_aton@plt>
mov    %ebx,%edi
call   1070 <htons@plt>
mov    %eax,0x20(%rsp)
mov    %r12d,%edi
mov    %r14,%rsi
mov    $0xc,%edx
call   1170 <connect@plt>
cmp    $0xffffffff,%eax
je     1663 <main+0x403>
mov    $0x100,%edi
call   1150 <epoll_create@plt>
mov    %eax,%ebp
mov    %r12d,%edi
call   1100 <setnonblocking@plt>
mov    0x2cca(%rip),%r14
mov    0x2c83(%rip),%rbx
mov    (%rbx),%eax
or     (%r14),%eax
mov    0x2c5f(%rip),%rcx
or     (%rcx),%eax
mov    %r12d,0x4(%rsp)
mov    %eax,(%rsp)
mov    0x2c9e(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rcx
mov    %ebp,0x8(%rsp)
mov    %ebp,%edi
mov    %r12d,%edx
call   10a0 <epoll_ctl@plt>
lea    0xcf2(%rip),%rdi
lea    0xcf4(%rip),%rsi
call   1110 <fopen@plt>
mov    %rax,0x18(%rsp)
test   %rax,%rax
je     1650 <main+0x3f0>
mov    %r12d,0x14(%rsp)
lea    0xccc(%rip),%rbp
lea    0x10(%rsp),%rsi
mov    %rbp,%rdi
call   10d0 <stat@plt>
mov    0x10(%rsp),%edx
lea    0xcc7(%rip),%rdi
mov    %rbp,%rsi
mov    %edx,0xc(%rsp)
xor    %eax,%eax
call   1080 <printf@plt>
xor    %r12d,%r12d
jmp    13bb <main+0x15b>
cs nopw 0x0(%rax,%rax,1)
nop
cmp    0xc(%rsp),%r12d
jge    1601 <main+0x3a1>
lea    0xcab(%rip),%rdi
mov    %r12d,%esi
xor    %eax,%eax
call   1080 <printf@plt>
mov    0x8(%rsp),%edi
mov    %rsp,%rsi
mov    $0x1,%edx
mov    $0x1f4,%ecx
call   10f0 <epoll_wait@plt>
test   %eax,%eax
jle    13b0 <main+0x150>
mov    %eax,%r13d
jmp    13f6 <main+0x196>
nopl   0x0(%rax,%rax,1)
add    $0xffffffff,%r13d
je     13b0 <main+0x150>
mov    0x4(%rsp),%r15d
test   %r15d,%r15d
js     13f0 <main+0x190>
mov    (%rsp),%eax
test   %eax,(%r14)
je     14a8 <main+0x248>
lea    0xc72(%rip),%rdi
xor    %eax,%eax
call   1080 <printf@plt>
mov    %r15d,%edi
lea    0x4030(%rsp),%rsi
mov    $0x4000,%edx
call   10b0 <read@plt>
mov    %eax,%ebp
test   %eax,%eax
js     1439 <main+0x1d9>
jne    1470 <main+0x210>
jmp    144d <main+0x1ed>
mov    0x2b58(%rip),%rax
mov    (%rax),%eax
mov    0x2b77(%rip),%rcx
cmp    (%rcx),%eax
jne    145f <main+0x1ff>
mov    %r15d,%edi
call   1090 <close@plt>
movl   $0xffffffff,0x4(%rsp)
ff
jmp    1470 <main+0x210>
lea    0xc28(%rip),%rdi
mov    %r15d,%esi
xor    %eax,%eax
call   1080 <printf@plt>
lea    0xc31(%rip),%rdi
mov    %ebp,%esi
mov    %r15d,%edx
xor    %eax,%eax
call   1080 <printf@plt>
mov    %r15d,0x4(%rsp)
mov    (%rbx),%eax
mov    %eax,(%rsp)
mov    0x2b24(%rip),%rax
mov    (%rax),%esi
mov    0x8(%rsp),%edi
mov    %r15d,%edx
mov    %rsp,%rcx
call   10a0 <epoll_ctl@plt>
mov    (%rsp),%eax
test   %eax,(%rbx)
je     1583 <main+0x323>
mov    %r12d,%ebx
mov    %r14,%r12
lea    0x30(%rsp),%rdi
mov    $0x1,%esi
mov    $0x4000,%edx
mov    0x18(%rsp),%rcx
call   1040 <fread@plt>
mov    %eax,%r14d
lea    0xbed(%rip),%rdi
mov    %eax,%esi
lea    0xb64(%rip),%rdx
xor    %eax,%eax
call   1080 <printf@plt>
mov    0xc(%rsp),%ebp
test   %r14d,%r14d
jle    1549 <main+0x2e9>
mov    %r15d,%edi
lea    0x30(%rsp),%rsi
mov    %r14d,%edx
call   1050 <write@plt>
mov    %eax,%ebp
test   %eax,%eax
jns    1530 <main+0x2d0>
mov    0x2a89(%rip),%rax
mov    (%rax),%eax
mov    0x2aa8(%rip),%rcx
cmp    (%rcx),%eax
jne    15eb <main+0x38b>
mov    %r15d,%edi
call   1090 <close@plt>
movl   $0xffffffff,0x4(%rsp)
ff
add    %ebx,%r14d
lea    0xbbf(%rip),%rdi
mov    %ebp,%esi
mov    %r15d,%edx
xor    %eax,%eax
call   1080 <printf@plt>
mov    %r14d,%ebp
mov    %r15d,0x4(%rsp)
mov    0x2a33(%rip),%rax
mov    (%rax),%eax
mov    %r12,%r14
or     (%r12),%eax
mov    %eax,(%rsp)
mov    0x2a50(%rip),%rax
mov    (%rax),%esi
mov    0x8(%rsp),%edi
mov    %r15d,%edx
mov    %rsp,%rcx
call   10a0 <epoll_ctl@plt>
mov    %ebp,%r12d
mov    0x2a1d(%rip),%rbx
cmp    0xc(%rsp),%r12d
jl     13f0 <main+0x190>
lea    0xb98(%rip),%rdi
call   1030 <puts@plt>
mov    %r15d,0x4(%rsp)
mov    0x29e2(%rip),%rax
mov    (%rax),%eax
or     (%r14),%eax
mov    %eax,(%rsp)
mov    0x2a03(%rip),%rax
mov    (%rax),%esi
mov    0x8(%rsp),%edi
mov    %r15d,%edx
mov    %rsp,%rcx
call   10a0 <epoll_ctl@plt>
jmp    13f0 <main+0x190>
mov    0x29de(%rip),%rax
mov    (%rax),%edi
mov    0x0(%rbp),%rdx
lea    0xa21(%rip),%rsi
call   10c0 <fprintf@plt>
mov    $0x1,%ebp
jmp    163c <main+0x3dc>
lea    0xaf0(%rip),%rdi
mov    %r15d,%esi
xor    %eax,%eax
call   1080 <printf@plt>
mov    0xc(%rsp),%r12d
lea    0xb0e(%rip),%rdi
call   1030 <puts@plt>
lea    0xa59(%rip),%rdi
xor    %ebp,%ebp
mov    %r12d,%esi
xor    %eax,%eax
call   1080 <printf@plt>
mov    0x8(%rsp),%edi
call   1090 <close@plt>
mov    0x18(%rsp),%rdi
call   1060 <fclose@plt>
mov    0x14(%rsp),%edi
call   1090 <close@plt>
mov    %ebp,%eax
add    $0x8038,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0x9fa(%rip),%rdi
call   1120 <perror@plt>
mov    $0xffffffff,%ebp
jmp    163c <main+0x3dc>
mov    0x292e(%rip),%rax
mov    (%rax),%esi
lea    0x9ad(%rip),%rdi
xor    %eax,%eax
call   1080 <printf@plt>
mov    0x294f(%rip),%rax
mov    (%rax),%esi
lea    0x9a8(%rip),%rdi
xor    %eax,%eax
call   1080 <printf@plt>
lea    0x9a6(%rip),%rdi
call   1120 <perror@plt>
mov    %r12d,%edi
call   1090 <close@plt>
mov    0x28e4(%rip),%rax
mov    (%rax),%edi
call   1160 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.epoll_event = type { i32, %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i32 }
%struct.stat = type { i32 }
%struct.sockaddr = type { i32 }
@stderr = global i32 0
@.str = [22 x i8] c"Usage:%s portnumber\07\0A\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.1 = [10 x i8] c"127.0.0.1\00"
@.str.2 = [18 x i8] c"connect error %d\0A\00"
@errno = global i32 0
@.str.3 = [12 x i8] c"EISCONN %d\0A\00"
@EISCONN = global i32 0
@.str.4 = [8 x i8] c"connect\00"
@EXIT_FAILURE = global i32 0
@EPOLLIN = global i32 0
@EPOLLOUT = global i32 0
@EPOLLET = global i32 0
@EPOLL_CTL_ADD = global i32 0
@.str.5 = [9 x i8] c"test.txt\00"
@.str.6 = [2 x i8] c"r\00"
@.str.7 = [8 x i8] c"fopen: \00"
@.str.8 = [20 x i8] c"file %s size is %d\0A\00"
@.str.9 = [24 x i8] c"total write size is %d\0A\00"
@.str.10 = [9 x i8] c"EPOLLIN\09\00"
@ECONNRESET = global i32 0
@.str.11 = [26 x i8] c"socket %d readline error\0A\00"
@.str.12 = [30 x i8] c"read %d bytes from socket %d\0A\00"
@EPOLL_CTL_MOD = global i32 0
@.str.13 = [28 x i8] c"read %d bytes from file %s\0A\00"
@.str.14 = [23 x i8] c"socket %d write error\0A\00"
@.str.15 = [29 x i8] c"write %d bytes to socket %d\0A\00"
@.str.16 = [33 x i8] c"write whole file, change events\0A\00"
@.str.17 = [24 x i8] c"write whole file, exit\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca %struct.sockaddr_in
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i32
%11 = alloca %struct.epoll_event
%12 = alloca i8*
%13 = alloca i32*
%14 = alloca [16384 x i8]
%15 = alloca [16384 x i8]
%16 = alloca i32
%17 = alloca i32
%18 = alloca %struct.stat
%19 = alloca i32
%20 = alloca i32
%21 = alloca i32
%22 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%23 = load i32, i32* %4
%24 = icmp eq i32 2, %23
br i1 %24, label %25, label %38
25: ; preds = %2
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 1
%28 = load i8*, i8** %27
%29 = call i32 @atoi(i8* %28)
store i32 %29, i32* %6
%30 = icmp slt i32 %29, 0
br i1 %30, label %31, label %37
31: ; preds = %25
%32 = load i32, i32* @stderr
%33 = load i8**, i8*** %5
%34 = getelementptr inbounds i8*, i8** %33, i64 0
%35 = load i8*, i8** %34
%36 = call i32 @fprintf(i32 %32, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %35)
store i32 1, i32* %3
br label %258
37: ; preds = %25
br label %44
38: ; preds = %2
%39 = load i32, i32* @stderr
%40 = load i8**, i8*** %5
%41 = getelementptr inbounds i8*, i8** %40, i64 0
%42 = load i8*, i8** %41
%43 = call i32 @fprintf(i32 %39, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %42)
store i32 1, i32* %3
br label %258
44: ; preds = %37
%45 = load i32, i32* @AF_INET
%46 = load i32, i32* @SOCK_STREAM
%47 = call i32 @socket(i32 %45, i32 %46, i32 0)
store i32 %47, i32* %8
%48 = call i32 @bzero(%struct.sockaddr_in* %7, i32 12)
%49 = load i32, i32* @AF_INET
%50 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 2
store i32 %49, i32* %50
store i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8** %9
%51 = load i8*, i8** %9
%52 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 1
%53 = call i32 @inet_aton(i8* %51, i32* %52)
%54 = load i32, i32* %6
%55 = call i32 @htons(i32 %54)
%56 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 0
store i32 %55, i32* %56
%57 = load i32, i32* %8
%58 = bitcast %struct.sockaddr_in* %7 to %struct.sockaddr*
%59 = call i32 @connect(i32 %57, %struct.sockaddr* %58, i32 12)
%60 = icmp eq i32 -1, %59
br i1 %60, label %61, label %71
61: ; preds = %44
%62 = load i32, i32* @errno
%63 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i32 %62)
%64 = load i32, i32* @EISCONN
%65 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i32 %64)
%66 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
%67 = load i32, i32* %8
%68 = call i32 @close(i32 %67)
%69 = load i32, i32* @EXIT_FAILURE
%70 = call i32 @exit(i32 %69)
unreachable
71: ; preds = %44
%72 = call i32 @epoll_create(i32 256)
store i32 %72, i32* %10
%73 = load i32, i32* %8
%74 = call i32 @setnonblocking(i32 %73)
%75 = load i32, i32* %8
%76 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %11, i32 0, i32 1
%77 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %76, i32 0, i32 0
store i32 %75, i32* %77
%78 = load i32, i32* @EPOLLIN
%79 = load i32, i32* @EPOLLOUT
%80 = or i32 %78, %79
%81 = load i32, i32* @EPOLLET
%82 = or i32 %80, %81
%83 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %11, i32 0, i32 0
store i32 %82, i32* %83
%84 = load i32, i32* %10
%85 = load i32, i32* @EPOLL_CTL_ADD
%86 = load i32, i32* %8
%87 = call i32 @epoll_ctl(i32 %84, i32 %85, i32 %86, %struct.epoll_event* %11)
store i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0), i8** %12
%88 = load i8*, i8** %12
%89 = call i32* @fopen(i8* %88, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
store i32* %89, i32** %13
%90 = load i32*, i32** %13
%91 = icmp eq i32* %90, null
br i1 %91, label %92, label %94
92: ; preds = %71
%93 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.7, i64 0, i64 0))
store i32 -1, i32* %3
br label %258
94: ; preds = %71
store i32 0, i32* %16
%95 = load i8*, i8** %12
%96 = call i32 @stat(i8* %95, %struct.stat* %18)
%97 = getelementptr inbounds %struct.stat, %struct.stat* %18, i32 0, i32 0
%98 = load i32, i32* %97
store i32 %98, i32* %17
%99 = load i8*, i8** %12
%100 = load i32, i32* %17
%101 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.8, i64 0, i64 0), i8* %99, i32 %100)
br label %102
102: ; preds = %248, %94
%103 = load i32, i32* %16
%104 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.9, i64 0, i64 0), i32 %103)
%105 = load i32, i32* %10
%106 = call i32 @epoll_wait(i32 %105, %struct.epoll_event* %11, i32 1, i32 500)
store i32 %106, i32* %22
store i32 0, i32* %19
br label %107
107: ; preds = %239, %102
%108 = load i32, i32* %19
%109 = load i32, i32* %22
%110 = icmp slt i32 %108, %109
br i1 %110, label %111, label %242
111: ; preds = %107
%112 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %11, i32 0, i32 1
%113 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %112, i32 0, i32 0
%114 = load i32, i32* %113
store i32 %114, i32* %21
%115 = icmp slt i32 %114, 0
br i1 %115, label %116, label %117
116: ; preds = %111
br label %239
117: ; preds = %111
%118 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %11, i32 0, i32 0
%119 = load i32, i32* %118
%120 = load i32, i32* @EPOLLIN
%121 = and i32 %119, %120
%122 = icmp ne i32 %121, 0
br i1 %122, label %123, label %164
123: ; preds = %117
%124 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.10, i64 0, i64 0))
%125 = load i32, i32* %21
%126 = getelementptr inbounds [16384 x i8], [16384 x i8]* %15, i64 0, i64 0
%127 = call i32 @read(i32 %125, i8* %126, i32 16384)
store i32 %127, i32* %20
%128 = icmp slt i32 %127, 0
br i1 %128, label %129, label %142
129: ; preds = %123
%130 = load i32, i32* @errno
%131 = load i32, i32* @ECONNRESET
%132 = icmp eq i32 %130, %131
br i1 %132, label %133, label %138
133: ; preds = %129
%134 = load i32, i32* %21
%135 = call i32 @close(i32 %134)
%136 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %11, i32 0, i32 1
%137 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %136, i32 0, i32 0
store i32 -1, i32* %137
br label %141
138: ; preds = %129
%139 = load i32, i32* %21
%140 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.11, i64 0, i64 0), i32 %139)
br label %141
141: ; preds = %138, %133
br label %151
142: ; preds = %123
%143 = load i32, i32* %20
%144 = icmp eq i32 %143, 0
br i1 %144, label %145, label %150
145: ; preds = %142
%146 = load i32, i32* %21
%147 = call i32 @close(i32 %146)
%148 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %11, i32 0, i32 1
%149 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %148, i32 0, i32 0
store i32 -1, i32* %149
br label %150
150: ; preds = %145, %142
br label %151
151: ; preds = %150, %141
%152 = load i32, i32* %20
%153 = load i32, i32* %21
%154 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.12, i64 0, i64 0), i32 %152, i32 %153)
%155 = load i32, i32* %21
%156 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %11, i32 0, i32 1
%157 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %156, i32 0, i32 0
store i32 %155, i32* %157
%158 = load i32, i32* @EPOLLOUT
%159 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %11, i32 0, i32 0
store i32 %158, i32* %159
%160 = load i32, i32* %10
%161 = load i32, i32* @EPOLL_CTL_MOD
%162 = load i32, i32* %21
%163 = call i32 @epoll_ctl(i32 %160, i32 %161, i32 %162, %struct.epoll_event* %11)
br label %164
164: ; preds = %151, %117
%165 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %11, i32 0, i32 0
%166 = load i32, i32* %165
%167 = load i32, i32* @EPOLLOUT
%168 = and i32 %166, %167
%169 = icmp ne i32 %168, 0
br i1 %169, label %170, label %221
170: ; preds = %164
%171 = getelementptr inbounds [16384 x i8], [16384 x i8]* %14, i64 0, i64 0
%172 = load i32*, i32** %13
%173 = call i32 @fread(i8* %171, i32 1, i32 16384, i32* %172)
store i32 %173, i32* %20
%174 = load i32, i32* %20
%175 = load i8*, i8** %12
%176 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.13, i64 0, i64 0), i32 %174, i8* %175)
%177 = load i32, i32* %20
%178 = icmp sgt i32 %177, 0
br i1 %178, label %179, label %207
179: ; preds = %170
%180 = load i32, i32* %20
%181 = load i32, i32* %16
%182 = add nsw i32 %181, %180
store i32 %182, i32* %16
%183 = load i32, i32* %21
%184 = getelementptr inbounds [16384 x i8], [16384 x i8]* %14, i64 0, i64 0
%185 = load i32, i32* %20
%186 = call i32 @write(i32 %183, i8* %184, i32 %185)
store i32 %186, i32* %20
%187 = load i32, i32* %20
%188 = icmp slt i32 %187, 0
br i1 %188, label %189, label %203
189: ; preds = %179
%190 = load i32, i32* @errno
%191 = load i32, i32* @ECONNRESET
%192 = icmp eq i32 %190, %191
br i1 %192, label %193, label %198
193: ; preds = %189
%194 = load i32, i32* %21
%195 = call i32 @close(i32 %194)
%196 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %11, i32 0, i32 1
%197 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %196, i32 0, i32 0
store i32 -1, i32* %197
br label %202
198: ; preds = %189
%199 = load i32, i32* %21
%200 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.14, i64 0, i64 0), i32 %199)
%201 = load i32, i32* %17
store i32 %201, i32* %16
br label %242
202: ; preds = %193
br label %203
203: ; preds = %202, %179
%204 = load i32, i32* %20
%205 = load i32, i32* %21
%206 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.15, i64 0, i64 0), i32 %204, i32 %205)
br label %209
207: ; preds = %170
%208 = load i32, i32* %17
store i32 %208, i32* %16
br label %209
209: ; preds = %207, %203
%210 = load i32, i32* %21
%211 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %11, i32 0, i32 1
%212 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %211, i32 0, i32 0
store i32 %210, i32* %212
%213 = load i32, i32* @EPOLLIN
%214 = load i32, i32* @EPOLLET
%215 = or i32 %213, %214
%216 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %11, i32 0, i32 0
store i32 %215, i32* %216
%217 = load i32, i32* %10
%218 = load i32, i32* @EPOLL_CTL_MOD
%219 = load i32, i32* %21
%220 = call i32 @epoll_ctl(i32 %217, i32 %218, i32 %219, %struct.epoll_event* %11)
br label %221
221: ; preds = %209, %164
%222 = load i32, i32* %16
%223 = load i32, i32* %17
%224 = icmp sge i32 %222, %223
br i1 %224, label %225, label %238
225: ; preds = %221
%226 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.16, i64 0, i64 0))
%227 = load i32, i32* %21
%228 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %11, i32 0, i32 1
%229 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %228, i32 0, i32 0
store i32 %227, i32* %229
%230 = load i32, i32* @EPOLLIN
%231 = load i32, i32* @EPOLLET
%232 = or i32 %230, %231
%233 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %11, i32 0, i32 0
store i32 %232, i32* %233
%234 = load i32, i32* %10
%235 = load i32, i32* @EPOLL_CTL_MOD
%236 = load i32, i32* %21
%237 = call i32 @epoll_ctl(i32 %234, i32 %235, i32 %236, %struct.epoll_event* %11)
br label %238
238: ; preds = %225, %221
br label %239
239: ; preds = %238, %116
%240 = load i32, i32* %19
%241 = add nsw i32 %240, 1
store i32 %241, i32* %19
br label %107
242: ; preds = %198, %107
%243 = load i32, i32* %16
%244 = load i32, i32* %17
%245 = icmp sge i32 %243, %244
br i1 %245, label %246, label %248
246: ; preds = %242
%247 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.17, i64 0, i64 0))
br label %249
248: ; preds = %242
br label %102
249: ; preds = %246
%250 = load i32, i32* %16
%251 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.9, i64 0, i64 0), i32 %250)
%252 = load i32, i32* %10
%253 = call i32 @close(i32 %252)
%254 = load i32*, i32** %13
%255 = call i32 @fclose(i32* %254)
%256 = load i32, i32* %8
%257 = call i32 @close(i32 %256)
store i32 0, i32* %3
br label %258
258: ; preds = %249, %92, %38, %31
%259 = load i32, i32* %3
ret i32 %259
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.epoll_event = type { i32, %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i32 }
%struct.stat = type { i32 }
%struct.sockaddr = type { i32 }
@stderr = global i32 0
@.str = [22 x i8] c"Usage:%s portnumber\07\0A\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.1 = [10 x i8] c"127.0.0.1\00"
@.str.2 = [18 x i8] c"connect error %d\0A\00"
@errno = global i32 0
@.str.3 = [12 x i8] c"EISCONN %d\0A\00"
@EISCONN = global i32 0
@.str.4 = [8 x i8] c"connect\00"
@EXIT_FAILURE = global i32 0
@EPOLLIN = global i32 0
@EPOLLOUT = global i32 0
@EPOLLET = global i32 0
@EPOLL_CTL_ADD = global i32 0
@.str.5 = [9 x i8] c"test.txt\00"
@.str.6 = [2 x i8] c"r\00"
@.str.7 = [8 x i8] c"fopen: \00"
@.str.8 = [20 x i8] c"file %s size is %d\0A\00"
@.str.9 = [24 x i8] c"total write size is %d\0A\00"
@.str.10 = [9 x i8] c"EPOLLIN\09\00"
@ECONNRESET = global i32 0
@.str.11 = [26 x i8] c"socket %d readline error\0A\00"
@.str.12 = [30 x i8] c"read %d bytes from socket %d\0A\00"
@EPOLL_CTL_MOD = global i32 0
@.str.13 = [28 x i8] c"read %d bytes from file %s\0A\00"
@.str.14 = [23 x i8] c"socket %d write error\0A\00"
@.str.15 = [29 x i8] c"write %d bytes to socket %d\0A\00"
@str = [23 x i8] c"write whole file, exit\00"
@str.18 = [32 x i8] c"write whole file, change events\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca %struct.epoll_event
%5 = alloca [16384 x i8]
%6 = alloca [16384 x i8]
%7 = alloca %struct.stat
%8 = icmp eq i32 %0, 2
br i1 %8, label %9, label %18
9: ; preds = %2
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = tail call i32 @atoi(i8* %11)
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %22
14: ; preds = %9
%15 = load i32, i32* @stderr
%16 = load i8*, i8** %1
%17 = tail call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %16)
br label %164
18: ; preds = %2
%19 = load i32, i32* @stderr
%20 = load i8*, i8** %1
%21 = tail call i32 @fprintf(i32 %19, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %20)
br label %164
22: ; preds = %9
%23 = bitcast %struct.sockaddr_in* %3 to i8*
%24 = load i32, i32* @AF_INET
%25 = load i32, i32* @SOCK_STREAM
%26 = tail call i32 @socket(i32 %24, i32 %25, i32 0)
%27 = call i32 @bzero(%struct.sockaddr_in* %3, i32 12)
%28 = load i32, i32* @AF_INET
%29 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %28, i32* %29
%30 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1
%31 = call i32 @inet_aton(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32* %30)
%32 = call i32 @htons(i32 %12)
%33 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
store i32 %32, i32* %33
%34 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%35 = call i32 @connect(i32 %26, %struct.sockaddr* %34, i32 12)
%36 = icmp eq i32 %35, -1
br i1 %36, label %37, label %46
37: ; preds = %22
%38 = load i32, i32* @errno
%39 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i32 %38)
%40 = load i32, i32* @EISCONN
%41 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i32 %40)
%42 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
%43 = call i32 @close(i32 %26)
%44 = load i32, i32* @EXIT_FAILURE
%45 = call i32 @exit(i32 %44)
unreachable
46: ; preds = %22
%47 = bitcast %struct.epoll_event* %4 to i8*
%48 = call i32 @epoll_create(i32 256)
%49 = call i32 @setnonblocking(i32 %26)
%50 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %4, i64 0, i32 1, i32 0
store i32 %26, i32* %50
%51 = load i32, i32* @EPOLLIN
%52 = load i32, i32* @EPOLLOUT
%53 = or i32 %52, %51
%54 = load i32, i32* @EPOLLET
%55 = or i32 %53, %54
%56 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %4, i64 0, i32 0
store i32 %55, i32* %56
%57 = load i32, i32* @EPOLL_CTL_ADD
%58 = call i32 @epoll_ctl(i32 %48, i32 %57, i32 %26, %struct.epoll_event* %4)
%59 = call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
%60 = icmp eq i32* %59, null
br i1 %60, label %61, label %63
61: ; preds = %46
%62 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.7, i64 0, i64 0))
br label %162
63: ; preds = %46
%64 = getelementptr inbounds [16384 x i8], [16384 x i8]* %5, i64 0, i64 0
%65 = getelementptr inbounds [16384 x i8], [16384 x i8]* %6, i64 0, i64 0
%66 = bitcast %struct.stat* %7 to i8*
%67 = call i32 @stat(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0), %struct.stat* %7)
%68 = getelementptr inbounds %struct.stat, %struct.stat* %7, i64 0, i32 0
%69 = load i32, i32* %68
%70 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.8, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0), i32 %69)
br label %71
71: ; preds = %152, %63
%72 = phi i32 [ 0, %63 ], [ %153, %152 ]
%73 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.9, i64 0, i64 0), i32 %72)
%74 = call i32 @epoll_wait(i32 %48, %struct.epoll_event* %4, i32 1, i32 500)
%75 = icmp sgt i32 %74, 0
br i1 %75, label %76, label %152
76: ; preds = %71, %148
%77 = phi i32 [ %150, %148 ], [ 0, %71 ]
%78 = phi i32 [ %149, %148 ], [ %72, %71 ]
%79 = load i32, i32* %50
%80 = icmp slt i32 %79, 0
br i1 %80, label %148, label %81
81: ; preds = %76
%82 = load i32, i32* %56
%83 = load i32, i32* @EPOLLIN
%84 = and i32 %83, %82
%85 = icmp eq i32 %84, 0
br i1 %85, label %108, label %86
86: ; preds = %81
%87 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.10, i64 0, i64 0))
%88 = call i32 @read(i32 %79, i8* %65, i32 16384)
%89 = icmp slt i32 %88, 0
br i1 %89, label %90, label %98
90: ; preds = %86
%91 = load i32, i32* @errno
%92 = load i32, i32* @ECONNRESET
%93 = icmp eq i32 %91, %92
br i1 %93, label %94, label %96
94: ; preds = %90
%95 = call i32 @close(i32 %79)
store i32 -1, i32* %50
br label %102
96: ; preds = %90
%97 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.11, i64 0, i64 0), i32 %79)
br label %102
98: ; preds = %86
%99 = icmp eq i32 %88, 0
br i1 %99, label %100, label %102
100: ; preds = %98
%101 = call i32 @close(i32 %79)
store i32 -1, i32* %50
br label %102
102: ; preds = %98, %100, %94, %96
%103 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.12, i64 0, i64 0), i32 %88, i32 %79)
store i32 %79, i32* %50
%104 = load i32, i32* @EPOLLOUT
store i32 %104, i32* %56
%105 = load i32, i32* @EPOLL_CTL_MOD
%106 = call i32 @epoll_ctl(i32 %48, i32 %105, i32 %79, %struct.epoll_event* %4)
%107 = load i32, i32* %56
br label %108
108: ; preds = %102, %81
%109 = phi i32 [ %107, %102 ], [ %82, %81 ]
%110 = load i32, i32* @EPOLLOUT
%111 = and i32 %110, %109
%112 = icmp eq i32 %111, 0
br i1 %112, label %138, label %113
113: ; preds = %108
%114 = call i32 @fread(i8* %64, i32 1, i32 16384, i32* %59)
%115 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.13, i64 0, i64 0), i32 %114, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0))
%116 = icmp sgt i32 %114, 0
br i1 %116, label %117, label %131
117: ; preds = %113
%118 = add nsw i32 %114, %78
%119 = call i32 @write(i32 %79, i8* %64, i32 %114)
%120 = icmp slt i32 %119, 0
br i1 %120, label %121, label %129
121: ; preds = %117
%122 = load i32, i32* @errno
%123 = load i32, i32* @ECONNRESET
%124 = icmp eq i32 %122, %123
br i1 %124, label %125, label %127
125: ; preds = %121
%126 = call i32 @close(i32 %79)
store i32 -1, i32* %50
br label %129
127: ; preds = %121
%128 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.14, i64 0, i64 0), i32 %79)
br label %155
129: ; preds = %125, %117
%130 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.15, i64 0, i64 0), i32 %119, i32 %79)
br label %131
131: ; preds = %113, %129
%132 = phi i32 [ %118, %129 ], [ %69, %113 ]
store i32 %79, i32* %50
%133 = load i32, i32* @EPOLLIN
%134 = load i32, i32* @EPOLLET
%135 = or i32 %134, %133
store i32 %135, i32* %56
%136 = load i32, i32* @EPOLL_CTL_MOD
%137 = call i32 @epoll_ctl(i32 %48, i32 %136, i32 %79, %struct.epoll_event* %4)
br label %138
138: ; preds = %131, %108
%139 = phi i32 [ %132, %131 ], [ %78, %108 ]
%140 = icmp slt i32 %139, %69
br i1 %140, label %148, label %141
141: ; preds = %138
%142 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @str.18, i64 0, i64 0))
store i32 %79, i32* %50
%143 = load i32, i32* @EPOLLIN
%144 = load i32, i32* @EPOLLET
%145 = or i32 %144, %143
store i32 %145, i32* %56
%146 = load i32, i32* @EPOLL_CTL_MOD
%147 = call i32 @epoll_ctl(i32 %48, i32 %146, i32 %79, %struct.epoll_event* %4)
br label %148
148: ; preds = %138, %141, %76
%149 = phi i32 [ %78, %76 ], [ %139, %141 ], [ %139, %138 ]
%150 = add nuw nsw i32 %77, 1
%151 = icmp eq i32 %150, %74
br i1 %151, label %152, label %76
152: ; preds = %148, %71
%153 = phi i32 [ %72, %71 ], [ %149, %148 ]
%154 = icmp slt i32 %153, %69
br i1 %154, label %71, label %155
155: ; preds = %152, %127
%156 = phi i32 [ %69, %127 ], [ %153, %152 ]
%157 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str, i64 0, i64 0))
%158 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.9, i64 0, i64 0), i32 %156)
%159 = call i32 @close(i32 %48)
%160 = call i32 @fclose(i32* %59)
%161 = call i32 @close(i32 %26)
br label %162
162: ; preds = %155, %61
%163 = phi i32 [ -1, %61 ], [ 0, %155 ]
br label %164
164: ; preds = %162, %18, %14
%165 = phi i32 [ 1, %14 ], [ %163, %162 ], [ 1, %18 ]
ret i32 %165
}