#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 fun2() {
  int ch;
  int flag = 0;
  while ((ch = getchar()) != EOF) {
    if (ch == ' ') {
      if (flag == 0) {
        putchar('\n');
      }
      flag = 1;
    } else {
      putchar(ch);
      flag = 0;
    }
  }
}


x86 assembly (clang, -O0):
<fun2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x8(%rbp)
mov    $0x0,%al
call   1040 <getchar@plt>
mov    %eax,-0x4(%rbp)
mov    0x2ea8(%rip),%rcx
cmp    (%rcx),%eax
je     1186 <fun2+0x66>
cmpl   $0x20,-0x4(%rbp)
jne    1172 <fun2+0x52>
cmpl   $0x0,-0x8(%rbp)
jne    1166 <fun2+0x46>
mov    $0xa,%edi
call   1030 <putchar@plt>
movl   $0x1,-0x8(%rbp)
jmp    1181 <fun2+0x61>
mov    -0x4(%rbp),%edi
call   1030 <putchar@plt>
movl   $0x0,-0x8(%rbp)
jmp    112f <fun2+0xf>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fun2>:
push   %rbp
push   %rbx
push   %rax
xor    %eax,%eax
call   1040 <getchar@plt>
mov    0x2eb7(%rip),%rbx
cmp    (%rbx),%eax
jne    113c <fun2+0x1c>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
xor    %ecx,%ecx
jmp    1154 <fun2+0x34>
mov    %eax,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
call   1040 <getchar@plt>
mov    %ebp,%ecx
cmp    (%rbx),%eax
je     1135 <fun2+0x15>
xor    %ebp,%ebp
cmp    $0x20,%eax
jne    1140 <fun2+0x20>
mov    $0x1,%ebp
test   %ecx,%ecx
jne    1147 <fun2+0x27>
mov    $0xa,%eax
jmp    1140 <fun2+0x20>

LLVM IR (-O0):
@EOF = global i32 0
define void @fun2() {
%1 = alloca i32
%2 = alloca i32
store i32 0, i32* %2
br label %3
3: ; preds = %19, %0
%4 = call i32 (...) @getchar()
store i32 %4, i32* %1
%5 = load i32, i32* @EOF
%6 = icmp ne i32 %4, %5
br i1 %6, label %7, label %20
7: ; preds = %3
%8 = load i32, i32* %1
%9 = icmp eq i32 %8, 32
br i1 %9, label %10, label %16
10: ; preds = %7
%11 = load i32, i32* %2
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %10
%14 = call i32 @putchar(i32 10)
br label %15
15: ; preds = %13, %10
store i32 1, i32* %2
br label %19
16: ; preds = %7
%17 = load i32, i32* %1
%18 = call i32 @putchar(i32 %17)
store i32 0, i32* %2
br label %19
19: ; preds = %16, %15
br label %3
20: ; preds = %3
ret void
}

LLVM IR (-O2):
@EOF = global i32 0
define void @fun2() {
%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 ], [ 0, %0 ]
%7 = icmp eq i32 %5, 32
br i1 %7, label %8, label %10
8: ; preds = %4
%9 = icmp eq i32 %6, 0
br i1 %9, label %10, label %14
10: ; preds = %4, %8
%11 = phi i32 [ 10, %8 ], [ %5, %4 ]
%12 = phi i32 [ 1, %8 ], [ 0, %4 ]
%13 = tail call i32 @putchar(i32 %11)
br label %14
14: ; preds = %10, %8
%15 = phi i32 [ 1, %8 ], [ %12, %10 ]
%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
ret void
}