#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 EOF;
int fgetc(int /*<<< orphan*/ *);
int ReadOneLine(FILE *f, char *buffer) {
  int c;
  int i = 0;
  while ((c = fgetc(f)) != EOF) {
    if (c == '\r')
      continue;
    if (c == '\n')
      break;
    buffer[i++] = c;
  }
  buffer[i] = 0;
  return i;
}


x86 assembly (clang, -O0):
<ReadOneLine>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <fgetc@plt>
mov    %eax,-0x14(%rbp)
mov    0x2eae(%rip),%rcx
cmp    (%rcx),%eax
je     117f <ReadOneLine+0x6f>
cmpl   $0xd,-0x14(%rbp)
jne    1151 <ReadOneLine+0x41>
jmp    1127 <ReadOneLine+0x17>
cmpl   $0xa,-0x14(%rbp)
jne    1160 <ReadOneLine+0x50>
jmp    117f <ReadOneLine+0x6f>
mov    -0x14(%rbp),%eax
mov    %al,%dl
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x18(%rbp)
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
jmp    1127 <ReadOneLine+0x17>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ReadOneLine>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
xor    %r15d,%r15d
mov    0x2ec0(%rip),%r12
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1030 <fgetc@plt>
cmp    (%r12),%eax
je     1152 <ReadOneLine+0x42>
cmp    $0xd,%eax
je     1130 <ReadOneLine+0x20>
cmp    $0xa,%eax
je     1152 <ReadOneLine+0x42>
mov    %al,(%r14,%r15,1)
add    $0x1,%r15
jmp    1130 <ReadOneLine+0x20>
mov    %r15d,%eax
movb   $0x0,(%r14,%rax,1)
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@EOF = global i32 0
define i32 @ReadOneLine(i32* %0, i8* %1) {
%3 = alloca i32*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
store i32* %0, i32** %3
store i8* %1, i8** %4
store i32 0, i32* %6
br label %7
7: ; preds = %20, %15, %2
%8 = load i32*, i32** %3
%9 = call i32 @fgetc(i32* %8)
store i32 %9, i32* %5
%10 = load i32, i32* @EOF
%11 = icmp ne i32 %9, %10
br i1 %11, label %12, label %28
12: ; preds = %7
%13 = load i32, i32* %5
%14 = icmp eq i32 %13, 13
br i1 %14, label %15, label %16
15: ; preds = %12
br label %7
16: ; preds = %12
%17 = load i32, i32* %5
%18 = icmp eq i32 %17, 10
br i1 %18, label %19, label %20
19: ; preds = %16
br label %28
20: ; preds = %16
%21 = load i32, i32* %5
%22 = trunc i32 %21 to i8
%23 = load i8*, i8** %4
%24 = load i32, i32* %6
%25 = add nsw i32 %24, 1
store i32 %25, i32* %6
%26 = sext i32 %24 to i64
%27 = getelementptr inbounds i8, i8* %23, i64 %26
store i8 %22, i8* %27
br label %7
28: ; preds = %19, %7
%29 = load i8*, i8** %4
%30 = load i32, i32* %6
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i8, i8* %29, i64 %31
store i8 0, i8* %32
%33 = load i32, i32* %6
ret i32 %33
}

LLVM IR (-O2):
@EOF = global i32 0
define i32 @ReadOneLine(i32* nocapture %0, i8* nocapture writeonly %1) {
br label %3
3: ; preds = %10, %2
%4 = phi i64 [ %12, %10 ], [ 0, %2 ]
br label %5
5: ; preds = %3, %9
%6 = tail call i32 @fgetc(i32* %0)
%7 = load i32, i32* @EOF
%8 = icmp eq i32 %6, %7
br i1 %8, label %14, label %9
9: ; preds = %5
switch i32 %6, label %10 [
i32 13, label %5
i32 10, label %14
]
10: ; preds = %9
%11 = trunc i32 %6 to i8
%12 = add nuw i64 %4, 1
%13 = getelementptr inbounds i8, i8* %1, i64 %4
store i8 %11, i8* %13
br label %3
14: ; preds = %9, %5
%15 = trunc i64 %4 to i32
%16 = and i64 %4, 4294967295
%17 = getelementptr inbounds i8, i8* %1, i64 %16
store i8 0, i8* %17
ret i32 %15
}