#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 read(int, char *, int);
int readln(int fildes, char *buf) {
  int i = 0, aux;
  for (i = 0; i < 128; i++) {
    aux = read(fildes, buf + i, 1);
    if (((char *)buf)[i] == '\n')
      break;
    if (aux <= 0)
      return aux;
  }
  ((char *)buf)[i] = '\0';
  return i + 1;
}


x86 assembly (clang, -O0):
<readln>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x80,-0x14(%rbp)
jge    1197 <readln+0x87>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
movslq -0x14(%rbp),%rax
add    %rax,%rsi
mov    $0x1,%edx
call   1030 <read@plt>
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0xa,%eax
jne    116f <readln+0x5f>
jmp    1197 <readln+0x87>
cmpl   $0x0,-0x18(%rbp)
jg     1184 <readln+0x74>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11ac <readln+0x9c>
jmp    1189 <readln+0x79>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    112d <readln+0x1d>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readln>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%rbx
mov    %edi,%r14d
xor    %ebp,%ebp
nopl   0x0(%rax)
lea    (%rbx,%rbp,1),%rsi
mov    %r14d,%edi
mov    $0x1,%edx
call   1030 <read@plt>
cmpb   $0xa,(%rbx,%rbp,1)
je     114f <readln+0x3f>
test   %eax,%eax
jle    115a <readln+0x4a>
add    $0x1,%rbp
cmp    $0x80,%rbp
jne    1120 <readln+0x10>
mov    $0x80,%eax
jmp    1151 <readln+0x41>
mov    %ebp,%eax
mov    %eax,%ecx
movb   $0x0,(%rbx,%rcx,1)
add    $0x1,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @readln(i32 %0, i8* nocapture %1) {
br label %3
3: ; preds = %2, %11
%4 = phi i64 [ 0, %2 ], [ %12, %11 ]
%5 = getelementptr inbounds i8, i8* %1, i64 %4
%6 = tail call i32 @read(i32 %0, i8* %5, i32 1)
%7 = load i8, i8* %5
%8 = icmp eq i8 %7, 10
br i1 %8, label %14, label %9
9: ; preds = %3
%10 = icmp slt i32 %6, 1
br i1 %10, label %21, label %11
11: ; preds = %9
%12 = add nuw nsw i64 %4, 1
%13 = icmp eq i64 %12, 128
br i1 %13, label %16, label %3
14: ; preds = %3
%15 = trunc i64 %4 to i32
br label %16
16: ; preds = %11, %14
%17 = phi i32 [ %15, %14 ], [ 128, %11 ]
%18 = zext i32 %17 to i64
%19 = getelementptr inbounds i8, i8* %1, i64 %18
store i8 0, i8* %19
%20 = add nuw nsw i32 %17, 1
br label %21
21: ; preds = %9, %16
%22 = phi i32 [ %20, %16 ], [ %6, %9 ]
ret i32 %22
}