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

/* Variables and functions */
scalar_t__ EINTR;
int /*<<< orphan*/ Error_Quit(char *);
scalar_t__ errno;
size_t write(int, char const *, size_t);
ssize_t Writeline(int sockd, const void *vptr, size_t n) {
  size_t nleft;
  ssize_t nwritten;
  const char *buffer;
  buffer = vptr;
  nleft = n;
  while (nleft > 0) {
    if ((nwritten = write(sockd, buffer, nleft)) <= 0) {
      if (errno == EINTR)
        nwritten = 0;
      else
        Error_Quit("Error in Writeline()");
    }
    nleft -= nwritten;
    buffer += nwritten;
  }
  return n;
}


x86 assembly (clang, -O0):
<Writeline>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jbe    11c4 <Writeline+0xa4>
mov    -0x4(%rbp),%edi
mov    -0x30(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1030 <write@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
ja     11a4 <Writeline+0x84>
mov    0x2e6d(%rip),%rax
mov    (%rax),%rax
mov    0x2e5b(%rip),%rcx
cmp    (%rcx),%rax
jne    1193 <Writeline+0x73>
movq   $0x0,-0x28(%rbp)
jmp    119f <Writeline+0x7f>
lea    0xe66(%rip),%rdi
call   1040 <Error_Quit@plt>
jmp    11a4 <Writeline+0x84>
mov    -0x28(%rbp),%rcx
mov    -0x20(%rbp),%rax
sub    %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x28(%rbp),%rax
add    -0x30(%rbp),%rax
mov    %rax,-0x30(%rbp)
jmp    1143 <Writeline+0x23>
mov    -0x18(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Writeline>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,(%rsp)
test   %rdx,%rdx
je     1184 <Writeline+0x64>
mov    %rsi,%rbx
mov    %edi,%r12d
mov    0x2e9f(%rip),%r15
mov    0x2e90(%rip),%r14
mov    (%rsp),%rbp
jmp    1158 <Writeline+0x38>
xchg   %ax,%ax
add    %r13,%rbx
sub    %r13,%rbp
je     1184 <Writeline+0x64>
mov    %r12d,%edi
mov    %rbx,%rsi
mov    %rbp,%rdx
call   1030 <write@plt>
mov    %rax,%r13
test   %rax,%rax
jne    1150 <Writeline+0x30>
mov    (%r15),%rax
cmp    (%r14),%rax
je     1150 <Writeline+0x30>
lea    0xe83(%rip),%rdi
call   1040 <Error_Quit@plt>
jmp    1150 <Writeline+0x30>
mov    (%rsp),%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@errno = global i64 0
@EINTR = global i64 0
@.str = [21 x i8] c"Error in Writeline()\00"
define i64 @Writeline(i32 %0, i8* %1, i64 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i64
%8 = alloca i64
%9 = alloca i8*
store i32 %0, i32* %4
store i8* %1, i8** %5
store i64 %2, i64* %6
%10 = load i8*, i8** %5
store i8* %10, i8** %9
%11 = load i64, i64* %6
store i64 %11, i64* %7
br label %12
12: ; preds = %29, %3
%13 = load i64, i64* %7
%14 = icmp ugt i64 %13, 0
br i1 %14, label %15, label %36
15: ; preds = %12
%16 = load i32, i32* %4
%17 = load i8*, i8** %9
%18 = load i64, i64* %7
%19 = call i64 @write(i32 %16, i8* %17, i64 %18)
store i64 %19, i64* %8
%20 = icmp ule i64 %19, 0
br i1 %20, label %21, label %29
21: ; preds = %15
%22 = load i64, i64* @errno
%23 = load i64, i64* @EINTR
%24 = icmp eq i64 %22, %23
br i1 %24, label %25, label %26
25: ; preds = %21
store i64 0, i64* %8
br label %28
26: ; preds = %21
%27 = call i32 @Error_Quit(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
br label %28
28: ; preds = %26, %25
br label %29
29: ; preds = %28, %15
%30 = load i64, i64* %8
%31 = load i64, i64* %7
%32 = sub i64 %31, %30
store i64 %32, i64* %7
%33 = load i64, i64* %8
%34 = load i8*, i8** %9
%35 = getelementptr inbounds i8, i8* %34, i64 %33
store i8* %35, i8** %9
br label %12
36: ; preds = %12
%37 = load i64, i64* %6
ret i64 %37
}

LLVM IR (-O2):
@errno = global i64 0
@EINTR = global i64 0
@.str = [21 x i8] c"Error in Writeline()\00"
define i64 @Writeline(i32 %0, i8* nocapture %1, i64 returned %2) {
%4 = icmp eq i64 %2, 0
br i1 %4, label %20, label %5
5: ; preds = %3, %16
%6 = phi i8* [ %18, %16 ], [ %1, %3 ]
%7 = phi i64 [ %17, %16 ], [ %2, %3 ]
%8 = tail call i64 @write(i32 %0, i8* %6, i64 %7)
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %16
10: ; preds = %5
%11 = load i64, i64* @errno
%12 = load i64, i64* @EINTR
%13 = icmp eq i64 %11, %12
br i1 %13, label %16, label %14
14: ; preds = %10
%15 = tail call i32 @Error_Quit(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
br label %16
16: ; preds = %10, %14, %5
%17 = sub i64 %7, %8
%18 = getelementptr inbounds i8, i8* %6, i64 %8
%19 = icmp eq i64 %17, 0
br i1 %19, label %20, label %5
20: ; preds = %16, %3
ret i64 %2
}