#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 */
char EOF;
char getchar();
int readln(char s[]) {
  char ch;
  int i;
  int chars_remain;
  i = 0;
  chars_remain = 1;
  while (chars_remain) {
    ch = getchar();
    if ((ch == '\n') || (ch == EOF)) {
      chars_remain = 0;
    } else if (i < 20 - 1) {
      s[i] = ch;
      i++;
    }
  }
  s[i] = '\0';
  return i;
}


x86 assembly (clang, -O0):
<readln>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x1,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     1198 <readln+0x88>
mov    $0x0,%al
call   1030 <getchar@plt>
mov    %al,-0x9(%rbp)
movsbl -0x9(%rbp),%eax
cmp    $0xa,%eax
je     1161 <readln+0x51>
movsbl -0x9(%rbp),%eax
mov    0x2e92(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
jne    116d <readln+0x5d>
movl   $0x0,-0x14(%rbp)
jmp    1193 <readln+0x83>
cmpl   $0x13,-0x10(%rbp)
jge    118e <readln+0x7e>
mov    -0x9(%rbp),%dl
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1193 <readln+0x83>
jmp    112a <readln+0x1a>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readln>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%r14
xor    %ebp,%ebp
xor    %eax,%eax
call   1030 <getchar@plt>
cmp    $0xa,%al
je     115e <readln+0x4e>
mov    0x2ebd(%rip),%rbx
cmp    (%rbx),%al
je     115e <readln+0x4e>
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
cmp    $0x12,%ebp
jg     114f <readln+0x3f>
movslq %ebp,%rcx
mov    %al,(%r14,%rcx,1)
add    $0x1,%ebp
xor    %eax,%eax
call   1030 <getchar@plt>
cmp    $0xa,%al
je     115e <readln+0x4e>
cmp    (%rbx),%al
jne    1140 <readln+0x30>
movslq %ebp,%rax
movb   $0x0,(%r14,%rax,1)
pop    %rbx
pop    %r14
pop    %rbp
ret

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

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