#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*/ feof(int /*<<< orphan*/ *);
char fgetc(int /*<<< orphan*/ *);
void file_readline(FILE *file, char *buffer, size_t size) {
  char c;
  size_t pos = 0;
  int ok = 1;
  while (ok) {
    c = fgetc(file);
    if (!feof(file) && c != 13 && c != 10 && c != 0 && pos < (size - 1))
      buffer[pos++] = c;
    else
      ok = 0;
  }
  buffer[pos] = 0;
}


x86 assembly (clang, -O0):
<file_readline>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movq   $0x0,-0x28(%rbp)
movl   $0x1,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
je     11d1 <file_readline+0xb1>
mov    -0x8(%rbp),%rdi
call   1030 <fgetc@plt>
mov    %al,-0x19(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <feof@plt>
cmp    $0x0,%eax
jne    11c5 <file_readline+0xa5>
movsbl -0x19(%rbp),%eax
cmp    $0xd,%eax
je     11c5 <file_readline+0xa5>
movsbl -0x19(%rbp),%eax
cmp    $0xa,%eax
je     11c5 <file_readline+0xa5>
movsbl -0x19(%rbp),%eax
cmp    $0x0,%eax
je     11c5 <file_readline+0xa5>
mov    -0x28(%rbp),%rax
mov    -0x18(%rbp),%rcx
sub    $0x1,%rcx
cmp    %rcx,%rax
jae    11c5 <file_readline+0xa5>
mov    -0x19(%rbp),%dl
mov    -0x10(%rbp),%rax
mov    -0x28(%rbp),%rcx
mov    %rcx,%rsi
add    $0x1,%rsi
mov    %rsi,-0x28(%rbp)
mov    %dl,(%rax,%rcx,1)
jmp    11cc <file_readline+0xac>
movl   $0x0,-0x2c(%rbp)
jmp    1143 <file_readline+0x23>
mov    -0x10(%rbp),%rax
mov    -0x28(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<file_readline>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r15
mov    %rsi,%r14
mov    %rdi,%r12
call   1030 <fgetc@plt>
mov    %eax,%ebp
mov    %r12,%rdi
call   1040 <feof@plt>
test   %eax,%eax
je     115d <file_readline+0x3d>
xor    %ebx,%ebx
movb   $0x0,(%r14,%rbx,1)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
add    $0xffffffffffffffff,%r15
xor    %ebx,%ebx
mov    $0x2401,%r13d
nopl   0x0(%rax)
cmp    $0xd,%bpl
ja     1180 <file_readline+0x60>
movzbl %bpl,%eax
bt     %rax,%r13
jb     1149 <file_readline+0x29>
cmp    %r15,%rbx
jae    1149 <file_readline+0x29>
mov    %bpl,(%r14,%rbx,1)
add    $0x1,%rbx
mov    %r12,%rdi
call   1030 <fgetc@plt>
mov    %eax,%ebp
mov    %r12,%rdi
call   1040 <feof@plt>
test   %eax,%eax
je     1170 <file_readline+0x50>
jmp    1149 <file_readline+0x29>

LLVM IR (-O0):
define void @file_readline(i32* %0, i8* %1, i64 %2) {
%4 = alloca i32*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i8
%8 = alloca i64
%9 = alloca i32
store i32* %0, i32** %4
store i8* %1, i8** %5
store i64 %2, i64* %6
store i64 0, i64* %8
store i32 1, i32* %9
br label %10
10: ; preds = %43, %3
%11 = load i32, i32* %9
%12 = icmp ne i32 %11, 0
br i1 %12, label %13, label %44
13: ; preds = %10
%14 = load i32*, i32** %4
%15 = call signext i8 @fgetc(i32* %14)
store i8 %15, i8* %7
%16 = load i32*, i32** %4
%17 = call i32 @feof(i32* %16)
%18 = icmp ne i32 %17, 0
br i1 %18, label %42, label %19
19: ; preds = %13
%20 = load i8, i8* %7
%21 = sext i8 %20 to i32
%22 = icmp ne i32 %21, 13
br i1 %22, label %23, label %42
23: ; preds = %19
%24 = load i8, i8* %7
%25 = sext i8 %24 to i32
%26 = icmp ne i32 %25, 10
br i1 %26, label %27, label %42
27: ; preds = %23
%28 = load i8, i8* %7
%29 = sext i8 %28 to i32
%30 = icmp ne i32 %29, 0
br i1 %30, label %31, label %42
31: ; preds = %27
%32 = load i64, i64* %8
%33 = load i64, i64* %6
%34 = sub i64 %33, 1
%35 = icmp ult i64 %32, %34
br i1 %35, label %36, label %42
36: ; preds = %31
%37 = load i8, i8* %7
%38 = load i8*, i8** %5
%39 = load i64, i64* %8
%40 = add i64 %39, 1
store i64 %40, i64* %8
%41 = getelementptr inbounds i8, i8* %38, i64 %39
store i8 %37, i8* %41
br label %43
42: ; preds = %31, %27, %23, %19, %13
store i32 0, i32* %9
br label %43
43: ; preds = %42, %36
br label %10
44: ; preds = %10
%45 = load i8*, i8** %5
%46 = load i64, i64* %8
%47 = getelementptr inbounds i8, i8* %45, i64 %46
store i8 0, i8* %47
ret void
}

LLVM IR (-O2):
define void @file_readline(i32* nocapture %0, i8* nocapture writeonly %1, i64 %2) {
%4 = add i64 %2, -1
%5 = tail call signext i8 @fgetc(i32* %0)
%6 = tail call i32 @feof(i32* %0)
%7 = icmp eq i32 %6, 0
br i1 %7, label %8, label %19
8: ; preds = %3, %13
%9 = phi i8 [ %16, %13 ], [ %5, %3 ]
%10 = phi i64 [ %14, %13 ], [ 0, %3 ]
switch i8 %9, label %11 [
i8 13, label %19
i8 10, label %19
i8 0, label %19
]
11: ; preds = %8
%12 = icmp ult i64 %10, %4
br i1 %12, label %13, label %19
13: ; preds = %11
%14 = add nuw i64 %10, 1
%15 = getelementptr inbounds i8, i8* %1, i64 %10
store i8 %9, i8* %15
%16 = tail call signext i8 @fgetc(i32* %0)
%17 = tail call i32 @feof(i32* %0)
%18 = icmp eq i32 %17, 0
br i1 %18, label %8, label %19
19: ; preds = %11, %13, %8, %8, %8, %3
%20 = phi i64 [ 0, %3 ], [ %10, %11 ], [ %14, %13 ], [ %10, %8 ], [ %10, %8 ], [ %10, %8 ]
%21 = getelementptr inbounds i8, i8* %1, i64 %20
store i8 0, i8* %21
ret void
}