#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 /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int getchar();
int /*<<< orphan*/ notimpl(char *);
int /*<<< orphan*/ stderr;
int Getline(void) {
  int c, i;
  extern int maxline;
  extern char *line;
  for (i = 0; i < maxline - 1 && (c = getchar()) != EOF && c != '\n'; ++i)
    line[i] = c;
  if (i == maxline - 1) {
    fprintf(stderr, "\n%s ", line);
    fprintf(stderr, "\nmaximum line length = %d ", maxline - 2);
    notimpl("maximum line length exceded");
  }
  if (c == '\n') {
    line[i] = c;
    ++i;
  }
  line[i] = '\0';
  return i;
}


x86 assembly (clang, -O0):
<Getline>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%ecx
mov    0x2e9f(%rip),%rax
mov    (%rax),%edx
sub    $0x1,%edx
xor    %eax,%eax
cmp    %edx,%ecx
mov    %al,-0x9(%rbp)
jge    1185 <Getline+0x55>
mov    $0x0,%al
call   1030 <getchar@plt>
mov    %eax,%ecx
mov    %ecx,-0x4(%rbp)
xor    %eax,%eax
mov    0x2e68(%rip),%rdx
cmp    (%rdx),%ecx
mov    %al,-0x9(%rbp)
je     1185 <Getline+0x55>
cmpl   $0xa,-0x4(%rbp)
setne  %al
mov    %al,-0x9(%rbp)
mov    -0x9(%rbp),%al
test   $0x1,%al
jne    1195 <Getline+0x65>
jmp    11b9 <Getline+0x89>
mov    -0x4(%rbp),%eax
mov    %al,%dl
mov    0x2e3f(%rip),%rax
mov    (%rax),%rax
movslq -0x8(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    113f <Getline+0xf>
mov    -0x8(%rbp),%eax
mov    0x2e25(%rip),%rcx
mov    (%rcx),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jne    1220 <Getline+0xf0>
mov    0x2df1(%rip),%rax
mov    (%rax),%edi
mov    0x2e00(%rip),%rax
mov    (%rax),%rdx
lea    0xe16(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    0x2dd0(%rip),%rax
mov    (%rax),%edi
mov    0x2de7(%rip),%rax
mov    (%rax),%edx
sub    $0x2,%edx
lea    0xdf8(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
lea    0xe05(%rip),%rdi
call   1050 <notimpl@plt>
cmpl   $0xa,-0x4(%rbp)
jne    1249 <Getline+0x119>
mov    -0x4(%rbp),%eax
mov    %al,%dl
mov    0x2daa(%rip),%rax
mov    (%rax),%rax
movslq -0x8(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
mov    0x2d90(%rip),%rax
mov    (%rax),%rax
movslq -0x8(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x8(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Getline>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    0x2ea9(%rip),%r14
mov    (%r14),%eax
cmp    $0x2,%eax
jl     118d <Getline+0x5d>
mov    0x2e8a(%rip),%r15
mov    0x2e8b(%rip),%r12
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1030 <getchar@plt>
mov    %eax,%ebp
cmp    $0xa,%eax
je     1191 <Getline+0x61>
cmp    (%r15),%ebp
je     1191 <Getline+0x61>
mov    (%r12),%rax
mov    %bpl,(%rax,%rbx,1)
add    $0x1,%rbx
movslq (%r14),%rax
lea    -0x1(%rax),%rcx
cmp    %rcx,%rbx
jl     1160 <Getline+0x30>
jmp    1194 <Getline+0x64>
xor    %ebx,%ebx
jmp    1194 <Getline+0x64>
mov    (%r14),%eax
add    $0xffffffff,%eax
cmp    %eax,%ebx
jne    11e0 <Getline+0xb0>
mov    0x2e26(%rip),%r15
mov    (%r15),%edi
mov    0x2e34(%rip),%rax
mov    (%rax),%rdx
lea    0xe4a(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    (%r15),%edi
mov    (%r14),%edx
add    $0xfffffffe,%edx
lea    0xe38(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
lea    0xe45(%rip),%rdi
call   1050 <notimpl@plt>
cmp    $0xa,%ebp
jne    11f8 <Getline+0xc8>
mov    0x2df4(%rip),%rax
mov    (%rax),%rax
mov    %ebx,%ecx
movb   $0xa,(%rax,%rcx,1)
add    $0x1,%ebx
mov    0x2de1(%rip),%rax
mov    (%rax),%rcx
movslq %ebx,%rax
movb   $0x0,(%rcx,%rax,1)
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@maxline = external global i32
@EOF = global i32 0
@line = external global i8*
@stderr = global i32 0
@.str = [5 x i8] c"\0A%s \00"
@.str.1 = [27 x i8] c"\0Amaximum line length = %d \00"
@.str.2 = [28 x i8] c"maximum line length exceded\00"
define i32 @Getline() {
%1 = alloca i32
%2 = alloca i32
store i32 0, i32* %2
br label %3
3: ; preds = %24, %0
%4 = load i32, i32* %2
%5 = load i32, i32* @maxline
%6 = sub nsw i32 %5, 1
%7 = icmp slt i32 %4, %6
br i1 %7, label %8, label %15
8: ; preds = %3
%9 = call i32 (...) @getchar()
store i32 %9, i32* %1
%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* %1
%14 = icmp ne i32 %13, 10
br label %15
15: ; preds = %12, %8, %3
%16 = phi i1 [ false, %8 ], [ false, %3 ], [ %14, %12 ]
br i1 %16, label %17, label %27
17: ; preds = %15
%18 = load i32, i32* %1
%19 = trunc i32 %18 to i8
%20 = load i8*, i8** @line
%21 = load i32, i32* %2
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i8, i8* %20, i64 %22
store i8 %19, i8* %23
br label %24
24: ; preds = %17
%25 = load i32, i32* %2
%26 = add nsw i32 %25, 1
store i32 %26, i32* %2
br label %3
27: ; preds = %15
%28 = load i32, i32* %2
%29 = load i32, i32* @maxline
%30 = sub nsw i32 %29, 1
%31 = icmp eq i32 %28, %30
br i1 %31, label %32, label %41
32: ; preds = %27
%33 = load i32, i32* @stderr
%34 = load i8*, i8** @line
%35 = call i32 (i32, i8*, ...) @fprintf(i32 %33, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %34)
%36 = load i32, i32* @stderr
%37 = load i32, i32* @maxline
%38 = sub nsw i32 %37, 2
%39 = call i32 (i32, i8*, ...) @fprintf(i32 %36, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i32 %38)
%40 = call i32 @notimpl(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0))
br label %41
41: ; preds = %32, %27
%42 = load i32, i32* %1
%43 = icmp eq i32 %42, 10
br i1 %43, label %44, label %53
44: ; preds = %41
%45 = load i32, i32* %1
%46 = trunc i32 %45 to i8
%47 = load i8*, i8** @line
%48 = load i32, i32* %2
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds i8, i8* %47, i64 %49
store i8 %46, i8* %50
%51 = load i32, i32* %2
%52 = add nsw i32 %51, 1
store i32 %52, i32* %2
br label %53
53: ; preds = %44, %41
%54 = load i8*, i8** @line
%55 = load i32, i32* %2
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds i8, i8* %54, i64 %56
store i8 0, i8* %57
%58 = load i32, i32* %2
ret i32 %58
}

LLVM IR (-O2):
@maxline = external global i32
@EOF = global i32 0
@line = external global i8*
@stderr = global i32 0
@.str = [5 x i8] c"\0A%s \00"
@.str.1 = [27 x i8] c"\0Amaximum line length = %d \00"
@.str.2 = [28 x i8] c"maximum line length exceded\00"
define i32 @Getline() {
%1 = load i32, i32* @maxline
%2 = icmp sgt i32 %1, 1
br i1 %2, label %3, label %25
3: ; preds = %0, %12
%4 = phi i64 [ %16, %12 ], [ 0, %0 ]
%5 = tail call i32 (...) @getchar()
%6 = load i32, i32* @EOF
%7 = icmp ne i32 %5, %6
%8 = icmp ne i32 %5, 10
%9 = and i1 %8, %7
br i1 %9, label %12, label %10
10: ; preds = %3
%11 = load i32, i32* @maxline
br label %21
12: ; preds = %3
%13 = trunc i32 %5 to i8
%14 = load i8*, i8** @line
%15 = getelementptr inbounds i8, i8* %14, i64 %4
store i8 %13, i8* %15
%16 = add nuw nsw i64 %4, 1
%17 = load i32, i32* @maxline
%18 = add nsw i32 %17, -1
%19 = sext i32 %18 to i64
%20 = icmp slt i64 %16, %19
br i1 %20, label %3, label %21
21: ; preds = %12, %10
%22 = phi i32 [ %11, %10 ], [ %17, %12 ]
%23 = phi i64 [ %4, %10 ], [ %16, %12 ]
%24 = trunc i64 %23 to i32
br label %25
25: ; preds = %21, %0
%26 = phi i32 [ %1, %0 ], [ %22, %21 ]
%27 = phi i32 [ 0, %0 ], [ %24, %21 ]
%28 = phi i32 [ undef, %0 ], [ %5, %21 ]
%29 = add nsw i32 %26, -1
%30 = icmp eq i32 %27, %29
br i1 %30, label %31, label %40
31: ; preds = %25
%32 = load i32, i32* @stderr
%33 = load i8*, i8** @line
%34 = tail call i32 (i32, i8*, ...) @fprintf(i32 %32, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %33)
%35 = load i32, i32* @stderr
%36 = load i32, i32* @maxline
%37 = add nsw i32 %36, -2
%38 = tail call i32 (i32, i8*, ...) @fprintf(i32 %35, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i32 %37)
%39 = tail call i32 @notimpl(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0))
br label %40
40: ; preds = %31, %25
%41 = icmp eq i32 %28, 10
br i1 %41, label %42, label %47
42: ; preds = %40
%43 = load i8*, i8** @line
%44 = zext i32 %27 to i64
%45 = getelementptr inbounds i8, i8* %43, i64 %44
store i8 10, i8* %45
%46 = add nuw nsw i32 %27, 1
br label %47
47: ; preds = %42, %40
%48 = phi i32 [ %46, %42 ], [ %27, %40 ]
%49 = load i8*, i8** @line
%50 = sext i32 %48 to i64
%51 = getelementptr inbounds i8, i8* %49, i64 %50
store i8 0, i8* %51
ret i32 %48
}