#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();
char *readLine(char *input, int size) {
  int count = 0;
  while (1) {
    int c = getchar();
    if (c == '\n' || c == EOF || count >= size)
      break;
    input[count++] = (char)c;
  }
  input[count++] = 0x00;
  return input;
}


x86 assembly (clang, -O0):
<readLine>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    $0x0,%al
call   1030 <getchar@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xa,-0x14(%rbp)
je     1158 <readLine+0x48>
mov    -0x14(%rbp),%eax
mov    0x2ea4(%rip),%rcx
cmp    (%rcx),%eax
je     1158 <readLine+0x48>
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jl     115d <readLine+0x4d>
jmp    117c <readLine+0x6c>
mov    -0x14(%rbp),%eax
mov    %al,%dl
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x10(%rbp)
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
jmp    1126 <readLine+0x16>
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0x10(%rbp)
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readLine>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %esi,%r14d
mov    %rdi,%r12
xor    %ebp,%ebp
xor    %eax,%eax
call   1030 <getchar@plt>
cmp    $0xa,%eax
je     116e <readLine+0x5e>
mov    0x2eb5(%rip),%r15
cmp    (%r15),%eax
je     116e <readLine+0x5e>
test   %r14d,%r14d
jle    116e <readLine+0x5e>
mov    %r14d,%ebx
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %al,(%r12,%rbp,1)
add    $0x1,%rbp
xor    %eax,%eax
call   1030 <getchar@plt>
cmp    $0xa,%eax
je     116e <readLine+0x5e>
cmp    (%r15),%eax
je     116e <readLine+0x5e>
cmp    %rbx,%rbp
jb     1150 <readLine+0x40>
movb   $0x0,(%r12,%rbp,1)
mov    %r12,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@EOF = global i32 0
define i8* @readLine(i8* returned writeonly %0, i32 %1) {
%3 = tail call i32 (...) @getchar()
%4 = icmp ne i32 %3, 10
%5 = load i32, i32* @EOF
%6 = icmp ne i32 %3, %5
%7 = select i1 %4, i1 %6, i1 false
%8 = icmp sgt i32 %1, 0
%9 = and i1 %7, %8
br i1 %9, label %10, label %27
10: ; preds = %2
%11 = zext i32 %1 to i64
br label %12
12: ; preds = %10, %12
%13 = phi i64 [ 0, %10 ], [ %16, %12 ]
%14 = phi i32 [ %3, %10 ], [ %18, %12 ]
%15 = trunc i32 %14 to i8
%16 = add nuw nsw i64 %13, 1
%17 = getelementptr inbounds i8, i8* %0, i64 %13
store i8 %15, i8* %17
%18 = tail call i32 (...) @getchar()
%19 = icmp ne i32 %18, 10
%20 = load i32, i32* @EOF
%21 = icmp ne i32 %18, %20
%22 = select i1 %19, i1 %21, i1 false
%23 = icmp ult i64 %16, %11
%24 = select i1 %22, i1 %23, i1 false
br i1 %24, label %12, label %25
25: ; preds = %12
%26 = and i64 %16, 4294967295
br label %27
27: ; preds = %25, %2
%28 = phi i64 [ 0, %2 ], [ %26, %25 ]
%29 = getelementptr inbounds i8, i8* %0, i64 %28
store i8 0, i8* %29
ret i8* %0
}