#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 /*<<< orphan*/ putchar(int);
int main() {
  int c, state;
  char blank;
  blank = ' ';
  state = 1;
  while ((c = getchar()) != EOF) {
    if (c != blank) {
      if (state == 0) {
        putchar(blank);
      }
      state = 1;
      putchar(c);
    } else {
      state = 0;
    }
  }
  printf("You signaled exit with EOF or CTRL+D\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
movb   $0x20,-0xd(%rbp)
movl   $0x1,-0xc(%rbp)
mov    $0x0,%al
call   1050 <getchar@plt>
mov    %eax,-0x8(%rbp)
mov    0x2e8d(%rip),%rcx
cmp    (%rcx),%eax
je     11a5 <main+0x75>
mov    -0x8(%rbp),%eax
movsbl -0xd(%rbp),%ecx
cmp    %ecx,%eax
je     1199 <main+0x69>
cmpl   $0x0,-0xc(%rbp)
jne    1185 <main+0x55>
movsbl -0xd(%rbp),%edi
call   1030 <putchar@plt>
movl   $0x1,-0xc(%rbp)
mov    -0x8(%rbp),%edi
call   1030 <putchar@plt>
jmp    11a0 <main+0x70>
movl   $0x0,-0xc(%rbp)
jmp    114a <main+0x1a>
lea    0xe54(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
xor    %eax,%eax
call   1050 <getchar@plt>
mov    0x2ea6(%rip),%r14
cmp    (%r14),%eax
jne    115a <main+0x2a>
lea    0xeb2(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    %eax,%ebx
mov    $0x1,%eax
jmp    118c <main+0x5c>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %ebx,%edi
call   1030 <putchar@plt>
mov    $0x1,%ebp
xor    %eax,%eax
call   1050 <getchar@plt>
mov    %eax,%ebx
mov    %ebp,%eax
cmp    (%r14),%ebx
je     1147 <main+0x17>
mov    $0x0,%ebp
cmp    $0x20,%ebx
je     117c <main+0x4c>
test   %eax,%eax
jne    1170 <main+0x40>
mov    $0x20,%edi
call   1030 <putchar@plt>
jmp    1170 <main+0x40>

LLVM IR (-O0):
@EOF = global i32 0
@.str = [38 x i8] c"You signaled exit with EOF or CTRL+D\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i8
store i32 0, i32* %1
store i8 32, i8* %4
store i32 1, i32* %3
br label %5
5: ; preds = %25, %0
%6 = call i32 (...) @getchar()
store i32 %6, i32* %2
%7 = load i32, i32* @EOF
%8 = icmp ne i32 %6, %7
br i1 %8, label %9, label %26
9: ; preds = %5
%10 = load i32, i32* %2
%11 = load i8, i8* %4
%12 = sext i8 %11 to i32
%13 = icmp ne i32 %10, %12
br i1 %13, label %14, label %24
14: ; preds = %9
%15 = load i32, i32* %3
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %21
17: ; preds = %14
%18 = load i8, i8* %4
%19 = sext i8 %18 to i32
%20 = call i32 @putchar(i32 %19)
br label %21
21: ; preds = %17, %14
store i32 1, i32* %3
%22 = load i32, i32* %2
%23 = call i32 @putchar(i32 %22)
br label %25
24: ; preds = %9
store i32 0, i32* %3
br label %25
25: ; preds = %24, %21
br label %5
26: ; preds = %5
%27 = call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@EOF = global i32 0
@str = [37 x i8] c"You signaled exit with EOF or CTRL+D\00"
define i32 @main() {
%1 = tail call i32 (...) @getchar()
%2 = load i32, i32* @EOF
%3 = icmp eq i32 %1, %2
br i1 %3, label %19, label %4
4: ; preds = %0, %14
%5 = phi i32 [ %16, %14 ], [ %1, %0 ]
%6 = phi i32 [ %15, %14 ], [ 1, %0 ]
%7 = icmp eq i32 %5, 32
br i1 %7, label %14, label %8
8: ; preds = %4
%9 = icmp eq i32 %6, 0
br i1 %9, label %10, label %12
10: ; preds = %8
%11 = tail call i32 @putchar(i32 32)
br label %12
12: ; preds = %10, %8
%13 = tail call i32 @putchar(i32 %5)
br label %14
14: ; preds = %4, %12
%15 = phi i32 [ 1, %12 ], [ 0, %4 ]
%16 = tail call i32 (...) @getchar()
%17 = load i32, i32* @EOF
%18 = icmp eq i32 %16, %17
br i1 %18, label %19, label %4
19: ; preds = %14, %0
%20 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @str, i64 0, i64 0))
ret i32 0
}