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

/* Forward declarations */
typedef struct TYPE_2__ TYPE_1__;

/* Type definitions */
struct TYPE_2__ {
  int /*<<< orphan*/ s_addr;
};
struct sockaddr_in {
  int /*<<< orphan*/ sin_port;
  int /*<<< orphan*/ sin_family;
  TYPE_1__ sin_addr;
};
struct sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ server;
typedef int /*<<< orphan*/ fd_set;

/* 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 atoi(char *);
int /*<<< orphan*/ bzero(char *, int);
int /*<<< orphan*/ close(int);
scalar_t__ connect(int, struct sockaddr *, int);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ inet_addr(char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *, ...);
scalar_t__ recv(int, char *, int, int /*<<< orphan*/);
int select(int, int /*<<< orphan*/ *, int /*<<< orphan*/ *,
           int /*<<< orphan*/ *, int /*<<< orphan*/ *);
scalar_t__ send(int, char *, int /*<<< orphan*/, int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ strcpy(char *, char *);
int /*<<< orphan*/ strlen(char *);
int main(int argc, char *argv[]) {
  int s, port;
  fd_set readfds;
  struct sockaddr_in server;
  char user[50], ip[50], message[512], server_message[512];
  strcpy(ip, "127.0.0.1");
  strcpy(user, "user");
  port = 8080;
  if (argc > 4) {
    strcpy(ip, argv[1]);
    port = atoi(argv[2]);
    strcpy(user, argv[3]);
  } else if (argc > 3) {
    strcpy(ip, argv[1]);
    port = atoi(argv[2]);
  } else if (argc > 2) {
    strcpy(ip, argv[1]);
  }
  s = socket(AF_INET, SOCK_STREAM, 0);
  if (s == -1) {
    perror("socket failed");
    return 1;
  }
  server.sin_addr.s_addr = inet_addr(ip);
  server.sin_family = AF_INET;
  server.sin_port = htons(port);
  if (connect(s, (struct sockaddr *)&server, sizeof(server)) < 0) {
    perror("connect failed");
    return 1;
  }
  printf("connected to %s:%d\n", ip, port);
  while (1) {
    FD_ZERO(&readfds);
    FD_SET(s, &readfds);
    FD_SET(0, &readfds);
    int rc = select(s + 1, &readfds, NULL, NULL, NULL);
    if (rc == 0)
      break;
    if (rc == -1)
      break;
    if (FD_ISSET(0, &readfds)) {
      if (fgets(message, 512, stdin) != NULL) {
        if (send(s, message, strlen(message), 0) < 0) {
          perror("send failed");
          return 1;
        }
        bzero(message, 512);
      }
    }
    if (FD_ISSET(s, &readfds)) {
      if (recv(s, server_message, 512, 0) < 0) {
        perror("recv failed");
        return 1;
      }
      printf("%s", server_message);
      bzero(server_message, 512);
    }
  }
  close(s);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x4c0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0xa0(%rbp),%rdi
lea    0xdb9(%rip),%rsi
call   1040 <strcpy@plt>
lea    -0x60(%rbp),%rdi
lea    0xdb3(%rip),%rsi
call   1040 <strcpy@plt>
movl   $0x1f90,-0x18(%rbp)
cmpl   $0x4,-0x8(%rbp)
jle    12a7 <main+0x87>
lea    -0xa0(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
call   1040 <strcpy@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1110 <atoi@plt>
mov    %eax,-0x18(%rbp)
lea    -0x60(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rsi
call   1040 <strcpy@plt>
jmp    1302 <main+0xe2>
cmpl   $0x3,-0x8(%rbp)
jle    12da <main+0xba>
lea    -0xa0(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
call   1040 <strcpy@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1110 <atoi@plt>
mov    %eax,-0x18(%rbp)
jmp    12fd <main+0xdd>
cmpl   $0x2,-0x8(%rbp)
jle    12f8 <main+0xd8>
lea    -0xa0(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
call   1040 <strcpy@plt>
jmp    12fd <main+0xdd>
jmp    1302 <main+0xe2>
mov    0x2cdf(%rip),%rax
mov    (%rax),%edi
mov    0x2cbe(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1140 <socket@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    1340 <main+0x120>
lea    0xce0(%rip),%rdi
call   10f0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1547 <main+0x327>
lea    -0xa0(%rbp),%rdi
call   10c0 <inet_addr@plt>
mov    %eax,-0x20(%rbp)
mov    0x2c92(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    -0x18(%rbp),%edi
call   1070 <htons@plt>
mov    %eax,-0x28(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x28(%rbp),%rsi
mov    $0xc,%edx
call   1120 <connect@plt>
cmp    $0x0,%rax
jge    1399 <main+0x179>
lea    0xc95(%rip),%rdi
call   10f0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1547 <main+0x327>
lea    -0xa0(%rbp),%rsi
mov    -0x18(%rbp),%edx
lea    0xc82(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
lea    -0x1c(%rbp),%rdi
call   10d0 <FD_ZERO@plt>
mov    -0x14(%rbp),%edi
lea    -0x1c(%rbp),%rsi
call   1130 <FD_SET@plt>
xor    %edi,%edi
lea    -0x1c(%rbp),%rsi
call   1130 <FD_SET@plt>
mov    -0x14(%rbp),%edi
add    $0x1,%edi
lea    -0x1c(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%r8d
mov    %r8,%rdx
mov    %r8,%rcx
call   10e0 <select@plt>
mov    %eax,-0x4a4(%rbp)
cmpl   $0x0,-0x4a4(%rbp)
jne    1403 <main+0x1e3>
jmp    1538 <main+0x318>
cmpl   $0xffffffff,-0x4a4(%rbp)
jne    1415 <main+0x1f5>
jmp    1538 <main+0x318>
xor    %edi,%edi
lea    -0x1c(%rbp),%rsi
call   1050 <FD_ISSET@plt>
cmp    $0x0,%rax
je     14bf <main+0x29f>
lea    -0x2a0(%rbp),%rdi
mov    0x2ba8(%rip),%rax
mov    (%rax),%edx
mov    $0x200,%esi
call   10b0 <fgets@plt>
cmp    $0x0,%rax
je     14ba <main+0x29a>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4b4(%rbp)
lea    -0x2a0(%rbp),%rax
mov    %rax,-0x4b0(%rbp)
lea    -0x2a0(%rbp),%rdi
call   1060 <strlen@plt>
mov    -0x4b4(%rbp),%edi
mov    -0x4b0(%rbp),%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1080 <send@plt>
cmp    $0x0,%rax
jge    14a9 <main+0x289>
lea    0xba8(%rip),%rdi
call   10f0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1547 <main+0x327>
lea    -0x2a0(%rbp),%rdi
mov    $0x200,%esi
call   1100 <bzero@plt>
jmp    14bf <main+0x29f>
mov    -0x14(%rbp),%edi
lea    -0x1c(%rbp),%rsi
call   1050 <FD_ISSET@plt>
cmp    $0x0,%rax
je     1533 <main+0x313>
mov    -0x14(%rbp),%edi
lea    -0x4a0(%rbp),%rsi
mov    $0x200,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
cmp    $0x0,%rax
jge    150d <main+0x2ed>
lea    0xb50(%rip),%rdi
call   10f0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1547 <main+0x327>
lea    -0x4a0(%rbp),%rsi
lea    0xb3d(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
lea    -0x4a0(%rbp),%rdi
mov    $0x200,%esi
call   1100 <bzero@plt>
jmp    13b1 <main+0x191>
mov    -0x14(%rbp),%edi
call   10a0 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x4c0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x498,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
lea    0xdc3(%rip),%rsi
lea    0x10(%rsp),%rdi
call   1040 <strcpy@plt>
lea    0xdbc(%rip),%rsi
lea    0x50(%rsp),%rdi
call   1040 <strcpy@plt>
cmp    $0x5,%ebp
jl     1287 <main+0x67>
mov    0x8(%rbx),%rsi
lea    0x10(%rsp),%rdi
call   1040 <strcpy@plt>
mov    0x10(%rbx),%rdi
call   1110 <atoi@plt>
mov    %eax,%r14d
mov    0x18(%rbx),%rsi
lea    0x50(%rsp),%rdi
call   1040 <strcpy@plt>
jmp    12be <main+0x9e>
cmp    $0x4,%ebp
jne    12a8 <main+0x88>
mov    0x8(%rbx),%rsi
lea    0x10(%rsp),%rdi
call   1040 <strcpy@plt>
mov    0x10(%rbx),%rdi
call   1110 <atoi@plt>
mov    %eax,%r14d
jmp    12be <main+0x9e>
mov    $0x1f90,%r14d
cmp    $0x3,%ebp
jl     12be <main+0x9e>
mov    0x8(%rbx),%rsi
lea    0x10(%rsp),%rdi
jmp    1280 <main+0x60>
mov    0x2d23(%rip),%rbp
mov    0x0(%rbp),%edi
mov    0x2d01(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1140 <socket@plt>
cmp    $0xffffffff,%eax
je     1453 <main+0x233>
mov    %eax,%ebx
lea    0x10(%rsp),%rdi
call   10c0 <inet_addr@plt>
mov    %eax,0x8(%rsp)
mov    0x0(%rbp),%eax
mov    %eax,0x4(%rsp)
mov    %r14d,%edi
call   1070 <htons@plt>
mov    %eax,(%rsp)
mov    %rsp,%rsi
mov    %ebx,%edi
mov    $0xc,%edx
call   1120 <connect@plt>
test   %rax,%rax
js     145c <main+0x23c>
lea    0xd0a(%rip),%rdi
lea    0x10(%rsp),%rsi
mov    %r14d,%edx
xor    %eax,%eax
call   1090 <printf@plt>
mov    %ebx,%r14d
add    $0x1,%r14d
lea    0xc(%rsp),%rbp
lea    0x90(%rsp),%r15
lea    0xd0c(%rip),%r12
lea    0x290(%rsp),%r13
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %rbp,%rdi
call   10d0 <FD_ZERO@plt>
mov    %ebx,%edi
mov    %rbp,%rsi
call   1130 <FD_SET@plt>
xor    %edi,%edi
mov    %rbp,%rsi
call   1130 <FD_SET@plt>
mov    %r14d,%edi
mov    %rbp,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   10e0 <select@plt>
add    $0x1,%eax
cmp    $0x2,%eax
jb     1438 <main+0x218>
xor    %edi,%edi
mov    %rbp,%rsi
call   1050 <FD_ISSET@plt>
test   %rax,%rax
je     13f0 <main+0x1d0>
mov    0x2c30(%rip),%rax
mov    (%rax),%edx
mov    %r13,%rdi
mov    $0x200,%esi
call   10b0 <fgets@plt>
test   %rax,%rax
je     13f0 <main+0x1d0>
mov    %r13,%rdi
call   1060 <strlen@plt>
mov    %ebx,%edi
mov    %r13,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1080 <send@plt>
test   %rax,%rax
js     146e <main+0x24e>
mov    %r13,%rdi
mov    $0x200,%esi
call   1100 <bzero@plt>
mov    %ebx,%edi
mov    %rbp,%rsi
call   1050 <FD_ISSET@plt>
test   %rax,%rax
je     1360 <main+0x140>
mov    %ebx,%edi
mov    %r15,%rsi
mov    $0x200,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
test   %rax,%rax
js     1465 <main+0x245>
mov    %r12,%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1090 <printf@plt>
mov    %r15,%rdi
mov    $0x200,%esi
call   1100 <bzero@plt>
jmp    1360 <main+0x140>
mov    %ebx,%edi
call   10a0 <close@plt>
xor    %eax,%eax
add    $0x498,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xbb5(%rip),%rdi
jmp    1475 <main+0x255>
lea    0xbba(%rip),%rdi
jmp    1475 <main+0x255>
lea    0xbe0(%rip),%rdi
jmp    1475 <main+0x255>
lea    0xbcb(%rip),%rdi
call   10f0 <perror@plt>
mov    $0x1,%eax
jmp    1441 <main+0x221>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, i32, %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [10 x i8] c"127.0.0.1\00"
@.str.1 = [5 x i8] c"user\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.2 = [14 x i8] c"socket failed\00"
@.str.3 = [15 x i8] c"connect failed\00"
@.str.4 = [20 x i8] c"connected to %s:%d\0A\00"
@stdin = global i32 0
@.str.5 = [12 x i8] c"send failed\00"
@.str.6 = [12 x i8] c"recv failed\00"
@.str.7 = [3 x i8] c"%s\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 i32
%9 = alloca %struct.sockaddr_in
%10 = alloca [50 x i8]
%11 = alloca [50 x i8]
%12 = alloca [512 x i8]
%13 = alloca [512 x i8]
%14 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%15 = getelementptr inbounds [50 x i8], [50 x i8]* %11, i64 0, i64 0
%16 = call i32 @strcpy(i8* %15, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%17 = getelementptr inbounds [50 x i8], [50 x i8]* %10, i64 0, i64 0
%18 = call i32 @strcpy(i8* %17, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
store i32 8080, i32* %7
%19 = load i32, i32* %4
%20 = icmp sgt i32 %19, 4
br i1 %20, label %21, label %36
21: ; preds = %2
%22 = getelementptr inbounds [50 x i8], [50 x i8]* %11, i64 0, i64 0
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 1
%25 = load i8*, i8** %24
%26 = call i32 @strcpy(i8* %22, i8* %25)
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 2
%29 = load i8*, i8** %28
%30 = call i32 @atoi(i8* %29)
store i32 %30, i32* %7
%31 = getelementptr inbounds [50 x i8], [50 x i8]* %10, i64 0, i64 0
%32 = load i8**, i8*** %5
%33 = getelementptr inbounds i8*, i8** %32, i64 3
%34 = load i8*, i8** %33
%35 = call i32 @strcpy(i8* %31, i8* %34)
br label %60
36: ; preds = %2
%37 = load i32, i32* %4
%38 = icmp sgt i32 %37, 3
br i1 %38, label %39, label %49
39: ; preds = %36
%40 = getelementptr inbounds [50 x i8], [50 x i8]* %11, i64 0, i64 0
%41 = load i8**, i8*** %5
%42 = getelementptr inbounds i8*, i8** %41, i64 1
%43 = load i8*, i8** %42
%44 = call i32 @strcpy(i8* %40, i8* %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)
store i32 %48, i32* %7
br label %59
49: ; preds = %36
%50 = load i32, i32* %4
%51 = icmp sgt i32 %50, 2
br i1 %51, label %52, label %58
52: ; preds = %49
%53 = getelementptr inbounds [50 x i8], [50 x i8]* %11, i64 0, i64 0
%54 = load i8**, i8*** %5
%55 = getelementptr inbounds i8*, i8** %54, i64 1
%56 = load i8*, i8** %55
%57 = call i32 @strcpy(i8* %53, i8* %56)
br label %58
58: ; preds = %52, %49
br label %59
59: ; preds = %58, %39
br label %60
60: ; preds = %59, %21
%61 = load i32, i32* @AF_INET
%62 = load i32, i32* @SOCK_STREAM
%63 = call i32 @socket(i32 %61, i32 %62, i32 0)
store i32 %63, i32* %6
%64 = load i32, i32* %6
%65 = icmp eq i32 %64, -1
br i1 %65, label %66, label %68
66: ; preds = %60
%67 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %3
br label %144
68: ; preds = %60
%69 = getelementptr inbounds [50 x i8], [50 x i8]* %11, i64 0, i64 0
%70 = call i32 @inet_addr(i8* %69)
%71 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 2
%72 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %71, i32 0, i32 0
store i32 %70, i32* %72
%73 = load i32, i32* @AF_INET
%74 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 1
store i32 %73, i32* %74
%75 = load i32, i32* %7
%76 = call i32 @htons(i32 %75)
%77 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 0
store i32 %76, i32* %77
%78 = load i32, i32* %6
%79 = bitcast %struct.sockaddr_in* %9 to %struct.sockaddr*
%80 = call i64 @connect(i32 %78, %struct.sockaddr* %79, i32 12)
%81 = icmp slt i64 %80, 0
br i1 %81, label %82, label %84
82: ; preds = %68
%83 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0))
store i32 1, i32* %3
br label %144
84: ; preds = %68
%85 = getelementptr inbounds [50 x i8], [50 x i8]* %11, i64 0, i64 0
%86 = load i32, i32* %7
%87 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0), i8* %85, i32 %86)
br label %88
88: ; preds = %84, %140
%89 = call i32 @FD_ZERO(i32* %8)
%90 = load i32, i32* %6
%91 = call i32 @FD_SET(i32 %90, i32* %8)
%92 = call i32 @FD_SET(i32 0, i32* %8)
%93 = load i32, i32* %6
%94 = add nsw i32 %93, 1
%95 = call i32 @select(i32 %94, i32* %8, i32* null, i32* null, i32* null)
store i32 %95, i32* %14
%96 = load i32, i32* %14
%97 = icmp eq i32 %96, 0
br i1 %97, label %98, label %99
98: ; preds = %88
br label %141
99: ; preds = %88
%100 = load i32, i32* %14
%101 = icmp eq i32 %100, -1
br i1 %101, label %102, label %103
102: ; preds = %99
br label %141
103: ; preds = %99
%104 = call i64 @FD_ISSET(i32 0, i32* %8)
%105 = icmp ne i64 %104, 0
br i1 %105, label %106, label %124
106: ; preds = %103
%107 = getelementptr inbounds [512 x i8], [512 x i8]* %12, i64 0, i64 0
%108 = load i32, i32* @stdin
%109 = call i32* @fgets(i8* %107, i32 512, i32 %108)
%110 = icmp ne i32* %109, null
br i1 %110, label %111, label %123
111: ; preds = %106
%112 = load i32, i32* %6
%113 = getelementptr inbounds [512 x i8], [512 x i8]* %12, i64 0, i64 0
%114 = getelementptr inbounds [512 x i8], [512 x i8]* %12, i64 0, i64 0
%115 = call i32 @strlen(i8* %114)
%116 = call i64 @send(i32 %112, i8* %113, i32 %115, i32 0)
%117 = icmp slt i64 %116, 0
br i1 %117, label %118, label %120
118: ; preds = %111
%119 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0))
store i32 1, i32* %3
br label %144
120: ; preds = %111
%121 = getelementptr inbounds [512 x i8], [512 x i8]* %12, i64 0, i64 0
%122 = call i32 @bzero(i8* %121, i32 512)
br label %123
123: ; preds = %120, %106
br label %124
124: ; preds = %123, %103
%125 = load i32, i32* %6
%126 = call i64 @FD_ISSET(i32 %125, i32* %8)
%127 = icmp ne i64 %126, 0
br i1 %127, label %128, label %140
128: ; preds = %124
%129 = load i32, i32* %6
%130 = getelementptr inbounds [512 x i8], [512 x i8]* %13, i64 0, i64 0
%131 = call i64 @recv(i32 %129, i8* %130, i32 512, i32 0)
%132 = icmp slt i64 %131, 0
br i1 %132, label %133, label %135
133: ; preds = %128
%134 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.6, i64 0, i64 0))
store i32 1, i32* %3
br label %144
135: ; preds = %128
%136 = getelementptr inbounds [512 x i8], [512 x i8]* %13, i64 0, i64 0
%137 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i8* %136)
%138 = getelementptr inbounds [512 x i8], [512 x i8]* %13, i64 0, i64 0
%139 = call i32 @bzero(i8* %138, i32 512)
br label %140
140: ; preds = %135, %124
br label %88
141: ; preds = %102, %98
%142 = load i32, i32* %6
%143 = call i32 @close(i32 %142)
store i32 0, i32* %3
br label %144
144: ; preds = %141, %133, %118, %82, %66
%145 = load i32, i32* %3
ret i32 %145
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, i32, %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [10 x i8] c"127.0.0.1\00"
@.str.1 = [5 x i8] c"user\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.2 = [14 x i8] c"socket failed\00"
@.str.3 = [15 x i8] c"connect failed\00"
@.str.4 = [20 x i8] c"connected to %s:%d\0A\00"
@stdin = global i32 0
@.str.5 = [12 x i8] c"send failed\00"
@.str.6 = [12 x i8] c"recv failed\00"
@.str.7 = [3 x i8] c"%s\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca %struct.sockaddr_in
%5 = alloca [50 x i8]
%6 = alloca [50 x i8]
%7 = alloca [512 x i8]
%8 = alloca [512 x i8]
%9 = bitcast i32* %3 to i8*
%10 = bitcast %struct.sockaddr_in* %4 to i8*
%11 = getelementptr inbounds [50 x i8], [50 x i8]* %5, i64 0, i64 0
%12 = getelementptr inbounds [50 x i8], [50 x i8]* %6, i64 0, i64 0
%13 = getelementptr inbounds [512 x i8], [512 x i8]* %7, i64 0, i64 0
%14 = getelementptr inbounds [512 x i8], [512 x i8]* %8, i64 0, i64 0
%15 = call i32 @strcpy(i8* %12, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%16 = call i32 @strcpy(i8* %11, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%17 = icmp sgt i32 %0, 4
br i1 %17, label %18, label %28
18: ; preds = %2
%19 = getelementptr inbounds i8*, i8** %1, i64 1
%20 = load i8*, i8** %19
%21 = call i32 @strcpy(i8* %12, i8* %20)
%22 = getelementptr inbounds i8*, i8** %1, i64 2
%23 = load i8*, i8** %22
%24 = call i32 @atoi(i8* %23)
%25 = getelementptr inbounds i8*, i8** %1, i64 3
%26 = load i8*, i8** %25
%27 = call i32 @strcpy(i8* %11, i8* %26)
br label %43
28: ; preds = %2
%29 = icmp eq i32 %0, 4
br i1 %29, label %30, label %37
30: ; preds = %28
%31 = getelementptr inbounds i8*, i8** %1, i64 1
%32 = load i8*, i8** %31
%33 = call i32 @strcpy(i8* %12, i8* %32)
%34 = getelementptr inbounds i8*, i8** %1, i64 2
%35 = load i8*, i8** %34
%36 = call i32 @atoi(i8* %35)
br label %43
37: ; preds = %28
%38 = icmp sgt i32 %0, 2
br i1 %38, label %39, label %43
39: ; preds = %37
%40 = getelementptr inbounds i8*, i8** %1, i64 1
%41 = load i8*, i8** %40
%42 = call i32 @strcpy(i8* %12, i8* %41)
br label %43
43: ; preds = %30, %39, %37, %18
%44 = phi i32 [ %24, %18 ], [ %36, %30 ], [ 8080, %39 ], [ 8080, %37 ]
%45 = load i32, i32* @AF_INET
%46 = load i32, i32* @SOCK_STREAM
%47 = call i32 @socket(i32 %45, i32 %46, i32 0)
%48 = icmp eq i32 %47, -1
br i1 %48, label %49, label %51
49: ; preds = %43
%50 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
br label %100
51: ; preds = %43
%52 = call i32 @inet_addr(i8* %12)
%53 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 2, i32 0
store i32 %52, i32* %53
%54 = load i32, i32* @AF_INET
%55 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 1
store i32 %54, i32* %55
%56 = call i32 @htons(i32 %44)
%57 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 0
store i32 %56, i32* %57
%58 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%59 = call i64 @connect(i32 %47, %struct.sockaddr* %58, i32 12)
%60 = icmp slt i64 %59, 0
br i1 %60, label %61, label %63
61: ; preds = %51
%62 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0))
br label %100
63: ; preds = %51
%64 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0), i8* %12, i32 %44)
%65 = add nuw nsw i32 %47, 1
br label %66
66: ; preds = %89, %63
%67 = call i32 @FD_ZERO(i32* %3)
%68 = call i32 @FD_SET(i32 %47, i32* %3)
%69 = call i32 @FD_SET(i32 0, i32* %3)
%70 = call i32 @select(i32 %65, i32* %3, i32* null, i32* null, i32* null)
switch i32 %70, label %71 [
i32 0, label %98
i32 -1, label %98
]
71: ; preds = %66
%72 = call i64 @FD_ISSET(i32 0, i32* %3)
%73 = icmp eq i64 %72, 0
br i1 %73, label %86, label %74
74: ; preds = %71
%75 = load i32, i32* @stdin
%76 = call i32* @fgets(i8* %13, i32 512, i32 %75)
%77 = icmp eq i32* %76, null
br i1 %77, label %86, label %78
78: ; preds = %74
%79 = call i32 @strlen(i8* %13)
%80 = call i64 @send(i32 %47, i8* %13, i32 %79, i32 0)
%81 = icmp slt i64 %80, 0
br i1 %81, label %82, label %84
82: ; preds = %78
%83 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0))
br label %100
84: ; preds = %78
%85 = call i32 @bzero(i8* %13, i32 512)
br label %86
86: ; preds = %74, %84, %71
%87 = call i64 @FD_ISSET(i32 %47, i32* %3)
%88 = icmp eq i64 %87, 0
br i1 %88, label %89, label %90
89: ; preds = %86, %95
br label %66
90: ; preds = %86
%91 = call i64 @recv(i32 %47, i8* %14, i32 512, i32 0)
%92 = icmp slt i64 %91, 0
br i1 %92, label %93, label %95
93: ; preds = %90
%94 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.6, i64 0, i64 0))
br label %100
95: ; preds = %90
%96 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i8* %14)
%97 = call i32 @bzero(i8* %14, i32 512)
br label %89
98: ; preds = %66, %66
%99 = call i32 @close(i32 %47)
br label %100
100: ; preds = %93, %82, %98, %61, %49
%101 = phi i32 [ 1, %49 ], [ 1, %61 ], [ 0, %98 ], [ 1, %82 ], [ 1, %93 ]
ret i32 %101
}