#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
char EOF;
char fgetc(int /*<<< orphan*/ *);
void readline(FILE *_fid, char *_buffer, unsigned int _n) {
  unsigned int i = 0;
  char c;
  while ((c = fgetc(_fid)) != EOF && c != '\n' && i < _n - 1) {
    _buffer[i] = c;
    i++;
  }
  _buffer[i] = '\0';
}


x86 assembly (clang, -O0):
<readline>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <fgetc@plt>
mov    %al,-0x19(%rbp)
movsbl %al,%ecx
mov    0x2ea8(%rip),%rax
movsbl (%rax),%edx
xor    %eax,%eax
cmp    %edx,%ecx
mov    %al,-0x1a(%rbp)
je     1173 <readline+0x63>
movsbl -0x19(%rbp),%ecx
xor    %eax,%eax
cmp    $0xa,%ecx
mov    %al,-0x1a(%rbp)
je     1173 <readline+0x63>
mov    -0x18(%rbp),%eax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
setb   %al
mov    %al,-0x1a(%rbp)
mov    -0x1a(%rbp),%al
test   $0x1,%al
jne    1183 <readline+0x73>
jmp    119e <readline+0x8e>
mov    -0x19(%rbp),%dl
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%ecx
mov    %dl,(%rax,%rcx,1)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    112a <readline+0x1a>
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%ecx
movb   $0x0,(%rax,%rcx,1)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readline>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edx,%r15d
mov    %rsi,%r14
mov    %rdi,%r13
call   1030 <fgetc@plt>
xor    %ebp,%ebp
cmp    $0xa,%al
je     116f <readline+0x5f>
mov    0x2eb2(%rip),%r12
cmp    (%r12),%al
je     116f <readline+0x5f>
add    $0xffffffff,%r15d
je     116f <readline+0x5f>
mov    %r15d,%ebx
xor    %ebp,%ebp
nopw   0x0(%rax,%rax,1)
mov    %al,(%r14,%rbp,1)
add    $0x1,%rbp
mov    %r13,%rdi
call   1030 <fgetc@plt>
cmp    $0xa,%al
je     116f <readline+0x5f>
cmp    (%r12),%al
je     116f <readline+0x5f>
cmp    %rbx,%rbp
jb     1150 <readline+0x40>
movb   $0x0,(%r14,%rbp,1)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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