#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*/ *);
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ memset(char *, char, int);
int ReadLine(FILE *Fin, char *Line, int MaxLine) {
  int C;
  int i;
  memset(Line, '\0', MaxLine);
  if (feof(Fin))
    return (-1);
  i = 0;
  C = fgetc(Fin);
  if (C < 0)
    return (-1);
  while (!feof(Fin) && (C >= 0) && (i < MaxLine)) {
    if (C == '\n') {
      if (i > 0)
        return (i);
    } else {
      Line[i] = C;
      i++;
    }
    C = fgetc(Fin);
  }
  return (i);
}


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)
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%edx
xor    %esi,%esi
call   1030 <memset@plt>
mov    -0x10(%rbp),%rdi
call   1050 <feof@plt>
cmp    $0x0,%rax
je     1170 <ReadLine+0x40>
movl   $0xffffffff,-0x4(%rbp)
jmp    1238 <ReadLine+0x108>
movl   $0x0,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <fgetc@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jge    1199 <ReadLine+0x69>
movl   $0xffffffff,-0x4(%rbp)
jmp    1238 <ReadLine+0x108>
jmp    119e <ReadLine+0x6e>
mov    -0x10(%rbp),%rdi
call   1050 <feof@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x25(%rbp)
jne    11d4 <ReadLine+0xa4>
xor    %eax,%eax
cmpl   $0x0,-0x20(%rbp)
mov    %al,-0x25(%rbp)
jl     11d4 <ReadLine+0xa4>
mov    -0x24(%rbp),%eax
cmp    -0x1c(%rbp),%eax
setl   %al
mov    %al,-0x25(%rbp)
mov    -0x25(%rbp),%al
test   $0x1,%al
jne    11e4 <ReadLine+0xb4>
jmp    1232 <ReadLine+0x102>
cmpl   $0xa,-0x20(%rbp)
jne    1208 <ReadLine+0xd8>
cmpl   $0x0,-0x24(%rbp)
jle    1203 <ReadLine+0xd3>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1238 <ReadLine+0x108>
jmp    1221 <ReadLine+0xf1>
mov    -0x20(%rbp),%eax
mov    %al,%dl
mov    -0x18(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <fgetc@plt>
mov    %eax,-0x20(%rbp)
jmp    119e <ReadLine+0x6e>
mov    -0x24(%rbp),%eax
mov    %eax,-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    %edx,%r15d
mov    %rsi,%r14
mov    %rdi,%r12
mov    %rsi,%rdi
xor    %esi,%esi
call   1030 <memset@plt>
mov    %r12,%rdi
call   1050 <feof@plt>
mov    $0xffffffff,%ebp
test   %rax,%rax
je     1168 <ReadLine+0x38>
mov    %ebp,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %r12,%rdi
call   1040 <fgetc@plt>
test   %eax,%eax
js     115d <ReadLine+0x2d>
mov    %eax,%ebx
mov    %r12,%rdi
call   1050 <feof@plt>
xor    %ebp,%ebp
test   %rax,%rax
jne    115d <ReadLine+0x2d>
test   %r15d,%r15d
jle    115d <ReadLine+0x2d>
xor    %ebp,%ebp
nopl   0x0(%rax)
cmp    $0xa,%ebx
jne    11a0 <ReadLine+0x70>
test   %ebp,%ebp
jle    11aa <ReadLine+0x7a>
jmp    115d <ReadLine+0x2d>
nopl   0x0(%rax,%rax,1)
movslq %ebp,%rbp
mov    %bl,(%r14,%rbp,1)
add    $0x1,%ebp
mov    %r12,%rdi
call   1040 <fgetc@plt>
mov    %eax,%ebx
mov    %r12,%rdi
call   1050 <feof@plt>
test   %ebx,%ebx
js     115d <ReadLine+0x2d>
test   %rax,%rax
jne    115d <ReadLine+0x2d>
cmp    %r15d,%ebp
jl     1190 <ReadLine+0x60>
jmp    115d <ReadLine+0x2d>

LLVM IR (-O0):
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
store i32* %0, i32** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
%10 = load i8*, i8** %6
%11 = load i32, i32* %7
%12 = call i32 @memset(i8* %10, i8 signext 0, i32 %11)
%13 = load i32*, i32** %5
%14 = call i64 @feof(i32* %13)
%15 = icmp ne i64 %14, 0
br i1 %15, label %16, label %17
16: ; preds = %3
store i32 -1, i32* %4
br label %60
17: ; preds = %3
store i32 0, i32* %9
%18 = load i32*, i32** %5
%19 = call i32 @fgetc(i32* %18)
store i32 %19, i32* %8
%20 = load i32, i32* %8
%21 = icmp slt i32 %20, 0
br i1 %21, label %22, label %23
22: ; preds = %17
store i32 -1, i32* %4
br label %60
23: ; preds = %17
br label %24
24: ; preds = %55, %23
%25 = load i32*, i32** %5
%26 = call i64 @feof(i32* %25)
%27 = icmp ne i64 %26, 0
br i1 %27, label %35, label %28
28: ; preds = %24
%29 = load i32, i32* %8
%30 = icmp sge i32 %29, 0
br i1 %30, label %31, label %35
31: ; preds = %28
%32 = load i32, i32* %9
%33 = load i32, i32* %7
%34 = icmp slt i32 %32, %33
br label %35
35: ; preds = %31, %28, %24
%36 = phi i1 [ false, %28 ], [ false, %24 ], [ %34, %31 ]
br i1 %36, label %37, label %58
37: ; preds = %35
%38 = load i32, i32* %8
%39 = icmp eq i32 %38, 10
br i1 %39, label %40, label %46
40: ; preds = %37
%41 = load i32, i32* %9
%42 = icmp sgt i32 %41, 0
br i1 %42, label %43, label %45
43: ; preds = %40
%44 = load i32, i32* %9
store i32 %44, i32* %4
br label %60
45: ; preds = %40
br label %55
46: ; preds = %37
%47 = load i32, i32* %8
%48 = trunc i32 %47 to i8
%49 = load i8*, i8** %6
%50 = load i32, i32* %9
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds i8, i8* %49, i64 %51
store i8 %48, i8* %52
%53 = load i32, i32* %9
%54 = add nsw i32 %53, 1
store i32 %54, i32* %9
br label %55
55: ; preds = %46, %45
%56 = load i32*, i32** %5
%57 = call i32 @fgetc(i32* %56)
store i32 %57, i32* %8
br label %24
58: ; preds = %35
%59 = load i32, i32* %9
store i32 %59, i32* %4
br label %60
60: ; preds = %58, %43, %22, %16
%61 = load i32, i32* %4
ret i32 %61
}

LLVM IR (-O2):
define i32 @ReadLine(i32* nocapture %0, i8* %1, i32 %2) {
%4 = tail call i32 @memset(i8* %1, i8 signext 0, i32 %2)
%5 = tail call i64 @feof(i32* %0)
%6 = icmp eq i64 %5, 0
br i1 %6, label %7, label %35
7: ; preds = %3
%8 = tail call i32 @fgetc(i32* %0)
%9 = icmp slt i32 %8, 0
br i1 %9, label %35, label %10
10: ; preds = %7
%11 = tail call i64 @feof(i32* %0)
%12 = icmp eq i64 %11, 0
%13 = icmp sgt i32 %2, 0
%14 = and i1 %12, %13
br i1 %14, label %15, label %35
15: ; preds = %10, %26
%16 = phi i32 [ %27, %26 ], [ 0, %10 ]
%17 = phi i32 [ %28, %26 ], [ %8, %10 ]
%18 = icmp eq i32 %17, 10
br i1 %18, label %19, label %21
19: ; preds = %15
%20 = icmp sgt i32 %16, 0
br i1 %20, label %35, label %26
21: ; preds = %15
%22 = trunc i32 %17 to i8
%23 = sext i32 %16 to i64
%24 = getelementptr inbounds i8, i8* %1, i64 %23
store i8 %22, i8* %24
%25 = add nsw i32 %16, 1
br label %26
26: ; preds = %19, %21
%27 = phi i32 [ %16, %19 ], [ %25, %21 ]
%28 = tail call i32 @fgetc(i32* %0)
%29 = tail call i64 @feof(i32* %0)
%30 = icmp eq i64 %29, 0
%31 = icmp sgt i32 %28, -1
%32 = and i1 %31, %30
%33 = icmp slt i32 %27, %2
%34 = select i1 %32, i1 %33, i1 false
br i1 %34, label %15, label %35
35: ; preds = %19, %26, %10, %7, %3
%36 = phi i32 [ -1, %3 ], [ -1, %7 ], [ 0, %10 ], [ %16, %19 ], [ %27, %26 ]
ret i32 %36
}