#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 println(char *, int);
int main(void) {
  extern int maxstr;
  extern int endarr;
  maxstr = 80;
  ++maxstr;
  endarr = maxstr - 2;
  int c;
  int col = 0;
  char line[maxstr];
  while ((c = getchar()) != EOF) {
    if (c == '\n' || col > endarr) {
      line[col] = '\0';
      col = println(line, c);
    } else {
      line[col++] = c;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e9a(%rip),%rax
movl   $0x50,(%rax)
mov    (%rax),%ecx
add    $0x1,%ecx
mov    %ecx,(%rax)
mov    (%rax),%edx
add    $0xfffffffe,%edx
mov    0x2e99(%rip),%rcx
mov    %edx,(%rcx)
movl   $0x0,-0xc(%rbp)
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x28(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x20(%rbp)
mov    $0x0,%al
call   1040 <getchar@plt>
mov    %eax,-0x8(%rbp)
mov    0x2e52(%rip),%rcx
cmp    (%rcx),%eax
je     11ed <main+0xcd>
cmpl   $0xa,-0x8(%rbp)
je     11b2 <main+0x92>
mov    -0xc(%rbp),%eax
mov    0x2e3e(%rip),%rcx
cmp    (%rcx),%eax
jle    11ce <main+0xae>
mov    -0x28(%rbp),%rdi
movslq -0xc(%rbp),%rax
movb   $0x0,(%rdi,%rax,1)
mov    -0x8(%rbp),%esi
call   1030 <println@plt>
mov    %eax,-0xc(%rbp)
jmp    11e8 <main+0xc8>
mov    -0x28(%rbp),%rax
mov    -0x8(%rbp),%ecx
mov    %cl,%dl
mov    -0xc(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0xc(%rbp)
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
jmp    117d <main+0x5d>
movl   $0x0,-0x4(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x58,%rsp
mov    0x2e9f(%rip),%rax
movl   $0x51,(%rax)
mov    0x2eaa(%rip),%r15
movl   $0x4f,(%r15)
xor    %eax,%eax
call   1040 <getchar@plt>
mov    0x2e8d(%rip),%rbx
cmp    (%rbx),%eax
jne    1164 <main+0x44>
xor    %eax,%eax
add    $0x58,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %rsp,%r14
xor    %ebp,%ebp
jmp    118b <main+0x6b>
nopl   0x0(%rax,%rax,1)
movb   $0x0,(%rsp,%rcx,1)
mov    %r14,%rdi
mov    %eax,%esi
call   1030 <println@plt>
mov    %eax,%ebp
xor    %eax,%eax
call   1040 <getchar@plt>
cmp    (%rbx),%eax
je     1157 <main+0x37>
movslq %ebp,%rcx
cmp    $0xa,%eax
je     1170 <main+0x50>
cmp    (%r15),%ebp
jg     1170 <main+0x50>
add    $0x1,%ebp
mov    %al,(%rsp,%rcx,1)
jmp    1180 <main+0x60>

LLVM IR (-O0):
@maxstr = external global i32
@endarr = external global i32
@EOF = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i64
store i32 0, i32* %1
store i32 80, i32* @maxstr
%6 = load i32, i32* @maxstr
%7 = add nsw i32 %6, 1
store i32 %7, i32* @maxstr
%8 = load i32, i32* @maxstr
%9 = sub nsw i32 %8, 2
store i32 %9, i32* @endarr
store i32 0, i32* %3
%10 = load i32, i32* @maxstr
%11 = zext i32 %10 to i64
%12 = call i8* @llvm.stacksave()
store i8* %12, i8** %4
%13 = alloca i8, i64 %11
store i64 %11, i64* %5
br label %14
14: ; preds = %38, %0
%15 = call i32 (...) @getchar()
store i32 %15, i32* %2
%16 = load i32, i32* @EOF
%17 = icmp ne i32 %15, %16
br i1 %17, label %18, label %39
18: ; preds = %14
%19 = load i32, i32* %2
%20 = icmp eq i32 %19, 10
br i1 %20, label %25, label %21
21: ; preds = %18
%22 = load i32, i32* %3
%23 = load i32, i32* @endarr
%24 = icmp sgt i32 %22, %23
br i1 %24, label %25, label %31
25: ; preds = %21, %18
%26 = load i32, i32* %3
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i8, i8* %13, i64 %27
store i8 0, i8* %28
%29 = load i32, i32* %2
%30 = call i32 @println(i8* %13, i32 %29)
store i32 %30, i32* %3
br label %38
31: ; preds = %21
%32 = load i32, i32* %2
%33 = trunc i32 %32 to i8
%34 = load i32, i32* %3
%35 = add nsw i32 %34, 1
store i32 %35, i32* %3
%36 = sext i32 %34 to i64
%37 = getelementptr inbounds i8, i8* %13, i64 %36
store i8 %33, i8* %37
br label %38
38: ; preds = %31, %25
br label %14
39: ; preds = %14
store i32 0, i32* %1
%40 = load i8*, i8** %4
%41 = load i32, i32* %1
ret i32 %41
}

LLVM IR (-O2):
@maxstr = external global i32
@endarr = external global i32
@EOF = global i32 0
define i32 @main() {
store i32 81, i32* @maxstr
store i32 79, i32* @endarr
%1 = alloca [81 x i8]
%2 = getelementptr inbounds [81 x i8], [81 x i8]* %1, i64 0, i64 0
%3 = call i32 (...) @getchar()
%4 = load i32, i32* @EOF
%5 = icmp eq i32 %3, %4
br i1 %5, label %27, label %6
6: ; preds = %0, %22
%7 = phi i32 [ %24, %22 ], [ %3, %0 ]
%8 = phi i32 [ %23, %22 ], [ 0, %0 ]
%9 = icmp eq i32 %7, 10
%10 = load i32, i32* @endarr
%11 = icmp sgt i32 %8, %10
%12 = select i1 %9, i1 true, i1 %11
br i1 %12, label %13, label %17
13: ; preds = %6
%14 = sext i32 %8 to i64
%15 = getelementptr inbounds [81 x i8], [81 x i8]* %1, i64 0, i64 %14
store i8 0, i8* %15
%16 = call i32 @println(i8* %2, i32 %7)
br label %22
17: ; preds = %6
%18 = trunc i32 %7 to i8
%19 = add nsw i32 %8, 1
%20 = sext i32 %8 to i64
%21 = getelementptr inbounds [81 x i8], [81 x i8]* %1, i64 0, i64 %20
store i8 %18, i8* %21
br label %22
22: ; preds = %17, %13
%23 = phi i32 [ %16, %13 ], [ %19, %17 ]
%24 = call i32 (...) @getchar()
%25 = load i32, i32* @EOF
%26 = icmp eq i32 %24, %25
br i1 %26, label %27, label %6
27: ; preds = %22, %0
ret i32 0
}