#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 */

/* Variables and functions */
int EOF;
int getchar();
int readbuff(char *buffer) {
  size_t i = 0;
  int c;
  while (i < 81) {
    c = getchar();
    if (c == EOF)
      return -1;
    if (c == '\n')
      return 0;
    buffer[i++] = c;
  }
  return 1;
}


x86 assembly (clang, -O0):
<readbuff>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
cmpq   $0x51,-0x18(%rbp)
jae    118d <readbuff+0x7d>
mov    $0x0,%al
call   1030 <getchar@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    0x2ea5(%rip),%rcx
cmp    (%rcx),%eax
jne    1157 <readbuff+0x47>
movl   $0xffffffff,-0x4(%rbp)
jmp    1194 <readbuff+0x84>
cmpl   $0xa,-0x1c(%rbp)
jne    116d <readbuff+0x5d>
movl   $0x0,-0x4(%rbp)
jmp    1194 <readbuff+0x84>
mov    -0x1c(%rbp),%eax
mov    %al,%dl
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    %rcx,%rsi
add    $0x1,%rsi
mov    %rsi,-0x18(%rbp)
mov    %dl,(%rax,%rcx,1)
jmp    1124 <readbuff+0x14>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readbuff>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r15
mov    0x2ec9(%rip),%r14
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1030 <getchar@plt>
cmp    (%r14),%eax
je     1156 <readbuff+0x46>
cmp    $0xa,%eax
je     115d <readbuff+0x4d>
mov    %al,(%r15,%rbx,1)
add    $0x1,%rbx
cmp    $0x51,%rbx
jne    1130 <readbuff+0x20>
mov    $0x1,%eax
jmp    115f <readbuff+0x4f>
mov    $0xffffffff,%eax
jmp    115f <readbuff+0x4f>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

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

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