#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 */
char *ap_str_find_first_char_from_set(char *, char *);
int /*<<< orphan*/ memmove(char *, char *, int);
size_t strlen(char *);
size_t strspn(char *, char *);
char *ap_str_shrink_spaces(char *str) {
  size_t seg_len = 0;
  size_t str_len = strlen(str);
  char *pos = ap_str_find_first_char_from_set(str, "\t ");
  if (pos == NULL) {
    goto finish;
  }
  seg_len = strspn(pos, "\t ");
  if (seg_len > 1) {
    memmove(pos + 1, pos + seg_len, str_len + str - pos - seg_len + 1);
    ap_str_shrink_spaces(pos + 1);
  }
finish:
  return str;
}


x86 assembly (clang, -O0):
<ap_str_shrink_spaces>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe84(%rip),%rsi
call   1030 <ap_str_find_first_char_from_set@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1195 <ap_str_shrink_spaces+0x45>
jmp    11f4 <ap_str_shrink_spaces+0xa4>
mov    -0x20(%rbp),%rdi
lea    0xe60(%rip),%rsi
call   1060 <strspn@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x1,-0x10(%rbp)
jbe    11ef <ap_str_shrink_spaces+0x9f>
mov    -0x20(%rbp),%rdi
add    $0x1,%rdi
mov    -0x20(%rbp),%rsi
add    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rax
add    -0x8(%rbp),%rax
mov    -0x20(%rbp),%rcx
sub    %rcx,%rax
sub    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %eax,%edx
call   1070 <memmove@plt>
mov    -0x20(%rbp),%rdi
add    $0x1,%rdi
call   1050 <ap_str_shrink_spaces@plt>
jmp    11f4 <ap_str_shrink_spaces+0xa4>
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ap_str_shrink_spaces>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
call   1040 <strlen@plt>
mov    %rax,%rbx
lea    0xea3(%rip),%rsi
mov    %r14,%rdi
call   1030 <ap_str_find_first_char_from_set@plt>
test   %rax,%rax
je     11e1 <ap_str_shrink_spaces+0xa1>
mov    %rax,%r12
xor    %r15d,%r15d
mov    %r12,%rdi
lea    0xe86(%rip),%rsi
call   1050 <strspn@plt>
cmp    $0x2,%rax
jb     11d8 <ap_str_shrink_spaces+0x98>
lea    0x1(%r12),%r13
mov    %rax,%rsi
add    %r12,%rsi
add    %r14d,%ebx
add    %eax,%r12d
sub    %r12d,%ebx
add    $0x1,%ebx
mov    %r13,%rdi
mov    %ebx,%edx
call   1060 <memmove@plt>
test   $0x1,%r15b
cmove  %r14,%rbp
mov    %r13,%rdi
call   1040 <strlen@plt>
mov    %rax,%rbx
mov    %r13,%rdi
lea    0xe3d(%rip),%rsi
call   1030 <ap_str_find_first_char_from_set@plt>
mov    %rax,%r12
mov    $0x1,%r15b
mov    %r13,%r14
test   %rax,%rax
jne    1170 <ap_str_shrink_spaces+0x30>
jmp    11de <ap_str_shrink_spaces+0x9e>
test   $0x1,%r15b
je     11e1 <ap_str_shrink_spaces+0xa1>
mov    %rbp,%r14
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"\09 \00"
define i8* @ap_str_shrink_spaces(i8* %0) {
%2 = alloca i8*
%3 = alloca i64
%4 = alloca i64
%5 = alloca i8*
store i8* %0, i8** %2
store i64 0, i64* %3
%6 = load i8*, i8** %2
%7 = call i64 @strlen(i8* %6)
store i64 %7, i64* %4
%8 = load i8*, i8** %2
%9 = call i8* @ap_str_find_first_char_from_set(i8* %8, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i8* %9, i8** %5
%10 = load i8*, i8** %5
%11 = icmp eq i8* %10, null
br i1 %11, label %12, label %13
12: ; preds = %1
br label %40
13: ; preds = %1
%14 = load i8*, i8** %5
%15 = call i64 @strspn(i8* %14, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i64 %15, i64* %3
%16 = load i64, i64* %3
%17 = icmp ugt i64 %16, 1
br i1 %17, label %18, label %39
18: ; preds = %13
%19 = load i8*, i8** %5
%20 = getelementptr inbounds i8, i8* %19, i64 1
%21 = load i8*, i8** %5
%22 = load i64, i64* %3
%23 = getelementptr inbounds i8, i8* %21, i64 %22
%24 = load i64, i64* %4
%25 = load i8*, i8** %2
%26 = getelementptr inbounds i8, i8* %25, i64 %24
%27 = load i8*, i8** %5
%28 = ptrtoint i8* %26 to i64
%29 = ptrtoint i8* %27 to i64
%30 = sub i64 %28, %29
%31 = load i64, i64* %3
%32 = sub i64 %30, %31
%33 = add i64 %32, 1
%34 = trunc i64 %33 to i32
%35 = call i32 @memmove(i8* %20, i8* %23, i32 %34)
%36 = load i8*, i8** %5
%37 = getelementptr inbounds i8, i8* %36, i64 1
%38 = call i8* @ap_str_shrink_spaces(i8* %37)
br label %39
39: ; preds = %18, %13
br label %40
40: ; preds = %39, %12
%41 = load i8*, i8** %2
ret i8* %41
}

LLVM IR (-O2):
@.str = [3 x i8] c"\09 \00"
define i8* @ap_str_shrink_spaces(i8* returned %0) {
%2 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%3 = tail call i8* @ap_str_find_first_char_from_set(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i8* %3, null
br i1 %4, label %31, label %5
5: ; preds = %1, %13
%6 = phi i8* [ %26, %13 ], [ %3, %1 ]
%7 = phi i64 [ %25, %13 ], [ %2, %1 ]
%8 = phi i1 [ true, %13 ], [ false, %1 ]
%9 = phi i8* [ %24, %13 ], [ undef, %1 ]
%10 = phi i8* [ %14, %13 ], [ %0, %1 ]
%11 = tail call i64 @strspn(i8* %6, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%12 = icmp ugt i64 %11, 1
br i1 %12, label %13, label %28
13: ; preds = %5
%14 = getelementptr inbounds i8, i8* %6, i64 1
%15 = getelementptr inbounds i8, i8* %6, i64 %11
%16 = getelementptr inbounds i8, i8* %10, i64 %7
%17 = ptrtoint i8* %16 to i64
%18 = ptrtoint i8* %6 to i64
%19 = add i64 %11, %18
%20 = sub i64 %17, %19
%21 = trunc i64 %20 to i32
%22 = add i32 %21, 1
%23 = tail call i32 @memmove(i8* %14, i8* %15, i32 %22)
%24 = select i1 %8, i8* %9, i8* %10
%25 = tail call i64 @strlen(i8* dereferenceable(1) %14)
%26 = tail call i8* @ap_str_find_first_char_from_set(i8* %14, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%27 = icmp eq i8* %26, null
br i1 %27, label %29, label %5
28: ; preds = %5
br i1 %8, label %29, label %31
29: ; preds = %13, %28
%30 = phi i8* [ %9, %28 ], [ %24, %13 ]
br label %31
31: ; preds = %1, %28, %29
%32 = phi i8* [ %30, %29 ], [ %10, %28 ], [ %0, %1 ]
ret i8* %32
}