#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, int max_len) {
  char c;
  int len = 0;
  while ((c = getchar()) != EOF) {
    if (len >= max_len - 1)
      break;
    s[len++] = c;
    if (c == '\n')
      break;
  }
  s[len - 1] = 0;
  return len;
}


x86 assembly (clang, -O0):
<readln>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x14(%rbp)
mov    $0x0,%al
call   1030 <getchar@plt>
mov    %al,-0xd(%rbp)
movsbl %al,%eax
mov    0x2eae(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     118a <readln+0x7a>
mov    -0x14(%rbp),%eax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jl     115b <readln+0x4b>
jmp    118a <readln+0x7a>
mov    -0xd(%rbp),%dl
mov    -0x8(%rbp),%rax
mov    -0x14(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x14(%rbp)
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
movsbl -0xd(%rbp),%eax
cmp    $0xa,%eax
jne    1185 <readln+0x75>
jmp    118a <readln+0x7a>
jmp    1126 <readln+0x16>
mov    -0x8(%rbp),%rax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readln>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
add    $0xffffffff,%esi
movslq %esi,%r15
mov    0x2ec0(%rip),%r12
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1030 <getchar@plt>
cmp    (%r12),%al
je     114e <readln+0x3e>
cmp    %r15,%rbx
jge    114e <readln+0x3e>
mov    %al,(%r14,%rbx,1)
add    $0x1,%rbx
cmp    $0xa,%al
jne    1130 <readln+0x20>
lea    -0x1(%rbx),%eax
cltq
movb   $0x0,(%r14,%rax,1)
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

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