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

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
scalar_t__ EOF;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ bzero(char *, int);
scalar_t__ connect(int, struct sockaddr *, int);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
scalar_t__ fputs(char *, int /*<<< orphan*/);
int /*<<< orphan*/ htons(int);
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 /*<<< orphan*/ stdin;
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ strlen(char *);
int write(int, char *, int /*<<< orphan*/);
int main(void) {
  int sockfd = 0, n = 0;
  char recvBuff[1024];
  struct sockaddr_in serv_addr;
  memset(recvBuff, '0', sizeof(recvBuff));
  if ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
    printf("\n Error : Could not create socket \n");
    return 1;
  }
  serv_addr.sin_family = AF_INET;
  serv_addr.sin_port = htons(8886);
  serv_addr.sin_addr.s_addr = inet_addr("127.0.0.1");
  if (connect(sockfd, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) < 0) {
    printf("\n Error : Connect Failed \n");
    return 1;
  }
  char buffer[256];
  printf("Please enter the message: ");
  bzero(buffer, 256);
  fgets(buffer, 255, stdin);
  n = write(sockfd, buffer, strlen(buffer));
  while ((n = read(sockfd, recvBuff, sizeof(recvBuff) - 1)) > 0) {
    recvBuff[n] = 0;
    if (fputs(recvBuff, stdout) == EOF) {
      printf("\n Error : Fputs error");
    }
  }
  if (n < 0) {
    printf("\n Read Error \n");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x530,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
lea    -0x410(%rbp),%rdi
mov    $0x30,%esi
mov    $0x400,%edx
call   1080 <memset@plt>
mov    0x2deb(%rip),%rax
mov    (%rax),%edi
mov    0x2dc2(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10e0 <socket@plt>
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
jge    1233 <main+0x73>
lea    0xdde(%rip),%rdi
call   1060 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    138a <main+0x1ca>
mov    0x2dae(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x418(%rbp)
mov    $0x22b6,%edi
call   1050 <htons@plt>
mov    %eax,-0x41c(%rbp)
lea    0xdcb(%rip),%rdi
call   10b0 <inet_addr@plt>
mov    %eax,-0x420(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x420(%rbp),%rsi
mov    $0xc,%edx
call   10d0 <connect@plt>
cmp    $0x0,%rax
jge    129a <main+0xda>
lea    0xda5(%rip),%rdi
call   1060 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    138a <main+0x1ca>
lea    0xda8(%rip),%rdi
call   1060 <printf@plt>
lea    -0x520(%rbp),%rdi
mov    $0x100,%esi
call   10c0 <bzero@plt>
lea    -0x520(%rbp),%rdi
mov    0x2d1b(%rip),%rax
mov    (%rax),%edx
mov    $0xff,%esi
call   10a0 <fgets@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0x52c(%rbp)
lea    -0x520(%rbp),%rax
mov    %rax,-0x528(%rbp)
lea    -0x520(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x52c(%rbp),%edi
mov    -0x528(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x410(%rbp),%rsi
mov    $0x3ff,%edx
call   1090 <read@plt>
mov    %eax,-0xc(%rbp)
cmp    $0x0,%eax
jle    136d <main+0x1ad>
movslq -0xc(%rbp),%rax
movb   $0x0,-0x410(%rbp,%rax,1)
lea    -0x410(%rbp),%rdi
mov    0x2c7b(%rip),%rax
mov    (%rax),%esi
call   1070 <fputs@plt>
mov    0x2c85(%rip),%rcx
cmp    (%rcx),%rax
jne    1368 <main+0x1a8>
lea    0xd01(%rip),%rdi
call   1060 <printf@plt>
jmp    130b <main+0x14b>
cmpl   $0x0,-0xc(%rbp)
jge    1383 <main+0x1c3>
lea    0xcfc(%rip),%rdi
call   1060 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x530,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x510,%rsp
lea    0x110(%rsp),%rdi
mov    $0x30,%esi
mov    $0x400,%edx
call   1090 <memset@plt>
mov    0x2deb(%rip),%rbx
mov    (%rbx),%edi
mov    0x2dc2(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10f0 <socket@plt>
test   %eax,%eax
js     132c <main+0x15c>
mov    %eax,%ebp
mov    (%rbx),%eax
mov    %eax,0x8(%rsp)
mov    $0x22b6,%edi
call   1060 <htons@plt>
mov    %eax,0x4(%rsp)
lea    0xdcc(%rip),%rdi
call   10c0 <inet_addr@plt>
mov    %eax,(%rsp)
mov    %rsp,%rsi
mov    %ebp,%edi
mov    $0xc,%edx
call   10e0 <connect@plt>
test   %rax,%rax
js     1335 <main+0x165>
lea    0xdaf(%rip),%rdi
call   1070 <printf@plt>
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x100,%esi
call   10d0 <bzero@plt>
mov    0x2d67(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
mov    $0xff,%esi
call   10b0 <fgets@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1040 <write@plt>
lea    0x110(%rsp),%rsi
mov    %ebp,%edi
mov    $0x3ff,%edx
call   10a0 <read@plt>
test   %eax,%eax
jle    1318 <main+0x148>
mov    0x2d05(%rip),%r15
lea    0x110(%rsp),%rbx
mov    0x2d0e(%rip),%r12
lea    0xd54(%rip),%r14
jmp    12f3 <main+0x123>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x3ff,%edx
call   10a0 <read@plt>
test   %eax,%eax
jle    1318 <main+0x148>
mov    %eax,%eax
movb   $0x0,0x110(%rsp,%rax,1)
mov    (%r15),%esi
mov    %rbx,%rdi
call   1080 <fputs@plt>
cmp    (%r12),%rax
jne    12e0 <main+0x110>
mov    %r14,%rdi
call   1070 <printf@plt>
jmp    12e0 <main+0x110>
test   %eax,%eax
jns    1328 <main+0x158>
lea    0xd18(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
jmp    1346 <main+0x176>
lea    0xd30(%rip),%rdi
jmp    133c <main+0x16c>
lea    0xd0d(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%eax
add    $0x510,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str = [36 x i8] c"\0A Error : Could not create socket \0A\00"
@.str.1 = [10 x i8] c"127.0.0.1\00"
@.str.2 = [27 x i8] c"\0A Error : Connect Failed \0A\00"
@.str.3 = [27 x i8] c"Please enter the message: \00"
@stdin = global i32 0
@stdout = global i32 0
@EOF = global i64 0
@.str.4 = [22 x i8] c"\0A Error : Fputs error\00"
@.str.5 = [15 x i8] c"\0A Read Error \0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca [1024 x i8]
%5 = alloca %struct.sockaddr_in
%6 = alloca [256 x i8]
store i32 0, i32* %1
store i32 0, i32* %2
store i32 0, i32* %3
%7 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%8 = call i32 @memset(i8* %7, i32 48, i32 1024)
%9 = load i32, i32* @AF_INET
%10 = load i32, i32* @SOCK_STREAM
%11 = call i32 @socket(i32 %9, i32 %10, i32 0)
store i32 %11, i32* %2
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %0
%14 = call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %1
br label %64
15: ; preds = %0
%16 = load i32, i32* @AF_INET
%17 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i32 0, i32 2
store i32 %16, i32* %17
%18 = call i32 @htons(i32 8886)
%19 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i32 0, i32 1
store i32 %18, i32* %19
%20 = call i32 @inet_addr(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%21 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i32 0, i32 0
%22 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %21, i32 0, i32 0
store i32 %20, i32* %22
%23 = load i32, i32* %2
%24 = bitcast %struct.sockaddr_in* %5 to %struct.sockaddr*
%25 = call i64 @connect(i32 %23, %struct.sockaddr* %24, i32 12)
%26 = icmp slt i64 %25, 0
br i1 %26, label %27, label %29
27: ; preds = %15
%28 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %1
br label %64
29: ; preds = %15
%30 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0))
%31 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%32 = call i32 @bzero(i8* %31, i32 256)
%33 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%34 = load i32, i32* @stdin
%35 = call i32 @fgets(i8* %33, i32 255, i32 %34)
%36 = load i32, i32* %2
%37 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%38 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%39 = call i32 @strlen(i8* %38)
%40 = call i32 @write(i32 %36, i8* %37, i32 %39)
store i32 %40, i32* %3
br label %41
41: ; preds = %57, %29
%42 = load i32, i32* %2
%43 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%44 = call i32 @read(i32 %42, i8* %43, i32 1023)
store i32 %44, i32* %3
%45 = icmp sgt i32 %44, 0
br i1 %45, label %46, label %58
46: ; preds = %41
%47 = load i32, i32* %3
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 %48
store i8 0, i8* %49
%50 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%51 = load i32, i32* @stdout
%52 = call i64 @fputs(i8* %50, i32 %51)
%53 = load i64, i64* @EOF
%54 = icmp eq i64 %52, %53
br i1 %54, label %55, label %57
55: ; preds = %46
%56 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0))
br label %57
57: ; preds = %55, %46
br label %41
58: ; preds = %41
%59 = load i32, i32* %3
%60 = icmp slt i32 %59, 0
br i1 %60, label %61, label %63
61: ; preds = %58
%62 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0))
br label %63
63: ; preds = %61, %58
store i32 0, i32* %1
br label %64
64: ; preds = %63, %27, %13
%65 = load i32, i32* %1
ret i32 %65
}

LLVM IR (-O2):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.1 = [10 x i8] c"127.0.0.1\00"
@.str.3 = [27 x i8] c"Please enter the message: \00"
@stdin = global i32 0
@stdout = global i32 0
@EOF = global i64 0
@.str.4 = [22 x i8] c"\0A Error : Fputs error\00"
@str = [14 x i8] c"\0A Read Error \00"
@str.6 = [26 x i8] c"\0A Error : Connect Failed \00"
@str.7 = [35 x i8] c"\0A Error : Could not create socket \00"
define i32 @main() {
%1 = alloca [1024 x i8]
%2 = alloca %struct.sockaddr_in
%3 = alloca [256 x i8]
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 0
%5 = bitcast %struct.sockaddr_in* %2 to i8*
%6 = call i32 @memset(i8* %4, i32 48, i32 1024)
%7 = load i32, i32* @AF_INET
%8 = load i32, i32* @SOCK_STREAM
%9 = call i32 @socket(i32 %7, i32 %8, i32 0)
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %0
%12 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @str.7, i64 0, i64 0))
br label %54
13: ; preds = %0
%14 = load i32, i32* @AF_INET
%15 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 2
store i32 %14, i32* %15
%16 = call i32 @htons(i32 8886)
%17 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 1
store i32 %16, i32* %17
%18 = call i32 @inet_addr(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%19 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 0, i32 0
store i32 %18, i32* %19
%20 = bitcast %struct.sockaddr_in* %2 to %struct.sockaddr*
%21 = call i64 @connect(i32 %9, %struct.sockaddr* %20, i32 12)
%22 = icmp slt i64 %21, 0
br i1 %22, label %23, label %25
23: ; preds = %13
%24 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str.6, i64 0, i64 0))
br label %54
25: ; preds = %13
%26 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%27 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0))
%28 = call i32 @bzero(i8* %26, i32 256)
%29 = load i32, i32* @stdin
%30 = call i32 @fgets(i8* %26, i32 255, i32 %29)
%31 = call i32 @strlen(i8* %26)
%32 = call i32 @write(i32 %9, i8* %26, i32 %31)
%33 = call i32 @read(i32 %9, i8* %4, i32 1023)
%34 = icmp sgt i32 %33, 0
br i1 %34, label %35, label %48
35: ; preds = %25, %45
%36 = phi i32 [ %46, %45 ], [ %33, %25 ]
%37 = zext i32 %36 to i64
%38 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 %37
store i8 0, i8* %38
%39 = load i32, i32* @stdout
%40 = call i64 @fputs(i8* %4, i32 %39)
%41 = load i64, i64* @EOF
%42 = icmp eq i64 %40, %41
br i1 %42, label %43, label %45
43: ; preds = %35
%44 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0))
br label %45
45: ; preds = %43, %35
%46 = call i32 @read(i32 %9, i8* %4, i32 1023)
%47 = icmp sgt i32 %46, 0
br i1 %47, label %35, label %48
48: ; preds = %45, %25
%49 = phi i32 [ %33, %25 ], [ %46, %45 ]
%50 = icmp slt i32 %49, 0
br i1 %50, label %51, label %53
51: ; preds = %48
%52 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str, i64 0, i64 0))
br label %53
53: ; preds = %51, %48
br label %54
54: ; preds = %53, %23, %11
%55 = phi i32 [ 1, %11 ], [ 1, %23 ], [ 0, %53 ]
ret i32 %55
}