#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 */
size_t write(int, void const *, size_t);
int child_comm_send(int fd, const void *buf, size_t len) {
  size_t off = 0;
  while (off < len) {
    size_t wrote = write(fd, buf + off, len - off);
    if (wrote < 0)
      return -1;
    off += wrote;
  }
  return 0;
}


x86 assembly (clang, -O0):
<child_comm_send>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    117d <child_comm_send+0x6d>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
add    -0x20(%rbp),%rsi
mov    -0x18(%rbp),%rdx
sub    -0x20(%rbp),%rdx
call   1030 <write@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jae    116c <child_comm_send+0x5c>
movl   $0xffffffff,-0x4(%rbp)
jmp    1184 <child_comm_send+0x74>
mov    -0x28(%rbp),%rax
add    -0x20(%rbp),%rax
mov    %rax,-0x20(%rbp)
jmp    112b <child_comm_send+0x1b>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<child_comm_send>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
test   %rdx,%rdx
je     114a <child_comm_send+0x3a>
mov    %rdx,%rbx
mov    %rsi,%r14
mov    %edi,%r15d
xor    %ebp,%ebp
nopw   0x0(%rax,%rax,1)
lea    (%r14,%rbp,1),%rsi
mov    %rbx,%rdx
sub    %rbp,%rdx
mov    %r15d,%edi
call   1030 <write@plt>
add    %rax,%rbp
cmp    %rbx,%rbp
jb     1130 <child_comm_send+0x20>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @child_comm_send(i32 %0, i8* nocapture %1, i64 %2) {
%4 = icmp eq i64 %2, 0
br i1 %4, label %12, label %5
5: ; preds = %3, %5
%6 = phi i64 [ %10, %5 ], [ 0, %3 ]
%7 = getelementptr i8, i8* %1, i64 %6
%8 = sub i64 %2, %6
%9 = tail call i64 @write(i32 %0, i8* %7, i64 %8)
%10 = add i64 %9, %6
%11 = icmp ult i64 %10, %2
br i1 %11, label %5, label %12
12: ; preds = %5, %3
ret i32 0
}