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

/* 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*/ F_SETFL;
int /*<<< orphan*/ O_NONBLOCK;
int /*<<< orphan*/ SOCK_STREAM;
int accept(int, struct sockaddr *, int *);
scalar_t__ bind(int, struct sockaddr_in *, int);
int /*<<< orphan*/ bzero(char *, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
scalar_t__ fcntl(int, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ inet_addr(char *);
int /*<<< orphan*/ listen(int, int);
int ntohs(int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int read(int, char *, int);
int select(int, int /*<<< orphan*/ *, int /*<<< orphan*/, int /*<<< orphan*/,
           struct timeval *);
int sendmsg_to_client(int, char *);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
main() {
  char *message = " hello to my server please enter message ";
  struct timeval to;
  char address[] = "192.168.12.211";
  int sock, length;
  struct sockaddr_in server;
  int msgsock;
  char buf[1024];
  int rval;
  fd_set ready;
  sock = socket(AF_INET, SOCK_STREAM, 0);
  if (sock < 0) {
    perror("opening stream socket");
    exit(1);
  }
  int one = 1;
  if (fcntl(sock, F_SETFL, O_NONBLOCK) < 0) {
    perror("ioctl stream socket");
    exit(1);
  };
  server.sin_family = AF_INET;
  server.sin_addr.s_addr = inet_addr(address);
  server.sin_port = htons(3333);
  if (bind(sock, &server, sizeof(server))) {
    perror("binding stream socket");
    exit(1);
  }
  printf("Socket has port #%d\n", ntohs(server.sin_port));
  listen(sock, 5);
  do {
    FD_ZERO(&ready);
    FD_SET(sock, &ready);
    to.tv_sec = 15;
    int r = select(sock + 1, &ready, 0, 0, &to);
    printf(" echo server :r is %d \n", r);
    if (r < 0) {
      perror("select");
      continue;
    }
    printf("after select\n");
    if (FD_ISSET(sock, &ready)) {
      msgsock = accept(sock, (struct sockaddr *)0, (int *)0);
      if (msgsock == -1)
        perror("accept");
      else
        do {
          int sndmsgl = sendmsg_to_client(msgsock, message);
          if (sndmsgl < 0)
            printf("error in  sendmsg\n");
          bzero(buf, sizeof(buf));
          if ((rval = read(msgsock, buf, 10)) < 0)
            perror("reading stream message");
          else if (rval == 2)
            printf("Ending connection\n");
          else
            printf("%d-->%s\n", rval, buf);
        } while (rval > 2);
      close(msgsock);
    } else
      printf("Do something else\n");
  } while (1);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x470,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xdb7(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    0xdd6(%rip),%rax
mov    %rax,-0x27(%rbp)
mov    0xdd4(%rip),%eax
mov    %eax,-0x1f(%rbp)
mov    0xdce(%rip),%ax
mov    %ax,-0x1b(%rbp)
mov    0xdc6(%rip),%al
mov    %al,-0x19(%rbp)
mov    0x2d6c(%rip),%rax
mov    (%rax),%edi
mov    0x2d43(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1150 <socket@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jge    12b1 <main+0x81>
lea    0xd97(%rip),%rdi
call   1100 <perror@plt>
mov    $0x1,%edi
call   1130 <exit@plt>
movl   $0x1,-0x45c(%rbp)
mov    -0x2c(%rbp),%edi
mov    0x2d0b(%rip),%rax
mov    (%rax),%esi
mov    0x2d12(%rip),%rax
mov    (%rax),%edx
call   1030 <fcntl@plt>
cmp    $0x0,%rax
jge    12f5 <main+0xc5>
lea    0xd69(%rip),%rdi
call   1100 <perror@plt>
mov    $0x1,%edi
call   1130 <exit@plt>
mov    0x2cec(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x38(%rbp)
lea    -0x27(%rbp),%rdi
call   10a0 <inet_addr@plt>
mov    %eax,-0x3c(%rbp)
mov    $0xd05,%edi
call   1060 <htons@plt>
mov    %eax,-0x40(%rbp)
mov    -0x2c(%rbp),%edi
lea    -0x40(%rbp),%rsi
mov    $0xc,%edx
call   10f0 <bind@plt>
cmp    $0x0,%rax
je     134b <main+0x11b>
lea    0xd27(%rip),%rdi
call   1100 <perror@plt>
mov    $0x1,%edi
call   1130 <exit@plt>
mov    -0x40(%rbp),%edi
call   10e0 <ntohs@plt>
mov    %eax,%esi
lea    0xd1d(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x2c(%rbp),%edi
mov    $0x5,%esi
call   10d0 <listen@plt>
lea    -0x458(%rbp),%rdi
call   10b0 <FD_ZERO@plt>
mov    -0x2c(%rbp),%edi
lea    -0x458(%rbp),%rsi
call   1140 <FD_SET@plt>
movl   $0xf,-0x18(%rbp)
mov    -0x2c(%rbp),%edi
add    $0x1,%edi
lea    -0x458(%rbp),%rsi
xor    %ecx,%ecx
lea    -0x18(%rbp),%r8
mov    %ecx,%edx
call   10c0 <select@plt>
mov    %eax,-0x460(%rbp)
mov    -0x460(%rbp),%esi
lea    0xccf(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
cmpl   $0x0,-0x460(%rbp)
jge    13e4 <main+0x1b4>
lea    0xccc(%rip),%rdi
call   1100 <perror@plt>
jmp    1526 <main+0x2f6>
lea    0xcc2(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x2c(%rbp),%edi
lea    -0x458(%rbp),%rsi
call   1040 <FD_ISSET@plt>
cmp    $0x0,%rax
je     1513 <main+0x2e3>
mov    -0x2c(%rbp),%edi
xor    %eax,%eax
mov    %eax,%edx
mov    %rdx,%rsi
call   1120 <accept@plt>
mov    %eax,-0x44(%rbp)
cmpl   $0xffffffff,-0x44(%rbp)
jne    1438 <main+0x208>
lea    0xc8d(%rip),%rdi
call   1100 <perror@plt>
jmp    1506 <main+0x2d6>
jmp    143d <main+0x20d>
mov    -0x44(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1050 <sendmsg_to_client@plt>
mov    %eax,-0x464(%rbp)
cmpl   $0x0,-0x464(%rbp)
jge    146a <main+0x23a>
lea    0xc5f(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    -0x450(%rbp),%rdi
mov    $0x400,%esi
call   1110 <bzero@plt>
mov    -0x44(%rbp),%edi
lea    -0x450(%rbp),%rsi
mov    $0xa,%edx
call   1090 <read@plt>
mov    %eax,-0x454(%rbp)
cmp    $0x0,%eax
jge    14af <main+0x27f>
lea    0xc30(%rip),%rdi
call   1100 <perror@plt>
jmp    14ef <main+0x2bf>
cmpl   $0x2,-0x454(%rbp)
jne    14cf <main+0x29f>
lea    0xc29(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
jmp    14ea <main+0x2ba>
mov    -0x454(%rbp),%esi
lea    -0x450(%rbp),%rdx
lea    0xc1c(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
jmp    14ef <main+0x2bf>
jmp    14f4 <main+0x2c4>
cmpl   $0x2,-0x454(%rbp)
jg     143d <main+0x20d>
jmp    1506 <main+0x2d6>
mov    -0x44(%rbp),%edi
call   1080 <close@plt>
jmp    1521 <main+0x2f1>
lea    0xbee(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
jmp    1526 <main+0x2f6>
mov    $0x1,%al
test   $0x1,%al
jne    1370 <main+0x140>
jmp    1535 <main+0x305>
mov    -0x4(%rbp),%eax
add    $0x470,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x438,%rsp
movabs $0x3131322e32312e,%rax
mov    %rax,0x27(%rsp)
movabs $0x2e3836312e323931,%rax
36 38 2e
mov    %rax,0x20(%rsp)
mov    0x2d72(%rip),%rbx
mov    (%rbx),%edi
mov    0x2d49(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1160 <socket@plt>
test   %eax,%eax
js     1486 <main+0x246>
mov    %eax,%r15d
mov    0x2d36(%rip),%rax
mov    (%rax),%esi
mov    0x2d3d(%rip),%rax
mov    (%rax),%edx
mov    %r15d,%edi
call   1040 <fcntl@plt>
test   %rax,%rax
js     148f <main+0x24f>
mov    (%rbx),%eax
mov    %eax,0x18(%rsp)
lea    0x20(%rsp),%rdi
call   10b0 <inet_addr@plt>
mov    %eax,0x14(%rsp)
mov    $0xd05,%edi
call   1070 <htons@plt>
mov    %eax,0x10(%rsp)
lea    0x10(%rsp),%rsi
mov    %r15d,%edi
mov    $0xc,%edx
call   1100 <bind@plt>
test   %rax,%rax
jne    1498 <main+0x258>
mov    0x10(%rsp),%edi
call   10f0 <ntohs@plt>
lea    0xd76(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1080 <printf@plt>
mov    %r15d,%edi
mov    $0x5,%esi
call   10e0 <listen@plt>
mov    %r15d,%eax
add    $0x1,%eax
mov    %eax,0x8(%rsp)
lea    0xc(%rsp),%rbp
lea    0xcd1(%rip),%r13
lea    0x30(%rsp),%r12
lea    0xd89(%rip),%r14
mov    %r15d,0x4(%rsp)
jmp    135c <main+0x11c>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
lea    0xd7c(%rip),%rdi
call   1110 <perror@plt>
mov    %rbp,%rdi
call   10c0 <FD_ZERO@plt>
mov    %r15d,%edi
mov    %rbp,%rsi
call   1150 <FD_SET@plt>
movl   $0xf,(%rsp)
mov    0x8(%rsp),%edi
mov    %rbp,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
mov    %rsp,%r8
call   10d0 <select@plt>
mov    %eax,%ebx
lea    0xcfc(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1080 <printf@plt>
test   %ebx,%ebx
js     1350 <main+0x110>
lea    0xd27(%rip),%rdi
call   1030 <puts@plt>
mov    %r15d,%edi
mov    %rbp,%rsi
call   1050 <FD_ISSET@plt>
test   %rax,%rax
jne    13d0 <main+0x190>
lea    0xd18(%rip),%rdi
call   1030 <puts@plt>
jmp    135c <main+0x11c>
nopl   0x0(%rax)
mov    %r15d,%edi
xor    %esi,%esi
xor    %edx,%edx
call   1130 <accept@plt>
mov    %eax,%ebx
cmp    $0xffffffff,%eax
lea    0xd16(%rip),%r15
jne    1400 <main+0x1c0>
lea    0xcb5(%rip),%rdi
call   1110 <perror@plt>
jmp    1470 <main+0x230>
nopl   0x0(%rax,%rax,1)
mov    %ebx,%edi
mov    %r13,%rsi
call   1060 <sendmsg_to_client@plt>
test   %eax,%eax
jns    1416 <main+0x1d6>
mov    %r15,%rdi
call   1030 <puts@plt>
mov    %r12,%rdi
mov    $0x400,%esi
call   1120 <bzero@plt>
mov    %ebx,%edi
mov    %r12,%rsi
mov    $0xa,%edx
call   10a0 <read@plt>
test   %eax,%eax
js     1453 <main+0x213>
mov    %eax,%ebp
cmp    $0x2,%eax
je     1461 <main+0x221>
mov    %r14,%rdi
mov    %ebp,%esi
mov    %r12,%rdx
xor    %eax,%eax
call   1080 <printf@plt>
cmp    $0x2,%ebp
ja     1400 <main+0x1c0>
jmp    1470 <main+0x230>
lea    0xc53(%rip),%rdi
call   1110 <perror@plt>
jmp    1470 <main+0x230>
lea    0xc84(%rip),%rdi
call   1030 <puts@plt>
nopl   (%rax)
mov    %ebx,%edi
call   1090 <close@plt>
mov    0x4(%rsp),%r15d
lea    0xc(%rsp),%rbp
jmp    135c <main+0x11c>
lea    0xbac(%rip),%rdi
jmp    149f <main+0x25f>
lea    0xbb9(%rip),%rdi
jmp    149f <main+0x25f>
lea    0xbc4(%rip),%rdi
call   1110 <perror@plt>
mov    $0x1,%edi
call   1140 <exit@plt>

LLVM IR (-O0):
%struct.timeval = type { i32 }
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [42 x i8] c" hello to my server please enter message \00"
@__const.main.address = [15 x i8] c"192.168.12.211\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.1 = [22 x i8] c"opening stream socket\00"
@F_SETFL = global i32 0
@O_NONBLOCK = global i32 0
@.str.2 = [20 x i8] c"ioctl stream socket\00"
@.str.3 = [22 x i8] c"binding stream socket\00"
@.str.4 = [21 x i8] c"Socket has port #%d\0A\00"
@.str.5 = [24 x i8] c" echo server :r is %d \0A\00"
@.str.6 = [7 x i8] c"select\00"
@.str.7 = [14 x i8] c"after select\0A\00"
@.str.8 = [7 x i8] c"accept\00"
@.str.9 = [19 x i8] c"error in sendmsg\0A\00"
@.str.10 = [23 x i8] c"reading stream message\00"
@.str.11 = [19 x i8] c"Ending connection\0A\00"
@.str.12 = [9 x i8] c"%d-->%s\0A\00"
@.str.13 = [19 x i8] c"Do something else\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca %struct.timeval
%4 = alloca [15 x i8]
%5 = alloca i32
%6 = alloca i32
%7 = alloca %struct.sockaddr_in
%8 = alloca i32
%9 = alloca [1024 x i8]
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
store i32 0, i32* %1
store i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0), i8** %2
%15 = bitcast [15 x i8]* %4 to i8*
%16 = load i32, i32* @AF_INET
%17 = load i32, i32* @SOCK_STREAM
%18 = call i32 @socket(i32 %16, i32 %17, i32 0)
store i32 %18, i32* %5
%19 = load i32, i32* %5
%20 = icmp slt i32 %19, 0
br i1 %20, label %21, label %24
21: ; preds = %0
%22 = call i32 @perror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
%23 = call i32 @exit(i32 1)
unreachable
24: ; preds = %0
store i32 1, i32* %12
%25 = load i32, i32* %5
%26 = load i32, i32* @F_SETFL
%27 = load i32, i32* @O_NONBLOCK
%28 = call i64 @fcntl(i32 %25, i32 %26, i32 %27)
%29 = icmp slt i64 %28, 0
br i1 %29, label %30, label %33
30: ; preds = %24
%31 = call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
%32 = call i32 @exit(i32 1)
unreachable
33: ; preds = %24
%34 = load i32, i32* @AF_INET
%35 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 2
store i32 %34, i32* %35
%36 = getelementptr inbounds [15 x i8], [15 x i8]* %4, i64 0, i64 0
%37 = call i32 @inet_addr(i8* %36)
%38 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 1
%39 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %38, i32 0, i32 0
store i32 %37, i32* %39
%40 = call i32 @htons(i32 3333)
%41 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 0
store i32 %40, i32* %41
%42 = load i32, i32* %5
%43 = call i64 @bind(i32 %42, %struct.sockaddr_in* %7, i32 12)
%44 = icmp ne i64 %43, 0
br i1 %44, label %45, label %48
45: ; preds = %33
%46 = call i32 @perror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0))
%47 = call i32 @exit(i32 1)
unreachable
48: ; preds = %33
%49 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 0
%50 = load i32, i32* %49
%51 = call i32 @ntohs(i32 %50)
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0), i32 %51)
%53 = load i32, i32* %5
%54 = call i32 @listen(i32 %53, i32 5)
br label %55
55: ; preds = %120, %48
%56 = call i32 @FD_ZERO(i32* %11)
%57 = load i32, i32* %5
%58 = call i32 @FD_SET(i32 %57, i32* %11)
%59 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i32 0, i32 0
store i32 15, i32* %59
%60 = load i32, i32* %5
%61 = add nsw i32 %60, 1
%62 = call i32 @select(i32 %61, i32* %11, i32 0, i32 0, %struct.timeval* %3)
store i32 %62, i32* %13
%63 = load i32, i32* %13
%64 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0), i32 %63)
%65 = load i32, i32* %13
%66 = icmp slt i32 %65, 0
br i1 %66, label %67, label %69
67: ; preds = %55
%68 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0))
br label %120
69: ; preds = %55
%70 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.7, i64 0, i64 0))
%71 = load i32, i32* %5
%72 = call i64 @FD_ISSET(i32 %71, i32* %11)
%73 = icmp ne i64 %72, 0
br i1 %73, label %74, label %117
74: ; preds = %69
%75 = load i32, i32* %5
%76 = call i32 @accept(i32 %75, %struct.sockaddr* null, i32* null)
store i32 %76, i32* %8
%77 = load i32, i32* %8
%78 = icmp eq i32 %77, -1
br i1 %78, label %79, label %81
79: ; preds = %74
%80 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.8, i64 0, i64 0))
br label %114
81: ; preds = %74
br label %82
82: ; preds = %110, %81
%83 = load i32, i32* %8
%84 = load i8*, i8** %2
%85 = call i32 @sendmsg_to_client(i32 %83, i8* %84)
store i32 %85, i32* %14
%86 = load i32, i32* %14
%87 = icmp slt i32 %86, 0
br i1 %87, label %88, label %90
88: ; preds = %82
%89 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.9, i64 0, i64 0))
br label %90
90: ; preds = %88, %82
%91 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%92 = call i32 @bzero(i8* %91, i32 1024)
%93 = load i32, i32* %8
%94 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%95 = call i32 @read(i32 %93, i8* %94, i32 10)
store i32 %95, i32* %10
%96 = icmp slt i32 %95, 0
br i1 %96, label %97, label %99
97: ; preds = %90
%98 = call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.10, i64 0, i64 0))
br label %109
99: ; preds = %90
%100 = load i32, i32* %10
%101 = icmp eq i32 %100, 2
br i1 %101, label %102, label %104
102: ; preds = %99
%103 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.11, i64 0, i64 0))
br label %108
104: ; preds = %99
%105 = load i32, i32* %10
%106 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%107 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.12, i64 0, i64 0), i32 %105, i8* %106)
br label %108
108: ; preds = %104, %102
br label %109
109: ; preds = %108, %97
br label %110
110: ; preds = %109
%111 = load i32, i32* %10
%112 = icmp sgt i32 %111, 2
br i1 %112, label %82, label %113
113: ; preds = %110
br label %114
114: ; preds = %113, %79
%115 = load i32, i32* %8
%116 = call i32 @close(i32 %115)
br label %119
117: ; preds = %69
%118 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.13, i64 0, i64 0))
br label %119
119: ; preds = %117, %114
br label %120
120: ; preds = %119, %67
br i1 true, label %55, label %121
121: ; preds = %120
%122 = load i32, i32* %1
ret i32 %122
}

LLVM IR (-O2):
%struct.timeval = type { i32 }
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [42 x i8] c" hello to my server please enter message \00"
@__const.main.address = [15 x i8] c"192.168.12.211\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.1 = [22 x i8] c"opening stream socket\00"
@F_SETFL = global i32 0
@O_NONBLOCK = global i32 0
@.str.2 = [20 x i8] c"ioctl stream socket\00"
@.str.3 = [22 x i8] c"binding stream socket\00"
@.str.4 = [21 x i8] c"Socket has port #%d\0A\00"
@.str.5 = [24 x i8] c" echo server :r is %d \0A\00"
@.str.6 = [7 x i8] c"select\00"
@.str.8 = [7 x i8] c"accept\00"
@.str.10 = [23 x i8] c"reading stream message\00"
@.str.12 = [9 x i8] c"%d-->%s\0A\00"
@str = [13 x i8] c"after select\00"
@str.14 = [18 x i8] c"Do something else\00"
@str.15 = [18 x i8] c"Ending connection\00"
@str.16 = [18 x i8] c"error in sendmsg\00"
define i32 @main() {
%1 = alloca %struct.timeval
%2 = alloca [15 x i8]
%3 = alloca %struct.sockaddr_in
%4 = alloca [1024 x i8]
%5 = alloca i32
%6 = bitcast %struct.timeval* %1 to i8*
%7 = getelementptr inbounds [15 x i8], [15 x i8]* %2, i64 0, i64 0
%8 = bitcast %struct.sockaddr_in* %3 to i8*
%9 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%10 = bitcast i32* %5 to i8*
%11 = load i32, i32* @AF_INET
%12 = load i32, i32* @SOCK_STREAM
%13 = tail call i32 @socket(i32 %11, i32 %12, i32 0)
%14 = icmp slt i32 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %0
%16 = tail call i32 @perror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
%17 = tail call i32 @exit(i32 1)
unreachable
18: ; preds = %0
%19 = load i32, i32* @F_SETFL
%20 = load i32, i32* @O_NONBLOCK
%21 = tail call i64 @fcntl(i32 %13, i32 %19, i32 %20)
%22 = icmp slt i64 %21, 0
br i1 %22, label %23, label %26
23: ; preds = %18
%24 = tail call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
%25 = tail call i32 @exit(i32 1)
unreachable
26: ; preds = %18
%27 = load i32, i32* @AF_INET
%28 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %27, i32* %28
%29 = call i32 @inet_addr(i8* %7)
%30 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1, i32 0
store i32 %29, i32* %30
%31 = call i32 @htons(i32 3333)
%32 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
store i32 %31, i32* %32
%33 = call i64 @bind(i32 %13, %struct.sockaddr_in* %3, i32 12)
%34 = icmp eq i64 %33, 0
br i1 %34, label %38, label %35
35: ; preds = %26
%36 = call i32 @perror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0))
%37 = call i32 @exit(i32 1)
unreachable
38: ; preds = %26
%39 = load i32, i32* %32
%40 = call i32 @ntohs(i32 %39)
%41 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0), i32 %40)
%42 = call i32 @listen(i32 %13, i32 5)
%43 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 0
%44 = add nuw nsw i32 %13, 1
br label %45
45: ; preds = %82, %38
%46 = call i32 @FD_ZERO(i32* %5)
%47 = call i32 @FD_SET(i32 %13, i32* %5)
store i32 15, i32* %43
%48 = call i32 @select(i32 %44, i32* %5, i32 0, i32 0, %struct.timeval* %1)
%49 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0), i32 %48)
%50 = icmp slt i32 %48, 0
br i1 %50, label %51, label %53
51: ; preds = %45
%52 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0))
br label %82
53: ; preds = %45
%54 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str, i64 0, i64 0))
%55 = call i64 @FD_ISSET(i32 %13, i32* %5)
%56 = icmp eq i64 %55, 0
br i1 %56, label %83, label %57
57: ; preds = %53
%58 = call i32 @accept(i32 %13, %struct.sockaddr* null, i32* null)
%59 = icmp eq i32 %58, -1
br i1 %59, label %60, label %62
60: ; preds = %57
%61 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.8, i64 0, i64 0))
br label %80
62: ; preds = %57, %77
%63 = call i32 @sendmsg_to_client(i32 %58, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0))
%64 = icmp slt i32 %63, 0
br i1 %64, label %65, label %67
65: ; preds = %62
%66 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str.16, i64 0, i64 0))
br label %67
67: ; preds = %65, %62
%68 = call i32 @bzero(i8* %9, i32 1024)
%69 = call i32 @read(i32 %58, i8* %9, i32 10)
%70 = icmp slt i32 %69, 0
br i1 %70, label %71, label %73
71: ; preds = %67
%72 = call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.10, i64 0, i64 0))
br label %80
73: ; preds = %67
%74 = icmp eq i32 %69, 2
br i1 %74, label %75, label %77
75: ; preds = %73
%76 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str.15, i64 0, i64 0))
br label %80
77: ; preds = %73
%78 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.12, i64 0, i64 0), i32 %69, i8* %9)
%79 = icmp ugt i32 %69, 2
br i1 %79, label %62, label %80
80: ; preds = %77, %71, %75, %60
%81 = call i32 @close(i32 %58)
br label %82
82: ; preds = %80, %83, %51
br label %45
83: ; preds = %53
%84 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str.14, i64 0, i64 0))
br label %82
}