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

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ close(int);
scalar_t__ connect(int, struct sockaddr *, int);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ inet_addr(char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ puts(char *);
scalar_t__ recv(int, char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ scanf(char *, char *);
scalar_t__ send(int, char *, int /*<<< orphan*/, int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strlen(char *);
int main(int argc, char *argv[]) {
  int sock;
  struct sockaddr_in server;
  char message[1000], server_reply[2000];
  sock = socket(AF_INET, SOCK_STREAM, 0);
  if (sock == -1) {
    printf("Could not create socket");
  }
  puts("Socket created");
  server.sin_addr.s_addr = inet_addr("127.0.0.1");
  server.sin_family = AF_INET;
  server.sin_port = htons(8888);
  if (connect(sock, (struct sockaddr *)&server, sizeof(server)) < 0) {
    perror("connect failed. Error");
    return 1;
  }
  puts("Connected\n");
  while (1) {
    printf("Enter message : ");
    scanf("%s", message);
    if (send(sock, message, strlen(message), 0) < 0) {
      puts("Send failed");
      return 1;
    }
    if (recv(sock, server_reply, 2000, 0) < 0) {
      puts("recv failed");
      break;
    }
    puts("Server reply :");
    puts(server_reply);
  }
  close(sock);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xbf0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e08(%rip),%rax
mov    (%rax),%edi
mov    0x2def(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10e0 <socket@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    120b <main+0x4b>
lea    0xdfa(%rip),%rdi
call   1080 <printf@plt>
lea    0xe06(%rip),%rdi
call   1040 <puts@plt>
lea    0xe09(%rip),%rdi
call   10a0 <inet_addr@plt>
mov    %eax,-0x18(%rbp)
mov    0x2dbb(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    $0x22b8,%edi
call   1060 <htons@plt>
mov    %eax,-0x20(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0xc,%edx
call   10d0 <connect@plt>
cmp    $0x0,%rax
jge    1272 <main+0xb2>
lea    0xdd0(%rip),%rdi
call   10c0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1355 <main+0x195>
lea    0xdce(%rip),%rdi
call   1040 <puts@plt>
lea    0xdcd(%rip),%rdi
call   1080 <printf@plt>
lea    -0x410(%rbp),%rsi
lea    0xdcb(%rip),%rdi
call   10b0 <scanf@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0xbec(%rbp)
lea    -0x410(%rbp),%rax
mov    %rax,-0xbe8(%rbp)
lea    -0x410(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0xbec(%rbp),%edi
mov    -0xbe8(%rbp),%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1070 <send@plt>
cmp    $0x0,%rax
jge    12f8 <main+0x138>
lea    0xd7f(%rip),%rdi
call   1040 <puts@plt>
movl   $0x1,-0x4(%rbp)
jmp    1355 <main+0x195>
mov    -0x14(%rbp),%edi
lea    -0xbe0(%rbp),%rsi
mov    $0x7d0,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
cmp    $0x0,%rax
jge    1329 <main+0x169>
lea    0xd53(%rip),%rdi
call   1040 <puts@plt>
jmp    1346 <main+0x186>
lea    0xd4e(%rip),%rdi
call   1040 <puts@plt>
lea    -0xbe0(%rbp),%rdi
call   1040 <puts@plt>
jmp    127e <main+0xbe>
mov    -0x14(%rbp),%edi
call   1090 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xbf0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xbd8,%rsp
mov    0x2e10(%rip),%rbp
mov    0x0(%rbp),%edi
mov    0x2df6(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10e0 <socket@plt>
mov    %eax,%ebx
cmp    $0xffffffff,%eax
jne    11fe <main+0x3e>
lea    0xe07(%rip),%rdi
call   1080 <printf@plt>
lea    0xe13(%rip),%rdi
call   1040 <puts@plt>
lea    0xe16(%rip),%rdi
call   10a0 <inet_addr@plt>
mov    %eax,0x8(%rsp)
mov    0x0(%rbp),%eax
mov    %eax,0x4(%rsp)
mov    $0x22b8,%edi
call   1060 <htons@plt>
mov    %eax,(%rsp)
mov    %rsp,%rsi
mov    %ebx,%edi
mov    $0xc,%edx
call   10d0 <connect@plt>
test   %rax,%rax
js     133e <main+0x17e>
lea    0xdfa(%rip),%rdi
call   1040 <puts@plt>
lea    0xdf9(%rip),%rdi
call   1080 <printf@plt>
lea    0xdfe(%rip),%rdi
lea    0x10(%rsp),%rbp
mov    %rbp,%rsi
call   10b0 <scanf@plt>
mov    %rbp,%rdi
call   1050 <strlen@plt>
mov    %ebx,%edi
mov    %rbp,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1070 <send@plt>
test   %rax,%rax
js     1304 <main+0x144>
lea    0x400(%rsp),%r14
lea    0xde2(%rip),%r15
lea    0xdaf(%rip),%r12
lea    0xdb9(%rip),%r13
lea    0x10(%rsp),%rbp
nop
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x7d0,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
test   %rax,%rax
js     1317 <main+0x157>
mov    %r15,%rdi
call   1040 <puts@plt>
mov    %r14,%rdi
call   1040 <puts@plt>
mov    %r12,%rdi
call   1080 <printf@plt>
mov    %r13,%rdi
mov    %rbp,%rsi
call   10b0 <scanf@plt>
mov    %rbp,%rdi
call   1050 <strlen@plt>
mov    %ebx,%edi
mov    %rbp,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1070 <send@plt>
test   %rax,%rax
jns    12b0 <main+0xf0>
lea    0xd5b(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%eax
jmp    132c <main+0x16c>
lea    0xd54(%rip),%rdi
call   1040 <puts@plt>
mov    %ebx,%edi
call   1090 <close@plt>
xor    %eax,%eax
add    $0xbd8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xcec(%rip),%rdi
call   10c0 <perror@plt>
jmp    1310 <main+0x150>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, i32, %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str = [24 x i8] c"Could not create socket\00"
@.str.1 = [15 x i8] c"Socket created\00"
@.str.2 = [10 x i8] c"127.0.0.1\00"
@.str.3 = [22 x i8] c"connect failed. Error\00"
@.str.4 = [11 x i8] c"Connected\0A\00"
@.str.5 = [17 x i8] c"Enter message : \00"
@.str.6 = [3 x i8] c"%s\00"
@.str.7 = [12 x i8] c"Send failed\00"
@.str.8 = [12 x i8] c"recv failed\00"
@.str.9 = [15 x i8] c"Server reply :\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca %struct.sockaddr_in
%8 = alloca [1000 x i8]
%9 = alloca [2000 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* @AF_INET
%11 = load i32, i32* @SOCK_STREAM
%12 = call i32 @socket(i32 %10, i32 %11, i32 0)
store i32 %12, i32* %6
%13 = load i32, i32* %6
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %17
15: ; preds = %2
%16 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
br label %17
17: ; preds = %15, %2
%18 = call i32 @puts(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
%19 = call i32 @inet_addr(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
%20 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 2
%21 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %20, i32 0, i32 0
store i32 %19, i32* %21
%22 = load i32, i32* @AF_INET
%23 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 1
store i32 %22, i32* %23
%24 = call i32 @htons(i32 8888)
%25 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 0
store i32 %24, i32* %25
%26 = load i32, i32* %6
%27 = bitcast %struct.sockaddr_in* %7 to %struct.sockaddr*
%28 = call i64 @connect(i32 %26, %struct.sockaddr* %27, i32 12)
%29 = icmp slt i64 %28, 0
br i1 %29, label %30, label %32
30: ; preds = %17
%31 = call i32 @perror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0))
store i32 1, i32* %3
br label %60
32: ; preds = %17
%33 = call i32 @puts(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0))
br label %34
34: ; preds = %32, %53
%35 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0))
%36 = getelementptr inbounds [1000 x i8], [1000 x i8]* %8, i64 0, i64 0
%37 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i8* %36)
%38 = load i32, i32* %6
%39 = getelementptr inbounds [1000 x i8], [1000 x i8]* %8, i64 0, i64 0
%40 = getelementptr inbounds [1000 x i8], [1000 x i8]* %8, i64 0, i64 0
%41 = call i32 @strlen(i8* %40)
%42 = call i64 @send(i32 %38, i8* %39, i32 %41, i32 0)
%43 = icmp slt i64 %42, 0
br i1 %43, label %44, label %46
44: ; preds = %34
%45 = call i32 @puts(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.7, i64 0, i64 0))
store i32 1, i32* %3
br label %60
46: ; preds = %34
%47 = load i32, i32* %6
%48 = getelementptr inbounds [2000 x i8], [2000 x i8]* %9, i64 0, i64 0
%49 = call i64 @recv(i32 %47, i8* %48, i32 2000, i32 0)
%50 = icmp slt i64 %49, 0
br i1 %50, label %51, label %53
51: ; preds = %46
%52 = call i32 @puts(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.8, i64 0, i64 0))
br label %57
53: ; preds = %46
%54 = call i32 @puts(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.9, i64 0, i64 0))
%55 = getelementptr inbounds [2000 x i8], [2000 x i8]* %9, i64 0, i64 0
%56 = call i32 @puts(i8* %55)
br label %34
57: ; preds = %51
%58 = load i32, i32* %6
%59 = call i32 @close(i32 %58)
store i32 0, i32* %3
br label %60
60: ; preds = %57, %44, %30
%61 = load i32, i32* %3
ret i32 %61
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, i32, %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str = [24 x i8] c"Could not create socket\00"
@.str.1 = [15 x i8] c"Socket created\00"
@.str.2 = [10 x i8] c"127.0.0.1\00"
@.str.3 = [22 x i8] c"connect failed. Error\00"
@.str.4 = [11 x i8] c"Connected\0A\00"
@.str.5 = [17 x i8] c"Enter message : \00"
@.str.6 = [3 x i8] c"%s\00"
@.str.7 = [12 x i8] c"Send failed\00"
@.str.8 = [12 x i8] c"recv failed\00"
@.str.9 = [15 x i8] c"Server reply :\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca [1000 x i8]
%5 = alloca [2000 x i8]
%6 = bitcast %struct.sockaddr_in* %3 to i8*
%7 = getelementptr inbounds [1000 x i8], [1000 x i8]* %4, i64 0, i64 0
%8 = getelementptr inbounds [2000 x i8], [2000 x i8]* %5, i64 0, i64 0
%9 = load i32, i32* @AF_INET
%10 = load i32, i32* @SOCK_STREAM
%11 = tail call i32 @socket(i32 %9, i32 %10, i32 0)
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %15
13: ; preds = %2
%14 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
br label %15
15: ; preds = %13, %2
%16 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
%17 = tail call i32 @inet_addr(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
%18 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2, i32 0
store i32 %17, i32* %18
%19 = load i32, i32* @AF_INET
%20 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1
store i32 %19, i32* %20
%21 = tail call i32 @htons(i32 8888)
%22 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
store i32 %21, i32* %22
%23 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%24 = call i64 @connect(i32 %11, %struct.sockaddr* %23, i32 12)
%25 = icmp slt i64 %24, 0
br i1 %25, label %26, label %28
26: ; preds = %15
%27 = call i32 @perror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0))
br label %51
28: ; preds = %15
%29 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0))
%30 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0))
%31 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i8* %7)
%32 = call i32 @strlen(i8* %7)
%33 = call i64 @send(i32 %11, i8* %7, i32 %32, i32 0)
%34 = icmp slt i64 %33, 0
br i1 %34, label %35, label %37
35: ; preds = %43, %28
%36 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.7, i64 0, i64 0))
br label %51
37: ; preds = %28, %43
%38 = call i64 @recv(i32 %11, i8* %8, i32 2000, i32 0)
%39 = icmp slt i64 %38, 0
br i1 %39, label %40, label %43
40: ; preds = %37
%41 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.8, i64 0, i64 0))
%42 = call i32 @close(i32 %11)
br label %51
43: ; preds = %37
%44 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.9, i64 0, i64 0))
%45 = call i32 @puts(i8* %8)
%46 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0))
%47 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i8* %7)
%48 = call i32 @strlen(i8* %7)
%49 = call i64 @send(i32 %11, i8* %7, i32 %48, i32 0)
%50 = icmp slt i64 %49, 0
br i1 %50, label %35, label %37
51: ; preds = %40, %35, %26
%52 = phi i32 [ 1, %26 ], [ 1, %35 ], [ 0, %40 ]
ret i32 %52
}