#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 */
typedef int uint32_t;
typedef char int32_t;

/* Variables and functions */
char EOF;
int EXIT_SUCCESS;
char getchar();
int /*<<< orphan*/ putchar(char);
int main(void) {
  uint32_t current_line_length = 0;
  int32_t buffer[80] = {0};
  bool buffer_in_use = true;
  int32_t character = 0;
  while ((character = getchar()) != EOF) {
    if (character == '\n') {
      if (current_line_length > 80) {
        putchar('\n');
      }
      current_line_length = 0;
      buffer_in_use = true;
    } else {
      current_line_length++;
      if (current_line_length <= 80) {
        buffer[current_line_length - 1] = character;
      } else {
        if (buffer_in_use == true) {
          uint32_t i;
          for (i = 0; i < 80; ++i) {
            putchar(buffer[i]);
          }
          buffer_in_use = false;
        }
        putchar(character);
      }
    }
  }
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
lea    -0x60(%rbp),%rdi
xor    %esi,%esi
mov    $0x50,%edx
call   1040 <memset@plt>
movl   $0x1,-0x64(%rbp)
movb   $0x0,-0x65(%rbp)
mov    $0x0,%al
call   1050 <getchar@plt>
mov    %al,-0x65(%rbp)
movsbl %al,%eax
mov    0x2e73(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     122c <main+0xfc>
movsbl -0x65(%rbp),%eax
cmp    $0xa,%eax
jne    11b4 <main+0x84>
cmpl   $0x50,-0x8(%rbp)
jle    11a1 <main+0x71>
mov    $0xa,%edi
call   1030 <putchar@plt>
movl   $0x0,-0x8(%rbp)
movl   $0x1,-0x64(%rbp)
jmp    1227 <main+0xf7>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
cmpl   $0x50,-0x8(%rbp)
jg     11db <main+0xab>
mov    -0x65(%rbp),%cl
mov    -0x8(%rbp),%eax
sub    $0x1,%eax
cltq
mov    %cl,-0x60(%rbp,%rax,1)
jmp    1222 <main+0xf2>
cmpl   $0x1,-0x64(%rbp)
jne    1219 <main+0xe9>
movl   $0x0,-0x6c(%rbp)
cmpl   $0x50,-0x6c(%rbp)
jge    1212 <main+0xe2>
movslq -0x6c(%rbp),%rax
movsbl -0x60(%rbp,%rax,1),%edi
call   1030 <putchar@plt>
mov    -0x6c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x6c(%rbp)
jmp    11ec <main+0xbc>
movl   $0x0,-0x64(%rbp)
movsbl -0x65(%rbp),%edi
call   1030 <putchar@plt>
jmp    1227 <main+0xf7>
jmp    1161 <main+0x31>
mov    0x2da5(%rip),%rax
mov    (%rax),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x50,%rsp
xorps  %xmm0,%xmm0
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
movaps %xmm0,(%rsp)
xor    %eax,%eax
call   1040 <getchar@plt>
mov    0x2e93(%rip),%r14
cmp    (%r14),%al
jne    1170 <main+0x50>
mov    0x2e77(%rip),%rax
mov    (%rax),%eax
add    $0x50,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %eax,%ebx
mov    $0x1,%r15d
xor    %eax,%eax
jmp    119c <main+0x7c>
nopl   0x0(%rax)
movsbl %bl,%edi
call   1030 <putchar@plt>
xor    %r15d,%r15d
xor    %eax,%eax
call   1040 <getchar@plt>
mov    %eax,%ebx
mov    %r12d,%eax
cmp    (%r14),%bl
je     115a <main+0x3a>
cmp    $0xa,%bl
jne    11c0 <main+0xa0>
mov    $0x1,%r15d
xor    %r12d,%r12d
cmp    $0x51,%eax
jl     118b <main+0x6b>
mov    $0xa,%edi
call   1030 <putchar@plt>
jmp    118b <main+0x6b>
nopl   0x0(%rax,%rax,1)
lea    0x1(%rax),%r12d
cmp    $0x4f,%eax
jg     11d0 <main+0xb0>
cltq
mov    %bl,(%rsp,%rax,1)
jmp    118b <main+0x6b>
cmp    $0x1,%r15d
jne    1180 <main+0x60>
xor    %ebp,%ebp
nopl   0x0(%rax,%rax,1)
movsbl (%rsp,%rbp,1),%edi
call   1030 <putchar@plt>
add    $0x1,%rbp
cmp    $0x50,%rbp
jne    11e0 <main+0xc0>
jmp    1180 <main+0x60>

LLVM IR (-O0):
@EOF = global i8 0
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [80 x i8]
%4 = alloca i32
%5 = alloca i8
%6 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %2
%7 = bitcast [80 x i8]* %3 to i8*
store i32 1, i32* %4
store i8 0, i8* %5
br label %8
8: ; preds = %56, %0
%9 = call signext i8 (...) @getchar()
store i8 %9, i8* %5
%10 = sext i8 %9 to i32
%11 = load i8, i8* @EOF
%12 = sext i8 %11 to i32
%13 = icmp ne i32 %10, %12
br i1 %13, label %14, label %57
14: ; preds = %8
%15 = load i8, i8* %5
%16 = sext i8 %15 to i32
%17 = icmp eq i32 %16, 10
br i1 %17, label %18, label %24
18: ; preds = %14
%19 = load i32, i32* %2
%20 = icmp sgt i32 %19, 80
br i1 %20, label %21, label %23
21: ; preds = %18
%22 = call i32 @putchar(i8 signext 10)
br label %23
23: ; preds = %21, %18
store i32 0, i32* %2
store i32 1, i32* %4
br label %56
24: ; preds = %14
%25 = load i32, i32* %2
%26 = add nsw i32 %25, 1
store i32 %26, i32* %2
%27 = load i32, i32* %2
%28 = icmp sle i32 %27, 80
br i1 %28, label %29, label %35
29: ; preds = %24
%30 = load i8, i8* %5
%31 = load i32, i32* %2
%32 = sub nsw i32 %31, 1
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 %33
store i8 %30, i8* %34
br label %55
35: ; preds = %24
%36 = load i32, i32* %4
%37 = icmp eq i32 %36, 1
br i1 %37, label %38, label %52
38: ; preds = %35
store i32 0, i32* %6
br label %39
39: ; preds = %48, %38
%40 = load i32, i32* %6
%41 = icmp slt i32 %40, 80
br i1 %41, label %42, label %51
42: ; preds = %39
%43 = load i32, i32* %6
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 %44
%46 = load i8, i8* %45
%47 = call i32 @putchar(i8 signext %46)
br label %48
48: ; preds = %42
%49 = load i32, i32* %6
%50 = add nsw i32 %49, 1
store i32 %50, i32* %6
br label %39
51: ; preds = %39
store i32 0, i32* %4
br label %52
52: ; preds = %51, %35
%53 = load i8, i8* %5
%54 = call i32 @putchar(i8 signext %53)
br label %55
55: ; preds = %52, %29
br label %56
56: ; preds = %55, %23
br label %8
57: ; preds = %8
%58 = load i32, i32* @EXIT_SUCCESS
ret i32 %58
}

LLVM IR (-O2):
@EOF = global i8 0
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca [80 x i8]
%2 = getelementptr inbounds [80 x i8], [80 x i8]* %1, i64 0, i64 0
%3 = tail call signext i8 (...) @getchar()
%4 = load i8, i8* @EOF
%5 = icmp eq i8 %3, %4
br i1 %5, label %38, label %6
6: ; preds = %0, %32
%7 = phi i8 [ %35, %32 ], [ %3, %0 ]
%8 = phi i32 [ %34, %32 ], [ 1, %0 ]
%9 = phi i32 [ %33, %32 ], [ 0, %0 ]
%10 = icmp eq i8 %7, 10
br i1 %10, label %11, label %15
11: ; preds = %6
%12 = icmp sgt i32 %9, 80
br i1 %12, label %13, label %32
13: ; preds = %11
%14 = tail call i32 @putchar(i8 signext 10)
br label %32
15: ; preds = %6
%16 = add nsw i32 %9, 1
%17 = icmp slt i32 %9, 80
br i1 %17, label %18, label %21
18: ; preds = %15
%19 = sext i32 %9 to i64
%20 = getelementptr inbounds [80 x i8], [80 x i8]* %1, i64 0, i64 %19
store i8 %7, i8* %20
br label %32
21: ; preds = %15
%22 = icmp eq i32 %8, 1
br i1 %22, label %23, label %30
23: ; preds = %21, %23
%24 = phi i64 [ %28, %23 ], [ 0, %21 ]
%25 = getelementptr inbounds [80 x i8], [80 x i8]* %1, i64 0, i64 %24
%26 = load i8, i8* %25
%27 = tail call i32 @putchar(i8 signext %26)
%28 = add nuw nsw i64 %24, 1
%29 = icmp eq i64 %28, 80
br i1 %29, label %30, label %23
30: ; preds = %23, %21
%31 = tail call i32 @putchar(i8 signext %7)
br label %32
32: ; preds = %11, %13, %18, %30
%33 = phi i32 [ %16, %18 ], [ %16, %30 ], [ 0, %13 ], [ 0, %11 ]
%34 = phi i32 [ %8, %18 ], [ 0, %30 ], [ 1, %13 ], [ 1, %11 ]
%35 = tail call signext i8 (...) @getchar()
%36 = load i8, i8* @EOF
%37 = icmp eq i8 %35, %36
br i1 %37, label %38, label %6
38: ; preds = %32, %0
%39 = load i32, i32* @EXIT_SUCCESS
ret i32 %39
}