#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;
};
typedef int /*<<< orphan*/ client_address;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ close(int);
int connect(int, struct sockaddr *, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ inet_addr(char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ read(int, char **, int);
int /*<<< orphan*/ scanf(char *, char *);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ write(int, char **, int);
int main() {
  int client_socktfd;
  int client_length;
  int outc_connect;
  struct sockaddr_in client_address;
  char buff[32];
  client_socktfd = socket(AF_INET, SOCK_STREAM, 0);
  client_address.sin_family = AF_INET;
  client_address.sin_addr.s_addr = inet_addr("127.0.0.1");
  client_address.sin_port = htons(9876);
  printf("%s\n", "Port Directioned...");
  client_length = sizeof(client_address);
  printf("%s\n", "Triying Connection...");
  outc_connect = connect(client_socktfd, (struct sockaddr *)&client_address,
                         client_length);
  if (outc_connect == -1) {
    perror("Oops: Couldnt stablish connection");
    exit(1);
  }
  printf("%s\n", "Successful Connection");
  printf("%s\n", "Waiting for entry...");
  while (1) {
    scanf("%s", &buff[0]);
    write(client_socktfd, &buff, 32);
    read(client_socktfd, &buff, 32);
    printf("%s\n", buff);
  }
  close(client_socktfd);
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e32(%rip),%rax
mov    (%rax),%edi
mov    0x2e19(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10c0 <socket@plt>
mov    %eax,-0x8(%rbp)
mov    0x2e16(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
lea    0xe22(%rip),%rdi
call   1070 <inet_addr@plt>
mov    %eax,-0x1c(%rbp)
mov    $0x2694,%edi
call   1040 <htons@plt>
mov    %eax,-0x20(%rbp)
lea    0xe10(%rip),%rdi
lea    0xe0d(%rip),%rsi
call   1050 <printf@plt>
movl   $0xc,-0xc(%rbp)
lea    0xdf6(%rip),%rdi
lea    0xe07(%rip),%rsi
call   1050 <printf@plt>
mov    -0x8(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    -0xc(%rbp),%edx
call   10b0 <connect@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0xffffffff,-0x10(%rbp)
jne    1252 <main+0xb2>
lea    0xdf5(%rip),%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
lea    0xdb1(%rip),%rdi
lea    0xdfa(%rip),%rsi
call   1050 <printf@plt>
lea    0xd9e(%rip),%rdi
lea    0xdfd(%rip),%rsi
call   1050 <printf@plt>
lea    -0x40(%rbp),%rsi
lea    0xe02(%rip),%rdi
call   1080 <scanf@plt>
mov    -0x8(%rbp),%edi
lea    -0x40(%rbp),%rsi
mov    $0x20,%edx
call   1030 <write@plt>
mov    -0x8(%rbp),%edi
lea    -0x40(%rbp),%rsi
mov    $0x20,%edx
call   1060 <read@plt>
lea    -0x40(%rbp),%rsi
lea    0xd55(%rip),%rdi
call   1050 <printf@plt>
jmp    1278 <main+0xd8>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x38,%rsp
mov    0x2e37(%rip),%rbx
mov    (%rbx),%edi
mov    0x2e1e(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10c0 <socket@plt>
mov    %eax,%ebp
mov    (%rbx),%eax
mov    %eax,0x8(%rsp)
lea    0xe2e(%rip),%rdi
call   1070 <inet_addr@plt>
mov    %eax,0x4(%rsp)
mov    $0x2694,%edi
call   1040 <htons@plt>
mov    %eax,(%rsp)
lea    0xe1b(%rip),%rbx
lea    0xe18(%rip),%rsi
mov    %rbx,%rdi
call   1050 <printf@plt>
lea    0xe1d(%rip),%rsi
mov    %rbx,%rdi
call   1050 <printf@plt>
mov    %rsp,%rsi
mov    %ebp,%edi
mov    $0xc,%edx
call   10b0 <connect@plt>
cmp    $0xffffffff,%eax
je     1296 <main+0xf6>
lea    0xde2(%rip),%r14
lea    0xe2b(%rip),%rsi
mov    %r14,%rdi
call   1050 <printf@plt>
lea    0xe32(%rip),%rsi
mov    %r14,%rdi
call   1050 <printf@plt>
lea    0xe38(%rip),%r15
lea    0x10(%rsp),%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r15,%rdi
mov    %rbx,%rsi
call   1080 <scanf@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x20,%edx
call   1030 <write@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x20,%edx
call   1060 <read@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1050 <printf@plt>
jmp    1260 <main+0xc0>
lea    0xd9b(%rip),%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str = [10 x i8] c"127.0.0.1\00"
@.str.1 = [4 x i8] c"%s\0A\00"
@.str.2 = [20 x i8] c"Port Directioned...\00"
@.str.3 = [22 x i8] c"Triying Connection...\00"
@.str.4 = [34 x i8] c"Oops: Couldnt stablish connection\00"
@.str.5 = [22 x i8] c"Successful Connection\00"
@.str.6 = [21 x i8] c"Waiting for entry...\00"
@.str.7 = [3 x i8] c"%s\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca %struct.sockaddr_in
%6 = alloca [32 x i8]
store i32 0, i32* %1
%7 = load i32, i32* @AF_INET
%8 = load i32, i32* @SOCK_STREAM
%9 = call i32 @socket(i32 %7, i32 %8, i32 0)
store i32 %9, i32* %2
%10 = load i32, i32* @AF_INET
%11 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i32 0, i32 2
store i32 %10, i32* %11
%12 = call i32 @inet_addr(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%13 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i32 0, i32 1
%14 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %13, i32 0, i32 0
store i32 %12, i32* %14
%15 = call i32 @htons(i32 9876)
%16 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i32 0, i32 0
store i32 %15, i32* %16
%17 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
store i32 12, i32* %3
%18 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0))
%19 = load i32, i32* %2
%20 = bitcast %struct.sockaddr_in* %5 to %struct.sockaddr*
%21 = load i32, i32* %3
%22 = call i32 @connect(i32 %19, %struct.sockaddr* %20, i32 %21)
store i32 %22, i32* %4
%23 = load i32, i32* %4
%24 = icmp eq i32 %23, -1
br i1 %24, label %25, label %28
25: ; preds = %0
%26 = call i32 @perror(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.4, i64 0, i64 0))
%27 = call i32 @exit(i32 1)
unreachable
28: ; preds = %0
%29 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0))
%30 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.6, i64 0, i64 0))
br label %31
31: ; preds = %28, %31
%32 = getelementptr inbounds [32 x i8], [32 x i8]* %6, i64 0, i64 0
%33 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i8* %32)
%34 = load i32, i32* %2
%35 = bitcast [32 x i8]* %6 to i8**
%36 = call i32 @write(i32 %34, i8** %35, i32 32)
%37 = load i32, i32* %2
%38 = bitcast [32 x i8]* %6 to i8**
%39 = call i32 @read(i32 %37, i8** %38, i32 32)
%40 = getelementptr inbounds [32 x i8], [32 x i8]* %6, i64 0, i64 0
%41 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %40)
br label %31
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str = [10 x i8] c"127.0.0.1\00"
@.str.1 = [4 x i8] c"%s\0A\00"
@.str.2 = [20 x i8] c"Port Directioned...\00"
@.str.3 = [22 x i8] c"Triying Connection...\00"
@.str.4 = [34 x i8] c"Oops: Couldnt stablish connection\00"
@.str.5 = [22 x i8] c"Successful Connection\00"
@.str.6 = [21 x i8] c"Waiting for entry...\00"
@.str.7 = [3 x i8] c"%s\00"
define i32 @main() {
%1 = alloca %struct.sockaddr_in
%2 = alloca [32 x i8]
%3 = bitcast %struct.sockaddr_in* %1 to i8*
%4 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 0
%5 = load i32, i32* @AF_INET
%6 = load i32, i32* @SOCK_STREAM
%7 = tail call i32 @socket(i32 %5, i32 %6, i32 0)
%8 = load i32, i32* @AF_INET
%9 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 2
store i32 %8, i32* %9
%10 = tail call i32 @inet_addr(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%11 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 1, i32 0
store i32 %10, i32* %11
%12 = tail call i32 @htons(i32 9876)
%13 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 0
store i32 %12, i32* %13
%14 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
%15 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0))
%16 = bitcast %struct.sockaddr_in* %1 to %struct.sockaddr*
%17 = call i32 @connect(i32 %7, %struct.sockaddr* %16, i32 12)
%18 = icmp eq i32 %17, -1
br i1 %18, label %19, label %22
19: ; preds = %0
%20 = call i32 @perror(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.4, i64 0, i64 0))
%21 = call i32 @exit(i32 1)
unreachable
22: ; preds = %0
%23 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0))
%24 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.6, i64 0, i64 0))
%25 = bitcast [32 x i8]* %2 to i8**
br label %26
26: ; preds = %26, %22
%27 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i8* %4)
%28 = call i32 @write(i32 %7, i8** %25, i32 32)
%29 = call i32 @read(i32 %7, i8** %25, i32 32)
%30 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %4)
br label %26
}