#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 *, int);
int /*<<< orphan*/ putchar(int);
int main() {
  int c, tmp, ts;
  int spaces = 0;
  int col = 0;
  printf("Just type. It'll wrap to %d characters per line.\n", 20);
  while ((c = getchar()) != EOF) {
    if (col >= 20) {
      putchar('\n');
      col = 0;
    }
    if (c == ' ') {
      if (col == 0) {
        continue;
      }
      spaces = 1;
      while ((tmp = getchar()) == ' ') {
        spaces++;
      }
      if (col + spaces < 20) {
        while (spaces > 0) {
          putchar(' ');
          col++;
          spaces--;
        }
      } else {
        putchar('\n');
        col = 0;
      }
      putchar(tmp);
      col++;
      continue;
    }
    if (c == '\t') {
      if (col == 0) {
        continue;
      }
      spaces = 1;
      while ((tmp = getchar()) == '\t') {
        spaces++;
      }
      ts = (spaces * 8) - (col % 8);
      if (col + ts < 20) {
        spaces = (spaces * 8) - (col % 8);
        while (spaces > 0) {
          putchar(' ');
          spaces--;
          col++;
        }
      } else {
        putchar('\n');
        col = 0;
      }
      putchar(tmp);
      col++;
      continue;
    }
    putchar(c);
    col++;
    if (c == '\n') {
      col = 0;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
lea    0xeac(%rip),%rdi
mov    $0x14,%esi
call   1040 <printf@plt>
mov    $0x0,%al
call   1050 <getchar@plt>
mov    %eax,-0x8(%rbp)
mov    0x2e79(%rip),%rcx
cmp    (%rcx),%eax
je     1344 <main+0x214>
cmpl   $0x14,-0x18(%rbp)
jl     1192 <main+0x62>
mov    $0xa,%edi
call   1030 <putchar@plt>
movl   $0x0,-0x18(%rbp)
cmpl   $0x20,-0x8(%rbp)
jne    123e <main+0x10e>
cmpl   $0x0,-0x18(%rbp)
jne    11ab <main+0x7b>
jmp    115e <main+0x2e>
movl   $0x1,-0x14(%rbp)
mov    $0x0,%al
call   1050 <getchar@plt>
mov    %eax,-0xc(%rbp)
cmp    $0x20,%eax
jne    11d3 <main+0xa3>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11b2 <main+0x82>
mov    -0x18(%rbp),%eax
add    -0x14(%rbp),%eax
cmp    $0x14,%eax
jge    1217 <main+0xe7>
jmp    11e7 <main+0xb7>
cmpl   $0x0,-0x14(%rbp)
jle    1212 <main+0xe2>
mov    $0x20,%edi
call   1030 <putchar@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
jmp    11e7 <main+0xb7>
jmp    1228 <main+0xf8>
mov    $0xa,%edi
call   1030 <putchar@plt>
movl   $0x0,-0x18(%rbp)
mov    -0xc(%rbp),%edi
call   1030 <putchar@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    115e <main+0x2e>
cmpl   $0x9,-0x8(%rbp)
jne    131d <main+0x1ed>
cmpl   $0x0,-0x18(%rbp)
jne    1257 <main+0x127>
jmp    115e <main+0x2e>
movl   $0x1,-0x14(%rbp)
mov    $0x0,%al
call   1050 <getchar@plt>
mov    %eax,-0xc(%rbp)
cmp    $0x9,%eax
jne    127f <main+0x14f>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    125e <main+0x12e>
mov    -0x14(%rbp),%eax
shl    $0x3,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
mov    -0x1c(%rbp),%eax
sub    %edx,%eax
mov    %eax,-0x10(%rbp)
mov    -0x18(%rbp),%eax
add    -0x10(%rbp),%eax
cmp    $0x14,%eax
jge    12f6 <main+0x1c6>
mov    -0x14(%rbp),%eax
shl    $0x3,%eax
mov    %eax,-0x20(%rbp)
mov    -0x18(%rbp),%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
mov    -0x20(%rbp),%eax
sub    %edx,%eax
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jle    12f1 <main+0x1c1>
mov    $0x20,%edi
call   1030 <putchar@plt>
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    12c6 <main+0x196>
jmp    1307 <main+0x1d7>
mov    $0xa,%edi
call   1030 <putchar@plt>
movl   $0x0,-0x18(%rbp)
mov    -0xc(%rbp),%edi
call   1030 <putchar@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    115e <main+0x2e>
mov    -0x8(%rbp),%edi
call   1030 <putchar@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
cmpl   $0xa,-0x8(%rbp)
jne    133f <main+0x20f>
movl   $0x0,-0x18(%rbp)
jmp    115e <main+0x2e>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0xebe(%rip),%rdi
mov    $0x14,%esi
call   1040 <printf@plt>
xor    %eax,%eax
call   1050 <getchar@plt>
mov    0x2e8e(%rip),%r15
cmp    (%r15),%eax
jne    1170 <main+0x40>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %eax,%ebx
xor    %r12d,%r12d
jmp    11a5 <main+0x75>
nopw   0x0(%rax,%rax,1)
mov    %ebx,%edi
call   1030 <putchar@plt>
add    $0x1,%r12d
cmp    $0xa,%ebx
mov    $0x0,%eax
cmove  %eax,%r12d
xor    %eax,%eax
call   1050 <getchar@plt>
mov    %eax,%ebx
cmp    (%r15),%eax
je     115f <main+0x2f>
cmp    $0x14,%r12d
jl     11b8 <main+0x88>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %r12d,%r12d
cmp    $0x9,%ebx
je     1230 <main+0x100>
cmp    $0x20,%ebx
jne    1180 <main+0x50>
test   %r12d,%r12d
je     12b0 <main+0x180>
xor    %ebx,%ebx
mov    $0x2,%eax
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %eax,%ebp
xor    %eax,%eax
call   1050 <getchar@plt>
mov    %eax,%r14d
add    $0x1,%ebx
lea    0x1(%rbp),%eax
cmp    $0x20,%r14d
je     11e0 <main+0xb0>
add    %ebx,%r12d
cmp    $0x13,%r12d
jg     12b8 <main+0x188>
cs nopw 0x0(%rax,%rax,1)
nop
mov    $0x20,%edi
call   1030 <putchar@plt>
add    $0xffffffff,%ebp
cmp    $0x1,%ebp
jg     1210 <main+0xe0>
jmp    12c5 <main+0x195>
nopw   0x0(%rax,%rax,1)
test   %r12d,%r12d
je     12b0 <main+0x180>
xor    %ebx,%ebx
mov    $0x9,%eax
nopl   0x0(%rax)
mov    %eax,%ebp
xor    %eax,%eax
call   1050 <getchar@plt>
mov    %eax,%r13d
add    $0x8,%ebx
lea    0x8(%rbp),%eax
cmp    $0x9,%r13d
je     1240 <main+0x110>
lea    0x7(%r12),%eax
test   %r12d,%r12d
cmovns %r12d,%eax
and    $0xfffffff8,%eax
lea    (%rax,%rbx,1),%r14d
cmp    $0x13,%r14d
jg     12d6 <main+0x1a6>
mov    %r12d,%r15d
sub    %eax,%r15d
sub    %r15d,%ebx
test   %ebx,%ebx
jle    12e3 <main+0x1b3>
neg    %r15d
add    %ebp,%r15d
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    $0x20,%edi
call   1030 <putchar@plt>
add    $0xffffffff,%r15d
cmp    $0x1,%r15d
ja     1290 <main+0x160>
mov    %r14d,%r12d
jmp    12e3 <main+0x1b3>
nopl   0x0(%rax)
xor    %r12d,%r12d
jmp    1197 <main+0x67>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %r12d,%r12d
mov    %r14d,%edi
call   1030 <putchar@plt>
add    $0x1,%r12d
jmp    1197 <main+0x67>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %r12d,%r12d
mov    %r13d,%edi
call   1030 <putchar@plt>
add    $0x1,%r12d
mov    0x2cf2(%rip),%r15
jmp    1197 <main+0x67>

LLVM IR (-O0):
@.str = [50 x i8] c"Just type. It'll wrap to %d characters per line.\0A\00"
@EOF = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %5
store i32 0, i32* %6
%7 = call i32 @printf(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str, i64 0, i64 0), i32 20)
br label %8
8: ; preds = %109, %96, %60, %49, %23, %0
%9 = call i32 (...) @getchar()
store i32 %9, i32* %2
%10 = load i32, i32* @EOF
%11 = icmp ne i32 %9, %10
br i1 %11, label %12, label %110
12: ; preds = %8
%13 = load i32, i32* %6
%14 = icmp sge i32 %13, 20
br i1 %14, label %15, label %17
15: ; preds = %12
%16 = call i32 @putchar(i32 10)
store i32 0, i32* %6
br label %17
17: ; preds = %15, %12
%18 = load i32, i32* %2
%19 = icmp eq i32 %18, 32
br i1 %19, label %20, label %54
20: ; preds = %17
%21 = load i32, i32* %6
%22 = icmp eq i32 %21, 0
br i1 %22, label %23, label %24
23: ; preds = %20
br label %8
24: ; preds = %20
store i32 1, i32* %5
br label %25
25: ; preds = %28, %24
%26 = call i32 (...) @getchar()
store i32 %26, i32* %3
%27 = icmp eq i32 %26, 32
br i1 %27, label %28, label %31
28: ; preds = %25
%29 = load i32, i32* %5
%30 = add nsw i32 %29, 1
store i32 %30, i32* %5
br label %25
31: ; preds = %25
%32 = load i32, i32* %6
%33 = load i32, i32* %5
%34 = add nsw i32 %32, %33
%35 = icmp slt i32 %34, 20
br i1 %35, label %36, label %47
36: ; preds = %31
br label %37
37: ; preds = %40, %36
%38 = load i32, i32* %5
%39 = icmp sgt i32 %38, 0
br i1 %39, label %40, label %46
40: ; preds = %37
%41 = call i32 @putchar(i32 32)
%42 = load i32, i32* %6
%43 = add nsw i32 %42, 1
store i32 %43, i32* %6
%44 = load i32, i32* %5
%45 = add nsw i32 %44, -1
store i32 %45, i32* %5
br label %37
46: ; preds = %37
br label %49
47: ; preds = %31
%48 = call i32 @putchar(i32 10)
store i32 0, i32* %6
br label %49
49: ; preds = %47, %46
%50 = load i32, i32* %3
%51 = call i32 @putchar(i32 %50)
%52 = load i32, i32* %6
%53 = add nsw i32 %52, 1
store i32 %53, i32* %6
br label %8
54: ; preds = %17
%55 = load i32, i32* %2
%56 = icmp eq i32 %55, 9
br i1 %56, label %57, label %101
57: ; preds = %54
%58 = load i32, i32* %6
%59 = icmp eq i32 %58, 0
br i1 %59, label %60, label %61
60: ; preds = %57
br label %8
61: ; preds = %57
store i32 1, i32* %5
br label %62
62: ; preds = %65, %61
%63 = call i32 (...) @getchar()
store i32 %63, i32* %3
%64 = icmp eq i32 %63, 9
br i1 %64, label %65, label %68
65: ; preds = %62
%66 = load i32, i32* %5
%67 = add nsw i32 %66, 1
store i32 %67, i32* %5
br label %62
68: ; preds = %62
%69 = load i32, i32* %5
%70 = mul nsw i32 %69, 8
%71 = load i32, i32* %6
%72 = srem i32 %71, 8
%73 = sub nsw i32 %70, %72
store i32 %73, i32* %4
%74 = load i32, i32* %6
%75 = load i32, i32* %4
%76 = add nsw i32 %74, %75
%77 = icmp slt i32 %76, 20
br i1 %77, label %78, label %94
78: ; preds = %68
%79 = load i32, i32* %5
%80 = mul nsw i32 %79, 8
%81 = load i32, i32* %6
%82 = srem i32 %81, 8
%83 = sub nsw i32 %80, %82
store i32 %83, i32* %5
br label %84
84: ; preds = %87, %78
%85 = load i32, i32* %5
%86 = icmp sgt i32 %85, 0
br i1 %86, label %87, label %93
87: ; preds = %84
%88 = call i32 @putchar(i32 32)
%89 = load i32, i32* %5
%90 = add nsw i32 %89, -1
store i32 %90, i32* %5
%91 = load i32, i32* %6
%92 = add nsw i32 %91, 1
store i32 %92, i32* %6
br label %84
93: ; preds = %84
br label %96
94: ; preds = %68
%95 = call i32 @putchar(i32 10)
store i32 0, i32* %6
br label %96
96: ; preds = %94, %93
%97 = load i32, i32* %3
%98 = call i32 @putchar(i32 %97)
%99 = load i32, i32* %6
%100 = add nsw i32 %99, 1
store i32 %100, i32* %6
br label %8
101: ; preds = %54
%102 = load i32, i32* %2
%103 = call i32 @putchar(i32 %102)
%104 = load i32, i32* %6
%105 = add nsw i32 %104, 1
store i32 %105, i32* %6
%106 = load i32, i32* %2
%107 = icmp eq i32 %106, 10
br i1 %107, label %108, label %109
108: ; preds = %101
store i32 0, i32* %6
br label %109
109: ; preds = %108, %101
br label %8
110: ; preds = %8
ret i32 0
}

LLVM IR (-O2):
@.str = [50 x i8] c"Just type. It'll wrap to %d characters per line.\0A\00"
@EOF = global i32 0
define i32 @main() {
%1 = tail call i32 @printf(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str, i64 0, i64 0), i32 20)
%2 = tail call i32 (...) @getchar()
%3 = load i32, i32* @EOF
%4 = icmp eq i32 %2, %3
br i1 %4, label %70, label %5
5: ; preds = %0, %34
%6 = phi i32 [ %36, %34 ], [ %2, %0 ]
%7 = phi i32 [ %35, %34 ], [ 0, %0 ]
%8 = icmp sgt i32 %7, 19
br i1 %8, label %9, label %11
9: ; preds = %5
%10 = tail call i32 @putchar(i32 10)
br label %11
11: ; preds = %9, %5
%12 = phi i32 [ 0, %9 ], [ %7, %5 ]
switch i32 %6, label %65 [
i32 32, label %13
i32 9, label %39
]
13: ; preds = %11
%14 = icmp eq i32 %12, 0
br i1 %14, label %34, label %15
15: ; preds = %13, %15
%16 = phi i32 [ %19, %15 ], [ 1, %13 ]
%17 = tail call i32 (...) @getchar()
%18 = icmp eq i32 %17, 32
%19 = add nuw nsw i32 %16, 1
br i1 %18, label %15, label %20
20: ; preds = %15
%21 = add i32 %16, %12
%22 = icmp slt i32 %21, 20
br i1 %22, label %23, label %28
23: ; preds = %20, %23
%24 = phi i32 [ %26, %23 ], [ %16, %20 ]
%25 = tail call i32 @putchar(i32 32)
%26 = add nsw i32 %24, -1
%27 = icmp sgt i32 %24, 1
br i1 %27, label %23, label %30
28: ; preds = %20
%29 = tail call i32 @putchar(i32 10)
br label %30
30: ; preds = %23, %28
%31 = phi i32 [ 0, %28 ], [ %21, %23 ]
%32 = tail call i32 @putchar(i32 %17)
%33 = add nsw i32 %31, 1
br label %34
34: ; preds = %30, %61, %65, %13, %39
%35 = phi i32 [ 0, %13 ], [ %33, %30 ], [ 0, %39 ], [ %64, %61 ], [ %69, %65 ]
%36 = tail call i32 (...) @getchar()
%37 = load i32, i32* @EOF
%38 = icmp eq i32 %36, %37
br i1 %38, label %70, label %5
39: ; preds = %11
%40 = icmp eq i32 %12, 0
br i1 %40, label %34, label %41
41: ; preds = %39, %41
%42 = phi i32 [ %45, %41 ], [ 1, %39 ]
%43 = tail call i32 (...) @getchar()
%44 = icmp eq i32 %43, 9
%45 = add nuw nsw i32 %42, 1
br i1 %44, label %41, label %46
46: ; preds = %41
%47 = shl nsw i32 %42, 3
%48 = srem i32 %12, 8
%49 = sub nsw i32 %47, %48
%50 = add i32 %49, %12
%51 = icmp slt i32 %50, 20
br i1 %51, label %52, label %59
52: ; preds = %46
%53 = icmp sgt i32 %49, 0
br i1 %53, label %54, label %61
54: ; preds = %52, %54
%55 = phi i32 [ %57, %54 ], [ %49, %52 ]
%56 = tail call i32 @putchar(i32 32)
%57 = add nsw i32 %55, -1
%58 = icmp ugt i32 %55, 1
br i1 %58, label %54, label %61
59: ; preds = %46
%60 = tail call i32 @putchar(i32 10)
br label %61
61: ; preds = %54, %52, %59
%62 = phi i32 [ 0, %59 ], [ %12, %52 ], [ %50, %54 ]
%63 = tail call i32 @putchar(i32 %43)
%64 = add nsw i32 %62, 1
br label %34
65: ; preds = %11
%66 = tail call i32 @putchar(i32 %6)
%67 = add nsw i32 %12, 1
%68 = icmp eq i32 %6, 10
%69 = select i1 %68, i32 0, i32 %67
br label %34
70: ; preds = %34, %0
ret i32 0
}