#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 getc(int /*<<< orphan*/ *);
int read_line(FILE *fp, char *bp) {
  char c = '\0';
  int i = 0;
  while ((c = getc(fp)) != '\n' && c != '\r') {
    if (c == EOF)
      return 0;
    bp[i] = c;
    i++;
  }
  bp[i] = '\0';
  return 1;
}


x86 assembly (clang, -O0):
<read_line>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movb   $0x0,-0x19(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <getc@plt>
mov    %al,-0x19(%rbp)
movsbl %al,%ecx
xor    %eax,%eax
cmp    $0xa,%ecx
mov    %al,-0x21(%rbp)
je     1155 <read_line+0x45>
movsbl -0x19(%rbp),%eax
cmp    $0xd,%eax
setne  %al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
test   $0x1,%al
jne    1165 <read_line+0x55>
jmp    11a3 <read_line+0x93>
movsbl -0x19(%rbp),%eax
mov    0x2e78(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
jne    1187 <read_line+0x77>
movl   $0x0,-0x4(%rbp)
jmp    11b6 <read_line+0xa6>
mov    -0x19(%rbp),%dl
mov    -0x18(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    112b <read_line+0x1b>
mov    -0x18(%rbp),%rax
movslq -0x20(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_line>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r15
xor    %ebx,%ebx
mov    0x2ec1(%rip),%r12
nopw   0x0(%rax,%rax,1)
mov    %r15,%rdi
call   1030 <getc@plt>
cmp    $0xa,%al
je     1150 <read_line+0x40>
cmp    $0xd,%al
je     1150 <read_line+0x40>
cmp    (%r12),%al
je     115e <read_line+0x4e>
mov    %al,(%r14,%rbx,1)
add    $0x1,%rbx
jmp    1130 <read_line+0x20>
mov    %ebx,%eax
movb   $0x0,(%r14,%rax,1)
mov    $0x1,%eax
jmp    1160 <read_line+0x50>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

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