#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 getlinee(char s[], int lim) {
  int i, c;
  for (i = 0; (i < lim - 1) && ((c = getchar()) != EOF) && (c != '\n'); i++)
    s[i] = c;
  s[i] = '\0';
  return i;
}


x86 assembly (clang, -O0):
<getlinee>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%ecx
mov    -0xc(%rbp),%edx
sub    $0x1,%edx
xor    %eax,%eax
cmp    %edx,%ecx
mov    %al,-0x15(%rbp)
jge    1166 <getlinee+0x56>
mov    $0x0,%al
call   1030 <getchar@plt>
mov    %eax,%ecx
mov    %ecx,-0x14(%rbp)
xor    %eax,%eax
mov    0x2e97(%rip),%rdx
cmp    (%rdx),%ecx
mov    %al,-0x15(%rbp)
je     1166 <getlinee+0x56>
cmpl   $0xa,-0x14(%rbp)
setne  %al
mov    %al,-0x15(%rbp)
mov    -0x15(%rbp),%al
test   $0x1,%al
jne    1176 <getlinee+0x66>
jmp    1194 <getlinee+0x84>
mov    -0x14(%rbp),%eax
mov    %al,%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    1126 <getlinee+0x16>
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):
<getlinee>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdi,%r15
xor    %ebp,%ebp
cmp    $0x2,%esi
jl     1162 <getlinee+0x52>
mov    %esi,%r14d
add    $0xffffffff,%r14d
mov    %r14d,%ebx
mov    0x2eb5(%rip),%r12
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nop
xor    %eax,%eax
call   1030 <getchar@plt>
cmp    $0xa,%eax
je     1162 <getlinee+0x52>
cmp    (%r12),%eax
je     1162 <getlinee+0x52>
mov    %al,(%r15,%rbp,1)
add    $0x1,%rbp
cmp    %rbp,%rbx
jne    1140 <getlinee+0x30>
mov    %r14d,%ebp
mov    %ebp,%eax
movb   $0x0,(%r15,%rax,1)
mov    %ebp,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

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