#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 scalar_t__ ssize_t;
typedef int /*<<< orphan*/ ch;

/* Variables and functions */
scalar_t__ EPIPE;
int /*<<< orphan*/ err(int, char *, char const *);
scalar_t__ errno;
int /*<<< orphan*/ errx(int, char *, char const *, scalar_t__);
scalar_t__ send(int, char *, int, int /*<<< orphan*/);
void test_send(const char *testname, int sock) {
  ssize_t len;
  char ch;
  ch = 0;
  len = send(sock, &ch, sizeof(ch), 0);
  if (len < 0) {
    if (errno == EPIPE)
      return;
    err(-1, "%s: send", testname);
  }
  errx(-1, "%s: send: returned %zd", testname, len);
}


x86 assembly (clang, -O0):
<test_send>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movb   $0x0,-0x19(%rbp)
mov    -0xc(%rbp),%edi
lea    -0x19(%rbp),%rsi
mov    $0x1,%edx
xor    %ecx,%ecx
call   1040 <send@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jge    1199 <test_send+0x69>
mov    0x2e6c(%rip),%rax
mov    (%rax),%rax
mov    0x2e6a(%rip),%rcx
cmp    (%rcx),%rax
jne    1184 <test_send+0x54>
jmp    11b2 <test_send+0x82>
mov    -0x8(%rbp),%rdx
mov    $0xffffffff,%edi
lea    0xe6c(%rip),%rsi
call   1050 <err@plt>
mov    -0x8(%rbp),%rdx
mov    -0x18(%rbp),%rcx
mov    $0xffffffff,%edi
lea    0xe5c(%rip),%rsi
call   1030 <errx@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_send>:
push   %r14
push   %rbx
push   %rax
mov    %esi,%eax
mov    %rdi,%r14
movb   $0x0,0x7(%rsp)
lea    0x7(%rsp),%rsi
mov    %eax,%edi
mov    $0x1,%edx
xor    %ecx,%ecx
call   1040 <send@plt>
mov    %rax,%rbx
test   %rax,%rax
jns    1183 <test_send+0x53>
mov    0x2e78(%rip),%rax
mov    (%rax),%rax
mov    0x2e76(%rip),%rcx
cmp    (%rcx),%rax
je     119a <test_send+0x6a>
lea    0xe8a(%rip),%rsi
mov    $0xffffffff,%edi
mov    %r14,%rdx
call   1050 <err@plt>
lea    0xe7f(%rip),%rsi
mov    $0xffffffff,%edi
mov    %r14,%rdx
mov    %rbx,%rcx
call   1030 <errx@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@errno = global i64 0
@EPIPE = global i64 0
@.str = [9 x i8] c"%s: send\00"
@.str.1 = [23 x i8] c"%s: send: returned %zd\00"
define void @test_send(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i64
%6 = alloca i8
store i8* %0, i8** %3
store i32 %1, i32* %4
store i8 0, i8* %6
%7 = load i32, i32* %4
%8 = call i64 @send(i32 %7, i8* %6, i32 1, i32 0)
store i64 %8, i64* %5
%9 = load i64, i64* %5
%10 = icmp slt i64 %9, 0
br i1 %10, label %11, label %19
11: ; preds = %2
%12 = load i64, i64* @errno
%13 = load i64, i64* @EPIPE
%14 = icmp eq i64 %12, %13
br i1 %14, label %15, label %16
15: ; preds = %11
br label %23
16: ; preds = %11
%17 = load i8*, i8** %3
%18 = call i32 @err(i32 -1, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* %17)
br label %19
19: ; preds = %16, %2
%20 = load i8*, i8** %3
%21 = load i64, i64* %5
%22 = call i32 @errx(i32 -1, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* %20, i64 %21)
br label %23
23: ; preds = %19, %15
ret void
}

LLVM IR (-O2):
@errno = global i64 0
@EPIPE = global i64 0
@.str = [9 x i8] c"%s: send\00"
@.str.1 = [23 x i8] c"%s: send: returned %zd\00"
define void @test_send(i8* %0, i32 %1) {
%3 = alloca i8
store i8 0, i8* %3
%4 = call i64 @send(i32 %1, i8* %3, i32 1, i32 0)
%5 = icmp slt i64 %4, 0
br i1 %5, label %6, label %12
6: ; preds = %2
%7 = load i64, i64* @errno
%8 = load i64, i64* @EPIPE
%9 = icmp eq i64 %7, %8
br i1 %9, label %14, label %10
10: ; preds = %6
%11 = call i32 @err(i32 -1, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %12
12: ; preds = %10, %2
%13 = call i32 @errx(i32 -1, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* %0, i64 %4)
br label %14
14: ; preds = %6, %12
ret void
}