#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*/ copy(char *, char *, int);
int getchar();
int getline(char *, int *, int);
int printUntil(int *, int);
int /*<<< orphan*/ printf(char *, ...);
int main(void) {
  int len;
  int c, newLen;
  char line[1000];
  char toPrint[1000];
  int isChar[1000];
  while ((len = getline(line, isChar, 1000)) > 0) {
    if (line[len - 1] != '\n')
      while ((c = getchar()) != EOF && c != '\n')
        ++len;
    newLen = printUntil(isChar, len);
    copy(toPrint, line, newLen);
    if (len > 0)
      printf("\nPrinting back:\n%s\nOriginal length of line:\n%d\n", toPrint,
             len + 1);
    printf("New length of line:\n%d\n", newLen + 1);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x17a0,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x400(%rbp),%rdi
lea    -0x1790(%rbp),%rsi
mov    $0x3e8,%edx
call   1070 <getline@plt>
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
jle    1260 <main+0x110>
mov    -0x8(%rbp),%eax
sub    $0x1,%eax
cltq
movsbl -0x400(%rbp,%rax,1),%eax
ff
cmp    $0xa,%eax
je     11fa <main+0xaa>
jmp    11a4 <main+0x54>
mov    $0x0,%al
call   1060 <getchar@plt>
mov    %eax,%ecx
mov    %ecx,-0xc(%rbp)
xor    %eax,%eax
mov    0x2e2f(%rip),%rdx
cmp    (%rdx),%ecx
mov    %al,-0x1791(%rbp)
je     11d4 <main+0x84>
cmpl   $0xa,-0xc(%rbp)
setne  %al
mov    %al,-0x1791(%rbp)
mov    -0x1791(%rbp),%al
test   $0x1,%al
jne    11e7 <main+0x97>
jmp    11f5 <main+0xa5>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    11a4 <main+0x54>
jmp    11fa <main+0xaa>
lea    -0x1790(%rbp),%rdi
mov    -0x8(%rbp),%esi
call   1040 <printUntil@plt>
mov    %eax,-0x10(%rbp)
lea    -0x7f0(%rbp),%rdi
lea    -0x400(%rbp),%rsi
mov    -0x10(%rbp),%edx
call   1050 <copy@plt>
cmpl   $0x0,-0x8(%rbp)
jle    1247 <main+0xf7>
lea    -0x7f0(%rbp),%rsi
mov    -0x8(%rbp),%edx
add    $0x1,%edx
lea    0xdc0(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%esi
add    $0x1,%esi
lea    0xddc(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1162 <main+0x12>
xor    %eax,%eax
add    $0x17a0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1788,%rsp
mov    %rsp,%rdi
lea    0x7e0(%rsp),%rsi
mov    $0x3e8,%edx
call   1070 <getline@plt>
test   %eax,%eax
jle    122e <main+0xde>
mov    %eax,%ebp
lea    0x7e0(%rsp),%r15
lea    0x3f0(%rsp),%r14
mov    %rsp,%rbx
mov    0x2e4e(%rip),%r13
jmp    11cb <main+0x7b>
nopl   0x0(%rax)
add    $0x1,%r12d
lea    0xe85(%rip),%rdi
mov    %r12d,%esi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    $0x3e8,%edx
call   1070 <getline@plt>
mov    %eax,%ebp
test   %eax,%eax
jle    122e <main+0xde>
lea    -0x1(%rbp),%eax
cmpb   $0xa,(%rsp,%rax,1)
je     11f5 <main+0xa5>
mov    %eax,%ebp
cs nopw 0x0(%rax,%rax,1)
xor    %eax,%eax
call   1060 <getchar@plt>
add    $0x1,%ebp
cmp    $0xa,%eax
je     11f5 <main+0xa5>
cmp    0x0(%r13),%eax
jne    11e0 <main+0x90>
mov    %r15,%rdi
mov    %ebp,%esi
call   1040 <printUntil@plt>
mov    %eax,%r12d
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
call   1050 <copy@plt>
test   %ebp,%ebp
jle    11a0 <main+0x50>
add    $0x1,%ebp
lea    0xde3(%rip),%rdi
mov    %r14,%rsi
mov    %ebp,%edx
xor    %eax,%eax
call   1030 <printf@plt>
jmp    11a0 <main+0x50>
xor    %eax,%eax
add    $0x1788,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@EOF = global i32 0
@.str = [48 x i8] c"\0APrinting back:\0A%s\0AOriginal length of line:\0A%d\0A\00"
@.str.1 = [24 x i8] c"New length of line:\0A%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca [1000 x i8]
%6 = alloca [1000 x i8]
%7 = alloca [1000 x i32]
store i32 0, i32* %1
br label %8
8: ; preds = %50, %0
%9 = getelementptr inbounds [1000 x i8], [1000 x i8]* %5, i64 0, i64 0
%10 = getelementptr inbounds [1000 x i32], [1000 x i32]* %7, i64 0, i64 0
%11 = call i32 @getline(i8* %9, i32* %10, i32 1000)
store i32 %11, i32* %2
%12 = icmp sgt i32 %11, 0
br i1 %12, label %13, label %54
13: ; preds = %8
%14 = load i32, i32* %2
%15 = sub nsw i32 %14, 1
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds [1000 x i8], [1000 x i8]* %5, i64 0, i64 %16
%18 = load i8, i8* %17
%19 = sext i8 %18 to i32
%20 = icmp ne i32 %19, 10
br i1 %20, label %21, label %35
21: ; preds = %13
br label %22
22: ; preds = %31, %21
%23 = call i32 (...) @getchar()
store i32 %23, i32* %3
%24 = load i32, i32* @EOF
%25 = icmp ne i32 %23, %24
br i1 %25, label %26, label %29
26: ; preds = %22
%27 = load i32, i32* %3
%28 = icmp ne i32 %27, 10
br label %29
29: ; preds = %26, %22
%30 = phi i1 [ false, %22 ], [ %28, %26 ]
br i1 %30, label %31, label %34
31: ; preds = %29
%32 = load i32, i32* %2
%33 = add nsw i32 %32, 1
store i32 %33, i32* %2
br label %22
34: ; preds = %29
br label %35
35: ; preds = %34, %13
%36 = getelementptr inbounds [1000 x i32], [1000 x i32]* %7, i64 0, i64 0
%37 = load i32, i32* %2
%38 = call i32 @printUntil(i32* %36, i32 %37)
store i32 %38, i32* %4
%39 = getelementptr inbounds [1000 x i8], [1000 x i8]* %6, i64 0, i64 0
%40 = getelementptr inbounds [1000 x i8], [1000 x i8]* %5, i64 0, i64 0
%41 = load i32, i32* %4
%42 = call i32 @copy(i8* %39, i8* %40, i32 %41)
%43 = load i32, i32* %2
%44 = icmp sgt i32 %43, 0
br i1 %44, label %45, label %50
45: ; preds = %35
%46 = getelementptr inbounds [1000 x i8], [1000 x i8]* %6, i64 0, i64 0
%47 = load i32, i32* %2
%48 = add nsw i32 %47, 1
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str, i64 0, i64 0), i8* %46, i32 %48)
br label %50
50: ; preds = %45, %35
%51 = load i32, i32* %4
%52 = add nsw i32 %51, 1
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i32 %52)
br label %8
54: ; preds = %8
ret i32 0
}

LLVM IR (-O2):
@EOF = global i32 0
@.str = [48 x i8] c"\0APrinting back:\0A%s\0AOriginal length of line:\0A%d\0A\00"
@.str.1 = [24 x i8] c"New length of line:\0A%d\0A\00"
define i32 @main() {
%1 = alloca [1000 x i8]
%2 = alloca [1000 x i8]
%3 = alloca [1000 x i32]
%4 = getelementptr inbounds [1000 x i8], [1000 x i8]* %1, i64 0, i64 0
%5 = getelementptr inbounds [1000 x i8], [1000 x i8]* %2, i64 0, i64 0
%6 = bitcast [1000 x i32]* %3 to i8*
%7 = getelementptr inbounds [1000 x i32], [1000 x i32]* %3, i64 0, i64 0
%8 = call i32 @getline(i8* %4, i32* %7, i32 1000)
%9 = icmp sgt i32 %8, 0
br i1 %9, label %10, label %38
10: ; preds = %0, %33
%11 = phi i32 [ %36, %33 ], [ %8, %0 ]
%12 = add nsw i32 %11, -1
%13 = zext i32 %12 to i64
%14 = getelementptr inbounds [1000 x i8], [1000 x i8]* %1, i64 0, i64 %13
%15 = load i8, i8* %14
%16 = icmp eq i8 %15, 10
br i1 %16, label %25, label %17
17: ; preds = %10, %17
%18 = phi i32 [ %24, %17 ], [ %11, %10 ]
%19 = call i32 (...) @getchar()
%20 = load i32, i32* @EOF
%21 = icmp ne i32 %19, %20
%22 = icmp ne i32 %19, 10
%23 = and i1 %22, %21
%24 = add nsw i32 %18, 1
br i1 %23, label %17, label %25
25: ; preds = %17, %10
%26 = phi i32 [ %11, %10 ], [ %18, %17 ]
%27 = call i32 @printUntil(i32* %7, i32 %26)
%28 = call i32 @copy(i8* %5, i8* %4, i32 %27)
%29 = icmp sgt i32 %26, 0
br i1 %29, label %30, label %33
30: ; preds = %25
%31 = add nuw nsw i32 %26, 1
%32 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([48 x i8], [48 x i8]* @.str, i64 0, i64 0), i8* %5, i32 %31)
br label %33
33: ; preds = %30, %25
%34 = add nsw i32 %27, 1
%35 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i32 %34)
%36 = call i32 @getline(i8* %4, i32* %7, i32 1000)
%37 = icmp sgt i32 %36, 0
br i1 %37, label %10, label %38
38: ; preds = %33, %0
ret i32 0
}