#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*/ close(int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int write(int, char *, int);
int socketWriteNoEnd(int new_fd, char *writebuff, int lenth) {
  int nbytes;
  if ((nbytes = write(new_fd, writebuff, lenth)) <= 0) {
    fprintf(stderr, "write Error:%s\n", strerror(errno));
    close(new_fd);
    return -1;
  }
  return nbytes;
}


x86 assembly (clang, -O0):
<socketWriteNoEnd>:
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)
cmp    $0x0,%eax
jg     11ad <socketWriteNoEnd+0x6d>
mov    0x2e6c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    0x2e58(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
mov    -0x1c(%rbp),%edi
mov    %rax,%rdx
lea    0xe6c(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x8(%rbp),%edi
call   1040 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b3 <socketWriteNoEnd+0x73>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<socketWriteNoEnd>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebx
call   1030 <write@plt>
test   %eax,%eax
jg     1182 <socketWriteNoEnd+0x42>
mov    0x2e8b(%rip),%rax
mov    (%rax),%ebp
mov    0x2e7a(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
lea    0xe94(%rip),%rsi
mov    %ebp,%edi
mov    %rax,%rdx
call   1050 <fprintf@plt>
mov    %ebx,%edi
call   1040 <close@plt>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [16 x i8] c"write Error:%s\0A\00"
@errno = global i32 0
define i32 @socketWriteNoEnd(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 = icmp sle i32 %12, 0
br i1 %13, label %14, label %21
14: ; preds = %3
%15 = load i32, i32* @stderr
%16 = load i32, i32* @errno
%17 = call i8* @strerror(i32 %16)
%18 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* %17)
%19 = load i32, i32* %5
%20 = call i32 @close(i32 %19)
store i32 -1, i32* %4
br label %23
21: ; preds = %3
%22 = load i32, i32* %8
store i32 %22, i32* %4
br label %23
23: ; preds = %21, %14
%24 = load i32, i32* %4
ret i32 %24
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [16 x i8] c"write Error:%s\0A\00"
@errno = global i32 0
define i32 @socketWriteNoEnd(i32 %0, i8* nocapture %1, i32 %2) {
%4 = tail call i32 @write(i32 %0, i8* %1, i32 %2)
%5 = icmp slt i32 %4, 1
br i1 %5, label %6, label %12
6: ; preds = %3
%7 = load i32, i32* @stderr
%8 = load i32, i32* @errno
%9 = tail call i8* @strerror(i32 %8)
%10 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* %9)
%11 = tail call i32 @close(i32 %0)
br label %12
12: ; preds = %3, %6
%13 = phi i32 [ -1, %6 ], [ %4, %3 ]
ret i32 %13
}