#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 fread(char *, int, int, int /*<<< orphan*/ *);
int read_line(FILE *f, char *buf) {
  int eof = 0;
  int len = 0;
  while (1) {
    if (fread(buf, 1, 1, f) != 1) {
      eof = 1;
      break;
    }
    if ((*buf == 0x0A) || (*buf == 0x0D))
      break;
    len++;
    buf++;
  }
  *buf = 0;
  return (eof == 0) || (len > 0);
}


x86 assembly (clang, -O0):
<read_line>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rcx
mov    $0x1,%edx
mov    %edx,%esi
call   1030 <fread@plt>
cmp    $0x1,%eax
je     1157 <read_line+0x47>
movl   $0x1,-0x14(%rbp)
jmp    1196 <read_line+0x86>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0xa,%eax
je     1177 <read_line+0x67>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0xd,%eax
jne    117c <read_line+0x6c>
jmp    1196 <read_line+0x86>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    112e <read_line+0x1e>
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
mov    $0x1,%al
cmpl   $0x0,-0x14(%rbp)
mov    %al,-0x19(%rbp)
je     11b6 <read_line+0xa6>
cmpl   $0x0,-0x18(%rbp)
setg   %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
and    $0x1,%al
movzbl %al,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_line>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%rbx
mov    %rdi,%r14
mov    %rsi,%rdi
mov    $0x1,%esi
mov    $0x1,%edx
mov    %r14,%rcx
call   1030 <fread@plt>
xor    %ebp,%ebp
cmp    $0x1,%eax
jne    1175 <read_line+0x65>
xor    %ebp,%ebp
nopl   0x0(%rax,%rax,1)
movzbl (%rbx),%eax
cmp    $0xa,%al
je     1179 <read_line+0x69>
cmp    $0xd,%al
je     1179 <read_line+0x69>
add    $0x1,%ebp
add    $0x1,%rbx
mov    %rbx,%rdi
mov    $0x1,%esi
mov    $0x1,%edx
mov    %r14,%rcx
call   1030 <fread@plt>
cmp    $0x1,%eax
je     1140 <read_line+0x30>
xor    %eax,%eax
mov    $0x1,%ebp
jmp    117b <read_line+0x6b>
xor    %eax,%eax
jmp    117b <read_line+0x6b>
mov    $0x1,%al
movb   $0x0,(%rbx)
test   %ebp,%ebp
setne  %cl
or     %al,%cl
movzbl %cl,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

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

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