#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*/ putchar(int);
void folder(int tabwidth, int linewidth) {
  int count = 0;
  int character;
  while ((character = getchar()) != EOF) {
    if (character == '\n') {
      count = 0;
      putchar(character);
    } else if (character == '\t') {
      count += tabwidth;
      if (count > linewidth) {
        putchar('\n');
        count = tabwidth;
      }
      putchar(character);
    } else {
      count++;
      if (count >= linewidth) {
        putchar('\n');
        count = 1;
      }
      putchar(character);
    }
  }
}


x86 assembly (clang, -O0):
<folder>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    $0x0,%al
call   1040 <getchar@plt>
mov    %eax,-0x10(%rbp)
mov    0x2ea2(%rip),%rcx
cmp    (%rcx),%eax
je     11e0 <folder+0xc0>
cmpl   $0xa,-0x10(%rbp)
jne    116c <folder+0x4c>
movl   $0x0,-0xc(%rbp)
mov    -0x10(%rbp),%edi
call   1030 <putchar@plt>
jmp    11db <folder+0xbb>
cmpl   $0x9,-0x10(%rbp)
jne    11a8 <folder+0x88>
mov    -0x4(%rbp),%eax
add    -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jle    119b <folder+0x7b>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    -0x4(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x10(%rbp),%edi
call   1030 <putchar@plt>
jmp    11d6 <folder+0xb6>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jl     11ce <folder+0xae>
mov    $0xa,%edi
call   1030 <putchar@plt>
movl   $0x1,-0xc(%rbp)
mov    -0x10(%rbp),%edi
call   1030 <putchar@plt>
jmp    11db <folder+0xbb>
jmp    1135 <folder+0x15>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<folder>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %esi,%r14d
mov    %edi,%r12d
xor    %eax,%eax
call   1040 <getchar@plt>
mov    0x2ea9(%rip),%r15
cmp    (%r15),%eax
jne    1153 <folder+0x33>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %eax,%ebx
xor    %ebp,%ebp
jmp    1177 <folder+0x57>
nopl   0x0(%rax)
xor    %ebp,%ebp
mov    %ebx,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
call   1040 <getchar@plt>
mov    %eax,%ebx
cmp    (%r15),%eax
je     1144 <folder+0x24>
cmp    $0xa,%ebx
je     1160 <folder+0x40>
cmp    $0x9,%ebx
jne    11a0 <folder+0x80>
add    %r12d,%ebp
mov    $0x9,%ebx
mov    %r12d,%r13d
cmp    %r14d,%ebp
jle    1162 <folder+0x42>
jmp    11ae <folder+0x8e>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
add    $0x1,%ebp
mov    $0x1,%r13d
cmp    %r14d,%ebp
jl     1162 <folder+0x42>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %r13d,%ebp
jmp    1162 <folder+0x42>

LLVM IR (-O0):
@EOF = global i32 0
define void @folder(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
store i32 0, i32* %5
br label %7
7: ; preds = %45, %2
%8 = call i32 (...) @getchar()
store i32 %8, i32* %6
%9 = load i32, i32* @EOF
%10 = icmp ne i32 %8, %9
br i1 %10, label %11, label %46
11: ; preds = %7
%12 = load i32, i32* %6
%13 = icmp eq i32 %12, 10
br i1 %13, label %14, label %17
14: ; preds = %11
store i32 0, i32* %5
%15 = load i32, i32* %6
%16 = call i32 @putchar(i32 %15)
br label %45
17: ; preds = %11
%18 = load i32, i32* %6
%19 = icmp eq i32 %18, 9
br i1 %19, label %20, label %33
20: ; preds = %17
%21 = load i32, i32* %3
%22 = load i32, i32* %5
%23 = add nsw i32 %22, %21
store i32 %23, i32* %5
%24 = load i32, i32* %5
%25 = load i32, i32* %4
%26 = icmp sgt i32 %24, %25
br i1 %26, label %27, label %30
27: ; preds = %20
%28 = call i32 @putchar(i32 10)
%29 = load i32, i32* %3
store i32 %29, i32* %5
br label %30
30: ; preds = %27, %20
%31 = load i32, i32* %6
%32 = call i32 @putchar(i32 %31)
br label %44
33: ; preds = %17
%34 = load i32, i32* %5
%35 = add nsw i32 %34, 1
store i32 %35, i32* %5
%36 = load i32, i32* %5
%37 = load i32, i32* %4
%38 = icmp sge i32 %36, %37
br i1 %38, label %39, label %41
39: ; preds = %33
%40 = call i32 @putchar(i32 10)
store i32 1, i32* %5
br label %41
41: ; preds = %39, %33
%42 = load i32, i32* %6
%43 = call i32 @putchar(i32 %42)
br label %44
44: ; preds = %41, %30
br label %45
45: ; preds = %44, %14
br label %7
46: ; preds = %7
ret void
}

LLVM IR (-O2):
@EOF = global i32 0
define void @folder(i32 %0, i32 %1) {
%3 = tail call i32 (...) @getchar()
%4 = load i32, i32* @EOF
%5 = icmp eq i32 %3, %4
br i1 %5, label %26, label %6
6: ; preds = %2, %19
%7 = phi i32 [ %23, %19 ], [ %3, %2 ]
%8 = phi i32 [ %21, %19 ], [ 0, %2 ]
switch i32 %7, label %12 [
i32 10, label %19
i32 9, label %9
]
9: ; preds = %6
%10 = add nsw i32 %8, %0
%11 = icmp sgt i32 %10, %1
br i1 %11, label %15, label %19
12: ; preds = %6
%13 = add nsw i32 %8, 1
%14 = icmp slt i32 %13, %1
br i1 %14, label %19, label %15
15: ; preds = %12, %9
%16 = phi i32 [ 9, %9 ], [ %7, %12 ]
%17 = phi i32 [ %0, %9 ], [ 1, %12 ]
%18 = tail call i32 @putchar(i32 10)
br label %19
19: ; preds = %15, %12, %9, %6
%20 = phi i32 [ %7, %6 ], [ 9, %9 ], [ %7, %12 ], [ %16, %15 ]
%21 = phi i32 [ 0, %6 ], [ %10, %9 ], [ %13, %12 ], [ %17, %15 ]
%22 = tail call i32 @putchar(i32 %20)
%23 = tail call i32 (...) @getchar()
%24 = load i32, i32* @EOF
%25 = icmp eq i32 %23, %24
br i1 %25, label %26, label %6
26: ; preds = %19, %2
ret void
}