#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 */
char EOF;
char getchar();
int get_line(char line[]) {
  char current_char = EOF;
  int index = 0;
  while ((current_char = getchar()) != '\n') {
    line[index++] = current_char;
  }
  line[index] = '\0';
  return index;
}


x86 assembly (clang, -O0):
<get_line>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    0x2ec5(%rip),%rax
mov    (%rax),%al
mov    %al,-0x9(%rbp)
movl   $0x0,-0x10(%rbp)
mov    $0x0,%al
call   1030 <getchar@plt>
mov    %al,-0x9(%rbp)
movsbl %al,%eax
cmp    $0xa,%eax
je     1162 <get_line+0x52>
mov    -0x9(%rbp),%dl
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x10(%rbp)
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
jmp    112f <get_line+0x1f>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_line>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
xor    %ebx,%ebx
xor    %eax,%eax
call   1030 <getchar@plt>
cmp    $0xa,%al
je     1143 <get_line+0x33>
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
mov    %al,(%r14,%rbx,1)
add    $0x1,%rbx
xor    %eax,%eax
call   1030 <getchar@plt>
cmp    $0xa,%al
jne    1130 <get_line+0x20>
mov    %ebx,%eax
movb   $0x0,(%r14,%rax,1)
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@EOF = global i8 0
define i32 @get_line(i8* %0) {
%2 = alloca i8*
%3 = alloca i8
%4 = alloca i32
store i8* %0, i8** %2
%5 = load i8, i8* @EOF
store i8 %5, i8* %3
store i32 0, i32* %4
br label %6
6: ; preds = %10, %1
%7 = call signext i8 (...) @getchar()
store i8 %7, i8* %3
%8 = sext i8 %7 to i32
%9 = icmp ne i32 %8, 10
br i1 %9, label %10, label %17
10: ; preds = %6
%11 = load i8, i8* %3
%12 = load i8*, i8** %2
%13 = load i32, i32* %4
%14 = add nsw i32 %13, 1
store i32 %14, i32* %4
%15 = sext i32 %13 to i64
%16 = getelementptr inbounds i8, i8* %12, i64 %15
store i8 %11, i8* %16
br label %6
17: ; preds = %6
%18 = load i8*, i8** %2
%19 = load i32, i32* %4
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i8, i8* %18, i64 %20
store i8 0, i8* %21
%22 = load i32, i32* %4
ret i32 %22
}

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