#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;
scalar_t__ getchar();
int get_line(char *line) {
  char c;
  char *p = line;
  while (1) {
    c = (char)getchar();
    if (c == (char)EOF)
      return EOF;
    else if (c == '\n') {
      *p = '\0';
      return 0;
    } else {
      *p = c;
      p++;
    }
  }
}


x86 assembly (clang, -O0):
<get_line>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    $0x0,%al
call   1030 <getchar@plt>
mov    %al,-0x11(%rbp)
movsbl -0x11(%rbp),%eax
mov    0x2eaf(%rip),%rcx
mov    (%rcx),%ecx
movsbl %cl,%ecx
cmp    %ecx,%eax
jne    1157 <get_line+0x47>
mov    0x2e9b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1196 <get_line+0x86>
movsbl -0x11(%rbp),%eax
cmp    $0xa,%eax
jne    1177 <get_line+0x67>
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
movl   $0x0,-0x4(%rbp)
jmp    1196 <get_line+0x86>
mov    -0x11(%rbp),%cl
mov    -0x20(%rbp),%rax
mov    %cl,(%rax)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1191 <get_line+0x81>
jmp    1124 <get_line+0x14>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_line>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
xor    %eax,%eax
call   1030 <getchar@plt>
movsbl %al,%edx
mov    0x2ec0(%rip),%r14
nopl   0x0(%rax,%rax,1)
mov    (%r14),%ecx
movsbl %cl,%esi
cmp    %edx,%esi
je     1155 <get_line+0x45>
cmp    $0xa,%al
je     1150 <get_line+0x40>
mov    %al,(%rbx)
add    $0x1,%rbx
xor    %eax,%eax
call   1030 <getchar@plt>
movsbl %al,%edx
jmp    1130 <get_line+0x20>
movb   $0x0,(%rbx)
xor    %ecx,%ecx
mov    %ecx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
@EOF = global i32 0
define i32 @get_line(i8* nocapture writeonly %0) {
%2 = tail call i64 (...) @getchar()
%3 = trunc i64 %2 to i8
%4 = sext i8 %3 to i32
%5 = load i32, i32* @EOF
%6 = shl i32 %5, 24
%7 = ashr exact i32 %6, 24
%8 = icmp eq i32 %7, %4
br i1 %8, label %23, label %9
9: ; preds = %1, %14
%10 = phi i8 [ %17, %14 ], [ %3, %1 ]
%11 = phi i8* [ %15, %14 ], [ %0, %1 ]
%12 = icmp eq i8 %10, 10
br i1 %12, label %13, label %14
13: ; preds = %9
store i8 0, i8* %11
br label %23
14: ; preds = %9
store i8 %10, i8* %11
%15 = getelementptr inbounds i8, i8* %11, i64 1
%16 = tail call i64 (...) @getchar()
%17 = trunc i64 %16 to i8
%18 = sext i8 %17 to i32
%19 = load i32, i32* @EOF
%20 = shl i32 %19, 24
%21 = ashr exact i32 %20, 24
%22 = icmp eq i32 %21, %18
br i1 %22, label %23, label %9
23: ; preds = %14, %1, %13
%24 = phi i32 [ 0, %13 ], [ %5, %1 ], [ %19, %14 ]
ret i32 %24
}