#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 pollfd {
  int fd;
  int events;
  int revents;
};
struct hostent {
  int /*<<< orphan*/ h_length;
  int /*<<< orphan*/ *h_addr_list;
};
typedef int /*<<< orphan*/ servaddr;
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int ERR;
int POLLIN;
int /*<<< orphan*/ SOCK_STREAM;
int STDIN_FILENO;
int /*<<< orphan*/ addch(int);
int /*<<< orphan*/ atoi(char *);
int /*<<< orphan*/ cbreak();
scalar_t__ connect(int, struct sockaddr *, int);
int getch();
struct hostent *gethostbyname(char *);
int /*<<< orphan*/ htons(int /*<<< orphan*/);
int /*<<< orphan*/ initscr();
int /*<<< orphan*/ memcpy(int /*<<< orphan*/ *, int /*<<< orphan*/,
                          int /*<<< orphan*/);
int /*<<< orphan*/ memset(struct sockaddr_in *, int /*<<< orphan*/, int);
int /*<<< orphan*/ noecho();
int /*<<< orphan*/ perror(char *);
int poll(struct pollfd *, int, int);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ printw(char *, char *);
int read(int, char *, int);
int /*<<< orphan*/ refresh();
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ timeout(int /*<<< orphan*/);
int /*<<< orphan*/ write(int, int *, int);
int main(int argc, char **argv) {
  if (argc < 3) {
    printf("Usage: %s host port\n", argv[0]);
    return 1;
  }
  int sock = socket(AF_INET, SOCK_STREAM, 0);
  if (sock < 0) {
    perror("socket");
    return 2;
  }
  struct sockaddr_in servaddr;
  memset(&servaddr, 0, sizeof(servaddr));
  servaddr.sin_family = AF_INET;
  servaddr.sin_port = htons(atoi(argv[2]));
  struct hostent *host = gethostbyname(argv[1]);
  if (!host) {
    perror("gethostbyname");
    return 3;
  }
  memcpy(&servaddr.sin_addr, host->h_addr_list[0], host->h_length);
  if (connect(sock, (struct sockaddr *)&servaddr, sizeof(servaddr))) {
    perror("connect");
    return 4;
  }
  initscr();
  cbreak();
  noecho();
  timeout(0);
  printw("%s\n", "Ember client!");
  while (1) {
    struct pollfd pfds[2];
    pfds[0].fd = sock;
    pfds[0].events = POLLIN;
    pfds[1].fd = STDIN_FILENO;
    pfds[1].events = POLLIN;
    int res = poll(pfds, 2, 1000);
    if (res > 0) {
      if (pfds[1].revents & POLLIN) {
        int c;
        while ((c = getch()) != ERR) {
          write(sock, &c, 1);
          if (c == '\n') {
            addch('\n');
            addch('\r');
          } else {
            addch(c);
          }
          refresh();
        }
      }
      if (pfds[0].revents & POLLIN) {
        char buf[1024];
        int r = read(sock, buf, sizeof(buf) - 1);
        if (r > 0) {
          buf[r] = 0;
          printw("%s", buf);
          refresh();
        }
      }
    }
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x460,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    1282 <main+0x42>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xd8f(%rip),%rdi
call   1060 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    14e0 <main+0x2a0>
mov    0x2d5f(%rip),%rax
mov    (%rax),%edi
mov    0x2d36(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1160 <socket@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    12c0 <main+0x80>
lea    0xd66(%rip),%rdi
call   1120 <perror@plt>
movl   $0x2,-0x4(%rbp)
jmp    14e0 <main+0x2a0>
lea    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1090 <memset@plt>
mov    0x2d11(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1140 <atoi@plt>
mov    %eax,%edi
call   1050 <htons@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10b0 <gethostbyname@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1327 <main+0xe7>
lea    0xd06(%rip),%rdi
call   1120 <perror@plt>
movl   $0x3,-0x4(%rbp)
jmp    14e0 <main+0x2a0>
lea    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rax
mov    0x8(%rax),%rax
mov    (%rax),%esi
mov    -0x28(%rbp),%rax
mov    (%rax),%edx
call   10c0 <memcpy@plt>
mov    -0x14(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0xc,%edx
call   1150 <connect@plt>
cmp    $0x0,%rax
je     1373 <main+0x133>
lea    0xcc8(%rip),%rdi
call   1120 <perror@plt>
movl   $0x4,-0x4(%rbp)
jmp    14e0 <main+0x2a0>
mov    $0x0,%al
call   1070 <initscr@plt>
mov    $0x0,%al
call   1030 <cbreak@plt>
mov    $0x0,%al
call   1130 <noecho@plt>
xor    %edi,%edi
call   1080 <timeout@plt>
lea    0xc9c(%rip),%rdi
lea    0xc99(%rip),%rsi
call   10d0 <printw@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x40(%rbp)
mov    0x2c29(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x3c(%rbp)
mov    0x2c05(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
mov    0x2c11(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x30(%rbp)
lea    -0x40(%rbp),%rdi
mov    $0x2,%esi
mov    $0x3e8,%edx
call   1100 <poll@plt>
mov    %eax,-0x44(%rbp)
cmpl   $0x0,-0x44(%rbp)
jle    14db <main+0x29b>
mov    -0x2c(%rbp),%eax
mov    0x2be2(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     146c <main+0x22c>
jmp    1406 <main+0x1c6>
mov    $0x0,%al
call   1110 <getch@plt>
mov    %eax,-0x48(%rbp)
mov    0x2bc9(%rip),%rcx
cmp    (%rcx),%eax
je     1467 <main+0x227>
mov    -0x14(%rbp),%edi
lea    -0x48(%rbp),%rsi
mov    $0x1,%edx
call   1040 <write@plt>
cmpl   $0xa,-0x48(%rbp)
jne    1453 <main+0x213>
mov    $0xa,%edi
call   10e0 <addch@plt>
mov    $0xd,%edi
call   10e0 <addch@plt>
jmp    145b <main+0x21b>
mov    -0x48(%rbp),%edi
call   10e0 <addch@plt>
mov    $0x0,%al
call   10f0 <refresh@plt>
jmp    1406 <main+0x1c6>
jmp    146c <main+0x22c>
mov    -0x38(%rbp),%eax
mov    0x2b62(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     14d6 <main+0x296>
mov    -0x14(%rbp),%edi
lea    -0x450(%rbp),%rsi
mov    $0x3ff,%edx
call   10a0 <read@plt>
mov    %eax,-0x454(%rbp)
cmpl   $0x0,-0x454(%rbp)
jle    14d1 <main+0x291>
movslq -0x454(%rbp),%rax
movb   $0x0,-0x450(%rbp,%rax,1)
lea    -0x450(%rbp),%rsi
lea    0xb7f(%rip),%rdi
call   10d0 <printw@plt>
mov    $0x0,%al
call   10f0 <refresh@plt>
jmp    14d6 <main+0x296>
jmp    14db <main+0x29b>
jmp    13a2 <main+0x162>
mov    -0x4(%rbp),%eax
add    $0x460,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x438,%rsp
mov    %rsi,%r14
cmp    $0x2,%edi
jg     1281 <main+0x41>
mov    (%r14),%rsi
lea    0xd9d(%rip),%rdi
call   1060 <printf@plt>
mov    $0x1,%ebx
mov    %ebx,%eax
add    $0x438,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d60(%rip),%rbp
mov    0x0(%rbp),%edi
mov    0x2d36(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1160 <socket@plt>
test   %eax,%eax
js     1436 <main+0x1f6>
mov    %eax,%ebx
mov    %rsp,%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1090 <memset@plt>
mov    0x0(%rbp),%eax
mov    %eax,0x8(%rsp)
mov    0x10(%r14),%rdi
call   1140 <atoi@plt>
mov    %eax,%edi
call   1050 <htons@plt>
mov    %eax,0x4(%rsp)
mov    0x8(%r14),%rdi
call   10b0 <gethostbyname@plt>
test   %rax,%rax
je     144c <main+0x20c>
mov    0x8(%rax),%rcx
mov    (%rcx),%esi
mov    (%rax),%edx
mov    %rsp,%rbp
mov    %rbp,%rdi
call   10c0 <memcpy@plt>
mov    %ebx,%edi
mov    %rbp,%rsi
mov    $0xc,%edx
call   1150 <connect@plt>
test   %rax,%rax
jne    145a <main+0x21a>
xor    %eax,%eax
call   1070 <initscr@plt>
xor    %eax,%eax
call   1030 <cbreak@plt>
xor    %eax,%eax
call   1130 <noecho@plt>
xor    %edi,%edi
call   1080 <timeout@plt>
lea    0xd03(%rip),%rdi
lea    0xd00(%rip),%rsi
call   10d0 <printw@plt>
mov    0x2c96(%rip),%rbp
mov    0x2c77(%rip),%r14
lea    0x10(%rsp),%r13
lea    0x30(%rsp),%r15
mov    0x2c86(%rip),%r12
nopw   0x0(%rax,%rax,1)
mov    %ebx,0x10(%rsp)
mov    0x0(%rbp),%eax
mov    %eax,0x14(%rsp)
mov    (%r14),%ecx
mov    %ecx,0x1c(%rsp)
mov    %eax,0x20(%rsp)
mov    %r13,%rdi
mov    $0x2,%esi
mov    $0x3e8,%edx
call   1100 <poll@plt>
test   %eax,%eax
jle    1360 <main+0x120>
mov    0x0(%rbp),%eax
test   %eax,0x24(%rsp)
je     13b0 <main+0x170>
xor    %eax,%eax
call   1110 <getch@plt>
mov    %eax,0x30(%rsp)
cmp    (%r12),%eax
jne    13eb <main+0x1ab>
mov    0x2c2b(%rip),%rbp
mov    0x0(%rbp),%eax
test   %eax,0x18(%rsp)
je     1360 <main+0x120>
mov    %ebx,%edi
mov    %r15,%rsi
mov    $0x3ff,%edx
call   10a0 <read@plt>
test   %eax,%eax
jle    1360 <main+0x120>
mov    %eax,%eax
movb   $0x0,0x30(%rsp,%rax,1)
lea    0xc6d(%rip),%rdi
mov    %r15,%rsi
call   10d0 <printw@plt>
xor    %eax,%eax
call   10f0 <refresh@plt>
jmp    1360 <main+0x120>
mov    %eax,%ebp
jmp    1411 <main+0x1d1>
nop
mov    %ebp,%edi
call   10e0 <addch@plt>
xor    %eax,%eax
call   10f0 <refresh@plt>
xor    %eax,%eax
call   1110 <getch@plt>
mov    %eax,%ebp
mov    %eax,0x30(%rsp)
cmp    (%r12),%eax
je     13a6 <main+0x166>
mov    %ebx,%edi
mov    %r15,%rsi
mov    $0x1,%edx
call   1040 <write@plt>
cmp    $0xa,%ebp
jne    13f0 <main+0x1b0>
mov    $0xa,%edi
call   10e0 <addch@plt>
mov    $0xd,%ebp
jmp    13f0 <main+0x1b0>
lea    0xbd8(%rip),%rdi
call   1120 <perror@plt>
mov    $0x2,%ebx
jmp    126d <main+0x2d>
mov    $0x3,%ebx
lea    0xbc4(%rip),%rdi
jmp    1466 <main+0x226>
mov    $0x4,%ebx
lea    0xbc4(%rip),%rdi
call   1120 <perror@plt>
jmp    126d <main+0x2d>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.hostent = type { i32, i32* }
%struct.pollfd = type { i32, i32, i32 }
%struct.sockaddr = type { i32 }
@.str = [21 x i8] c"Usage: %s host port\0A\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.1 = [7 x i8] c"socket\00"
@.str.2 = [14 x i8] c"gethostbyname\00"
@.str.3 = [8 x i8] c"connect\00"
@.str.4 = [4 x i8] c"%s\0A\00"
@.str.5 = [14 x i8] c"Ember client!\00"
@POLLIN = global i32 0
@STDIN_FILENO = global i32 0
@ERR = global i32 0
@.str.6 = [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 %struct.sockaddr_in
%8 = alloca %struct.hostent*
%9 = alloca [2 x %struct.pollfd]
%10 = alloca i32
%11 = alloca i32
%12 = alloca [1024 x i8]
%13 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%14 = load i32, i32* %4
%15 = icmp slt i32 %14, 3
br i1 %15, label %16, label %21
16: ; preds = %2
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 0
%19 = load i8*, i8** %18
%20 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %19)
store i32 1, i32* %3
br label %136
21: ; preds = %2
%22 = load i32, i32* @AF_INET
%23 = load i32, i32* @SOCK_STREAM
%24 = call i32 @socket(i32 %22, i32 %23, i32 0)
store i32 %24, i32* %6
%25 = load i32, i32* %6
%26 = icmp slt i32 %25, 0
br i1 %26, label %27, label %29
27: ; preds = %21
%28 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
store i32 2, i32* %3
br label %136
29: ; preds = %21
%30 = call i32 @memset(%struct.sockaddr_in* %7, i32 0, i32 12)
%31 = load i32, i32* @AF_INET
%32 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 2
store i32 %31, i32* %32
%33 = load i8**, i8*** %5
%34 = getelementptr inbounds i8*, i8** %33, i64 2
%35 = load i8*, i8** %34
%36 = call i32 @atoi(i8* %35)
%37 = call i32 @htons(i32 %36)
%38 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 1
store i32 %37, i32* %38
%39 = load i8**, i8*** %5
%40 = getelementptr inbounds i8*, i8** %39, i64 1
%41 = load i8*, i8** %40
%42 = call %struct.hostent* @gethostbyname(i8* %41)
store %struct.hostent* %42, %struct.hostent** %8
%43 = load %struct.hostent*, %struct.hostent** %8
%44 = icmp ne %struct.hostent* %43, null
br i1 %44, label %47, label %45
45: ; preds = %29
%46 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
store i32 3, i32* %3
br label %136
47: ; preds = %29
%48 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 0
%49 = load %struct.hostent*, %struct.hostent** %8
%50 = getelementptr inbounds %struct.hostent, %struct.hostent* %49, i32 0, i32 1
%51 = load i32*, i32** %50
%52 = getelementptr inbounds i32, i32* %51, i64 0
%53 = load i32, i32* %52
%54 = load %struct.hostent*, %struct.hostent** %8
%55 = getelementptr inbounds %struct.hostent, %struct.hostent* %54, i32 0, i32 0
%56 = load i32, i32* %55
%57 = call i32 @memcpy(i32* %48, i32 %53, i32 %56)
%58 = load i32, i32* %6
%59 = bitcast %struct.sockaddr_in* %7 to %struct.sockaddr*
%60 = call i64 @connect(i32 %58, %struct.sockaddr* %59, i32 12)
%61 = icmp ne i64 %60, 0
br i1 %61, label %62, label %64
62: ; preds = %47
%63 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
store i32 4, i32* %3
br label %136
64: ; preds = %47
%65 = call i32 (...) @initscr()
%66 = call i32 (...) @cbreak()
%67 = call i32 (...) @noecho()
%68 = call i32 @timeout(i32 0)
%69 = call i32 @printw(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0))
br label %70
70: ; preds = %64, %135
%71 = load i32, i32* %6
%72 = getelementptr inbounds [2 x %struct.pollfd], [2 x %struct.pollfd]* %9, i64 0, i64 0
%73 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %72, i32 0, i32 0
store i32 %71, i32* %73
%74 = load i32, i32* @POLLIN
%75 = getelementptr inbounds [2 x %struct.pollfd], [2 x %struct.pollfd]* %9, i64 0, i64 0
%76 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %75, i32 0, i32 1
store i32 %74, i32* %76
%77 = load i32, i32* @STDIN_FILENO
%78 = getelementptr inbounds [2 x %struct.pollfd], [2 x %struct.pollfd]* %9, i64 0, i64 1
%79 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %78, i32 0, i32 0
store i32 %77, i32* %79
%80 = load i32, i32* @POLLIN
%81 = getelementptr inbounds [2 x %struct.pollfd], [2 x %struct.pollfd]* %9, i64 0, i64 1
%82 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %81, i32 0, i32 1
store i32 %80, i32* %82
%83 = getelementptr inbounds [2 x %struct.pollfd], [2 x %struct.pollfd]* %9, i64 0, i64 0
%84 = call i32 @poll(%struct.pollfd* %83, i32 2, i32 1000)
store i32 %84, i32* %10
%85 = load i32, i32* %10
%86 = icmp sgt i32 %85, 0
br i1 %86, label %87, label %135
87: ; preds = %70
%88 = getelementptr inbounds [2 x %struct.pollfd], [2 x %struct.pollfd]* %9, i64 0, i64 1
%89 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %88, i32 0, i32 2
%90 = load i32, i32* %89
%91 = load i32, i32* @POLLIN
%92 = and i32 %90, %91
%93 = icmp ne i32 %92, 0
br i1 %93, label %94, label %113
94: ; preds = %87
br label %95
95: ; preds = %110, %94
%96 = call i32 (...) @getch()
store i32 %96, i32* %11
%97 = load i32, i32* @ERR
%98 = icmp ne i32 %96, %97
br i1 %98, label %99, label %112
99: ; preds = %95
%100 = load i32, i32* %6
%101 = call i32 @write(i32 %100, i32* %11, i32 1)
%102 = load i32, i32* %11
%103 = icmp eq i32 %102, 10
br i1 %103, label %104, label %107
104: ; preds = %99
%105 = call i32 @addch(i32 10)
%106 = call i32 @addch(i32 13)
br label %110
107: ; preds = %99
%108 = load i32, i32* %11
%109 = call i32 @addch(i32 %108)
br label %110
110: ; preds = %107, %104
%111 = call i32 (...) @refresh()
br label %95
112: ; preds = %95
br label %113
113: ; preds = %112, %87
%114 = getelementptr inbounds [2 x %struct.pollfd], [2 x %struct.pollfd]* %9, i64 0, i64 0
%115 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %114, i32 0, i32 2
%116 = load i32, i32* %115
%117 = load i32, i32* @POLLIN
%118 = and i32 %116, %117
%119 = icmp ne i32 %118, 0
br i1 %119, label %120, label %134
120: ; preds = %113
%121 = load i32, i32* %6
%122 = getelementptr inbounds [1024 x i8], [1024 x i8]* %12, i64 0, i64 0
%123 = call i32 @read(i32 %121, i8* %122, i32 1023)
store i32 %123, i32* %13
%124 = load i32, i32* %13
%125 = icmp sgt i32 %124, 0
br i1 %125, label %126, label %133
126: ; preds = %120
%127 = load i32, i32* %13
%128 = sext i32 %127 to i64
%129 = getelementptr inbounds [1024 x i8], [1024 x i8]* %12, i64 0, i64 %128
store i8 0, i8* %129
%130 = getelementptr inbounds [1024 x i8], [1024 x i8]* %12, i64 0, i64 0
%131 = call i32 @printw(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i8* %130)
%132 = call i32 (...) @refresh()
br label %133
133: ; preds = %126, %120
br label %134
134: ; preds = %133, %113
br label %135
135: ; preds = %134, %70
br label %70
136: ; preds = %62, %45, %27, %16
%137 = load i32, i32* %3
ret i32 %137
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.pollfd = type { i32, i32, i32 }
%struct.hostent = type { i32, i32* }
%struct.sockaddr = type { i32 }
@.str = [21 x i8] c"Usage: %s host port\0A\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.1 = [7 x i8] c"socket\00"
@.str.2 = [14 x i8] c"gethostbyname\00"
@.str.3 = [8 x i8] c"connect\00"
@.str.4 = [4 x i8] c"%s\0A\00"
@.str.5 = [14 x i8] c"Ember client!\00"
@POLLIN = global i32 0
@STDIN_FILENO = global i32 0
@ERR = global i32 0
@.str.6 = [3 x i8] c"%s\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca [2 x %struct.pollfd]
%5 = alloca i32
%6 = alloca [1024 x i8]
%7 = icmp slt i32 %0, 3
br i1 %7, label %8, label %11
8: ; preds = %2
%9 = load i8*, i8** %1
%10 = tail call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %9)
br label %107
11: ; preds = %2
%12 = load i32, i32* @AF_INET
%13 = load i32, i32* @SOCK_STREAM
%14 = tail call i32 @socket(i32 %12, i32 %13, i32 0)
%15 = icmp slt i32 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %11
%17 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
br label %107
18: ; preds = %11
%19 = bitcast %struct.sockaddr_in* %3 to i8*
%20 = call i32 @memset(%struct.sockaddr_in* %3, i32 0, i32 12)
%21 = load i32, i32* @AF_INET
%22 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %21, i32* %22
%23 = getelementptr inbounds i8*, i8** %1, i64 2
%24 = load i8*, i8** %23
%25 = call i32 @atoi(i8* %24)
%26 = call i32 @htons(i32 %25)
%27 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1
store i32 %26, i32* %27
%28 = getelementptr inbounds i8*, i8** %1, i64 1
%29 = load i8*, i8** %28
%30 = call %struct.hostent* @gethostbyname(i8* %29)
%31 = icmp eq %struct.hostent* %30, null
br i1 %31, label %103, label %32
32: ; preds = %18
%33 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
%34 = getelementptr inbounds %struct.hostent, %struct.hostent* %30, i64 0, i32 1
%35 = load i32*, i32** %34
%36 = load i32, i32* %35
%37 = getelementptr inbounds %struct.hostent, %struct.hostent* %30, i64 0, i32 0
%38 = load i32, i32* %37
%39 = call i32 @memcpy(i32* %33, i32 %36, i32 %38)
%40 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%41 = call i64 @connect(i32 %14, %struct.sockaddr* %40, i32 12)
%42 = icmp eq i64 %41, 0
br i1 %42, label %43, label %103
43: ; preds = %32
%44 = call i32 (...) @initscr()
%45 = call i32 (...) @cbreak()
%46 = call i32 (...) @noecho()
%47 = call i32 @timeout(i32 0)
%48 = call i32 @printw(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0))
%49 = bitcast [2 x %struct.pollfd]* %4 to i8*
%50 = getelementptr inbounds [2 x %struct.pollfd], [2 x %struct.pollfd]* %4, i64 0, i64 0
%51 = getelementptr inbounds [2 x %struct.pollfd], [2 x %struct.pollfd]* %4, i64 0, i64 0, i32 0
%52 = getelementptr inbounds [2 x %struct.pollfd], [2 x %struct.pollfd]* %4, i64 0, i64 0, i32 1
%53 = getelementptr inbounds [2 x %struct.pollfd], [2 x %struct.pollfd]* %4, i64 0, i64 1, i32 0
%54 = getelementptr inbounds [2 x %struct.pollfd], [2 x %struct.pollfd]* %4, i64 0, i64 1, i32 1
%55 = getelementptr inbounds [2 x %struct.pollfd], [2 x %struct.pollfd]* %4, i64 0, i64 1, i32 2
%56 = bitcast i32* %5 to i8*
%57 = getelementptr inbounds [2 x %struct.pollfd], [2 x %struct.pollfd]* %4, i64 0, i64 0, i32 2
%58 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
br label %59
59: ; preds = %102, %43
store i32 %14, i32* %51
%60 = load i32, i32* @POLLIN
store i32 %60, i32* %52
%61 = load i32, i32* @STDIN_FILENO
store i32 %61, i32* %53
store i32 %60, i32* %54
%62 = call i32 @poll(%struct.pollfd* %50, i32 2, i32 1000)
%63 = icmp sgt i32 %62, 0
br i1 %63, label %64, label %102
64: ; preds = %59
%65 = load i32, i32* %55
%66 = load i32, i32* @POLLIN
%67 = and i32 %66, %65
%68 = icmp eq i32 %67, 0
br i1 %68, label %88, label %69
69: ; preds = %64
%70 = call i32 (...) @getch()
store i32 %70, i32* %5
%71 = load i32, i32* @ERR
%72 = icmp eq i32 %70, %71
br i1 %72, label %86, label %73
73: ; preds = %69, %79
%74 = phi i32 [ %83, %79 ], [ %70, %69 ]
%75 = call i32 @write(i32 %14, i32* %5, i32 1)
%76 = icmp eq i32 %74, 10
br i1 %76, label %77, label %79
77: ; preds = %73
%78 = call i32 @addch(i32 10)
br label %79
79: ; preds = %73, %77
%80 = phi i32 [ 13, %77 ], [ %74, %73 ]
%81 = call i32 @addch(i32 %80)
%82 = call i32 (...) @refresh()
%83 = call i32 (...) @getch()
store i32 %83, i32* %5
%84 = load i32, i32* @ERR
%85 = icmp eq i32 %83, %84
br i1 %85, label %86, label %73
86: ; preds = %79, %69
%87 = load i32, i32* @POLLIN
br label %88
88: ; preds = %86, %64
%89 = phi i32 [ %87, %86 ], [ %66, %64 ]
%90 = load i32, i32* %57
%91 = and i32 %89, %90
%92 = icmp eq i32 %91, 0
br i1 %92, label %102, label %93
93: ; preds = %88
%94 = call i32 @read(i32 %14, i8* %58, i32 1023)
%95 = icmp sgt i32 %94, 0
br i1 %95, label %96, label %101
96: ; preds = %93
%97 = zext i32 %94 to i64
%98 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 %97
store i8 0, i8* %98
%99 = call i32 @printw(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i8* %58)
%100 = call i32 (...) @refresh()
br label %101
101: ; preds = %96, %93
br label %102
102: ; preds = %88, %101, %59
br label %59
103: ; preds = %32, %18
%104 = phi i8* [ getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), %18 ], [ getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), %32 ]
%105 = phi i32 [ 3, %18 ], [ 4, %32 ]
%106 = call i32 @perror(i8* %104)
br label %107
107: ; preds = %16, %103, %8
%108 = phi i32 [ 1, %8 ], [ 2, %16 ], [ %105, %103 ]
ret i32 %108
}