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

/* Variables and functions */
scalar_t__ fread(int *, int, int, int /*<<< orphan*/ *);
uint8_t readnline(FILE *fptr, uint8_t *out, uint8_t length) {
  uint8_t previ = 0, i = 0;
  do {
    previ = i;
    i += fread(out + i, 1, 1, fptr);
  } while (out[i - 1] != '\n' && i < length && previ != i);
  out[i - 1] = 0;
  return 0;
}


x86 assembly (clang, -O0):
<readnline>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
movslq -0x1c(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rdi
mov    -0x8(%rbp),%rcx
mov    $0x1,%edx
mov    %edx,%esi
call   1030 <fread@plt>
mov    %rax,%rcx
movslq -0x1c(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rcx
mov    -0x1c(%rbp),%eax
sub    $0x1,%eax
movslq %eax,%rdx
xor    %eax,%eax
cmpl   $0xa,(%rcx,%rdx,4)
mov    %al,-0x1d(%rbp)
je     119c <readnline+0x8c>
mov    -0x1c(%rbp),%ecx
xor    %eax,%eax
cmp    -0x14(%rbp),%ecx
mov    %al,-0x1d(%rbp)
jge    119c <readnline+0x8c>
mov    -0x18(%rbp),%eax
cmp    -0x1c(%rbp),%eax
setne  %al
mov    %al,-0x1d(%rbp)
mov    -0x1d(%rbp),%al
test   $0x1,%al
jne    1131 <readnline+0x21>
mov    -0x10(%rbp),%rax
mov    -0x1c(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movl   $0x0,(%rax,%rcx,4)
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readnline>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%r14d
mov    %rsi,%rbx
mov    %rdi,%r15
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movslq %ebp,%rbp
lea    (%rbx,%rbp,4),%rdi
mov    $0x1,%esi
mov    $0x1,%edx
mov    %r15,%rcx
call   1030 <fread@plt>
add    %eax,%ebp
movslq %ebp,%rcx
test   %eax,%eax
je     115e <readnline+0x4e>
cmpl   $0xa,-0x4(%rbx,%rcx,4)
je     115e <readnline+0x4e>
cmp    %r14d,%ebp
jl     1130 <readnline+0x20>
add    $0xffffffffffffffff,%rcx
movl   $0x0,(%rbx,%rcx,4)
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @readnline(i32* nocapture %0, i32* nocapture %1, i32 %2) {
br label %4
4: ; preds = %4, %3
%5 = phi i32 [ 0, %3 ], [ %10, %4 ]
%6 = sext i32 %5 to i64
%7 = getelementptr inbounds i32, i32* %1, i64 %6
%8 = tail call i64 @fread(i32* %7, i32 1, i32 1, i32* %0)
%9 = trunc i64 %8 to i32
%10 = add i32 %5, %9
%11 = add nsw i32 %10, -1
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds i32, i32* %1, i64 %12
%14 = load i32, i32* %13
%15 = icmp eq i32 %14, 10
%16 = icmp sge i32 %10, %2
%17 = select i1 %15, i1 true, i1 %16
%18 = icmp eq i32 %9, 0
%19 = or i1 %18, %17
br i1 %19, label %20, label %4
20: ; preds = %4
%21 = getelementptr inbounds i32, i32* %1, i64 %12
store i32 0, i32* %21
ret i32 0
}