#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 write(int, void *, size_t);
int write_full(int fd, void *buf, size_t size) {
  size_t insize = size;
  int now;
  while (size) {
    now = write(fd, buf, size);
    if (now <= 0)
      return now;
    size -= now;
    buf += now;
  }
  return insize;
}


x86 assembly (clang, -O0):
<write_full>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1183 <write_full+0x73>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1030 <write@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jg     115e <write_full+0x4e>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    118a <write_full+0x7a>
movslq -0x24(%rbp),%rcx
mov    -0x18(%rbp),%rax
sub    %rcx,%rax
mov    %rax,-0x18(%rbp)
mov    -0x24(%rbp),%ecx
mov    -0x10(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x10(%rbp)
jmp    112b <write_full+0x1b>
mov    -0x20(%rbp),%rax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_full>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdx,%r14
test   %rdx,%rdx
je     1151 <write_full+0x41>
mov    %rsi,%rbx
mov    %edi,%r15d
mov    %r14,%rbp
nopl   0x0(%rax,%rax,1)
mov    %r15d,%edi
mov    %rbx,%rsi
mov    %rbp,%rdx
call   1030 <write@plt>
test   %eax,%eax
jle    114e <write_full+0x3e>
mov    %eax,%eax
add    %rax,%rbx
sub    %rax,%rbp
jne    1130 <write_full+0x20>
jmp    1151 <write_full+0x41>
mov    %eax,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

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