#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 */

/* Variables and functions */
int EOF;
int getchar();
int readLine(char line[], int maxlength) {
  int c;
  int i = -1;
  do {
    c = getchar();
    if (c == EOF)
      c = '\0';
    line[++i] = (char)c;
    if (line[i] == '\n')
      break;
    if (line[i] == '\r')
      break;
    if (line[i] == '\0')
      break;
  } while (i + 1 < maxlength);
  return i;
}


x86 assembly (clang, -O0):
<readLine>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0xffffffff,-0x14(%rbp)
mov    $0x0,%al
call   1030 <getchar@plt>
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
mov    0x2eae(%rip),%rcx
cmp    (%rcx),%eax
jne    1149 <readLine+0x39>
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
mov    %al,%dl
mov    -0x8(%rbp),%rax
mov    -0x14(%rbp),%ecx
add    $0x1,%ecx
mov    %ecx,-0x14(%rbp)
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0xa,%eax
jne    117b <readLine+0x6b>
jmp    11c3 <readLine+0xb3>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0xd,%eax
jne    1195 <readLine+0x85>
jmp    11c3 <readLine+0xb3>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
jne    11af <readLine+0x9f>
jmp    11c3 <readLine+0xb3>
jmp    11b4 <readLine+0xa4>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
cmp    -0xc(%rbp),%eax
jl     1126 <readLine+0x16>
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readLine>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r15
cmp    $0x2,%esi
mov    $0x1,%r14d
cmovge %esi,%r14d
add    $0xffffffff,%r14d
lea    0x1(%r14),%r12
mov    0x2eae(%rip),%r13
mov    $0x2401,%ebp
xor    %ebx,%ebx
jmp    1159 <readLine+0x49>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
add    $0x1,%rbx
cmp    %rbx,%r12
je     1182 <readLine+0x72>
xor    %eax,%eax
call   1030 <getchar@plt>
mov    $0x0,%ecx
cmp    0x0(%r13),%eax
je     116d <readLine+0x5d>
mov    %eax,%ecx
mov    %cl,(%r15,%rbx,1)
cmp    $0xd,%cl
ja     1150 <readLine+0x40>
movzbl %cl,%eax
bt     %rax,%rbp
jae    1150 <readLine+0x40>
mov    %ebx,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@EOF = global i32 0
define i32 @readLine(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
store i32 -1, i32* %6
br label %7
7: ; preds = %48, %2
%8 = call i32 (...) @getchar()
store i32 %8, i32* %5
%9 = load i32, i32* %5
%10 = load i32, i32* @EOF
%11 = icmp eq i32 %9, %10
br i1 %11, label %12, label %13
12: ; preds = %7
store i32 0, i32* %5
br label %13
13: ; preds = %12, %7
%14 = load i32, i32* %5
%15 = trunc i32 %14 to i8
%16 = load i8*, i8** %3
%17 = load i32, i32* %6
%18 = add nsw i32 %17, 1
store i32 %18, i32* %6
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i8, i8* %16, i64 %19
store i8 %15, i8* %20
%21 = load i8*, i8** %3
%22 = load i32, i32* %6
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8, i8* %21, i64 %23
%25 = load i8, i8* %24
%26 = sext i8 %25 to i32
%27 = icmp eq i32 %26, 10
br i1 %27, label %28, label %29
28: ; preds = %13
br label %53
29: ; preds = %13
%30 = load i8*, i8** %3
%31 = load i32, i32* %6
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i8, i8* %30, i64 %32
%34 = load i8, i8* %33
%35 = sext i8 %34 to i32
%36 = icmp eq i32 %35, 13
br i1 %36, label %37, label %38
37: ; preds = %29
br label %53
38: ; preds = %29
%39 = load i8*, i8** %3
%40 = load i32, i32* %6
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds i8, i8* %39, i64 %41
%43 = load i8, i8* %42
%44 = sext i8 %43 to i32
%45 = icmp eq i32 %44, 0
br i1 %45, label %46, label %47
46: ; preds = %38
br label %53
47: ; preds = %38
br label %48
48: ; preds = %47
%49 = load i32, i32* %6
%50 = add nsw i32 %49, 1
%51 = load i32, i32* %4
%52 = icmp slt i32 %50, %51
br i1 %52, label %7, label %53
53: ; preds = %48, %46, %37, %28
%54 = load i32, i32* %6
ret i32 %54
}

LLVM IR (-O2):
@EOF = global i32 0
define i32 @readLine(i8* nocapture writeonly %0, i32 %1) {
%3 = call i32 @llvm.smax.i32(i32 %1, i32 1)
%4 = add nsw i32 %3, -1
%5 = zext i32 %4 to i64
br label %6
6: ; preds = %15, %2
%7 = phi i64 [ %13, %15 ], [ -1, %2 ]
%8 = tail call i32 (...) @getchar()
%9 = load i32, i32* @EOF
%10 = icmp eq i32 %8, %9
%11 = trunc i32 %8 to i8
%12 = select i1 %10, i8 0, i8 %11
%13 = add nsw i64 %7, 1
%14 = getelementptr inbounds i8, i8* %0, i64 %13
store i8 %12, i8* %14
switch i8 %12, label %15 [
i8 10, label %17
i8 13, label %17
i8 0, label %17
]
15: ; preds = %6
%16 = icmp eq i64 %13, %5
br i1 %16, label %19, label %6
17: ; preds = %6, %6, %6
%18 = trunc i64 %13 to i32
br label %19
19: ; preds = %15, %17
%20 = phi i32 [ %18, %17 ], [ %4, %15 ]
ret i32 %20
}