#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 */
typedef int /*<<< orphan*/ writeBuffer;
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;
};
struct hostent {
  int /*<<< orphan*/ h_length;
  scalar_t__ h_addr;
};
typedef int /*<<< orphan*/ serverAddr;
typedef int /*<<< orphan*/ readBuffer;
typedef int /*<<< orphan*/ name;
typedef int /*<<< orphan*/ fd_set;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int EXIT_SUCCESS;
scalar_t__ FD_ISSET(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ FD_SET(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ FD_SETSIZE;
int /*<<< orphan*/ FD_ZERO(int /*<<< orphan*/ *);
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ bcopy(char *, char *, int /*<<< orphan*/);
int /*<<< orphan*/ bzero(char *, int);
int /*<<< orphan*/ close(int);
scalar_t__ connect(int, struct sockaddr *, int);
int /*<<< orphan*/ error(char *);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
int fileno(int /*<<< orphan*/);
struct hostent *gethostbyname(char *);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ puts(char *);
int read(int, char *, int);
int select(int /*<<< orphan*/, int /*<<< orphan*/ *, int /*<<< orphan*/ *,
           int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ strcat(char *, char *);
int strlen(char *);
int /*<<< orphan*/ strncat(char *, char *, int);
scalar_t__ strncmp(char *, char *, int);
int /*<<< orphan*/ strncpy(char *, char *, int);
int write(int, char *, int);
int chatClient(void) {
  int port = 12543;
  int sockfd;
  int bytes;
  int activity;
  int inputfd = fileno(stdin);
  struct sockaddr_in serverAddr;
  struct hostent *server;
  char writeBuffer[128] = {0};
  char readBuffer[128] = {0};
  char name[32] = {0};
  fd_set fds;
  printf("Input your name: ");
  fgets(name, sizeof(name), stdin);
  name[strlen(name) - 1] = '\0';
  strcat(name, ": ");
  if (0 == strncmp(name, ": ", strlen(name))) {
    bzero(name, sizeof(name));
    strcat(name, "anonymous coward: ");
  }
  puts("Type \"exit\" without quotes to leave the chat.");
  if ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
    error("ERROR: socket() failed");
  }
  if ((server = gethostbyname("localhost")) == NULL) {
    error("ERROR: gethostbyname() failed");
  }
  bzero((char *)&serverAddr, sizeof(serverAddr));
  serverAddr.sin_family = AF_INET;
  bcopy((char *)server->h_addr, (char *)&serverAddr.sin_addr.s_addr,
        server->h_length);
  serverAddr.sin_port = htons(port);
  if (connect(sockfd, (struct sockaddr *)&serverAddr, sizeof(serverAddr)) < 0) {
    error("ERROR connect() failed");
  }
  strcat(writeBuffer, name);
  strcat(writeBuffer, "has joined the chat\n");
  if ((bytes = write(sockfd, writeBuffer, sizeof(writeBuffer))) <= 0) {
    error("ERROR: write() failed");
  }
  bzero(writeBuffer, sizeof(writeBuffer));
  for (;;) {
    FD_ZERO(&fds);
    FD_SET(inputfd, &fds);
    FD_SET(sockfd, &fds);
    if ((activity = select(FD_SETSIZE, &fds, NULL, NULL, NULL)) < 0) {
      error("ERROR: select() failed");
    }
    if (FD_ISSET(inputfd, &fds)) {
      bzero(readBuffer, sizeof(readBuffer));
      if ((bytes = read(inputfd, readBuffer, sizeof(readBuffer))) <= 0)
        error("ERROR: read() failed");
      if (0 == strncmp("exit", readBuffer, 4))
        break;
      strncpy(writeBuffer, name, strlen(name));
      strncat(writeBuffer, readBuffer, bytes - 1);
      if ((bytes = write(sockfd, writeBuffer, sizeof(writeBuffer))) <= 0)
        error("ERROR: write() failed");
      bzero(writeBuffer, sizeof(writeBuffer));
    }
    if (FD_ISSET(sockfd, &fds)) {
      bzero(readBuffer, sizeof(readBuffer));
      if ((bytes = read(sockfd, readBuffer, sizeof(readBuffer))) <= 0)
        error("ERROR: recv() failed");
      printf("%s\n", readBuffer);
    }
  }
  strcat(writeBuffer, name);
  strcat(writeBuffer, "has left the chat\n");
  if ((bytes = write(sockfd, writeBuffer, sizeof(writeBuffer))) <= 0)
    error("ERROR: write() failed");
  bzero(writeBuffer, sizeof(writeBuffer));
  close(sockfd);
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<chatClient>:
push   %rbp
mov    %rsp,%rbp
sub    $0x170,%rsp
movl   $0x30ff,-0x4(%rbp)
mov    0x2d47(%rip),%rax
mov    (%rax),%edi
call   1110 <fileno@plt>
mov    %eax,-0x14(%rbp)
lea    -0xb0(%rbp),%rdi
xor    %esi,%esi
mov    $0x80,%edx
call   10b0 <memset@plt>
lea    -0x130(%rbp),%rdi
xor    %esi,%esi
mov    $0x80,%edx
call   10b0 <memset@plt>
lea    -0x150(%rbp),%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   10b0 <memset@plt>
lea    0xd1d(%rip),%rdi
mov    $0x0,%al
call   10a0 <printf@plt>
lea    -0x150(%rbp),%rdi
mov    0x2ce8(%rip),%rax
mov    (%rax),%edx
mov    $0x20,%esi
call   10f0 <fgets@plt>
lea    -0x150(%rbp),%rdi
call   1080 <strlen@plt>
sub    $0x1,%eax
cltq
movb   $0x0,-0x150(%rbp,%rax,1)
lea    -0x150(%rbp),%rdi
lea    0xcf7(%rip),%rsi
call   1170 <strcat@plt>
lea    -0x150(%rbp),%rax
mov    %rax,-0x160(%rbp)
lea    -0x150(%rbp),%rdi
call   1080 <strlen@plt>
mov    -0x160(%rbp),%rdi
mov    %eax,%edx
lea    0xcc8(%rip),%rsi
call   1040 <strncmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jne    1391 <chatClient+0x111>
lea    -0x150(%rbp),%rdi
mov    $0x20,%esi
call   1160 <bzero@plt>
lea    -0x150(%rbp),%rdi
lea    0xc86(%rip),%rsi
call   1170 <strcat@plt>
lea    0xc8d(%rip),%rdi
call   1050 <puts@plt>
mov    0x2c44(%rip),%rax
mov    (%rax),%edi
mov    0x2c23(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   11a0 <socket@plt>
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
jge    13ce <chatClient+0x14e>
lea    0xc8a(%rip),%rdi
call   1150 <error@plt>
lea    0xc95(%rip),%rdi
call   1100 <gethostbyname@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    13f4 <chatClient+0x174>
lea    0xc85(%rip),%rdi
call   1150 <error@plt>
lea    -0x20(%rbp),%rdi
mov    $0xc,%esi
call   1160 <bzero@plt>
mov    0x2bdf(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    -0x28(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x20(%rbp),%rsi
add    $0x4,%rsi
mov    -0x28(%rbp),%rax
mov    (%rax),%edx
call   1140 <bcopy@plt>
mov    -0x4(%rbp),%edi
call   1090 <htons@plt>
mov    %eax,-0x20(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0xc,%edx
call   1180 <connect@plt>
cmp    $0x0,%rax
jge    145b <chatClient+0x1db>
lea    0xc3c(%rip),%rdi
call   1150 <error@plt>
lea    -0xb0(%rbp),%rdi
lea    -0x150(%rbp),%rsi
call   1170 <strcat@plt>
lea    -0xb0(%rbp),%rdi
lea    0xc2d(%rip),%rsi
call   1170 <strcat@plt>
mov    -0x8(%rbp),%edi
lea    -0xb0(%rbp),%rsi
mov    $0x80,%edx
call   1060 <write@plt>
mov    %eax,-0xc(%rbp)
cmp    $0x0,%eax
jg     14ad <chatClient+0x22d>
lea    0xc16(%rip),%rdi
call   1150 <error@plt>
lea    -0xb0(%rbp),%rdi
mov    $0x80,%esi
call   1160 <bzero@plt>
lea    -0x154(%rbp),%rdi
call   1120 <FD_ZERO@plt>
mov    -0x14(%rbp),%edi
lea    -0x154(%rbp),%rsi
call   1190 <FD_SET@plt>
mov    -0x8(%rbp),%edi
lea    -0x154(%rbp),%rsi
call   1190 <FD_SET@plt>
mov    0x2ad9(%rip),%rax
mov    (%rax),%edi
lea    -0x154(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%r8d
mov    %r8,%rdx
mov    %r8,%rcx
call   1130 <select@plt>
mov    %eax,-0x10(%rbp)
cmp    $0x0,%eax
jge    1520 <chatClient+0x2a0>
lea    0xbb9(%rip),%rdi
call   1150 <error@plt>
mov    -0x14(%rbp),%edi
lea    -0x154(%rbp),%rsi
call   1070 <FD_ISSET@plt>
cmp    $0x0,%rax
je     1634 <chatClient+0x3b4>
lea    -0x130(%rbp),%rdi
mov    $0x80,%esi
call   1160 <bzero@plt>
mov    -0x14(%rbp),%edi
lea    -0x130(%rbp),%rsi
mov    $0x80,%edx
call   10e0 <read@plt>
mov    %eax,-0xc(%rbp)
cmp    $0x0,%eax
jg     1576 <chatClient+0x2f6>
lea    0xb7a(%rip),%rdi
call   1150 <error@plt>
lea    -0x130(%rbp),%rsi
lea    0xb7c(%rip),%rdi
mov    $0x4,%edx
call   1040 <strncmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jne    15a1 <chatClient+0x321>
jmp    16a4 <chatClient+0x424>
lea    -0xb0(%rbp),%rax
mov    %rax,-0x170(%rbp)
lea    -0x150(%rbp),%rax
mov    %rax,-0x168(%rbp)
lea    -0x150(%rbp),%rdi
call   1080 <strlen@plt>
mov    -0x170(%rbp),%rdi
mov    -0x168(%rbp),%rsi
mov    %eax,%edx
call   1030 <strncpy@plt>
lea    -0xb0(%rbp),%rdi
lea    -0x130(%rbp),%rsi
mov    -0xc(%rbp),%edx
sub    $0x1,%edx
call   10c0 <strncat@plt>
mov    -0x8(%rbp),%edi
lea    -0xb0(%rbp),%rsi
mov    $0x80,%edx
call   1060 <write@plt>
mov    %eax,-0xc(%rbp)
cmp    $0x0,%eax
jg     1623 <chatClient+0x3a3>
lea    0xaa0(%rip),%rdi
call   1150 <error@plt>
lea    -0xb0(%rbp),%rdi
mov    $0x80,%esi
call   1160 <bzero@plt>
mov    -0x8(%rbp),%edi
lea    -0x154(%rbp),%rsi
call   1070 <FD_ISSET@plt>
cmp    $0x0,%rax
je     169f <chatClient+0x41f>
lea    -0x130(%rbp),%rdi
mov    $0x80,%esi
call   1160 <bzero@plt>
mov    -0x8(%rbp),%edi
lea    -0x130(%rbp),%rsi
mov    $0x80,%edx
call   10e0 <read@plt>
mov    %eax,-0xc(%rbp)
cmp    $0x0,%eax
jg     168a <chatClient+0x40a>
lea    0xa80(%rip),%rdi
call   1150 <error@plt>
lea    -0x130(%rbp),%rsi
lea    0xa82(%rip),%rdi
mov    $0x0,%al
call   10a0 <printf@plt>
jmp    14be <chatClient+0x23e>
lea    -0xb0(%rbp),%rdi
lea    -0x150(%rbp),%rsi
call   1170 <strcat@plt>
lea    -0xb0(%rbp),%rdi
lea    0xa59(%rip),%rsi
call   1170 <strcat@plt>
mov    -0x8(%rbp),%edi
lea    -0xb0(%rbp),%rsi
mov    $0x80,%edx
call   1060 <write@plt>
mov    %eax,-0xc(%rbp)
cmp    $0x0,%eax
jg     16f6 <chatClient+0x476>
lea    0x9cd(%rip),%rdi
call   1150 <error@plt>
lea    -0xb0(%rbp),%rdi
mov    $0x80,%esi
call   1160 <bzero@plt>
mov    -0x8(%rbp),%edi
call   10d0 <close@plt>
mov    0x28aa(%rip),%rax
mov    (%rax),%eax
add    $0x170,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<chatClient>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x148,%rsp
mov    0x2d58(%rip),%rbx
mov    (%rbx),%edi
call   1100 <fileno@plt>
mov    %eax,%r12d
xorps  %xmm0,%xmm0
movaps %xmm0,0xb0(%rsp)
movaps %xmm0,0xa0(%rsp)
movaps %xmm0,0x90(%rsp)
movaps %xmm0,0x80(%rsp)
movaps %xmm0,0x70(%rsp)
movaps %xmm0,0x60(%rsp)
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x130(%rsp)
movaps %xmm0,0x120(%rsp)
movaps %xmm0,0x110(%rsp)
movaps %xmm0,0x100(%rsp)
movaps %xmm0,0xf0(%rsp)
movaps %xmm0,0xe0(%rsp)
movaps %xmm0,0xd0(%rsp)
movaps %xmm0,0xc0(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
lea    0xce6(%rip),%rdi
xor    %eax,%eax
call   10a0 <printf@plt>
mov    (%rbx),%edx
lea    0x20(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x20,%esi
call   10e0 <fgets@plt>
mov    %rbx,%rdi
call   1080 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%rbx,1)
lea    0xcd7(%rip),%rbp
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1160 <strcat@plt>
mov    %rbx,%rdi
call   1080 <strlen@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
mov    %eax,%edx
call   1040 <strncmp@plt>
test   %rax,%rax
jne    1391 <chatClient+0x121>
lea    0x20(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x20,%esi
call   1150 <bzero@plt>
lea    0xc89(%rip),%rsi
mov    %rbx,%rdi
call   1160 <strcat@plt>
lea    0xc8d(%rip),%rdi
call   1050 <puts@plt>
mov    0x2c44(%rip),%r14
mov    (%r14),%edi
mov    0x2c22(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1190 <socket@plt>
mov    %eax,0xc(%rsp)
test   %eax,%eax
jns    13cb <chatClient+0x15b>
lea    0xc8d(%rip),%rdi
call   1140 <error@plt>
lea    0xc98(%rip),%rdi
call   10f0 <gethostbyname@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    13eb <chatClient+0x17b>
lea    0xc8e(%rip),%rdi
call   1140 <error@plt>
lea    0x10(%rsp),%rbp
mov    %rbp,%rdi
mov    $0xc,%esi
call   1150 <bzero@plt>
mov    (%r14),%eax
mov    %eax,0x18(%rsp)
mov    0x8(%rbx),%rsi
lea    0x14(%rsp),%rdi
mov    (%rbx),%edx
call   1130 <memmove@plt>
mov    $0x30ff,%edi
call   1090 <htons@plt>
mov    %eax,0x10(%rsp)
mov    0xc(%rsp),%r14d
mov    %r14d,%edi
mov    %rbp,%rsi
mov    $0xc,%edx
call   1170 <connect@plt>
test   %rax,%rax
jns    1448 <chatClient+0x1d8>
lea    0xc4f(%rip),%rdi
call   1140 <error@plt>
lea    0x40(%rsp),%rbx
lea    0x20(%rsp),%rsi
mov    %rbx,%rdi
call   1160 <strcat@plt>
lea    0xc48(%rip),%rsi
mov    %rbx,%rdi
call   1160 <strcat@plt>
mov    %r14d,%edi
mov    %rbx,%rsi
mov    $0x80,%edx
call   1060 <write@plt>
test   %eax,%eax
jg     1489 <chatClient+0x219>
lea    0xc3a(%rip),%rdi
call   1140 <error@plt>
lea    0x40(%rsp),%rbp
mov    %rbp,%rdi
mov    $0x80,%esi
call   1150 <bzero@plt>
lea    0x1c(%rsp),%rbx
lea    0xc0(%rsp),%r15
jmp    14b8 <chatClient+0x248>
nopw   0x0(%rax,%rax,1)
mov    %r15,%rdi
call   1050 <puts@plt>
mov    %rbx,%rdi
call   1110 <FD_ZERO@plt>
mov    %r12d,%edi
mov    %rbx,%rsi
call   1180 <FD_SET@plt>
mov    %r14d,%edi
mov    %rbx,%rsi
call   1180 <FD_SET@plt>
mov    0x2aeb(%rip),%rax
mov    (%rax),%edi
mov    %rbx,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   1120 <select@plt>
test   %eax,%eax
jns    14fe <chatClient+0x28e>
lea    0xbdb(%rip),%rdi
call   1140 <error@plt>
mov    %r12d,%edi
mov    %rbx,%rsi
call   1070 <FD_ISSET@plt>
test   %rax,%rax
je     15c3 <chatClient+0x353>
mov    %r15,%rdi
mov    $0x80,%esi
call   1150 <bzero@plt>
mov    %r12d,%r13d
mov    %r12d,%edi
mov    %r15,%rsi
mov    $0x80,%edx
call   10d0 <read@plt>
mov    %eax,%r12d
test   %eax,%eax
jg     1545 <chatClient+0x2d5>
lea    0xbab(%rip),%rdi
call   1140 <error@plt>
lea    0xbb4(%rip),%rdi
mov    %r15,%rsi
mov    $0x4,%edx
call   1040 <strncmp@plt>
test   %rax,%rax
je     160d <chatClient+0x39d>
lea    0x20(%rsp),%r14
mov    %r14,%rdi
call   1080 <strlen@plt>
mov    %rbp,%rdi
mov    %r14,%rsi
mov    0xc(%rsp),%r14d
mov    %eax,%edx
call   1030 <strncpy@plt>
add    $0xffffffff,%r12d
mov    %rbp,%rdi
mov    %r15,%rsi
mov    %r12d,%edx
call   10b0 <strncat@plt>
mov    %r14d,%edi
mov    %rbp,%rsi
mov    $0x80,%edx
call   1060 <write@plt>
test   %eax,%eax
jg     15b3 <chatClient+0x343>
lea    0xb10(%rip),%rdi
call   1140 <error@plt>
mov    %rbp,%rdi
mov    $0x80,%esi
call   1150 <bzero@plt>
mov    %r13d,%r12d
mov    %r14d,%edi
mov    %rbx,%rsi
call   1070 <FD_ISSET@plt>
test   %rax,%rax
je     14b8 <chatClient+0x248>
mov    %r15,%rdi
mov    $0x80,%esi
call   1150 <bzero@plt>
mov    %r14d,%edi
mov    %r15,%rsi
mov    $0x80,%edx
call   10d0 <read@plt>
test   %eax,%eax
jg     14b0 <chatClient+0x240>
lea    0xb02(%rip),%rdi
call   1140 <error@plt>
jmp    14b0 <chatClient+0x240>
lea    0x40(%rsp),%rbx
lea    0x20(%rsp),%rsi
mov    %rbx,%rdi
call   1160 <strcat@plt>
lea    0xaf4(%rip),%rsi
mov    %rbx,%rdi
call   1160 <strcat@plt>
mov    %r14d,%edi
mov    %rbx,%rsi
mov    $0x80,%edx
call   1060 <write@plt>
test   %eax,%eax
jg     164e <chatClient+0x3de>
lea    0xa75(%rip),%rdi
call   1140 <error@plt>
lea    0x40(%rsp),%rdi
mov    $0x80,%esi
call   1150 <bzero@plt>
mov    %r14d,%edi
call   10c0 <close@plt>
mov    0x2954(%rip),%rax
mov    (%rax),%eax
add    $0x148,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.hostent = type { i32, i64 }
%struct.sockaddr = type { i32 }
@stdin = global i32 0
@.str = [18 x i8] c"Input your name: \00"
@.str.1 = [3 x i8] c": \00"
@.str.2 = [19 x i8] c"anonymous coward: \00"
@.str.3 = [46 x i8] c"Type \22exit\22 without quotes to leave the chat.\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.4 = [23 x i8] c"ERROR: socket() failed\00"
@.str.5 = [10 x i8] c"localhost\00"
@.str.6 = [30 x i8] c"ERROR: gethostbyname() failed\00"
@.str.7 = [23 x i8] c"ERROR connect() failed\00"
@.str.8 = [21 x i8] c"has joined the chat\0A\00"
@.str.9 = [22 x i8] c"ERROR: write() failed\00"
@FD_SETSIZE = global i32 0
@.str.10 = [23 x i8] c"ERROR: select() failed\00"
@.str.11 = [21 x i8] c"ERROR: read() failed\00"
@.str.12 = [5 x i8] c"exit\00"
@.str.13 = [21 x i8] c"ERROR: recv() failed\00"
@.str.14 = [4 x i8] c"%s\0A\00"
@.str.15 = [19 x i8] c"has left the chat\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @chatClient() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca %struct.sockaddr_in
%7 = alloca %struct.hostent*
%8 = alloca [128 x i8]
%9 = alloca [128 x i8]
%10 = alloca [32 x i8]
%11 = alloca i32
store i32 12543, i32* %1
%12 = load i32, i32* @stdin
%13 = call i32 @fileno(i32 %12)
store i32 %13, i32* %5
%14 = bitcast [128 x i8]* %8 to i8*
%15 = bitcast [128 x i8]* %9 to i8*
%16 = bitcast [32 x i8]* %10 to i8*
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%18 = getelementptr inbounds [32 x i8], [32 x i8]* %10, i64 0, i64 0
%19 = load i32, i32* @stdin
%20 = call i32 @fgets(i8* %18, i32 32, i32 %19)
%21 = getelementptr inbounds [32 x i8], [32 x i8]* %10, i64 0, i64 0
%22 = call i32 @strlen(i8* %21)
%23 = sub nsw i32 %22, 1
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds [32 x i8], [32 x i8]* %10, i64 0, i64 %24
store i8 0, i8* %25
%26 = getelementptr inbounds [32 x i8], [32 x i8]* %10, i64 0, i64 0
%27 = call i32 @strcat(i8* %26, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%28 = getelementptr inbounds [32 x i8], [32 x i8]* %10, i64 0, i64 0
%29 = getelementptr inbounds [32 x i8], [32 x i8]* %10, i64 0, i64 0
%30 = call i32 @strlen(i8* %29)
%31 = call i64 @strncmp(i8* %28, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %30)
%32 = icmp eq i64 0, %31
br i1 %32, label %33, label %38
33: ; preds = %0
%34 = getelementptr inbounds [32 x i8], [32 x i8]* %10, i64 0, i64 0
%35 = call i32 @bzero(i8* %34, i32 32)
%36 = getelementptr inbounds [32 x i8], [32 x i8]* %10, i64 0, i64 0
%37 = call i32 @strcat(i8* %36, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
br label %38
38: ; preds = %33, %0
%39 = call i32 @puts(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.3, i64 0, i64 0))
%40 = load i32, i32* @AF_INET
%41 = load i32, i32* @SOCK_STREAM
%42 = call i32 @socket(i32 %40, i32 %41, i32 0)
store i32 %42, i32* %2
%43 = icmp slt i32 %42, 0
br i1 %43, label %44, label %46
44: ; preds = %38
%45 = call i32 @error(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0))
br label %46
46: ; preds = %44, %38
%47 = call %struct.hostent* @gethostbyname(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i64 0, i64 0))
store %struct.hostent* %47, %struct.hostent** %7
%48 = icmp eq %struct.hostent* %47, null
br i1 %48, label %49, label %51
49: ; preds = %46
%50 = call i32 @error(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.6, i64 0, i64 0))
br label %51
51: ; preds = %49, %46
%52 = bitcast %struct.sockaddr_in* %6 to i8*
%53 = call i32 @bzero(i8* %52, i32 12)
%54 = load i32, i32* @AF_INET
%55 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 2
store i32 %54, i32* %55
%56 = load %struct.hostent*, %struct.hostent** %7
%57 = getelementptr inbounds %struct.hostent, %struct.hostent* %56, i32 0, i32 1
%58 = load i64, i64* %57
%59 = inttoptr i64 %58 to i8*
%60 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 1
%61 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %60, i32 0, i32 0
%62 = bitcast i32* %61 to i8*
%63 = load %struct.hostent*, %struct.hostent** %7
%64 = getelementptr inbounds %struct.hostent, %struct.hostent* %63, i32 0, i32 0
%65 = load i32, i32* %64
%66 = call i32 @bcopy(i8* %59, i8* %62, i32 %65)
%67 = load i32, i32* %1
%68 = call i32 @htons(i32 %67)
%69 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 0
store i32 %68, i32* %69
%70 = load i32, i32* %2
%71 = bitcast %struct.sockaddr_in* %6 to %struct.sockaddr*
%72 = call i64 @connect(i32 %70, %struct.sockaddr* %71, i32 12)
%73 = icmp slt i64 %72, 0
br i1 %73, label %74, label %76
74: ; preds = %51
%75 = call i32 @error(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.7, i64 0, i64 0))
br label %76
76: ; preds = %74, %51
%77 = getelementptr inbounds [128 x i8], [128 x i8]* %8, i64 0, i64 0
%78 = getelementptr inbounds [32 x i8], [32 x i8]* %10, i64 0, i64 0
%79 = call i32 @strcat(i8* %77, i8* %78)
%80 = getelementptr inbounds [128 x i8], [128 x i8]* %8, i64 0, i64 0
%81 = call i32 @strcat(i8* %80, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.8, i64 0, i64 0))
%82 = load i32, i32* %2
%83 = getelementptr inbounds [128 x i8], [128 x i8]* %8, i64 0, i64 0
%84 = call i32 @write(i32 %82, i8* %83, i32 128)
store i32 %84, i32* %3
%85 = icmp sle i32 %84, 0
br i1 %85, label %86, label %88
86: ; preds = %76
%87 = call i32 @error(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.9, i64 0, i64 0))
br label %88
88: ; preds = %86, %76
%89 = getelementptr inbounds [128 x i8], [128 x i8]* %8, i64 0, i64 0
%90 = call i32 @bzero(i8* %89, i32 128)
br label %91
91: ; preds = %156, %88
%92 = call i32 @FD_ZERO(i32* %11)
%93 = load i32, i32* %5
%94 = call i32 @FD_SET(i32 %93, i32* %11)
%95 = load i32, i32* %2
%96 = call i32 @FD_SET(i32 %95, i32* %11)
%97 = load i32, i32* @FD_SETSIZE
%98 = call i32 @select(i32 %97, i32* %11, i32* null, i32* null, i32* null)
store i32 %98, i32* %4
%99 = icmp slt i32 %98, 0
br i1 %99, label %100, label %102
100: ; preds = %91
%101 = call i32 @error(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.10, i64 0, i64 0))
br label %102
102: ; preds = %100, %91
%103 = load i32, i32* %5
%104 = call i64 @FD_ISSET(i32 %103, i32* %11)
%105 = icmp ne i64 %104, 0
br i1 %105, label %106, label %140
106: ; preds = %102
%107 = getelementptr inbounds [128 x i8], [128 x i8]* %9, i64 0, i64 0
%108 = call i32 @bzero(i8* %107, i32 128)
%109 = load i32, i32* %5
%110 = getelementptr inbounds [128 x i8], [128 x i8]* %9, i64 0, i64 0
%111 = call i32 @read(i32 %109, i8* %110, i32 128)
store i32 %111, i32* %3
%112 = icmp sle i32 %111, 0
br i1 %112, label %113, label %115
113: ; preds = %106
%114 = call i32 @error(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.11, i64 0, i64 0))
br label %115
115: ; preds = %113, %106
%116 = getelementptr inbounds [128 x i8], [128 x i8]* %9, i64 0, i64 0
%117 = call i64 @strncmp(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.12, i64 0, i64 0), i8* %116, i32 4)
%118 = icmp eq i64 0, %117
br i1 %118, label %119, label %120
119: ; preds = %115
br label %157
120: ; preds = %115
%121 = getelementptr inbounds [128 x i8], [128 x i8]* %8, i64 0, i64 0
%122 = getelementptr inbounds [32 x i8], [32 x i8]* %10, i64 0, i64 0
%123 = getelementptr inbounds [32 x i8], [32 x i8]* %10, i64 0, i64 0
%124 = call i32 @strlen(i8* %123)
%125 = call i32 @strncpy(i8* %121, i8* %122, i32 %124)
%126 = getelementptr inbounds [128 x i8], [128 x i8]* %8, i64 0, i64 0
%127 = getelementptr inbounds [128 x i8], [128 x i8]* %9, i64 0, i64 0
%128 = load i32, i32* %3
%129 = sub nsw i32 %128, 1
%130 = call i32 @strncat(i8* %126, i8* %127, i32 %129)
%131 = load i32, i32* %2
%132 = getelementptr inbounds [128 x i8], [128 x i8]* %8, i64 0, i64 0
%133 = call i32 @write(i32 %131, i8* %132, i32 128)
store i32 %133, i32* %3
%134 = icmp sle i32 %133, 0
br i1 %134, label %135, label %137
135: ; preds = %120
%136 = call i32 @error(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.9, i64 0, i64 0))
br label %137
137: ; preds = %135, %120
%138 = getelementptr inbounds [128 x i8], [128 x i8]* %8, i64 0, i64 0
%139 = call i32 @bzero(i8* %138, i32 128)
br label %140
140: ; preds = %137, %102
%141 = load i32, i32* %2
%142 = call i64 @FD_ISSET(i32 %141, i32* %11)
%143 = icmp ne i64 %142, 0
br i1 %143, label %144, label %156
144: ; preds = %140
%145 = getelementptr inbounds [128 x i8], [128 x i8]* %9, i64 0, i64 0
%146 = call i32 @bzero(i8* %145, i32 128)
%147 = load i32, i32* %2
%148 = getelementptr inbounds [128 x i8], [128 x i8]* %9, i64 0, i64 0
%149 = call i32 @read(i32 %147, i8* %148, i32 128)
store i32 %149, i32* %3
%150 = icmp sle i32 %149, 0
br i1 %150, label %151, label %153
151: ; preds = %144
%152 = call i32 @error(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.13, i64 0, i64 0))
br label %153
153: ; preds = %151, %144
%154 = getelementptr inbounds [128 x i8], [128 x i8]* %9, i64 0, i64 0
%155 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.14, i64 0, i64 0), i8* %154)
br label %156
156: ; preds = %153, %140
br label %91
157: ; preds = %119
%158 = getelementptr inbounds [128 x i8], [128 x i8]* %8, i64 0, i64 0
%159 = getelementptr inbounds [32 x i8], [32 x i8]* %10, i64 0, i64 0
%160 = call i32 @strcat(i8* %158, i8* %159)
%161 = getelementptr inbounds [128 x i8], [128 x i8]* %8, i64 0, i64 0
%162 = call i32 @strcat(i8* %161, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.15, i64 0, i64 0))
%163 = load i32, i32* %2
%164 = getelementptr inbounds [128 x i8], [128 x i8]* %8, i64 0, i64 0
%165 = call i32 @write(i32 %163, i8* %164, i32 128)
store i32 %165, i32* %3
%166 = icmp sle i32 %165, 0
br i1 %166, label %167, label %169
167: ; preds = %157
%168 = call i32 @error(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.9, i64 0, i64 0))
br label %169
169: ; preds = %167, %157
%170 = getelementptr inbounds [128 x i8], [128 x i8]* %8, i64 0, i64 0
%171 = call i32 @bzero(i8* %170, i32 128)
%172 = load i32, i32* %2
%173 = call i32 @close(i32 %172)
%174 = load i32, i32* @EXIT_SUCCESS
ret i32 %174
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.hostent = type { i32, i64 }
%struct.sockaddr = type { i32 }
@stdin = global i32 0
@.str = [18 x i8] c"Input your name: \00"
@.str.1 = [3 x i8] c": \00"
@.str.2 = [19 x i8] c"anonymous coward: \00"
@.str.3 = [46 x i8] c"Type \22exit\22 without quotes to leave the chat.\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.4 = [23 x i8] c"ERROR: socket() failed\00"
@.str.5 = [10 x i8] c"localhost\00"
@.str.6 = [30 x i8] c"ERROR: gethostbyname() failed\00"
@.str.7 = [23 x i8] c"ERROR connect() failed\00"
@.str.8 = [21 x i8] c"has joined the chat\0A\00"
@.str.9 = [22 x i8] c"ERROR: write() failed\00"
@FD_SETSIZE = global i32 0
@.str.10 = [23 x i8] c"ERROR: select() failed\00"
@.str.11 = [21 x i8] c"ERROR: read() failed\00"
@.str.12 = [5 x i8] c"exit\00"
@.str.13 = [21 x i8] c"ERROR: recv() failed\00"
@.str.15 = [19 x i8] c"has left the chat\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @chatClient() {
%1 = alloca %struct.sockaddr_in
%2 = alloca [128 x i8]
%3 = alloca [128 x i8]
%4 = alloca [32 x i8]
%5 = alloca i32
%6 = load i32, i32* @stdin
%7 = tail call i32 @fileno(i32 %6)
%8 = bitcast %struct.sockaddr_in* %1 to i8*
%9 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 0
%10 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%11 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 0
%12 = bitcast i32* %5 to i8*
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%14 = load i32, i32* @stdin
%15 = call i32 @fgets(i8* %11, i32 32, i32 %14)
%16 = call i32 @strlen(i8* %11)
%17 = add nsw i32 %16, -1
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 %18
store i8 0, i8* %19
%20 = call i32 @strcat(i8* %11, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%21 = call i32 @strlen(i8* %11)
%22 = call i64 @strncmp(i8* %11, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %21)
%23 = icmp eq i64 %22, 0
br i1 %23, label %24, label %27
24: ; preds = %0
%25 = call i32 @bzero(i8* %11, i32 32)
%26 = call i32 @strcat(i8* %11, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
br label %27
27: ; preds = %24, %0
%28 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([46 x i8], [46 x i8]* @.str.3, i64 0, i64 0))
%29 = load i32, i32* @AF_INET
%30 = load i32, i32* @SOCK_STREAM
%31 = call i32 @socket(i32 %29, i32 %30, i32 0)
%32 = icmp slt i32 %31, 0
br i1 %32, label %33, label %35
33: ; preds = %27
%34 = call i32 @error(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0))
br label %35
35: ; preds = %33, %27
%36 = call %struct.hostent* @gethostbyname(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i64 0, i64 0))
%37 = icmp eq %struct.hostent* %36, null
br i1 %37, label %38, label %40
38: ; preds = %35
%39 = call i32 @error(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.6, i64 0, i64 0))
br label %40
40: ; preds = %38, %35
%41 = call i32 @bzero(i8* %8, i32 12)
%42 = load i32, i32* @AF_INET
%43 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 2
store i32 %42, i32* %43
%44 = getelementptr inbounds %struct.hostent, %struct.hostent* %36, i64 0, i32 1
%45 = load i64, i64* %44
%46 = inttoptr i64 %45 to i8*
%47 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 1, i32 0
%48 = bitcast i32* %47 to i8*
%49 = getelementptr inbounds %struct.hostent, %struct.hostent* %36, i64 0, i32 0
%50 = load i32, i32* %49
%51 = call i32 @htons(i32 12543)
%52 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 0
store i32 %51, i32* %52
%53 = bitcast %struct.sockaddr_in* %1 to %struct.sockaddr*
%54 = call i64 @connect(i32 %31, %struct.sockaddr* %53, i32 12)
%55 = icmp slt i64 %54, 0
br i1 %55, label %56, label %58
56: ; preds = %40
%57 = call i32 @error(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.7, i64 0, i64 0))
br label %58
58: ; preds = %56, %40
%59 = call i32 @strcat(i8* %9, i8* %11)
%60 = call i32 @strcat(i8* %9, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.8, i64 0, i64 0))
%61 = call i32 @write(i32 %31, i8* %9, i32 128)
%62 = icmp slt i32 %61, 1
br i1 %62, label %63, label %65
63: ; preds = %58
%64 = call i32 @error(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.9, i64 0, i64 0))
br label %65
65: ; preds = %63, %58
%66 = call i32 @bzero(i8* %9, i32 128)
br label %67
67: ; preds = %110, %65
%68 = call i32 @FD_ZERO(i32* %5)
%69 = call i32 @FD_SET(i32 %7, i32* %5)
%70 = call i32 @FD_SET(i32 %31, i32* %5)
%71 = load i32, i32* @FD_SETSIZE
%72 = call i32 @select(i32 %71, i32* %5, i32* null, i32* null, i32* null)
%73 = icmp slt i32 %72, 0
br i1 %73, label %74, label %76
74: ; preds = %67
%75 = call i32 @error(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.10, i64 0, i64 0))
br label %76
76: ; preds = %74, %67
%77 = call i64 @FD_ISSET(i32 %7, i32* %5)
%78 = icmp eq i64 %77, 0
br i1 %78, label %99, label %79
79: ; preds = %76
%80 = call i32 @bzero(i8* %10, i32 128)
%81 = call i32 @read(i32 %7, i8* %10, i32 128)
%82 = icmp slt i32 %81, 1
br i1 %82, label %83, label %85
83: ; preds = %79
%84 = call i32 @error(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.11, i64 0, i64 0))
br label %85
85: ; preds = %83, %79
%86 = call i64 @strncmp(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.12, i64 0, i64 0), i8* %10, i32 4)
%87 = icmp eq i64 %86, 0
br i1 %87, label %111, label %88
88: ; preds = %85
%89 = call i32 @strlen(i8* %11)
%90 = call i32 @strncpy(i8* %9, i8* %11, i32 %89)
%91 = add nsw i32 %81, -1
%92 = call i32 @strncat(i8* %9, i8* %10, i32 %91)
%93 = call i32 @write(i32 %31, i8* %9, i32 128)
%94 = icmp slt i32 %93, 1
br i1 %94, label %95, label %97
95: ; preds = %88
%96 = call i32 @error(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.9, i64 0, i64 0))
br label %97
97: ; preds = %95, %88
%98 = call i32 @bzero(i8* %9, i32 128)
br label %99
99: ; preds = %97, %76
%100 = call i64 @FD_ISSET(i32 %31, i32* %5)
%101 = icmp eq i64 %100, 0
br i1 %101, label %110, label %102
102: ; preds = %99
%103 = call i32 @bzero(i8* %10, i32 128)
%104 = call i32 @read(i32 %31, i8* %10, i32 128)
%105 = icmp slt i32 %104, 1
br i1 %105, label %106, label %108
106: ; preds = %102
%107 = call i32 @error(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.13, i64 0, i64 0))
br label %108
108: ; preds = %106, %102
%109 = call i32 @puts(i8* %10)
br label %110
110: ; preds = %108, %99
br label %67
111: ; preds = %85
%112 = call i32 @strcat(i8* %9, i8* %11)
%113 = call i32 @strcat(i8* %9, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.15, i64 0, i64 0))
%114 = call i32 @write(i32 %31, i8* %9, i32 128)
%115 = icmp slt i32 %114, 1
br i1 %115, label %116, label %118
116: ; preds = %111
%117 = call i32 @error(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.9, i64 0, i64 0))
br label %118
118: ; preds = %116, %111
%119 = call i32 @bzero(i8* %9, i32 128)
%120 = call i32 @close(i32 %31)
%121 = load i32, i32* @EXIT_SUCCESS
ret i32 %121
}