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

/* Variables and functions */
scalar_t__ EINTR;
scalar_t__ errno;
int write(int, char const *, size_t);
int ss_write_bytevector(int fd, const char *buf, size_t count) {
  ssize_t res;
  do {
    res = write(fd, buf, count);
    if (res > 0) {
      buf += res;
      count -= res;
    }
  } while (count && (res != -1 || errno == EINTR));
  return res != -1;
}


x86 assembly (clang, -O0):
<ss_write_bytevector>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1030 <write@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jle    1160 <ss_write_bytevector+0x50>
mov    -0x1c(%rbp),%ecx
mov    -0x10(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x10(%rbp)
movslq -0x1c(%rbp),%rcx
mov    -0x18(%rbp),%rax
sub    %rcx,%rax
mov    %rax,-0x18(%rbp)
jmp    1165 <ss_write_bytevector+0x55>
xor    %eax,%eax
cmpq   $0x0,-0x18(%rbp)
mov    %al,-0x1d(%rbp)
je     11a4 <ss_write_bytevector+0x94>
mov    $0x1,%al
cmpl   $0xffffffff,-0x1c(%rbp)
mov    %al,-0x1e(%rbp)
jne    119e <ss_write_bytevector+0x8e>
mov    0x2e55(%rip),%rax
mov    (%rax),%rax
mov    0x2e43(%rip),%rcx
cmp    (%rcx),%rax
sete   %al
mov    %al,-0x1e(%rbp)
mov    -0x1e(%rbp),%al
mov    %al,-0x1d(%rbp)
mov    -0x1d(%rbp),%al
test   $0x1,%al
jne    1123 <ss_write_bytevector+0x13>
cmpl   $0xffffffff,-0x1c(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ss_write_bytevector>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdx,%rbx
mov    %rsi,%r14
mov    %edi,%ebp
mov    0x2eb9(%rip),%r15
mov    0x2eaa(%rip),%r12
xchg   %ax,%ax
mov    %ebp,%edi
mov    %r14,%rsi
mov    %rbx,%rdx
call   1030 <write@plt>
test   %eax,%eax
mov    $0x0,%ecx
cmovns %eax,%ecx
sub    %rcx,%rbx
je     115d <ss_write_bytevector+0x4d>
add    %rcx,%r14
cmp    $0xffffffff,%eax
jne    1130 <ss_write_bytevector+0x20>
mov    (%r12),%rcx
cmp    %rcx,(%r15)
je     1130 <ss_write_bytevector+0x20>
xor    %ecx,%ecx
cmp    $0xffffffff,%eax
setne  %cl
mov    %ecx,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

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