#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 */
scalar_t__ feof(int /*<<< orphan*/ *);
scalar_t__ fgetc(int /*<<< orphan*/ *);
int readline(FILE *in, char *out, size_t out_size) {
  for (size_t i = 0; i < out_size; i++) {
    if ((out[i] = (char)fgetc(in)) == '\n') {
      out[i] = '\0';
      return 0;
    }
    if (feof(in) != 0)
      return -1;
  }
  return -1;
}


x86 assembly (clang, -O0):
<readline>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x20(%rbp),%rax
jae    11b7 <readline+0x97>
mov    -0x10(%rbp),%rdi
call   1030 <fgetc@plt>
mov    -0x18(%rbp),%rcx
mov    -0x28(%rbp),%rdx
mov    %al,(%rcx,%rdx,1)
movsbl %al,%eax
cmp    $0xa,%eax
jne    1182 <readline+0x62>
mov    -0x18(%rbp),%rax
mov    -0x28(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
movl   $0x0,-0x4(%rbp)
jmp    11be <readline+0x9e>
mov    -0x10(%rbp),%rdi
call   1040 <feof@plt>
cmp    $0x0,%rax
je     11a1 <readline+0x81>
movl   $0xffffffff,-0x4(%rbp)
jmp    11be <readline+0x9e>
jmp    11a6 <readline+0x86>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    113c <readline+0x1c>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readline>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    $0xffffffff,%r14d
test   %rdx,%rdx
je     1185 <readline+0x65>
mov    %rdx,%r12
mov    %rsi,%r15
mov    %rdi,%rbx
mov    $0x1,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1030 <fgetc@plt>
mov    %al,-0x1(%r15,%rbp,1)
cmp    $0xa,%al
je     117c <readline+0x5c>
mov    %rbx,%rdi
call   1040 <feof@plt>
test   %rax,%rax
jne    1185 <readline+0x65>
lea    0x1(%rbp),%rax
cmp    %r12,%rbp
mov    %rax,%rbp
jb     1150 <readline+0x30>
jmp    1185 <readline+0x65>
movb   $0x0,-0x1(%r15,%rbp,1)
xor    %r14d,%r14d
mov    %r14d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @readline(i32* nocapture %0, i8* nocapture writeonly %1, i64 %2) {
%4 = icmp eq i64 %2, 0
br i1 %4, label %19, label %5
5: ; preds = %3, %13
%6 = phi i64 [ %16, %13 ], [ 0, %3 ]
%7 = tail call i64 @fgetc(i32* %0)
%8 = trunc i64 %7 to i8
%9 = getelementptr inbounds i8, i8* %1, i64 %6
store i8 %8, i8* %9
%10 = icmp eq i8 %8, 10
br i1 %10, label %11, label %13
11: ; preds = %5
%12 = getelementptr inbounds i8, i8* %1, i64 %6
store i8 0, i8* %12
br label %19
13: ; preds = %5
%14 = tail call i64 @feof(i32* %0)
%15 = icmp eq i64 %14, 0
%16 = add nuw i64 %6, 1
%17 = icmp ult i64 %16, %2
%18 = select i1 %15, i1 %17, i1 false
br i1 %18, label %5, label %19
19: ; preds = %13, %3, %11
%20 = phi i32 [ 0, %11 ], [ -1, %3 ], [ -1, %13 ]
ret i32 %20
}