#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 get_line(void) {
  int c, i;
  extern char line[];
  for (i = 0; i < 1000 - 1 && (c = getchar()) != EOF && c != '\n'; ++i)
    line[i] = c;
  if (c == '\n')
    line[i] = c;
  line[i] = '\0';
  return i;
}


x86 assembly (clang, -O0):
<get_line>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x8(%rbp)
xor    %eax,%eax
cmpl   $0x3e7,-0x8(%rbp)
mov    %al,-0x9(%rbp)
jge    115b <get_line+0x4b>
mov    $0x0,%al
call   1030 <getchar@plt>
mov    %eax,%ecx
mov    %ecx,-0x4(%rbp)
xor    %eax,%eax
mov    0x2e9a(%rip),%rdx
cmp    (%rdx),%ecx
mov    %al,-0x9(%rbp)
je     115b <get_line+0x4b>
cmpl   $0xa,-0x4(%rbp)
setne  %al
mov    %al,-0x9(%rbp)
mov    -0x9(%rbp),%al
test   $0x1,%al
jne    116b <get_line+0x5b>
jmp    118c <get_line+0x7c>
mov    -0x4(%rbp),%eax
mov    %al,%dl
movslq -0x8(%rbp),%rcx
mov    0x2e6d(%rip),%rax
mov    %dl,(%rax,%rcx,1)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    111f <get_line+0xf>
cmpl   $0xa,-0x4(%rbp)
jne    11a9 <get_line+0x99>
mov    -0x4(%rbp),%eax
mov    %al,%dl
movslq -0x8(%rbp),%rcx
mov    0x2e42(%rip),%rax
mov    %dl,(%rax,%rcx,1)
movslq -0x8(%rbp),%rcx
mov    0x2e34(%rip),%rax
movb   $0x0,(%rax,%rcx,1)
mov    -0x8(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_line>:
push   %r15
push   %r14
push   %rbx
mov    0x2ec4(%rip),%r15
mov    0x2ec5(%rip),%r14
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nop
xor    %eax,%eax
call   1030 <getchar@plt>
cmp    $0xa,%eax
je     1159 <get_line+0x49>
cmp    (%r15),%eax
je     1159 <get_line+0x49>
mov    %al,(%r14,%rbx,1)
add    $0x1,%rbx
cmp    $0x3e7,%rbx
jne    1130 <get_line+0x20>
mov    $0x3e7,%ebx
jmp    1163 <get_line+0x53>
cmp    $0xa,%eax
jne    1163 <get_line+0x53>
movb   $0xa,(%r14,%rbx,1)
mov    %ebx,%eax
movb   $0x0,(%r14,%rax,1)
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

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

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