#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 write(int, char *, int);
int /*<<< orphan*/ write_log(char *);
int s_send(int sockfd, char *message, int len) {
  int n;
  n = write(sockfd, message, len);
  if (n < 0) {
    write_log("ERROR writing to socket\n");
    return -1;
  } else if (n == 0) {
    write_log("Socket shutted down\n");
    return -2;
  }
  return 0;
}


x86 assembly (clang, -O0):
<s_send>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1030 <write@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    1166 <s_send+0x46>
lea    0xeab(%rip),%rdi
call   1040 <write_log@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1194 <s_send+0x74>
cmpl   $0x0,-0x18(%rbp)
jne    1188 <s_send+0x68>
lea    0xea2(%rip),%rdi
call   1040 <write_log@plt>
movl   $0xfffffffe,-0x4(%rbp)
jmp    1194 <s_send+0x74>
jmp    118d <s_send+0x6d>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<s_send>:
push   %rbx
call   1030 <write@plt>
test   %eax,%eax
js     113e <s_send+0x1e>
xor    %ebx,%ebx
test   %eax,%eax
jne    114f <s_send+0x2f>
mov    $0xfffffffe,%ebx
lea    0xedd(%rip),%rdi
jmp    114a <s_send+0x2a>
mov    $0xffffffff,%ebx
lea    0xeb6(%rip),%rdi
call   1040 <write_log@plt>
mov    %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [25 x i8] c"ERROR writing to socket\0A\00"
@.str.1 = [21 x i8] c"Socket shutted down\0A\00"
define i32 @s_send(i32 %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
store i32 %0, i32* %5
store i8* %1, i8** %6
store i32 %2, i32* %7
%9 = load i32, i32* %5
%10 = load i8*, i8** %6
%11 = load i32, i32* %7
%12 = call i32 @write(i32 %9, i8* %10, i32 %11)
store i32 %12, i32* %8
%13 = load i32, i32* %8
%14 = icmp slt i32 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %3
%16 = call i32 @write_log(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %4
br label %24
17: ; preds = %3
%18 = load i32, i32* %8
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %17
%21 = call i32 @write_log(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
store i32 -2, i32* %4
br label %24
22: ; preds = %17
br label %23
23: ; preds = %22
store i32 0, i32* %4
br label %24
24: ; preds = %23, %20, %15
%25 = load i32, i32* %4
ret i32 %25
}

LLVM IR (-O2):
@.str = [25 x i8] c"ERROR writing to socket\0A\00"
@.str.1 = [21 x i8] c"Socket shutted down\0A\00"
define i32 @s_send(i32 %0, i8* nocapture %1, i32 %2) {
%4 = tail call i32 @write(i32 %0, i8* %1, i32 %2)
%5 = icmp slt i32 %4, 0
br i1 %5, label %8, label %6
6: ; preds = %3
%7 = icmp eq i32 %4, 0
br i1 %7, label %8, label %12
8: ; preds = %6, %3
%9 = phi i8* [ getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), %3 ], [ getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), %6 ]
%10 = phi i32 [ -1, %3 ], [ -2, %6 ]
%11 = tail call i32 @write_log(i8* %9)
br label %12
12: ; preds = %8, %6
%13 = phi i32 [ 0, %6 ], [ %10, %8 ]
ret i32 %13
}