#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(char *line) {
  int character, line_length;
  for (line_length = 0; (character = getchar()) != '\n' && character != EOF &&
                        line_length < 1000;
       ++line_length)
    *line++ = character;
  *line = '\0';
  return line_length += (character == '\n') ? 1 : 0;
}


x86 assembly (clang, -O0):
<get_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
cmp    $0xa,%ecx
mov    %al,-0x11(%rbp)
je     1161 <get_line+0x51>
mov    -0xc(%rbp),%ecx
xor    %eax,%eax
mov    0x2e9f(%rip),%rdx
cmp    (%rdx),%ecx
mov    %al,-0x11(%rbp)
je     1161 <get_line+0x51>
cmpl   $0x3e8,-0x10(%rbp)
setl   %al
mov    %al,-0x11(%rbp)
mov    -0x11(%rbp),%al
test   $0x1,%al
jne    1171 <get_line+0x61>
jmp    1195 <get_line+0x85>
mov    -0xc(%rbp),%eax
mov    %al,%cl
mov    -0x8(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x8(%rbp)
mov    %cl,(%rax)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1123 <get_line+0x13>
mov    -0x8(%rbp),%rax
movb   $0x0,(%rax)
mov    -0xc(%rbp),%edx
xor    %eax,%eax
mov    $0x1,%ecx
cmp    $0xa,%edx
cmove  %ecx,%eax
add    -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_line>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
xor    %eax,%eax
call   1030 <getchar@plt>
mov    $0x1,%ecx
cmp    $0xa,%eax
je     1175 <get_line+0x65>
mov    0x2eb5(%rip),%r12
xor    %r15d,%r15d
cs nopw 0x0(%rax,%rax,1)
cmp    (%r12),%eax
setne  %cl
cmp    $0x3e8,%r15d
setb   %bl
and    %cl,%bl
cmp    $0x1,%bl
jne    116c <get_line+0x5c>
mov    %al,(%r14,%r15,1)
xor    %eax,%eax
call   1030 <getchar@plt>
add    $0x1,%r15
cmp    $0xa,%eax
jne    1140 <get_line+0x30>
add    %r15,%r14
movzbl %bl,%ecx
add    %r15d,%ecx
movb   $0x0,(%r14)
mov    %ecx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

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