#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 */
typedef int /*<<< orphan*/ ssize_t;

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int, void const *,
                           size_t);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ write(int, void const *, size_t);
extern ssize_t Write(int fd, const void *buf, size_t nbytes) {
  ssize_t result;
  if ((result = write(fd, buf, nbytes)) < 0) {
    perror("write error");
    fprintf(stderr, "\nfd:[%d] &buf[%p] nbytes[%d]", fd, buf, nbytes);
  }
  return result;
}


x86 assembly (clang, -O0):
<Write>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1030 <write@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
jge    118b <Write+0x5b>
lea    0xe9a(%rip),%rdi
call   1050 <perror@plt>
mov    0x2e6e(%rip),%rax
mov    (%rax),%edi
mov    -0x4(%rbp),%edx
mov    -0x10(%rbp),%rcx
mov    -0x18(%rbp),%r8
lea    0xe86(%rip),%rsi
call   1040 <fprintf@plt>
mov    -0x1c(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Write>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%r15
mov    %edi,%ebp
call   1030 <write@plt>
mov    %eax,%ebx
test   %eax,%eax
js     1157 <Write+0x27>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xea2(%rip),%rdi
call   1050 <perror@plt>
mov    0x2e76(%rip),%rax
mov    (%rax),%edi
lea    0xe99(%rip),%rsi
mov    %ebp,%edx
mov    %r15,%rcx
mov    %r14,%r8
call   1040 <fprintf@plt>
jmp    114a <Write+0x1a>

LLVM IR (-O0):
@.str = [12 x i8] c"write error\00"
@stderr = global i32 0
@.str.1 = [29 x i8] c"\0Afd:[%d] &buf[%p] nbytes[%d]\00"
define i32 @Write(i32 %0, i8* %1, i64 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i32
store i32 %0, i32* %4
store i8* %1, i8** %5
store i64 %2, i64* %6
%8 = load i32, i32* %4
%9 = load i8*, i8** %5
%10 = load i64, i64* %6
%11 = call i32 @write(i32 %8, i8* %9, i64 %10)
store i32 %11, i32* %7
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %20
13: ; preds = %3
%14 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%15 = load i32, i32* @stderr
%16 = load i32, i32* %4
%17 = load i8*, i8** %5
%18 = load i64, i64* %6
%19 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i32 %16, i8* %17, i64 %18)
br label %20
20: ; preds = %13, %3
%21 = load i32, i32* %7
ret i32 %21
}

LLVM IR (-O2):
@.str = [12 x i8] c"write error\00"
@stderr = global i32 0
@.str.1 = [29 x i8] c"\0Afd:[%d] &buf[%p] nbytes[%d]\00"
define i32 @Write(i32 %0, i8* %1, i64 %2) {
%4 = tail call i32 @write(i32 %0, i8* %1, i64 %2)
%5 = icmp slt i32 %4, 0
br i1 %5, label %6, label %10
6: ; preds = %3
%7 = tail call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%8 = load i32, i32* @stderr
%9 = tail call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i32 %0, i8* %1, i64 %2)
br label %10
10: ; preds = %6, %3
ret i32 %4
}