#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 */
char getc(int /*<<< orphan*/ *);
int /*<<< orphan*/ ungetc(char, int /*<<< orphan*/ *);
void fread_to_eol(FILE *fp) {
  char c;
  do {
    c = getc(fp);
  } while (c != '\n' && c != '\r');
  do {
    c = getc(fp);
  } while (c == '\n' || c == '\r');
  ungetc(c, fp);
  return;
}


x86 assembly (clang, -O0):
<fread_to_eol>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <getc@plt>
mov    %al,-0x9(%rbp)
movsbl -0x9(%rbp),%ecx
xor    %eax,%eax
cmp    $0xa,%ecx
mov    %al,-0xa(%rbp)
je     1157 <fread_to_eol+0x37>
movsbl -0x9(%rbp),%eax
cmp    $0xd,%eax
setne  %al
mov    %al,-0xa(%rbp)
mov    -0xa(%rbp),%al
test   $0x1,%al
jne    112c <fread_to_eol+0xc>
jmp    1167 <fread_to_eol+0x47>
mov    -0x8(%rbp),%rdi
call   1040 <getc@plt>
mov    %al,-0x9(%rbp)
movsbl -0x9(%rbp),%ecx
mov    $0x1,%al
cmp    $0xa,%ecx
mov    %al,-0xb(%rbp)
je     1192 <fread_to_eol+0x72>
movsbl -0x9(%rbp),%eax
cmp    $0xd,%eax
sete   %al
mov    %al,-0xb(%rbp)
mov    -0xb(%rbp),%al
test   $0x1,%al
jne    1167 <fread_to_eol+0x47>
mov    -0x9(%rbp),%al
mov    -0x8(%rbp),%rsi
movsbl %al,%edi
call   1030 <ungetc@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fread_to_eol>:
push   %rbx
mov    %rdi,%rbx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %rbx,%rdi
call   1040 <getc@plt>
cmp    $0xd,%al
je     1140 <fread_to_eol+0x20>
cmp    $0xa,%al
jne    1130 <fread_to_eol+0x10>
mov    %rbx,%rdi
call   1040 <getc@plt>
cmp    $0xa,%al
je     1140 <fread_to_eol+0x20>
cmp    $0xd,%al
je     1140 <fread_to_eol+0x20>
movsbl %al,%edi
mov    %rbx,%rsi
pop    %rbx
jmp    1030 <ungetc@plt>

LLVM IR (-O0):
define void @fread_to_eol(i32* %0) {
%2 = alloca i32*
%3 = alloca i8
store i32* %0, i32** %2
br label %4
4: ; preds = %15, %1
%5 = load i32*, i32** %2
%6 = call signext i8 @getc(i32* %5)
store i8 %6, i8* %3
br label %7
7: ; preds = %4
%8 = load i8, i8* %3
%9 = sext i8 %8 to i32
%10 = icmp ne i32 %9, 10
br i1 %10, label %11, label %15
11: ; preds = %7
%12 = load i8, i8* %3
%13 = sext i8 %12 to i32
%14 = icmp ne i32 %13, 13
br label %15
15: ; preds = %11, %7
%16 = phi i1 [ false, %7 ], [ %14, %11 ]
br i1 %16, label %4, label %17
17: ; preds = %15
br label %18
18: ; preds = %29, %17
%19 = load i32*, i32** %2
%20 = call signext i8 @getc(i32* %19)
store i8 %20, i8* %3
br label %21
21: ; preds = %18
%22 = load i8, i8* %3
%23 = sext i8 %22 to i32
%24 = icmp eq i32 %23, 10
br i1 %24, label %29, label %25
25: ; preds = %21
%26 = load i8, i8* %3
%27 = sext i8 %26 to i32
%28 = icmp eq i32 %27, 13
br label %29
29: ; preds = %25, %21
%30 = phi i1 [ true, %21 ], [ %28, %25 ]
br i1 %30, label %18, label %31
31: ; preds = %29
%32 = load i8, i8* %3
%33 = load i32*, i32** %2
%34 = call i32 @ungetc(i8 signext %32, i32* %33)
ret void
}

LLVM IR (-O2):
define void @fread_to_eol(i32* nocapture %0) {
br label %2
2: ; preds = %2, %1
%3 = tail call signext i8 @getc(i32* %0)
switch i8 %3, label %2 [
i8 13, label %4
i8 10, label %4
]
4: ; preds = %2, %2
br label %5
5: ; preds = %7, %4
%6 = tail call signext i8 @getc(i32* %0)
switch i8 %6, label %8 [
i8 13, label %7
i8 10, label %7
]
7: ; preds = %5, %5
br label %5
8: ; preds = %5
%9 = tail call i32 @ungetc(i8 signext %6, i32* %0)
ret void
}