#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 neio_write(int, char const *, unsigned int);
int neio_bwrite(int fd, const char *buf, unsigned int size) {
  while (size) {
    int wd = neio_write(fd, buf, size);
    do {
      if ((wd))
        return -1;
    } while (0);
    if (wd > 0) {
      buf += wd;
      size -= wd;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<neio_bwrite>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     1184 <neio_bwrite+0x74>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1030 <neio_write@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
je     1154 <neio_bwrite+0x44>
movl   $0xffffffff,-0x4(%rbp)
jmp    118b <neio_bwrite+0x7b>
jmp    1159 <neio_bwrite+0x49>
cmpl   $0x0,-0x18(%rbp)
jle    117f <neio_bwrite+0x6f>
mov    -0x18(%rbp),%ecx
mov    -0x10(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x10(%rbp)
mov    -0x18(%rbp),%ecx
mov    -0x14(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x14(%rbp)
jmp    1122 <neio_bwrite+0x12>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<neio_bwrite>:
test   %edx,%edx
je     113a <neio_bwrite+0x2a>
push   %rbp
push   %r14
push   %rbx
mov    %edx,%ebx
mov    %rsi,%r14
mov    %edi,%ebp
nop
mov    %ebp,%edi
mov    %r14,%rsi
mov    %ebx,%edx
call   1030 <neio_write@plt>
test   %eax,%eax
je     1120 <neio_bwrite+0x10>
mov    $0xffffffff,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret
xor    %eax,%eax
ret

LLVM IR (-O0):
define i32 @neio_bwrite(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
br label %9
9: ; preds = %33, %3
%10 = load i32, i32* %7
%11 = icmp ne i32 %10, 0
br i1 %11, label %12, label %34
12: ; preds = %9
%13 = load i32, i32* %5
%14 = load i8*, i8** %6
%15 = load i32, i32* %7
%16 = call i32 @neio_write(i32 %13, i8* %14, i32 %15)
store i32 %16, i32* %8
br label %17
17: ; preds = %12
%18 = load i32, i32* %8
%19 = icmp ne i32 %18, 0
br i1 %19, label %20, label %21
20: ; preds = %17
store i32 -1, i32* %4
br label %35
21: ; preds = %17
br label %22
22: ; preds = %21
%23 = load i32, i32* %8
%24 = icmp sgt i32 %23, 0
br i1 %24, label %25, label %33
25: ; preds = %22
%26 = load i32, i32* %8
%27 = load i8*, i8** %6
%28 = sext i32 %26 to i64
%29 = getelementptr inbounds i8, i8* %27, i64 %28
store i8* %29, i8** %6
%30 = load i32, i32* %8
%31 = load i32, i32* %7
%32 = sub i32 %31, %30
store i32 %32, i32* %7
br label %33
33: ; preds = %25, %22
br label %9
34: ; preds = %9
store i32 0, i32* %4
br label %35
35: ; preds = %34, %20
%36 = load i32, i32* %4
ret i32 %36
}

LLVM IR (-O2):
define i32 @neio_bwrite(i32 %0, i8* %1, i32 %2) {
%4 = icmp eq i32 %2, 0
br i1 %4, label %8, label %5
5: ; preds = %3, %5
%6 = tail call i32 @neio_write(i32 %0, i8* %1, i32 %2)
%7 = icmp eq i32 %6, 0
br i1 %7, label %5, label %8
8: ; preds = %5, %3
%9 = phi i32 [ 0, %3 ], [ -1, %5 ]
ret i32 %9
}