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

/* Forward declarations */

/* Type definitions */
struct sockaddr_in {
  int /*<<< orphan*/ sin_addr;
  int /*<<< orphan*/ sin_port;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
struct in_addr {
  int dummy;
};
struct hostent {
  int dummy;
};
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*/ PF_INET;
int /*<<< orphan*/ SOCK_STREAM;
int STDIN_FILENO;
int /*<<< orphan*/ STDOUT_FILENO;
int /*<<< orphan*/ close(int);
int connect(int, struct sockaddr const *, int);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, ...);
int /*<<< orphan*/ htons(int);
int inet_aton(char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int recv(int, char *, int, int /*<<< orphan*/);
int select(int, int /*<<< orphan*/ *, int /*<<< orphan*/ *,
           int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ send(int, char *, int, int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int sscanf(char *, char *, int *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdin;
int strlen(char *);
int /*<<< orphan*/ write(int /*<<< orphan*/, char *, int);
int main(int argc, char *argv[]) {
  static char buffer[256];
  int sock_fd, err, length, port;
  struct sockaddr_in server_addr;
  fd_set input_fdset;
  struct hostent *host;
  struct in_addr *host_ip;
  if (argc != 3) {
    fprintf(stderr, "Usage: %s ip-addr port \n", argv[0]);
    return (1);
  }
  if (sscanf(argv[2], "%d", &port) != 1) {
    fprintf(stderr, "Usage: %s bad argument '%s'\n", argv[0], argv[2]);
    return (1);
  }
  sock_fd = socket(PF_INET, SOCK_STREAM, 0);
  if (sock_fd == -1) {
    perror("Connect: Can't create new socket");
    return (1);
  }
  server_addr.sin_family = AF_INET;
  server_addr.sin_port = htons(port);
  err = inet_aton(argv[1], &(server_addr.sin_addr));
  if (err = 0) {
    fprintf(stderr, "%s: Bad IP-Address '%s'\n", argv[0], argv[1]);
    return (1);
  }
  const struct sockaddr *to_cast = (struct sockaddr *)&server_addr;
  err = connect(sock_fd, to_cast, sizeof(struct sockaddr_in));
  if (err = -1) {
    perror("connect: connect() failed");
  }
  while (1) {
    FD_ZERO(&input_fdset);
    FD_SET(STDIN_FILENO, &input_fdset);
    FD_SET(sock_fd, &input_fdset);
    if (select(sock_fd + 1, &input_fdset, NULL, NULL, NULL) == -1) {
      perror("Connect: select() failed");
    }
    if (FD_ISSET(STDIN_FILENO, &input_fdset)) {
      if (fgets(buffer, 256, stdin) == NULL) {
        printf("%s: Closing socket.\n", argv[0]);
        break;
      }
      length = strlen(buffer);
      send(sock_fd, buffer, length, 0);
    } else {
      length = recv(sock_fd, buffer, 256, 0);
      if (length == 0) {
        printf("Conection closed by remote host.\n");
        break;
      }
      write(STDOUT_FILENO, buffer, length);
    }
  }
  close(sock_fd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     126a <main+0x4a>
mov    0x2d81(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xda9(%rip),%rsi
mov    $0x0,%al
call   10c0 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    14eb <main+0x2cb>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xda0(%rip),%rsi
lea    -0x20(%rbp),%rdx
call   1100 <sscanf@plt>
cmp    $0x1,%eax
je     12bd <main+0x9d>
mov    0x2d36(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rcx
lea    0xd72(%rip),%rsi
mov    $0x0,%al
call   10c0 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    14eb <main+0x2cb>
mov    0x2cf4(%rip),%rax
mov    (%rax),%edi
mov    0x2cf3(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1140 <socket@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    12fb <main+0xdb>
lea    0xd4f(%rip),%rdi
call   1110 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    14eb <main+0x2cb>
mov    0x2cde(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
mov    -0x20(%rbp),%edi
call   1070 <htons@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x30(%rbp),%rsi
call   10f0 <inet_aton@plt>
mov    %eax,-0x18(%rbp)
movl   $0x0,-0x18(%rbp)
xor    %eax,%eax
test   $0x1,%al
jne    133c <main+0x11c>
jmp    136e <main+0x14e>
mov    0x2c85(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rcx
lea    0xcff(%rip),%rsi
mov    $0x0,%al
call   10c0 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    14eb <main+0x2cb>
lea    -0x30(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x14(%rbp),%edi
mov    -0x50(%rbp),%rsi
mov    $0xc,%edx
call   1120 <connect@plt>
mov    %eax,-0x18(%rbp)
movl   $0xffffffff,-0x18(%rbp)
mov    $0x1,%al
test   $0x1,%al
jne    13a0 <main+0x180>
jmp    13ac <main+0x18c>
lea    0xccc(%rip),%rdi
call   1110 <perror@plt>
jmp    13b1 <main+0x191>
lea    -0x34(%rbp),%rdi
call   10d0 <FD_ZERO@plt>
mov    0x2bef(%rip),%rax
mov    (%rax),%edi
lea    -0x34(%rbp),%rsi
call   1130 <FD_SET@plt>
mov    -0x14(%rbp),%edi
lea    -0x34(%rbp),%rsi
call   1130 <FD_SET@plt>
mov    -0x14(%rbp),%edi
add    $0x1,%edi
lea    -0x34(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%r8d
mov    %r8,%rdx
mov    %r8,%rcx
call   10e0 <select@plt>
cmp    $0xffffffff,%eax
jne    1407 <main+0x1e7>
lea    0xc8b(%rip),%rdi
call   1110 <perror@plt>
mov    0x2ba2(%rip),%rax
mov    (%rax),%edi
lea    -0x34(%rbp),%rsi
call   1050 <FD_ISSET@plt>
cmp    $0x0,%rax
je     1489 <main+0x269>
mov    0x2bae(%rip),%rax
mov    (%rax),%edx
lea    0x2c8d(%rip),%rdi
mov    $0x100,%esi
call   10b0 <fgets@plt>
cmp    $0x0,%rax
jne    1461 <main+0x241>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xc51(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
jmp    14dc <main+0x2bc>
lea    0x2c58(%rip),%rdi
call   1060 <strlen@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x14(%rbp),%edi
mov    -0x1c(%rbp),%edx
lea    0x2c43(%rip),%rsi
xor    %ecx,%ecx
call   1080 <send@plt>
jmp    14d7 <main+0x2b7>
mov    -0x14(%rbp),%edi
lea    0x2c2d(%rip),%rsi
mov    $0x100,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jne    14bf <main+0x29f>
lea    0xc08(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
jmp    14dc <main+0x2bc>
mov    0x2b2a(%rip),%rax
mov    (%rax),%edi
mov    -0x1c(%rbp),%edx
lea    0x2bee(%rip),%rsi
call   1040 <write@plt>
jmp    13b1 <main+0x191>
mov    -0x14(%rbp),%edi
call   10a0 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rbx
cmp    $0x3,%edi
jne    1280 <main+0x50>
mov    0x10(%rbx),%rdi
lea    0xdc8(%rip),%rsi
lea    0x4(%rsp),%rdx
call   1110 <sscanf@plt>
cmp    $0x1,%eax
je     12ae <main+0x7e>
mov    0x2d61(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
mov    0x10(%rbx),%rcx
lea    0xda5(%rip),%rsi
xor    %eax,%eax
call   10d0 <fprintf@plt>
jmp    129a <main+0x6a>
mov    0x2d41(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xd6d(%rip),%rsi
xor    %eax,%eax
call   10d0 <fprintf@plt>
mov    $0x1,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d03(%rip),%rax
mov    (%rax),%edi
mov    0x2d02(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1150 <socket@plt>
cmp    $0xffffffff,%eax
jne    12da <main+0xaa>
lea    0xd66(%rip),%rdi
call   1120 <perror@plt>
jmp    129a <main+0x6a>
mov    %eax,%r15d
mov    0x2cfc(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x10(%rsp)
mov    0x4(%rsp),%edi
call   1080 <htons@plt>
mov    %eax,0xc(%rsp)
mov    0x8(%rbx),%rdi
lea    0x8(%rsp),%rbp
mov    %rbp,%rsi
call   1100 <inet_aton@plt>
mov    %r15d,%edi
mov    %rbp,%rsi
mov    $0xc,%edx
call   1130 <connect@plt>
lea    0xd3b(%rip),%rdi
call   1120 <perror@plt>
mov    %r15d,%r14d
add    $0x1,%r14d
lea    0x14(%rsp),%rbp
mov    0x2c79(%rip),%r12
lea    0x2d92(%rip),%r13
xchg   %ax,%ax
mov    %rbp,%rdi
call   10e0 <FD_ZERO@plt>
mov    (%r12),%edi
mov    %rbp,%rsi
call   1140 <FD_SET@plt>
mov    %r15d,%edi
mov    %rbp,%rsi
call   1140 <FD_SET@plt>
mov    %r14d,%edi
mov    %rbp,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   10f0 <select@plt>
cmp    $0xffffffff,%eax
je     13e9 <main+0x1b9>
mov    (%r12),%edi
mov    %rbp,%rsi
call   1060 <FD_ISSET@plt>
test   %rax,%rax
je     13bb <main+0x18b>
mov    0x2c4a(%rip),%rax
mov    (%rax),%edx
mov    %r13,%rdi
mov    $0x100,%esi
call   10c0 <fgets@plt>
test   %rax,%rax
je     13fa <main+0x1ca>
mov    %r13,%rdi
call   1070 <strlen@plt>
mov    %r15d,%edi
mov    %r13,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1090 <send@plt>
jmp    1340 <main+0x110>
mov    %r15d,%edi
mov    %r13,%rsi
mov    $0x100,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
test   %eax,%eax
je     140d <main+0x1dd>
mov    0x2c18(%rip),%rcx
mov    (%rcx),%edi
mov    %r13,%rsi
mov    %eax,%edx
call   1050 <write@plt>
jmp    1340 <main+0x110>
lea    0xc84(%rip),%rdi
call   1120 <perror@plt>
jmp    1376 <main+0x146>
mov    (%rbx),%rsi
lea    0xc89(%rip),%rdi
xor    %eax,%eax
call   10a0 <printf@plt>
jmp    1419 <main+0x1e9>
lea    0xc8e(%rip),%rdi
call   1040 <puts@plt>
mov    %r15d,%edi
call   10b0 <close@plt>
xor    %eax,%eax
jmp    129f <main+0x6f>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.hostent = type { i32 }
%struct.in_addr = type { i32 }
%struct.sockaddr = type { i32 }
@main.buffer = internal global [256 x i8] zeroinitializer
@stderr = global i32 0
@.str = [25 x i8] c"Usage: %s ip-addr port \0A\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [29 x i8] c"Usage: %s bad argument '%s'\0A\00"
@PF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.3 = [33 x i8] c"Connect: Can't create new socket\00"
@AF_INET = global i32 0
@.str.4 = [25 x i8] c"%s: Bad IP-Address '%s'\0A\00"
@.str.5 = [26 x i8] c"connect: connect() failed\00"
@STDIN_FILENO = global i32 0
@.str.6 = [25 x i8] c"Connect: select() failed\00"
@stdin = global i32 0
@.str.7 = [21 x i8] c"%s: Closing socket.\0A\00"
@.str.8 = [34 x i8] c"Conection closed by remote host.\0A\00"
@STDOUT_FILENO = global i32 0
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 i32
%10 = alloca %struct.sockaddr_in
%11 = alloca i32
%12 = alloca %struct.hostent*
%13 = alloca %struct.in_addr*
%14 = alloca %struct.sockaddr*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%15 = load i32, i32* %4
%16 = icmp ne i32 %15, 3
br i1 %16, label %17, label %23
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 (i32, i8*, i8*, ...) @fprintf(i32 %18, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %21)
store i32 1, i32* %3
br label %119
23: ; preds = %2
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 2
%26 = load i8*, i8** %25
%27 = call i32 @sscanf(i8* %26, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %9)
%28 = icmp ne i32 %27, 1
br i1 %28, label %29, label %38
29: ; preds = %23
%30 = load i32, i32* @stderr
%31 = load i8**, i8*** %5
%32 = getelementptr inbounds i8*, i8** %31, i64 0
%33 = load i8*, i8** %32
%34 = load i8**, i8*** %5
%35 = getelementptr inbounds i8*, i8** %34, i64 2
%36 = load i8*, i8** %35
%37 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %30, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0), i8* %33, i8* %36)
store i32 1, i32* %3
br label %119
38: ; preds = %23
%39 = load i32, i32* @PF_INET
%40 = load i32, i32* @SOCK_STREAM
%41 = call i32 @socket(i32 %39, i32 %40, i32 0)
store i32 %41, i32* %6
%42 = load i32, i32* %6
%43 = icmp eq i32 %42, -1
br i1 %43, label %44, label %46
44: ; preds = %38
%45 = call i32 @perror(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0))
store i32 1, i32* %3
br label %119
46: ; preds = %38
%47 = load i32, i32* @AF_INET
%48 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 2
store i32 %47, i32* %48
%49 = load i32, i32* %9
%50 = call i32 @htons(i32 %49)
%51 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 1
store i32 %50, i32* %51
%52 = load i8**, i8*** %5
%53 = getelementptr inbounds i8*, i8** %52, i64 1
%54 = load i8*, i8** %53
%55 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 0
%56 = call i32 @inet_aton(i8* %54, i32* %55)
store i32 %56, i32* %7
store i32 0, i32* %7
br i1 false, label %57, label %66
57: ; preds = %46
%58 = load i32, i32* @stderr
%59 = load i8**, i8*** %5
%60 = getelementptr inbounds i8*, i8** %59, i64 0
%61 = load i8*, i8** %60
%62 = load i8**, i8*** %5
%63 = getelementptr inbounds i8*, i8** %62, i64 1
%64 = load i8*, i8** %63
%65 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %58, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0), i8* %61, i8* %64)
store i32 1, i32* %3
br label %119
66: ; preds = %46
%67 = bitcast %struct.sockaddr_in* %10 to %struct.sockaddr*
store %struct.sockaddr* %67, %struct.sockaddr** %14
%68 = load i32, i32* %6
%69 = load %struct.sockaddr*, %struct.sockaddr** %14
%70 = call i32 @connect(i32 %68, %struct.sockaddr* %69, i32 12)
store i32 %70, i32* %7
store i32 -1, i32* %7
br i1 true, label %71, label %73
71: ; preds = %66
%72 = call i32 @perror(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.5, i64 0, i64 0))
br label %73
73: ; preds = %71, %66
br label %74
74: ; preds = %73, %115
%75 = call i32 @FD_ZERO(i32* %11)
%76 = load i32, i32* @STDIN_FILENO
%77 = call i32 @FD_SET(i32 %76, i32* %11)
%78 = load i32, i32* %6
%79 = call i32 @FD_SET(i32 %78, i32* %11)
%80 = load i32, i32* %6
%81 = add nsw i32 %80, 1
%82 = call i32 @select(i32 %81, i32* %11, i32* null, i32* null, i32* null)
%83 = icmp eq i32 %82, -1
br i1 %83, label %84, label %86
84: ; preds = %74
%85 = call i32 @perror(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.6, i64 0, i64 0))
br label %86
86: ; preds = %84, %74
%87 = load i32, i32* @STDIN_FILENO
%88 = call i64 @FD_ISSET(i32 %87, i32* %11)
%89 = icmp ne i64 %88, 0
br i1 %89, label %90, label %104
90: ; preds = %86
%91 = load i32, i32* @stdin
%92 = call i32* @fgets(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @main.buffer, i64 0, i64 0), i32 256, i32 %91)
%93 = icmp eq i32* %92, null
br i1 %93, label %94, label %99
94: ; preds = %90
%95 = load i8**, i8*** %5
%96 = getelementptr inbounds i8*, i8** %95, i64 0
%97 = load i8*, i8** %96
%98 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.7, i64 0, i64 0), i8* %97)
br label %116
99: ; preds = %90
%100 = call i32 @strlen(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @main.buffer, i64 0, i64 0))
store i32 %100, i32* %8
%101 = load i32, i32* %6
%102 = load i32, i32* %8
%103 = call i32 @send(i32 %101, i8* getelementptr inbounds ([256 x i8], [256 x i8]* @main.buffer, i64 0, i64 0), i32 %102, i32 0)
br label %115
104: ; preds = %86
%105 = load i32, i32* %6
%106 = call i32 @recv(i32 %105, i8* getelementptr inbounds ([256 x i8], [256 x i8]* @main.buffer, i64 0, i64 0), i32 256, i32 0)
store i32 %106, i32* %8
%107 = load i32, i32* %8
%108 = icmp eq i32 %107, 0
br i1 %108, label %109, label %111
109: ; preds = %104
%110 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.8, i64 0, i64 0))
br label %116
111: ; preds = %104
%112 = load i32, i32* @STDOUT_FILENO
%113 = load i32, i32* %8
%114 = call i32 @write(i32 %112, i8* getelementptr inbounds ([256 x i8], [256 x i8]* @main.buffer, i64 0, i64 0), i32 %113)
br label %115
115: ; preds = %111, %99
br label %74
116: ; preds = %109, %94
%117 = load i32, i32* %6
%118 = call i32 @close(i32 %117)
store i32 0, i32* %3
br label %119
119: ; preds = %116, %57, %44, %29, %17
%120 = load i32, i32* %3
ret i32 %120
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.hostent = type { i32 }
%struct.in_addr = type { i32 }
%struct.sockaddr = type { i32 }
@main.buffer = internal global [256 x i8] zeroinitializer
@stderr = global i32 0
@.str = [25 x i8] c"Usage: %s ip-addr port \0A\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [29 x i8] c"Usage: %s bad argument '%s'\0A\00"
@PF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.3 = [33 x i8] c"Connect: Can't create new socket\00"
@AF_INET = global i32 0
@.str.5 = [26 x i8] c"connect: connect() failed\00"
@STDIN_FILENO = global i32 0
@.str.6 = [25 x i8] c"Connect: select() failed\00"
@stdin = global i32 0
@.str.7 = [21 x i8] c"%s: Closing socket.\0A\00"
@STDOUT_FILENO = global i32 0
@str = [33 x i8] c"Conection closed by remote host.\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca %struct.sockaddr_in
%5 = alloca i32
%6 = bitcast i32* %3 to i8*
%7 = bitcast %struct.sockaddr_in* %4 to i8*
%8 = bitcast i32* %5 to i8*
%9 = icmp eq i32 %0, 3
br i1 %9, label %14, label %10
10: ; preds = %2
%11 = load i32, i32* @stderr
%12 = load i8*, i8** %1
%13 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %11, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %12)
br label %79
14: ; preds = %2
%15 = getelementptr inbounds i8*, i8** %1, i64 2
%16 = load i8*, i8** %15
%17 = call i32 @sscanf(i8* %16, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %3)
%18 = icmp eq i32 %17, 1
br i1 %18, label %24, label %19
19: ; preds = %14
%20 = load i32, i32* @stderr
%21 = load i8*, i8** %1
%22 = load i8*, i8** %15
%23 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %20, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0), i8* %21, i8* %22)
br label %79
24: ; preds = %14
%25 = load i32, i32* @PF_INET
%26 = load i32, i32* @SOCK_STREAM
%27 = call i32 @socket(i32 %25, i32 %26, i32 0)
%28 = icmp eq i32 %27, -1
br i1 %28, label %29, label %31
29: ; preds = %24
%30 = call i32 @perror(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0))
br label %79
31: ; preds = %24
%32 = load i32, i32* @AF_INET
%33 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 2
store i32 %32, i32* %33
%34 = load i32, i32* %3
%35 = call i32 @htons(i32 %34)
%36 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 1
store i32 %35, i32* %36
%37 = getelementptr inbounds i8*, i8** %1, i64 1
%38 = load i8*, i8** %37
%39 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 0
%40 = call i32 @inet_aton(i8* %38, i32* %39)
%41 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%42 = call i32 @connect(i32 %27, %struct.sockaddr* %41, i32 12)
%43 = call i32 @perror(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.5, i64 0, i64 0))
%44 = add nuw nsw i32 %27, 1
br label %45
45: ; preds = %76, %31
%46 = call i32 @FD_ZERO(i32* %5)
%47 = load i32, i32* @STDIN_FILENO
%48 = call i32 @FD_SET(i32 %47, i32* %5)
%49 = call i32 @FD_SET(i32 %27, i32* %5)
%50 = call i32 @select(i32 %44, i32* %5, i32* null, i32* null, i32* null)
%51 = icmp eq i32 %50, -1
br i1 %51, label %52, label %54
52: ; preds = %45
%53 = call i32 @perror(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.6, i64 0, i64 0))
br label %54
54: ; preds = %52, %45
%55 = load i32, i32* @STDIN_FILENO
%56 = call i64 @FD_ISSET(i32 %55, i32* %5)
%57 = icmp eq i64 %56, 0
br i1 %57, label %68, label %58
58: ; preds = %54
%59 = load i32, i32* @stdin
%60 = call i32* @fgets(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @main.buffer, i64 0, i64 0), i32 256, i32 %59)
%61 = icmp eq i32* %60, null
br i1 %61, label %62, label %65
62: ; preds = %58
%63 = load i8*, i8** %1
%64 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.7, i64 0, i64 0), i8* %63)
br label %77
65: ; preds = %58
%66 = call i32 @strlen(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @main.buffer, i64 0, i64 0))
%67 = call i32 @send(i32 %27, i8* getelementptr inbounds ([256 x i8], [256 x i8]* @main.buffer, i64 0, i64 0), i32 %66, i32 0)
br label %76
68: ; preds = %54
%69 = call i32 @recv(i32 %27, i8* getelementptr inbounds ([256 x i8], [256 x i8]* @main.buffer, i64 0, i64 0), i32 256, i32 0)
%70 = icmp eq i32 %69, 0
br i1 %70, label %71, label %73
71: ; preds = %68
%72 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @str, i64 0, i64 0))
br label %77
73: ; preds = %68
%74 = load i32, i32* @STDOUT_FILENO
%75 = call i32 @write(i32 %74, i8* getelementptr inbounds ([256 x i8], [256 x i8]* @main.buffer, i64 0, i64 0), i32 %69)
br label %76
76: ; preds = %73, %65
br label %45
77: ; preds = %71, %62
%78 = call i32 @close(i32 %27)
br label %79
79: ; preds = %77, %29, %19, %10
%80 = phi i32 [ 1, %10 ], [ 1, %19 ], [ 1, %29 ], [ 0, %77 ]
ret i32 %80
}