#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 /*<<< orphan*/ serv_addr;
typedef int /*<<< orphan*/ cli_addr;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ INADDR_ANY;
int /*<<< orphan*/ SOCK_STREAM;
int accept(int, struct sockaddr *, int *);
int atoi(char *);
scalar_t__ bind(int, struct sockaddr *, int);
int /*<<< orphan*/ bzero(char *, int);
int /*<<< orphan*/ exit(int);
char getchar();
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ listen(int, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int read(int, char *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ sprintf(char *, char *, int, char *);
int strlen(char *);
int /*<<< orphan*/ write(int, char *, int);
int main1(int argc, char *argv[]) {
  int sockfd, newsockfd, portno, clilen;
  printf("TCP server is started\n");
  char buffer[9999];
  struct sockaddr_in serv_addr, cli_addr;
  int n;
  sockfd = socket(AF_INET, SOCK_STREAM, 0);
  if (sockfd < 0) {
    perror("ERROR opening socket");
    exit(1);
  }
  bzero((char *)&serv_addr, sizeof(serv_addr));
  portno = 8001;
  serv_addr.sin_family = AF_INET;
  serv_addr.sin_addr.s_addr = INADDR_ANY;
  serv_addr.sin_port = htons(portno);
  if (bind(sockfd, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) < 0) {
    perror("ERROR on binding");
    exit(1);
  }
  listen(sockfd, 5);
  clilen = sizeof(cli_addr);
  newsockfd = accept(sockfd, (struct sockaddr *)&cli_addr, &clilen);
  if (newsockfd < 0) {
    perror("ERROR on accept");
    exit(1);
  } else
    printf("new connection is established\n");
  bzero(buffer, 256);
  n = read(newsockfd, buffer, 4);
  buffer[4] = '\0';
  int length = atoi(buffer);
  printf("data length is : %d\n", length);
  n = read(newsockfd, buffer, length);
  if (n > 1) {
    buffer[n + 1] = '\0';
    printf("data is %s\n", buffer);
  }
  write(newsockfd, "0004list", 8);
  n = read(newsockfd, buffer, 4);
  buffer[4] = '\0';
  length = atoi(buffer);
  printf("data length is : %d\n", length);
  n = read(newsockfd, buffer, length);
  if (n > 1) {
    buffer[n] = '\0';
    printf("response is %s\n", buffer);
  }
  printf("try commands\n");
  char cmd[256];
  while (1) {
    bzero(cmd, 256);
    bzero(buffer, 9999);
    char ch;
    int i = 0;
    while (i < 255) {
      ch = getchar();
      if (ch != '\n')
        cmd[i++] = ch;
      else
        break;
    }
    sprintf(buffer, "%04d%s", strlen(cmd), cmd);
    write(newsockfd, buffer, strlen(buffer));
    n = read(newsockfd, buffer, 4);
    buffer[4] = '\0';
    length = atoi(buffer);
    printf("data length is : %d\n", length);
    n = read(newsockfd, buffer, length);
    if (n > 1) {
      buffer[n] = '\0';
      printf("response is %s\n", buffer);
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main1>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2880,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xdf7(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    0x2dd1(%rip),%rax
mov    (%rax),%edi
mov    0x2db0(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1110 <socket@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    124c <main1+0x5c>
lea    0xdda(%rip),%rdi
call   10b0 <perror@plt>
mov    $0x1,%edi
call   1100 <exit@plt>
lea    -0x2740(%rbp),%rdi
mov    $0xc,%esi
call   10c0 <bzero@plt>
movl   $0x1f41,-0x1c(%rbp)
mov    0x2d7d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2738(%rbp)
mov    0x2d66(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x273c(%rbp)
mov    -0x1c(%rbp),%edi
call   1050 <htons@plt>
mov    %eax,-0x2740(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x2740(%rbp),%rsi
mov    $0xc,%edx
call   10a0 <bind@plt>
cmp    $0x0,%rax
jge    12c4 <main1+0xd4>
lea    0xd77(%rip),%rdi
call   10b0 <perror@plt>
mov    $0x1,%edi
call   1100 <exit@plt>
mov    -0x14(%rbp),%edi
mov    $0x5,%esi
call   1090 <listen@plt>
movl   $0xc,-0x20(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x2750(%rbp),%rsi
lea    -0x20(%rbp),%rdx
call   10d0 <accept@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    130e <main1+0x11e>
lea    0xd3e(%rip),%rdi
call   10b0 <perror@plt>
mov    $0x1,%edi
call   1100 <exit@plt>
lea    0xd38(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    -0x2730(%rbp),%rdi
mov    $0x100,%esi
call   10c0 <bzero@plt>
mov    -0x18(%rbp),%edi
lea    -0x2730(%rbp),%rsi
mov    $0x4,%edx
call   1070 <read@plt>
mov    %eax,-0x2754(%rbp)
movb   $0x0,-0x272c(%rbp)
lea    -0x2730(%rbp),%rdi
call   10e0 <atoi@plt>
mov    %eax,-0x2758(%rbp)
mov    -0x2758(%rbp),%esi
lea    0xcff(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x18(%rbp),%edi
lea    -0x2730(%rbp),%rsi
mov    -0x2758(%rbp),%edx
call   1070 <read@plt>
mov    %eax,-0x2754(%rbp)
cmpl   $0x1,-0x2754(%rbp)
jle    13c4 <main1+0x1d4>
mov    -0x2754(%rbp),%eax
add    $0x1,%eax
cltq
movb   $0x0,-0x2730(%rbp,%rax,1)
lea    -0x2730(%rbp),%rsi
lea    0xcc4(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x18(%rbp),%edi
lea    0xcbf(%rip),%rsi
mov    $0x8,%edx
call   1030 <write@plt>
mov    -0x18(%rbp),%edi
lea    -0x2730(%rbp),%rsi
mov    $0x4,%edx
call   1070 <read@plt>
mov    %eax,-0x2754(%rbp)
movb   $0x0,-0x272c(%rbp)
lea    -0x2730(%rbp),%rdi
call   10e0 <atoi@plt>
mov    %eax,-0x2758(%rbp)
mov    -0x2758(%rbp),%esi
lea    0xc54(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x18(%rbp),%edi
lea    -0x2730(%rbp),%rsi
mov    -0x2758(%rbp),%edx
call   1070 <read@plt>
mov    %eax,-0x2754(%rbp)
cmpl   $0x1,-0x2754(%rbp)
jle    146b <main1+0x27b>
movslq -0x2754(%rbp),%rax
movb   $0x0,-0x2730(%rbp,%rax,1)
lea    -0x2730(%rbp),%rsi
lea    0xc32(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    0xc34(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    -0x2860(%rbp),%rdi
mov    $0x100,%esi
call   10c0 <bzero@plt>
lea    -0x2730(%rbp),%rdi
mov    $0x270f,%esi
call   10c0 <bzero@plt>
movl   $0x0,-0x2868(%rbp)
cmpl   $0xff,-0x2868(%rbp)
jge    1501 <main1+0x311>
mov    $0x0,%al
call   1080 <getchar@plt>
mov    %al,-0x2861(%rbp)
movsbl -0x2861(%rbp),%eax
cmp    $0xa,%eax
je     14f7 <main1+0x307>
mov    -0x2861(%rbp),%cl
mov    -0x2868(%rbp),%eax
mov    %eax,%edx
add    $0x1,%edx
mov    %edx,-0x2868(%rbp)
cltq
mov    %cl,-0x2860(%rbp,%rax,1)
jmp    14fc <main1+0x30c>
jmp    1501 <main1+0x311>
jmp    14a5 <main1+0x2b5>
lea    -0x2730(%rbp),%rax
mov    %rax,-0x2880(%rbp)
lea    -0x2860(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x2880(%rbp),%rdi
mov    %eax,%edx
lea    -0x2860(%rbp),%rcx
lea    0xb82(%rip),%rsi
call   10f0 <sprintf@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x2874(%rbp)
lea    -0x2730(%rbp),%rax
mov    %rax,-0x2870(%rbp)
lea    -0x2730(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x2874(%rbp),%edi
mov    -0x2870(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    -0x18(%rbp),%edi
lea    -0x2730(%rbp),%rsi
mov    $0x4,%edx
call   1070 <read@plt>
mov    %eax,-0x2754(%rbp)
movb   $0x0,-0x272c(%rbp)
lea    -0x2730(%rbp),%rdi
call   10e0 <atoi@plt>
mov    %eax,-0x2758(%rbp)
mov    -0x2758(%rbp),%esi
lea    0xabe(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x18(%rbp),%edi
lea    -0x2730(%rbp),%rsi
mov    -0x2758(%rbp),%edx
call   1070 <read@plt>
mov    %eax,-0x2754(%rbp)
cmpl   $0x1,-0x2754(%rbp)
jle    1601 <main1+0x411>
movslq -0x2754(%rbp),%rax
movb   $0x0,-0x2730(%rbp,%rax,1)
lea    -0x2730(%rbp),%rsi
lea    0xa9c(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    1479 <main1+0x289>

x86 assembly (clang, -O2):
<main1>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x2848,%rsp
lea    0xe5f(%rip),%rdi
call   1030 <puts@plt>
mov    0x2dc4(%rip),%r14
mov    (%r14),%edi
mov    0x2da2(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1120 <socket@plt>
test   %eax,%eax
js     14b3 <main1+0x2b3>
mov    %eax,%ebx
lea    0x10(%rsp),%rbp
mov    %rbp,%rdi
mov    $0xc,%esi
call   10d0 <bzero@plt>
mov    (%r14),%eax
mov    %eax,0x18(%rsp)
mov    0x2d7f(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x14(%rsp)
mov    $0x1f41,%edi
call   1060 <htons@plt>
mov    %eax,0x10(%rsp)
mov    %ebx,%edi
mov    %rbp,%rsi
mov    $0xc,%edx
call   10b0 <bind@plt>
test   %rax,%rax
js     14bc <main1+0x2bc>
mov    %ebx,%edi
mov    $0x5,%esi
call   10a0 <listen@plt>
movl   $0xc,0xc(%rsp)
lea    0x20(%rsp),%rsi
lea    0xc(%rsp),%rdx
mov    %ebx,%edi
call   10e0 <accept@plt>
test   %eax,%eax
js     14c5 <main1+0x2c5>
mov    %eax,%r15d
lea    0xdc9(%rip),%rdi
call   1030 <puts@plt>
lea    0x130(%rsp),%r14
mov    %r14,%rdi
mov    $0x100,%esi
call   10d0 <bzero@plt>
mov    %r15d,%edi
mov    %r14,%rsi
mov    $0x4,%edx
call   1080 <read@plt>
movb   $0x0,0x134(%rsp)
mov    %r14,%rdi
call   10f0 <atoi@plt>
mov    %eax,%ebx
lea    0xd2f(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %r15d,%edi
mov    %r14,%rsi
mov    %ebx,%edx
call   1080 <read@plt>
cmp    $0x2,%eax
jl     133b <main1+0x13b>
mov    %eax,%eax
movb   $0x0,0x1(%rax,%r14,1)
lea    0xd1a(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
lea    0xd15(%rip),%rsi
mov    %r15d,%edi
mov    $0x8,%edx
call   1040 <write@plt>
lea    0x130(%rsp),%r14
mov    %r15d,%edi
mov    %r14,%rsi
mov    $0x4,%edx
call   1080 <read@plt>
movb   $0x0,0x134(%rsp)
mov    %r14,%rdi
call   10f0 <atoi@plt>
mov    %eax,%ebx
lea    0xcb6(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %r15d,%edi
mov    %r14,%rsi
mov    %ebx,%edx
call   1080 <read@plt>
cmp    $0x2,%eax
jl     13bb <main1+0x1bb>
mov    %eax,%eax
movb   $0x0,0x130(%rsp,%rax,1)
lea    0xcb4(%rip),%rdi
lea    0x130(%rsp),%rsi
xor    %eax,%eax
call   1070 <printf@plt>
lea    0xce9(%rip),%rdi
call   1030 <puts@plt>
lea    0x30(%rsp),%r14
lea    0x130(%rsp),%rbx
lea    0xc5b(%rip),%r12
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    $0x100,%esi
call   10d0 <bzero@plt>
mov    %rbx,%rdi
mov    $0x270f,%esi
call   10d0 <bzero@plt>
xor    %ebp,%ebp
nopl   0x0(%rax)
xor    %eax,%eax
call   1090 <getchar@plt>
cmp    $0xa,%al
je     141c <main1+0x21c>
mov    %al,0x30(%rsp,%rbp,1)
add    $0x1,%rbp
cmp    $0xff,%rbp
jne    1400 <main1+0x200>
mov    %r14,%rdi
call   1050 <strlen@plt>
mov    %rbx,%rdi
lea    0xc42(%rip),%rsi
mov    %eax,%edx
mov    %r14,%rcx
call   1100 <sprintf@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %r15d,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1040 <write@plt>
mov    %r15d,%edi
mov    %rbx,%rsi
mov    $0x4,%edx
call   1080 <read@plt>
movb   $0x0,0x134(%rsp)
mov    %rbx,%rdi
call   10f0 <atoi@plt>
mov    %eax,%r13d
mov    %r12,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %r15d,%edi
mov    %rbx,%rsi
mov    %r13d,%edx
call   1080 <read@plt>
cmp    $0x2,%eax
jl     13e0 <main1+0x1e0>
mov    %eax,%eax
movb   $0x0,0x130(%rsp,%rax,1)
lea    0xbbc(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
jmp    13e0 <main1+0x1e0>
lea    0xb46(%rip),%rdi
jmp    14cc <main1+0x2cc>
lea    0xb52(%rip),%rdi
jmp    14cc <main1+0x2cc>
lea    0xb5a(%rip),%rdi
call   10c0 <perror@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 }
@.str = [23 x i8] c"TCP server is started\0A\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.1 = [21 x i8] c"ERROR opening socket\00"
@INADDR_ANY = global i32 0
@.str.2 = [17 x i8] c"ERROR on binding\00"
@.str.3 = [16 x i8] c"ERROR on accept\00"
@.str.4 = [31 x i8] c"new connection is established\0A\00"
@.str.5 = [21 x i8] c"data length is : %d\0A\00"
@.str.6 = [12 x i8] c"data is %s\0A\00"
@.str.7 = [9 x i8] c"0004list\00"
@.str.8 = [16 x i8] c"response is %s\0A\00"
@.str.9 = [14 x i8] c"try commands\0A\00"
@.str.10 = [7 x i8] c"%04d%s\00"
define i32 @main1(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca [9999 x i8]
%10 = alloca %struct.sockaddr_in
%11 = alloca %struct.sockaddr_in
%12 = alloca i32
%13 = alloca i32
%14 = alloca [256 x i8]
%15 = alloca i8
%16 = alloca i32
store i32 %0, i32* %3
store i8** %1, i8*** %4
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%18 = load i32, i32* @AF_INET
%19 = load i32, i32* @SOCK_STREAM
%20 = call i32 @socket(i32 %18, i32 %19, i32 0)
store i32 %20, i32* %5
%21 = load i32, i32* %5
%22 = icmp slt i32 %21, 0
br i1 %22, label %23, label %26
23: ; preds = %2
%24 = call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
%25 = call i32 @exit(i32 1)
unreachable
26: ; preds = %2
%27 = bitcast %struct.sockaddr_in* %10 to i8*
%28 = call i32 @bzero(i8* %27, i32 12)
store i32 8001, i32* %7
%29 = load i32, i32* @AF_INET
%30 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 2
store i32 %29, i32* %30
%31 = load i32, i32* @INADDR_ANY
%32 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 1
%33 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %32, i32 0, i32 0
store i32 %31, i32* %33
%34 = load i32, i32* %7
%35 = call i32 @htons(i32 %34)
%36 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 0
store i32 %35, i32* %36
%37 = load i32, i32* %5
%38 = bitcast %struct.sockaddr_in* %10 to %struct.sockaddr*
%39 = call i64 @bind(i32 %37, %struct.sockaddr* %38, i32 12)
%40 = icmp slt i64 %39, 0
br i1 %40, label %41, label %44
41: ; preds = %26
%42 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
%43 = call i32 @exit(i32 1)
unreachable
44: ; preds = %26
%45 = load i32, i32* %5
%46 = call i32 @listen(i32 %45, i32 5)
store i32 12, i32* %8
%47 = load i32, i32* %5
%48 = bitcast %struct.sockaddr_in* %11 to %struct.sockaddr*
%49 = call i32 @accept(i32 %47, %struct.sockaddr* %48, i32* %8)
store i32 %49, i32* %6
%50 = load i32, i32* %6
%51 = icmp slt i32 %50, 0
br i1 %51, label %52, label %55
52: ; preds = %44
%53 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0))
%54 = call i32 @exit(i32 1)
unreachable
55: ; preds = %44
%56 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0))
br label %57
57: ; preds = %55
%58 = getelementptr inbounds [9999 x i8], [9999 x i8]* %9, i64 0, i64 0
%59 = call i32 @bzero(i8* %58, i32 256)
%60 = load i32, i32* %6
%61 = getelementptr inbounds [9999 x i8], [9999 x i8]* %9, i64 0, i64 0
%62 = call i32 @read(i32 %60, i8* %61, i32 4)
store i32 %62, i32* %12
%63 = getelementptr inbounds [9999 x i8], [9999 x i8]* %9, i64 0, i64 4
store i8 0, i8* %63
%64 = getelementptr inbounds [9999 x i8], [9999 x i8]* %9, i64 0, i64 0
%65 = call i32 @atoi(i8* %64)
store i32 %65, i32* %13
%66 = load i32, i32* %13
%67 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.5, i64 0, i64 0), i32 %66)
%68 = load i32, i32* %6
%69 = getelementptr inbounds [9999 x i8], [9999 x i8]* %9, i64 0, i64 0
%70 = load i32, i32* %13
%71 = call i32 @read(i32 %68, i8* %69, i32 %70)
store i32 %71, i32* %12
%72 = load i32, i32* %12
%73 = icmp sgt i32 %72, 1
br i1 %73, label %74, label %81
74: ; preds = %57
%75 = load i32, i32* %12
%76 = add nsw i32 %75, 1
%77 = sext i32 %76 to i64
%78 = getelementptr inbounds [9999 x i8], [9999 x i8]* %9, i64 0, i64 %77
store i8 0, i8* %78
%79 = getelementptr inbounds [9999 x i8], [9999 x i8]* %9, i64 0, i64 0
%80 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.6, i64 0, i64 0), i8* %79)
br label %81
81: ; preds = %74, %57
%82 = load i32, i32* %6
%83 = call i32 @write(i32 %82, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.7, i64 0, i64 0), i32 8)
%84 = load i32, i32* %6
%85 = getelementptr inbounds [9999 x i8], [9999 x i8]* %9, i64 0, i64 0
%86 = call i32 @read(i32 %84, i8* %85, i32 4)
store i32 %86, i32* %12
%87 = getelementptr inbounds [9999 x i8], [9999 x i8]* %9, i64 0, i64 4
store i8 0, i8* %87
%88 = getelementptr inbounds [9999 x i8], [9999 x i8]* %9, i64 0, i64 0
%89 = call i32 @atoi(i8* %88)
store i32 %89, i32* %13
%90 = load i32, i32* %13
%91 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.5, i64 0, i64 0), i32 %90)
%92 = load i32, i32* %6
%93 = getelementptr inbounds [9999 x i8], [9999 x i8]* %9, i64 0, i64 0
%94 = load i32, i32* %13
%95 = call i32 @read(i32 %92, i8* %93, i32 %94)
store i32 %95, i32* %12
%96 = load i32, i32* %12
%97 = icmp sgt i32 %96, 1
br i1 %97, label %98, label %104
98: ; preds = %81
%99 = load i32, i32* %12
%100 = sext i32 %99 to i64
%101 = getelementptr inbounds [9999 x i8], [9999 x i8]* %9, i64 0, i64 %100
store i8 0, i8* %101
%102 = getelementptr inbounds [9999 x i8], [9999 x i8]* %9, i64 0, i64 0
%103 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.8, i64 0, i64 0), i8* %102)
br label %104
104: ; preds = %98, %81
%105 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.9, i64 0, i64 0))
br label %106
106: ; preds = %104, %158
%107 = getelementptr inbounds [256 x i8], [256 x i8]* %14, i64 0, i64 0
%108 = call i32 @bzero(i8* %107, i32 256)
%109 = getelementptr inbounds [9999 x i8], [9999 x i8]* %9, i64 0, i64 0
%110 = call i32 @bzero(i8* %109, i32 9999)
store i32 0, i32* %16
br label %111
111: ; preds = %126, %106
%112 = load i32, i32* %16
%113 = icmp slt i32 %112, 255
br i1 %113, label %114, label %127
114: ; preds = %111
%115 = call signext i8 (...) @getchar()
store i8 %115, i8* %15
%116 = load i8, i8* %15
%117 = sext i8 %116 to i32
%118 = icmp ne i32 %117, 10
br i1 %118, label %119, label %125
119: ; preds = %114
%120 = load i8, i8* %15
%121 = load i32, i32* %16
%122 = add nsw i32 %121, 1
store i32 %122, i32* %16
%123 = sext i32 %121 to i64
%124 = getelementptr inbounds [256 x i8], [256 x i8]* %14, i64 0, i64 %123
store i8 %120, i8* %124
br label %126
125: ; preds = %114
br label %127
126: ; preds = %119
br label %111
127: ; preds = %125, %111
%128 = getelementptr inbounds [9999 x i8], [9999 x i8]* %9, i64 0, i64 0
%129 = getelementptr inbounds [256 x i8], [256 x i8]* %14, i64 0, i64 0
%130 = call i32 @strlen(i8* %129)
%131 = getelementptr inbounds [256 x i8], [256 x i8]* %14, i64 0, i64 0
%132 = call i32 @sprintf(i8* %128, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.10, i64 0, i64 0), i32 %130, i8* %131)
%133 = load i32, i32* %6
%134 = getelementptr inbounds [9999 x i8], [9999 x i8]* %9, i64 0, i64 0
%135 = getelementptr inbounds [9999 x i8], [9999 x i8]* %9, i64 0, i64 0
%136 = call i32 @strlen(i8* %135)
%137 = call i32 @write(i32 %133, i8* %134, i32 %136)
%138 = load i32, i32* %6
%139 = getelementptr inbounds [9999 x i8], [9999 x i8]* %9, i64 0, i64 0
%140 = call i32 @read(i32 %138, i8* %139, i32 4)
store i32 %140, i32* %12
%141 = getelementptr inbounds [9999 x i8], [9999 x i8]* %9, i64 0, i64 4
store i8 0, i8* %141
%142 = getelementptr inbounds [9999 x i8], [9999 x i8]* %9, i64 0, i64 0
%143 = call i32 @atoi(i8* %142)
store i32 %143, i32* %13
%144 = load i32, i32* %13
%145 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.5, i64 0, i64 0), i32 %144)
%146 = load i32, i32* %6
%147 = getelementptr inbounds [9999 x i8], [9999 x i8]* %9, i64 0, i64 0
%148 = load i32, i32* %13
%149 = call i32 @read(i32 %146, i8* %147, i32 %148)
store i32 %149, i32* %12
%150 = load i32, i32* %12
%151 = icmp sgt i32 %150, 1
br i1 %151, label %152, label %158
152: ; preds = %127
%153 = load i32, i32* %12
%154 = sext i32 %153 to i64
%155 = getelementptr inbounds [9999 x i8], [9999 x i8]* %9, i64 0, i64 %154
store i8 0, i8* %155
%156 = getelementptr inbounds [9999 x i8], [9999 x i8]* %9, i64 0, i64 0
%157 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.8, i64 0, i64 0), i8* %156)
br label %158
158: ; preds = %152, %127
br label %106
}

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.1 = [21 x i8] c"ERROR opening socket\00"
@INADDR_ANY = global i32 0
@.str.2 = [17 x i8] c"ERROR on binding\00"
@.str.3 = [16 x i8] c"ERROR on accept\00"
@.str.5 = [21 x i8] c"data length is : %d\0A\00"
@.str.6 = [12 x i8] c"data is %s\0A\00"
@.str.7 = [9 x i8] c"0004list\00"
@.str.8 = [16 x i8] c"response is %s\0A\00"
@.str.10 = [7 x i8] c"%04d%s\00"
@str = [22 x i8] c"TCP server is started\00"
@str.11 = [30 x i8] c"new connection is established\00"
@str.12 = [13 x i8] c"try commands\00"
define i32 @main1(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = alloca [9999 x i8]
%5 = alloca %struct.sockaddr_in
%6 = alloca %struct.sockaddr_in
%7 = alloca [256 x i8]
%8 = bitcast i32* %3 to i8*
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str, i64 0, i64 0))
%10 = getelementptr inbounds [9999 x i8], [9999 x i8]* %4, i64 0, i64 0
%11 = bitcast %struct.sockaddr_in* %5 to i8*
%12 = bitcast %struct.sockaddr_in* %6 to i8*
%13 = load i32, i32* @AF_INET
%14 = load i32, i32* @SOCK_STREAM
%15 = tail call i32 @socket(i32 %13, i32 %14, i32 0)
%16 = icmp slt i32 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %2
%18 = tail call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
%19 = tail call i32 @exit(i32 1)
unreachable
20: ; preds = %2
%21 = call i32 @bzero(i8* %11, i32 12)
%22 = load i32, i32* @AF_INET
%23 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 2
store i32 %22, i32* %23
%24 = load i32, i32* @INADDR_ANY
%25 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 1, i32 0
store i32 %24, i32* %25
%26 = tail call i32 @htons(i32 8001)
%27 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 0
store i32 %26, i32* %27
%28 = bitcast %struct.sockaddr_in* %5 to %struct.sockaddr*
%29 = call i64 @bind(i32 %15, %struct.sockaddr* %28, i32 12)
%30 = icmp slt i64 %29, 0
br i1 %30, label %31, label %34
31: ; preds = %20
%32 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
%33 = call i32 @exit(i32 1)
unreachable
34: ; preds = %20
%35 = call i32 @listen(i32 %15, i32 5)
store i32 12, i32* %3
%36 = bitcast %struct.sockaddr_in* %6 to %struct.sockaddr*
%37 = call i32 @accept(i32 %15, %struct.sockaddr* %36, i32* %3)
%38 = icmp slt i32 %37, 0
br i1 %38, label %39, label %42
39: ; preds = %34
%40 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0))
%41 = call i32 @exit(i32 1)
unreachable
42: ; preds = %34
%43 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @str.11, i64 0, i64 0))
%44 = call i32 @bzero(i8* %10, i32 256)
%45 = call i32 @read(i32 %37, i8* %10, i32 4)
%46 = getelementptr inbounds [9999 x i8], [9999 x i8]* %4, i64 0, i64 4
store i8 0, i8* %46
%47 = call i32 @atoi(i8* %10)
%48 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.5, i64 0, i64 0), i32 %47)
%49 = call i32 @read(i32 %37, i8* %10, i32 %47)
%50 = icmp sgt i32 %49, 1
br i1 %50, label %51, label %56
51: ; preds = %42
%52 = add nuw nsw i32 %49, 1
%53 = zext i32 %52 to i64
%54 = getelementptr inbounds [9999 x i8], [9999 x i8]* %4, i64 0, i64 %53
store i8 0, i8* %54
%55 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.6, i64 0, i64 0), i8* %10)
br label %56
56: ; preds = %51, %42
%57 = call i32 @write(i32 %37, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.7, i64 0, i64 0), i32 8)
%58 = call i32 @read(i32 %37, i8* %10, i32 4)
store i8 0, i8* %46
%59 = call i32 @atoi(i8* %10)
%60 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.5, i64 0, i64 0), i32 %59)
%61 = call i32 @read(i32 %37, i8* %10, i32 %59)
%62 = icmp sgt i32 %61, 1
br i1 %62, label %63, label %67
63: ; preds = %56
%64 = zext i32 %61 to i64
%65 = getelementptr inbounds [9999 x i8], [9999 x i8]* %4, i64 0, i64 %64
store i8 0, i8* %65
%66 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.8, i64 0, i64 0), i8* %10)
br label %67
67: ; preds = %63, %56
%68 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str.12, i64 0, i64 0))
%69 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
br label %70
70: ; preds = %95, %67
%71 = call i32 @bzero(i8* %69, i32 256)
%72 = call i32 @bzero(i8* %10, i32 9999)
br label %73
73: ; preds = %70, %77
%74 = phi i64 [ 0, %70 ], [ %78, %77 ]
%75 = call signext i8 (...) @getchar()
%76 = icmp eq i8 %75, 10
br i1 %76, label %81, label %77
77: ; preds = %73
%78 = add nuw nsw i64 %74, 1
%79 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 %74
store i8 %75, i8* %79
%80 = icmp eq i64 %78, 255
br i1 %80, label %81, label %73
81: ; preds = %73, %77
%82 = call i32 @strlen(i8* %69)
%83 = call i32 @sprintf(i8* %10, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.10, i64 0, i64 0), i32 %82, i8* %69)
%84 = call i32 @strlen(i8* %10)
%85 = call i32 @write(i32 %37, i8* %10, i32 %84)
%86 = call i32 @read(i32 %37, i8* %10, i32 4)
store i8 0, i8* %46
%87 = call i32 @atoi(i8* %10)
%88 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.5, i64 0, i64 0), i32 %87)
%89 = call i32 @read(i32 %37, i8* %10, i32 %87)
%90 = icmp sgt i32 %89, 1
br i1 %90, label %91, label %95
91: ; preds = %81
%92 = zext i32 %89 to i64
%93 = getelementptr inbounds [9999 x i8], [9999 x i8]* %4, i64 0, i64 %92
store i8 0, i8* %93
%94 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.8, i64 0, i64 0), i8* %10)
br label %95
95: ; preds = %91, %81
br label %70
}