#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*/ uint8_t;

/* Variables and functions */
int write(int, int /*<<< orphan*/ *, int);
int write_all(int fd, uint8_t *buff, int size) {
  int n, sent;
  for (sent = 0; sent < size; sent += n)
    if ((n = write(fd, buff + sent, size - sent)) == -1)
      return -1;
  return sent;
}


x86 assembly (clang, -O0):
<write_all>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    117d <write_all+0x6d>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
movslq -0x1c(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
mov    -0x14(%rbp),%edx
sub    -0x1c(%rbp),%edx
call   1030 <write@plt>
mov    %eax,-0x18(%rbp)
cmp    $0xffffffff,%eax
jne    116a <write_all+0x5a>
movl   $0xffffffff,-0x4(%rbp)
jmp    1183 <write_all+0x73>
jmp    116f <write_all+0x5f>
mov    -0x18(%rbp),%eax
add    -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
jmp    1129 <write_all+0x19>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_all>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
test   %edx,%edx
jle    1150 <write_all+0x40>
mov    %edx,%ebp
mov    %rsi,%r14
mov    %edi,%r15d
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nop
movslq %ebx,%rax
lea    (%r14,%rax,4),%rsi
mov    %ebp,%edx
sub    %eax,%edx
mov    %r15d,%edi
call   1030 <write@plt>
cmp    $0xffffffff,%eax
je     1154 <write_all+0x44>
add    %eax,%ebx
cmp    %ebp,%ebx
jl     1130 <write_all+0x20>
jmp    1159 <write_all+0x49>
xor    %ebx,%ebx
jmp    1159 <write_all+0x49>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @write_all(i32 %0, i32* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 %0, i32* %5
store i32* %1, i32** %6
store i32 %2, i32* %7
store i32 0, i32* %9
br label %10
10: ; preds = %27, %3
%11 = load i32, i32* %9
%12 = load i32, i32* %7
%13 = icmp slt i32 %11, %12
br i1 %13, label %14, label %31
14: ; preds = %10
%15 = load i32, i32* %5
%16 = load i32*, i32** %6
%17 = load i32, i32* %9
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i32, i32* %16, i64 %18
%20 = load i32, i32* %7
%21 = load i32, i32* %9
%22 = sub nsw i32 %20, %21
%23 = call i32 @write(i32 %15, i32* %19, i32 %22)
store i32 %23, i32* %8
%24 = icmp eq i32 %23, -1
br i1 %24, label %25, label %26
25: ; preds = %14
store i32 -1, i32* %4
br label %33
26: ; preds = %14
br label %27
27: ; preds = %26
%28 = load i32, i32* %8
%29 = load i32, i32* %9
%30 = add nsw i32 %29, %28
store i32 %30, i32* %9
br label %10
31: ; preds = %10
%32 = load i32, i32* %9
store i32 %32, i32* %4
br label %33
33: ; preds = %31, %25
%34 = load i32, i32* %4
ret i32 %34
}

LLVM IR (-O2):
define i32 @write_all(i32 %0, i32* nocapture %1, i32 %2) {
%4 = icmp sgt i32 %2, 0
br i1 %4, label %7, label %15
5: ; preds = %7
%6 = icmp slt i32 %14, %2
br i1 %6, label %7, label %15
7: ; preds = %3, %5
%8 = phi i32 [ %14, %5 ], [ 0, %3 ]
%9 = sext i32 %8 to i64
%10 = getelementptr inbounds i32, i32* %1, i64 %9
%11 = sub nsw i32 %2, %8
%12 = tail call i32 @write(i32 %0, i32* %10, i32 %11)
%13 = icmp eq i32 %12, -1
%14 = add nsw i32 %12, %8
br i1 %13, label %15, label %5
15: ; preds = %7, %5, %3
%16 = phi i32 [ 0, %3 ], [ %14, %5 ], [ -1, %7 ]
ret i32 %16
}