#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 /*<<< orphan*/ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ ferror(int /*<<< orphan*/ *);
scalar_t__ fscanf(int /*<<< orphan*/ *, char *, char *);
void file_readline(FILE *file, char *output, int MaxLength) {
  char c = '\x07';
  char *outputscan = output;
  int i = 0;
  while (((int)c != '\n') && (!feof(file)) && (!ferror(file)))
    if ((fscanf(file, "%c", &c) >= 0) && ((c > 31) || (c == 9)) &&
        (i < MaxLength - 2)) {
      i++;
      *(outputscan++) = c;
    }
  *(outputscan++) = '\0';
}


x86 assembly (clang, -O0):
<file_readline>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movb   $0x7,-0x15(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
movsbl -0x15(%rbp),%ecx
xor    %eax,%eax
cmp    $0xa,%ecx
mov    %al,-0x25(%rbp)
je     1195 <file_readline+0x65>
mov    -0x8(%rbp),%rdi
call   1050 <feof@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x25(%rbp)
jne    1195 <file_readline+0x65>
mov    -0x8(%rbp),%rdi
call   1030 <ferror@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
mov    %al,-0x25(%rbp)
mov    -0x25(%rbp),%al
test   $0x1,%al
jne    11a5 <file_readline+0x75>
jmp    1210 <file_readline+0xe0>
mov    -0x8(%rbp),%rdi
lea    0xe50(%rip),%rsi
lea    -0x15(%rbp),%rdx
call   1040 <fscanf@plt>
cmp    $0x0,%rax
jl     120b <file_readline+0xdb>
movsbl -0x15(%rbp),%eax
cmp    $0x1f,%eax
jg     11dd <file_readline+0xad>
movsbl -0x15(%rbp),%eax
cmp    $0x9,%eax
jne    120b <file_readline+0xdb>
mov    -0x24(%rbp),%eax
mov    -0x14(%rbp),%ecx
sub    $0x2,%ecx
cmp    %ecx,%eax
jge    120b <file_readline+0xdb>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
mov    -0x15(%rbp),%cl
mov    -0x20(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x20(%rbp)
mov    %cl,(%rax)
jmp    1156 <file_readline+0x26>
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x20(%rbp)
movb   $0x0,(%rax)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<file_readline>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edx,%r14d
mov    %rsi,%r13
mov    %rdi,%rbp
movb   $0x7,0x7(%rsp)
add    $0xfffffffe,%r14d
xor    %ebx,%ebx
lea    0xeaa(%rip),%r15
lea    0x7(%rsp),%r12
jmp    1167 <file_readline+0x37>
nopl   (%rax)
cmpb   $0xa,0x7(%rsp)
je     11b7 <file_readline+0x87>
mov    %rbp,%rdi
call   1050 <feof@plt>
test   %eax,%eax
jne    11b7 <file_readline+0x87>
mov    %rbp,%rdi
call   1030 <ferror@plt>
test   %eax,%eax
jne    11b7 <file_readline+0x87>
mov    %rbp,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
call   1040 <fscanf@plt>
test   %rax,%rax
js     1160 <file_readline+0x30>
movzbl 0x7(%rsp),%eax
cmp    $0x20,%al
setl   %cl
cmp    $0x9,%al
setne  %dl
test   %dl,%cl
jne    1160 <file_readline+0x30>
cmp    %r14d,%ebx
jge    1160 <file_readline+0x30>
add    $0x1,%ebx
mov    %al,0x0(%r13)
add    $0x1,%r13
jmp    1160 <file_readline+0x30>
movb   $0x0,0x0(%r13)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%c\00"
define void @file_readline(i32* %0, i8* %1, i32 %2) {
%4 = alloca i32*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8
%8 = alloca i8*
%9 = alloca i32
store i32* %0, i32** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
store i8 7, i8* %7
%10 = load i8*, i8** %5
store i8* %10, i8** %8
store i32 0, i32* %9
br label %11
11: ; preds = %49, %3
%12 = load i8, i8* %7
%13 = sext i8 %12 to i32
%14 = icmp ne i32 %13, 10
br i1 %14, label %15, label %24
15: ; preds = %11
%16 = load i32*, i32** %4
%17 = call i32 @feof(i32* %16)
%18 = icmp ne i32 %17, 0
br i1 %18, label %24, label %19
19: ; preds = %15
%20 = load i32*, i32** %4
%21 = call i32 @ferror(i32* %20)
%22 = icmp ne i32 %21, 0
%23 = xor i1 %22, true
br label %24
24: ; preds = %19, %15, %11
%25 = phi i1 [ false, %15 ], [ false, %11 ], [ %23, %19 ]
br i1 %25, label %26, label %50
26: ; preds = %24
%27 = load i32*, i32** %4
%28 = call i64 @fscanf(i32* %27, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %7)
%29 = icmp sge i64 %28, 0
br i1 %29, label %30, label %49
30: ; preds = %26
%31 = load i8, i8* %7
%32 = sext i8 %31 to i32
%33 = icmp sgt i32 %32, 31
br i1 %33, label %38, label %34
34: ; preds = %30
%35 = load i8, i8* %7
%36 = sext i8 %35 to i32
%37 = icmp eq i32 %36, 9
br i1 %37, label %38, label %49
38: ; preds = %34, %30
%39 = load i32, i32* %9
%40 = load i32, i32* %6
%41 = sub nsw i32 %40, 2
%42 = icmp slt i32 %39, %41
br i1 %42, label %43, label %49
43: ; preds = %38
%44 = load i32, i32* %9
%45 = add nsw i32 %44, 1
store i32 %45, i32* %9
%46 = load i8, i8* %7
%47 = load i8*, i8** %8
%48 = getelementptr inbounds i8, i8* %47, i32 1
store i8* %48, i8** %8
store i8 %46, i8* %47
br label %49
49: ; preds = %43, %38, %34, %26
br label %11
50: ; preds = %24
%51 = load i8*, i8** %8
%52 = getelementptr inbounds i8, i8* %51, i32 1
store i8* %52, i8** %8
store i8 0, i8* %51
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"%c\00"
define void @file_readline(i32* nocapture %0, i8* nocapture writeonly %1, i32 %2) {
%4 = alloca i8
store i8 7, i8* %4
%5 = add nsw i32 %2, -2
br label %6
6: ; preds = %3, %27
%7 = phi i32 [ 0, %3 ], [ %29, %27 ]
%8 = phi i8* [ %1, %3 ], [ %28, %27 ]
%9 = call i32 @feof(i32* %0)
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %32
11: ; preds = %6
%12 = call i32 @ferror(i32* %0)
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %32
14: ; preds = %11
%15 = call i64 @fscanf(i32* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %4)
%16 = icmp sgt i64 %15, -1
br i1 %16, label %17, label %27
17: ; preds = %14
%18 = load i8, i8* %4
%19 = icmp sgt i8 %18, 31
%20 = icmp eq i8 %18, 9
%21 = or i1 %19, %20
%22 = icmp slt i32 %7, %5
%23 = select i1 %21, i1 %22, i1 false
br i1 %23, label %24, label %27
24: ; preds = %17
%25 = add nsw i32 %7, 1
%26 = getelementptr inbounds i8, i8* %8, i64 1
store i8 %18, i8* %8
br label %27
27: ; preds = %17, %24, %14
%28 = phi i8* [ %26, %24 ], [ %8, %17 ], [ %8, %14 ]
%29 = phi i32 [ %25, %24 ], [ %7, %17 ], [ %7, %14 ]
%30 = load i8, i8* %4
%31 = icmp eq i8 %30, 10
br i1 %31, label %32, label %6
32: ; preds = %27, %6, %11
%33 = phi i8* [ %28, %27 ], [ %8, %6 ], [ %8, %11 ]
store i8 0, i8* %33
ret void
}