#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*/ server_addr;
typedef int /*<<< orphan*/ sendbuf;
typedef int /*<<< orphan*/ recvbuf;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ close(int);
scalar_t__ connect(int, struct sockaddr *, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ inet_addr(char *);
int /*<<< orphan*/ memset(void *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ recv(int, char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ scanf(char *, char *);
int /*<<< orphan*/ send(int, char *, int, int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  int client_socket;
  if ((client_socket = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
    perror("socket()");
    exit(1);
  }
  struct sockaddr_in server_addr;
  memset((void *)&server_addr, 0, sizeof(server_addr));
  server_addr.sin_family = AF_INET;
  server_addr.sin_port = htons(5555);
  server_addr.sin_addr.s_addr = inet_addr("127.0.0.1");
  if (connect(client_socket, (struct sockaddr *)&server_addr,
              sizeof(server_addr)) < 0) {
    perror("connect()");
    exit(1);
  } else {
    printf("Connect success ...\n");
  }
  char sendbuf[1024];
  char recvbuf[1024];
  printf("Input client message:>");
  scanf("%s", sendbuf);
  send(client_socket, sendbuf, sizeof(sendbuf), 0);
  recv(client_socket, recvbuf, sizeof(recvbuf), 0);
  printf("recv data from server is: %s\n", recvbuf);
  close(client_socket);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x820,%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)
cmp    $0x0,%eax
jge    1214 <main+0x54>
lea    0xdfb(%rip),%rdi
call   10b0 <perror@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
lea    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1070 <memset@plt>
mov    0x2dbd(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    $0x15b3,%edi
call   1040 <htons@plt>
mov    %eax,-0x1c(%rbp)
lea    0xdc5(%rip),%rdi
call   1090 <inet_addr@plt>
mov    %eax,-0x20(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0xc,%edx
call   10d0 <connect@plt>
cmp    $0x0,%rax
jge    127d <main+0xbd>
lea    0xda5(%rip),%rdi
call   10b0 <perror@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
lea    0xd99(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    0xda0(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    -0x420(%rbp),%rsi
lea    0xda2(%rip),%rdi
call   10a0 <scanf@plt>
mov    -0x14(%rbp),%edi
lea    -0x420(%rbp),%rsi
mov    $0x400,%edx
xor    %ecx,%ecx
call   1050 <send@plt>
mov    -0x14(%rbp),%edi
lea    -0x820(%rbp),%rsi
mov    $0x400,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
lea    -0x820(%rbp),%rsi
lea    0xd66(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x14(%rbp),%edi
call   1080 <close@plt>
xor    %eax,%eax
add    $0x820,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x810,%rsp
mov    0x2e05(%rip),%r15
mov    (%r15),%edi
mov    0x2deb(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10f0 <socket@plt>
test   %eax,%eax
js     12cd <main+0xfd>
mov    %eax,%ebx
mov    %rsp,%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1080 <memset@plt>
mov    (%r15),%eax
mov    %eax,0x8(%rsp)
mov    $0x15b3,%edi
call   1050 <htons@plt>
mov    %eax,0x4(%rsp)
lea    0xddb(%rip),%rdi
call   10a0 <inet_addr@plt>
mov    %eax,(%rsp)
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0xc,%edx
call   10e0 <connect@plt>
test   %rax,%rax
js     12d6 <main+0x106>
lea    0xe00(%rip),%rdi
call   1040 <puts@plt>
lea    0xdbc(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
lea    0xdc5(%rip),%rdi
lea    0x410(%rsp),%r14
mov    %r14,%rsi
call   10b0 <scanf@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x400,%edx
xor    %ecx,%ecx
call   1060 <send@plt>
lea    0x10(%rsp),%r14
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x400,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
lea    0xd8a(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %ebx,%edi
call   1090 <close@plt>
xor    %eax,%eax
add    $0x810,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xd2c(%rip),%rdi
jmp    12dd <main+0x10d>
lea    0xd36(%rip),%rdi
call   10c0 <perror@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>

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 = [9 x i8] c"socket()\00"
@.str.1 = [10 x i8] c"127.0.0.1\00"
@.str.2 = [10 x i8] c"connect()\00"
@.str.3 = [21 x i8] c"Connect success ...\0A\00"
@.str.4 = [23 x i8] c"Input client message:>\00"
@.str.5 = [3 x i8] c"%s\00"
@.str.6 = [30 x i8] c"recv data from server is: %s\0A\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 [1024 x i8]
%9 = alloca [1024 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 = icmp slt i32 %12, 0
br i1 %13, label %14, label %17
14: ; preds = %2
%15 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%16 = call i32 @exit(i32 1)
unreachable
17: ; preds = %2
%18 = bitcast %struct.sockaddr_in* %7 to i8*
%19 = call i32 @memset(i8* %18, i32 0, i32 12)
%20 = load i32, i32* @AF_INET
%21 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 2
store i32 %20, i32* %21
%22 = call i32 @htons(i32 5555)
%23 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 1
store i32 %22, i32* %23
%24 = call i32 @inet_addr(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%25 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 0
%26 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %25, i32 0, i32 0
store i32 %24, i32* %26
%27 = load i32, i32* %6
%28 = bitcast %struct.sockaddr_in* %7 to %struct.sockaddr*
%29 = call i64 @connect(i32 %27, %struct.sockaddr* %28, i32 12)
%30 = icmp slt i64 %29, 0
br i1 %30, label %31, label %34
31: ; preds = %17
%32 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
%33 = call i32 @exit(i32 1)
unreachable
34: ; preds = %17
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0))
br label %36
36: ; preds = %34
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0))
%38 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%39 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i8* %38)
%40 = load i32, i32* %6
%41 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%42 = call i32 @send(i32 %40, i8* %41, i32 1024, i32 0)
%43 = load i32, i32* %6
%44 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%45 = call i32 @recv(i32 %43, i8* %44, i32 1024, i32 0)
%46 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.6, i64 0, i64 0), i8* %46)
%48 = load i32, i32* %6
%49 = call i32 @close(i32 %48)
ret i32 0
}

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 = [9 x i8] c"socket()\00"
@.str.1 = [10 x i8] c"127.0.0.1\00"
@.str.2 = [10 x i8] c"connect()\00"
@.str.4 = [23 x i8] c"Input client message:>\00"
@.str.5 = [3 x i8] c"%s\00"
@.str.6 = [30 x i8] c"recv data from server is: %s\0A\00"
@str = [20 x i8] c"Connect success ...\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca [1024 x i8]
%5 = alloca [1024 x i8]
%6 = load i32, i32* @AF_INET
%7 = load i32, i32* @SOCK_STREAM
%8 = tail call i32 @socket(i32 %6, i32 %7, i32 0)
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %13
10: ; preds = %2
%11 = tail call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%12 = tail call i32 @exit(i32 1)
unreachable
13: ; preds = %2
%14 = bitcast %struct.sockaddr_in* %3 to i8*
%15 = call i32 @memset(i8* %14, i32 0, i32 12)
%16 = load i32, i32* @AF_INET
%17 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %16, i32* %17
%18 = call i32 @htons(i32 5555)
%19 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 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* %3, i64 0, i32 0, i32 0
store i32 %20, i32* %21
%22 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%23 = call i64 @connect(i32 %8, %struct.sockaddr* %22, i32 12)
%24 = icmp slt i64 %23, 0
br i1 %24, label %25, label %28
25: ; preds = %13
%26 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
%27 = call i32 @exit(i32 1)
unreachable
28: ; preds = %13
%29 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str, i64 0, i64 0))
%30 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%31 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%32 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0))
%33 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i8* %30)
%34 = call i32 @send(i32 %8, i8* %30, i32 1024, i32 0)
%35 = call i32 @recv(i32 %8, i8* %31, i32 1024, i32 0)
%36 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.6, i64 0, i64 0), i8* %31)
%37 = call i32 @close(i32 %8)
ret i32 0
}