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

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ PF_INET;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ connect(int, struct sockaddr *, int);
char *format_message_package(char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
char *get_final_message(char *);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ inet_addr(char *);
int /*<<< orphan*/ memset(int /*<<< orphan*/, char, int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ recv(int, char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ scanf(char *, char *);
int send(int, char *, int /*<<< orphan*/, int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strlen(char *);
int main(int argc, char *argv[]) {
  int clientSocket;
  char buffer[1024];
  struct sockaddr_in serverAddr;
  socklen_t addr_size;
  clientSocket = socket(PF_INET, SOCK_STREAM, 0);
  serverAddr.sin_family = AF_INET;
  serverAddr.sin_port = htons(7891);
  serverAddr.sin_addr.s_addr = inet_addr("127.0.0.1");
  memset(serverAddr.sin_zero, '\0', sizeof serverAddr.sin_zero);
  addr_size = sizeof serverAddr;
  connect(clientSocket, (struct sockaddr *)&serverAddr, addr_size);
  char *values;
  scanf("%[^\n]s", values);
  char *message_package = format_message_package(values);
  if (send(clientSocket, message_package, strlen(message_package), 0) == -1)
    printf("send");
  recv(clientSocket, buffer, 1024, 0);
  char *final_message = get_final_message(buffer);
  fprintf(stderr, "%s\n", final_message);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x460,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2dd8(%rip),%rax
mov    (%rax),%edi
mov    0x2dd7(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10f0 <socket@plt>
mov    %eax,-0x14(%rbp)
mov    0x2ddc(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x424(%rbp)
mov    $0x1ed3,%edi
call   1060 <htons@plt>
mov    %eax,-0x428(%rbp)
lea    0xdd5(%rip),%rdi
call   10b0 <inet_addr@plt>
mov    %eax,-0x42c(%rbp)
mov    -0x430(%rbp),%edi
xor    %esi,%esi
mov    $0x4,%edx
call   10a0 <memset@plt>
movl   $0x10,-0x434(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x430(%rbp),%rsi
mov    -0x434(%rbp),%edx
call   10e0 <connect@plt>
mov    -0x440(%rbp),%rsi
lea    0xd95(%rip),%rdi
call   10d0 <scanf@plt>
mov    -0x440(%rbp),%rdi
call   1090 <format_message_package@plt>
mov    %rax,-0x448(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x45c(%rbp)
mov    -0x448(%rbp),%rax
mov    %rax,-0x458(%rbp)
mov    -0x448(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x45c(%rbp),%edi
mov    -0x458(%rbp),%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1070 <send@plt>
cmp    $0xffffffff,%eax
jne    12db <main+0x10b>
lea    0xd3b(%rip),%rdi
call   1080 <printf@plt>
mov    -0x14(%rbp),%edi
lea    -0x420(%rbp),%rsi
mov    $0x400,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
lea    -0x420(%rbp),%rdi
call   1040 <get_final_message@plt>
mov    %rax,-0x450(%rbp)
mov    0x2ccd(%rip),%rax
mov    (%rax),%edi
mov    -0x450(%rbp),%rdx
lea    0xcfb(%rip),%rsi
call   10c0 <fprintf@plt>
xor    %eax,%eax
add    $0x460,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
sub    $0x418,%rsp
mov    0x2de8(%rip),%rax
mov    (%rax),%edi
mov    0x2de7(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10f0 <socket@plt>
mov    %eax,%ebp
mov    0x2ded(%rip),%rax
mov    (%rax),%eax
mov    %eax,0xc(%rsp)
mov    $0x1ed3,%edi
call   1060 <htons@plt>
mov    %eax,0x8(%rsp)
lea    0xdea(%rip),%rdi
call   10b0 <inet_addr@plt>
mov    %eax,0x4(%rsp)
xor    %esi,%esi
mov    $0x4,%edx
call   10a0 <memset@plt>
mov    %rsp,%rsi
mov    %ebp,%edi
mov    $0x10,%edx
call   10e0 <connect@plt>
lea    0xdc9(%rip),%rdi
call   10d0 <scanf@plt>
call   1090 <format_message_package@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1050 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1070 <send@plt>
cmp    $0xffffffff,%eax
jne    1275 <main+0xa5>
lea    0xda1(%rip),%rdi
call   1080 <printf@plt>
lea    0x10(%rsp),%rbx
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x400,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %rbx,%rdi
call   1040 <get_final_message@plt>
mov    0x2d3e(%rip),%rcx
mov    (%rcx),%edi
lea    0xd73(%rip),%rsi
mov    %rax,%rdx
call   10c0 <fprintf@plt>
xor    %eax,%eax
add    $0x418,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@PF_INET = global i32 0
@SOCK_STREAM = global i32 0
@AF_INET = global i32 0
@.str = [10 x i8] c"127.0.0.1\00"
@.str.1 = [7 x i8] c"%[^\0A]s\00"
@.str.2 = [5 x i8] c"send\00"
@stderr = global i32 0
@.str.3 = [4 x i8] c"%s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca [1024 x i8]
%8 = alloca %struct.sockaddr_in
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%13 = load i32, i32* @PF_INET
%14 = load i32, i32* @SOCK_STREAM
%15 = call i32 @socket(i32 %13, i32 %14, i32 0)
store i32 %15, i32* %6
%16 = load i32, i32* @AF_INET
%17 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 3
store i32 %16, i32* %17
%18 = call i32 @htons(i32 7891)
%19 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 2
store i32 %18, i32* %19
%20 = call i32 @inet_addr(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%21 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 1
%22 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %21, i32 0, i32 0
store i32 %20, i32* %22
%23 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 0
%24 = load i32, i32* %23
%25 = call i32 @memset(i32 %24, i8 signext 0, i32 4)
store i32 16, i32* %9
%26 = load i32, i32* %6
%27 = bitcast %struct.sockaddr_in* %8 to %struct.sockaddr*
%28 = load i32, i32* %9
%29 = call i32 @connect(i32 %26, %struct.sockaddr* %27, i32 %28)
%30 = load i8*, i8** %10
%31 = call i32 @scanf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8* %30)
%32 = load i8*, i8** %10
%33 = call i8* @format_message_package(i8* %32)
store i8* %33, i8** %11
%34 = load i32, i32* %6
%35 = load i8*, i8** %11
%36 = load i8*, i8** %11
%37 = call i32 @strlen(i8* %36)
%38 = call i32 @send(i32 %34, i8* %35, i32 %37, i32 0)
%39 = icmp eq i32 %38, -1
br i1 %39, label %40, label %42
40: ; preds = %2
%41 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
br label %42
42: ; preds = %40, %2
%43 = load i32, i32* %6
%44 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, 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]* %7, i64 0, i64 0
%47 = call i8* @get_final_message(i8* %46)
store i8* %47, i8** %12
%48 = load i32, i32* @stderr
%49 = load i8*, i8** %12
%50 = call i32 @fprintf(i32 %48, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %49)
ret i32 0
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@PF_INET = global i32 0
@SOCK_STREAM = global i32 0
@AF_INET = global i32 0
@.str = [10 x i8] c"127.0.0.1\00"
@.str.1 = [7 x i8] c"%[^\0A]s\00"
@.str.2 = [5 x i8] c"send\00"
@stderr = global i32 0
@.str.3 = [4 x i8] c"%s\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [1024 x i8]
%4 = alloca %struct.sockaddr_in
%5 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%6 = bitcast %struct.sockaddr_in* %4 to i8*
%7 = load i32, i32* @PF_INET
%8 = load i32, i32* @SOCK_STREAM
%9 = tail call i32 @socket(i32 %7, i32 %8, i32 0)
%10 = load i32, i32* @AF_INET
%11 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 3
store i32 %10, i32* %11
%12 = tail call i32 @htons(i32 7891)
%13 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 2
store i32 %12, i32* %13
%14 = tail call i32 @inet_addr(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%15 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 1, i32 0
store i32 %14, i32* %15
%16 = tail call i32 @memset(i32 undef, i8 signext 0, i32 4)
%17 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%18 = call i32 @connect(i32 %9, %struct.sockaddr* %17, i32 16)
%19 = call i32 @scanf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8* undef)
%20 = call i8* @format_message_package(i8* undef)
%21 = call i32 @strlen(i8* %20)
%22 = call i32 @send(i32 %9, i8* %20, i32 %21, i32 0)
%23 = icmp eq i32 %22, -1
br i1 %23, label %24, label %26
24: ; preds = %2
%25 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
br label %26
26: ; preds = %24, %2
%27 = call i32 @recv(i32 %9, i8* %5, i32 1024, i32 0)
%28 = call i8* @get_final_message(i8* %5)
%29 = load i32, i32* @stderr
%30 = call i32 @fprintf(i32 %29, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %28)
ret i32 0
}