#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;
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
struct in_addr {
  int /*<<< orphan*/ s_addr;
};
struct hostent {
  scalar_t__ h_addr;
};

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SOCK_STREAM;
int atoi(char *);
int /*<<< orphan*/ close(int);
scalar_t__ connect(int, struct sockaddr *, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/);
struct hostent *gethostbyname(char *);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ isNumber(char *);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int read(int, char *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stdin;
int strlen(char *);
int /*<<< orphan*/ write(int, char *, int);
int main(int argc, char *argv[]) {
  struct hostent *host;
  struct sockaddr_in servaddr;
  int port, sd, nread;
  char input[256], c;
  if (argc != 3) {
    printf("%s\n", "Usage: client serverAddress serverPort");
    exit(1);
  }
  host = gethostbyname(argv[1]);
  if (host == NULL) {
    printf("%s not found in /etc/hosts\n", argv[1]);
    exit(2);
  }
  if (!isNumber(argv[2])) {
    printf("%s\n", "Usage: client serverAddress serverPort");
    printf("%s is not a number\n", argv[2]);
    exit(3);
  }
  port = atoi(argv[2]);
  if (port < 1024 || port > 65535) {
    printf("Port must be in [1024, 65535]\n");
    exit(4);
  }
  memset((char *)&servaddr, 0, sizeof(struct sockaddr_in));
  servaddr.sin_family = AF_INET;
  servaddr.sin_addr.s_addr = ((struct in_addr *)(host->h_addr))->s_addr;
  servaddr.sin_port = htons(port);
  sd = socket(AF_INET, SOCK_STREAM, 0);
  if (sd < 0) {
    perror("Opening Socket");
    exit(1);
  }
  printf("Socket created: sd=%d\n", sd);
  if (connect(sd, (struct sockaddr *)&servaddr, sizeof(struct sockaddr)) < 0) {
    perror("connect");
    exit(1);
  }
  printf("%s", "Insert Input: ");
  while (fgets(input, 256, stdin) != NULL) {
    if (input[strlen(input) - 1] == '\n')
      input[strlen(input) - 1] = '\0';
    write(sd, input, strlen(input) + 1);
    while ((nread = read(sd, &c, sizeof(char))) > 0) {
      if (c == '\0')
        break;
      write(1, &c, sizeof(char));
    }
    printf("\nDONE\n");
    printf("\n%s", "Insert Input: ");
  }
  close(sd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x160,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     1232 <main+0x42>
lea    0xde6(%rip),%rdi
lea    0xde3(%rip),%rsi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x1,%edi
call   10f0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10b0 <gethostbyname@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    126e <main+0x7e>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xdce(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x2,%edi
call   10f0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   10c0 <isNumber@plt>
cmp    $0x0,%eax
jne    12b9 <main+0xc9>
lea    0xd75(%rip),%rdi
lea    0xd72(%rip),%rsi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
lea    0xd9f(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x3,%edi
call   10f0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   10e0 <atoi@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x400,-0x2c(%rbp)
jl     12e3 <main+0xf3>
cmpl   $0xffff,-0x2c(%rbp)
jle    12fb <main+0x10b>
lea    0xd71(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x4,%edi
call   10f0 <exit@plt>
lea    -0x28(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1070 <memset@plt>
mov    0x2cd6(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    -0x2c(%rbp),%edi
call   1050 <htons@plt>
mov    %eax,-0x28(%rbp)
mov    0x2cb3(%rip),%rax
mov    (%rax),%edi
mov    0x2c92(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1110 <socket@plt>
mov    %eax,-0x30(%rbp)
cmpl   $0x0,-0x30(%rbp)
jge    136a <main+0x17a>
lea    0xd1f(%rip),%rdi
call   10d0 <perror@plt>
mov    $0x1,%edi
call   10f0 <exit@plt>
mov    -0x30(%rbp),%esi
lea    0xd15(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x30(%rbp),%edi
lea    -0x28(%rbp),%rsi
mov    $0x4,%edx
call   1100 <connect@plt>
cmp    $0x0,%rax
jge    13ac <main+0x1bc>
lea    0xd03(%rip),%rdi
call   10d0 <perror@plt>
mov    $0x1,%edi
call   10f0 <exit@plt>
lea    0xd0c(%rip),%rdi
lea    0xcee(%rip),%rsi
mov    $0x0,%al
call   1060 <printf@plt>
lea    -0x140(%rbp),%rdi
mov    0x2c11(%rip),%rax
mov    (%rax),%edx
mov    $0x100,%esi
call   10a0 <fgets@plt>
cmp    $0x0,%rax
je     14cf <main+0x2df>
lea    -0x140(%rbp),%rdi
call   1040 <strlen@plt>
sub    $0x1,%eax
cltq
movsbl -0x140(%rbp,%rax,1),%eax
ff
cmp    $0xa,%eax
jne    1420 <main+0x230>
lea    -0x140(%rbp),%rdi
call   1040 <strlen@plt>
sub    $0x1,%eax
cltq
movb   $0x0,-0x140(%rbp,%rax,1)
mov    -0x30(%rbp),%eax
mov    %eax,-0x154(%rbp)
lea    -0x140(%rbp),%rax
mov    %rax,-0x150(%rbp)
lea    -0x140(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x154(%rbp),%edi
mov    -0x150(%rbp),%rsi
mov    %eax,%edx
add    $0x1,%edx
call   1030 <write@plt>
mov    -0x30(%rbp),%edi
lea    -0x141(%rbp),%rsi
mov    $0x1,%edx
call   1090 <read@plt>
mov    %eax,-0x34(%rbp)
cmp    $0x0,%eax
jle    14a7 <main+0x2b7>
movsbl -0x141(%rbp),%eax
cmp    $0x0,%eax
jne    148f <main+0x29f>
jmp    14a7 <main+0x2b7>
mov    $0x1,%edx
lea    -0x141(%rbp),%rsi
mov    %edx,%edi
call   1030 <write@plt>
jmp    145a <main+0x26a>
lea    0xc09(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    0xc02(%rip),%rdi
lea    0xbe5(%rip),%rsi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    13c1 <main+0x1d1>
mov    -0x30(%rbp),%edi
call   1080 <close@plt>
xor    %eax,%eax
add    $0x160,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x128,%rsp
cmp    $0x3,%edi
jne    13f1 <main+0x1f1>
mov    %rsi,%rbp
mov    0x8(%rsi),%rdi
call   10c0 <gethostbyname@plt>
test   %rax,%rax
je     1407 <main+0x207>
mov    %rax,%rbx
mov    0x10(%rbp),%rdi
call   10d0 <isNumber@plt>
test   %eax,%eax
je     1423 <main+0x223>
mov    0x10(%rbp),%rdi
call   10f0 <atoi@plt>
mov    %eax,%ebp
lea    -0x10000(%rbp),%eax
cmp    $0xffff03ff,%eax
jbe    144b <main+0x24b>
lea    0x10(%rsp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1080 <memset@plt>
mov    0x2d71(%rip),%r14
mov    (%r14),%eax
mov    %eax,0x18(%rsp)
mov    (%rbx),%rax
mov    (%rax),%eax
mov    %eax,0x14(%rsp)
mov    %ebp,%edi
call   1060 <htons@plt>
mov    %eax,0x10(%rsp)
mov    (%r14),%edi
mov    0x2d34(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1120 <socket@plt>
test   %eax,%eax
js     1461 <main+0x261>
mov    %eax,%ebp
lea    0xdb0(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1070 <printf@plt>
lea    0x10(%rsp),%rsi
mov    %ebp,%edi
mov    $0x4,%edx
call   1110 <connect@plt>
test   %rax,%rax
js     146a <main+0x26a>
lea    0xdb5(%rip),%rdi
lea    0xd9e(%rip),%rsi
xor    %eax,%eax
call   1070 <printf@plt>
mov    0x2ceb(%rip),%rax
mov    (%rax),%edx
lea    0x20(%rsp),%r14
mov    %r14,%rdi
mov    $0x100,%esi
call   10b0 <fgets@plt>
test   %rax,%rax
je     13d6 <main+0x1d6>
lea    0xf(%rsp),%rbx
lea    0xd7a(%rip),%r15
lea    0xd6f(%rip),%r12
lea    0xd59(%rip),%r13
jmp    1360 <main+0x160>
xchg   %ax,%ax
mov    %r15,%rdi
call   1030 <puts@plt>
mov    %r12,%rdi
mov    %r13,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
mov    0x2c94(%rip),%rax
mov    (%rax),%edx
mov    %r14,%rdi
mov    $0x100,%esi
call   10b0 <fgets@plt>
test   %rax,%rax
je     13d6 <main+0x1d6>
mov    %r14,%rdi
call   1050 <strlen@plt>
cltq
cmpb   $0xa,-0x1(%rax,%r14,1)
jne    1382 <main+0x182>
mov    %r14,%rdi
call   1050 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%r14,1)
mov    %r14,%rdi
call   1050 <strlen@plt>
lea    0x1(%rax),%edx
mov    %ebp,%edi
mov    %r14,%rsi
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
call   1040 <write@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x1,%edx
call   10a0 <read@plt>
test   %eax,%eax
jle    1330 <main+0x130>
cmpb   $0x0,0xf(%rsp)
je     1330 <main+0x130>
mov    $0x1,%edi
mov    %rbx,%rsi
mov    $0x1,%edx
jmp    13a0 <main+0x1a0>
mov    %ebp,%edi
call   1090 <close@plt>
xor    %eax,%eax
add    $0x128,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xc08(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1100 <exit@plt>
mov    0x8(%rbp),%rsi
lea    0xc15(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    $0x2,%edi
call   1100 <exit@plt>
lea    0xbd6(%rip),%rdi
call   1030 <puts@plt>
mov    0x10(%rbp),%rsi
lea    0xc09(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    $0x3,%edi
call   1100 <exit@plt>
lea    0xc4c(%rip),%rdi
call   1030 <puts@plt>
mov    $0x4,%edi
call   1100 <exit@plt>
lea    0xbef(%rip),%rdi
jmp    1471 <main+0x271>
lea    0xc0c(%rip),%rdi
call   10e0 <perror@plt>
mov    $0x1,%edi
call   1100 <exit@plt>

LLVM IR (-O0):
%struct.hostent = type { i64 }
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.in_addr = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [4 x i8] c"%s\0A\00"
@.str.1 = [39 x i8] c"Usage: client serverAddress serverPort\00"
@.str.2 = [28 x i8] c"%s not found in /etc/hosts\0A\00"
@.str.3 = [20 x i8] c"%s is not a number\0A\00"
@.str.4 = [31 x i8] c"Port must be in [1024, 65535]\0A\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.5 = [15 x i8] c"Opening Socket\00"
@.str.6 = [23 x i8] c"Socket created: sd=%d\0A\00"
@.str.7 = [8 x i8] c"connect\00"
@.str.8 = [3 x i8] c"%s\00"
@.str.9 = [15 x i8] c"Insert Input: \00"
@stdin = global i32 0
@.str.10 = [7 x i8] c"\0ADONE\0A\00"
@.str.11 = [4 x i8] c"\0A%s\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.hostent*
%7 = alloca %struct.sockaddr_in
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca [256 x i8]
%12 = alloca i8
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%13 = load i32, i32* %4
%14 = icmp ne i32 %13, 3
br i1 %14, label %15, label %18
15: ; preds = %2
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0))
%17 = call i32 @exit(i32 1)
unreachable
18: ; preds = %2
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 1
%21 = load i8*, i8** %20
%22 = call %struct.hostent* @gethostbyname(i8* %21)
store %struct.hostent* %22, %struct.hostent** %6
%23 = load %struct.hostent*, %struct.hostent** %6
%24 = icmp eq %struct.hostent* %23, null
br i1 %24, label %25, label %31
25: ; preds = %18
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 1
%28 = load i8*, i8** %27
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i8* %28)
%30 = call i32 @exit(i32 2)
unreachable
31: ; preds = %18
%32 = load i8**, i8*** %5
%33 = getelementptr inbounds i8*, i8** %32, i64 2
%34 = load i8*, i8** %33
%35 = call i32 @isNumber(i8* %34)
%36 = icmp ne i32 %35, 0
br i1 %36, label %44, label %37
37: ; preds = %31
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0))
%39 = load i8**, i8*** %5
%40 = getelementptr inbounds i8*, i8** %39, i64 2
%41 = load i8*, i8** %40
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i8* %41)
%43 = call i32 @exit(i32 3)
unreachable
44: ; preds = %31
%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* %8
%49 = load i32, i32* %8
%50 = icmp slt i32 %49, 1024
br i1 %50, label %54, label %51
51: ; preds = %44
%52 = load i32, i32* %8
%53 = icmp sgt i32 %52, 65535
br i1 %53, label %54, label %57
54: ; preds = %51, %44
%55 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0))
%56 = call i32 @exit(i32 4)
unreachable
57: ; preds = %51
%58 = bitcast %struct.sockaddr_in* %7 to i8*
%59 = call i32 @memset(i8* %58, i32 0, i32 12)
%60 = load i32, i32* @AF_INET
%61 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 2
store i32 %60, i32* %61
%62 = load %struct.hostent*, %struct.hostent** %6
%63 = getelementptr inbounds %struct.hostent, %struct.hostent* %62, i32 0, i32 0
%64 = load i64, i64* %63
%65 = inttoptr i64 %64 to %struct.in_addr*
%66 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %65, i32 0, i32 0
%67 = load i32, i32* %66
%68 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 1
%69 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %68, i32 0, i32 0
store i32 %67, i32* %69
%70 = load i32, i32* %8
%71 = call i32 @htons(i32 %70)
%72 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 0
store i32 %71, i32* %72
%73 = load i32, i32* @AF_INET
%74 = load i32, i32* @SOCK_STREAM
%75 = call i32 @socket(i32 %73, i32 %74, i32 0)
store i32 %75, i32* %9
%76 = load i32, i32* %9
%77 = icmp slt i32 %76, 0
br i1 %77, label %78, label %81
78: ; preds = %57
%79 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0))
%80 = call i32 @exit(i32 1)
unreachable
81: ; preds = %57
%82 = load i32, i32* %9
%83 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.6, i64 0, i64 0), i32 %82)
%84 = load i32, i32* %9
%85 = bitcast %struct.sockaddr_in* %7 to %struct.sockaddr*
%86 = call i64 @connect(i32 %84, %struct.sockaddr* %85, i32 4)
%87 = icmp slt i64 %86, 0
br i1 %87, label %88, label %91
88: ; preds = %81
%89 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.7, i64 0, i64 0))
%90 = call i32 @exit(i32 1)
unreachable
91: ; preds = %81
%92 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.9, i64 0, i64 0))
br label %93
93: ; preds = %131, %91
%94 = getelementptr inbounds [256 x i8], [256 x i8]* %11, i64 0, i64 0
%95 = load i32, i32* @stdin
%96 = call i32* @fgets(i8* %94, i32 256, i32 %95)
%97 = icmp ne i32* %96, null
br i1 %97, label %98, label %134
98: ; preds = %93
%99 = getelementptr inbounds [256 x i8], [256 x i8]* %11, i64 0, i64 0
%100 = call i32 @strlen(i8* %99)
%101 = sub nsw i32 %100, 1
%102 = sext i32 %101 to i64
%103 = getelementptr inbounds [256 x i8], [256 x i8]* %11, i64 0, i64 %102
%104 = load i8, i8* %103
%105 = sext i8 %104 to i32
%106 = icmp eq i32 %105, 10
br i1 %106, label %107, label %113
107: ; preds = %98
%108 = getelementptr inbounds [256 x i8], [256 x i8]* %11, i64 0, i64 0
%109 = call i32 @strlen(i8* %108)
%110 = sub nsw i32 %109, 1
%111 = sext i32 %110 to i64
%112 = getelementptr inbounds [256 x i8], [256 x i8]* %11, i64 0, i64 %111
store i8 0, i8* %112
br label %113
113: ; preds = %107, %98
%114 = load i32, i32* %9
%115 = getelementptr inbounds [256 x i8], [256 x i8]* %11, i64 0, i64 0
%116 = getelementptr inbounds [256 x i8], [256 x i8]* %11, i64 0, i64 0
%117 = call i32 @strlen(i8* %116)
%118 = add nsw i32 %117, 1
%119 = call i32 @write(i32 %114, i8* %115, i32 %118)
br label %120
120: ; preds = %129, %113
%121 = load i32, i32* %9
%122 = call i32 @read(i32 %121, i8* %12, i32 1)
store i32 %122, i32* %10
%123 = icmp sgt i32 %122, 0
br i1 %123, label %124, label %131
124: ; preds = %120
%125 = load i8, i8* %12
%126 = sext i8 %125 to i32
%127 = icmp eq i32 %126, 0
br i1 %127, label %128, label %129
128: ; preds = %124
br label %131
129: ; preds = %124
%130 = call i32 @write(i32 1, i8* %12, i32 1)
br label %120
131: ; preds = %128, %120
%132 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.10, i64 0, i64 0))
%133 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.11, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.9, i64 0, i64 0))
br label %93
134: ; preds = %93
%135 = load i32, i32* %9
%136 = call i32 @close(i32 %135)
ret i32 0
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.hostent = type { i64 }
%struct.in_addr = type { i32 }
%struct.sockaddr = type { i32 }
@.str.1 = [39 x i8] c"Usage: client serverAddress serverPort\00"
@.str.2 = [28 x i8] c"%s not found in /etc/hosts\0A\00"
@.str.3 = [20 x i8] c"%s is not a number\0A\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.5 = [15 x i8] c"Opening Socket\00"
@.str.6 = [23 x i8] c"Socket created: sd=%d\0A\00"
@.str.7 = [8 x i8] c"connect\00"
@.str.8 = [3 x i8] c"%s\00"
@.str.9 = [15 x i8] c"Insert Input: \00"
@stdin = global i32 0
@.str.11 = [4 x i8] c"\0A%s\00"
@str = [6 x i8] c"\0ADONE\00"
@str.12 = [30 x i8] c"Port must be in [1024, 65535]\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca [256 x i8]
%5 = alloca i8
%6 = bitcast %struct.sockaddr_in* %3 to i8*
%7 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%8 = icmp eq i32 %0, 3
br i1 %8, label %12, label %9
9: ; preds = %2
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0))
%11 = tail call i32 @exit(i32 1)
unreachable
12: ; preds = %2
%13 = getelementptr inbounds i8*, i8** %1, i64 1
%14 = load i8*, i8** %13
%15 = tail call %struct.hostent* @gethostbyname(i8* %14)
%16 = icmp eq %struct.hostent* %15, null
br i1 %16, label %17, label %21
17: ; preds = %12
%18 = load i8*, i8** %13
%19 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i8* %18)
%20 = tail call i32 @exit(i32 2)
unreachable
21: ; preds = %12
%22 = getelementptr inbounds i8*, i8** %1, i64 2
%23 = load i8*, i8** %22
%24 = tail call i32 @isNumber(i8* %23)
%25 = icmp eq i32 %24, 0
br i1 %25, label %26, label %31
26: ; preds = %21
%27 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0))
%28 = load i8*, i8** %22
%29 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i8* %28)
%30 = tail call i32 @exit(i32 3)
unreachable
31: ; preds = %21
%32 = load i8*, i8** %22
%33 = tail call i32 @atoi(i8* %32)
%34 = add i32 %33, -65536
%35 = icmp ult i32 %34, -64512
br i1 %35, label %36, label %39
36: ; preds = %31
%37 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @str.12, i64 0, i64 0))
%38 = tail call i32 @exit(i32 4)
unreachable
39: ; preds = %31
%40 = call i32 @memset(i8* %6, i32 0, i32 12)
%41 = load i32, i32* @AF_INET
%42 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %41, i32* %42
%43 = getelementptr inbounds %struct.hostent, %struct.hostent* %15, i64 0, i32 0
%44 = load i64, i64* %43
%45 = inttoptr i64 %44 to %struct.in_addr*
%46 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %45, i64 0, i32 0
%47 = load i32, i32* %46
%48 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1, i32 0
store i32 %47, i32* %48
%49 = call i32 @htons(i32 %33)
%50 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
store i32 %49, i32* %50
%51 = load i32, i32* @AF_INET
%52 = load i32, i32* @SOCK_STREAM
%53 = call i32 @socket(i32 %51, i32 %52, i32 0)
%54 = icmp slt i32 %53, 0
br i1 %54, label %55, label %58
55: ; preds = %39
%56 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0))
%57 = call i32 @exit(i32 1)
unreachable
58: ; preds = %39
%59 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.6, i64 0, i64 0), i32 %53)
%60 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%61 = call i64 @connect(i32 %53, %struct.sockaddr* %60, i32 4)
%62 = icmp slt i64 %61, 0
br i1 %62, label %63, label %66
63: ; preds = %58
%64 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.7, i64 0, i64 0))
%65 = call i32 @exit(i32 1)
unreachable
66: ; preds = %58
%67 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.9, i64 0, i64 0))
%68 = load i32, i32* @stdin
%69 = call i32* @fgets(i8* %7, i32 256, i32 %68)
%70 = icmp eq i32* %69, null
br i1 %70, label %105, label %71
71: ; preds = %66, %99
%72 = call i32 @strlen(i8* %7)
%73 = add nsw i32 %72, -1
%74 = sext i32 %73 to i64
%75 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 %74
%76 = load i8, i8* %75
%77 = icmp eq i8 %76, 10
br i1 %77, label %78, label %83
78: ; preds = %71
%79 = call i32 @strlen(i8* %7)
%80 = add nsw i32 %79, -1
%81 = sext i32 %80 to i64
%82 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 %81
store i8 0, i8* %82
br label %83
83: ; preds = %78, %71
%84 = call i32 @strlen(i8* %7)
%85 = add nsw i32 %84, 1
%86 = call i32 @write(i32 %53, i8* %7, i32 %85)
%87 = call i32 @read(i32 %53, i8* %5, i32 1)
%88 = icmp slt i32 %87, 1
%89 = load i8, i8* %5
%90 = icmp eq i8 %89, 0
%91 = select i1 %88, i1 true, i1 %90
br i1 %91, label %99, label %92
92: ; preds = %83, %92
%93 = call i32 @write(i32 1, i8* %5, i32 1)
%94 = call i32 @read(i32 %53, i8* %5, i32 1)
%95 = icmp slt i32 %94, 1
%96 = load i8, i8* %5
%97 = icmp eq i8 %96, 0
%98 = select i1 %95, i1 true, i1 %97
br i1 %98, label %99, label %92
99: ; preds = %92, %83
%100 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @str, i64 0, i64 0))
%101 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.11, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.9, i64 0, i64 0))
%102 = load i32, i32* @stdin
%103 = call i32* @fgets(i8* %7, i32 256, i32 %102)
%104 = icmp eq i32* %103, null
br i1 %104, label %105, label %71
105: ; preds = %99, %66
%106 = call i32 @close(i32 %53)
ret i32 0
}