#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 */

/* Type definitions */
typedef int /*<<< orphan*/ server_reply;

/* Variables and functions */
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
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 /*<<< orphan*/ strlen(char *);
void send_receive_message(int sock) {
  int read_size;
  char message[1000], server_reply[2000];
  while (1) {
    printf("Enter message : ");
    scanf("%s", message);
    if (send(sock, message, strlen(message), 0) < 0) {
      puts("Send failed");
      return;
    }
    if (recv(sock, server_reply, 2000, 0) < 0) {
      puts("recv failed");
      break;
    }
    puts("Server reply :");
    puts(server_reply);
    memset(server_reply, 0, sizeof(server_reply));
  }
}


x86 assembly (clang, -O0):
<send_receive_message>:
push   %rbp
mov    %rsp,%rbp
sub    $0xbd0,%rsp
mov    %edi,-0x4(%rbp)
lea    0xe7b(%rip),%rdi
call   1070 <printf@plt>
lea    -0x3f0(%rbp),%rsi
lea    0xe79(%rip),%rdi
call   1090 <scanf@plt>
mov    -0x4(%rbp),%eax
mov    %eax,-0xbcc(%rbp)
lea    -0x3f0(%rbp),%rax
mov    %rax,-0xbc8(%rbp)
lea    -0x3f0(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0xbcc(%rbp),%edi
mov    -0xbc8(%rbp),%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1060 <send@plt>
cmp    $0x0,%rax
jge    11f1 <send_receive_message+0x81>
lea    0xe2d(%rip),%rdi
call   1040 <puts@plt>
jmp    1252 <send_receive_message+0xe2>
mov    -0x4(%rbp),%edi
lea    -0xbc0(%rbp),%rsi
mov    $0x7d0,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
cmp    $0x0,%rax
jge    1222 <send_receive_message+0xb2>
lea    0xe08(%rip),%rdi
call   1040 <puts@plt>
jmp    1252 <send_receive_message+0xe2>
lea    0xe03(%rip),%rdi
call   1040 <puts@plt>
lea    -0xbc0(%rbp),%rdi
call   1040 <puts@plt>
lea    -0xbc0(%rbp),%rdi
xor    %esi,%esi
mov    $0x7d0,%edx
call   1080 <memset@plt>
jmp    117e <send_receive_message+0xe>
add    $0xbd0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<send_receive_message>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xbc8,%rsp
mov    %edi,%ebx
lea    0xe76(%rip),%rdi
call   1070 <printf@plt>
lea    0xe7b(%rip),%rdi
mov    %rsp,%rbp
mov    %rbp,%rsi
call   1090 <scanf@plt>
mov    %rbp,%rdi
call   1050 <strlen@plt>
mov    %ebx,%edi
mov    %rbp,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1060 <send@plt>
lea    0xe56(%rip),%rdi
test   %rax,%rax
js     1263 <send_receive_message+0xf3>
lea    0x3f0(%rsp),%r15
lea    0xe56(%rip),%r12
lea    0xe23(%rip),%r13
lea    0xe2d(%rip),%rbp
mov    %rsp,%r14
nopw   0x0(%rax,%rax,1)
mov    %ebx,%edi
mov    %r15,%rsi
mov    $0x7d0,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
test   %rax,%rax
js     125c <send_receive_message+0xec>
mov    %r12,%rdi
call   1040 <puts@plt>
mov    %r15,%rdi
call   1040 <puts@plt>
mov    %r15,%rdi
xor    %esi,%esi
mov    $0x7d0,%edx
call   1080 <memset@plt>
mov    %r13,%rdi
call   1070 <printf@plt>
mov    %rbp,%rdi
mov    %r14,%rsi
call   1090 <scanf@plt>
mov    %r14,%rdi
call   1050 <strlen@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1060 <send@plt>
test   %rax,%rax
jns    11f0 <send_receive_message+0x80>
lea    0xdba(%rip),%rdi
jmp    1263 <send_receive_message+0xf3>
lea    0xdbd(%rip),%rdi
call   1040 <puts@plt>
add    $0xbc8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [17 x i8] c"Enter message : \00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [12 x i8] c"Send failed\00"
@.str.3 = [12 x i8] c"recv failed\00"
@.str.4 = [15 x i8] c"Server reply :\00"
define void @send_receive_message(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca [1000 x i8]
%5 = alloca [2000 x i8]
store i32 %0, i32* %2
br label %6
6: ; preds = %1, %25
%7 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%8 = getelementptr inbounds [1000 x i8], [1000 x i8]* %4, i64 0, i64 0
%9 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %8)
%10 = load i32, i32* %2
%11 = getelementptr inbounds [1000 x i8], [1000 x i8]* %4, i64 0, i64 0
%12 = getelementptr inbounds [1000 x i8], [1000 x i8]* %4, i64 0, i64 0
%13 = call i32 @strlen(i8* %12)
%14 = call i64 @send(i32 %10, i8* %11, i32 %13, i32 0)
%15 = icmp slt i64 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %6
%17 = call i32 @puts(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
br label %31
18: ; preds = %6
%19 = load i32, i32* %2
%20 = getelementptr inbounds [2000 x i8], [2000 x i8]* %5, i64 0, i64 0
%21 = call i64 @recv(i32 %19, i8* %20, i32 2000, i32 0)
%22 = icmp slt i64 %21, 0
br i1 %22, label %23, label %25
23: ; preds = %18
%24 = call i32 @puts(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0))
br label %31
25: ; preds = %18
%26 = call i32 @puts(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0))
%27 = getelementptr inbounds [2000 x i8], [2000 x i8]* %5, i64 0, i64 0
%28 = call i32 @puts(i8* %27)
%29 = getelementptr inbounds [2000 x i8], [2000 x i8]* %5, i64 0, i64 0
%30 = call i32 @memset(i8* %29, i32 0, i32 2000)
br label %6
31: ; preds = %16, %23
ret void
}

LLVM IR (-O2):
@.str = [17 x i8] c"Enter message : \00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [12 x i8] c"Send failed\00"
@.str.3 = [12 x i8] c"recv failed\00"
@.str.4 = [15 x i8] c"Server reply :\00"
define void @send_receive_message(i32 %0) {
%2 = alloca [1000 x i8]
%3 = alloca [2000 x i8]
%4 = getelementptr inbounds [1000 x i8], [1000 x i8]* %2, i64 0, i64 0
%5 = getelementptr inbounds [2000 x i8], [2000 x i8]* %3, i64 0, i64 0
%6 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%7 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %4)
%8 = call i32 @strlen(i8* %4)
%9 = call i64 @send(i32 %0, i8* %4, i32 %8, i32 0)
%10 = icmp slt i64 %9, 0
br i1 %10, label %23, label %11
11: ; preds = %1, %14
%12 = call i64 @recv(i32 %0, i8* %5, i32 2000, i32 0)
%13 = icmp slt i64 %12, 0
br i1 %13, label %23, label %14
14: ; preds = %11
%15 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0))
%16 = call i32 @puts(i8* %5)
%17 = call i32 @memset(i8* %5, i32 0, i32 2000)
%18 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%19 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %4)
%20 = call i32 @strlen(i8* %4)
%21 = call i64 @send(i32 %0, i8* %4, i32 %20, i32 0)
%22 = icmp slt i64 %21, 0
br i1 %22, label %23, label %11
23: ; preds = %11, %14, %1
%24 = phi i8* [ getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), %1 ], [ getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), %14 ], [ getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), %11 ]
%25 = call i32 @puts(i8* dereferenceable(1) %24)
ret void
}