#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*/ error(char *);
int write(int, void *, int);
void ewrite(int fd, void *buf, int size) {
  int ret;
  if ((ret = write(fd, buf, size)) < 0)
    error("write");
  else if (ret < size)
    ewrite(fd, (char *)buf + ret, size - ret);
}


x86 assembly (clang, -O0):
<ewrite>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1030 <write@plt>
mov    %eax,-0x18(%rbp)
cmp    $0x0,%eax
jge    116e <ewrite+0x3e>
lea    0xe9c(%rip),%rdi
call   1040 <error@plt>
jmp    1198 <ewrite+0x68>
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1193 <ewrite+0x63>
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
movslq -0x18(%rbp),%rax
add    %rax,%rsi
mov    -0x14(%rbp),%edx
sub    -0x18(%rbp),%edx
call   1050 <ewrite@plt>
jmp    1198 <ewrite+0x68>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ewrite>:
push   %rbp
push   %r14
push   %rbx
mov    %edx,%ebx
mov    %rsi,%r14
mov    %edi,%ebp
nopl   0x0(%rax,%rax,1)
call   1030 <write@plt>
test   %eax,%eax
js     114b <ewrite+0x2b>
sub    %eax,%ebx
jle    115b <ewrite+0x3b>
mov    %eax,%eax
add    %rax,%r14
mov    %ebp,%edi
mov    %r14,%rsi
mov    %ebx,%edx
jmp    1130 <ewrite+0x10>
lea    0xeae(%rip),%rdi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1040 <error@plt>
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [6 x i8] c"write\00"
define void @ewrite(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
%8 = load i32, i32* %4
%9 = load i8*, i8** %5
%10 = load i32, i32* %6
%11 = call i32 @write(i32 %8, i8* %9, i32 %10)
store i32 %11, i32* %7
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %3
%14 = call i32 @error(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
br label %29
15: ; preds = %3
%16 = load i32, i32* %7
%17 = load i32, i32* %6
%18 = icmp slt i32 %16, %17
br i1 %18, label %19, label %28
19: ; preds = %15
%20 = load i32, i32* %4
%21 = load i8*, i8** %5
%22 = load i32, i32* %7
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8, i8* %21, i64 %23
%25 = load i32, i32* %6
%26 = load i32, i32* %7
%27 = sub nsw i32 %25, %26
br label %28
28: ; preds = %19, %15
br label %29
29: ; preds = %28, %13
ret void
}

LLVM IR (-O2):
@.str = [6 x i8] c"write\00"
define void @ewrite(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 %6, label %8
6: ; preds = %13, %3
%7 = tail call i32 @error(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
br label %19
8: ; preds = %3, %13
%9 = phi i32 [ %17, %13 ], [ %4, %3 ]
%10 = phi i32 [ %16, %13 ], [ %2, %3 ]
%11 = phi i8* [ %15, %13 ], [ %1, %3 ]
%12 = icmp sgt i32 %10, %9
br i1 %12, label %13, label %19
13: ; preds = %8
%14 = zext i32 %9 to i64
%15 = getelementptr inbounds i8, i8* %11, i64 %14
%16 = sub nsw i32 %10, %9
%17 = tail call i32 @write(i32 %0, i8* %15, i32 %16)
%18 = icmp slt i32 %17, 0
br i1 %18, label %6, label %8
19: ; preds = %8, %6
ret void
}