#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();
scalar_t__ isspace(int);
int /*<<< orphan*/ putchar(int);
int main() {
  int space_buf[1000];
  int spaces = 0;
  int ch;
  while ((ch = getchar()) != EOF) {
    if (ch == '\n') {
      putchar(ch);
      spaces = 0;
    } else if (isspace(ch)) {
      space_buf[spaces++] = ch;
    } else {
      int i;
      for (i = 0; i < spaces; i++) {
        putchar(space_buf[i]);
      }
      spaces = 0;
      putchar(ch);
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xfc0,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0xfb4(%rbp)
mov    $0x0,%al
call   1050 <getchar@plt>
mov    %eax,-0xfb8(%rbp)
mov    0x2e88(%rip),%rcx
cmp    (%rcx),%eax
je     122b <main+0xfb>
cmpl   $0xa,-0xfb8(%rbp)
jne    118f <main+0x5f>
mov    -0xfb8(%rbp),%edi
call   1030 <putchar@plt>
movl   $0x0,-0xfb4(%rbp)
jmp    1226 <main+0xf6>
mov    -0xfb8(%rbp),%edi
call   1040 <isspace@plt>
cmp    $0x0,%rax
je     11c9 <main+0x99>
mov    -0xfb8(%rbp),%ecx
mov    -0xfb4(%rbp),%eax
mov    %eax,%edx
add    $0x1,%edx
mov    %edx,-0xfb4(%rbp)
cltq
mov    %ecx,-0xfb0(%rbp,%rax,4)
jmp    1221 <main+0xf1>
movl   $0x0,-0xfbc(%rbp)
mov    -0xfbc(%rbp),%eax
cmp    -0xfb4(%rbp),%eax
jge    120c <main+0xdc>
movslq -0xfbc(%rbp),%rax
mov    -0xfb0(%rbp,%rax,4),%edi
call   1030 <putchar@plt>
mov    -0xfbc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xfbc(%rbp)
jmp    11d3 <main+0xa3>
movl   $0x0,-0xfb4(%rbp)
mov    -0xfb8(%rbp),%edi
call   1030 <putchar@plt>
jmp    1226 <main+0xf6>
jmp    114c <main+0x1c>
xor    %eax,%eax
add    $0xfc0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0xfa8,%rsp
xor    %eax,%eax
call   1050 <getchar@plt>
mov    0x2e9d(%rip),%r14
cmp    (%r14),%eax
jne    1160 <main+0x30>
xor    %eax,%eax
add    $0xfa8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %eax,%r15d
xor    %ebp,%ebp
jmp    118b <main+0x5b>
nopw   0x0(%rax,%rax,1)
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %ebp,%ebp
xor    %eax,%eax
call   1050 <getchar@plt>
mov    %eax,%r15d
cmp    (%r14),%eax
je     1150 <main+0x20>
cmp    $0xa,%r15d
je     1170 <main+0x40>
mov    %r15d,%edi
call   1040 <isspace@plt>
test   %rax,%rax
je     11aa <main+0x7a>
movslq %ebp,%rax
add    $0x1,%ebp
mov    %r15d,(%rsp,%rax,4)
jmp    117c <main+0x4c>
test   %ebp,%ebp
jle    11d1 <main+0xa1>
mov    %ebp,%ebp
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    (%rsp,%rbx,4),%edi
call   1030 <putchar@plt>
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    11c0 <main+0x90>
mov    %r15d,%edi
jmp    1175 <main+0x45>

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

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