#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 scalar_t__ uint32_t;
typedef int int32_t;

/* Variables and functions */
int write(int, int /*<<< orphan*/ *, scalar_t__);
int32_t writeall(int sock, uint8_t *buff, uint32_t leng) {
  uint32_t bsent;
  int res;
  bsent = 0;
  while (bsent < leng) {
    res = write(sock, buff + bsent, leng - bsent);
    if (res < 0) {
      return -1;
    }
    bsent += res;
  }
  return bsent;
}


x86 assembly (clang, -O0):
<writeall>:
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
jge    1182 <writeall+0x72>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x20(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
mov    -0x18(%rbp),%rdx
sub    -0x20(%rbp),%rdx
call   1030 <write@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    1171 <writeall+0x61>
movl   $0xffffffff,-0x4(%rbp)
jmp    1189 <writeall+0x79>
movslq -0x24(%rbp),%rax
add    -0x20(%rbp),%rax
mov    %rax,-0x20(%rbp)
jmp    112b <writeall+0x1b>
mov    -0x20(%rbp),%rax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<writeall>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
test   %rdx,%rdx
jle    1151 <writeall+0x41>
mov    %rdx,%r14
mov    %rsi,%r15
mov    %edi,%ebp
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
lea    (%r15,%rbx,4),%rsi
mov    %r14,%rdx
sub    %rbx,%rdx
mov    %ebp,%edi
call   1030 <write@plt>
test   %eax,%eax
js     1155 <writeall+0x45>
mov    %eax,%eax
add    %rax,%rbx
cmp    %r14,%rbx
jl     1130 <writeall+0x20>
jmp    115a <writeall+0x4a>
xor    %ebx,%ebx
jmp    115a <writeall+0x4a>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

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