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

/* Variables and functions */
scalar_t__ EINTR;
scalar_t__ errno;
int write(int, int /*<<< orphan*/ const *, size_t);
int write_all(int fd, const uint8_t *data, size_t len) {
  ssize_t wret;
  while (len != 0) {
    while ((wret = write(fd, data, len)) == -1 && errno == EINTR)
      ;
    if (wret <= 0)
      return -1;
    data += wret;
    len -= wret;
  }
  return 0;
}


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)
cmpq   $0x0,-0x18(%rbp)
je     11c4 <write_all+0xb4>
jmp    1133 <write_all+0x23>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1030 <write@plt>
mov    %eax,%ecx
mov    %ecx,-0x1c(%rbp)
xor    %eax,%eax
cmp    $0xffffffff,%ecx
mov    %al,-0x1d(%rbp)
jne    1170 <write_all+0x60>
mov    0x2e83(%rip),%rax
mov    (%rax),%rax
mov    0x2e71(%rip),%rcx
cmp    (%rcx),%rax
sete   %al
mov    %al,-0x1d(%rbp)
mov    -0x1d(%rbp),%al
test   $0x1,%al
jne    1180 <write_all+0x70>
jmp    1185 <write_all+0x75>
jmp    1133 <write_all+0x23>
cmpl   $0x0,-0x1c(%rbp)
jg     119b <write_all+0x8b>
movl   $0xffffffff,-0x4(%rbp)
jmp    11cb <write_all+0xbb>
mov    -0x1c(%rbp),%ecx
mov    -0x10(%rbp),%rax
movslq %ecx,%rcx
shl    $0x2,%rcx
add    %rcx,%rax
mov    %rax,-0x10(%rbp)
movslq -0x1c(%rbp),%rcx
mov    -0x18(%rbp),%rax
sub    %rcx,%rax
mov    %rax,-0x18(%rbp)
jmp    1123 <write_all+0x13>
movl   $0x0,-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   %r13
push   %r12
push   %rbx
push   %rax
xor    %r14d,%r14d
test   %rdx,%rdx
je     1175 <write_all+0x65>
mov    %rdx,%rbx
mov    %rsi,%rbp
mov    %edi,%r15d
mov    0x2ead(%rip),%r12
mov    0x2e9e(%rip),%r13
nopw   0x0(%rax,%rax,1)
mov    %r15d,%edi
mov    %rbp,%rsi
mov    %rbx,%rdx
call   1030 <write@plt>
cmp    $0xffffffff,%eax
jne    115d <write_all+0x4d>
mov    0x0(%r13),%rcx
cmp    %rcx,(%r12)
je     1140 <write_all+0x30>
test   %eax,%eax
jle    116f <write_all+0x5f>
mov    %eax,%eax
lea    0x0(%rbp,%rax,4),%rbp
sub    %rax,%rbx
jne    1140 <write_all+0x30>
jmp    1175 <write_all+0x65>
mov    $0xffffffff,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@errno = global i64 0
@EINTR = global i64 0
define i32 @write_all(i32 %0, i32* %1, i64 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i64
%8 = alloca i32
store i32 %0, i32* %5
store i32* %1, i32** %6
store i64 %2, i64* %7
br label %9
9: ; preds = %30, %3
%10 = load i64, i64* %7
%11 = icmp ne i64 %10, 0
br i1 %11, label %12, label %39
12: ; preds = %9
br label %13
13: ; preds = %25, %12
%14 = load i32, i32* %5
%15 = load i32*, i32** %6
%16 = load i64, i64* %7
%17 = call i32 @write(i32 %14, i32* %15, i64 %16)
store i32 %17, i32* %8
%18 = icmp eq i32 %17, -1
br i1 %18, label %19, label %23
19: ; preds = %13
%20 = load i64, i64* @errno
%21 = load i64, i64* @EINTR
%22 = icmp eq i64 %20, %21
br label %23
23: ; preds = %19, %13
%24 = phi i1 [ false, %13 ], [ %22, %19 ]
br i1 %24, label %25, label %26
25: ; preds = %23
br label %13
26: ; preds = %23
%27 = load i32, i32* %8
%28 = icmp sle i32 %27, 0
br i1 %28, label %29, label %30
29: ; preds = %26
store i32 -1, i32* %4
br label %40
30: ; preds = %26
%31 = load i32, i32* %8
%32 = load i32*, i32** %6
%33 = sext i32 %31 to i64
%34 = getelementptr inbounds i32, i32* %32, i64 %33
store i32* %34, i32** %6
%35 = load i32, i32* %8
%36 = sext i32 %35 to i64
%37 = load i64, i64* %7
%38 = sub i64 %37, %36
store i64 %38, i64* %7
br label %9
39: ; preds = %9
store i32 0, i32* %4
br label %40
40: ; preds = %39, %29
%41 = load i32, i32* %4
ret i32 %41
}

LLVM IR (-O2):
@errno = global i64 0
@EINTR = global i64 0
define i32 @write_all(i32 %0, i32* nocapture %1, i64 %2) {
%4 = icmp eq i64 %2, 0
br i1 %4, label %22, label %5
5: ; preds = %3, %17
%6 = phi i64 [ %20, %17 ], [ %2, %3 ]
%7 = phi i32* [ %19, %17 ], [ %1, %3 ]
br label %8
8: ; preds = %5, %8
%9 = tail call i32 @write(i32 %0, i32* %7, i64 %6)
%10 = icmp eq i32 %9, -1
%11 = load i64, i64* @errno
%12 = load i64, i64* @EINTR
%13 = icmp eq i64 %11, %12
%14 = select i1 %10, i1 %13, i1 false
br i1 %14, label %8, label %15
15: ; preds = %8
%16 = icmp slt i32 %9, 1
br i1 %16, label %22, label %17
17: ; preds = %15
%18 = zext i32 %9 to i64
%19 = getelementptr inbounds i32, i32* %7, i64 %18
%20 = sub i64 %6, %18
%21 = icmp eq i64 %20, 0
br i1 %21, label %22, label %5
22: ; preds = %15, %17, %3
%23 = phi i32 [ 0, %3 ], [ 0, %17 ], [ -1, %15 ]
ret i32 %23
}