#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*/ *);
char getc(int /*<<< orphan*/ *);
int /*<<< orphan*/ i3_log(char *, char *);
int /*<<< orphan*/ ungetc(char, int /*<<< orphan*/ *);
void i3fread_to_eol(FILE *fp) {
  char c;
  do {
    if (feof(fp)) {
      i3_log("%s", "i3fread_to_eol: EOF encountered on read.");
      return;
    }
    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):
<i3fread_to_eol>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <feof@plt>
cmp    $0x0,%rax
je     1177 <i3fread_to_eol+0x37>
lea    0xe9a(%rip),%rdi
lea    0xe96(%rip),%rsi
call   1060 <i3_log@plt>
jmp    11f7 <i3fread_to_eol+0xb7>
mov    -0x8(%rbp),%rdi
call   1050 <getc@plt>
mov    %al,-0x9(%rbp)
movsbl -0x9(%rbp),%ecx
xor    %eax,%eax
cmp    $0xa,%ecx
mov    %al,-0xa(%rbp)
je     11a2 <i3fread_to_eol+0x62>
movsbl -0x9(%rbp),%eax
cmp    $0xd,%eax
setne  %al
mov    %al,-0xa(%rbp)
mov    -0xa(%rbp),%al
test   $0x1,%al
jne    114c <i3fread_to_eol+0xc>
jmp    11b2 <i3fread_to_eol+0x72>
mov    -0x8(%rbp),%rdi
call   1050 <getc@plt>
mov    %al,-0x9(%rbp)
movsbl -0x9(%rbp),%ecx
mov    $0x1,%al
cmp    $0xa,%ecx
mov    %al,-0xb(%rbp)
je     11dd <i3fread_to_eol+0x9d>
movsbl -0x9(%rbp),%eax
cmp    $0xd,%eax
sete   %al
mov    %al,-0xb(%rbp)
mov    -0xb(%rbp),%al
test   $0x1,%al
jne    11b2 <i3fread_to_eol+0x72>
mov    -0x9(%rbp),%al
mov    -0x8(%rbp),%rsi
movsbl %al,%edi
call   1040 <ungetc@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<i3fread_to_eol>:
push   %rbx
mov    %rdi,%rbx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %rbx,%rdi
call   1030 <feof@plt>
test   %rax,%rax
jne    118c <i3fread_to_eol+0x4c>
mov    %rbx,%rdi
call   1050 <getc@plt>
cmp    $0xd,%al
je     1170 <i3fread_to_eol+0x30>
cmp    $0xa,%al
jne    1150 <i3fread_to_eol+0x10>
nopl   (%rax)
mov    %rbx,%rdi
call   1050 <getc@plt>
cmp    $0xa,%al
je     1170 <i3fread_to_eol+0x30>
cmp    $0xd,%al
je     1170 <i3fread_to_eol+0x30>
movsbl %al,%edi
mov    %rbx,%rsi
pop    %rbx
jmp    1040 <ungetc@plt>
lea    0xe6d(%rip),%rdi
lea    0xe69(%rip),%rsi
pop    %rbx
jmp    1060 <i3_log@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"%s\00"
@.str.1 = [41 x i8] c"i3fread_to_eol: EOF encountered on read.\00"
define void @i3fread_to_eol(i32* %0) {
%2 = alloca i32*
%3 = alloca i8
store i32* %0, i32** %2
br label %4
4: ; preds = %21, %1
%5 = load i32*, i32** %2
%6 = call i64 @feof(i32* %5)
%7 = icmp ne i64 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %4
%9 = call i32 @i3_log(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i64 0, i64 0))
br label %41
10: ; preds = %4
%11 = load i32*, i32** %2
%12 = call signext i8 @getc(i32* %11)
store i8 %12, i8* %3
br label %13
13: ; preds = %10
%14 = load i8, i8* %3
%15 = sext i8 %14 to i32
%16 = icmp ne i32 %15, 10
br i1 %16, label %17, label %21
17: ; preds = %13
%18 = load i8, i8* %3
%19 = sext i8 %18 to i32
%20 = icmp ne i32 %19, 13
br label %21
21: ; preds = %17, %13
%22 = phi i1 [ false, %13 ], [ %20, %17 ]
br i1 %22, label %4, label %23
23: ; preds = %21
br label %24
24: ; preds = %35, %23
%25 = load i32*, i32** %2
%26 = call signext i8 @getc(i32* %25)
store i8 %26, i8* %3
br label %27
27: ; preds = %24
%28 = load i8, i8* %3
%29 = sext i8 %28 to i32
%30 = icmp eq i32 %29, 10
br i1 %30, label %35, label %31
31: ; preds = %27
%32 = load i8, i8* %3
%33 = sext i8 %32 to i32
%34 = icmp eq i32 %33, 13
br label %35
35: ; preds = %31, %27
%36 = phi i1 [ true, %27 ], [ %34, %31 ]
br i1 %36, label %24, label %37
37: ; preds = %35
%38 = load i8, i8* %3
%39 = load i32*, i32** %2
%40 = call i32 @ungetc(i8 signext %38, i32* %39)
br label %41
41: ; preds = %37, %8
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"%s\00"
@.str.1 = [41 x i8] c"i3fread_to_eol: EOF encountered on read.\00"
define void @i3fread_to_eol(i32* nocapture %0) {
br label %2
2: ; preds = %7, %1
%3 = tail call i64 @feof(i32* %0)
%4 = icmp eq i64 %3, 0
br i1 %4, label %7, label %5
5: ; preds = %2
%6 = tail call i32 @i3_log(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i64 0, i64 0))
br label %15
7: ; preds = %2
%8 = tail call signext i8 @getc(i32* %0)
switch i8 %8, label %2 [
i8 13, label %9
i8 10, label %9
]
9: ; preds = %7, %7
br label %10
10: ; preds = %12, %9
%11 = tail call signext i8 @getc(i32* %0)
switch i8 %11, label %13 [
i8 13, label %12
i8 10, label %12
]
12: ; preds = %10, %10
br label %10
13: ; preds = %10
%14 = tail call i32 @ungetc(i8 signext %11, i32* %0)
br label %15
15: ; preds = %13, %5
ret void
}