#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 /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int getc(int /*<<< orphan*/ *);
int /*<<< orphan*/ ungetc(int, int /*<<< orphan*/ *);
int ReadLine(FILE *fp) {
  int thechar;
  while (1) {
    thechar = getc(fp);
    if (thechar == EOF) {
      fclose(fp);
      return 0;
    }
    if (thechar == 0x0a)
      return 1;
    if (thechar == 0x0d) {
      thechar = getc(fp);
      if (thechar == EOF) {
        fclose(fp);
        return 0;
      }
      if (thechar == 0x0d)
        return 1;
      ungetc(thechar, fp);
      return 1;
    }
  }
}


x86 assembly (clang, -O0):
<ReadLine>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <getc@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    0x2e96(%rip),%rcx
cmp    (%rcx),%eax
jne    116f <ReadLine+0x3f>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
jmp    11f5 <ReadLine+0xc5>
cmpl   $0xa,-0x14(%rbp)
jne    1185 <ReadLine+0x55>
movl   $0x1,-0x4(%rbp)
jmp    11f5 <ReadLine+0xc5>
cmpl   $0xd,-0x14(%rbp)
jne    11f0 <ReadLine+0xc0>
mov    -0x10(%rbp),%rdi
call   1050 <getc@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    0x2e43(%rip),%rcx
cmp    (%rcx),%eax
jne    11c2 <ReadLine+0x92>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
jmp    11f5 <ReadLine+0xc5>
cmpl   $0xd,-0x14(%rbp)
jne    11d8 <ReadLine+0xa8>
movl   $0x1,-0x4(%rbp)
jmp    11f5 <ReadLine+0xc5>
mov    -0x14(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1040 <ungetc@plt>
movl   $0x1,-0x4(%rbp)
jmp    11f5 <ReadLine+0xc5>
jmp    113c <ReadLine+0xc>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ReadLine>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    0x2eab(%rip),%rbp
nopl   (%rax)
mov    %rbx,%rdi
call   1050 <getc@plt>
cmp    0x0(%rbp),%eax
je     1164 <ReadLine+0x34>
cmp    $0xa,%eax
je     1170 <ReadLine+0x40>
cmp    $0xd,%eax
jne    1140 <ReadLine+0x10>
mov    %rbx,%rdi
call   1050 <getc@plt>
cmp    0x0(%rbp),%eax
jne    1177 <ReadLine+0x47>
mov    %rbx,%rdi
call   1030 <fclose@plt>
xor    %ebp,%ebp
jmp    118b <ReadLine+0x5b>
mov    $0x1,%ebp
jmp    118b <ReadLine+0x5b>
mov    $0x1,%ebp
cmp    $0xd,%eax
je     118b <ReadLine+0x5b>
mov    %eax,%edi
mov    %rbx,%rsi
call   1040 <ungetc@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@EOF = global i32 0
define i32 @ReadLine(i32* %0) {
%2 = alloca i32
%3 = alloca i32*
%4 = alloca i32
store i32* %0, i32** %3
br label %5
5: ; preds = %1, %38
%6 = load i32*, i32** %3
%7 = call i32 @getc(i32* %6)
store i32 %7, i32* %4
%8 = load i32, i32* %4
%9 = load i32, i32* @EOF
%10 = icmp eq i32 %8, %9
br i1 %10, label %11, label %14
11: ; preds = %5
%12 = load i32*, i32** %3
%13 = call i32 @fclose(i32* %12)
store i32 0, i32* %2
br label %39
14: ; preds = %5
%15 = load i32, i32* %4
%16 = icmp eq i32 %15, 10
br i1 %16, label %17, label %18
17: ; preds = %14
store i32 1, i32* %2
br label %39
18: ; preds = %14
%19 = load i32, i32* %4
%20 = icmp eq i32 %19, 13
br i1 %20, label %21, label %38
21: ; preds = %18
%22 = load i32*, i32** %3
%23 = call i32 @getc(i32* %22)
store i32 %23, i32* %4
%24 = load i32, i32* %4
%25 = load i32, i32* @EOF
%26 = icmp eq i32 %24, %25
br i1 %26, label %27, label %30
27: ; preds = %21
%28 = load i32*, i32** %3
%29 = call i32 @fclose(i32* %28)
store i32 0, i32* %2
br label %39
30: ; preds = %21
%31 = load i32, i32* %4
%32 = icmp eq i32 %31, 13
br i1 %32, label %33, label %34
33: ; preds = %30
store i32 1, i32* %2
br label %39
34: ; preds = %30
%35 = load i32, i32* %4
%36 = load i32*, i32** %3
%37 = call i32 @ungetc(i32 %35, i32* %36)
store i32 1, i32* %2
br label %39
38: ; preds = %18
br label %5
39: ; preds = %34, %33, %27, %17, %11
%40 = load i32, i32* %2
ret i32 %40
}

LLVM IR (-O2):
@EOF = global i32 0
define i32 @ReadLine(i32* nocapture %0) {
br label %2
2: ; preds = %8, %1
%3 = tail call i32 @getc(i32* %0)
%4 = load i32, i32* @EOF
%5 = icmp eq i32 %3, %4
br i1 %5, label %6, label %8
6: ; preds = %2
%7 = tail call i32 @fclose(i32* %0)
br label %19
8: ; preds = %2
switch i32 %3, label %2 [
i32 10, label %19
i32 13, label %9
]
9: ; preds = %8
%10 = tail call i32 @getc(i32* %0)
%11 = load i32, i32* @EOF
%12 = icmp eq i32 %10, %11
br i1 %12, label %13, label %15
13: ; preds = %9
%14 = tail call i32 @fclose(i32* %0)
br label %19
15: ; preds = %9
%16 = icmp eq i32 %10, 13
br i1 %16, label %19, label %17
17: ; preds = %15
%18 = tail call i32 @ungetc(i32 %10, i32* %0)
br label %19
19: ; preds = %8, %15, %17, %13, %6
%20 = phi i32 [ 0, %6 ], [ 0, %13 ], [ 1, %17 ], [ 1, %15 ], [ 1, %8 ]
ret i32 %20
}