#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_port;
  int /*<<< orphan*/ sin_addr;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ serv_name;
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*/ SOCK_STREAM;
int STDIN_FILENO;
int /*<<< orphan*/ atoi(char *);
int /*<<< orphan*/ close(int);
int connect(int, struct sockaddr *, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ htons(int /*<<< orphan*/);
int /*<<< orphan*/ inet_aton(char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ initMessage(char *);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int read(int, char *, int);
int /*<<< orphan*/ receiveMessage(char *);
int select(int, int /*<<< orphan*/ *, int /*<<< orphan*/ *,
           int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ sendMessage(int, char *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  int sock_fd, max_fd;
  struct sockaddr_in serv_name;
  int status;
  char buf[256];
  int nbytes;
  int ret;
  fd_set read_fds_master, read_fds;
  if (argc < 4) {
    fprintf(stderr, "Usage: %s ip_address port_number username\n", argv[0]);
    exit(1);
  }
  initMessage(argv[3]);
  sock_fd = socket(AF_INET, SOCK_STREAM, 0);
  if (sock_fd == -1) {
    perror("Socket creation");
    exit(1);
  }
  serv_name.sin_family = AF_INET;
  inet_aton(argv[1], &serv_name.sin_addr);
  serv_name.sin_port = htons(atoi(argv[2]));
  status = connect(sock_fd, (struct sockaddr *)&serv_name, sizeof(serv_name));
  if (status == -1) {
    perror("Connection error");
    exit(1);
  }
  max_fd = sock_fd;
  FD_ZERO(&read_fds_master);
  FD_SET(STDIN_FILENO, &read_fds_master);
  FD_SET(sock_fd, &read_fds_master);
  while (1) {
    read_fds = read_fds_master;
    ret = select(max_fd + 1, &read_fds, NULL, NULL, NULL);
    if (ret == -1) {
      perror("Select");
      return -1;
    } else if (ret == 0) {
      printf("Select timeout\n");
      continue;
    }
    if (FD_ISSET(STDIN_FILENO, &read_fds)) {
      nbytes = read(STDIN_FILENO, buf, sizeof(buf));
      if (nbytes > 0 && buf[0] != '\n') {
        buf[nbytes - 1] = '\0';
        sendMessage(sock_fd, buf, nbytes);
      }
    }
    if (FD_ISSET(sock_fd, &read_fds)) {
      memset(buf, 0, sizeof(buf));
      nbytes = read(sock_fd, buf, sizeof(buf));
      if (nbytes == 0) {
        printf("server disconnect\n");
        break;
      } else {
        receiveMessage(buf);
      }
    }
  }
  close(sock_fd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x140,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x4,-0x8(%rbp)
jge    1279 <main+0x49>
mov    0x2d7e(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xd96(%rip),%rsi
call   1090 <fprintf@plt>
mov    $0x1,%edi
call   1120 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
call   10f0 <initMessage@plt>
mov    0x2d5b(%rip),%rax
mov    (%rax),%edi
mov    0x2d3a(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1150 <socket@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    12c2 <main+0x92>
lea    0xd78(%rip),%rdi
call   1100 <perror@plt>
mov    $0x1,%edi
call   1120 <exit@plt>
mov    0x2d1f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x28(%rbp),%rsi
add    $0x4,%rsi
call   10d0 <inet_aton@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1110 <atoi@plt>
mov    %eax,%edi
call   1040 <htons@plt>
mov    %eax,-0x28(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x28(%rbp),%rsi
mov    $0xc,%edx
call   1130 <connect@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0xffffffff,-0x2c(%rbp)
jne    132e <main+0xfe>
lea    0xd1c(%rip),%rdi
call   1100 <perror@plt>
mov    $0x1,%edi
call   1120 <exit@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
lea    -0x13c(%rbp),%rdi
call   10b0 <FD_ZERO@plt>
mov    0x2c81(%rip),%rax
mov    (%rax),%edi
lea    -0x13c(%rbp),%rsi
call   1140 <FD_SET@plt>
mov    -0x14(%rbp),%edi
lea    -0x13c(%rbp),%rsi
call   1140 <FD_SET@plt>
mov    -0x13c(%rbp),%eax
mov    %eax,-0x140(%rbp)
mov    -0x18(%rbp),%edi
add    $0x1,%edi
lea    -0x140(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%r8d
mov    %r8,%rdx
mov    %r8,%rcx
call   10c0 <select@plt>
mov    %eax,-0x138(%rbp)
cmpl   $0xffffffff,-0x138(%rbp)
jne    13b8 <main+0x188>
lea    0xca5(%rip),%rdi
call   1100 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    14ed <main+0x2bd>
cmpl   $0x0,-0x138(%rbp)
jne    13d6 <main+0x1a6>
lea    0xc87(%rip),%rdi
call   1050 <printf@plt>
jmp    1364 <main+0x134>
jmp    13db <main+0x1ab>
mov    0x2be6(%rip),%rax
mov    (%rax),%edi
lea    -0x140(%rbp),%rsi
call   1030 <FD_ISSET@plt>
cmp    $0x0,%rax
je     1464 <main+0x234>
mov    0x2bc7(%rip),%rax
mov    (%rax),%edi
lea    -0x130(%rbp),%rsi
mov    $0x100,%edx
call   1080 <read@plt>
mov    %eax,-0x134(%rbp)
cmpl   $0x0,-0x134(%rbp)
jle    145f <main+0x22f>
movsbl -0x130(%rbp),%eax
cmp    $0xa,%eax
je     145f <main+0x22f>
mov    -0x134(%rbp),%eax
sub    $0x1,%eax
cltq
movb   $0x0,-0x130(%rbp,%rax,1)
mov    -0x14(%rbp),%edi
lea    -0x130(%rbp),%rsi
mov    -0x134(%rbp),%edx
call   10a0 <sendMessage@plt>
jmp    1464 <main+0x234>
mov    -0x14(%rbp),%edi
lea    -0x140(%rbp),%rsi
call   1030 <FD_ISSET@plt>
cmp    $0x0,%rax
je     14d9 <main+0x2a9>
lea    -0x130(%rbp),%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1060 <memset@plt>
mov    -0x14(%rbp),%edi
lea    -0x130(%rbp),%rsi
mov    $0x100,%edx
call   1080 <read@plt>
mov    %eax,-0x134(%rbp)
cmpl   $0x0,-0x134(%rbp)
jne    14c8 <main+0x298>
lea    0xba5(%rip),%rdi
call   1050 <printf@plt>
jmp    14de <main+0x2ae>
lea    -0x130(%rbp),%rdi
call   10e0 <receiveMessage@plt>
jmp    14d9 <main+0x2a9>
jmp    1364 <main+0x134>
mov    -0x14(%rbp),%edi
call   1070 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x140,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x128,%rsp
mov    %rsi,%rbx
cmp    $0x3,%edi
jle    13fd <main+0x1cd>
mov    0x18(%rbx),%rdi
call   10f0 <initMessage@plt>
mov    0x2d8b(%rip),%rbp
mov    0x0(%rbp),%edi
mov    0x2d69(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1150 <socket@plt>
cmp    $0xffffffff,%eax
je     141f <main+0x1ef>
mov    %eax,%r14d
mov    0x0(%rbp),%eax
mov    %eax,0x18(%rsp)
mov    0x8(%rbx),%rdi
lea    0x14(%rsp),%rsi
call   10d0 <inet_aton@plt>
mov    0x10(%rbx),%rdi
call   1110 <atoi@plt>
mov    %eax,%edi
call   1050 <htons@plt>
mov    %eax,0x10(%rsp)
lea    0x10(%rsp),%rsi
mov    %r14d,%edi
mov    $0xc,%edx
call   1130 <connect@plt>
cmp    $0xffffffff,%eax
je     1428 <main+0x1f8>
lea    0xc(%rsp),%rbx
mov    %rbx,%rdi
call   10b0 <FD_ZERO@plt>
mov    0x2cf4(%rip),%r13
mov    0x0(%r13),%edi
mov    %rbx,%rsi
call   1140 <FD_SET@plt>
mov    %r14d,%edi
mov    %rbx,%rsi
call   1140 <FD_SET@plt>
mov    %r14d,%ebp
add    $0x1,%ebp
lea    0x8(%rsp),%rbx
lea    0xd68(%rip),%r15
lea    0x20(%rsp),%r12
jmp    1318 <main+0xe8>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r15,%rdi
call   1030 <puts@plt>
mov    0xc(%rsp),%eax
mov    %eax,0x8(%rsp)
mov    %ebp,%edi
mov    %rbx,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   10c0 <select@plt>
test   %eax,%eax
je     1310 <main+0xe0>
cmp    $0xffffffff,%eax
je     13ea <main+0x1ba>
mov    0x0(%r13),%edi
mov    %rbx,%rsi
call   1040 <FD_ISSET@plt>
test   %rax,%rax
je     1382 <main+0x152>
mov    0x0(%r13),%edi
mov    %r12,%rsi
mov    $0x100,%edx
call   1080 <read@plt>
test   %eax,%eax
jle    1382 <main+0x152>
cmpb   $0xa,0x20(%rsp)
je     1382 <main+0x152>
mov    %eax,%ecx
add    $0xffffffff,%ecx
movb   $0x0,0x20(%rsp,%rcx,1)
mov    %r14d,%edi
mov    %r12,%rsi
mov    %eax,%edx
call   10a0 <sendMessage@plt>
mov    %r14d,%edi
mov    %rbx,%rsi
call   1040 <FD_ISSET@plt>
test   %rax,%rax
je     1318 <main+0xe8>
mov    %r12,%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1060 <memset@plt>
mov    %r14d,%edi
mov    %r12,%rsi
mov    $0x100,%edx
call   1080 <read@plt>
test   %eax,%eax
je     13c2 <main+0x192>
mov    %r12,%rdi
call   10e0 <receiveMessage@plt>
jmp    1318 <main+0xe8>
lea    0xc8a(%rip),%rdi
call   1030 <puts@plt>
mov    %r14d,%edi
call   1070 <close@plt>
xor    %eax,%eax
add    $0x128,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xc5b(%rip),%rdi
call   1100 <perror@plt>
mov    $0xffffffff,%eax
jmp    13d8 <main+0x1a8>
mov    0x2bd4(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xbf0(%rip),%rsi
call   1090 <fprintf@plt>
mov    $0x1,%edi
call   1120 <exit@plt>
lea    0xc05(%rip),%rdi
jmp    142f <main+0x1ff>
lea    0xc0c(%rip),%rdi
call   1100 <perror@plt>
mov    $0x1,%edi
call   1120 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.sockaddr = type { i32 }
@stderr = global i32 0
@.str = [43 x i8] c"Usage: %s ip_address port_number username\0A\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.1 = [16 x i8] c"Socket creation\00"
@.str.2 = [17 x i8] c"Connection error\00"
@STDIN_FILENO = global i32 0
@.str.3 = [7 x i8] c"Select\00"
@.str.4 = [16 x i8] c"Select timeout\0A\00"
@.str.5 = [19 x i8] c"server disconnect\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca %struct.sockaddr_in
%9 = alloca i32
%10 = alloca [256 x i8]
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%15 = load i32, i32* %4
%16 = icmp slt i32 %15, 4
br i1 %16, label %17, label %24
17: ; preds = %2
%18 = load i32, i32* @stderr
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 0
%21 = load i8*, i8** %20
%22 = call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0), i8* %21)
%23 = call i32 @exit(i32 1)
unreachable
24: ; preds = %2
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 3
%27 = load i8*, i8** %26
%28 = call i32 @initMessage(i8* %27)
%29 = load i32, i32* @AF_INET
%30 = load i32, i32* @SOCK_STREAM
%31 = call i32 @socket(i32 %29, i32 %30, i32 0)
store i32 %31, i32* %6
%32 = load i32, i32* %6
%33 = icmp eq i32 %32, -1
br i1 %33, label %34, label %37
34: ; preds = %24
%35 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
%36 = call i32 @exit(i32 1)
unreachable
37: ; preds = %24
%38 = load i32, i32* @AF_INET
%39 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 2
store i32 %38, i32* %39
%40 = load i8**, i8*** %5
%41 = getelementptr inbounds i8*, i8** %40, i64 1
%42 = load i8*, i8** %41
%43 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 1
%44 = call i32 @inet_aton(i8* %42, i32* %43)
%45 = load i8**, i8*** %5
%46 = getelementptr inbounds i8*, i8** %45, i64 2
%47 = load i8*, i8** %46
%48 = call i32 @atoi(i8* %47)
%49 = call i32 @htons(i32 %48)
%50 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 0
store i32 %49, i32* %50
%51 = load i32, i32* %6
%52 = bitcast %struct.sockaddr_in* %8 to %struct.sockaddr*
%53 = call i32 @connect(i32 %51, %struct.sockaddr* %52, i32 12)
store i32 %53, i32* %9
%54 = load i32, i32* %9
%55 = icmp eq i32 %54, -1
br i1 %55, label %56, label %59
56: ; preds = %37
%57 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
%58 = call i32 @exit(i32 1)
unreachable
59: ; preds = %37
%60 = load i32, i32* %6
store i32 %60, i32* %7
%61 = call i32 @FD_ZERO(i32* %13)
%62 = load i32, i32* @STDIN_FILENO
%63 = call i32 @FD_SET(i32 %62, i32* %13)
%64 = load i32, i32* %6
%65 = call i32 @FD_SET(i32 %64, i32* %13)
br label %66
66: ; preds = %59, %78, %124
%67 = load i32, i32* %13
store i32 %67, i32* %14
%68 = load i32, i32* %7
%69 = add nsw i32 %68, 1
%70 = call i32 @select(i32 %69, i32* %14, i32* null, i32* null, i32* null)
store i32 %70, i32* %12
%71 = load i32, i32* %12
%72 = icmp eq i32 %71, -1
br i1 %72, label %73, label %75
73: ; preds = %66
%74 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
store i32 -1, i32* %3
br label %128
75: ; preds = %66
%76 = load i32, i32* %12
%77 = icmp eq i32 %76, 0
br i1 %77, label %78, label %80
78: ; preds = %75
%79 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0))
br label %66
80: ; preds = %75
br label %81
81: ; preds = %80
%82 = load i32, i32* @STDIN_FILENO
%83 = call i64 @FD_ISSET(i32 %82, i32* %14)
%84 = icmp ne i64 %83, 0
br i1 %84, label %85, label %106
85: ; preds = %81
%86 = load i32, i32* @STDIN_FILENO
%87 = getelementptr inbounds [256 x i8], [256 x i8]* %10, i64 0, i64 0
%88 = call i32 @read(i32 %86, i8* %87, i32 256)
store i32 %88, i32* %11
%89 = load i32, i32* %11
%90 = icmp sgt i32 %89, 0
br i1 %90, label %91, label %105
91: ; preds = %85
%92 = getelementptr inbounds [256 x i8], [256 x i8]* %10, i64 0, i64 0
%93 = load i8, i8* %92
%94 = sext i8 %93 to i32
%95 = icmp ne i32 %94, 10
br i1 %95, label %96, label %105
96: ; preds = %91
%97 = load i32, i32* %11
%98 = sub nsw i32 %97, 1
%99 = sext i32 %98 to i64
%100 = getelementptr inbounds [256 x i8], [256 x i8]* %10, i64 0, i64 %99
store i8 0, i8* %100
%101 = load i32, i32* %6
%102 = getelementptr inbounds [256 x i8], [256 x i8]* %10, i64 0, i64 0
%103 = load i32, i32* %11
%104 = call i32 @sendMessage(i32 %101, i8* %102, i32 %103)
br label %105
105: ; preds = %96, %91, %85
br label %106
106: ; preds = %105, %81
%107 = load i32, i32* %6
%108 = call i64 @FD_ISSET(i32 %107, i32* %14)
%109 = icmp ne i64 %108, 0
br i1 %109, label %110, label %124
110: ; preds = %106
%111 = getelementptr inbounds [256 x i8], [256 x i8]* %10, i64 0, i64 0
%112 = call i32 @memset(i8* %111, i32 0, i32 256)
%113 = load i32, i32* %6
%114 = getelementptr inbounds [256 x i8], [256 x i8]* %10, i64 0, i64 0
%115 = call i32 @read(i32 %113, i8* %114, i32 256)
store i32 %115, i32* %11
%116 = load i32, i32* %11
%117 = icmp eq i32 %116, 0
br i1 %117, label %118, label %120
118: ; preds = %110
%119 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.5, i64 0, i64 0))
br label %125
120: ; preds = %110
%121 = getelementptr inbounds [256 x i8], [256 x i8]* %10, i64 0, i64 0
%122 = call i32 @receiveMessage(i8* %121)
br label %123
123: ; preds = %120
br label %124
124: ; preds = %123, %106
br label %66
125: ; preds = %118
%126 = load i32, i32* %6
%127 = call i32 @close(i32 %126)
store i32 0, i32* %3
br label %128
128: ; preds = %125, %73
%129 = load i32, i32* %3
ret i32 %129
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.sockaddr = type { i32 }
@stderr = global i32 0
@.str = [43 x i8] c"Usage: %s ip_address port_number username\0A\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.1 = [16 x i8] c"Socket creation\00"
@.str.2 = [17 x i8] c"Connection error\00"
@STDIN_FILENO = global i32 0
@.str.3 = [7 x i8] c"Select\00"
@str = [18 x i8] c"server disconnect\00"
@str.6 = [15 x i8] c"Select timeout\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca [256 x i8]
%5 = alloca i32
%6 = alloca i32
%7 = bitcast %struct.sockaddr_in* %3 to i8*
%8 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%9 = bitcast i32* %5 to i8*
%10 = bitcast i32* %6 to i8*
%11 = icmp slt i32 %0, 4
br i1 %11, label %12, label %17
12: ; preds = %2
%13 = load i32, i32* @stderr
%14 = load i8*, i8** %1
%15 = tail call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0), i8* %14)
%16 = tail call i32 @exit(i32 1)
unreachable
17: ; preds = %2
%18 = getelementptr inbounds i8*, i8** %1, i64 3
%19 = load i8*, i8** %18
%20 = tail call i32 @initMessage(i8* %19)
%21 = load i32, i32* @AF_INET
%22 = load i32, i32* @SOCK_STREAM
%23 = tail call i32 @socket(i32 %21, i32 %22, i32 0)
%24 = icmp eq i32 %23, -1
br i1 %24, label %25, label %28
25: ; preds = %17
%26 = tail call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
%27 = tail call i32 @exit(i32 1)
unreachable
28: ; preds = %17
%29 = load i32, i32* @AF_INET
%30 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %29, i32* %30
%31 = getelementptr inbounds i8*, i8** %1, i64 1
%32 = load i8*, i8** %31
%33 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1
%34 = call i32 @inet_aton(i8* %32, i32* %33)
%35 = getelementptr inbounds i8*, i8** %1, i64 2
%36 = load i8*, i8** %35
%37 = call i32 @atoi(i8* %36)
%38 = call i32 @htons(i32 %37)
%39 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
store i32 %38, i32* %39
%40 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%41 = call i32 @connect(i32 %23, %struct.sockaddr* %40, i32 12)
%42 = icmp eq i32 %41, -1
br i1 %42, label %43, label %46
43: ; preds = %28
%44 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
%45 = call i32 @exit(i32 1)
unreachable
46: ; preds = %28
%47 = call i32 @FD_ZERO(i32* %5)
%48 = load i32, i32* @STDIN_FILENO
%49 = call i32 @FD_SET(i32 %48, i32* %5)
%50 = call i32 @FD_SET(i32 %23, i32* %5)
%51 = add nuw nsw i32 %23, 1
br label %52
52: ; preds = %78, %46
%53 = load i32, i32* %5
store i32 %53, i32* %6
%54 = call i32 @select(i32 %51, i32* %6, i32* null, i32* null, i32* null)
switch i32 %54, label %59 [
i32 -1, label %55
i32 0, label %57
]
55: ; preds = %52
%56 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
br label %88
57: ; preds = %52
%58 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str.6, i64 0, i64 0))
br label %78
59: ; preds = %52
%60 = load i32, i32* @STDIN_FILENO
%61 = call i64 @FD_ISSET(i32 %60, i32* %6)
%62 = icmp eq i64 %61, 0
br i1 %62, label %75, label %63
63: ; preds = %59
%64 = load i32, i32* @STDIN_FILENO
%65 = call i32 @read(i32 %64, i8* %8, i32 256)
%66 = icmp sgt i32 %65, 0
%67 = load i8, i8* %8
%68 = icmp ne i8 %67, 10
%69 = select i1 %66, i1 %68, i1 false
br i1 %69, label %70, label %75
70: ; preds = %63
%71 = add nsw i32 %65, -1
%72 = zext i32 %71 to i64
%73 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 %72
store i8 0, i8* %73
%74 = call i32 @sendMessage(i32 %23, i8* %8, i32 %65)
br label %75
75: ; preds = %63, %70, %59
%76 = call i64 @FD_ISSET(i32 %23, i32* %6)
%77 = icmp eq i64 %76, 0
br i1 %77, label %78, label %79
78: ; preds = %75, %86, %57
br label %52
79: ; preds = %75
%80 = call i32 @memset(i8* %8, i32 0, i32 256)
%81 = call i32 @read(i32 %23, i8* %8, i32 256)
%82 = icmp eq i32 %81, 0
br i1 %82, label %83, label %86
83: ; preds = %79
%84 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str, i64 0, i64 0))
%85 = call i32 @close(i32 %23)
br label %88
86: ; preds = %79
%87 = call i32 @receiveMessage(i8* %8)
br label %78
88: ; preds = %83, %55
%89 = phi i32 [ -1, %55 ], [ 0, %83 ]
ret i32 %89
}