#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 */
scalar_t__ char_is_invisible(char);
int /*<<< orphan*/ str_remove_sps_eol(char *);
int /*<<< orphan*/ str_remove_sps_sol(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
char *str_remove_dbl_spaces(char *str) {
  char dest[2048];
  str_remove_sps_sol(dest, str);
  str_remove_sps_eol(dest);
  strcpy(str, dest);
  if (strlen(str) <= 3)
    return str;
  char *s, *v, *prev;
  for (s = str + 1; (*s != '\0'); ++s)
    if (char_is_invisible(*s))
      *s = ' ';
  v = str + 2, s = str + 2, prev = str + 1;
SKIP_CHAR:
  if (*prev == ' ')
    while (*v == ' ')
      ++v;
  if (*v == '\0')
    goto CLOSE_STR;
  prev = v;
  if (v != s)
    *s = *v;
  ++v;
  ++s;
  if (*v != '\0')
    goto SKIP_CHAR;
CLOSE_STR:
  *s = '\0';
  return str;
}


x86 assembly (clang, -O0):
<str_remove_dbl_spaces>:
push   %rbp
mov    %rsp,%rbp
sub    $0x830,%rsp
mov    %rdi,-0x10(%rbp)
lea    -0x810(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <str_remove_sps_sol@plt>
lea    -0x810(%rbp),%rdi
call   1070 <str_remove_sps_eol@plt>
mov    -0x10(%rbp),%rdi
lea    -0x810(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
cmp    $0x3,%eax
jg     11aa <str_remove_dbl_spaces+0x5a>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    131e <str_remove_dbl_spaces+0x1ce>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x818(%rbp)
mov    -0x818(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     120b <str_remove_dbl_spaces+0xbb>
mov    -0x818(%rbp),%rax
movsbl (%rax),%edi
call   1060 <char_is_invisible@plt>
cmp    $0x0,%rax
je     11ef <str_remove_dbl_spaces+0x9f>
mov    -0x818(%rbp),%rax
movb   $0x20,(%rax)
jmp    11f4 <str_remove_dbl_spaces+0xa4>
mov    -0x818(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x818(%rbp)
jmp    11b9 <str_remove_dbl_spaces+0x69>
mov    -0x10(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x820(%rbp)
mov    -0x10(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x818(%rbp)
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x828(%rbp)
mov    -0x828(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x20,%eax
jne    127f <str_remove_dbl_spaces+0x12f>
jmp    1250 <str_remove_dbl_spaces+0x100>
mov    -0x820(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x20,%eax
jne    127a <str_remove_dbl_spaces+0x12a>
mov    -0x820(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x820(%rbp)
jmp    1250 <str_remove_dbl_spaces+0x100>
jmp    127f <str_remove_dbl_spaces+0x12f>
mov    -0x820(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    1297 <str_remove_dbl_spaces+0x147>
jmp    130c <str_remove_dbl_spaces+0x1bc>
mov    -0x820(%rbp),%rax
mov    %rax,-0x828(%rbp)
mov    -0x820(%rbp),%rax
cmp    -0x818(%rbp),%rax
je     12cb <str_remove_dbl_spaces+0x17b>
mov    -0x820(%rbp),%rax
mov    (%rax),%cl
mov    -0x818(%rbp),%rax
mov    %cl,(%rax)
mov    -0x820(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x820(%rbp)
mov    -0x818(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x818(%rbp)
mov    -0x820(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1307 <str_remove_dbl_spaces+0x1b7>
jmp    1238 <str_remove_dbl_spaces+0xe8>
jmp    130c <str_remove_dbl_spaces+0x1bc>
mov    -0x818(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x830,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<str_remove_dbl_spaces>:
push   %r14
push   %rbx
sub    $0x808,%rsp
mov    %rdi,%r14
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    %r14,%rsi
call   1040 <str_remove_sps_sol@plt>
mov    %rbx,%rdi
call   1070 <str_remove_sps_eol@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1030 <strcpy@plt>
mov    %r14,%rdi
call   1050 <strlen@plt>
cmp    $0x4,%eax
jl     1225 <str_remove_dbl_spaces+0xd5>
mov    0x1(%r14),%al
test   %al,%al
je     11be <str_remove_dbl_spaces+0x6e>
lea    0x2(%r14),%rbx
jmp    11ab <str_remove_dbl_spaces+0x5b>
nopl   (%rax)
movzbl (%rbx),%eax
add    $0x1,%rbx
test   %al,%al
je     11be <str_remove_dbl_spaces+0x6e>
movsbl %al,%edi
call   1060 <char_is_invisible@plt>
test   %rax,%rax
je     11a0 <str_remove_dbl_spaces+0x50>
movb   $0x20,-0x1(%rbx)
jmp    11a0 <str_remove_dbl_spaces+0x50>
lea    0x1(%r14),%rcx
lea    0x2(%r14),%rax
mov    %rax,%rdx
jmp    11de <str_remove_dbl_spaces+0x8e>
nopl   0x0(%rax,%rax,1)
lea    0x1(%rcx),%rdx
add    $0x1,%rax
cmpb   $0x0,0x1(%rcx)
je     1222 <str_remove_dbl_spaces+0xd2>
cmpb   $0x20,(%rcx)
jne    1210 <str_remove_dbl_spaces+0xc0>
add    $0xffffffffffffffff,%rdx
mov    %rdx,%rcx
nopw   0x0(%rax,%rax,1)
movzbl 0x1(%rcx),%ebx
add    $0x1,%rcx
cmp    $0x20,%bl
je     11f0 <str_remove_dbl_spaces+0xa0>
test   %bl,%bl
jne    1219 <str_remove_dbl_spaces+0xc9>
jmp    1222 <str_remove_dbl_spaces+0xd2>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    (%rdx),%bl
mov    %rdx,%rcx
test   %bl,%bl
je     1222 <str_remove_dbl_spaces+0xd2>
cmp    %rax,%rcx
je     11d0 <str_remove_dbl_spaces+0x80>
mov    %bl,(%rax)
jmp    11d0 <str_remove_dbl_spaces+0x80>
movb   $0x0,(%rax)
mov    %r14,%rax
add    $0x808,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i8* @str_remove_dbl_spaces(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca [2048 x i8]
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
store i8* %0, i8** %3
%8 = getelementptr inbounds [2048 x i8], [2048 x i8]* %4, i64 0, i64 0
%9 = load i8*, i8** %3
%10 = call i32 @str_remove_sps_sol(i8* %8, i8* %9)
%11 = getelementptr inbounds [2048 x i8], [2048 x i8]* %4, i64 0, i64 0
%12 = call i32 @str_remove_sps_eol(i8* %11)
%13 = load i8*, i8** %3
%14 = getelementptr inbounds [2048 x i8], [2048 x i8]* %4, i64 0, i64 0
%15 = call i32 @strcpy(i8* %13, i8* %14)
%16 = load i8*, i8** %3
%17 = call i32 @strlen(i8* %16)
%18 = icmp sle i32 %17, 3
br i1 %18, label %19, label %21
19: ; preds = %1
%20 = load i8*, i8** %3
store i8* %20, i8** %2
br label %91
21: ; preds = %1
%22 = load i8*, i8** %3
%23 = getelementptr inbounds i8, i8* %22, i64 1
store i8* %23, i8** %5
br label %24
24: ; preds = %37, %21
%25 = load i8*, i8** %5
%26 = load i8, i8* %25
%27 = sext i8 %26 to i32
%28 = icmp ne i32 %27, 0
br i1 %28, label %29, label %40
29: ; preds = %24
%30 = load i8*, i8** %5
%31 = load i8, i8* %30
%32 = call i64 @char_is_invisible(i8 signext %31)
%33 = icmp ne i64 %32, 0
br i1 %33, label %34, label %36
34: ; preds = %29
%35 = load i8*, i8** %5
store i8 32, i8* %35
br label %36
36: ; preds = %34, %29
br label %37
37: ; preds = %36
%38 = load i8*, i8** %5
%39 = getelementptr inbounds i8, i8* %38, i32 1
store i8* %39, i8** %5
br label %24
40: ; preds = %24
%41 = load i8*, i8** %3
%42 = getelementptr inbounds i8, i8* %41, i64 2
store i8* %42, i8** %6
%43 = load i8*, i8** %3
%44 = getelementptr inbounds i8, i8* %43, i64 2
store i8* %44, i8** %5
%45 = load i8*, i8** %3
%46 = getelementptr inbounds i8, i8* %45, i64 1
store i8* %46, i8** %7
br label %47
47: ; preds = %86, %40
%48 = load i8*, i8** %7
%49 = load i8, i8* %48
%50 = sext i8 %49 to i32
%51 = icmp eq i32 %50, 32
br i1 %51, label %52, label %62
52: ; preds = %47
br label %53
53: ; preds = %58, %52
%54 = load i8*, i8** %6
%55 = load i8, i8* %54
%56 = sext i8 %55 to i32
%57 = icmp eq i32 %56, 32
br i1 %57, label %58, label %61
58: ; preds = %53
%59 = load i8*, i8** %6
%60 = getelementptr inbounds i8, i8* %59, i32 1
store i8* %60, i8** %6
br label %53
61: ; preds = %53
br label %62
62: ; preds = %61, %47
%63 = load i8*, i8** %6
%64 = load i8, i8* %63
%65 = sext i8 %64 to i32
%66 = icmp eq i32 %65, 0
br i1 %66, label %67, label %68
67: ; preds = %62
br label %88
68: ; preds = %62
%69 = load i8*, i8** %6
store i8* %69, i8** %7
%70 = load i8*, i8** %6
%71 = load i8*, i8** %5
%72 = icmp ne i8* %70, %71
br i1 %72, label %73, label %77
73: ; preds = %68
%74 = load i8*, i8** %6
%75 = load i8, i8* %74
%76 = load i8*, i8** %5
store i8 %75, i8* %76
br label %77
77: ; preds = %73, %68
%78 = load i8*, i8** %6
%79 = getelementptr inbounds i8, i8* %78, i32 1
store i8* %79, i8** %6
%80 = load i8*, i8** %5
%81 = getelementptr inbounds i8, i8* %80, i32 1
store i8* %81, i8** %5
%82 = load i8*, i8** %6
%83 = load i8, i8* %82
%84 = sext i8 %83 to i32
%85 = icmp ne i32 %84, 0
br i1 %85, label %86, label %87
86: ; preds = %77
br label %47
87: ; preds = %77
br label %88
88: ; preds = %87, %67
%89 = load i8*, i8** %5
store i8 0, i8* %89
%90 = load i8*, i8** %3
store i8* %90, i8** %2
br label %91
91: ; preds = %88, %19
%92 = load i8*, i8** %2
ret i8* %92
}

LLVM IR (-O2):
define i8* @str_remove_dbl_spaces(i8* returned %0) {
%2 = alloca [2048 x i8]
%3 = getelementptr inbounds [2048 x i8], [2048 x i8]* %2, i64 0, i64 0
%4 = call i32 @str_remove_sps_sol(i8* %3, i8* %0)
%5 = call i32 @str_remove_sps_eol(i8* %3)
%6 = call i32 @strcpy(i8* %0, i8* %3)
%7 = call i32 @strlen(i8* %0)
%8 = icmp slt i32 %7, 4
br i1 %8, label %52, label %9
9: ; preds = %1
%10 = getelementptr inbounds i8, i8* %0, i64 1
%11 = load i8, i8* %10
%12 = icmp eq i8 %11, 0
br i1 %12, label %23, label %13
13: ; preds = %9, %19
%14 = phi i8 [ %21, %19 ], [ %11, %9 ]
%15 = phi i8* [ %20, %19 ], [ %10, %9 ]
%16 = call i64 @char_is_invisible(i8 signext %14)
%17 = icmp eq i64 %16, 0
br i1 %17, label %19, label %18
18: ; preds = %13
store i8 32, i8* %15
br label %19
19: ; preds = %13, %18
%20 = getelementptr inbounds i8, i8* %15, i64 1
%21 = load i8, i8* %20
%22 = icmp eq i8 %21, 0
br i1 %22, label %23, label %13
23: ; preds = %19, %9
%24 = getelementptr inbounds i8, i8* %0, i64 2
br label %25
25: ; preds = %45, %23
%26 = phi i8* [ %24, %23 ], [ %47, %45 ]
%27 = phi i8* [ %24, %23 ], [ %46, %45 ]
%28 = phi i8* [ %10, %23 ], [ %40, %45 ]
%29 = load i8, i8* %28
%30 = icmp eq i8 %29, 32
br i1 %30, label %31, label %36
31: ; preds = %25, %31
%32 = phi i8* [ %35, %31 ], [ %27, %25 ]
%33 = load i8, i8* %32
%34 = icmp eq i8 %33, 32
%35 = getelementptr inbounds i8, i8* %32, i64 1
br i1 %34, label %31, label %38
36: ; preds = %25
%37 = load i8, i8* %27
br label %38
38: ; preds = %31, %36
%39 = phi i8 [ %37, %36 ], [ %33, %31 ]
%40 = phi i8* [ %27, %36 ], [ %32, %31 ]
%41 = icmp eq i8 %39, 0
br i1 %41, label %50, label %42
42: ; preds = %38
%43 = icmp eq i8* %40, %26
br i1 %43, label %45, label %44
44: ; preds = %42
store i8 %39, i8* %26
br label %45
45: ; preds = %44, %42
%46 = getelementptr inbounds i8, i8* %40, i64 1
%47 = getelementptr inbounds i8, i8* %26, i64 1
%48 = load i8, i8* %46
%49 = icmp eq i8 %48, 0
br i1 %49, label %50, label %25
50: ; preds = %45, %38
%51 = phi i8* [ %26, %38 ], [ %47, %45 ]
store i8 0, i8* %51
br label %52
52: ; preds = %1, %50
ret i8* %0
}