#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 read(int, char *, int);
ssize_t Readline(int sockd, void *vptr, size_t maxlen) {
  ssize_t n, rc;
  char c, *buffer;
  buffer = vptr;
  for (n = 1; n < maxlen; n++) {
    if ((rc = read(sockd, &c, 1)) == 1) {
      *buffer++ = c;
      if (c == '\n')
        break;
    } else if (rc == 0) {
      if (n == 1)
        return 0;
      else
        break;
    } else {
      if (errno == EINTR)
        continue;
      Error_Quit("Error in Readline()");
    }
  }
  *buffer = 0;
  return n;
}


x86 assembly (clang, -O0):
<Readline>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0xc(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x40(%rbp)
movq   $0x1,-0x28(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x20(%rbp),%rax
jae    1209 <Readline+0xe9>
mov    -0xc(%rbp),%edi
lea    -0x31(%rbp),%rsi
mov    $0x1,%edx
call   1030 <read@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x1,%rax
jne    119b <Readline+0x7b>
mov    -0x31(%rbp),%cl
mov    -0x40(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x40(%rbp)
mov    %cl,(%rax)
movsbl -0x31(%rbp),%eax
cmp    $0xa,%eax
jne    1196 <Readline+0x76>
jmp    1209 <Readline+0xe9>
jmp    11f3 <Readline+0xd3>
cmpq   $0x0,-0x30(%rbp)
jne    11c3 <Readline+0xa3>
cmpq   $0x1,-0x28(%rbp)
jne    11be <Readline+0x9e>
movq   $0x0,-0x8(%rbp)
jmp    1218 <Readline+0xf8>
jmp    1209 <Readline+0xe9>
mov    0x2e16(%rip),%rax
mov    (%rax),%rax
mov    0x2e04(%rip),%rcx
cmp    (%rcx),%rax
jne    11e2 <Readline+0xc2>
jmp    11f8 <Readline+0xd8>
lea    0xe17(%rip),%rdi
call   1040 <Error_Quit@plt>
jmp    11f3 <Readline+0xd3>
jmp    11f8 <Readline+0xd8>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    1143 <Readline+0x23>
mov    -0x40(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Readline>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    $0x1,%ebx
cmp    $0x2,%rdx
jb     11c3 <Readline+0xa3>
mov    %rdx,%r15
mov    %edi,%ebp
mov    $0x1,%ebx
lea    0x7(%rsp),%r12
mov    0x2e85(%rip),%r13
jmp    117c <Readline+0x5c>
cs nopw 0x0(%rax,%rax,1)
nop
movzbl 0x7(%rsp),%eax
mov    %al,(%r14)
add    $0x1,%r14
cmpb   $0xa,0x7(%rsp)
je     11c3 <Readline+0xa3>
add    $0x1,%rbx
cmp    %rbx,%r15
je     11b4 <Readline+0x94>
mov    %ebp,%edi
mov    %r12,%rsi
mov    $0x1,%edx
call   1030 <read@plt>
cmp    $0x1,%rax
je     1160 <Readline+0x40>
test   %rax,%rax
je     11b9 <Readline+0x99>
mov    0x2e43(%rip),%rax
mov    (%rax),%rax
cmp    0x0(%r13),%rax
je     1173 <Readline+0x53>
lea    0xe53(%rip),%rdi
call   1040 <Error_Quit@plt>
jmp    1173 <Readline+0x53>
mov    %r15,%rbx
jmp    11c3 <Readline+0xa3>
cmp    $0x1,%rbx
jne    11c3 <Readline+0xa3>
xor    %ebx,%ebx
jmp    11c7 <Readline+0xa7>
movb   $0x0,(%r14)
mov    %rbx,%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 = [20 x i8] c"Error in Readline()\00"
define i64 @Readline(i32 %0, i8* %1, i64 %2) {
%4 = alloca i64
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i64
%9 = alloca i64
%10 = alloca i8
%11 = alloca i8*
store i32 %0, i32* %5
store i8* %1, i8** %6
store i64 %2, i64* %7
%12 = load i8*, i8** %6
store i8* %12, i8** %11
store i64 1, i64* %8
br label %13
13: ; preds = %47, %3
%14 = load i64, i64* %8
%15 = load i64, i64* %7
%16 = icmp ult i64 %14, %15
br i1 %16, label %17, label %50
17: ; preds = %13
%18 = load i32, i32* %5
%19 = call i64 @read(i32 %18, i8* %10, i32 1)
store i64 %19, i64* %9
%20 = icmp eq i64 %19, 1
br i1 %20, label %21, label %30
21: ; preds = %17
%22 = load i8, i8* %10
%23 = load i8*, i8** %11
%24 = getelementptr inbounds i8, i8* %23, i32 1
store i8* %24, i8** %11
store i8 %22, i8* %23
%25 = load i8, i8* %10
%26 = sext i8 %25 to i32
%27 = icmp eq i32 %26, 10
br i1 %27, label %28, label %29
28: ; preds = %21
br label %50
29: ; preds = %21
br label %46
30: ; preds = %17
%31 = load i64, i64* %9
%32 = icmp eq i64 %31, 0
br i1 %32, label %33, label %38
33: ; preds = %30
%34 = load i64, i64* %8
%35 = icmp eq i64 %34, 1
br i1 %35, label %36, label %37
36: ; preds = %33
store i64 0, i64* %4
br label %53
37: ; preds = %33
br label %50
38: ; preds = %30
%39 = load i64, i64* @errno
%40 = load i64, i64* @EINTR
%41 = icmp eq i64 %39, %40
br i1 %41, label %42, label %43
42: ; preds = %38
br label %47
43: ; preds = %38
%44 = call i32 @Error_Quit(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
br label %45
45: ; preds = %43
br label %46
46: ; preds = %45, %29
br label %47
47: ; preds = %46, %42
%48 = load i64, i64* %8
%49 = add i64 %48, 1
store i64 %49, i64* %8
br label %13
50: ; preds = %37, %28, %13
%51 = load i8*, i8** %11
store i8 0, i8* %51
%52 = load i64, i64* %8
store i64 %52, i64* %4
br label %53
53: ; preds = %50, %36
%54 = load i64, i64* %4
ret i64 %54
}

LLVM IR (-O2):
@errno = global i64 0
@EINTR = global i64 0
@.str = [20 x i8] c"Error in Readline()\00"
define i64 @Readline(i32 %0, i8* nocapture writeonly %1, i64 %2) {
%4 = alloca i8
%5 = icmp ugt i64 %2, 1
br i1 %5, label %6, label %27
6: ; preds = %3, %23
%7 = phi i8* [ %24, %23 ], [ %1, %3 ]
%8 = phi i64 [ %25, %23 ], [ 1, %3 ]
%9 = call i64 @read(i32 %0, i8* %4, i32 1)
switch i64 %9, label %17 [
i64 1, label %10
i64 0, label %15
]
10: ; preds = %6
%11 = load i8, i8* %4
%12 = getelementptr inbounds i8, i8* %7, i64 1
store i8 %11, i8* %7
%13 = load i8, i8* %4
%14 = icmp eq i8 %13, 10
br i1 %14, label %27, label %23
15: ; preds = %6
%16 = icmp eq i64 %8, 1
br i1 %16, label %30, label %27
17: ; preds = %6
%18 = load i64, i64* @errno
%19 = load i64, i64* @EINTR
%20 = icmp eq i64 %18, %19
br i1 %20, label %23, label %21
21: ; preds = %17
%22 = tail call i32 @Error_Quit(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
br label %23
23: ; preds = %21, %10, %17
%24 = phi i8* [ %12, %10 ], [ %7, %17 ], [ %7, %21 ]
%25 = add nuw i64 %8, 1
%26 = icmp eq i64 %25, %2
br i1 %26, label %27, label %6
27: ; preds = %23, %10, %3, %15
%28 = phi i64 [ %8, %15 ], [ 1, %3 ], [ %2, %23 ], [ %8, %10 ]
%29 = phi i8* [ %7, %15 ], [ %1, %3 ], [ %24, %23 ], [ %12, %10 ]
store i8 0, i8* %29
br label %30
30: ; preds = %15, %27
%31 = phi i64 [ %28, %27 ], [ 0, %15 ]
ret i64 %31
}