#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*/ memmove(char *const, char *const, size_t const);
void *strlen(char *);
char *strstr(char *, char *);
size_t replace_unicode_spaces(char *text) {
  size_t textlen = strlen(text);
  char *spaces[] = {"\u00A0", "\u2000", "\u2001", "\u2002",    "\u2003",
                    "\u2004", "\u2005", "\u2006", "\u2007",    "\u2008",
                    "\u2009", "\u200A", "\u202F", (char *)NULL};
  int n = 0;
  char *needle;
  while ((needle = spaces[n++]) != NULL) {
    char *pos = strstr(text, needle);
    if (pos == NULL)
      continue;
    const size_t ndllen = strlen(needle);
    do {
      *pos = ' ';
      char *const move_to = pos + 1;
      char *const move_from = pos + ndllen;
      const size_t move_size = textlen - (move_from - text) + 1;
      memmove(move_to, move_from, move_size);
      textlen = textlen - ndllen + 1;
    } while ((pos = strstr(text, needle)) != NULL);
  }
  return textlen;
}


x86 assembly (clang, -O0):
<replace_unicode_spaces>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc0,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x10(%rbp)
lea    -0x80(%rbp),%rdi
lea    0x2c49(%rip),%rsi
mov    $0x70,%edx
call   1040 <memcpy@plt>
movl   $0x0,-0x84(%rbp)
mov    -0x84(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x84(%rbp)
cltq
mov    -0x80(%rbp,%rax,8),%rax
mov    %rax,-0x90(%rbp)
cmp    $0x0,%rax
je     1285 <replace_unicode_spaces+0x145>
mov    -0x8(%rbp),%rdi
mov    -0x90(%rbp),%rsi
call   1060 <strstr@plt>
mov    %rax,-0x98(%rbp)
cmpq   $0x0,-0x98(%rbp)
jne    11ce <replace_unicode_spaces+0x8e>
jmp    117b <replace_unicode_spaces+0x3b>
mov    -0x90(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0xa0(%rbp)
mov    -0x98(%rbp),%rax
movb   $0x20,(%rax)
mov    -0x98(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0xa8(%rbp)
mov    -0x98(%rbp),%rax
add    -0xa0(%rbp),%rax
mov    %rax,-0xb0(%rbp)
mov    -0x10(%rbp),%rax
mov    -0xb0(%rbp),%rcx
mov    -0x8(%rbp),%rdx
sub    %rdx,%rcx
sub    %rcx,%rax
add    $0x1,%rax
mov    %rax,-0xb8(%rbp)
mov    -0xa8(%rbp),%rdi
mov    -0xb0(%rbp),%rsi
mov    -0xb8(%rbp),%rdx
call   1050 <memmove@plt>
mov    -0x10(%rbp),%rax
sub    -0xa0(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x90(%rbp),%rsi
call   1060 <strstr@plt>
mov    %rax,-0x98(%rbp)
cmp    $0x0,%rax
jne    11e1 <replace_unicode_spaces+0xa1>
jmp    117b <replace_unicode_spaces+0x3b>
mov    -0x10(%rbp),%rax
add    $0xc0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<replace_unicode_spaces>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%r14
call   1030 <strlen@plt>
mov    %rax,%r13
lea    0x1(%r14),%rax
mov    %rax,0x8(%rsp)
lea    0xea7(%rip),%r15
mov    $0x1,%ebp
jmp    117a <replace_unicode_spaces+0x4a>
lea    0x2c49(%rip),%rax
mov    0x10(%rsp),%rcx
mov    (%rax,%rcx,8),%r15
lea    0x1(%rcx),%rbp
cmp    $0xd,%rcx
je     11ea <replace_unicode_spaces+0xba>
mov    %r14,%rdi
mov    %r15,%rsi
call   1050 <strstr@plt>
test   %rax,%rax
mov    %rbp,0x10(%rsp)
je     1160 <replace_unicode_spaces+0x30>
mov    %rax,%rbx
mov    %r15,%rdi
call   1030 <strlen@plt>
mov    %rax,%r12
mov    0x8(%rsp),%rbp
sub    %rax,%rbp
cs nopw 0x0(%rax,%rax,1)
nop
movb   $0x20,(%rbx)
lea    0x1(%rbx),%rdi
mov    %rbp,%rdx
add    %r13,%rdx
sub    %rbx,%rdx
add    %r12,%rbx
mov    %rbx,%rsi
call   1040 <memmove@plt>
sub    %r12,%r13
add    $0x1,%r13
mov    %r14,%rdi
mov    %r15,%rsi
call   1050 <strstr@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    11b0 <replace_unicode_spaces+0x80>
jmp    1160 <replace_unicode_spaces+0x30>
mov    %r13,%rax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"\C2\A0\00"
@.str.1 = [4 x i8] c"\E2\80\80\00"
@.str.2 = [4 x i8] c"\E2\80\81\00"
@.str.3 = [4 x i8] c"\E2\80\82\00"
@.str.4 = [4 x i8] c"\E2\80\83\00"
@.str.5 = [4 x i8] c"\E2\80\84\00"
@.str.6 = [4 x i8] c"\E2\80\85\00"
@.str.7 = [4 x i8] c"\E2\80\86\00"
@.str.8 = [4 x i8] c"\E2\80\87\00"
@.str.9 = [4 x i8] c"\E2\80\88\00"
@.str.10 = [4 x i8] c"\E2\80\89\00"
@.str.11 = [4 x i8] c"\E2\80\8A\00"
@.str.12 = [4 x i8] c"\E2\80\AF\00"
@__const.replace_unicode_spaces.spaces = [14 x i8*] [i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.9, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.10, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.11, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.12, i32 0, i32 0), i8* null]
define i64 @replace_unicode_spaces(i8* %0) {
%2 = alloca i8*
%3 = alloca i64
%4 = alloca [14 x i8*]
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i64
store i8* %0, i8** %2
%12 = load i8*, i8** %2
%13 = call i8* @strlen(i8* %12)
%14 = ptrtoint i8* %13 to i64
store i64 %14, i64* %3
%15 = bitcast [14 x i8*]* %4 to i8*
store i32 0, i32* %5
br label %16
16: ; preds = %62, %29, %1
%17 = load i32, i32* %5
%18 = add nsw i32 %17, 1
store i32 %18, i32* %5
%19 = sext i32 %17 to i64
%20 = getelementptr inbounds [14 x i8*], [14 x i8*]* %4, i64 0, i64 %19
%21 = load i8*, i8** %20
store i8* %21, i8** %6
%22 = icmp ne i8* %21, null
br i1 %22, label %23, label %63
23: ; preds = %16
%24 = load i8*, i8** %2
%25 = load i8*, i8** %6
%26 = call i8* @strstr(i8* %24, i8* %25)
store i8* %26, i8** %7
%27 = load i8*, i8** %7
%28 = icmp eq i8* %27, null
br i1 %28, label %29, label %30
29: ; preds = %23
br label %16
30: ; preds = %23
%31 = load i8*, i8** %6
%32 = call i8* @strlen(i8* %31)
%33 = ptrtoint i8* %32 to i64
store i64 %33, i64* %8
br label %34
34: ; preds = %57, %30
%35 = load i8*, i8** %7
store i8 32, i8* %35
%36 = load i8*, i8** %7
%37 = getelementptr inbounds i8, i8* %36, i64 1
store i8* %37, i8** %9
%38 = load i8*, i8** %7
%39 = load i64, i64* %8
%40 = getelementptr inbounds i8, i8* %38, i64 %39
store i8* %40, i8** %10
%41 = load i64, i64* %3
%42 = load i8*, i8** %10
%43 = load i8*, i8** %2
%44 = ptrtoint i8* %42 to i64
%45 = ptrtoint i8* %43 to i64
%46 = sub i64 %44, %45
%47 = sub i64 %41, %46
%48 = add i64 %47, 1
store i64 %48, i64* %11
%49 = load i8*, i8** %9
%50 = load i8*, i8** %10
%51 = load i64, i64* %11
%52 = call i32 @memmove(i8* %49, i8* %50, i64 %51)
%53 = load i64, i64* %3
%54 = load i64, i64* %8
%55 = sub i64 %53, %54
%56 = add i64 %55, 1
store i64 %56, i64* %3
br label %57
57: ; preds = %34
%58 = load i8*, i8** %2
%59 = load i8*, i8** %6
%60 = call i8* @strstr(i8* %58, i8* %59)
store i8* %60, i8** %7
%61 = icmp ne i8* %60, null
br i1 %61, label %34, label %62
62: ; preds = %57
br label %16
63: ; preds = %16
%64 = load i64, i64* %3
ret i64 %64
}

LLVM IR (-O2):
@.str = [3 x i8] c"\C2\A0\00"
@.str.1 = [4 x i8] c"\E2\80\80\00"
@.str.2 = [4 x i8] c"\E2\80\81\00"
@.str.3 = [4 x i8] c"\E2\80\82\00"
@.str.4 = [4 x i8] c"\E2\80\83\00"
@.str.5 = [4 x i8] c"\E2\80\84\00"
@.str.6 = [4 x i8] c"\E2\80\85\00"
@.str.7 = [4 x i8] c"\E2\80\86\00"
@.str.8 = [4 x i8] c"\E2\80\87\00"
@.str.9 = [4 x i8] c"\E2\80\88\00"
@.str.10 = [4 x i8] c"\E2\80\89\00"
@.str.11 = [4 x i8] c"\E2\80\8A\00"
@.str.12 = [4 x i8] c"\E2\80\AF\00"
@__const.replace_unicode_spaces.spaces = [14 x i8*] [i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.9, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.10, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.11, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.12, i32 0, i32 0), i8* null]
define i64 @replace_unicode_spaces(i8* %0) {
%2 = tail call i8* @strlen(i8* %0)
%3 = ptrtoint i8* %2 to i64
%4 = ptrtoint i8* %0 to i64
%5 = add i64 %4, 1
br label %6
6: ; preds = %1, %28
%7 = phi i64 [ 1, %1 ], [ %30, %28 ]
%8 = phi i8* [ getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), %1 ], [ %32, %28 ]
%9 = phi i64 [ %3, %1 ], [ %29, %28 ]
%10 = tail call i8* @strstr(i8* dereferenceable(1) %0, i8* dereferenceable(1) %8)
%11 = icmp eq i8* %10, null
br i1 %11, label %28, label %12
12: ; preds = %6
%13 = tail call i8* @strlen(i8* %8)
%14 = ptrtoint i8* %13 to i64
br label %15
15: ; preds = %15, %12
%16 = phi i8* [ %10, %12 ], [ %26, %15 ]
%17 = phi i64 [ %9, %12 ], [ %25, %15 ]
store i8 32, i8* %16
%18 = getelementptr inbounds i8, i8* %16, i64 1
%19 = getelementptr inbounds i8, i8* %16, i64 %14
%20 = ptrtoint i8* %19 to i64
%21 = add i64 %5, %17
%22 = sub i64 %21, %20
%23 = tail call i32 @memmove(i8* %18, i8* %19, i64 %22)
%24 = sub i64 %17, %14
%25 = add i64 %24, 1
%26 = tail call i8* @strstr(i8* dereferenceable(1) %0, i8* dereferenceable(1) %8)
%27 = icmp eq i8* %26, null
br i1 %27, label %28, label %15
28: ; preds = %15, %6
%29 = phi i64 [ %9, %6 ], [ %25, %15 ]
%30 = add nuw nsw i64 %7, 1
%31 = getelementptr inbounds [14 x i8*], [14 x i8*]* @__const.replace_unicode_spaces.spaces, i64 0, i64 %7
%32 = load i8*, i8** %31
%33 = icmp eq i64 %7, 13
br i1 %33, label %34, label %6
34: ; preds = %28
ret i64 %29
}