#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 ssize_t;

/* Variables and functions */
int errno;
int /*<<< orphan*/ memset(void *, int /*<<< orphan*/, size_t);
int recv(int, void *, size_t, int /*<<< orphan*/);
int send(int, void const *, size_t, int /*<<< orphan*/);
void send_recv(int comm_socket, const void *data, size_t data_len, void *buffer,
               size_t buf_len, ssize_t *byte_sent, ssize_t *byte_rcvd,
               int *send_errno, int *recv_errno) {
  *byte_sent = send(comm_socket, data, data_len, 0);
  if (*byte_sent == -1) {
    *send_errno = errno;
  } else {
    *send_errno = 0;
  }
  if (*byte_sent == -1) {
    *byte_rcvd = 0;
    *recv_errno = 0;
    return;
  }
  memset(buffer, 0, buf_len);
  *byte_rcvd = recv(comm_socket, buffer, buf_len, 0);
  if (*byte_rcvd == -1) {
    *recv_errno = errno;
  } else {
    *recv_errno = 0;
  }
}


x86 assembly (clang, -O0):
<send_recv>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    0x20(%rbp),%rax
mov    0x18(%rbp),%rax
mov    0x10(%rbp),%rax
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9,-0x30(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
xor    %ecx,%ecx
call   1040 <send@plt>
mov    %eax,%ecx
mov    -0x30(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x30(%rbp),%rax
cmpl   $0xffffffff,(%rax)
jne    1196 <send_recv+0x66>
mov    0x2e57(%rip),%rax
mov    (%rax),%ecx
mov    0x18(%rbp),%rax
mov    %ecx,(%rax)
jmp    11a0 <send_recv+0x70>
mov    0x18(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x30(%rbp),%rax
cmpl   $0xffffffff,(%rax)
jne    11c6 <send_recv+0x96>
mov    0x10(%rbp),%rax
movl   $0x0,(%rax)
mov    0x20(%rbp),%rax
movl   $0x0,(%rax)
jmp    121a <send_recv+0xea>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rdx
xor    %esi,%esi
call   1050 <memset@plt>
mov    -0x4(%rbp),%edi
mov    -0x20(%rbp),%rsi
mov    -0x28(%rbp),%rdx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,%ecx
mov    0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    0x10(%rbp),%rax
cmpl   $0xffffffff,(%rax)
jne    1210 <send_recv+0xe0>
mov    0x2ddd(%rip),%rax
mov    (%rax),%ecx
mov    0x20(%rbp),%rax
mov    %ecx,(%rax)
jmp    121a <send_recv+0xea>
mov    0x20(%rbp),%rax
movl   $0x0,(%rax)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<send_recv>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r9,%rbx
mov    %r8,%r14
mov    %rcx,%r15
mov    %edi,%ebp
mov    0x48(%rsp),%r12
xor    %r13d,%r13d
xor    %ecx,%ecx
call   1040 <send@plt>
mov    %eax,(%rbx)
mov    0x2e82(%rip),%rcx
cmp    $0xffffffff,%eax
jne    1166 <send_recv+0x36>
mov    (%rcx),%r13d
mov    0x50(%rsp),%rax
mov    0x40(%rsp),%rdx
mov    %r13d,(%r12)
cmpl   $0xffffffff,(%rbx)
je     11b4 <send_recv+0x84>
mov    %rax,%r12
xor    %ebx,%ebx
mov    %r15,%rdi
xor    %esi,%esi
mov    %rdx,%r13
mov    %r14,%rdx
call   1050 <memset@plt>
mov    %ebp,%edi
mov    %r15,%rsi
mov    %r14,%rdx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,0x0(%r13)
cmp    $0xffffffff,%eax
jne    11af <send_recv+0x7f>
mov    0x2e33(%rip),%rax
mov    (%rax),%ebx
mov    %r12,%rax
jmp    11bc <send_recv+0x8c>
movl   $0x0,(%rdx)
xor    %ebx,%ebx
mov    %ebx,(%rax)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@errno = global i32 0
define void @send_recv(i32 %0, i8* %1, i64 %2, i8* %3, i64 %4, i32* %5, i32* %6, i32* %7, i32* %8) {
%10 = alloca i32
%11 = alloca i8*
%12 = alloca i64
%13 = alloca i8*
%14 = alloca i64
%15 = alloca i32*
%16 = alloca i32*
%17 = alloca i32*
%18 = alloca i32*
store i32 %0, i32* %10
store i8* %1, i8** %11
store i64 %2, i64* %12
store i8* %3, i8** %13
store i64 %4, i64* %14
store i32* %5, i32** %15
store i32* %6, i32** %16
store i32* %7, i32** %17
store i32* %8, i32** %18
%19 = load i32, i32* %10
%20 = load i8*, i8** %11
%21 = load i64, i64* %12
%22 = call i32 @send(i32 %19, i8* %20, i64 %21, i32 0)
%23 = load i32*, i32** %15
store i32 %22, i32* %23
%24 = load i32*, i32** %15
%25 = load i32, i32* %24
%26 = icmp eq i32 %25, -1
br i1 %26, label %27, label %30
27: ; preds = %9
%28 = load i32, i32* @errno
%29 = load i32*, i32** %17
store i32 %28, i32* %29
br label %32
30: ; preds = %9
%31 = load i32*, i32** %17
store i32 0, i32* %31
br label %32
32: ; preds = %30, %27
%33 = load i32*, i32** %15
%34 = load i32, i32* %33
%35 = icmp eq i32 %34, -1
br i1 %35, label %36, label %39
36: ; preds = %32
%37 = load i32*, i32** %16
store i32 0, i32* %37
%38 = load i32*, i32** %18
store i32 0, i32* %38
br label %56
39: ; preds = %32
%40 = load i8*, i8** %13
%41 = load i64, i64* %14
%42 = call i32 @memset(i8* %40, i32 0, i64 %41)
%43 = load i32, i32* %10
%44 = load i8*, i8** %13
%45 = load i64, i64* %14
%46 = call i32 @recv(i32 %43, i8* %44, i64 %45, i32 0)
%47 = load i32*, i32** %16
store i32 %46, i32* %47
%48 = load i32*, i32** %16
%49 = load i32, i32* %48
%50 = icmp eq i32 %49, -1
br i1 %50, label %51, label %54
51: ; preds = %39
%52 = load i32, i32* @errno
%53 = load i32*, i32** %18
store i32 %52, i32* %53
br label %56
54: ; preds = %39
%55 = load i32*, i32** %18
store i32 0, i32* %55
br label %56
56: ; preds = %36, %54, %51
ret void
}

LLVM IR (-O2):
@errno = global i32 0
define void @send_recv(i32 %0, i8* %1, i64 %2, i8* %3, i64 %4, i32* nocapture %5, i32* nocapture writeonly %6, i32* nocapture writeonly %7, i32* nocapture writeonly %8) {
%10 = tail call i32 @send(i32 %0, i8* %1, i64 %2, i32 0)
store i32 %10, i32* %5
%11 = icmp eq i32 %10, -1
%12 = load i32, i32* @errno
%13 = select i1 %11, i32 %12, i32 0
store i32 %13, i32* %7
%14 = load i32, i32* %5
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %17
16: ; preds = %9
store i32 0, i32* %6
br label %23
17: ; preds = %9
%18 = tail call i32 @memset(i8* %3, i32 0, i64 %4)
%19 = tail call i32 @recv(i32 %0, i8* %3, i64 %4, i32 0)
store i32 %19, i32* %6
%20 = icmp eq i32 %19, -1
%21 = load i32, i32* @errno
%22 = select i1 %20, i32 %21, i32 0
br label %23
23: ; preds = %17, %16
%24 = phi i32 [ 0, %16 ], [ %22, %17 ]
store i32 %24, i32* %8
ret void
}