#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 EOF;
int getc(int /*<<< orphan*/ *);
int rd(FILE *file, char *buf) {
  register int i, c;
  i = 0;
  while ((c = getc(file)) != EOF) {
    *buf = c;
    if (c == '\n' || i > 256 - 2) {
      *buf = '\0';
      return (0);
    }
    i++;
    buf++;
  }
  return (-1);
}


x86 assembly (clang, -O0):
<rd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <getc@plt>
mov    %eax,-0x20(%rbp)
mov    0x2eae(%rip),%rcx
cmp    (%rcx),%eax
je     1191 <rd+0x81>
mov    -0x20(%rbp),%eax
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %cl,(%rax)
cmpl   $0xa,-0x20(%rbp)
je     1164 <rd+0x54>
cmpl   $0xfe,-0x1c(%rbp)
jle    1177 <rd+0x67>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
movl   $0x0,-0x4(%rbp)
jmp    1198 <rd+0x88>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1127 <rd+0x17>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rd>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%r12
mov    %rdi,%rbp
call   1030 <getc@plt>
mov    0x2ebe(%rip),%r15
mov    $0xffffffff,%r14d
cmp    (%r15),%eax
je     116c <rd+0x5c>
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
mov    %al,(%r12,%rbx,1)
cmp    $0xa,%eax
je     1164 <rd+0x54>
cmp    $0xff,%ebx
jae    1164 <rd+0x54>
mov    %rbp,%rdi
call   1030 <getc@plt>
add    $0x1,%rbx
cmp    (%r15),%eax
jne    1140 <rd+0x30>
jmp    116c <rd+0x5c>
movb   $0x0,(%r12,%rbx,1)
xor    %r14d,%r14d
mov    %r14d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@EOF = global i32 0
define i32 @rd(i32* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
store i32* %0, i32** %4
store i8* %1, i8** %5
store i32 0, i32* %6
br label %8
8: ; preds = %24, %2
%9 = load i32*, i32** %4
%10 = call i32 @getc(i32* %9)
store i32 %10, i32* %7
%11 = load i32, i32* @EOF
%12 = icmp ne i32 %10, %11
br i1 %12, label %13, label %29
13: ; preds = %8
%14 = load i32, i32* %7
%15 = trunc i32 %14 to i8
%16 = load i8*, i8** %5
store i8 %15, i8* %16
%17 = load i32, i32* %7
%18 = icmp eq i32 %17, 10
br i1 %18, label %22, label %19
19: ; preds = %13
%20 = load i32, i32* %6
%21 = icmp sgt i32 %20, 254
br i1 %21, label %22, label %24
22: ; preds = %19, %13
%23 = load i8*, i8** %5
store i8 0, i8* %23
store i32 0, i32* %3
br label %30
24: ; preds = %19
%25 = load i32, i32* %6
%26 = add nsw i32 %25, 1
store i32 %26, i32* %6
%27 = load i8*, i8** %5
%28 = getelementptr inbounds i8, i8* %27, i32 1
store i8* %28, i8** %5
br label %8
29: ; preds = %8
store i32 -1, i32* %3
br label %30
30: ; preds = %29, %22
%31 = load i32, i32* %3
ret i32 %31
}

LLVM IR (-O2):
@EOF = global i32 0
define i32 @rd(i32* nocapture %0, i8* nocapture writeonly %1) {
%3 = tail call i32 @getc(i32* %0)
%4 = load i32, i32* @EOF
%5 = icmp eq i32 %3, %4
br i1 %5, label %21, label %6
6: ; preds = %2, %15
%7 = phi i32 [ %18, %15 ], [ %3, %2 ]
%8 = phi i32 [ %16, %15 ], [ 0, %2 ]
%9 = phi i8* [ %17, %15 ], [ %1, %2 ]
%10 = trunc i32 %7 to i8
store i8 %10, i8* %9
%11 = icmp eq i32 %7, 10
%12 = icmp ugt i32 %8, 254
%13 = select i1 %11, i1 true, i1 %12
br i1 %13, label %14, label %15
14: ; preds = %6
store i8 0, i8* %9
br label %21
15: ; preds = %6
%16 = add nuw nsw i32 %8, 1
%17 = getelementptr inbounds i8, i8* %9, i64 1
%18 = tail call i32 @getc(i32* %0)
%19 = load i32, i32* @EOF
%20 = icmp eq i32 %18, %19
br i1 %20, label %21, label %6
21: ; preds = %15, %2, %14
%22 = phi i32 [ 0, %14 ], [ -1, %2 ], [ -1, %15 ]
ret i32 %22
}