#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 /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ rewind(int /*<<< orphan*/ *);
char *rindex(char *, char);
int /*<<< orphan*/ strncpy(char *, char *, int);
void get_eol(FILE *in, char *eol) {
  char *p = NULL;
  char buf[256 + 1];
  memset(eol, 0, 3);
  memset(buf, 0, 256 + 1);
  fgets(buf, 256, in);
  if (!buf[0])
    goto not_found;
  p = rindex(buf, '\r');
  if (!p) {
    p = rindex(buf, '\n');
    if (!p)
      goto not_found;
  }
  strncpy(eol, p, 2);
  rewind(in);
  return;
not_found:
  strncpy(eol, "\r\n", 2);
  rewind(in);
}


x86 assembly (clang, -O0):
<get_eol>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
xor    %esi,%esi
mov    $0x3,%edx
call   1050 <memset@plt>
lea    -0x120(%rbp),%rdi
xor    %esi,%esi
mov    $0x101,%edx
call   1050 <memset@plt>
lea    -0x120(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    $0x100,%esi
call   1060 <fgets@plt>
cmpb   $0x0,-0x120(%rbp)
jne    11b5 <get_eol+0x65>
jmp    121f <get_eol+0xcf>
lea    -0x120(%rbp),%rdi
mov    $0xd,%esi
call   1070 <rindex@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11ff <get_eol+0xaf>
lea    -0x120(%rbp),%rdi
mov    $0xa,%esi
call   1070 <rindex@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11fa <get_eol+0xaa>
jmp    121f <get_eol+0xcf>
jmp    11ff <get_eol+0xaf>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    $0x2,%edx
call   1030 <strncpy@plt>
mov    -0x8(%rbp),%rdi
call   1040 <rewind@plt>
jmp    123d <get_eol+0xed>
mov    -0x10(%rbp),%rdi
lea    0xdd6(%rip),%rsi
mov    $0x2,%edx
call   1030 <strncpy@plt>
mov    -0x8(%rbp),%rdi
call   1040 <rewind@plt>
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_eol>:
push   %r15
push   %r14
push   %rbx
sub    $0x110,%rsp
mov    %rsi,%r15
mov    %rdi,%r14
mov    %rsi,%rdi
xor    %esi,%esi
mov    $0x3,%edx
call   1050 <memset@plt>
mov    %rsp,%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x101,%edx
call   1050 <memset@plt>
mov    %rbx,%rdi
mov    $0x100,%esi
mov    %r14,%rdx
call   1060 <fgets@plt>
cmpb   $0x0,(%rsp)
je     11c5 <get_eol+0x75>
mov    %rsp,%rdi
mov    $0xd,%esi
call   1070 <rindex@plt>
test   %rax,%rax
jne    11bd <get_eol+0x6d>
mov    %rsp,%rdi
mov    $0xa,%esi
call   1070 <rindex@plt>
test   %rax,%rax
je     11c5 <get_eol+0x75>
mov    %r15,%rdi
mov    %rax,%rsi
jmp    11cf <get_eol+0x7f>
lea    0xe34(%rip),%rsi
mov    %r15,%rdi
mov    $0x2,%edx
call   1030 <strncpy@plt>
mov    %r14,%rdi
call   1040 <rewind@plt>
add    $0x110,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [3 x i8] c"\0D\0A\00"
define void @get_eol(i32* %0, i8* %1) {
%3 = alloca i32*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca [257 x i8]
store i32* %0, i32** %3
store i8* %1, i8** %4
store i8* null, i8** %5
%7 = load i8*, i8** %4
%8 = call i32 @memset(i8* %7, i32 0, i32 3)
%9 = getelementptr inbounds [257 x i8], [257 x i8]* %6, i64 0, i64 0
%10 = call i32 @memset(i8* %9, i32 0, i32 257)
%11 = getelementptr inbounds [257 x i8], [257 x i8]* %6, i64 0, i64 0
%12 = load i32*, i32** %3
%13 = call i32 @fgets(i8* %11, i32 256, i32* %12)
%14 = getelementptr inbounds [257 x i8], [257 x i8]* %6, i64 0, i64 0
%15 = load i8, i8* %14
%16 = icmp ne i8 %15, 0
br i1 %16, label %18, label %17
17: ; preds = %2
br label %36
18: ; preds = %2
%19 = getelementptr inbounds [257 x i8], [257 x i8]* %6, i64 0, i64 0
%20 = call i8* @rindex(i8* %19, i8 signext 13)
store i8* %20, i8** %5
%21 = load i8*, i8** %5
%22 = icmp ne i8* %21, null
br i1 %22, label %30, label %23
23: ; preds = %18
%24 = getelementptr inbounds [257 x i8], [257 x i8]* %6, i64 0, i64 0
%25 = call i8* @rindex(i8* %24, i8 signext 10)
store i8* %25, i8** %5
%26 = load i8*, i8** %5
%27 = icmp ne i8* %26, null
br i1 %27, label %29, label %28
28: ; preds = %23
br label %36
29: ; preds = %23
br label %30
30: ; preds = %29, %18
%31 = load i8*, i8** %4
%32 = load i8*, i8** %5
%33 = call i32 @strncpy(i8* %31, i8* %32, i32 2)
%34 = load i32*, i32** %3
%35 = call i32 @rewind(i32* %34)
br label %41
36: ; preds = %28, %17
%37 = load i8*, i8** %4
%38 = call i32 @strncpy(i8* %37, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 2)
%39 = load i32*, i32** %3
%40 = call i32 @rewind(i32* %39)
br label %41
41: ; preds = %36, %30
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"\0D\0A\00"
define void @get_eol(i32* nocapture %0, i8* %1) {
%3 = alloca [257 x i8]
%4 = getelementptr inbounds [257 x i8], [257 x i8]* %3, i64 0, i64 0
%5 = tail call i32 @memset(i8* %1, i32 0, i32 3)
%6 = call i32 @memset(i8* %4, i32 0, i32 257)
%7 = call i32 @fgets(i8* %4, i32 256, i32* %0)
%8 = load i8, i8* %4
%9 = icmp eq i8 %8, 0
br i1 %9, label %19, label %10
10: ; preds = %2
%11 = call i8* @rindex(i8* %4, i8 signext 13)
%12 = icmp eq i8* %11, null
br i1 %12, label %13, label %16
13: ; preds = %10
%14 = call i8* @rindex(i8* %4, i8 signext 10)
%15 = icmp eq i8* %14, null
br i1 %15, label %19, label %16
16: ; preds = %13, %10
%17 = phi i8* [ %11, %10 ], [ %14, %13 ]
%18 = call i32 @strncpy(i8* %1, i8* %17, i32 2)
br label %21
19: ; preds = %13, %2
%20 = call i32 @strncpy(i8* %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 2)
br label %21
21: ; preds = %19, %16
%22 = call i32 @rewind(i32* %0)
ret void
}