#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 read_line(char *s) {
  int c, i;
  for (i = 0; (c = getchar()) != EOF && c != '\n' && i < 80; ++i)
    s[i] = c;
  s[i] = '\0';
  return i;
}


x86 assembly (clang, -O0):
<read_line>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0x10(%rbp)
mov    $0x0,%al
call   1030 <getchar@plt>
mov    %eax,%ecx
mov    %ecx,-0xc(%rbp)
xor    %eax,%eax
mov    0x2eb0(%rip),%rdx
cmp    (%rdx),%ecx
mov    %al,-0x11(%rbp)
je     115c <read_line+0x4c>
xor    %eax,%eax
cmpl   $0xa,-0xc(%rbp)
mov    %al,-0x11(%rbp)
je     115c <read_line+0x4c>
cmpl   $0x50,-0x10(%rbp)
setl   %al
mov    %al,-0x11(%rbp)
mov    -0x11(%rbp),%al
test   $0x1,%al
jne    116c <read_line+0x5c>
jmp    118a <read_line+0x7a>
mov    -0xc(%rbp),%eax
mov    %al,%dl
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1123 <read_line+0x13>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_line>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
xor    %r12d,%r12d
xor    %eax,%eax
call   1030 <getchar@plt>
cmp    $0xa,%eax
je     1162 <read_line+0x52>
mov    0x2eb7(%rip),%r15
cmp    (%r15),%eax
je     1162 <read_line+0x52>
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
mov    %al,(%r14,%rbx,1)
lea    0x1(%rbx),%r12
xor    %eax,%eax
call   1030 <getchar@plt>
cmp    $0xa,%eax
je     1162 <read_line+0x52>
cmp    (%r15),%eax
je     1162 <read_line+0x52>
cmp    $0x4f,%rbx
mov    %r12,%rbx
jb     1140 <read_line+0x30>
mov    %r12d,%eax
movb   $0x0,(%r14,%rax,1)
mov    %r12d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@EOF = global i32 0
define i32 @read_line(i8* nocapture writeonly %0) {
%2 = tail call i32 (...) @getchar()
%3 = load i32, i32* @EOF
%4 = icmp ne i32 %2, %3
%5 = icmp ne i32 %2, 10
%6 = and i1 %5, %4
br i1 %6, label %7, label %22
7: ; preds = %1, %7
%8 = phi i64 [ %12, %7 ], [ 0, %1 ]
%9 = phi i32 [ %13, %7 ], [ %2, %1 ]
%10 = trunc i32 %9 to i8
%11 = getelementptr inbounds i8, i8* %0, i64 %8
store i8 %10, i8* %11
%12 = add nuw nsw i64 %8, 1
%13 = tail call i32 (...) @getchar()
%14 = load i32, i32* @EOF
%15 = icmp ne i32 %13, %14
%16 = icmp ne i32 %13, 10
%17 = and i1 %16, %15
%18 = icmp ult i64 %8, 79
%19 = select i1 %17, i1 %18, i1 false
br i1 %19, label %7, label %20
20: ; preds = %7
%21 = trunc i64 %12 to i32
br label %22
22: ; preds = %20, %1
%23 = phi i32 [ 0, %1 ], [ %21, %20 ]
%24 = zext i32 %23 to i64
%25 = getelementptr inbounds i8, i8* %0, i64 %24
store i8 0, i8* %25
ret i32 %23
}