#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*/ stderr;
int write(int, void *, size_t);
int sock_send(int fd, void *src, size_t size) {
  int err;
  if (!src)
    return -1;
  err = write(fd, src, size);
  if (err < 0) {
    fprintf(stderr, "sock_send: socket write error\n");
    return err;
  }
  return err;
}


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)
cmpq   $0x0,-0x10(%rbp)
jne    114a <sock_send+0x2a>
movl   $0xffffffff,-0x4(%rbp)
jmp    118d <sock_send+0x6d>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1030 <write@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    1187 <sock_send+0x67>
mov    0x2e72(%rip),%rax
mov    (%rax),%edi
lea    0xe89(%rip),%rsi
call   1040 <fprintf@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    118d <sock_send+0x6d>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sock_send>:
push   %rbx
test   %rsi,%rsi
je     1148 <sock_send+0x28>
call   1030 <write@plt>
mov    %eax,%ebx
test   %eax,%eax
jns    114d <sock_send+0x2d>
mov    0x2ea8(%rip),%rax
mov    (%rax),%edi
lea    0xebf(%rip),%rsi
call   1040 <fprintf@plt>
jmp    114d <sock_send+0x2d>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [31 x i8] c"sock_send: socket write error\0A\00"
define i32 @sock_send(i32 %0, i8* %1, i64 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i32
store i32 %0, i32* %5
store i8* %1, i8** %6
store i64 %2, i64* %7
%9 = load i8*, i8** %6
%10 = icmp ne i8* %9, null
br i1 %10, label %12, label %11
11: ; preds = %3
store i32 -1, i32* %4
br label %25
12: ; preds = %3
%13 = load i32, i32* %5
%14 = load i8*, i8** %6
%15 = load i64, i64* %7
%16 = call i32 @write(i32 %13, i8* %14, i64 %15)
store i32 %16, i32* %8
%17 = load i32, i32* %8
%18 = icmp slt i32 %17, 0
br i1 %18, label %19, label %23
19: ; preds = %12
%20 = load i32, i32* @stderr
%21 = call i32 @fprintf(i32 %20, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
%22 = load i32, i32* %8
store i32 %22, i32* %4
br label %25
23: ; preds = %12
%24 = load i32, i32* %8
store i32 %24, i32* %4
br label %25
25: ; preds = %23, %19, %11
%26 = load i32, i32* %4
ret i32 %26
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [31 x i8] c"sock_send: socket write error\0A\00"
define i32 @sock_send(i32 %0, i8* %1, i64 %2) {
%4 = icmp eq i8* %1, null
br i1 %4, label %11, label %5
5: ; preds = %3
%6 = tail call i32 @write(i32 %0, i8* %1, i64 %2)
%7 = icmp slt i32 %6, 0
br i1 %7, label %8, label %11
8: ; preds = %5
%9 = load i32, i32* @stderr
%10 = tail call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
br label %11
11: ; preds = %5, %3, %8
%12 = phi i32 [ %6, %8 ], [ -1, %3 ], [ %6, %5 ]
ret i32 %12
}