#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 /*<<< orphan*/ putchar(int);
void format_space(char *text) {
  int c, i, last = -1;
  for (i = 0; (c = *(text + i)) != 0; i++) {
    if (c == ' ' && last == ' ')
      continue;
    putchar(c);
    last = c;
  }
}


x86 assembly (clang, -O0):
<format_space>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0xffffffff,-0x14(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
mov    %eax,-0xc(%rbp)
cmp    $0x0,%eax
je     1177 <format_space+0x67>
cmpl   $0x20,-0xc(%rbp)
jne    115b <format_space+0x4b>
cmpl   $0x20,-0x14(%rbp)
jne    115b <format_space+0x4b>
jmp    1169 <format_space+0x59>
mov    -0xc(%rbp),%edi
call   1030 <putchar@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    112a <format_space+0x1a>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<format_space>:
push   %rbp
push   %rbx
push   %rax
mov    (%rdi),%al
test   %al,%al
je     1152 <format_space+0x42>
mov    %rdi,%rbx
add    $0x1,%rbx
mov    $0xffffffff,%ecx
jmp    1144 <format_space+0x34>
nopw   0x0(%rax,%rax,1)
mov    %ebp,%edi
call   1030 <putchar@plt>
movzbl (%rbx),%eax
add    $0x1,%rbx
mov    %ebp,%ecx
test   %al,%al
je     1152 <format_space+0x42>
movsbl %al,%ebp
cmp    $0x20,%al
jne    1130 <format_space+0x20>
cmp    $0x20,%ecx
je     1137 <format_space+0x27>
jmp    1130 <format_space+0x20>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define void @format_space(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i8* %0, i8** %2
store i32 -1, i32* %5
store i32 0, i32* %4
br label %6
6: ; preds = %25, %1
%7 = load i8*, i8** %2
%8 = load i32, i32* %4
%9 = sext i32 %8 to i64
%10 = getelementptr inbounds i8, i8* %7, i64 %9
%11 = load i8, i8* %10
%12 = sext i8 %11 to i32
store i32 %12, i32* %3
%13 = icmp ne i32 %12, 0
br i1 %13, label %14, label %28
14: ; preds = %6
%15 = load i32, i32* %3
%16 = icmp eq i32 %15, 32
br i1 %16, label %17, label %21
17: ; preds = %14
%18 = load i32, i32* %5
%19 = icmp eq i32 %18, 32
br i1 %19, label %20, label %21
20: ; preds = %17
br label %25
21: ; preds = %17, %14
%22 = load i32, i32* %3
%23 = call i32 @putchar(i32 %22)
%24 = load i32, i32* %3
store i32 %24, i32* %5
br label %25
25: ; preds = %21, %20
%26 = load i32, i32* %4
%27 = add nsw i32 %26, 1
store i32 %27, i32* %4
br label %6
28: ; preds = %6
ret void
}

LLVM IR (-O2):
define void @format_space(i8* nocapture %0) {
%2 = load i8, i8* %0
%3 = icmp eq i8 %2, 0
br i1 %3, label %19, label %4
4: ; preds = %1, %14
%5 = phi i64 [ %15, %14 ], [ 0, %1 ]
%6 = phi i8 [ %17, %14 ], [ %2, %1 ]
%7 = phi i32 [ %8, %14 ], [ -1, %1 ]
%8 = sext i8 %6 to i32
%9 = icmp eq i8 %6, 32
%10 = icmp eq i32 %7, 32
%11 = select i1 %9, i1 %10, i1 false
br i1 %11, label %14, label %12
12: ; preds = %4
%13 = tail call i32 @putchar(i32 %8)
br label %14
14: ; preds = %4, %12
%15 = add nuw i64 %5, 1
%16 = getelementptr inbounds i8, i8* %0, i64 %15
%17 = load i8, i8* %16
%18 = icmp eq i8 %17, 0
br i1 %18, label %19, label %4
19: ; preds = %14, %1
ret void
}