#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 EOF;
char fgetc(int /*<<< orphan*/ *);
void getLine(FILE *file, char *buffer, int size) {
  int i = 0;
  char c = fgetc(file);
  while (c != '\r' && c != '\n' && c != EOF) {
    if (i < size) {
      buffer[i] = c;
      i++;
    }
    c = fgetc(file);
  }
  buffer[i] = '\0';
}


x86 assembly (clang, -O0):
<getLine>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <fgetc@plt>
mov    %al,-0x19(%rbp)
movsbl -0x19(%rbp),%ecx
xor    %eax,%eax
cmp    $0xd,%ecx
mov    %al,-0x1a(%rbp)
je     1170 <getLine+0x60>
movsbl -0x19(%rbp),%ecx
xor    %eax,%eax
cmp    $0xa,%ecx
mov    %al,-0x1a(%rbp)
je     1170 <getLine+0x60>
movsbl -0x19(%rbp),%eax
mov    0x2e83(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
setne  %al
mov    %al,-0x1a(%rbp)
mov    -0x1a(%rbp),%al
test   $0x1,%al
jne    1180 <getLine+0x70>
jmp    11b4 <getLine+0xa4>
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11a3 <getLine+0x93>
mov    -0x19(%rbp),%dl
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <fgetc@plt>
mov    %al,-0x19(%rbp)
jmp    1136 <getLine+0x26>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getLine>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edx,%r15d
mov    %rsi,%r14
mov    %rdi,%rbx
xor    %ebp,%ebp
mov    0x2ebe(%rip),%r12
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1030 <fgetc@plt>
cmp    $0xa,%al
je     1156 <getLine+0x46>
cmp    $0xd,%al
je     1156 <getLine+0x46>
cmp    (%r12),%al
je     1156 <getLine+0x46>
cmp    %r15d,%ebp
jge    1130 <getLine+0x20>
mov    %ebp,%ecx
mov    %al,(%r14,%rcx,1)
add    $0x1,%ebp
jmp    1130 <getLine+0x20>
mov    %ebp,%eax
movb   $0x0,(%r14,%rax,1)
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

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