#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 TYPE_2__ {
  int /*<<< orphan*/ s_addr;
};
struct sockaddr_in {
  int /*<<< orphan*/ sin_port;
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
typedef int ssize_t;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ INADDR_ANY;
int O_CREAT;
int /*<<< orphan*/ O_RDONLY;
int O_TRUNC;
int O_WRONLY;
int /*<<< orphan*/ SOCK_STREAM;
int accept(int, struct sockaddr *, int *);
scalar_t__ bind(int, struct sockaddr *, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
scalar_t__ getsockname(int, struct sockaddr *, int *);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ listen(int, int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int ntohs(int /*<<< orphan*/);
int open(char *, int, ...);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ read(int, char *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int write(int, char *, int);
int main() {
  int length, clilen;
  struct sockaddr_in server, client;
  int ServerListenSock, ServerTempSock;
  ServerListenSock = socket(AF_INET, SOCK_STREAM, 0);
  if (ServerListenSock < 0) {
    perror("opening stream socket");
    exit(1);
  }
  server.sin_family = AF_INET;
  server.sin_addr.s_addr = INADDR_ANY;
  server.sin_port = htons(20000);
  if (bind(ServerListenSock, (struct sockaddr *)&server, sizeof server) < 0) {
    perror("Wrong:binding stream socket");
    exit(1);
  }
  length = sizeof server;
  if (getsockname(ServerListenSock, (struct sockaddr *)&server, &length) < 0) {
    perror("Wrong:getting socket name");
    exit(1);
  }
  printf("Socket port: %d\n", ntohs(server.sin_port));
  listen(ServerListenSock, 5);
  printf("ÕýÔÚ¼àÌý......\n\n");
  while (1) {
    clilen = sizeof client;
    ServerTempSock =
        accept(ServerListenSock, (struct sockaddr *)&client, (int *)&clilen);
    printf("´´½¨ÁÙÊ±socket£¬ÓÃÓÚÒ»´Î·þÎñ......\n\n");
    if (ServerTempSock != -1) {
      int infile;
      ssize_t file_nread;
      char buf[128];
      int i = 0;
      if ((infile = open("test.txt", O_RDONLY)) == -1) {
        printf("ÕÒ²»µ½ÎÄ¼þtest.txt»ò´ò²»¿ª,Í£Ö¹ÔËÐÐ\n");
        exit(1);
      }
      printf("´ò¿ªÎÄ¼þtest.txt£¬½«ÆäÄÚÈÝ·¢ËÍ³öÈ¥......\n\n");
      memset(buf, 0, sizeof buf);
      while ((file_nread = read(infile, buf, 128 - 2)) > 0) {
        printf("´ÓÎÄ¼þÖÐ¶ÁÁË´óÐ¡Îª %d µÄÊý¾Ý¡£", file_nread);
        buf[128 - 2] = file_nread;
        i++;
        buf[128 - 1] = (i % 10) + 48;
        if (write(ServerTempSock, buf, 128) <= file_nread)
          printf("Ð´sock³öÁË´í\n");
        else
          printf("·¢ËÍ°ü´óÐ¡ %d, ¿é±àºÅ %d ......\n", 128, i % 10);
        memset(buf, 0, sizeof buf);
        if (read(ServerTempSock, buf, 128) < 0)
          printf("¶Ásock³öÁË´í\n");
        else
          printf("...ÊÕµ½Ó¦´ð£¬¶Ô·½ÊÕµ½¿é±àºÅÎª %s µÄ°ü¡£\n\n", buf);
      }
      close(infile);
      printf("......¶ÁÎÄ¼þ½áÊø£¬¹Ø±ÕÎÄ¼þtest.txt¡£\n\n");
      printf("·¢ËÍÊµ¼ÊÊý¾Ý´óÐ¡Îª0µÄ°ü£¬×÷ÎªÎÄ¼þ´«ËÍ½áÊø±êÖ¾£¬²»ÐèÒªÓ¦´ð......"
             "\n\n");
      buf[128 - 2] = 0;
      if (write(ServerTempSock, buf, 128) <= file_nread)
        printf("Ð´sock³ö´í\n");
      int outfile;
      ssize_t sock_nread;
      int realn;
      int i2 = 0;
      char charnum;
      printf("´´½¨ÎÄ¼þtest2.txtÓÃÓÚ½ÓÊÕÍøÂçÐÅÏ¢......\n\n\n");
      if ((outfile = open("test2.txt", O_WRONLY | O_CREAT | O_TRUNC, 0644)) ==
          -1) {
        printf("´´½¨ÎÄ¼þ³ö´í\n");
        exit(1);
      }
      memset(buf, 0, sizeof buf);
      while ((sock_nread = read(ServerTempSock, buf, 128)) > 0) {
        printf("...´Ósock¶ÁÁËµÚ %d ¸öÊý¾Ý°ü,´óÐ¡ÊÇ %d ,", ++i2, sock_nread);
        realn = buf[128 - 2];
        printf("Êý¾ÝÊµ¼Ê´óÐ¡ÊÇ %d £¬¿é±àºÅÊÇ\"%c\".  \n", realn, buf[128 - 1]);
        if (realn == 0) {
          printf("\n....."
                 "ÊÕµ½Êý¾ÝÊµ¼Ê´óÐ¡Îª0µÄÌØ¶¨°ü£¬¶Ô·½·¢ËÍ½áÊø£¬Ìø³öÑ­»·£¬½ÓÊÕÎÄ¼þ"
                 "½áÊø...\n\n");
          break;
        }
        printf("½«ÓÐÐ§Êý¾ÝÐ´ÈëÎÄ¼þ¡£");
        if (write(outfile, buf, realn) < realn)
          printf("Ð´ÎÄ¼þÊ±³öÁË´í\n");
        charnum = buf[128 - 1];
        printf("½«¿é±àºÅ \"%c\" ·µ»Ø·þÎñÆ÷×÷ÎªÓ¦´ð......\n\n", charnum);
        memset(buf, 0, sizeof buf);
        buf[0] = charnum;
        write(ServerTempSock, buf, 128);
      }
      printf("......¹Ø±ÕÎÄ¼þtest2.txt\n\n");
      close(outfile);
    } else
      perror("Wrong:accept");
    printf("......Ò»´Î·þÎñ½áÊø£¬ÁÙÊ±socket²»ÔÙÐèÒª£¬Ïû³ý¡£\n\n");
    close(ServerTempSock);
    printf("¼ÌÐø¼àÌý......\n\n");
  }
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xe0,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2dcf(%rip),%rax
mov    (%rax),%edi
mov    0x2da6(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1110 <socket@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jge    123e <main+0x4e>
lea    0xdd1(%rip),%rdi
call   10d0 <perror@plt>
mov    $0x1,%edi
call   1100 <exit@plt>
mov    0x2d93(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
mov    0x2d77(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    $0x4e20,%edi
call   1040 <htons@plt>
mov    %eax,-0x18(%rbp)
mov    -0x2c(%rbp),%edi
lea    -0x18(%rbp),%rsi
mov    $0xc,%edx
call   10b0 <bind@plt>
cmp    $0x0,%rax
jge    1294 <main+0xa4>
lea    0xd91(%rip),%rdi
call   10d0 <perror@plt>
mov    $0x1,%edi
call   1100 <exit@plt>
movl   $0xc,-0x8(%rbp)
mov    -0x2c(%rbp),%edi
lea    -0x18(%rbp),%rsi
lea    -0x8(%rbp),%rdx
call   10f0 <getsockname@plt>
cmp    $0x0,%rax
jge    12cb <main+0xdb>
lea    0xd76(%rip),%rdi
call   10d0 <perror@plt>
mov    $0x1,%edi
call   1100 <exit@plt>
mov    -0x18(%rbp),%edi
call   10a0 <ntohs@plt>
mov    %eax,%esi
lea    0xd70(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x2c(%rbp),%edi
mov    $0x5,%esi
call   1090 <listen@plt>
lea    0xd66(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0xc,-0xc(%rbp)
mov    -0x2c(%rbp),%edi
lea    -0x28(%rbp),%rsi
lea    -0xc(%rbp),%rdx
call   10e0 <accept@plt>
mov    %eax,-0x30(%rbp)
lea    0xd57(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
cmpl   $0xffffffff,-0x30(%rbp)
je     16b0 <main+0x4c0>
movl   $0x0,-0xc4(%rbp)
mov    0x2c8f(%rip),%rax
mov    (%rax),%esi
lea    0xd67(%rip),%rdi
mov    $0x0,%al
call   10c0 <open@plt>
mov    %eax,-0x34(%rbp)
cmp    $0xffffffff,%eax
jne    1375 <main+0x185>
lea    0xd56(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x1,%edi
call   1100 <exit@plt>
lea    0xd7d(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0xc0(%rbp),%rdi
xor    %esi,%esi
mov    $0x80,%edx
call   1060 <memset@plt>
mov    -0x34(%rbp),%edi
lea    -0xc0(%rbp),%rsi
mov    $0x7e,%edx
call   1080 <read@plt>
mov    %eax,-0x38(%rbp)
cmp    $0x0,%eax
jle    14a1 <main+0x2b1>
mov    -0x38(%rbp),%esi
lea    0xd7e(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x38(%rbp),%eax
mov    %al,-0x42(%rbp)
mov    -0xc4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc4(%rbp)
mov    -0xc4(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
add    $0x30,%edx
mov    %dl,%al
mov    %al,-0x41(%rbp)
mov    -0x30(%rbp),%edi
lea    -0xc0(%rbp),%rsi
mov    $0x80,%edx
call   1030 <write@plt>
cmp    -0x38(%rbp),%eax
jg     1422 <main+0x232>
lea    0xd61(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1443 <main+0x253>
mov    -0xc4(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
lea    0xd56(%rip),%rdi
mov    $0x80,%esi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0xc0(%rbp),%rdi
xor    %esi,%esi
mov    $0x80,%edx
call   1060 <memset@plt>
mov    -0x30(%rbp),%edi
lea    -0xc0(%rbp),%rsi
mov    $0x80,%edx
call   1080 <read@plt>
cmp    $0x0,%rax
jge    1487 <main+0x297>
lea    0xd43(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    149c <main+0x2ac>
lea    -0xc0(%rbp),%rsi
lea    0xd3f(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1396 <main+0x1a6>
mov    -0x34(%rbp),%edi
call   1070 <close@plt>
lea    0xd6e(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xd9d(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movb   $0x0,-0x42(%rbp)
mov    -0x30(%rbp),%edi
lea    -0xc0(%rbp),%rsi
mov    $0x80,%edx
call   1030 <write@plt>
cmp    -0x38(%rbp),%eax
jg     14f4 <main+0x304>
lea    0xde8(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0xd4(%rbp)
lea    0xde2(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    0x2a95(%rip),%rax
mov    (%rax),%esi
mov    0x2adc(%rip),%rax
or     (%rax),%esi
mov    0x2acb(%rip),%rax
or     (%rax),%esi
lea    0xdfc(%rip),%rdi
mov    $0x1a4,%edx
mov    $0x0,%al
call   10c0 <open@plt>
mov    %eax,-0xc8(%rbp)
cmp    $0xffffffff,%eax
jne    1561 <main+0x371>
lea    0xde4(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x1,%edi
call   1100 <exit@plt>
lea    -0xc0(%rbp),%rdi
xor    %esi,%esi
mov    $0x80,%edx
call   1060 <memset@plt>
mov    -0x30(%rbp),%edi
lea    -0xc0(%rbp),%rsi
mov    $0x80,%edx
call   1080 <read@plt>
mov    %eax,-0xcc(%rbp)
cmp    $0x0,%eax
jle    1692 <main+0x4a2>
mov    -0xd4(%rbp),%esi
add    $0x1,%esi
mov    %esi,-0xd4(%rbp)
mov    -0xcc(%rbp),%edx
lea    0xd9b(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movsbl -0x42(%rbp),%eax
mov    %eax,-0xd0(%rbp)
mov    -0xd0(%rbp),%esi
movsbl -0x41(%rbp),%edx
lea    0xdb7(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
cmpl   $0x0,-0xd0(%rbp)
jne    15fc <main+0x40c>
lea    0xdd9(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1692 <main+0x4a2>
lea    0xe53(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0xc8(%rbp),%edi
lea    -0xc0(%rbp),%rsi
mov    -0xd0(%rbp),%edx
call   1030 <write@plt>
cmp    -0xd0(%rbp),%eax
jge    163c <main+0x44c>
lea    0xe4a(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x41(%rbp),%al
mov    %al,-0xd5(%rbp)
movsbl -0xd5(%rbp),%esi
lea    0xe4a(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0xc0(%rbp),%rdi
xor    %esi,%esi
mov    $0x80,%edx
call   1060 <memset@plt>
mov    -0xd5(%rbp),%al
mov    %al,-0xc0(%rbp)
mov    -0x30(%rbp),%edi
lea    -0xc0(%rbp),%rsi
mov    $0x80,%edx
call   1030 <write@plt>
jmp    1574 <main+0x384>
lea    0xe47(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0xc8(%rbp),%edi
call   1070 <close@plt>
jmp    16bc <main+0x4cc>
lea    0xe4b(%rip),%rdi
call   10d0 <perror@plt>
lea    0xe4c(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x30(%rbp),%edi
call   1070 <close@plt>
lea    0xe89(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    12fe <main+0x10e>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xb8,%rsp
mov    0x2dc0(%rip),%rbp
mov    0x0(%rbp),%edi
mov    0x2d96(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1120 <socket@plt>
test   %eax,%eax
jns    1238 <main+0x38>
lea    0xdca(%rip),%rdi
jmp    12a0 <main+0xa0>
mov    %eax,%ebx
mov    0x0(%rbp),%eax
mov    %eax,0x10(%rsp)
mov    0x2d80(%rip),%rax
mov    (%rax),%eax
mov    %eax,0xc(%rsp)
mov    $0x4e20,%edi
call   1050 <htons@plt>
mov    %eax,0x8(%rsp)
lea    0x8(%rsp),%rsi
mov    %ebx,%edi
mov    $0xc,%edx
call   10c0 <bind@plt>
test   %rax,%rax
jns    127b <main+0x7b>
lea    0xd9d(%rip),%rdi
jmp    12a0 <main+0xa0>
movl   $0xc,0x1c(%rsp)
lea    0x8(%rsp),%rsi
lea    0x1c(%rsp),%rdx
mov    %ebx,%edi
call   1100 <getsockname@plt>
test   %rax,%rax
jns    12af <main+0xaf>
lea    0xd92(%rip),%rdi
call   10e0 <perror@plt>
mov    $0x1,%edi
call   1110 <exit@plt>
mov    0x8(%rsp),%edi
call   10b0 <ntohs@plt>
lea    0xd8d(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %ebx,%edi
mov    $0x5,%esi
call   10a0 <listen@plt>
lea    0xf3d(%rip),%rdi
call   1030 <puts@plt>
lea    0x20(%rsp),%r13
mov    %ebx,0x14(%rsp)
jmp    1339 <main+0x139>
nopl   0x0(%rax,%rax,1)
lea    0x1156(%rip),%rdi
call   1030 <puts@plt>
lea    0x20(%rsp),%r13
lea    0x1107(%rip),%rdi
call   1030 <puts@plt>
mov    %r12d,%edi
call   1080 <close@plt>
mov    0x14(%rsp),%ebx
lea    0xf4a(%rip),%rdi
call   1030 <puts@plt>
mov    %r15d,%edi
call   1080 <close@plt>
lea    0xf88(%rip),%rdi
call   1030 <puts@plt>
movl   $0xc,0x18(%rsp)
mov    %ebx,%edi
lea    0xa8(%rsp),%rsi
lea    0x18(%rsp),%rdx
call   10f0 <accept@plt>
mov    %eax,%r15d
lea    0xed1(%rip),%rdi
call   1030 <puts@plt>
cmp    $0xffffffff,%r15d
je     1660 <main+0x460>
mov    0x2c5b(%rip),%rax
mov    (%rax),%esi
lea    0xcdf(%rip),%rdi
xor    %eax,%eax
call   10d0 <open@plt>
cmp    $0xffffffff,%eax
je     1671 <main+0x471>
mov    %eax,%r14d
lea    0xf3c(%rip),%rdi
call   1030 <puts@plt>
mov    %r13,%rdi
xor    %esi,%esi
mov    $0x80,%edx
call   1070 <memset@plt>
mov    %r14d,%edi
mov    %r13,%rsi
mov    $0x7e,%edx
call   1090 <read@plt>
mov    %rax,%r12
test   %r12d,%r12d
jle    14d0 <main+0x2d0>
mov    $0x1,%ebx
jmp    1400 <main+0x200>
nop
lea    0xcf9(%rip),%rdi
mov    %r13,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %r14d,%edi
mov    %r13,%rsi
mov    $0x7e,%edx
call   1090 <read@plt>
mov    %rax,%r12
add    $0x1,%ebx
test   %r12d,%r12d
jle    14d0 <main+0x2d0>
mov    %ebx,%eax
mov    $0xcccccccd,%ecx
imul   %rcx,%rax
shr    $0x23,%rax
add    %eax,%eax
lea    (%rax,%rax,4),%ebp
mov    %ebx,%r13d
sub    %bpl,%r13b
lea    0xc45(%rip),%rdi
mov    %r12d,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %r12b,0x9e(%rsp)
or     $0x30,%r13b
mov    %r13b,0x9f(%rsp)
lea    0x20(%rsp),%r13
mov    %r15d,%edi
mov    %r13,%rsi
mov    $0x80,%edx
call   1040 <write@plt>
cmp    %r12d,%eax
jle    1480 <main+0x280>
mov    %ebx,%edx
sub    %ebp,%edx
lea    0xc3b(%rip),%rdi
mov    $0x80,%esi
xor    %eax,%eax
call   1060 <printf@plt>
jmp    148c <main+0x28c>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
lea    0x1091(%rip),%rdi
call   1030 <puts@plt>
mov    %r13,%rdi
xor    %esi,%esi
mov    $0x80,%edx
call   1070 <memset@plt>
mov    %r15d,%edi
mov    %r13,%rsi
mov    $0x80,%edx
call   1090 <read@plt>
test   %rax,%rax
jns    13d0 <main+0x1d0>
lea    0x1048(%rip),%rdi
call   1030 <puts@plt>
jmp    13e1 <main+0x1e1>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r14d,%edi
call   1080 <close@plt>
lea    0xe39(%rip),%rdi
call   1030 <puts@plt>
lea    0xe69(%rip),%rdi
call   1030 <puts@plt>
movb   $0x0,0x9e(%rsp)
mov    %r15d,%edi
mov    %r13,%rsi
mov    $0x80,%edx
call   1040 <write@plt>
cmp    %r12d,%eax
jg     1519 <main+0x319>
lea    0xfde(%rip),%rdi
call   1030 <puts@plt>
lea    0xead(%rip),%rdi
call   1030 <puts@plt>
mov    0x2acc(%rip),%rax
mov    (%rax),%esi
mov    0x2a73(%rip),%rax
or     (%rax),%esi
mov    0x2ab2(%rip),%rax
or     (%rax),%esi
lea    0xbd3(%rip),%rdi
mov    $0x1a4,%edx
xor    %eax,%eax
call   10d0 <open@plt>
cmp    $0xffffffff,%eax
je     167a <main+0x47a>
mov    %eax,%r12d
mov    %r13,%rdi
xor    %esi,%esi
mov    $0x80,%edx
call   1070 <memset@plt>
mov    %r15d,%edi
mov    %r13,%rsi
mov    $0x80,%edx
call   1090 <read@plt>
test   %eax,%eax
jle    1301 <main+0x101>
mov    $0x1,%ebp
jmp    15eb <main+0x3eb>
nopl   (%rax)
movsbl 0x9f(%rsp),%ebx
lea    0xc29(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0x20(%rsp),%r13
mov    %r13,%rdi
xor    %esi,%esi
mov    $0x80,%edx
call   1070 <memset@plt>
mov    %bl,0x20(%rsp)
mov    %r15d,%edi
mov    %r13,%rsi
mov    $0x80,%edx
call   1040 <write@plt>
mov    %r15d,%edi
mov    %r13,%rsi
mov    $0x80,%edx
call   1090 <read@plt>
add    $0x1,%ebp
test   %eax,%eax
jle    1301 <main+0x101>
lea    0xb32(%rip),%rdi
mov    %ebp,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1060 <printf@plt>
movsbl 0x9e(%rsp),%r13d
movsbl 0x9f(%rsp),%edx
lea    0xb4d(%rip),%rdi
mov    %r13d,%esi
xor    %eax,%eax
call   1060 <printf@plt>
test   %r13d,%r13d
je     12f0 <main+0xf0>
lea    0xb70(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %r12d,%edi
lea    0x20(%rsp),%rsi
mov    %r13d,%edx
call   1040 <write@plt>
cmp    %r13d,%eax
jge    1590 <main+0x390>
lea    0xdda(%rip),%rdi
call   1030 <puts@plt>
jmp    1590 <main+0x390>
lea    0xba4(%rip),%rdi
call   10e0 <perror@plt>
jmp    1319 <main+0x119>
lea    0xeb5(%rip),%rdi
jmp    1681 <main+0x481>
lea    0xe58(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1110 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str = [22 x i8] c"opening stream socket\00"
@INADDR_ANY = global i32 0
@.str.1 = [28 x i8] c"Wrong:binding stream socket\00"
@.str.2 = [26 x i8] c"Wrong:getting socket name\00"
@.str.3 = [17 x i8] c"Socket port: %d\0A\00"
@.str.4 = [25 x i8] c"\C3\95\C3\BD\C3\94\C3\9A\C2\BC\C3\A0\C3\8C\C3\BD......\0A\0A\00"
@.str.5 = [59 x i8] c"\C2\B4\C2\B4\C2\BD\C2\A8\C3\81\C3\99\C3\8A\C2\B1socket\C2\A3\C2\AC\C3\93\C3\83\C3\93\C3\9A\C3\92\C2\BB\C2\B4\C3\8E\C2\B7\C3\BE\C3\8E\C3\B1......\0A\0A\00"
@.str.6 = [9 x i8] c"test.txt\00"
@O_RDONLY = global i32 0
@.str.7 = [63 x i8] c"\C3\95\C3\92\C2\B2\C2\BB\C2\B5\C2\BD\C3\8E\C3\84\C2\BC\C3\BEtest.txt\C2\BB\C3\B2\C2\B4\C3\B2\C2\B2\C2\BB\C2\BF\C2\AA,\C3\8D\C2\A3\C3\96\C2\B9\C3\94\C3\8B\C3\90\C3\90\0A\00"
@.str.8 = [69 x i8] c"\C2\B4\C3\B2\C2\BF\C2\AA\C3\8E\C3\84\C2\BC\C3\BEtest.txt\C2\A3\C2\AC\C2\BD\C2\AB\C3\86\C3\A4\C3\84\C3\9A\C3\88\C3\9D\C2\B7\C2\A2\C3\8B\C3\8D\C2\B3\C3\B6\C3\88\C2\A5......\0A\0A\00"
@.str.9 = [57 x i8] c"\C2\B4\C3\93\C3\8E\C3\84\C2\BC\C3\BE\C3\96\C3\90\C2\B6\C3\81\C3\81\C3\8B\C2\B4\C3\B3\C3\90\C2\A1\C3\8E\C2\AA %d \C2\B5\C3\84\C3\8A\C3\BD\C2\BE\C3\9D\C2\A1\C2\A3\00"
@.str.10 = [22 x i8] c"\C3\90\C2\B4sock\C2\B3\C3\B6\C3\81\C3\8B\C2\B4\C3\AD\0A\00"
@.str.11 = [49 x i8] c"\C2\B7\C2\A2\C3\8B\C3\8D\C2\B0\C3\BC\C2\B4\C3\B3\C3\90\C2\A1 %d, \C2\BF\C3\A9\C2\B1\C3\A0\C2\BA\C3\85 %d ......\0A\00"
@.str.12 = [22 x i8] c"\C2\B6\C3\81sock\C2\B3\C3\B6\C3\81\C3\8B\C2\B4\C3\AD\0A\00"
@.str.13 = [74 x i8] c"...\C3\8A\C3\95\C2\B5\C2\BD\C3\93\C2\A6\C2\B4\C3\B0\C2\A3\C2\AC\C2\B6\C3\94\C2\B7\C2\BD\C3\8A\C3\95\C2\B5\C2\BD\C2\BF\C3\A9\C2\B1\C3\A0\C2\BA\C3\85\C3\8E\C2\AA %s \C2\B5\C3\84\C2\B0\C3\BC\C2\A1\C2\A3\0A\0A\00"
@.str.14 = [61 x i8] c"......\C2\B6\C3\81\C3\8E\C3\84\C2\BC\C3\BE\C2\BD\C3\A1\C3\8A\C3\B8\C2\A3\C2\AC\C2\B9\C3\98\C2\B1\C3\95\C3\8E\C3\84\C2\BC\C3\BEtest.txt\C2\A1\C2\A3\0A\0A\00"
@.str.15 = [122 x i8] c"\C2\B7\C2\A2\C3\8B\C3\8D\C3\8A\C2\B5\C2\BC\C3\8A\C3\8A\C3\BD\C2\BE\C3\9D\C2\B4\C3\B3\C3\90\C2\A1\C3\8E\C2\AA0\C2\B5\C3\84\C2\B0\C3\BC\C2\A3\C2\AC\C3\97\C3\B7\C3\8E\C2\AA\C3\8E\C3\84\C2\BC\C3\BE\C2\B4\C2\AB\C3\8B\C3\8D\C2\BD\C3\A1\C3\8A\C3\B8\C2\B1\C3\AA\C3\96\C2\BE\C2\A3\C2\AC\C2\B2\C2\BB\C3\90\C3\A8\C3\92\C2\AA\C3\93\C2\A6\C2\B4\C3\B0......\0A\0A\00"
@.str.16 = [18 x i8] c"\C3\90\C2\B4sock\C2\B3\C3\B6\C2\B4\C3\AD\0A\00"
@.str.17 = [67 x i8] c"\C2\B4\C2\B4\C2\BD\C2\A8\C3\8E\C3\84\C2\BC\C3\BEtest2.txt\C3\93\C3\83\C3\93\C3\9A\C2\BD\C3\93\C3\8A\C3\95\C3\8D\C3\B8\C3\82\C3\A7\C3\90\C3\85\C3\8F\C2\A2......\0A\0A\0A\00"
@.str.18 = [10 x i8] c"test2.txt\00"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@.str.19 = [26 x i8] c"\C2\B4\C2\B4\C2\BD\C2\A8\C3\8E\C3\84\C2\BC\C3\BE\C2\B3\C3\B6\C2\B4\C3\AD\0A\00"
@.str.20 = [62 x i8] c"...\C2\B4\C3\93sock\C2\B6\C3\81\C3\81\C3\8B\C2\B5\C3\9A %d \C2\B8\C3\B6\C3\8A\C3\BD\C2\BE\C3\9D\C2\B0\C3\BC,\C2\B4\C3\B3\C3\90\C2\A1\C3\8A\C3\87 %d ,\00"
@.str.21 = [61 x i8] c"\C3\8A\C3\BD\C2\BE\C3\9D\C3\8A\C2\B5\C2\BC\C3\8A\C2\B4\C3\B3\C3\90\C2\A1\C3\8A\C3\87 %d \C2\A3\C2\AC\C2\BF\C3\A9\C2\B1\C3\A0\C2\BA\C3\85\C3\8A\C3\87\22%c\22. \0A\00"
@.str.22 = [141 x i8] c"\0A.....\C3\8A\C3\95\C2\B5\C2\BD\C3\8A\C3\BD\C2\BE\C3\9D\C3\8A\C2\B5\C2\BC\C3\8A\C2\B4\C3\B3\C3\90\C2\A1\C3\8E\C2\AA0\C2\B5\C3\84\C3\8C\C3\98\C2\B6\C2\A8\C2\B0\C3\BC\C2\A3\C2\AC\C2\B6\C3\94\C2\B7\C2\BD\C2\B7\C2\A2\C3\8B\C3\8D\C2\BD\C3\A1\C3\8A\C3\B8\C2\A3\C2\AC\C3\8C\C3\B8\C2\B3\C3\B6\C3\91\C2\AD\C2\BB\C2\B7\C2\A3\C2\AC\C2\BD\C3\93\C3\8A\C3\95\C3\8E\C3\84\C2\BC\C3\BE\C2\BD\C3\A1\C3\8A\C3\B8...\0A\0A\00"
@.str.23 = [41 x i8] c"\C2\BD\C2\AB\C3\93\C3\90\C3\90\C2\A7\C3\8A\C3\BD\C2\BE\C3\9D\C3\90\C2\B4\C3\88\C3\AB\C3\8E\C3\84\C2\BC\C3\BE\C2\A1\C2\A3\00"
@.str.24 = [30 x i8] c"\C3\90\C2\B4\C3\8E\C3\84\C2\BC\C3\BE\C3\8A\C2\B1\C2\B3\C3\B6\C3\81\C3\8B\C2\B4\C3\AD\0A\00"
@.str.25 = [67 x i8] c"\C2\BD\C2\AB\C2\BF\C3\A9\C2\B1\C3\A0\C2\BA\C3\85 \22%c\22 \C2\B7\C2\B5\C2\BB\C3\98\C2\B7\C3\BE\C3\8E\C3\B1\C3\86\C3\B7\C3\97\C3\B7\C3\8E\C2\AA\C3\93\C2\A6\C2\B4\C3\B0......\0A\0A\00"
@.str.26 = [34 x i8] c"......\C2\B9\C3\98\C2\B1\C3\95\C3\8E\C3\84\C2\BC\C3\BEtest2.txt\0A\0A\00"
@.str.27 = [13 x i8] c"Wrong:accept\00"
@.str.28 = [83 x i8] c"......\C3\92\C2\BB\C2\B4\C3\8E\C2\B7\C3\BE\C3\8E\C3\B1\C2\BD\C3\A1\C3\8A\C3\B8\C2\A3\C2\AC\C3\81\C3\99\C3\8A\C2\B1socket\C2\B2\C2\BB\C3\94\C3\99\C3\90\C3\A8\C3\92\C2\AA\C2\A3\C2\AC\C3\8F\C3\BB\C2\B3\C3\BD\C2\A1\C2\A3\0A\0A\00"
@.str.29 = [25 x i8] c"\C2\BC\C3\8C\C3\90\C3\B8\C2\BC\C3\A0\C3\8C\C3\BD......\0A\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca %struct.sockaddr_in
%5 = alloca %struct.sockaddr_in
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca [128 x i8]
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca i8
store i32 0, i32* %1
%17 = load i32, i32* @AF_INET
%18 = load i32, i32* @SOCK_STREAM
%19 = call i32 @socket(i32 %17, i32 %18, i32 0)
store i32 %19, i32* %6
%20 = load i32, i32* %6
%21 = icmp slt i32 %20, 0
br i1 %21, label %22, label %25
22: ; preds = %0
%23 = call i32 @perror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%24 = call i32 @exit(i32 1)
unreachable
25: ; preds = %0
%26 = load i32, i32* @AF_INET
%27 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i32 0, i32 2
store i32 %26, i32* %27
%28 = load i32, i32* @INADDR_ANY
%29 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i32 0, i32 1
%30 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %29, i32 0, i32 0
store i32 %28, i32* %30
%31 = call i32 @htons(i32 20000)
%32 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i32 0, i32 0
store i32 %31, i32* %32
%33 = load i32, i32* %6
%34 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%35 = call i64 @bind(i32 %33, %struct.sockaddr* %34, i32 12)
%36 = icmp slt i64 %35, 0
br i1 %36, label %37, label %40
37: ; preds = %25
%38 = call i32 @perror(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0))
%39 = call i32 @exit(i32 1)
unreachable
40: ; preds = %25
store i32 12, i32* %2
%41 = load i32, i32* %6
%42 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%43 = call i64 @getsockname(i32 %41, %struct.sockaddr* %42, i32* %2)
%44 = icmp slt i64 %43, 0
br i1 %44, label %45, label %48
45: ; preds = %40
%46 = call i32 @perror(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
%47 = call i32 @exit(i32 1)
unreachable
48: ; preds = %40
%49 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i32 0, i32 0
%50 = load i32, i32* %49
%51 = call i32 @ntohs(i32 %50)
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0), i32 %51)
%53 = load i32, i32* %6
%54 = call i32 @listen(i32 %53, i32 5)
%55 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0))
br label %56
56: ; preds = %48, %197
store i32 12, i32* %3
%57 = load i32, i32* %6
%58 = bitcast %struct.sockaddr_in* %5 to %struct.sockaddr*
%59 = call i32 @accept(i32 %57, %struct.sockaddr* %58, i32* %3)
store i32 %59, i32* %7
%60 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str.5, i64 0, i64 0))
%61 = load i32, i32* %7
%62 = icmp ne i32 %61, -1
br i1 %62, label %63, label %195
63: ; preds = %56
store i32 0, i32* %11
%64 = load i32, i32* @O_RDONLY
%65 = call i32 (i8*, i32, ...) @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0), i32 %64)
store i32 %65, i32* %8
%66 = icmp eq i32 %65, -1
br i1 %66, label %67, label %70
67: ; preds = %63
%68 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([63 x i8], [63 x i8]* @.str.7, i64 0, i64 0))
%69 = call i32 @exit(i32 1)
unreachable
70: ; preds = %63
%71 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([69 x i8], [69 x i8]* @.str.8, i64 0, i64 0))
%72 = getelementptr inbounds [128 x i8], [128 x i8]* %10, i64 0, i64 0
%73 = call i32 @memset(i8* %72, i32 0, i32 128)
br label %74
74: ; preds = %116, %70
%75 = load i32, i32* %8
%76 = getelementptr inbounds [128 x i8], [128 x i8]* %10, i64 0, i64 0
%77 = call i64 @read(i32 %75, i8* %76, i32 126)
%78 = trunc i64 %77 to i32
store i32 %78, i32* %9
%79 = icmp sgt i32 %78, 0
br i1 %79, label %80, label %117
80: ; preds = %74
%81 = load i32, i32* %9
%82 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str.9, i64 0, i64 0), i32 %81)
%83 = load i32, i32* %9
%84 = trunc i32 %83 to i8
%85 = getelementptr inbounds [128 x i8], [128 x i8]* %10, i64 0, i64 126
store i8 %84, i8* %85
%86 = load i32, i32* %11
%87 = add nsw i32 %86, 1
store i32 %87, i32* %11
%88 = load i32, i32* %11
%89 = srem i32 %88, 10
%90 = add nsw i32 %89, 48
%91 = trunc i32 %90 to i8
%92 = getelementptr inbounds [128 x i8], [128 x i8]* %10, i64 0, i64 127
store i8 %91, i8* %92
%93 = load i32, i32* %7
%94 = getelementptr inbounds [128 x i8], [128 x i8]* %10, i64 0, i64 0
%95 = call i32 @write(i32 %93, i8* %94, i32 128)
%96 = load i32, i32* %9
%97 = icmp sle i32 %95, %96
br i1 %97, label %98, label %100
98: ; preds = %80
%99 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.10, i64 0, i64 0))
br label %104
100: ; preds = %80
%101 = load i32, i32* %11
%102 = srem i32 %101, 10
%103 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.11, i64 0, i64 0), i32 128, i32 %102)
br label %104
104: ; preds = %100, %98
%105 = getelementptr inbounds [128 x i8], [128 x i8]* %10, i64 0, i64 0
%106 = call i32 @memset(i8* %105, i32 0, i32 128)
%107 = load i32, i32* %7
%108 = getelementptr inbounds [128 x i8], [128 x i8]* %10, i64 0, i64 0
%109 = call i64 @read(i32 %107, i8* %108, i32 128)
%110 = icmp slt i64 %109, 0
br i1 %110, label %111, label %113
111: ; preds = %104
%112 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.12, i64 0, i64 0))
br label %116
113: ; preds = %104
%114 = getelementptr inbounds [128 x i8], [128 x i8]* %10, i64 0, i64 0
%115 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([74 x i8], [74 x i8]* @.str.13, i64 0, i64 0), i8* %114)
br label %116
116: ; preds = %113, %111
br label %74
117: ; preds = %74
%118 = load i32, i32* %8
%119 = call i32 @close(i32 %118)
%120 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str.14, i64 0, i64 0))
%121 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([122 x i8], [122 x i8]* @.str.15, i64 0, i64 0))
%122 = getelementptr inbounds [128 x i8], [128 x i8]* %10, i64 0, i64 126
store i8 0, i8* %122
%123 = load i32, i32* %7
%124 = getelementptr inbounds [128 x i8], [128 x i8]* %10, i64 0, i64 0
%125 = call i32 @write(i32 %123, i8* %124, i32 128)
%126 = load i32, i32* %9
%127 = icmp sle i32 %125, %126
br i1 %127, label %128, label %130
128: ; preds = %117
%129 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.16, i64 0, i64 0))
br label %130
130: ; preds = %128, %117
store i32 0, i32* %15
%131 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([67 x i8], [67 x i8]* @.str.17, i64 0, i64 0))
%132 = load i32, i32* @O_WRONLY
%133 = load i32, i32* @O_CREAT
%134 = or i32 %132, %133
%135 = load i32, i32* @O_TRUNC
%136 = or i32 %134, %135
%137 = call i32 (i8*, i32, ...) @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.18, i64 0, i64 0), i32 %136, i32 420)
store i32 %137, i32* %12
%138 = icmp eq i32 %137, -1
br i1 %138, label %139, label %142
139: ; preds = %130
%140 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.19, i64 0, i64 0))
%141 = call i32 @exit(i32 1)
unreachable
142: ; preds = %130
%143 = getelementptr inbounds [128 x i8], [128 x i8]* %10, i64 0, i64 0
%144 = call i32 @memset(i8* %143, i32 0, i32 128)
br label %145
145: ; preds = %178, %142
%146 = load i32, i32* %7
%147 = getelementptr inbounds [128 x i8], [128 x i8]* %10, i64 0, i64 0
%148 = call i64 @read(i32 %146, i8* %147, i32 128)
%149 = trunc i64 %148 to i32
store i32 %149, i32* %13
%150 = icmp sgt i32 %149, 0
br i1 %150, label %151, label %191
151: ; preds = %145
%152 = load i32, i32* %15
%153 = add nsw i32 %152, 1
store i32 %153, i32* %15
%154 = load i32, i32* %13
%155 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([62 x i8], [62 x i8]* @.str.20, i64 0, i64 0), i32 %153, i32 %154)
%156 = getelementptr inbounds [128 x i8], [128 x i8]* %10, i64 0, i64 126
%157 = load i8, i8* %156
%158 = sext i8 %157 to i32
store i32 %158, i32* %14
%159 = load i32, i32* %14
%160 = getelementptr inbounds [128 x i8], [128 x i8]* %10, i64 0, i64 127
%161 = load i8, i8* %160
%162 = sext i8 %161 to i32
%163 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str.21, i64 0, i64 0), i32 %159, i32 %162)
%164 = load i32, i32* %14
%165 = icmp eq i32 %164, 0
br i1 %165, label %166, label %168
166: ; preds = %151
%167 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([141 x i8], [141 x i8]* @.str.22, i64 0, i64 0))
br label %191
168: ; preds = %151
%169 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.23, i64 0, i64 0))
%170 = load i32, i32* %12
%171 = getelementptr inbounds [128 x i8], [128 x i8]* %10, i64 0, i64 0
%172 = load i32, i32* %14
%173 = call i32 @write(i32 %170, i8* %171, i32 %172)
%174 = load i32, i32* %14
%175 = icmp slt i32 %173, %174
br i1 %175, label %176, label %178
176: ; preds = %168
%177 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.24, i64 0, i64 0))
br label %178
178: ; preds = %176, %168
%179 = getelementptr inbounds [128 x i8], [128 x i8]* %10, i64 0, i64 127
%180 = load i8, i8* %179
store i8 %180, i8* %16
%181 = load i8, i8* %16
%182 = sext i8 %181 to i32
%183 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([67 x i8], [67 x i8]* @.str.25, i64 0, i64 0), i32 %182)
%184 = getelementptr inbounds [128 x i8], [128 x i8]* %10, i64 0, i64 0
%185 = call i32 @memset(i8* %184, i32 0, i32 128)
%186 = load i8, i8* %16
%187 = getelementptr inbounds [128 x i8], [128 x i8]* %10, i64 0, i64 0
store i8 %186, i8* %187
%188 = load i32, i32* %7
%189 = getelementptr inbounds [128 x i8], [128 x i8]* %10, i64 0, i64 0
%190 = call i32 @write(i32 %188, i8* %189, i32 128)
br label %145
191: ; preds = %166, %145
%192 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.26, i64 0, i64 0))
%193 = load i32, i32* %12
%194 = call i32 @close(i32 %193)
br label %197
195: ; preds = %56
%196 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.27, i64 0, i64 0))
br label %197
197: ; preds = %195, %191
%198 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([83 x i8], [83 x i8]* @.str.28, i64 0, i64 0))
%199 = load i32, i32* %7
%200 = call i32 @close(i32 %199)
%201 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.29, i64 0, i64 0))
br label %56
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str = [22 x i8] c"opening stream socket\00"
@INADDR_ANY = global i32 0
@.str.1 = [28 x i8] c"Wrong:binding stream socket\00"
@.str.2 = [26 x i8] c"Wrong:getting socket name\00"
@.str.3 = [17 x i8] c"Socket port: %d\0A\00"
@.str.6 = [9 x i8] c"test.txt\00"
@O_RDONLY = global i32 0
@.str.9 = [57 x i8] c"\C2\B4\C3\93\C3\8E\C3\84\C2\BC\C3\BE\C3\96\C3\90\C2\B6\C3\81\C3\81\C3\8B\C2\B4\C3\B3\C3\90\C2\A1\C3\8E\C2\AA %d \C2\B5\C3\84\C3\8A\C3\BD\C2\BE\C3\9D\C2\A1\C2\A3\00"
@.str.11 = [49 x i8] c"\C2\B7\C2\A2\C3\8B\C3\8D\C2\B0\C3\BC\C2\B4\C3\B3\C3\90\C2\A1 %d, \C2\BF\C3\A9\C2\B1\C3\A0\C2\BA\C3\85 %d ......\0A\00"
@.str.13 = [74 x i8] c"...\C3\8A\C3\95\C2\B5\C2\BD\C3\93\C2\A6\C2\B4\C3\B0\C2\A3\C2\AC\C2\B6\C3\94\C2\B7\C2\BD\C3\8A\C3\95\C2\B5\C2\BD\C2\BF\C3\A9\C2\B1\C3\A0\C2\BA\C3\85\C3\8E\C2\AA %s \C2\B5\C3\84\C2\B0\C3\BC\C2\A1\C2\A3\0A\0A\00"
@.str.18 = [10 x i8] c"test2.txt\00"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@.str.20 = [62 x i8] c"...\C2\B4\C3\93sock\C2\B6\C3\81\C3\81\C3\8B\C2\B5\C3\9A %d \C2\B8\C3\B6\C3\8A\C3\BD\C2\BE\C3\9D\C2\B0\C3\BC,\C2\B4\C3\B3\C3\90\C2\A1\C3\8A\C3\87 %d ,\00"
@.str.21 = [61 x i8] c"\C3\8A\C3\BD\C2\BE\C3\9D\C3\8A\C2\B5\C2\BC\C3\8A\C2\B4\C3\B3\C3\90\C2\A1\C3\8A\C3\87 %d \C2\A3\C2\AC\C2\BF\C3\A9\C2\B1\C3\A0\C2\BA\C3\85\C3\8A\C3\87\22%c\22. \0A\00"
@.str.23 = [41 x i8] c"\C2\BD\C2\AB\C3\93\C3\90\C3\90\C2\A7\C3\8A\C3\BD\C2\BE\C3\9D\C3\90\C2\B4\C3\88\C3\AB\C3\8E\C3\84\C2\BC\C3\BE\C2\A1\C2\A3\00"
@.str.25 = [67 x i8] c"\C2\BD\C2\AB\C2\BF\C3\A9\C2\B1\C3\A0\C2\BA\C3\85 \22%c\22 \C2\B7\C2\B5\C2\BB\C3\98\C2\B7\C3\BE\C3\8E\C3\B1\C3\86\C3\B7\C3\97\C3\B7\C3\8E\C2\AA\C3\93\C2\A6\C2\B4\C3\B0......\0A\0A\00"
@.str.27 = [13 x i8] c"Wrong:accept\00"
@str = [24 x i8] c"\C3\95\C3\BD\C3\94\C3\9A\C2\BC\C3\A0\C3\8C\C3\BD......\0A\00"
@str.30 = [58 x i8] c"\C2\B4\C2\B4\C2\BD\C2\A8\C3\81\C3\99\C3\8A\C2\B1socket\C2\A3\C2\AC\C3\93\C3\83\C3\93\C3\9A\C3\92\C2\BB\C2\B4\C3\8E\C2\B7\C3\BE\C3\8E\C3\B1......\0A\00"
@str.31 = [82 x i8] c"......\C3\92\C2\BB\C2\B4\C3\8E\C2\B7\C3\BE\C3\8E\C3\B1\C2\BD\C3\A1\C3\8A\C3\B8\C2\A3\C2\AC\C3\81\C3\99\C3\8A\C2\B1socket\C2\B2\C2\BB\C3\94\C3\99\C3\90\C3\A8\C3\92\C2\AA\C2\A3\C2\AC\C3\8F\C3\BB\C2\B3\C3\BD\C2\A1\C2\A3\0A\00"
@str.32 = [24 x i8] c"\C2\BC\C3\8C\C3\90\C3\B8\C2\BC\C3\A0\C3\8C\C3\BD......\0A\00"
@str.33 = [68 x i8] c"\C2\B4\C3\B2\C2\BF\C2\AA\C3\8E\C3\84\C2\BC\C3\BEtest.txt\C2\A3\C2\AC\C2\BD\C2\AB\C3\86\C3\A4\C3\84\C3\9A\C3\88\C3\9D\C2\B7\C2\A2\C3\8B\C3\8D\C2\B3\C3\B6\C3\88\C2\A5......\0A\00"
@str.34 = [60 x i8] c"......\C2\B6\C3\81\C3\8E\C3\84\C2\BC\C3\BE\C2\BD\C3\A1\C3\8A\C3\B8\C2\A3\C2\AC\C2\B9\C3\98\C2\B1\C3\95\C3\8E\C3\84\C2\BC\C3\BEtest.txt\C2\A1\C2\A3\0A\00"
@str.35 = [121 x i8] c"\C2\B7\C2\A2\C3\8B\C3\8D\C3\8A\C2\B5\C2\BC\C3\8A\C3\8A\C3\BD\C2\BE\C3\9D\C2\B4\C3\B3\C3\90\C2\A1\C3\8E\C2\AA0\C2\B5\C3\84\C2\B0\C3\BC\C2\A3\C2\AC\C3\97\C3\B7\C3\8E\C2\AA\C3\8E\C3\84\C2\BC\C3\BE\C2\B4\C2\AB\C3\8B\C3\8D\C2\BD\C3\A1\C3\8A\C3\B8\C2\B1\C3\AA\C3\96\C2\BE\C2\A3\C2\AC\C2\B2\C2\BB\C3\90\C3\A8\C3\92\C2\AA\C3\93\C2\A6\C2\B4\C3\B0......\0A\00"
@str.36 = [66 x i8] c"\C2\B4\C2\B4\C2\BD\C2\A8\C3\8E\C3\84\C2\BC\C3\BEtest2.txt\C3\93\C3\83\C3\93\C3\9A\C2\BD\C3\93\C3\8A\C3\95\C3\8D\C3\B8\C3\82\C3\A7\C3\90\C3\85\C3\8F\C2\A2......\0A\0A\00"
@str.37 = [33 x i8] c"......\C2\B9\C3\98\C2\B1\C3\95\C3\8E\C3\84\C2\BC\C3\BEtest2.txt\0A\00"
@str.38 = [29 x i8] c"\C3\90\C2\B4\C3\8E\C3\84\C2\BC\C3\BE\C3\8A\C2\B1\C2\B3\C3\B6\C3\81\C3\8B\C2\B4\C3\AD\00"
@str.39 = [140 x i8] c"\0A.....\C3\8A\C3\95\C2\B5\C2\BD\C3\8A\C3\BD\C2\BE\C3\9D\C3\8A\C2\B5\C2\BC\C3\8A\C2\B4\C3\B3\C3\90\C2\A1\C3\8E\C2\AA0\C2\B5\C3\84\C3\8C\C3\98\C2\B6\C2\A8\C2\B0\C3\BC\C2\A3\C2\AC\C2\B6\C3\94\C2\B7\C2\BD\C2\B7\C2\A2\C3\8B\C3\8D\C2\BD\C3\A1\C3\8A\C3\B8\C2\A3\C2\AC\C3\8C\C3\B8\C2\B3\C3\B6\C3\91\C2\AD\C2\BB\C2\B7\C2\A3\C2\AC\C2\BD\C3\93\C3\8A\C3\95\C3\8E\C3\84\C2\BC\C3\BE\C2\BD\C3\A1\C3\8A\C3\B8...\0A\00"
@str.40 = [25 x i8] c"\C2\B4\C2\B4\C2\BD\C2\A8\C3\8E\C3\84\C2\BC\C3\BE\C2\B3\C3\B6\C2\B4\C3\AD\00"
@str.41 = [17 x i8] c"\C3\90\C2\B4sock\C2\B3\C3\B6\C2\B4\C3\AD\00"
@str.42 = [21 x i8] c"\C2\B6\C3\81sock\C2\B3\C3\B6\C3\81\C3\8B\C2\B4\C3\AD\00"
@str.43 = [21 x i8] c"\C3\90\C2\B4sock\C2\B3\C3\B6\C3\81\C3\8B\C2\B4\C3\AD\00"
@str.44 = [62 x i8] c"\C3\95\C3\92\C2\B2\C2\BB\C2\B5\C2\BD\C3\8E\C3\84\C2\BC\C3\BEtest.txt\C2\BB\C3\B2\C2\B4\C3\B2\C2\B2\C2\BB\C2\BF\C2\AA,\C3\8D\C2\A3\C3\96\C2\B9\C3\94\C3\8B\C3\90\C3\90\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca %struct.sockaddr_in
%4 = alloca %struct.sockaddr_in
%5 = alloca [128 x i8]
%6 = bitcast i32* %1 to i8*
%7 = bitcast i32* %2 to i8*
%8 = bitcast %struct.sockaddr_in* %3 to i8*
%9 = bitcast %struct.sockaddr_in* %4 to i8*
%10 = load i32, i32* @AF_INET
%11 = load i32, i32* @SOCK_STREAM
%12 = tail call i32 @socket(i32 %10, i32 %11, i32 0)
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %17
14: ; preds = %0
%15 = tail call i32 @perror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%16 = tail call i32 @exit(i32 1)
unreachable
17: ; preds = %0
%18 = load i32, i32* @AF_INET
%19 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %18, i32* %19
%20 = load i32, i32* @INADDR_ANY
%21 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1, i32 0
store i32 %20, i32* %21
%22 = tail call i32 @htons(i32 20000)
%23 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
store i32 %22, i32* %23
%24 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%25 = call i64 @bind(i32 %12, %struct.sockaddr* %24, i32 12)
%26 = icmp slt i64 %25, 0
br i1 %26, label %27, label %30
27: ; preds = %17
%28 = call i32 @perror(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0))
%29 = call i32 @exit(i32 1)
unreachable
30: ; preds = %17
store i32 12, i32* %1
%31 = call i64 @getsockname(i32 %12, %struct.sockaddr* %24, i32* %1)
%32 = icmp slt i64 %31, 0
br i1 %32, label %33, label %36
33: ; preds = %30
%34 = call i32 @perror(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
%35 = call i32 @exit(i32 1)
unreachable
36: ; preds = %30
%37 = load i32, i32* %23
%38 = call i32 @ntohs(i32 %37)
%39 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0), i32 %38)
%40 = call i32 @listen(i32 %12, i32 5)
%41 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str, i64 0, i64 0))
%42 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%43 = getelementptr inbounds [128 x i8], [128 x i8]* %5, i64 0, i64 0
%44 = getelementptr inbounds [128 x i8], [128 x i8]* %5, i64 0, i64 126
%45 = getelementptr inbounds [128 x i8], [128 x i8]* %5, i64 0, i64 127
br label %46
46: ; preds = %152, %36
store i32 12, i32* %2
%47 = call i32 @accept(i32 %12, %struct.sockaddr* %42, i32* %2)
%48 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([58 x i8], [58 x i8]* @str.30, i64 0, i64 0))
%49 = icmp eq i32 %47, -1
br i1 %49, label %150, label %50
50: ; preds = %46
%51 = load i32, i32* @O_RDONLY
%52 = call i32 (i8*, i32, ...) @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0), i32 %51)
%53 = icmp eq i32 %52, -1
br i1 %53, label %54, label %57
54: ; preds = %50
%55 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([62 x i8], [62 x i8]* @str.44, i64 0, i64 0))
%56 = call i32 @exit(i32 1)
unreachable
57: ; preds = %50
%58 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([68 x i8], [68 x i8]* @str.33, i64 0, i64 0))
%59 = call i32 @memset(i8* %43, i32 0, i32 128)
%60 = call i64 @read(i32 %52, i8* %43, i32 126)
%61 = trunc i64 %60 to i32
%62 = icmp sgt i32 %61, 0
br i1 %62, label %63, label %93
63: ; preds = %57, %87
%64 = phi i32 [ %89, %87 ], [ %61, %57 ]
%65 = phi i64 [ %88, %87 ], [ %60, %57 ]
%66 = phi i32 [ %69, %87 ], [ 0, %57 ]
%67 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([57 x i8], [57 x i8]* @.str.9, i64 0, i64 0), i32 %64)
%68 = trunc i64 %65 to i8
store i8 %68, i8* %44
%69 = add nuw nsw i32 %66, 1
%70 = urem i32 %69, 10
%71 = trunc i32 %70 to i8
%72 = or i8 %71, 48
store i8 %72, i8* %45
%73 = call i32 @write(i32 %47, i8* %43, i32 128)
%74 = icmp sgt i32 %73, %64
br i1 %74, label %77, label %75
75: ; preds = %63
%76 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str.43, i64 0, i64 0))
br label %79
77: ; preds = %63
%78 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([49 x i8], [49 x i8]* @.str.11, i64 0, i64 0), i32 128, i32 %70)
br label %79
79: ; preds = %77, %75
%80 = call i32 @memset(i8* %43, i32 0, i32 128)
%81 = call i64 @read(i32 %47, i8* %43, i32 128)
%82 = icmp slt i64 %81, 0
br i1 %82, label %83, label %85
83: ; preds = %79
%84 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str.42, i64 0, i64 0))
br label %87
85: ; preds = %79
%86 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([74 x i8], [74 x i8]* @.str.13, i64 0, i64 0), i8* %43)
br label %87
87: ; preds = %85, %83
%88 = call i64 @read(i32 %52, i8* %43, i32 126)
%89 = trunc i64 %88 to i32
%90 = icmp sgt i32 %89, 0
br i1 %90, label %63, label %91
91: ; preds = %87
%92 = trunc i64 %88 to i32
br label %93
93: ; preds = %91, %57
%94 = phi i32 [ %61, %57 ], [ %92, %91 ]
%95 = call i32 @close(i32 %52)
%96 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([60 x i8], [60 x i8]* @str.34, i64 0, i64 0))
%97 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([121 x i8], [121 x i8]* @str.35, i64 0, i64 0))
store i8 0, i8* %44
%98 = call i32 @write(i32 %47, i8* %43, i32 128)
%99 = icmp sgt i32 %98, %94
br i1 %99, label %102, label %100
100: ; preds = %93
%101 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str.41, i64 0, i64 0))
br label %102
102: ; preds = %100, %93
%103 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([66 x i8], [66 x i8]* @str.36, i64 0, i64 0))
%104 = load i32, i32* @O_WRONLY
%105 = load i32, i32* @O_CREAT
%106 = or i32 %105, %104
%107 = load i32, i32* @O_TRUNC
%108 = or i32 %106, %107
%109 = call i32 (i8*, i32, ...) @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.18, i64 0, i64 0), i32 %108, i32 420)
%110 = icmp eq i32 %109, -1
br i1 %110, label %111, label %114
111: ; preds = %102
%112 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str.40, i64 0, i64 0))
%113 = call i32 @exit(i32 1)
unreachable
114: ; preds = %102
%115 = call i32 @memset(i8* %43, i32 0, i32 128)
%116 = call i64 @read(i32 %47, i8* %43, i32 128)
%117 = trunc i64 %116 to i32
%118 = icmp sgt i32 %117, 0
br i1 %118, label %119, label %147
119: ; preds = %114, %138
%120 = phi i32 [ %145, %138 ], [ %117, %114 ]
%121 = phi i32 [ %122, %138 ], [ 0, %114 ]
%122 = add nuw nsw i32 %121, 1
%123 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([62 x i8], [62 x i8]* @.str.20, i64 0, i64 0), i32 %122, i32 %120)
%124 = load i8, i8* %44
%125 = sext i8 %124 to i32
%126 = load i8, i8* %45
%127 = sext i8 %126 to i32
%128 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([61 x i8], [61 x i8]* @.str.21, i64 0, i64 0), i32 %125, i32 %127)
%129 = icmp eq i8 %124, 0
br i1 %129, label %130, label %132
130: ; preds = %119
%131 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([140 x i8], [140 x i8]* @str.39, i64 0, i64 0))
br label %147
132: ; preds = %119
%133 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @.str.23, i64 0, i64 0))
%134 = call i32 @write(i32 %109, i8* %43, i32 %125)
%135 = icmp slt i32 %134, %125
br i1 %135, label %136, label %138
136: ; preds = %132
%137 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str.38, i64 0, i64 0))
br label %138
138: ; preds = %136, %132
%139 = load i8, i8* %45
%140 = sext i8 %139 to i32
%141 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([67 x i8], [67 x i8]* @.str.25, i64 0, i64 0), i32 %140)
%142 = call i32 @memset(i8* %43, i32 0, i32 128)
store i8 %139, i8* %43
%143 = call i32 @write(i32 %47, i8* %43, i32 128)
%144 = call i64 @read(i32 %47, i8* %43, i32 128)
%145 = trunc i64 %144 to i32
%146 = icmp sgt i32 %145, 0
br i1 %146, label %119, label %147
147: ; preds = %138, %114, %130
%148 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @str.37, i64 0, i64 0))
%149 = call i32 @close(i32 %109)
br label %152
150: ; preds = %46
%151 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.27, i64 0, i64 0))
br label %152
152: ; preds = %150, %147
%153 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([82 x i8], [82 x i8]* @str.31, i64 0, i64 0))
%154 = call i32 @close(i32 %47)
%155 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str.32, i64 0, i64 0))
br label %46
}