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

/* Variables and functions */
void *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);
void *htons(int /*<<< orphan*/);
void *inet_addr(char *);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, ...);
int read(int, char *, int);
int /*<<< orphan*/ scanf(char *, int *);
int /*<<< orphan*/ sleep(int);
int socket(void *, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ sprintf(char *, char *, int);
scalar_t__ strcmp(char *, char *);
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("Type Port no. of Service : ");
  scanf("%d", &serv_no);
  sprintf(buf, "%d", serv_no);
  write(sfd, buf, strlen(buf));
  read(sfd, buf, 128);
  close(sfd);
  if (strcmp(buf, "exit") == 0) {
    printf("%s\n", "Service Unavailable !");
    exit(1);
  };
  if ((sfd = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
    printf("%s\n", "socket() error");
    exit(1);
  };
  memset((char *)&s_addr, 0, sizeof(s_addr));
  s_addr.sin_family = AF_INET;
  s_addr.sin_port = htons((u_short)serv_no);
  s_addr.sin_addr.s_addr = inet_addr("127.0.0.1");
  sleep(3);
  if (connect(sfd, (struct sockaddr *)&s_addr, sizeof(s_addr)) < 0) {
    printf("%s\n", "connect() error");
    exit(1);
  };
  printf("connection successfull\n");
  while (1) {
    read(0, buf, 128);
    if (write(sfd, buf, strlen(buf)) < 0) {
      printf("%s\n", "send() error");
      exit(1);
    }
    if (strcmp(buf, "exit") == 0)
      break;
    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    $0x4f0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x1,-0x8(%rbp)
jne    1242 <main+0x42>
lea    0xdd6(%rip),%rdi
lea    0xdd3(%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   10d0 <atoi@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x400,-0x14(%rbp)
jl     126c <main+0x6c>
cmpl   $0xffff,-0x14(%rbp)
jle    128b <main+0x8b>
lea    0xd8d(%rip),%rdi
lea    0xda1(%rip),%rsi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x1,%edi
call   10f0 <exit@plt>
jmp    1290 <main+0x90>
lea    -0xb8(%rbp),%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1070 <memset@plt>
mov    0x2d3e(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0xa8(%rbp)
mov    -0x14(%rbp),%edi
call   1050 <htons@plt>
mov    %rax,-0xb0(%rbp)
lea    0xd71(%rip),%rdi
call   10a0 <inet_addr@plt>
mov    %rax,-0xb8(%rbp)
mov    0x2d0b(%rip),%rax
mov    (%rax),%rdi
mov    0x2cf1(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1120 <socket@plt>
mov    %eax,-0x4c4(%rbp)
cmp    $0x0,%eax
jge    131e <main+0x11e>
lea    0xcfa(%rip),%rdi
lea    0xd38(%rip),%rsi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x1,%edi
call   10f0 <exit@plt>
mov    -0x4c4(%rbp),%edi
lea    -0xb8(%rbp),%rsi
mov    $0x18,%edx
call   1100 <connect@plt>
cmp    $0x0,%rax
jge    135e <main+0x15e>
lea    0xcba(%rip),%rdi
lea    0xd07(%rip),%rsi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x1,%edi
call   10f0 <exit@plt>
lea    0xcff(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    0xd0d(%rip),%rdi
lea    -0x18(%rbp),%rsi
call   10c0 <scanf@plt>
lea    -0xa0(%rbp),%rdi
mov    -0x18(%rbp),%edx
lea    0xcf3(%rip),%rsi
call   10e0 <sprintf@plt>
mov    -0x4c4(%rbp),%eax
mov    %eax,-0x4d4(%rbp)
lea    -0xa0(%rbp),%rax
mov    %rax,-0x4d0(%rbp)
lea    -0xa0(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x4d4(%rbp),%edi
mov    -0x4d0(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    -0x4c4(%rbp),%edi
lea    -0xa0(%rbp),%rsi
mov    $0x80,%edx
call   1090 <read@plt>
mov    -0x4c4(%rbp),%edi
call   1080 <close@plt>
lea    -0xa0(%rbp),%rdi
lea    0xc87(%rip),%rsi
call   10b0 <strcmp@plt>
cmp    $0x0,%rax
jne    142a <main+0x22a>
lea    0xbee(%rip),%rdi
lea    0xc6f(%rip),%rsi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x1,%edi
call   10f0 <exit@plt>
mov    0x2bb7(%rip),%rax
mov    (%rax),%rdi
mov    0x2b9d(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1120 <socket@plt>
mov    %eax,-0x4c4(%rbp)
cmp    $0x0,%eax
jge    1472 <main+0x272>
lea    0xba6(%rip),%rdi
lea    0xbe4(%rip),%rsi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x1,%edi
call   10f0 <exit@plt>
lea    -0xb8(%rbp),%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1070 <memset@plt>
mov    0x2b5c(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0xa8(%rbp)
mov    -0x18(%rbp),%edi
call   1050 <htons@plt>
mov    %rax,-0xb0(%rbp)
lea    0xb8f(%rip),%rdi
call   10a0 <inet_addr@plt>
mov    %rax,-0xb8(%rbp)
mov    $0x3,%edi
call   1110 <sleep@plt>
mov    -0x4c4(%rbp),%edi
lea    -0xb8(%rbp),%rsi
mov    $0x18,%edx
call   1100 <connect@plt>
cmp    $0x0,%rax
jge    1502 <main+0x302>
lea    0xb16(%rip),%rdi
lea    0xb63(%rip),%rsi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x1,%edi
call   10f0 <exit@plt>
lea    0xb95(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    -0xa0(%rbp),%rsi
xor    %edi,%edi
mov    $0x80,%edx
call   1090 <read@plt>
mov    -0x4c4(%rbp),%eax
mov    %eax,-0x4e4(%rbp)
lea    -0xa0(%rbp),%rax
mov    %rax,-0x4e0(%rbp)
lea    -0xa0(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x4e4(%rbp),%edi
mov    -0x4e0(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
cmp    $0x0,%rax
jge    1586 <main+0x386>
lea    0xa92(%rip),%rdi
lea    0xb41(%rip),%rsi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x1,%edi
call   10f0 <exit@plt>
lea    -0xa0(%rbp),%rdi
lea    0xaef(%rip),%rsi
call   10b0 <strcmp@plt>
cmp    $0x0,%rax
jne    15a8 <main+0x3a8>
jmp    1609 <main+0x409>
mov    -0x4c4(%rbp),%edi
lea    -0x4c0(%rbp),%rsi
mov    $0x80,%edx
call   1090 <read@plt>
mov    %eax,-0x4c8(%rbp)
cmp    $0x0,%eax
jge    15ed <main+0x3ed>
lea    0xa2b(%rip),%rdi
lea    0xae7(%rip),%rsi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x1,%edi
call   10f0 <exit@plt>
lea    -0x4c0(%rbp),%rsi
mov    -0x4c8(%rbp),%edx
mov    $0x1,%edi
call   1030 <write@plt>
jmp    1510 <main+0x310>
lea    0xac0(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x4c4(%rbp),%edi
call   1080 <close@plt>
xor    %eax,%eax
add    $0x4f0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x4a0,%rsp
cmp    $0x1,%edi
je     14b0 <main+0x2a0>
mov    0x8(%rsi),%rdi
call   10e0 <atoi@plt>
mov    %eax,%ebx
lea    -0x10000(%rbx),%eax
cmp    $0xffff03ff,%eax
jbe    14b9 <main+0x2a9>
lea    0x8(%rsp),%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1080 <memset@plt>
mov    0x2d8c(%rip),%r15
mov    (%r15),%rax
mov    %rax,0x18(%rsp)
mov    %ebx,%edi
call   1060 <htons@plt>
mov    %rax,0x10(%rsp)
lea    0xdc0(%rip),%rdi
call   10b0 <inet_addr@plt>
mov    %rax,0x8(%rsp)
mov    (%r15),%rdi
mov    0x2d4d(%rip),%r12
mov    (%r12),%esi
xor    %edx,%edx
call   1130 <socket@plt>
test   %eax,%eax
js     149e <main+0x28e>
mov    %eax,%ebx
lea    0x8(%rsp),%rsi
mov    %eax,%edi
mov    $0x18,%edx
call   1110 <connect@plt>
test   %rax,%rax
js     14a7 <main+0x297>
lea    0xd9f(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
lea    0xdad(%rip),%r14
lea    0x4(%rsp),%rsi
mov    %r14,%rdi
call   10d0 <scanf@plt>
mov    0x4(%rsp),%edx
lea    0x20(%rsp),%rbp
mov    %rbp,%rdi
mov    %r14,%rsi
call   10f0 <sprintf@plt>
mov    %rbp,%rdi
call   1050 <strlen@plt>
mov    %ebx,%edi
mov    %rbp,%rsi
mov    %eax,%edx
call   1040 <write@plt>
mov    %ebx,%edi
mov    %rbp,%rsi
mov    $0x80,%edx
call   10a0 <read@plt>
mov    %ebx,%edi
call   1090 <close@plt>
lea    0xd5e(%rip),%rsi
mov    %rbp,%rdi
call   10c0 <strcmp@plt>
test   %rax,%rax
je     14c2 <main+0x2b2>
mov    (%r15),%rdi
mov    (%r12),%esi
xor    %edx,%edx
call   1130 <socket@plt>
test   %eax,%eax
js     149e <main+0x28e>
mov    %eax,%ebp
lea    0x8(%rsp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1080 <memset@plt>
mov    (%r15),%rax
mov    %rax,0x18(%rsp)
mov    0x4(%rsp),%edi
call   1060 <htons@plt>
mov    %rax,0x10(%rsp)
lea    0xcbc(%rip),%rdi
call   10b0 <inet_addr@plt>
mov    %rax,0x8(%rsp)
mov    $0x3,%edi
call   1120 <sleep@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x18,%edx
call   1110 <connect@plt>
test   %rax,%rax
js     14a7 <main+0x297>
lea    0xd06(%rip),%rdi
call   1030 <puts@plt>
lea    0x20(%rsp),%rbx
xor    %edi,%edi
mov    %rbx,%rsi
mov    $0x80,%edx
call   10a0 <read@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1040 <write@plt>
test   %rax,%rax
js     145a <main+0x24a>
lea    0xc98(%rip),%r14
lea    0x20(%rsp),%rbx
lea    0xa0(%rsp),%r15
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %rbx,%rdi
mov    %r14,%rsi
call   10c0 <strcmp@plt>
test   %rax,%rax
je     1463 <main+0x253>
mov    %ebp,%edi
mov    %r15,%rsi
mov    $0x80,%edx
call   10a0 <read@plt>
test   %eax,%eax
js     1488 <main+0x278>
mov    $0x1,%edi
mov    %r15,%rsi
mov    %eax,%edx
call   1040 <write@plt>
xor    %edi,%edi
mov    %rbx,%rsi
mov    $0x80,%edx
call   10a0 <read@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1040 <write@plt>
test   %rax,%rax
jns    1400 <main+0x1f0>
lea    0xc39(%rip),%rdi
jmp    148f <main+0x27f>
lea    0xc61(%rip),%rdi
call   1030 <puts@plt>
mov    %ebp,%edi
call   1090 <close@plt>
xor    %eax,%eax
add    $0x4a0,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xc18(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1100 <exit@plt>
lea    0xb9c(%rip),%rdi
jmp    148f <main+0x27f>
lea    0xba2(%rip),%rdi
jmp    148f <main+0x27f>
lea    0xb49(%rip),%rdi
jmp    148f <main+0x27f>
lea    0xb57(%rip),%rdi
jmp    148f <main+0x27f>
lea    0xbbb(%rip),%rdi
jmp    148f <main+0x27f>

LLVM IR (-O0):
%struct.sockaddr_in = type { %struct.TYPE_2__, i8*, i8* }
%struct.TYPE_2__ = type { i8* }
%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 i8* null
@.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 = [28 x i8] c"Type Port no. of Service : \00"
@.str.7 = [3 x i8] c"%d\00"
@.str.8 = [5 x i8] c"exit\00"
@.str.9 = [22 x i8] c"Service Unavailable !\00"
@.str.10 = [24 x i8] c"connection successfull\0A\00"
@.str.11 = [13 x i8] c"send() error\00"
@.str.12 = [13 x i8] c"recv() error\00"
@.str.13 = [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 24)
%35 = load i8*, i8** @AF_INET
%36 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 2
store i8* %35, i8** %36
%37 = load i32, i32* %6
%38 = call i8* @htons(i32 %37)
%39 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 1
store i8* %38, i8** %39
%40 = call i8* @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 i8* %40, i8** %42
%43 = load i8*, i8** @AF_INET
%44 = load i32, i32* @SOCK_STREAM
%45 = call i32 @socket(i8* %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 24)
%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 ([28 x i8], [28 x i8]* @.str.6, i64 0, i64 0))
%60 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i32* %7)
%61 = getelementptr inbounds [128 x i8], [128 x i8]* %8, i64 0, i64 0
%62 = load i32, i32* %7
%63 = call i32 @sprintf(i8* %61, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i32 %62)
%64 = load i32, i32* %11
%65 = getelementptr inbounds [128 x i8], [128 x i8]* %8, i64 0, i64 0
%66 = getelementptr inbounds [128 x i8], [128 x i8]* %8, i64 0, i64 0
%67 = call i32 @strlen(i8* %66)
%68 = call i64 @write(i32 %64, i8* %65, i32 %67)
%69 = load i32, i32* %11
%70 = getelementptr inbounds [128 x i8], [128 x i8]* %8, i64 0, i64 0
%71 = call i32 @read(i32 %69, i8* %70, i32 128)
%72 = load i32, i32* %11
%73 = call i32 @close(i32 %72)
%74 = getelementptr inbounds [128 x i8], [128 x i8]* %8, i64 0, i64 0
%75 = call i64 @strcmp(i8* %74, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0))
%76 = icmp eq i64 %75, 0
br i1 %76, label %77, label %80
77: ; preds = %58
%78 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.9, i64 0, i64 0))
%79 = call i32 @exit(i32 1)
unreachable
80: ; preds = %58
%81 = load i8*, i8** @AF_INET
%82 = load i32, i32* @SOCK_STREAM
%83 = call i32 @socket(i8* %81, i32 %82, i32 0)
store i32 %83, i32* %11
%84 = icmp slt i32 %83, 0
br i1 %84, label %85, label %88
85: ; preds = %80
%86 = 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))
%87 = call i32 @exit(i32 1)
unreachable
88: ; preds = %80
%89 = bitcast %struct.sockaddr_in* %9 to i8*
%90 = call i32 @memset(i8* %89, i32 0, i32 24)
%91 = load i8*, i8** @AF_INET
%92 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 2
store i8* %91, i8** %92
%93 = load i32, i32* %7
%94 = call i8* @htons(i32 %93)
%95 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 1
store i8* %94, i8** %95
%96 = call i8* @inet_addr(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0))
%97 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 0
%98 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %97, i32 0, i32 0
store i8* %96, i8** %98
%99 = call i32 @sleep(i32 3)
%100 = load i32, i32* %11
%101 = bitcast %struct.sockaddr_in* %9 to %struct.sockaddr*
%102 = call i64 @connect(i32 %100, %struct.sockaddr* %101, i32 24)
%103 = icmp slt i64 %102, 0
br i1 %103, label %104, label %107
104: ; preds = %88
%105 = 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))
%106 = call i32 @exit(i32 1)
unreachable
107: ; preds = %88
%108 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.10, i64 0, i64 0))
br label %109
109: ; preds = %107, %134
%110 = getelementptr inbounds [128 x i8], [128 x i8]* %8, i64 0, i64 0
%111 = call i32 @read(i32 0, i8* %110, i32 128)
%112 = load i32, i32* %11
%113 = getelementptr inbounds [128 x i8], [128 x i8]* %8, i64 0, i64 0
%114 = getelementptr inbounds [128 x i8], [128 x i8]* %8, i64 0, i64 0
%115 = call i32 @strlen(i8* %114)
%116 = call i64 @write(i32 %112, i8* %113, i32 %115)
%117 = icmp slt i64 %116, 0
br i1 %117, label %118, label %121
118: ; preds = %109
%119 = 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.11, i64 0, i64 0))
%120 = call i32 @exit(i32 1)
unreachable
121: ; preds = %109
%122 = getelementptr inbounds [128 x i8], [128 x i8]* %8, i64 0, i64 0
%123 = call i64 @strcmp(i8* %122, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0))
%124 = icmp eq i64 %123, 0
br i1 %124, label %125, label %126
125: ; preds = %121
br label %138
126: ; preds = %121
%127 = load i32, i32* %11
%128 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%129 = call i32 @read(i32 %127, i8* %128, i32 128)
store i32 %129, i32* %12
%130 = icmp slt i32 %129, 0
br i1 %130, label %131, label %134
131: ; preds = %126
%132 = 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.12, i64 0, i64 0))
%133 = call i32 @exit(i32 1)
unreachable
134: ; preds = %126
%135 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%136 = load i32, i32* %12
%137 = call i64 @write(i32 1, i8* %135, i32 %136)
br label %109
138: ; preds = %125
%139 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.13, i64 0, i64 0))
%140 = load i32, i32* %11
%141 = call i32 @close(i32 %140)
ret i32 0
}

LLVM IR (-O2):
%struct.sockaddr_in = type { %struct.TYPE_2__, i8*, i8* }
%struct.TYPE_2__ = type { i8* }
%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 i8* null
@.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 = [28 x i8] c"Type Port no. of Service : \00"
@.str.7 = [3 x i8] c"%d\00"
@.str.8 = [5 x i8] c"exit\00"
@.str.9 = [22 x i8] c"Service Unavailable !\00"
@.str.11 = [13 x i8] c"send() error\00"
@.str.12 = [13 x i8] c"recv() error\00"
@str = [23 x i8] c"connection successfull\00"
@str.14 = [13 x i8] c"\0AExiting ...\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca [128 x i8]
%5 = alloca %struct.sockaddr_in
%6 = alloca [1024 x i8]
%7 = bitcast i32* %3 to i8*
%8 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%9 = icmp eq i32 %0, 1
br i1 %9, label %10, label %13
10: ; preds = %2
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
%12 = tail call i32 @exit(i32 1)
unreachable
13: ; preds = %2
%14 = getelementptr inbounds i8*, i8** %1, i64 1
%15 = load i8*, i8** %14
%16 = tail call i32 @atoi(i8* %15)
%17 = add i32 %16, -65536
%18 = icmp ult i32 %17, -64512
br i1 %18, label %19, label %22
19: ; preds = %13
%20 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0))
%21 = tail call i32 @exit(i32 1)
unreachable
22: ; preds = %13
%23 = bitcast %struct.sockaddr_in* %5 to i8*
%24 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%25 = call i32 @memset(i8* %23, i32 0, i32 24)
%26 = load i8*, i8** @AF_INET
%27 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 2
store i8* %26, i8** %27
%28 = call i8* @htons(i32 %16)
%29 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 1
store i8* %28, i8** %29
%30 = call i8* @inet_addr(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0))
%31 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 0, i32 0
store i8* %30, i8** %31
%32 = load i8*, i8** @AF_INET
%33 = load i32, i32* @SOCK_STREAM
%34 = call i32 @socket(i8* %32, i32 %33, i32 0)
%35 = icmp slt i32 %34, 0
br i1 %35, label %36, label %39
36: ; preds = %22
%37 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0))
%38 = call i32 @exit(i32 1)
unreachable
39: ; preds = %22
%40 = bitcast %struct.sockaddr_in* %5 to %struct.sockaddr*
%41 = call i64 @connect(i32 %34, %struct.sockaddr* %40, i32 24)
%42 = icmp slt i64 %41, 0
br i1 %42, label %43, label %46
43: ; preds = %39
%44 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0))
%45 = call i32 @exit(i32 1)
unreachable
46: ; preds = %39
%47 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.6, i64 0, i64 0))
%48 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i32* %3)
%49 = load i32, i32* %3
%50 = call i32 @sprintf(i8* %8, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i32 %49)
%51 = call i32 @strlen(i8* %8)
%52 = call i64 @write(i32 %34, i8* %8, i32 %51)
%53 = call i32 @read(i32 %34, i8* %8, i32 128)
%54 = call i32 @close(i32 %34)
%55 = call i64 @strcmp(i8* %8, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0))
%56 = icmp eq i64 %55, 0
br i1 %56, label %57, label %60
57: ; preds = %46
%58 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.9, i64 0, i64 0))
%59 = call i32 @exit(i32 1)
unreachable
60: ; preds = %46
%61 = load i8*, i8** @AF_INET
%62 = load i32, i32* @SOCK_STREAM
%63 = call i32 @socket(i8* %61, i32 %62, i32 0)
%64 = icmp slt i32 %63, 0
br i1 %64, label %65, label %68
65: ; preds = %60
%66 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0))
%67 = call i32 @exit(i32 1)
unreachable
68: ; preds = %60
%69 = call i32 @memset(i8* %23, i32 0, i32 24)
%70 = load i8*, i8** @AF_INET
store i8* %70, i8** %27
%71 = load i32, i32* %3
%72 = call i8* @htons(i32 %71)
store i8* %72, i8** %29
%73 = call i8* @inet_addr(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0))
store i8* %73, i8** %31
%74 = call i32 @sleep(i32 3)
%75 = call i64 @connect(i32 %63, %struct.sockaddr* %40, i32 24)
%76 = icmp slt i64 %75, 0
br i1 %76, label %77, label %80
77: ; preds = %68
%78 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0))
%79 = call i32 @exit(i32 1)
unreachable
80: ; preds = %68
%81 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str, i64 0, i64 0))
%82 = call i32 @read(i32 0, i8* %8, i32 128)
%83 = call i32 @strlen(i8* %8)
%84 = call i64 @write(i32 %63, i8* %8, i32 %83)
%85 = icmp slt i64 %84, 0
br i1 %85, label %86, label %89
86: ; preds = %98, %80
%87 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.11, i64 0, i64 0))
%88 = call i32 @exit(i32 1)
unreachable
89: ; preds = %80, %98
%90 = call i64 @strcmp(i8* %8, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0))
%91 = icmp eq i64 %90, 0
br i1 %91, label %104, label %92
92: ; preds = %89
%93 = call i32 @read(i32 %63, i8* %24, i32 128)
%94 = icmp slt i32 %93, 0
br i1 %94, label %95, label %98
95: ; preds = %92
%96 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.12, i64 0, i64 0))
%97 = call i32 @exit(i32 1)
unreachable
98: ; preds = %92
%99 = call i64 @write(i32 1, i8* %24, i32 %93)
%100 = call i32 @read(i32 0, i8* %8, i32 128)
%101 = call i32 @strlen(i8* %8)
%102 = call i64 @write(i32 %63, i8* %8, i32 %101)
%103 = icmp slt i64 %102, 0
br i1 %103, label %86, label %89
104: ; preds = %89
%105 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str.14, i64 0, i64 0))
%106 = call i32 @close(i32 %63)
ret i32 0
}