#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */
struct sockaddr_in {
  int /*<<< orphan*/ sin_addr;
  int /*<<< orphan*/ sin_port;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ fd_set;
typedef int /*<<< orphan*/ dr;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
scalar_t__ FD_ISSET(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ FD_SET(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ FD_ZERO(int /*<<< orphan*/ *);
int /*<<< orphan*/ SOCK_STREAM;
int accept(int, int /*<<< orphan*/, int /*<<< orphan*/);
int bind(int, struct sockaddr *, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ inet_aton(char *, int /*<<< orphan*/ *);
int listen(int, int);
int /*<<< orphan*/ printf(char *);
int recv(int, char *, int, int /*<<< orphan*/);
int select(int, int /*<<< orphan*/ *, int /*<<< orphan*/, int /*<<< orphan*/,
           int /*<<< orphan*/);
int /*<<< orphan*/ send(int, char *, int, int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int);
int main() {
  int sfd;
  int fdall[100];
  int count;
  int r;
  struct sockaddr_in dr;
  fd_set fds;
  int maxfd;
  int i, j;
  char buf[1024];
  sfd = socket(AF_INET, SOCK_STREAM, 6);
  if (sfd == -1) {
    printf("create socket : %m\n");
    exit(-1);
  }
  printf("create socket success.....\n");
  dr.sin_family = AF_INET;
  dr.sin_port = htons(6688);
  inet_aton("192.168.137.3", &dr.sin_addr);
  r = bind(sfd, (struct sockaddr *)&dr, sizeof(dr));
  if (r == -1) {
    printf("bind socket : %m\n");
    exit(-1);
  }
  printf("bind socket success.....\n");
  r = listen(sfd, 10);
  if (r == -1) {
    printf("listen socket : %m\n");
    exit(-1);
  }
  printf("listen socket success.....\n");
  count = 0;
  maxfd = 0;
  FD_ZERO(&fds);
  for (i = 0; i < 100; i++) {
    fdall[i] = -1;
  }
  while (1) {
    FD_ZERO(&fds);
    maxfd = 0;
    FD_SET(sfd, &fds);
    maxfd = (maxfd >= sfd ? maxfd : sfd);
    for (i = 0; i < count; i++) {
      if (fdall[i] != -1) {
        FD_SET(fdall[i], &fds);
        maxfd = (maxfd >= fdall[i] ? maxfd : fdall[i]);
      }
    }
    r = select(maxfd + 1, &fds, 0, 0, 0);
    if (r == -1) {
      printf("listen socket : %m\n");
      break;
    }
    if (FD_ISSET(sfd, &fds)) {
      fdall[count++] = accept(sfd, 0, 0);
      printf("has client connect ....\n");
    }
    for (i = 0; i < count; i++) {
      if (fdall[i] != -1 && FD_ISSET(fdall[i], &fds)) {
        r = recv(fdall[i], buf, 1023, 0);
        if (r == 0) {
          printf("has client exit......\n");
          close(fdall[i]);
          fdall[i] = -1;
        }
        if (r == -1) {
          printf("has internet fail....(%m)\n");
          close(fdall[i]);
          fdall[i] = -1;
        }
        if (r > 0) {
          for (j = 0; j < count; j++) {
            if (fdall[j] != -1) {
              send(fdall[j], buf, r, 0);
            }
          }
        }
      }
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x5e0,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2ddf(%rip),%rax
mov    (%rax),%edi
mov    0x2dc6(%rip),%rax
mov    (%rax),%esi
mov    $0x6,%edx
call   1110 <socket@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0xffffffff,-0x8(%rbp)
jne    1241 <main+0x51>
lea    0xdce(%rip),%rdi
call   1070 <printf@plt>
mov    $0xffffffff,%edi
call   10f0 <exit@plt>
lea    0xdcc(%rip),%rdi
call   1070 <printf@plt>
mov    0x2d94(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1b0(%rbp)
mov    $0x1a20,%edi
call   1050 <htons@plt>
mov    %eax,-0x1b4(%rbp)
lea    -0x1b8(%rbp),%rsi
lea    0xdb6(%rip),%rdi
call   10b0 <inet_aton@plt>
mov    -0x8(%rbp),%edi
lea    -0x1b8(%rbp),%rsi
mov    $0xc,%edx
call   10d0 <bind@plt>
mov    %eax,-0x1a8(%rbp)
cmpl   $0xffffffff,-0x1a8(%rbp)
jne    12bc <main+0xcc>
lea    0xd91(%rip),%rdi
call   1070 <printf@plt>
mov    $0xffffffff,%edi
call   10f0 <exit@plt>
lea    0xd8d(%rip),%rdi
call   1070 <printf@plt>
mov    -0x8(%rbp),%edi
mov    $0xa,%esi
call   10c0 <listen@plt>
mov    %eax,-0x1a8(%rbp)
cmpl   $0xffffffff,-0x1a8(%rbp)
jne    12fe <main+0x10e>
lea    0xd7b(%rip),%rdi
call   1070 <printf@plt>
mov    $0xffffffff,%edi
call   10f0 <exit@plt>
lea    0xd79(%rip),%rdi
call   1070 <printf@plt>
movl   $0x0,-0x1a4(%rbp)
movl   $0x0,-0x1c0(%rbp)
lea    -0x1bc(%rbp),%rdi
call   1090 <FD_ZERO@plt>
movl   $0x0,-0x1c4(%rbp)
cmpl   $0x64,-0x1c4(%rbp)
jge    1367 <main+0x177>
movslq -0x1c4(%rbp),%rax
movl   $0xffffffff,-0x1a0(%rbp,%rax,4)
ff ff ff ff
mov    -0x1c4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c4(%rbp)
jmp    1334 <main+0x144>
jmp    136c <main+0x17c>
lea    -0x1bc(%rbp),%rdi
call   1090 <FD_ZERO@plt>
movl   $0x0,-0x1c0(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x1bc(%rbp),%rsi
call   1100 <FD_SET@plt>
mov    -0x1c0(%rbp),%eax
cmp    -0x8(%rbp),%eax
jl     13b1 <main+0x1c1>
mov    -0x1c0(%rbp),%eax
mov    %eax,-0x5d4(%rbp)
jmp    13ba <main+0x1ca>
mov    -0x8(%rbp),%eax
mov    %eax,-0x5d4(%rbp)
mov    -0x5d4(%rbp),%eax
mov    %eax,-0x1c0(%rbp)
movl   $0x0,-0x1c4(%rbp)
mov    -0x1c4(%rbp),%eax
cmp    -0x1a4(%rbp),%eax
jge    1475 <main+0x285>
movslq -0x1c4(%rbp),%rax
cmpl   $0xffffffff,-0x1a0(%rbp,%rax,4)
ff
je     145c <main+0x26c>
movslq -0x1c4(%rbp),%rax
mov    -0x1a0(%rbp,%rax,4),%edi
lea    -0x1bc(%rbp),%rsi
call   1100 <FD_SET@plt>
mov    -0x1c0(%rbp),%eax
movslq -0x1c4(%rbp),%rcx
cmp    -0x1a0(%rbp,%rcx,4),%eax
jl     143c <main+0x24c>
mov    -0x1c0(%rbp),%eax
mov    %eax,-0x5d8(%rbp)
jmp    1450 <main+0x260>
movslq -0x1c4(%rbp),%rax
mov    -0x1a0(%rbp,%rax,4),%eax
mov    %eax,-0x5d8(%rbp)
mov    -0x5d8(%rbp),%eax
mov    %eax,-0x1c0(%rbp)
jmp    1461 <main+0x271>
mov    -0x1c4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c4(%rbp)
jmp    13d0 <main+0x1e0>
mov    -0x1c0(%rbp),%edi
add    $0x1,%edi
lea    -0x1bc(%rbp),%rsi
xor    %r8d,%r8d
mov    %r8d,%edx
mov    %r8d,%ecx
call   10a0 <select@plt>
mov    %eax,-0x1a8(%rbp)
cmpl   $0xffffffff,-0x1a8(%rbp)
jne    14b7 <main+0x2c7>
lea    0xbbd(%rip),%rdi
call   1070 <printf@plt>
jmp    169d <main+0x4ad>
mov    -0x8(%rbp),%edi
lea    -0x1bc(%rbp),%rsi
call   1040 <FD_ISSET@plt>
cmp    $0x0,%rax
je     1504 <main+0x314>
mov    -0x8(%rbp),%edi
xor    %edx,%edx
mov    %edx,%esi
call   10e0 <accept@plt>
mov    %eax,%ecx
mov    -0x1a4(%rbp),%eax
mov    %eax,%edx
add    $0x1,%edx
mov    %edx,-0x1a4(%rbp)
cltq
mov    %ecx,-0x1a0(%rbp,%rax,4)
lea    0xb9b(%rip),%rdi
call   1070 <printf@plt>
movl   $0x0,-0x1c4(%rbp)
mov    -0x1c4(%rbp),%eax
cmp    -0x1a4(%rbp),%eax
jge    1698 <main+0x4a8>
movslq -0x1c4(%rbp),%rax
cmpl   $0xffffffff,-0x1a0(%rbp,%rax,4)
ff
je     167f <main+0x48f>
movslq -0x1c4(%rbp),%rax
mov    -0x1a0(%rbp,%rax,4),%edi
lea    -0x1bc(%rbp),%rsi
call   1040 <FD_ISSET@plt>
cmp    $0x0,%rax
je     167f <main+0x48f>
movslq -0x1c4(%rbp),%rax
mov    -0x1a0(%rbp,%rax,4),%edi
lea    -0x5d0(%rbp),%rsi
mov    $0x3ff,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,-0x1a8(%rbp)
cmpl   $0x0,-0x1a8(%rbp)
jne    15be <main+0x3ce>
lea    0xb1f(%rip),%rdi
call   1070 <printf@plt>
movslq -0x1c4(%rbp),%rax
mov    -0x1a0(%rbp,%rax,4),%edi
call   1080 <close@plt>
movslq -0x1c4(%rbp),%rax
movl   $0xffffffff,-0x1a0(%rbp,%rax,4)
ff ff ff ff
cmpl   $0xffffffff,-0x1a8(%rbp)
jne    15fc <main+0x40c>
lea    0xaf8(%rip),%rdi
call   1070 <printf@plt>
movslq -0x1c4(%rbp),%rax
mov    -0x1a0(%rbp,%rax,4),%edi
call   1080 <close@plt>
movslq -0x1c4(%rbp),%rax
movl   $0xffffffff,-0x1a0(%rbp,%rax,4)
ff ff ff ff
cmpl   $0x0,-0x1a8(%rbp)
jle    167a <main+0x48a>
movl   $0x0,-0x1c8(%rbp)
mov    -0x1c8(%rbp),%eax
cmp    -0x1a4(%rbp),%eax
jge    1675 <main+0x485>
movslq -0x1c8(%rbp),%rax
cmpl   $0xffffffff,-0x1a0(%rbp,%rax,4)
ff
je     165c <main+0x46c>
movslq -0x1c8(%rbp),%rax
mov    -0x1a0(%rbp,%rax,4),%edi
lea    -0x5d0(%rbp),%rsi
mov    -0x1a8(%rbp),%edx
xor    %ecx,%ecx
call   1060 <send@plt>
jmp    1661 <main+0x471>
mov    -0x1c8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c8(%rbp)
jmp    1613 <main+0x423>
jmp    167a <main+0x48a>
jmp    167f <main+0x48f>
jmp    1684 <main+0x494>
mov    -0x1c4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c4(%rbp)
jmp    150e <main+0x31e>
jmp    136c <main+0x17c>
xor    %eax,%eax
add    $0x5e0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x5b8,%rsp
mov    0x2dc0(%rip),%rbx
mov    (%rbx),%edi
mov    0x2da7(%rip),%rax
mov    (%rax),%esi
mov    $0x6,%edx
call   1130 <socket@plt>
cmp    $0xffffffff,%eax
je     14c5 <main+0x2b5>
mov    %eax,%r14d
lea    0xe13(%rip),%rdi
call   1040 <puts@plt>
mov    (%rbx),%eax
mov    %eax,0x18(%rsp)
mov    $0x1a20,%edi
call   1060 <htons@plt>
mov    %eax,0x14(%rsp)
lea    0xda4(%rip),%rdi
lea    0x10(%rsp),%rbx
mov    %rbx,%rsi
call   10d0 <inet_aton@plt>
mov    %r14d,%edi
mov    %rbx,%rsi
mov    $0xc,%edx
call   10f0 <bind@plt>
cmp    $0xffffffff,%eax
je     14ce <main+0x2be>
lea    0xde1(%rip),%rdi
call   1040 <puts@plt>
mov    %r14d,%edi
mov    $0xa,%esi
call   10e0 <listen@plt>
cmp    $0xffffffff,%eax
je     14d7 <main+0x2c7>
lea    0xdd8(%rip),%rdi
call   1040 <puts@plt>
lea    0x1c(%rsp),%rbx
mov    %rbx,%rdi
call   10b0 <FD_ZERO@plt>
lea    0x20(%rsp),%rdi
mov    $0x190,%edx
mov    $0xff,%esi
call   1090 <memset@plt>
xor    %ebp,%ebp
test   %r14d,%r14d
mov    %r14d,%eax
cmovs  %ebp,%eax
mov    %eax,0x4(%rsp)
mov    %r14d,(%rsp)
jmp    130c <main+0xfc>
nopw   0x0(%rax,%rax,1)
mov    (%rsp),%r14d
mov    %r12,%rbx
mov    0x8(%rsp),%rbp
mov    %rbx,%rdi
call   10b0 <FD_ZERO@plt>
mov    %r14d,%edi
mov    %rbx,%r12
mov    %rbx,%rsi
call   1120 <FD_SET@plt>
mov    0x4(%rsp),%r13d
mov    %rbp,%r15
test   %ebp,%ebp
jle    1370 <main+0x160>
mov    %r15d,%r14d
xor    %ebx,%ebx
mov    0x4(%rsp),%r13d
jmp    1349 <main+0x139>
nopw   0x0(%rax,%rax,1)
add    $0x1,%rbx
cmp    %rbx,%r14
je     1370 <main+0x160>
mov    0x20(%rsp,%rbx,4),%ebp
cmp    $0xffffffff,%ebp
je     1340 <main+0x130>
mov    %ebp,%edi
mov    %r12,%rsi
call   1120 <FD_SET@plt>
cmp    %ebp,%r13d
cmovl  %ebp,%r13d
jmp    1340 <main+0x130>
cs nopw 0x0(%rax,%rax,1)
nop
add    $0x1,%r13d
mov    %r13d,%edi
mov    %r12,%rbx
mov    %r12,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   10c0 <select@plt>
cmp    $0xffffffff,%eax
je     14a5 <main+0x295>
mov    (%rsp),%r14d
mov    %r14d,%edi
mov    %rbx,%rsi
call   1050 <FD_ISSET@plt>
test   %rax,%rax
je     13e0 <main+0x1d0>
mov    %r14d,%edi
xor    %esi,%esi
xor    %edx,%edx
call   1100 <accept@plt>
mov    %r15,%rbp
movslq %ebp,%rcx
add    $0x1,%ebp
mov    %eax,0x20(%rsp,%rcx,4)
lea    0xd02(%rip),%rdi
call   1040 <puts@plt>
test   %ebp,%ebp
jg     13eb <main+0x1db>
jmp    130c <main+0xfc>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r15,%rbp
test   %ebp,%ebp
jle    130c <main+0xfc>
mov    %rbp,0x8(%rsp)
mov    %ebp,%r15d
xor    %r14d,%r14d
jmp    1422 <main+0x212>
lea    0xc49(%rip),%rdi
call   1080 <printf@plt>
mov    %r13d,%edi
call   10a0 <close@plt>
movl   $0xffffffff,0x20(%rsp,%r14,4)
ff ff
add    $0x1,%r14
cmp    %r15,%r14
je     1300 <main+0xf0>
mov    0x20(%rsp,%r14,4),%r13d
cmp    $0xffffffff,%r13d
je     1415 <main+0x205>
mov    %r13d,%edi
mov    %r12,%rsi
call   1050 <FD_ISSET@plt>
test   %rax,%rax
je     1415 <main+0x205>
mov    %r13d,%edi
lea    0x1b0(%rsp),%rsi
mov    $0x3ff,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
cmp    $0xffffffff,%eax
je     13f8 <main+0x1e8>
mov    %eax,%ebx
test   %eax,%eax
jne    146d <main+0x25d>
lea    0xc4c(%rip),%rdi
call   1040 <puts@plt>
jmp    1404 <main+0x1f4>
jle    1415 <main+0x205>
xor    %ebp,%ebp
jmp    1489 <main+0x279>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
add    $0x1,%rbp
cmp    %rbp,%r15
je     1415 <main+0x205>
mov    0x20(%rsp,%rbp,4),%edi
cmp    $0xffffffff,%edi
je     1480 <main+0x270>
lea    0x1b0(%rsp),%rsi
mov    %ebx,%edx
xor    %ecx,%ecx
call   1070 <send@plt>
jmp    1480 <main+0x270>
lea    0xb88(%rip),%rdi
call   1080 <printf@plt>
xor    %eax,%eax
add    $0x5b8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xb34(%rip),%rdi
jmp    14de <main+0x2ce>
lea    0xb4d(%rip),%rdi
jmp    14de <main+0x2ce>
lea    0xb56(%rip),%rdi
call   1080 <printf@plt>
mov    $0xffffffff,%edi
call   1110 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str = [20 x i8] c"create socket : %m\0A\00"
@.str.1 = [28 x i8] c"create socket success.....\0A\00"
@.str.2 = [14 x i8] c"192.168.137.3\00"
@.str.3 = [18 x i8] c"bind socket : %m\0A\00"
@.str.4 = [26 x i8] c"bind socket success.....\0A\00"
@.str.5 = [20 x i8] c"listen socket : %m\0A\00"
@.str.6 = [28 x i8] c"listen socket success.....\0A\00"
@.str.7 = [25 x i8] c"has client connect ....\0A\00"
@.str.8 = [23 x i8] c"has client exit......\0A\00"
@.str.9 = [27 x i8] c"has internet fail....(%m)\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [100 x i32]
%4 = alloca i32
%5 = alloca i32
%6 = alloca %struct.sockaddr_in
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca [1024 x i8]
store i32 0, i32* %1
%12 = load i32, i32* @AF_INET
%13 = load i32, i32* @SOCK_STREAM
%14 = call i32 @socket(i32 %12, i32 %13, i32 6)
store i32 %14, i32* %2
%15 = load i32, i32* %2
%16 = icmp eq i32 %15, -1
br i1 %16, label %17, label %20
17: ; preds = %0
%18 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%19 = call i32 @exit(i32 -1)
unreachable
20: ; preds = %0
%21 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0))
%22 = load i32, i32* @AF_INET
%23 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 2
store i32 %22, i32* %23
%24 = call i32 @htons(i32 6688)
%25 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 1
store i32 %24, i32* %25
%26 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 0
%27 = call i32 @inet_aton(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i32* %26)
%28 = load i32, i32* %2
%29 = bitcast %struct.sockaddr_in* %6 to %struct.sockaddr*
%30 = call i32 @bind(i32 %28, %struct.sockaddr* %29, i32 12)
store i32 %30, i32* %5
%31 = load i32, i32* %5
%32 = icmp eq i32 %31, -1
br i1 %32, label %33, label %36
33: ; preds = %20
%34 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0))
%35 = call i32 @exit(i32 -1)
unreachable
36: ; preds = %20
%37 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0))
%38 = load i32, i32* %2
%39 = call i32 @listen(i32 %38, i32 10)
store i32 %39, i32* %5
%40 = load i32, i32* %5
%41 = icmp eq i32 %40, -1
br i1 %41, label %42, label %45
42: ; preds = %36
%43 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0))
%44 = call i32 @exit(i32 -1)
unreachable
45: ; preds = %36
%46 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.6, i64 0, i64 0))
store i32 0, i32* %4
store i32 0, i32* %8
%47 = call i32 @FD_ZERO(i32* %7)
store i32 0, i32* %9
br label %48
48: ; preds = %55, %45
%49 = load i32, i32* %9
%50 = icmp slt i32 %49, 100
br i1 %50, label %51, label %58
51: ; preds = %48
%52 = load i32, i32* %9
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds [100 x i32], [100 x i32]* %3, i64 0, i64 %53
store i32 -1, i32* %54
br label %55
55: ; preds = %51
%56 = load i32, i32* %9
%57 = add nsw i32 %56, 1
store i32 %57, i32* %9
br label %48
58: ; preds = %48
br label %59
59: ; preds = %58, %209
%60 = call i32 @FD_ZERO(i32* %7)
store i32 0, i32* %8
%61 = load i32, i32* %2
%62 = call i32 @FD_SET(i32 %61, i32* %7)
%63 = load i32, i32* %8
%64 = load i32, i32* %2
%65 = icmp sge i32 %63, %64
br i1 %65, label %66, label %68
66: ; preds = %59
%67 = load i32, i32* %8
br label %70
68: ; preds = %59
%69 = load i32, i32* %2
br label %70
70: ; preds = %68, %66
%71 = phi i32 [ %67, %66 ], [ %69, %68 ]
store i32 %71, i32* %8
store i32 0, i32* %9
br label %72
72: ; preds = %104, %70
%73 = load i32, i32* %9
%74 = load i32, i32* %4
%75 = icmp slt i32 %73, %74
br i1 %75, label %76, label %107
76: ; preds = %72
%77 = load i32, i32* %9
%78 = sext i32 %77 to i64
%79 = getelementptr inbounds [100 x i32], [100 x i32]* %3, i64 0, i64 %78
%80 = load i32, i32* %79
%81 = icmp ne i32 %80, -1
br i1 %81, label %82, label %103
82: ; preds = %76
%83 = load i32, i32* %9
%84 = sext i32 %83 to i64
%85 = getelementptr inbounds [100 x i32], [100 x i32]* %3, i64 0, i64 %84
%86 = load i32, i32* %85
%87 = call i32 @FD_SET(i32 %86, i32* %7)
%88 = load i32, i32* %8
%89 = load i32, i32* %9
%90 = sext i32 %89 to i64
%91 = getelementptr inbounds [100 x i32], [100 x i32]* %3, i64 0, i64 %90
%92 = load i32, i32* %91
%93 = icmp sge i32 %88, %92
br i1 %93, label %94, label %96
94: ; preds = %82
%95 = load i32, i32* %8
br label %101
96: ; preds = %82
%97 = load i32, i32* %9
%98 = sext i32 %97 to i64
%99 = getelementptr inbounds [100 x i32], [100 x i32]* %3, i64 0, i64 %98
%100 = load i32, i32* %99
br label %101
101: ; preds = %96, %94
%102 = phi i32 [ %95, %94 ], [ %100, %96 ]
store i32 %102, i32* %8
br label %103
103: ; preds = %101, %76
br label %104
104: ; preds = %103
%105 = load i32, i32* %9
%106 = add nsw i32 %105, 1
store i32 %106, i32* %9
br label %72
107: ; preds = %72
%108 = load i32, i32* %8
%109 = add nsw i32 %108, 1
%110 = call i32 @select(i32 %109, i32* %7, i32 0, i32 0, i32 0)
store i32 %110, i32* %5
%111 = load i32, i32* %5
%112 = icmp eq i32 %111, -1
br i1 %112, label %113, label %115
113: ; preds = %107
%114 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0))
br label %210
115: ; preds = %107
%116 = load i32, i32* %2
%117 = call i64 @FD_ISSET(i32 %116, i32* %7)
%118 = icmp ne i64 %117, 0
br i1 %118, label %119, label %127
119: ; preds = %115
%120 = load i32, i32* %2
%121 = call i32 @accept(i32 %120, i32 0, i32 0)
%122 = load i32, i32* %4
%123 = add nsw i32 %122, 1
store i32 %123, i32* %4
%124 = sext i32 %122 to i64
%125 = getelementptr inbounds [100 x i32], [100 x i32]* %3, i64 0, i64 %124
store i32 %121, i32* %125
%126 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.7, i64 0, i64 0))
br label %127
127: ; preds = %119, %115
store i32 0, i32* %9
br label %128
128: ; preds = %206, %127
%129 = load i32, i32* %9
%130 = load i32, i32* %4
%131 = icmp slt i32 %129, %130
br i1 %131, label %132, label %209
132: ; preds = %128
%133 = load i32, i32* %9
%134 = sext i32 %133 to i64
%135 = getelementptr inbounds [100 x i32], [100 x i32]* %3, i64 0, i64 %134
%136 = load i32, i32* %135
%137 = icmp ne i32 %136, -1
br i1 %137, label %138, label %205
138: ; preds = %132
%139 = load i32, i32* %9
%140 = sext i32 %139 to i64
%141 = getelementptr inbounds [100 x i32], [100 x i32]* %3, i64 0, i64 %140
%142 = load i32, i32* %141
%143 = call i64 @FD_ISSET(i32 %142, i32* %7)
%144 = icmp ne i64 %143, 0
br i1 %144, label %145, label %205
145: ; preds = %138
%146 = load i32, i32* %9
%147 = sext i32 %146 to i64
%148 = getelementptr inbounds [100 x i32], [100 x i32]* %3, i64 0, i64 %147
%149 = load i32, i32* %148
%150 = getelementptr inbounds [1024 x i8], [1024 x i8]* %11, i64 0, i64 0
%151 = call i32 @recv(i32 %149, i8* %150, i32 1023, i32 0)
store i32 %151, i32* %5
%152 = load i32, i32* %5
%153 = icmp eq i32 %152, 0
br i1 %153, label %154, label %164
154: ; preds = %145
%155 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.8, i64 0, i64 0))
%156 = load i32, i32* %9
%157 = sext i32 %156 to i64
%158 = getelementptr inbounds [100 x i32], [100 x i32]* %3, i64 0, i64 %157
%159 = load i32, i32* %158
%160 = call i32 @close(i32 %159)
%161 = load i32, i32* %9
%162 = sext i32 %161 to i64
%163 = getelementptr inbounds [100 x i32], [100 x i32]* %3, i64 0, i64 %162
store i32 -1, i32* %163
br label %164
164: ; preds = %154, %145
%165 = load i32, i32* %5
%166 = icmp eq i32 %165, -1
br i1 %166, label %167, label %177
167: ; preds = %164
%168 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.9, i64 0, i64 0))
%169 = load i32, i32* %9
%170 = sext i32 %169 to i64
%171 = getelementptr inbounds [100 x i32], [100 x i32]* %3, i64 0, i64 %170
%172 = load i32, i32* %171
%173 = call i32 @close(i32 %172)
%174 = load i32, i32* %9
%175 = sext i32 %174 to i64
%176 = getelementptr inbounds [100 x i32], [100 x i32]* %3, i64 0, i64 %175
store i32 -1, i32* %176
br label %177
177: ; preds = %167, %164
%178 = load i32, i32* %5
%179 = icmp sgt i32 %178, 0
br i1 %179, label %180, label %204
180: ; preds = %177
store i32 0, i32* %10
br label %181
181: ; preds = %200, %180
%182 = load i32, i32* %10
%183 = load i32, i32* %4
%184 = icmp slt i32 %182, %183
br i1 %184, label %185, label %203
185: ; preds = %181
%186 = load i32, i32* %10
%187 = sext i32 %186 to i64
%188 = getelementptr inbounds [100 x i32], [100 x i32]* %3, i64 0, i64 %187
%189 = load i32, i32* %188
%190 = icmp ne i32 %189, -1
br i1 %190, label %191, label %199
191: ; preds = %185
%192 = load i32, i32* %10
%193 = sext i32 %192 to i64
%194 = getelementptr inbounds [100 x i32], [100 x i32]* %3, i64 0, i64 %193
%195 = load i32, i32* %194
%196 = getelementptr inbounds [1024 x i8], [1024 x i8]* %11, i64 0, i64 0
%197 = load i32, i32* %5
%198 = call i32 @send(i32 %195, i8* %196, i32 %197, i32 0)
br label %199
199: ; preds = %191, %185
br label %200
200: ; preds = %199
%201 = load i32, i32* %10
%202 = add nsw i32 %201, 1
store i32 %202, i32* %10
br label %181
203: ; preds = %181
br label %204
204: ; preds = %203, %177
br label %205
205: ; preds = %204, %138, %132
br label %206
206: ; preds = %205
%207 = load i32, i32* %9
%208 = add nsw i32 %207, 1
store i32 %208, i32* %9
br label %128
209: ; preds = %128
br label %59
210: ; preds = %113
ret i32 0
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str = [20 x i8] c"create socket : %m\0A\00"
@.str.2 = [14 x i8] c"192.168.137.3\00"
@.str.3 = [18 x i8] c"bind socket : %m\0A\00"
@.str.5 = [20 x i8] c"listen socket : %m\0A\00"
@.str.9 = [27 x i8] c"has internet fail....(%m)\0A\00"
@str = [27 x i8] c"create socket success.....\00"
@str.10 = [25 x i8] c"bind socket success.....\00"
@str.11 = [27 x i8] c"listen socket success.....\00"
@str.12 = [22 x i8] c"has client exit......\00"
@str.13 = [24 x i8] c"has client connect ....\00"
define i32 @main() {
%1 = alloca [100 x i32]
%2 = bitcast [100 x i32]* %1 to i8*
%3 = alloca %struct.sockaddr_in
%4 = alloca i32
%5 = alloca [1024 x i8]
%6 = bitcast %struct.sockaddr_in* %3 to i8*
%7 = bitcast i32* %4 to i8*
%8 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%9 = load i32, i32* @AF_INET
%10 = load i32, i32* @SOCK_STREAM
%11 = tail call i32 @socket(i32 %9, i32 %10, i32 6)
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %16
13: ; preds = %0
%14 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%15 = tail call i32 @exit(i32 -1)
unreachable
16: ; preds = %0
%17 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str, i64 0, i64 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 = tail call i32 @htons(i32 6688)
%21 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1
store i32 %20, i32* %21
%22 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
%23 = call i32 @inet_aton(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i32* %22)
%24 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%25 = call i32 @bind(i32 %11, %struct.sockaddr* %24, i32 12)
%26 = icmp eq i32 %25, -1
br i1 %26, label %27, label %30
27: ; preds = %16
%28 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0))
%29 = call i32 @exit(i32 -1)
unreachable
30: ; preds = %16
%31 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str.10, i64 0, i64 0))
%32 = call i32 @listen(i32 %11, i32 10)
%33 = icmp eq i32 %32, -1
br i1 %33, label %34, label %37
34: ; preds = %30
%35 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0))
%36 = call i32 @exit(i32 -1)
unreachable
37: ; preds = %30
%38 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str.11, i64 0, i64 0))
%39 = call i32 @FD_ZERO(i32* %4)
%40 = icmp sgt i32 %11, 0
%41 = select i1 %40, i32 %11, i32 0
br label %42
42: ; preds = %82, %37
%43 = phi i32 [ 0, %37 ], [ %80, %82 ]
%44 = call i32 @FD_ZERO(i32* %4)
%45 = call i32 @FD_SET(i32 %11, i32* %4)
%46 = icmp sgt i32 %43, 0
br i1 %46, label %47, label %63
47: ; preds = %42
%48 = zext i32 %43 to i64
br label %49
49: ; preds = %47, %59
%50 = phi i64 [ 0, %47 ], [ %61, %59 ]
%51 = phi i32 [ %41, %47 ], [ %60, %59 ]
%52 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 %50
%53 = load i32, i32* %52
%54 = icmp eq i32 %53, -1
br i1 %54, label %59, label %55
55: ; preds = %49
%56 = call i32 @FD_SET(i32 %53, i32* %4)
%57 = icmp slt i32 %51, %53
%58 = select i1 %57, i32 %53, i32 %51
br label %59
59: ; preds = %49, %55
%60 = phi i32 [ %58, %55 ], [ %51, %49 ]
%61 = add nuw nsw i64 %50, 1
%62 = icmp eq i64 %61, %48
br i1 %62, label %63, label %49
63: ; preds = %59, %42
%64 = phi i32 [ %41, %42 ], [ %60, %59 ]
%65 = add nsw i32 %64, 1
%66 = call i32 @select(i32 %65, i32* %4, i32 0, i32 0, i32 0)
%67 = icmp eq i32 %66, -1
br i1 %67, label %68, label %70
68: ; preds = %63
%69 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0))
ret i32 0
70: ; preds = %63
%71 = call i64 @FD_ISSET(i32 %11, i32* %4)
%72 = icmp eq i64 %71, 0
br i1 %72, label %79, label %73
73: ; preds = %70
%74 = call i32 @accept(i32 %11, i32 0, i32 0)
%75 = add nsw i32 %43, 1
%76 = sext i32 %43 to i64
%77 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 %76
store i32 %74, i32* %77
%78 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str.13, i64 0, i64 0))
br label %79
79: ; preds = %73, %70
%80 = phi i32 [ %75, %73 ], [ %43, %70 ]
%81 = icmp sgt i32 %80, 0
br i1 %81, label %83, label %82
82: ; preds = %113, %79
br label %42
83: ; preds = %79
%84 = zext i32 %80 to i64
br label %85
85: ; preds = %83, %113
%86 = phi i64 [ 0, %83 ], [ %114, %113 ]
%87 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 %86
%88 = load i32, i32* %87
%89 = icmp eq i32 %88, -1
br i1 %89, label %113, label %90
90: ; preds = %85
%91 = call i64 @FD_ISSET(i32 %88, i32* %4)
%92 = icmp eq i64 %91, 0
br i1 %92, label %113, label %93
93: ; preds = %90
%94 = call i32 @recv(i32 %88, i8* %8, i32 1023, i32 0)
switch i32 %94, label %99 [
i32 0, label %95
i32 -1, label %97
]
95: ; preds = %93
%96 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str.12, i64 0, i64 0))
br label %111
97: ; preds = %93
%98 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.9, i64 0, i64 0))
br label %111
99: ; preds = %93
%100 = icmp slt i32 %94, 1
br i1 %100, label %113, label %101
101: ; preds = %99, %108
%102 = phi i64 [ %109, %108 ], [ 0, %99 ]
%103 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 %102
%104 = load i32, i32* %103
%105 = icmp eq i32 %104, -1
br i1 %105, label %108, label %106
106: ; preds = %101
%107 = call i32 @send(i32 %104, i8* %8, i32 %94, i32 0)
br label %108
108: ; preds = %101, %106
%109 = add nuw nsw i64 %102, 1
%110 = icmp eq i64 %109, %84
br i1 %110, label %113, label %101
111: ; preds = %95, %97
%112 = call i32 @close(i32 %88)
store i32 -1, i32* %87
br label %113
113: ; preds = %108, %111, %99, %85, %90
%114 = add nuw nsw i64 %86, 1
%115 = icmp eq i64 %114, %84
br i1 %115, label %82, label %85
}