#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 */
int EOF;
int getc(int /*<<< orphan*/ *);
int readline(FILE *fin, char *line, int maxlen) {
  int i;
  int ct;
  char c;
  for (i = 0; i < maxlen - 1; i++) {
    ct = getc(fin);
    if (ct == '\n') {
      break;
    }
    if (ct == EOF) {
      if (i == 0) {
        return -1;
      }
      break;
    }
    line[i] = (char)ct;
  }
  line[i] = '\0';
  return 0;
}


x86 assembly (clang, -O0):
<readline>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
mov    -0x1c(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    11a1 <readline+0x91>
mov    -0x10(%rbp),%rdi
call   1030 <getc@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0xa,-0x24(%rbp)
jne    1156 <readline+0x46>
jmp    11a1 <readline+0x91>
mov    -0x24(%rbp),%eax
mov    0x2e88(%rip),%rcx
cmp    (%rcx),%eax
jne    1183 <readline+0x73>
cmpl   $0x0,-0x20(%rbp)
jne    117e <readline+0x6e>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b4 <readline+0xa4>
jmp    11a1 <readline+0x91>
mov    -0x24(%rbp),%eax
mov    %al,%dl
mov    -0x18(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    112a <readline+0x1a>
mov    -0x18(%rbp),%rax
movslq -0x20(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readline>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r12
xor    %eax,%eax
mov    $0x0,%ebx
cmp    $0x2,%edx
jl     116f <readline+0x5f>
mov    %edx,%r15d
mov    %rdi,%r13
add    $0xffffffff,%r15d
mov    %r15d,%ebp
xor    %ebx,%ebx
mov    0x2ea8(%rip),%r14
mov    %r13,%rdi
call   1030 <getc@plt>
cmp    $0xa,%eax
je     1162 <readline+0x52>
cmp    (%r14),%eax
je     1166 <readline+0x56>
mov    %al,(%r12,%rbx,1)
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1140 <readline+0x30>
mov    %r15d,%ebx
xor    %eax,%eax
jmp    116f <readline+0x5f>
test   %ebx,%ebx
mov    $0x0,%eax
je     1185 <readline+0x75>
mov    %ebx,%ecx
movb   $0x0,(%r12,%rcx,1)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    $0xffffffff,%eax
jmp    1176 <readline+0x66>

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

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