#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 count_num_spaces(int *);
int getchar();
int /*<<< orphan*/ putchar(int);
int main() {
  int current_char = EOF;
  int char_position = 0;
  while ((current_char = getchar()) != EOF) {
    if (current_char == ' ') {
      int num_spaces = count_num_spaces(&current_char);
      while (num_spaces >= 4) {
        num_spaces -= 4;
        putchar('\t');
        char_position += 4;
      }
      while (num_spaces > 0) {
        --num_spaces;
        putchar(' ');
        ++char_position;
      }
    }
    if (current_char == '\n') {
      char_position = 0;
      putchar('\n');
    }
    if (current_char != '\n' && current_char != ' ') {
      putchar(current_char);
      ++char_position;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2ea2(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    $0x0,%al
call   1050 <getchar@plt>
mov    %eax,-0x8(%rbp)
mov    0x2e85(%rip),%rcx
cmp    (%rcx),%eax
je     1226 <main+0xf6>
cmpl   $0x20,-0x8(%rbp)
jne    11e1 <main+0xb1>
lea    -0x8(%rbp),%rdi
call   1040 <count_num_spaces@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x4,-0x10(%rbp)
jl     11ac <main+0x7c>
mov    -0x10(%rbp),%eax
sub    $0x4,%eax
mov    %eax,-0x10(%rbp)
mov    $0x9,%edi
call   1030 <putchar@plt>
mov    -0xc(%rbp),%eax
add    $0x4,%eax
mov    %eax,-0xc(%rbp)
jmp    1181 <main+0x51>
jmp    11b1 <main+0x81>
cmpl   $0x0,-0x10(%rbp)
jle    11dc <main+0xac>
mov    -0x10(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x10(%rbp)
mov    $0x20,%edi
call   1030 <putchar@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    11b1 <main+0x81>
jmp    11e1 <main+0xb1>
cmpl   $0xa,-0x8(%rbp)
jne    11fc <main+0xcc>
movl   $0x0,-0xc(%rbp)
mov    $0xa,%edi
call   1030 <putchar@plt>
cmpl   $0xa,-0x8(%rbp)
je     1221 <main+0xf1>
cmpl   $0x20,-0x8(%rbp)
je     1221 <main+0xf1>
mov    -0x8(%rbp),%edi
call   1030 <putchar@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1152 <main+0x22>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
xor    %eax,%eax
call   1050 <getchar@plt>
mov    %eax,0x4(%rsp)
mov    0x2e9f(%rip),%r15
cmp    (%r15),%eax
jne    115b <main+0x2b>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0x4(%rsp),%r14
jmp    1180 <main+0x50>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
xor    %eax,%eax
call   1050 <getchar@plt>
mov    %eax,0x4(%rsp)
cmp    (%r15),%eax
je     114e <main+0x1e>
cmp    $0x20,%eax
je     11a0 <main+0x70>
cmp    $0xa,%eax
je     11eb <main+0xbb>
cmp    $0xa,%eax
jne    1202 <main+0xd2>
jmp    1170 <main+0x40>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
call   1040 <count_num_spaces@plt>
mov    %eax,%ebx
cmp    $0x4,%eax
jl     11c4 <main+0x94>
nop
lea    -0x4(%rbx),%ebp
mov    $0x9,%edi
call   1030 <putchar@plt>
cmp    $0x7,%ebx
mov    %ebp,%ebx
ja     11b0 <main+0x80>
test   %ebx,%ebx
jle    11e2 <main+0xb2>
add    $0x1,%ebx
nopl   0x0(%rax,%rax,1)
mov    $0x20,%edi
call   1030 <putchar@plt>
add    $0xffffffff,%ebx
cmp    $0x1,%ebx
ja     11d0 <main+0xa0>
mov    0x4(%rsp),%eax
cmp    $0xa,%eax
jne    118a <main+0x5a>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    0x4(%rsp),%eax
cmp    $0xa,%eax
je     1170 <main+0x40>
cmp    $0x20,%eax
je     1170 <main+0x40>
mov    %eax,%edi
call   1030 <putchar@plt>
jmp    1170 <main+0x40>

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

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