#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*/ time_t;
struct link {
  int dummy;
};
typedef int ssize_t;

/* Variables and functions */
int EINVAL;
int errno;
int link_write(struct link *, char const *, size_t, int /*<<< orphan*/);
ssize_t link_putlstring(struct link *link, const char *data, size_t count,
                        time_t stoptime) {
  ssize_t total = 0;
  if (!link)
    return errno = EINVAL, -1;
  while (count > 0) {
    ssize_t w = link_write(link, data, count, stoptime);
    if (w == -1)
      return -1;
    count -= w;
    total += w;
    data += w;
  }
  return total;
}


x86 assembly (clang, -O0):
<link_putlstring>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1157 <link_putlstring+0x47>
mov    0x2e98(%rip),%rax
mov    (%rax),%ecx
mov    0x2e97(%rip),%rax
mov    %ecx,(%rax)
movl   $0xffffffff,-0x4(%rbp)
jmp    11c8 <link_putlstring+0xb8>
jmp    115c <link_putlstring+0x4c>
cmpq   $0x0,-0x20(%rbp)
jbe    11c2 <link_putlstring+0xb2>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    -0x24(%rbp),%ecx
call   1030 <link_write@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0xffffffff,-0x2c(%rbp)
jne    1194 <link_putlstring+0x84>
movl   $0xffffffff,-0x4(%rbp)
jmp    11c8 <link_putlstring+0xb8>
movslq -0x2c(%rbp),%rcx
mov    -0x20(%rbp),%rax
sub    %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x2c(%rbp),%eax
add    -0x28(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x2c(%rbp),%ecx
mov    -0x18(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x18(%rbp)
jmp    115c <link_putlstring+0x4c>
mov    -0x28(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<link_putlstring>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
test   %rdi,%rdi
je     1158 <link_putlstring+0x48>
mov    %ecx,%r14d
mov    %rdx,%rbp
mov    %rsi,%rbx
mov    %rdi,%r12
xor    %r15d,%r15d
nopl   0x0(%rax)
test   %rbp,%rbp
je     1170 <link_putlstring+0x60>
mov    %r12,%rdi
mov    %rbx,%rsi
mov    %rbp,%rdx
mov    %r14d,%ecx
call   1030 <link_write@plt>
cltq
sub    %rax,%rbp
add    %eax,%r15d
add    %rax,%rbx
cmp    $0xffffffff,%eax
jne    1130 <link_putlstring+0x20>
jmp    116a <link_putlstring+0x5a>
mov    0x2e79(%rip),%rax
mov    (%rax),%eax
mov    0x2e78(%rip),%rcx
mov    %eax,(%rcx)
mov    $0xffffffff,%r15d
mov    %r15d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.link = type { i32 }
@EINVAL = global i32 0
@errno = global i32 0
define i32 @link_putlstring(%struct.link* %0, i8* %1, i64 %2, i32 %3) {
%5 = alloca i32
%6 = alloca %struct.link*
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store %struct.link* %0, %struct.link** %6
store i8* %1, i8** %7
store i64 %2, i64* %8
store i32 %3, i32* %9
store i32 0, i32* %10
%12 = load %struct.link*, %struct.link** %6
%13 = icmp ne %struct.link* %12, null
br i1 %13, label %16, label %14
14: ; preds = %4
%15 = load i32, i32* @EINVAL
store i32 %15, i32* @errno
store i32 -1, i32* %5
br label %43
16: ; preds = %4
br label %17
17: ; preds = %29, %16
%18 = load i64, i64* %8
%19 = icmp ugt i64 %18, 0
br i1 %19, label %20, label %41
20: ; preds = %17
%21 = load %struct.link*, %struct.link** %6
%22 = load i8*, i8** %7
%23 = load i64, i64* %8
%24 = load i32, i32* %9
%25 = call i32 @link_write(%struct.link* %21, i8* %22, i64 %23, i32 %24)
store i32 %25, i32* %11
%26 = load i32, i32* %11
%27 = icmp eq i32 %26, -1
br i1 %27, label %28, label %29
28: ; preds = %20
store i32 -1, i32* %5
br label %43
29: ; preds = %20
%30 = load i32, i32* %11
%31 = sext i32 %30 to i64
%32 = load i64, i64* %8
%33 = sub i64 %32, %31
store i64 %33, i64* %8
%34 = load i32, i32* %11
%35 = load i32, i32* %10
%36 = add nsw i32 %35, %34
store i32 %36, i32* %10
%37 = load i32, i32* %11
%38 = load i8*, i8** %7
%39 = sext i32 %37 to i64
%40 = getelementptr inbounds i8, i8* %38, i64 %39
store i8* %40, i8** %7
br label %17
41: ; preds = %17
%42 = load i32, i32* %10
store i32 %42, i32* %5
br label %43
43: ; preds = %41, %28, %14
%44 = load i32, i32* %5
ret i32 %44
}

LLVM IR (-O2):
%struct.link = type { i32 }
@EINVAL = global i32 0
@errno = global i32 0
define i32 @link_putlstring(%struct.link* %0, i8* %1, i64 %2, i32 %3) {
%5 = icmp eq %struct.link* %0, null
br i1 %5, label %6, label %8
6: ; preds = %4
%7 = load i32, i32* @EINVAL
store i32 %7, i32* @errno
br label %20
8: ; preds = %4, %13
%9 = phi i64 [ %17, %13 ], [ %2, %4 ]
%10 = phi i8* [ %19, %13 ], [ %1, %4 ]
%11 = phi i32 [ %18, %13 ], [ 0, %4 ]
%12 = icmp eq i64 %9, 0
br i1 %12, label %20, label %13
13: ; preds = %8
%14 = tail call i32 @link_write(%struct.link* %0, i8* %10, i64 %9, i32 %3)
%15 = icmp eq i32 %14, -1
%16 = sext i32 %14 to i64
%17 = sub i64 %9, %16
%18 = add nsw i32 %14, %11
%19 = getelementptr inbounds i8, i8* %10, i64 %16
br i1 %15, label %20, label %8
20: ; preds = %8, %13, %6
%21 = phi i32 [ -1, %6 ], [ %11, %8 ], [ -1, %13 ]
ret i32 %21
}