#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 getc(int /*<<< orphan*/ *);
int /*<<< orphan*/ ungetc(int, int /*<<< orphan*/ *);
int mygetc(FILE *f, int *end_of_file) {
  int c;
  if (*end_of_file)
    return (-1);
  c = getc(f);
  if (c == '\r') {
    c = getc(f);
    if (c == EOF) {
      *end_of_file = 1;
      return '\n';
    }
    if (c != '\n')
      ungetc(c, f);
    return '\n';
  }
  if (c == EOF) {
    *end_of_file = 1;
    return (-1);
  }
  return c;
}


x86 assembly (clang, -O0):
<mygetc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmpl   $0x0,(%rax)
je     1149 <mygetc+0x29>
movl   $0xffffffff,-0x4(%rbp)
jmp    11e3 <mygetc+0xc3>
mov    -0x10(%rbp),%rdi
call   1040 <getc@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xd,-0x1c(%rbp)
jne    11b5 <mygetc+0x95>
mov    -0x10(%rbp),%rdi
call   1040 <getc@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    0x2e73(%rip),%rcx
cmp    (%rcx),%eax
jne    1193 <mygetc+0x73>
mov    -0x18(%rbp),%rax
movl   $0x1,(%rax)
movl   $0xa,-0x4(%rbp)
jmp    11e3 <mygetc+0xc3>
cmpl   $0xa,-0x1c(%rbp)
je     11a9 <mygetc+0x89>
mov    -0x1c(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1030 <ungetc@plt>
movl   $0xa,-0x4(%rbp)
jmp    11e3 <mygetc+0xc3>
mov    -0x1c(%rbp),%eax
mov    0x2e29(%rip),%rcx
cmp    (%rcx),%eax
jne    11dd <mygetc+0xbd>
mov    -0x18(%rbp),%rax
movl   $0x1,(%rax)
movl   $0xffffffff,-0x4(%rbp)
jmp    11e3 <mygetc+0xc3>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mygetc>:
push   %r15
push   %r14
push   %rbx
mov    $0xffffffff,%ebx
cmpl   $0x0,(%rsi)
je     1137 <mygetc+0x17>
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %r15
ret
mov    %rsi,%r14
mov    %rdi,%r15
call   1040 <getc@plt>
cmp    $0xd,%eax
jne    1168 <mygetc+0x48>
mov    %r15,%rdi
call   1040 <getc@plt>
mov    0x2e92(%rip),%rcx
cmp    (%rcx),%eax
jne    1183 <mygetc+0x63>
movl   $0x1,(%r14)
mov    $0xa,%ebx
jmp    112f <mygetc+0xf>
mov    %eax,%ebx
mov    0x2e77(%rip),%rax
cmp    (%rax),%ebx
jne    112f <mygetc+0xf>
movl   $0x1,(%r14)
mov    $0xffffffff,%ebx
jmp    112f <mygetc+0xf>
mov    $0xa,%ebx
cmp    $0xa,%eax
je     112f <mygetc+0xf>
mov    %eax,%edi
mov    %r15,%rsi
call   1030 <ungetc@plt>
jmp    112f <mygetc+0xf>

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

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