#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 */
scalar_t__ EINTR;
scalar_t__ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, int);
int send(int, void const *, size_t, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
char *strerror(scalar_t__);
int sock_send(int sock_fd, size_t size, const void *buf) {
  int rc;
retry_after_signal:
  rc = send(sock_fd, buf, size, 0);
  if (rc != size) {
    fprintf(stderr, "send failed: %s, rc=%d\n", strerror(errno), rc);
    if ((errno == EINTR) && (rc != 0))
      goto retry_after_signal;
    if (rc)
      return rc;
    else
      return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<sock_send>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    -0x10(%rbp),%rdx
xor    %ecx,%ecx
call   1030 <send@plt>
mov    %eax,-0x1c(%rbp)
movslq -0x1c(%rbp),%rax
cmp    -0x10(%rbp),%rax
je     11e0 <sock_send+0xb0>
mov    0x2e73(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    0x2e5f(%rip),%rax
mov    (%rax),%rdi
call   1050 <strerror@plt>
mov    -0x20(%rbp),%edi
mov    %rax,%rdx
mov    -0x1c(%rbp),%ecx
lea    0xe6f(%rip),%rsi
call   1040 <fprintf@plt>
mov    0x2e3b(%rip),%rax
mov    (%rax),%rax
mov    0x2e29(%rip),%rcx
cmp    (%rcx),%rax
jne    11bf <sock_send+0x8f>
cmpl   $0x0,-0x1c(%rbp)
je     11bf <sock_send+0x8f>
jmp    1143 <sock_send+0x13>
cmpl   $0x0,-0x1c(%rbp)
je     11d4 <sock_send+0xa4>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11e7 <sock_send+0xb7>
movl   $0xffffffff,-0x4(%rbp)
jmp    11e7 <sock_send+0xb7>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sock_send>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%r13
mov    %edi,%r12d
mov    0x2e8d(%rip),%r15
nopl   0x0(%rax,%rax,1)
xor    %ebx,%ebx
mov    %r12d,%edi
mov    %r14,%rsi
mov    %r13,%rdx
xor    %ecx,%ecx
call   1030 <send@plt>
mov    %eax,%ebp
cltq
cmp    %r13,%rax
je     11a9 <sock_send+0x79>
mov    0x2e6e(%rip),%rax
mov    (%rax),%ebx
mov    (%r15),%rdi
call   1050 <strerror@plt>
mov    %ebx,%edi
lea    0xe7b(%rip),%rsi
mov    %rax,%rdx
mov    %ebp,%ecx
call   1040 <fprintf@plt>
mov    (%r15),%rax
mov    0x2e37(%rip),%rcx
cmp    (%rcx),%rax
jne    11a2 <sock_send+0x72>
test   %ebp,%ebp
jne    1150 <sock_send+0x20>
cmp    $0x1,%ebp
sbb    %ebx,%ebx
or     %ebp,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [24 x i8] c"send failed: %s, rc=%d\0A\00"
@errno = global i64 0
@EINTR = global i64 0
define i32 @sock_send(i32 %0, i64 %1, i8* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i64
%7 = alloca i8*
%8 = alloca i32
store i32 %0, i32* %5
store i64 %1, i64* %6
store i8* %2, i8** %7
br label %9
9: ; preds = %30, %3
%10 = load i32, i32* %5
%11 = load i8*, i8** %7
%12 = load i64, i64* %6
%13 = call i32 @send(i32 %10, i8* %11, i64 %12, i32 0)
store i32 %13, i32* %8
%14 = load i32, i32* %8
%15 = sext i32 %14 to i64
%16 = load i64, i64* %6
%17 = icmp ne i64 %15, %16
br i1 %17, label %18, label %37
18: ; preds = %9
%19 = load i32, i32* @stderr
%20 = load i64, i64* @errno
%21 = call i8* @strerror(i64 %20)
%22 = load i32, i32* %8
%23 = call i32 @fprintf(i32 %19, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* %21, i32 %22)
%24 = load i64, i64* @errno
%25 = load i64, i64* @EINTR
%26 = icmp eq i64 %24, %25
br i1 %26, label %27, label %31
27: ; preds = %18
%28 = load i32, i32* %8
%29 = icmp ne i32 %28, 0
br i1 %29, label %30, label %31
30: ; preds = %27
br label %9
31: ; preds = %27, %18
%32 = load i32, i32* %8
%33 = icmp ne i32 %32, 0
br i1 %33, label %34, label %36
34: ; preds = %31
%35 = load i32, i32* %8
store i32 %35, i32* %4
br label %38
36: ; preds = %31
store i32 -1, i32* %4
br label %38
37: ; preds = %9
store i32 0, i32* %4
br label %38
38: ; preds = %37, %36, %34
%39 = load i32, i32* %4
ret i32 %39
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [24 x i8] c"send failed: %s, rc=%d\0A\00"
@errno = global i64 0
@EINTR = global i64 0
define i32 @sock_send(i32 %0, i64 %1, i8* %2) {
br label %4
4: ; preds = %8, %3
%5 = tail call i32 @send(i32 %0, i8* %2, i64 %1, i32 0)
%6 = sext i32 %5 to i64
%7 = icmp eq i64 %6, %1
br i1 %7, label %20, label %8
8: ; preds = %4
%9 = load i32, i32* @stderr
%10 = load i64, i64* @errno
%11 = tail call i8* @strerror(i64 %10)
%12 = tail call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* %11, i32 %5)
%13 = load i64, i64* @errno
%14 = load i64, i64* @EINTR
%15 = icmp eq i64 %13, %14
%16 = icmp ne i32 %5, 0
%17 = select i1 %15, i1 %16, i1 false
br i1 %17, label %4, label %18
18: ; preds = %8
%19 = select i1 %16, i32 %5, i32 -1
br label %20
20: ; preds = %4, %18
%21 = phi i32 [ %19, %18 ], [ 0, %4 ]
ret i32 %21
}