#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);
    ((void)(wd));
    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,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     1169 <neio_bwrite+0x59>
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1030 <neio_write@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jle    1164 <neio_bwrite+0x54>
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>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<neio_bwrite>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
test   %edx,%edx
je     114a <neio_bwrite+0x3a>
mov    %edx,%ebp
mov    %rsi,%rbx
mov    %edi,%r14d
xor    %r15d,%r15d
cs nopw 0x0(%rax,%rax,1)
mov    %r14d,%edi
mov    %rbx,%rsi
mov    %ebp,%edx
call   1030 <neio_write@plt>
test   %eax,%eax
cmovs  %r15d,%eax
add    %rax,%rbx
sub    %eax,%ebp
jne    1130 <neio_bwrite+0x20>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @neio_bwrite(i32 %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %4
store i8* %1, i8** %5
store i32 %2, i32* %6
br label %8
8: ; preds = %27, %3
%9 = load i32, i32* %6
%10 = icmp ne i32 %9, 0
br i1 %10, label %11, label %28
11: ; preds = %8
%12 = load i32, i32* %4
%13 = load i8*, i8** %5
%14 = load i32, i32* %6
%15 = call i32 @neio_write(i32 %12, i8* %13, i32 %14)
store i32 %15, i32* %7
%16 = load i32, i32* %7
%17 = load i32, i32* %7
%18 = icmp sgt i32 %17, 0
br i1 %18, label %19, label %27
19: ; preds = %11
%20 = load i32, i32* %7
%21 = load i8*, i8** %5
%22 = sext i32 %20 to i64
%23 = getelementptr inbounds i8, i8* %21, i64 %22
store i8* %23, i8** %5
%24 = load i32, i32* %7
%25 = load i32, i32* %6
%26 = sub i32 %25, %24
store i32 %26, i32* %6
br label %27
27: ; preds = %19, %11
br label %8
28: ; preds = %8
ret i32 0
}

LLVM IR (-O2):
define i32 @neio_bwrite(i32 %0, i8* %1, i32 %2) {
%4 = icmp eq i32 %2, 0
br i1 %4, label %15, label %5
5: ; preds = %3, %5
%6 = phi i8* [ %13, %5 ], [ %1, %3 ]
%7 = phi i32 [ %11, %5 ], [ %2, %3 ]
%8 = tail call i32 @neio_write(i32 %0, i8* %6, i32 %7)
%9 = icmp sgt i32 %8, 0
%10 = select i1 %9, i32 %8, i32 0
%11 = sub i32 %7, %10
%12 = zext i32 %10 to i64
%13 = getelementptr i8, i8* %6, i64 %12
%14 = icmp eq i32 %11, 0
br i1 %14, label %15, label %5
15: ; preds = %5, %3
ret i32 0
}