#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 */

/* Variables and functions */
int /*<<< orphan*/ Console_Flush();
int /*<<< orphan*/ Console_Read(unsigned char *);
long long Platform_Halt(int);
void Console_ReadLine(unsigned char *line, long long line__len) {
  long long i;
  unsigned char ch;
  Console_Flush();
  i = 0;
  Console_Read(&ch);
  while ((((i < line__len - 1 && ch != 0x0a)) && ch != 0x00)) {
    line[(((unsigned long long)(i) < (unsigned long long)(line__len))
              ? i
              : (Platform_Halt(-2), 0))] = ch;
    i += 1;
    Console_Read(&ch);
  }
  line[(((unsigned long long)(i) < (unsigned long long)(line__len))
            ? i
            : (Platform_Halt(-2), 0))] = 0x00;
}


x86 assembly (clang, -O0):
<Console_ReadLine>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x0,%al
call   1030 <Console_Flush@plt>
movq   $0x0,-0x18(%rbp)
lea    -0x19(%rbp),%rdi
call   1040 <Console_Read@plt>
mov    -0x18(%rbp),%rcx
mov    -0x10(%rbp),%rdx
sub    $0x1,%rdx
xor    %eax,%eax
cmp    %rdx,%rcx
mov    %al,-0x1a(%rbp)
jge    1191 <Console_ReadLine+0x61>
movzbl -0x19(%rbp),%ecx
xor    %eax,%eax
cmp    $0xa,%ecx
mov    %al,-0x1a(%rbp)
je     1191 <Console_ReadLine+0x61>
movzbl -0x19(%rbp),%eax
cmp    $0x0,%eax
setne  %al
mov    %al,-0x1a(%rbp)
mov    -0x1a(%rbp),%al
test   $0x1,%al
jne    11a1 <Console_ReadLine+0x71>
jmp    1202 <Console_ReadLine+0xd2>
mov    -0x19(%rbp),%al
mov    %al,-0x29(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    11ca <Console_ReadLine+0x9a>
mov    -0x18(%rbp),%rax
mov    %rax,-0x38(%rbp)
jmp    11da <Console_ReadLine+0xaa>
mov    $0xfffffffe,%edi
call   1050 <Platform_Halt@plt>
xor    %eax,%eax
mov    %rax,-0x38(%rbp)
mov    -0x28(%rbp),%rax
mov    -0x29(%rbp),%dl
mov    -0x38(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
lea    -0x19(%rbp),%rdi
call   1040 <Console_Read@plt>
jmp    1158 <Console_ReadLine+0x28>
mov    -0x8(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    1225 <Console_ReadLine+0xf5>
mov    -0x18(%rbp),%rax
mov    %rax,-0x48(%rbp)
jmp    1235 <Console_ReadLine+0x105>
mov    $0xfffffffe,%edi
call   1050 <Platform_Halt@plt>
xor    %eax,%eax
mov    %rax,-0x48(%rbp)
mov    -0x40(%rbp),%rax
mov    -0x48(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Console_ReadLine>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r12
mov    %rdi,%r14
xor    %ebp,%ebp
xor    %eax,%eax
call   1030 <Console_Flush@plt>
lea    0x7(%rsp),%rdi
call   1040 <Console_Read@plt>
cmp    $0x2,%r12
jl     11a9 <Console_ReadLine+0x79>
lea    -0x1(%r12),%r13
xor    %ebp,%ebp
lea    0x7(%rsp),%r15
jmp    1185 <Console_ReadLine+0x55>
nopl   0x0(%rax,%rax,1)
mov    %bl,(%r14,%rax,1)
add    $0x1,%rbp
mov    %r15,%rdi
call   1040 <Console_Read@plt>
cmp    %r13,%rbp
jge    11a9 <Console_ReadLine+0x79>
movzbl 0x7(%rsp),%ebx
test   %bl,%bl
je     11a9 <Console_ReadLine+0x79>
cmp    $0xa,%bl
je     11a9 <Console_ReadLine+0x79>
mov    %rbp,%rax
cmp    %r12,%rbp
jb     1170 <Console_ReadLine+0x40>
mov    $0xfffffffe,%edi
call   1050 <Platform_Halt@plt>
xor    %eax,%eax
jmp    1170 <Console_ReadLine+0x40>
cmp    %r12,%rbp
jb     11ba <Console_ReadLine+0x8a>
mov    $0xfffffffe,%edi
call   1050 <Platform_Halt@plt>
xor    %ebp,%ebp
movb   $0x0,(%r14,%rbp,1)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define void @Console_ReadLine(i8* nocapture writeonly %0, i64 %1) {
%3 = alloca i8
%4 = tail call i32 (...) @Console_Flush()
%5 = call i32 @Console_Read(i8* %3)
%6 = add nsw i64 %1, -1
%7 = icmp sgt i64 %1, 1
br i1 %7, label %8, label %22
8: ; preds = %2, %15
%9 = phi i64 [ %18, %15 ], [ 0, %2 ]
%10 = load i8, i8* %3
switch i8 %10, label %11 [
i8 10, label %22
i8 0, label %22
]
11: ; preds = %8
%12 = icmp ult i64 %9, %1
br i1 %12, label %15, label %13
13: ; preds = %11
%14 = call i64 @Platform_Halt(i32 -2)
br label %15
15: ; preds = %11, %13
%16 = phi i64 [ 0, %13 ], [ %9, %11 ]
%17 = getelementptr inbounds i8, i8* %0, i64 %16
store i8 %10, i8* %17
%18 = add nuw nsw i64 %9, 1
%19 = call i32 @Console_Read(i8* %3)
%20 = icmp slt i64 %18, %6
%21 = freeze i1 %20
br i1 %21, label %8, label %22
22: ; preds = %15, %8, %8, %2
%23 = phi i64 [ 0, %2 ], [ %9, %8 ], [ %9, %8 ], [ %18, %15 ]
%24 = icmp ult i64 %23, %1
br i1 %24, label %27, label %25
25: ; preds = %22
%26 = call i64 @Platform_Halt(i32 -2)
br label %27
27: ; preds = %22, %25
%28 = phi i64 [ 0, %25 ], [ %23, %22 ]
%29 = getelementptr inbounds i8, i8* %0, i64 %28
store i8 0, i8* %29
ret void
}