#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__ ferror(int /*<<< orphan*/ *);
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stderr;
int asciinpRead(char *buffer, const int BUFFER_SIZE, FILE *stream) {
  int c;
  int i = 0;
  for (; i < BUFFER_SIZE - 1; i++) {
    c = fgetc(stream);
    if (c == '\n') {
      buffer[i++] = '\r';
      buffer[i] = '\n';
    } else if (feof(stream)) {
      fprintf(stderr, "EOF\n");
      break;
    } else if (ferror(stream)) {
      perror("getc()");
      return -1;
    } else {
      buffer[i] = c;
    }
  }
  return i;
}


x86 assembly (clang, -O0):
<asciinpRead>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    123d <asciinpRead+0xed>
mov    -0x20(%rbp),%rdi
call   1040 <fgetc@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0xa,-0x24(%rbp)
jne    11b8 <asciinpRead+0x68>
mov    -0x10(%rbp),%rax
mov    -0x28(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0x28(%rbp)
movslq %ecx,%rcx
movb   $0xd,(%rax,%rcx,1)
mov    -0x10(%rbp),%rax
movslq -0x28(%rbp),%rcx
movb   $0xa,(%rax,%rcx,1)
jmp    122a <asciinpRead+0xda>
mov    -0x20(%rbp),%rdi
call   1060 <feof@plt>
cmp    $0x0,%rax
je     11e5 <asciinpRead+0x95>
mov    0x2e0e(%rip),%rax
mov    (%rax),%edi
lea    0xe25(%rip),%rsi
call   1050 <fprintf@plt>
jmp    123d <asciinpRead+0xed>
mov    -0x20(%rbp),%rdi
call   1030 <ferror@plt>
cmp    $0x0,%rax
je     1210 <asciinpRead+0xc0>
lea    0xe06(%rip),%rdi
call   1070 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1243 <asciinpRead+0xf3>
mov    -0x24(%rbp),%eax
mov    %al,%dl
mov    -0x10(%rbp),%rax
movslq -0x28(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
jmp    1225 <asciinpRead+0xd5>
jmp    122a <asciinpRead+0xda>
jmp    122f <asciinpRead+0xdf>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    116a <asciinpRead+0x1a>
mov    -0x28(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<asciinpRead>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
xor    %ebx,%ebx
cmp    $0x2,%esi
jl     11de <asciinpRead+0x8e>
mov    %rdx,%r14
mov    %esi,%r15d
mov    %rdi,%r12
add    $0xffffffff,%r15d
xor    %ebx,%ebx
jmp    118d <asciinpRead+0x3d>
movslq %ebx,%rax
add    $0x1,%ebx
movb   $0xd,(%r12,%rax,1)
mov    $0xa,%bpl
movslq %ebx,%rbx
mov    %bpl,(%r12,%rbx,1)
add    $0x1,%ebx
cmp    %r15d,%ebx
jge    11de <asciinpRead+0x8e>
mov    %r14,%rdi
call   1040 <fgetc@plt>
cmp    $0xa,%eax
je     1170 <asciinpRead+0x20>
mov    %eax,%ebp
mov    %r14,%rdi
call   1060 <feof@plt>
test   %rax,%rax
jne    11c9 <asciinpRead+0x79>
mov    %r14,%rdi
call   1030 <ferror@plt>
test   %rax,%rax
je     117e <asciinpRead+0x2e>
lea    0xe48(%rip),%rdi
call   1070 <perror@plt>
mov    $0xffffffff,%ebx
jmp    11de <asciinpRead+0x8e>
mov    0x2e10(%rip),%rax
mov    (%rax),%edi
lea    0xe27(%rip),%rsi
call   1050 <fprintf@plt>
mov    %ebx,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [5 x i8] c"EOF\0A\00"
@.str.1 = [7 x i8] c"getc()\00"
define i32 @asciinpRead(i8* %0, i32 %1, i32* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i32
store i8* %0, i8** %5
store i32 %1, i32* %6
store i32* %2, i32** %7
store i32 0, i32* %9
br label %10
10: ; preds = %53, %3
%11 = load i32, i32* %9
%12 = load i32, i32* %6
%13 = sub nsw i32 %12, 1
%14 = icmp slt i32 %11, %13
br i1 %14, label %15, label %56
15: ; preds = %10
%16 = load i32*, i32** %7
%17 = call i32 @fgetc(i32* %16)
store i32 %17, i32* %8
%18 = load i32, i32* %8
%19 = icmp eq i32 %18, 10
br i1 %19, label %20, label %30
20: ; preds = %15
%21 = load i8*, i8** %5
%22 = load i32, i32* %9
%23 = add nsw i32 %22, 1
store i32 %23, i32* %9
%24 = sext i32 %22 to i64
%25 = getelementptr inbounds i8, i8* %21, i64 %24
store i8 13, i8* %25
%26 = load i8*, i8** %5
%27 = load i32, i32* %9
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i8, i8* %26, i64 %28
store i8 10, i8* %29
br label %52
30: ; preds = %15
%31 = load i32*, i32** %7
%32 = call i64 @feof(i32* %31)
%33 = icmp ne i64 %32, 0
br i1 %33, label %34, label %37
34: ; preds = %30
%35 = load i32, i32* @stderr
%36 = call i32 @fprintf(i32 %35, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
br label %56
37: ; preds = %30
%38 = load i32*, i32** %7
%39 = call i64 @ferror(i32* %38)
%40 = icmp ne i64 %39, 0
br i1 %40, label %41, label %43
41: ; preds = %37
%42 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %4
br label %58
43: ; preds = %37
%44 = load i32, i32* %8
%45 = trunc i32 %44 to i8
%46 = load i8*, i8** %5
%47 = load i32, i32* %9
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds i8, i8* %46, i64 %48
store i8 %45, i8* %49
br label %50
50: ; preds = %43
br label %51
51: ; preds = %50
br label %52
52: ; preds = %51, %20
br label %53
53: ; preds = %52
%54 = load i32, i32* %9
%55 = add nsw i32 %54, 1
store i32 %55, i32* %9
br label %10
56: ; preds = %34, %10
%57 = load i32, i32* %9
store i32 %57, i32* %4
br label %58
58: ; preds = %56, %41
%59 = load i32, i32* %4
ret i32 %59
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [5 x i8] c"EOF\0A\00"
@.str.1 = [7 x i8] c"getc()\00"
define i32 @asciinpRead(i8* nocapture writeonly %0, i32 %1, i32* nocapture %2) {
%4 = add nsw i32 %1, -1
%5 = icmp sgt i32 %1, 1
br i1 %5, label %6, label %34
6: ; preds = %3, %27
%7 = phi i32 [ %32, %27 ], [ 0, %3 ]
%8 = tail call i32 @fgetc(i32* %2)
%9 = icmp eq i32 %8, 10
br i1 %9, label %10, label %14
10: ; preds = %6
%11 = add nsw i32 %7, 1
%12 = sext i32 %7 to i64
%13 = getelementptr inbounds i8, i8* %0, i64 %12
store i8 13, i8* %13
br label %27
14: ; preds = %6
%15 = tail call i64 @feof(i32* %2)
%16 = icmp eq i64 %15, 0
br i1 %16, label %20, label %17
17: ; preds = %14
%18 = load i32, i32* @stderr
%19 = tail call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
br label %34
20: ; preds = %14
%21 = tail call i64 @ferror(i32* %2)
%22 = icmp eq i64 %21, 0
br i1 %22, label %25, label %23
23: ; preds = %20
%24 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
br label %34
25: ; preds = %20
%26 = trunc i32 %8 to i8
br label %27
27: ; preds = %10, %25
%28 = phi i32 [ %11, %10 ], [ %7, %25 ]
%29 = phi i8 [ 10, %10 ], [ %26, %25 ]
%30 = sext i32 %28 to i64
%31 = getelementptr inbounds i8, i8* %0, i64 %30
store i8 %29, i8* %31
%32 = add nsw i32 %28, 1
%33 = icmp slt i32 %32, %4
br i1 %33, label %6, label %34
34: ; preds = %27, %3, %17, %23
%35 = phi i32 [ -1, %23 ], [ %7, %17 ], [ 0, %3 ], [ %32, %27 ]
ret i32 %35
}