#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 ssize_t;

/* Variables and functions */
int write_auto_resume(int, char const *, int);
ssize_t write_all(int fd, const char *buffer, size_t n_) {
  ssize_t n = n_;
  do {
    ssize_t m = write_auto_resume(fd, buffer, n);
    if (m == -1)
      return -1;
    buffer += m;
    n -= m;
  } while (n);
  return n_;
}


x86 assembly (clang, -O0):
<write_all>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1030 <write_auto_resume@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0xffffffff,-0x20(%rbp)
jne    1152 <write_all+0x42>
movl   $0xffffffff,-0x4(%rbp)
jmp    117f <write_all+0x6f>
mov    -0x20(%rbp),%ecx
mov    -0x10(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x10(%rbp)
mov    -0x20(%rbp),%ecx
mov    -0x1c(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jne    112a <write_all+0x1a>
mov    -0x18(%rbp),%rax
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
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %edi,%r15d
mov    %r14d,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r15d,%edi
mov    %rbx,%rsi
mov    %ebp,%edx
call   1030 <write_auto_resume@plt>
cmp    $0xffffffff,%eax
je     114f <write_all+0x3f>
sub    %eax,%ebp
cltq
add    %rax,%rbx
test   %ebp,%ebp
jne    1130 <write_all+0x20>
jmp    1155 <write_all+0x45>
mov    $0xffffffff,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

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