#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 errno;
int /*<<< orphan*/ ltr_int_log_message(char *, int);
int /*<<< orphan*/ ltr_int_my_perror(char *);
scalar_t__ write(int, void *, size_t);
int ltr_int_socket_send(int socket, void *buf, size_t size) {
  if (socket <= 0) {
    return -1;
  }
  if (write(socket, buf, size) < 0) {
    ltr_int_log_message("Write @fd %d failed:\n", socket);
    int err = errno;
    ltr_int_my_perror("write@socket_send");
    return -err;
  }
  return 0;
}


x86 assembly (clang, -O0):
<ltr_int_socket_send>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
cmpl   $0x0,-0x8(%rbp)
jg     1159 <ltr_int_socket_send+0x29>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ae <ltr_int_socket_send+0x7e>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1030 <write@plt>
cmp    $0x0,%rax
jge    11a7 <ltr_int_socket_send+0x77>
mov    -0x8(%rbp),%esi
lea    0xe83(%rip),%rdi
call   1040 <ltr_int_log_message@plt>
mov    0x2e57(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
lea    0xe81(%rip),%rdi
call   1050 <ltr_int_my_perror@plt>
xor    %eax,%eax
sub    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11ae <ltr_int_socket_send+0x7e>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ltr_int_socket_send>:
push   %rbp
push   %rbx
push   %rax
test   %edi,%edi
jle    116c <ltr_int_socket_send+0x3c>
mov    %edi,%ebx
call   1030 <write@plt>
xor    %ebp,%ebp
test   %rax,%rax
jns    1171 <ltr_int_socket_send+0x41>
lea    0xeb4(%rip),%rdi
mov    %ebx,%esi
call   1040 <ltr_int_log_message@plt>
mov    0x2e86(%rip),%rax
xor    %ebp,%ebp
sub    (%rax),%ebp
lea    0xeb1(%rip),%rdi
call   1050 <ltr_int_my_perror@plt>
jmp    1171 <ltr_int_socket_send+0x41>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [22 x i8] c"Write @fd %d failed:\0A\00"
@errno = global i32 0
@.str.1 = [18 x i8] c"write@socket_send\00"
define i32 @ltr_int_socket_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 i32, i32* %5
%10 = icmp sle i32 %9, 0
br i1 %10, label %11, label %12
11: ; preds = %3
store i32 -1, i32* %4
br label %26
12: ; preds = %3
%13 = load i32, i32* %5
%14 = load i8*, i8** %6
%15 = load i64, i64* %7
%16 = call i64 @write(i32 %13, i8* %14, i64 %15)
%17 = icmp slt i64 %16, 0
br i1 %17, label %18, label %25
18: ; preds = %12
%19 = load i32, i32* %5
%20 = call i32 @ltr_int_log_message(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 %19)
%21 = load i32, i32* @errno
store i32 %21, i32* %8
%22 = call i32 @ltr_int_my_perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
%23 = load i32, i32* %8
%24 = sub nsw i32 0, %23
store i32 %24, i32* %4
br label %26
25: ; preds = %12
store i32 0, i32* %4
br label %26
26: ; preds = %25, %18, %11
%27 = load i32, i32* %4
ret i32 %27
}

LLVM IR (-O2):
@.str = [22 x i8] c"Write @fd %d failed:\0A\00"
@errno = global i32 0
@.str.1 = [18 x i8] c"write@socket_send\00"
define i32 @ltr_int_socket_send(i32 %0, i8* nocapture %1, i64 %2) {
%4 = icmp slt i32 %0, 1
br i1 %4, label %13, label %5
5: ; preds = %3
%6 = tail call i64 @write(i32 %0, i8* %1, i64 %2)
%7 = icmp slt i64 %6, 0
br i1 %7, label %8, label %13
8: ; preds = %5
%9 = tail call i32 @ltr_int_log_message(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 %0)
%10 = load i32, i32* @errno
%11 = tail call i32 @ltr_int_my_perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
%12 = sub nsw i32 0, %10
br label %13
13: ; preds = %5, %3, %8
%14 = phi i32 [ %12, %8 ], [ -1, %3 ], [ 0, %5 ]
ret i32 %14
}