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

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int recv(int, char *, int, int /*<<< orphan*/);
int send(int, char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int sendrecv(int sock, char *s, int slen, char *r, int rlen) {
  int numbytes;
  if (send(sock, s, slen, 0) == -1) {
    fprintf(stderr, "Error sending data to server\n");
    return -1;
  }
  memset(r, 0, rlen);
  if ((numbytes = recv(sock, r, rlen, 0)) == -1) {
    fprintf(stderr, "Error reading from server\n");
    return -1;
  }
  return numbytes;
}


x86 assembly (clang, -O0):
<sendrecv>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8d,-0x24(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
xor    %ecx,%ecx
call   1040 <send@plt>
cmp    $0xffffffff,%eax
jne    1195 <sendrecv+0x55>
mov    0x2e65(%rip),%rax
mov    (%rax),%edi
lea    0xe7c(%rip),%rsi
call   1060 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11e7 <sendrecv+0xa7>
mov    -0x20(%rbp),%rdi
mov    -0x24(%rbp),%edx
xor    %esi,%esi
call   1050 <memset@plt>
mov    -0x8(%rbp),%edi
mov    -0x20(%rbp),%rsi
mov    -0x24(%rbp),%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,-0x28(%rbp)
cmp    $0xffffffff,%eax
jne    11e1 <sendrecv+0xa1>
mov    0x2e19(%rip),%rax
mov    (%rax),%edi
lea    0xe4e(%rip),%rsi
call   1060 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11e7 <sendrecv+0xa7>
mov    -0x28(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sendrecv>:
push   %rbp
push   %r14
push   %rbx
mov    %r8d,%r14d
mov    %rcx,%rbx
mov    %edi,%ebp
xor    %ecx,%ecx
call   1040 <send@plt>
cmp    $0xffffffff,%eax
je     1182 <sendrecv+0x42>
mov    %rbx,%rdi
xor    %esi,%esi
mov    %r14d,%edx
call   1050 <memset@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r14d,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
cmp    $0xffffffff,%eax
jne    119c <sendrecv+0x5c>
lea    0xe9e(%rip),%rsi
jmp    1189 <sendrecv+0x49>
lea    0xe77(%rip),%rsi
mov    0x2e50(%rip),%rax
mov    (%rax),%edi
call   1060 <fprintf@plt>
mov    $0xffffffff,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [30 x i8] c"Error sending data to server\0A\00"
@.str.1 = [27 x i8] c"Error reading from server\0A\00"
define i32 @sendrecv(i32 %0, i8* %1, i32 %2, i8* %3, i32 %4) {
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i32
%12 = alloca i32
store i32 %0, i32* %7
store i8* %1, i8** %8
store i32 %2, i32* %9
store i8* %3, i8** %10
store i32 %4, i32* %11
%13 = load i32, i32* %7
%14 = load i8*, i8** %8
%15 = load i32, i32* %9
%16 = call i32 @send(i32 %13, i8* %14, i32 %15, i32 0)
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %21
18: ; preds = %5
%19 = load i32, i32* @stderr
%20 = call i32 @fprintf(i32 %19, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %6
br label %35
21: ; preds = %5
%22 = load i8*, i8** %10
%23 = load i32, i32* %11
%24 = call i32 @memset(i8* %22, i32 0, i32 %23)
%25 = load i32, i32* %7
%26 = load i8*, i8** %10
%27 = load i32, i32* %11
%28 = call i32 @recv(i32 %25, i8* %26, i32 %27, i32 0)
store i32 %28, i32* %12
%29 = icmp eq i32 %28, -1
br i1 %29, label %30, label %33
30: ; preds = %21
%31 = load i32, i32* @stderr
%32 = call i32 @fprintf(i32 %31, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %6
br label %35
33: ; preds = %21
%34 = load i32, i32* %12
store i32 %34, i32* %6
br label %35
35: ; preds = %33, %30, %18
%36 = load i32, i32* %6
ret i32 %36
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [30 x i8] c"Error sending data to server\0A\00"
@.str.1 = [27 x i8] c"Error reading from server\0A\00"
define i32 @sendrecv(i32 %0, i8* %1, i32 %2, i8* %3, i32 %4) {
%6 = tail call i32 @send(i32 %0, i8* %1, i32 %2, i32 0)
%7 = icmp eq i32 %6, -1
br i1 %7, label %12, label %8
8: ; preds = %5
%9 = tail call i32 @memset(i8* %3, i32 0, i32 %4)
%10 = tail call i32 @recv(i32 %0, i8* %3, i32 %4, i32 0)
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %16
12: ; preds = %8, %5
%13 = phi i8* [ getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), %5 ], [ getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), %8 ]
%14 = load i32, i32* @stderr
%15 = tail call i32 @fprintf(i32 %14, i8* %13)
br label %16
16: ; preds = %12, %8
%17 = phi i32 [ %10, %8 ], [ -1, %12 ]
ret i32 %17
}