#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 myGetline(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;
    ++i;
  }
  line[i] = '\0';
  return i;
}


x86 assembly (clang, -O0):
<myGetline>:
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 <myGetline+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 <myGetline+0x4b>
cmpl   $0xa,-0x4(%rbp)
setne  %al
mov    %al,-0x9(%rbp)
mov    -0x9(%rbp),%al
test   $0x1,%al
jne    116b <myGetline+0x5b>
jmp    118c <myGetline+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 <myGetline+0xf>
cmpl   $0xa,-0x4(%rbp)
jne    11b2 <myGetline+0xa2>
mov    -0x4(%rbp),%eax
mov    %al,%dl
movslq -0x8(%rbp),%rcx
mov    0x2e42(%rip),%rax
mov    %dl,(%rax,%rcx,1)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
movslq -0x8(%rbp),%rcx
mov    0x2e2b(%rip),%rax
movb   $0x0,(%rax,%rcx,1)
mov    -0x8(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<myGetline>:
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 <myGetline+0x49>
cmp    (%r15),%eax
je     1159 <myGetline+0x49>
mov    %al,(%r14,%rbx,1)
add    $0x1,%rbx
cmp    $0x3e7,%rbx
jne    1130 <myGetline+0x20>
mov    $0x3e7,%ebx
jmp    1166 <myGetline+0x56>
cmp    $0xa,%eax
jne    1166 <myGetline+0x56>
movb   $0xa,(%r14,%rbx,1)
add    $0x1,%ebx
movslq %ebx,%rax
movb   $0x0,(%r14,%rax,1)
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@EOF = global i32 0
@line = external global [0 x i8]
define i32 @myGetline() {
%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 %35
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
%33 = load i32, i32* %2
%34 = add nsw i32 %33, 1
store i32 %34, i32* %2
br label %35
35: ; preds = %27, %24
%36 = load i32, i32* %2
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds [0 x i8], [0 x i8]* @line, i64 0, i64 %37
store i8 0, i8* %38
%39 = load i32, i32* %2
ret i32 %39
}

LLVM IR (-O2):
@EOF = global i32 0
@line = external global [0 x i8]
define i32 @myGetline() {
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 %20, label %1
13: ; preds = %1
%14 = trunc i64 %2 to i32
%15 = icmp eq i32 %3, 10
br i1 %15, label %16, label %20
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
%19 = add nuw nsw i32 %14, 1
br label %20
20: ; preds = %8, %16, %13
%21 = phi i32 [ %19, %16 ], [ %14, %13 ], [ 999, %8 ]
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds [0 x i8], [0 x i8]* @line, i64 0, i64 %22
store i8 0, i8* %23
ret i32 %21
}