#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 /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ putchar(int);
int main() {
  char buf[80 + 1];
  int buf_pos = 0;
  int ch;
  while ((ch = getchar()) != EOF) {
    if (buf_pos < 80) {
      buf[buf_pos++] = ch;
    } else if (buf_pos == 80) {
      buf[buf_pos++] = '\0';
      printf("%s", buf);
      putchar(ch);
    } else if (buf_pos > 80) {
      putchar(ch);
    }
    if (ch == '\n') {
      buf_pos = 0;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x64(%rbp)
mov    $0x0,%al
call   1050 <getchar@plt>
mov    %eax,-0x68(%rbp)
mov    0x2e91(%rip),%rcx
cmp    (%rcx),%eax
je     11ef <main+0xbf>
cmpl   $0x50,-0x64(%rbp)
jge    1184 <main+0x54>
mov    -0x68(%rbp),%eax
mov    %al,%cl
mov    -0x64(%rbp),%eax
mov    %eax,%edx
add    $0x1,%edx
mov    %edx,-0x64(%rbp)
cltq
mov    %cl,-0x60(%rbp,%rax,1)
jmp    11d9 <main+0xa9>
cmpl   $0x50,-0x64(%rbp)
jne    11bd <main+0x8d>
mov    -0x64(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x64(%rbp)
cltq
movb   $0x0,-0x60(%rbp,%rax,1)
lea    -0x60(%rbp),%rsi
lea    0xe55(%rip),%rdi
call   1040 <printf@plt>
mov    -0x68(%rbp),%edi
call   1030 <putchar@plt>
jmp    11d4 <main+0xa4>
cmpl   $0x50,-0x64(%rbp)
jle    11cf <main+0x9f>
mov    -0x68(%rbp),%edi
call   1030 <putchar@plt>
jmp    11d4 <main+0xa4>
jmp    11d9 <main+0xa9>
cmpl   $0xa,-0x68(%rbp)
jne    11ea <main+0xba>
movl   $0x0,-0x64(%rbp)
jmp    1146 <main+0x16>
xor    %eax,%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x58,%rsp
xor    %r12d,%r12d
xor    %eax,%eax
call   1050 <getchar@plt>
mov    0x2e99(%rip),%r13
cmp    0x0(%r13),%eax
jne    1166 <main+0x36>
xor    %eax,%eax
add    $0x58,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %eax,%ebp
lea    0xe91(%rip),%r14
mov    %rsp,%r15
xor    %ebx,%ebx
jmp    11a0 <main+0x70>
cs nopw 0x0(%rax,%rax,1)
movslq %ebx,%rax
add    $0x1,%ebx
mov    %bpl,(%rsp,%rax,1)
cmp    $0xa,%ebp
cmove  %r12d,%ebx
xor    %eax,%eax
call   1050 <getchar@plt>
mov    %eax,%ebp
cmp    0x0(%r13),%eax
je     1155 <main+0x25>
cmp    $0x4f,%ebx
jle    1180 <main+0x50>
cmp    $0x50,%ebx
jne    11d0 <main+0xa0>
movb   $0x0,0x50(%rsp)
mov    %r14,%rdi
mov    %r15,%rsi
call   1040 <printf@plt>
mov    %ebp,%edi
call   1030 <putchar@plt>
mov    $0x51,%ebx
jmp    118a <main+0x5a>
nopl   0x0(%rax,%rax,1)
mov    %ebp,%edi
call   1030 <putchar@plt>
jmp    118a <main+0x5a>

LLVM IR (-O0):
@EOF = global i32 0
@.str = [3 x i8] c"%s\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [81 x i8]
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %3
br label %5
5: ; preds = %43, %0
%6 = call i32 (...) @getchar()
store i32 %6, i32* %4
%7 = load i32, i32* @EOF
%8 = icmp ne i32 %6, %7
br i1 %8, label %9, label %44
9: ; preds = %5
%10 = load i32, i32* %3
%11 = icmp slt i32 %10, 80
br i1 %11, label %12, label %19
12: ; preds = %9
%13 = load i32, i32* %4
%14 = trunc i32 %13 to i8
%15 = load i32, i32* %3
%16 = add nsw i32 %15, 1
store i32 %16, i32* %3
%17 = sext i32 %15 to i64
%18 = getelementptr inbounds [81 x i8], [81 x i8]* %2, i64 0, i64 %17
store i8 %14, i8* %18
br label %39
19: ; preds = %9
%20 = load i32, i32* %3
%21 = icmp eq i32 %20, 80
br i1 %21, label %22, label %31
22: ; preds = %19
%23 = load i32, i32* %3
%24 = add nsw i32 %23, 1
store i32 %24, i32* %3
%25 = sext i32 %23 to i64
%26 = getelementptr inbounds [81 x i8], [81 x i8]* %2, i64 0, i64 %25
store i8 0, i8* %26
%27 = getelementptr inbounds [81 x i8], [81 x i8]* %2, i64 0, i64 0
%28 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %27)
%29 = load i32, i32* %4
%30 = call i32 @putchar(i32 %29)
br label %38
31: ; preds = %19
%32 = load i32, i32* %3
%33 = icmp sgt i32 %32, 80
br i1 %33, label %34, label %37
34: ; preds = %31
%35 = load i32, i32* %4
%36 = call i32 @putchar(i32 %35)
br label %37
37: ; preds = %34, %31
br label %38
38: ; preds = %37, %22
br label %39
39: ; preds = %38, %12
%40 = load i32, i32* %4
%41 = icmp eq i32 %40, 10
br i1 %41, label %42, label %43
42: ; preds = %39
store i32 0, i32* %3
br label %43
43: ; preds = %42, %39
br label %5
44: ; preds = %5
ret i32 0
}

LLVM IR (-O2):
@EOF = global i32 0
@.str = [3 x i8] c"%s\00"
define i32 @main() {
%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 %31, label %6
6: ; preds = %0
%7 = getelementptr inbounds [81 x i8], [81 x i8]* %1, i64 0, i64 80
br label %8
8: ; preds = %6, %24
%9 = phi i32 [ %3, %6 ], [ %28, %24 ]
%10 = phi i32 [ 0, %6 ], [ %27, %24 ]
%11 = icmp slt i32 %10, 80
br i1 %11, label %12, label %17
12: ; preds = %8
%13 = trunc i32 %9 to i8
%14 = add nsw i32 %10, 1
%15 = sext i32 %10 to i64
%16 = getelementptr inbounds [81 x i8], [81 x i8]* %1, i64 0, i64 %15
store i8 %13, i8* %16
br label %24
17: ; preds = %8
%18 = icmp eq i32 %10, 80
br i1 %18, label %19, label %22
19: ; preds = %17
store i8 0, i8* %7
%20 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %2)
%21 = call i32 @putchar(i32 %9)
br label %24
22: ; preds = %17
%23 = call i32 @putchar(i32 %9)
br label %24
24: ; preds = %19, %22, %12
%25 = phi i32 [ %14, %12 ], [ 81, %19 ], [ %10, %22 ]
%26 = icmp eq i32 %9, 10
%27 = select i1 %26, i32 0, i32 %25
%28 = call i32 (...) @getchar()
%29 = load i32, i32* @EOF
%30 = icmp eq i32 %28, %29
br i1 %30, label %31, label %8
31: ; preds = %24, %0
ret i32 0
}