#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*/ u_short;
struct TYPE_2__ {
  int /*<<< orphan*/ s_addr;
};
struct sockaddr_in {
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_port;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ s_addr;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SOCK_STREAM;
int atoi(char const *);
int /*<<< orphan*/ close(int);
scalar_t__ connect(int, struct sockaddr *, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ htons(int /*<<< orphan*/);
int /*<<< orphan*/ inet_addr(char *);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, ...);
int read(int, char *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int strlen(char *);
scalar_t__ write(int, char *, int);
int main(int argc, char const *argv[]) {
  int port, serv_no;
  char buf[128];
  if (argc == 1) {
    {
      printf("%s\n", "Usage: ./client <port>");
      exit(1);
    };
  } else {
    port = atoi(argv[1]);
    if (port < 1024 || port > 65535) {
      printf("%s\n", "Port must between 1024 to 65535");
      exit(1);
    };
  }
  struct sockaddr_in s_addr;
  char buffer[1024];
  int sfd, n;
  memset((char *)&s_addr, 0, sizeof(s_addr));
  s_addr.sin_family = AF_INET;
  s_addr.sin_port = htons((u_short)port);
  s_addr.sin_addr.s_addr = inet_addr("127.0.0.1");
  if ((sfd = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
    printf("%s\n", "socket() error");
    exit(1);
  };
  if (connect(sfd, (struct sockaddr *)&s_addr, sizeof(s_addr)) < 0) {
    printf("%s\n", "connect() error");
    exit(1);
  };
  printf("connection successfull\n");
  read(0, buf, 128);
  if (write(sfd, buf, strlen(buf)) < 0) {
    printf("%s\n", "send() error");
    exit(1);
  }
  if ((n = read(sfd, buffer, 128)) < 0) {
    printf("%s\n", "recv() error");
    exit(1);
  };
  write(1, buffer, n);
  printf("\nExiting ...\n");
  close(sfd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x4d0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x1,-0x8(%rbp)
jne    1202 <main+0x42>
lea    0xe16(%rip),%rdi
lea    0xe13(%rip),%rsi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10b0 <atoi@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x400,-0x14(%rbp)
jl     122c <main+0x6c>
cmpl   $0xffff,-0x14(%rbp)
jle    124b <main+0x8b>
lea    0xdcd(%rip),%rdi
lea    0xde1(%rip),%rsi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
jmp    1250 <main+0x90>
lea    -0xb0(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1070 <memset@plt>
mov    0x2d7e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xa8(%rbp)
mov    -0x14(%rbp),%edi
call   1050 <htons@plt>
mov    %eax,-0xac(%rbp)
lea    0xdb4(%rip),%rdi
call   10a0 <inet_addr@plt>
mov    %eax,-0xb0(%rbp)
mov    0x2d4f(%rip),%rax
mov    (%rax),%edi
mov    0x2d36(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10e0 <socket@plt>
mov    %eax,-0x4b4(%rbp)
cmp    $0x0,%eax
jge    12d9 <main+0x119>
lea    0xd3f(%rip),%rdi
lea    0xd7d(%rip),%rsi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    -0x4b4(%rbp),%edi
lea    -0xb0(%rbp),%rsi
mov    $0xc,%edx
call   10d0 <connect@plt>
cmp    $0x0,%rax
jge    1319 <main+0x159>
lea    0xcff(%rip),%rdi
lea    0xd4c(%rip),%rsi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
lea    0xd44(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    -0xa0(%rbp),%rsi
xor    %edi,%edi
mov    $0x80,%edx
call   1090 <read@plt>
mov    -0x4b4(%rbp),%eax
mov    %eax,-0x4c4(%rbp)
lea    -0xa0(%rbp),%rax
mov    %rax,-0x4c0(%rbp)
lea    -0xa0(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x4c4(%rbp),%edi
mov    -0x4c0(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
cmp    $0x0,%rax
jge    139d <main+0x1dd>
lea    0xc7b(%rip),%rdi
lea    0xcf0(%rip),%rsi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    -0x4b4(%rbp),%edi
lea    -0x4b0(%rbp),%rsi
mov    $0x80,%edx
call   1090 <read@plt>
mov    %eax,-0x4b8(%rbp)
cmp    $0x0,%eax
jge    13e2 <main+0x222>
lea    0xc36(%rip),%rdi
lea    0xcb8(%rip),%rsi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
lea    -0x4b0(%rbp),%rsi
mov    -0x4b8(%rbp),%edx
mov    $0x1,%edi
call   1030 <write@plt>
lea    0xc96(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x4b4(%rbp),%edi
call   1080 <close@plt>
xor    %eax,%eax
add    $0x4d0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x498,%rsp
cmp    $0x1,%edi
je     12e0 <main+0x120>
mov    0x8(%rsi),%rdi
call   10b0 <atoi@plt>
mov    %eax,%ebx
lea    -0x10000(%rbx),%eax
cmp    $0xffff03ff,%eax
jbe    12e9 <main+0x129>
mov    %rsp,%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1070 <memset@plt>
mov    0x2de3(%rip),%r14
mov    (%r14),%eax
mov    %eax,0x8(%rsp)
mov    %ebx,%edi
call   1060 <htons@plt>
mov    %eax,0x4(%rsp)
lea    0xe19(%rip),%rdi
call   10a0 <inet_addr@plt>
mov    %eax,(%rsp)
mov    (%r14),%edi
mov    0x2da8(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10e0 <socket@plt>
test   %eax,%eax
js     12f2 <main+0x132>
mov    %eax,%ebx
mov    %rsp,%rsi
mov    %eax,%edi
mov    $0xc,%edx
call   10d0 <connect@plt>
test   %rax,%rax
js     12fb <main+0x13b>
lea    0xe18(%rip),%rdi
call   1030 <puts@plt>
lea    0x10(%rsp),%r14
xor    %edi,%edi
mov    %r14,%rsi
mov    $0x80,%edx
call   1090 <read@plt>
mov    %r14,%rdi
call   1050 <strlen@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    %eax,%edx
call   1040 <write@plt>
test   %rax,%rax
js     1304 <main+0x144>
lea    0x90(%rsp),%rsi
mov    %ebx,%edi
mov    $0x80,%edx
call   1090 <read@plt>
test   %eax,%eax
js     130d <main+0x14d>
lea    0x90(%rsp),%rsi
mov    $0x1,%edi
mov    %eax,%edx
call   1040 <write@plt>
lea    0xdca(%rip),%rdi
call   1030 <puts@plt>
mov    %ebx,%edi
call   1080 <close@plt>
xor    %eax,%eax
add    $0x498,%rsp
pop    %rbx
pop    %r14
ret
lea    0xd19(%rip),%rdi
jmp    1314 <main+0x154>
lea    0xd27(%rip),%rdi
jmp    1314 <main+0x154>
lea    0xd48(%rip),%rdi
jmp    1314 <main+0x154>
lea    0xd4e(%rip),%rdi
jmp    1314 <main+0x154>
lea    0xd55(%rip),%rdi
jmp    1314 <main+0x154>
lea    0xd59(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [4 x i8] c"%s\0A\00"
@.str.1 = [23 x i8] c"Usage: ./client <port>\00"
@.str.2 = [32 x i8] c"Port must between 1024 to 65535\00"
@AF_INET = global i32 0
@.str.3 = [10 x i8] c"127.0.0.1\00"
@SOCK_STREAM = global i32 0
@.str.4 = [15 x i8] c"socket() error\00"
@.str.5 = [16 x i8] c"connect() error\00"
@.str.6 = [24 x i8] c"connection successfull\0A\00"
@.str.7 = [13 x i8] c"send() error\00"
@.str.8 = [13 x i8] c"recv() error\00"
@.str.9 = [14 x i8] c"\0AExiting ...\0A\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 [128 x i8]
%9 = alloca %struct.sockaddr_in
%10 = alloca [1024 x i8]
%11 = alloca i32
%12 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%13 = load i32, i32* %4
%14 = icmp eq i32 %13, 1
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 ([23 x i8], [23 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 i32 @atoi(i8* %21)
store i32 %22, i32* %6
%23 = load i32, i32* %6
%24 = icmp slt i32 %23, 1024
br i1 %24, label %28, label %25
25: ; preds = %18
%26 = load i32, i32* %6
%27 = icmp sgt i32 %26, 65535
br i1 %27, label %28, label %31
28: ; preds = %25, %18
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0))
%30 = call i32 @exit(i32 1)
unreachable
31: ; preds = %25
br label %32
32: ; preds = %31
%33 = bitcast %struct.sockaddr_in* %9 to i8*
%34 = call i32 @memset(i8* %33, i32 0, i32 12)
%35 = load i32, i32* @AF_INET
%36 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 2
store i32 %35, i32* %36
%37 = load i32, i32* %6
%38 = call i32 @htons(i32 %37)
%39 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 1
store i32 %38, i32* %39
%40 = call i32 @inet_addr(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0))
%41 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 0
%42 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %41, i32 0, i32 0
store i32 %40, i32* %42
%43 = load i32, i32* @AF_INET
%44 = load i32, i32* @SOCK_STREAM
%45 = call i32 @socket(i32 %43, i32 %44, i32 0)
store i32 %45, i32* %11
%46 = icmp slt i32 %45, 0
br i1 %46, label %47, label %50
47: ; preds = %32
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0))
%49 = call i32 @exit(i32 1)
unreachable
50: ; preds = %32
%51 = load i32, i32* %11
%52 = bitcast %struct.sockaddr_in* %9 to %struct.sockaddr*
%53 = call i64 @connect(i32 %51, %struct.sockaddr* %52, i32 12)
%54 = icmp slt i64 %53, 0
br i1 %54, label %55, label %58
55: ; preds = %50
%56 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0))
%57 = call i32 @exit(i32 1)
unreachable
58: ; preds = %50
%59 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.6, i64 0, i64 0))
%60 = getelementptr inbounds [128 x i8], [128 x i8]* %8, i64 0, i64 0
%61 = call i32 @read(i32 0, i8* %60, i32 128)
%62 = load i32, i32* %11
%63 = getelementptr inbounds [128 x i8], [128 x i8]* %8, i64 0, i64 0
%64 = getelementptr inbounds [128 x i8], [128 x i8]* %8, i64 0, i64 0
%65 = call i32 @strlen(i8* %64)
%66 = call i64 @write(i32 %62, i8* %63, i32 %65)
%67 = icmp slt i64 %66, 0
br i1 %67, label %68, label %71
68: ; preds = %58
%69 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.7, i64 0, i64 0))
%70 = call i32 @exit(i32 1)
unreachable
71: ; preds = %58
%72 = load i32, i32* %11
%73 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%74 = call i32 @read(i32 %72, i8* %73, i32 128)
store i32 %74, i32* %12
%75 = icmp slt i32 %74, 0
br i1 %75, label %76, label %79
76: ; preds = %71
%77 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.8, i64 0, i64 0))
%78 = call i32 @exit(i32 1)
unreachable
79: ; preds = %71
%80 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%81 = load i32, i32* %12
%82 = call i64 @write(i32 1, i8* %80, i32 %81)
%83 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.9, i64 0, i64 0))
%84 = load i32, i32* %11
%85 = call i32 @close(i32 %84)
ret i32 0
}

LLVM IR (-O2):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@.str.1 = [23 x i8] c"Usage: ./client <port>\00"
@.str.2 = [32 x i8] c"Port must between 1024 to 65535\00"
@AF_INET = global i32 0
@.str.3 = [10 x i8] c"127.0.0.1\00"
@SOCK_STREAM = global i32 0
@.str.4 = [15 x i8] c"socket() error\00"
@.str.5 = [16 x i8] c"connect() error\00"
@.str.7 = [13 x i8] c"send() error\00"
@.str.8 = [13 x i8] c"recv() error\00"
@str = [23 x i8] c"connection successfull\00"
@str.10 = [13 x i8] c"\0AExiting ...\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [128 x i8]
%4 = alloca %struct.sockaddr_in
%5 = alloca [1024 x i8]
%6 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%7 = icmp eq i32 %0, 1
br i1 %7, label %8, label %11
8: ; preds = %2
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
%10 = tail call i32 @exit(i32 1)
unreachable
11: ; preds = %2
%12 = getelementptr inbounds i8*, i8** %1, i64 1
%13 = load i8*, i8** %12
%14 = tail call i32 @atoi(i8* %13)
%15 = add i32 %14, -65536
%16 = icmp ult i32 %15, -64512
br i1 %16, label %17, label %20
17: ; preds = %11
%18 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0))
%19 = tail call i32 @exit(i32 1)
unreachable
20: ; preds = %11
%21 = bitcast %struct.sockaddr_in* %4 to i8*
%22 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%23 = call i32 @memset(i8* %21, i32 0, i32 12)
%24 = load i32, i32* @AF_INET
%25 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 2
store i32 %24, i32* %25
%26 = call i32 @htons(i32 %14)
%27 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 1
store i32 %26, i32* %27
%28 = call i32 @inet_addr(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0))
%29 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 0, i32 0
store i32 %28, i32* %29
%30 = load i32, i32* @AF_INET
%31 = load i32, i32* @SOCK_STREAM
%32 = call i32 @socket(i32 %30, i32 %31, i32 0)
%33 = icmp slt i32 %32, 0
br i1 %33, label %34, label %37
34: ; preds = %20
%35 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0))
%36 = call i32 @exit(i32 1)
unreachable
37: ; preds = %20
%38 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%39 = call i64 @connect(i32 %32, %struct.sockaddr* %38, i32 12)
%40 = icmp slt i64 %39, 0
br i1 %40, label %41, label %44
41: ; preds = %37
%42 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0))
%43 = call i32 @exit(i32 1)
unreachable
44: ; preds = %37
%45 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str, i64 0, i64 0))
%46 = call i32 @read(i32 0, i8* %6, i32 128)
%47 = call i32 @strlen(i8* %6)
%48 = call i64 @write(i32 %32, i8* %6, i32 %47)
%49 = icmp slt i64 %48, 0
br i1 %49, label %50, label %53
50: ; preds = %44
%51 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.7, i64 0, i64 0))
%52 = call i32 @exit(i32 1)
unreachable
53: ; preds = %44
%54 = call i32 @read(i32 %32, i8* %22, i32 128)
%55 = icmp slt i32 %54, 0
br i1 %55, label %56, label %59
56: ; preds = %53
%57 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.8, i64 0, i64 0))
%58 = call i32 @exit(i32 1)
unreachable
59: ; preds = %53
%60 = call i64 @write(i32 1, i8* %22, i32 %54)
%61 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str.10, i64 0, i64 0))
%62 = call i32 @close(i32 %32)
ret i32 0
}