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

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ err(int /*<<< orphan*/, char *, char const *);
scalar_t__ write(int, void const *, size_t);
void full_write(int fd, const void *buf, size_t count, const char *error) {
  while (count) {
    ssize_t n = write(fd, buf, count);
    if (n < 0)
      err(EXIT_FAILURE, "%s", error);
    count -= n;
    buf += n;
  }
}


x86 assembly (clang, -O0):
<full_write>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     119a <full_write+0x7a>
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1030 <write@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jge    117a <full_write+0x5a>
mov    0x2e78(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rdx
lea    0xe8b(%rip),%rsi
call   1040 <err@plt>
mov    -0x28(%rbp),%rcx
mov    -0x18(%rbp),%rax
sub    %rcx,%rax
mov    %rax,-0x18(%rbp)
mov    -0x28(%rbp),%rax
add    -0x10(%rbp),%rax
mov    %rax,-0x10(%rbp)
jmp    1137 <full_write+0x17>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<full_write>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %rdx,%rdx
je     1184 <full_write+0x64>
mov    %rcx,%r14
mov    %rdx,%r15
mov    %rsi,%rbx
mov    %edi,%r13d
lea    0xebd(%rip),%r12
jmp    1158 <full_write+0x38>
cs nopw 0x0(%rax,%rax,1)
nop
add    %rbp,%rbx
sub    %rbp,%r15
je     1184 <full_write+0x64>
mov    %r13d,%edi
mov    %rbx,%rsi
mov    %r15,%rdx
call   1030 <write@plt>
mov    %rax,%rbp
test   %rax,%rax
jns    1150 <full_write+0x30>
mov    0x2e6b(%rip),%rax
mov    (%rax),%edi
mov    %r12,%rsi
mov    %r14,%rdx
call   1040 <err@plt>
jmp    1150 <full_write+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@EXIT_FAILURE = global i32 0
@.str = [3 x i8] c"%s\00"
define void @full_write(i32 %0, i8* %1, i64 %2, i8* %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i8*
%9 = alloca i64
store i32 %0, i32* %5
store i8* %1, i8** %6
store i64 %2, i64* %7
store i8* %3, i8** %8
br label %10
10: ; preds = %24, %4
%11 = load i64, i64* %7
%12 = icmp ne i64 %11, 0
br i1 %12, label %13, label %31
13: ; preds = %10
%14 = load i32, i32* %5
%15 = load i8*, i8** %6
%16 = load i64, i64* %7
%17 = call i64 @write(i32 %14, i8* %15, i64 %16)
store i64 %17, i64* %9
%18 = load i64, i64* %9
%19 = icmp slt i64 %18, 0
br i1 %19, label %20, label %24
20: ; preds = %13
%21 = load i32, i32* @EXIT_FAILURE
%22 = load i8*, i8** %8
%23 = call i32 @err(i32 %21, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %22)
br label %24
24: ; preds = %20, %13
%25 = load i64, i64* %9
%26 = load i64, i64* %7
%27 = sub i64 %26, %25
store i64 %27, i64* %7
%28 = load i64, i64* %9
%29 = load i8*, i8** %6
%30 = getelementptr i8, i8* %29, i64 %28
store i8* %30, i8** %6
br label %10
31: ; preds = %10
ret void
}

LLVM IR (-O2):
@EXIT_FAILURE = global i32 0
@.str = [3 x i8] c"%s\00"
define void @full_write(i32 %0, i8* nocapture %1, i64 %2, i8* %3) {
%5 = icmp eq i64 %2, 0
br i1 %5, label %18, label %6
6: ; preds = %4, %14
%7 = phi i8* [ %16, %14 ], [ %1, %4 ]
%8 = phi i64 [ %15, %14 ], [ %2, %4 ]
%9 = tail call i64 @write(i32 %0, i8* %7, i64 %8)
%10 = icmp slt i64 %9, 0
br i1 %10, label %11, label %14
11: ; preds = %6
%12 = load i32, i32* @EXIT_FAILURE
%13 = tail call i32 @err(i32 %12, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %3)
br label %14
14: ; preds = %11, %6
%15 = sub i64 %8, %9
%16 = getelementptr i8, i8* %7, i64 %9
%17 = icmp eq i64 %15, 0
br i1 %17, label %18, label %6
18: ; preds = %14, %4
ret void
}