char *remove_spaces_between_parenthesis(char *str) {
  char *p, *q;
  p = q = str;
  while (*(p + 1) != 0)
    if (*p == ')' && *(p + 1) == ' ')
      p++;
    else {
      *(q + 1) = *(p + 1);
      p++;
      q++;
    }
  *(q + 1) = 0;
  return str;
}


x86 assembly (clang, -O0):
<remove_spaces_between_parenthesis>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x0,%eax
je     1182 <remove_spaces_between_parenthesis+0x82>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x29,%eax
jne    1157 <remove_spaces_between_parenthesis+0x57>
mov    -0x10(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x20,%eax
jne    1157 <remove_spaces_between_parenthesis+0x57>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    117d <remove_spaces_between_parenthesis+0x7d>
mov    -0x10(%rbp),%rax
mov    0x1(%rax),%cl
mov    -0x18(%rbp),%rax
mov    %cl,0x1(%rax)
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1114 <remove_spaces_between_parenthesis+0x14>
mov    -0x18(%rbp),%rax
movb   $0x0,0x1(%rax)
mov    -0x8(%rbp),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<remove_spaces_between_parenthesis>:
mov    %rdi,%rax
mov    0x1(%rdi),%cl
mov    %rdi,%rsi
test   %cl,%cl
je     113f <remove_spaces_between_parenthesis+0x3f>
lea    0x2(%rax),%rdx
mov    %rax,%rsi
jmp    1132 <remove_spaces_between_parenthesis+0x32>
cs nopw 0x0(%rax,%rax,1)
mov    %cl,0x1(%rsi)
add    $0x1,%rsi
movzbl (%rdx),%ecx
add    $0x1,%rdx
test   %cl,%cl
je     113f <remove_spaces_between_parenthesis+0x3f>
cmpb   $0x29,-0x2(%rdx)
jne    1120 <remove_spaces_between_parenthesis+0x20>
cmp    $0x20,%cl
je     1127 <remove_spaces_between_parenthesis+0x27>
jmp    1120 <remove_spaces_between_parenthesis+0x20>
movb   $0x0,0x1(%rsi)
ret

LLVM IR (-O0):
define i8* @remove_spaces_between_parenthesis(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
store i8* %0, i8** %2
%5 = load i8*, i8** %2
store i8* %5, i8** %4
store i8* %5, i8** %3
br label %6
6: ; preds = %36, %1
%7 = load i8*, i8** %3
%8 = getelementptr inbounds i8, i8* %7, i64 1
%9 = load i8, i8* %8
%10 = sext i8 %9 to i32
%11 = icmp ne i32 %10, 0
br i1 %11, label %12, label %37
12: ; preds = %6
%13 = load i8*, i8** %3
%14 = load i8, i8* %13
%15 = sext i8 %14 to i32
%16 = icmp eq i32 %15, 41
br i1 %16, label %17, label %26
17: ; preds = %12
%18 = load i8*, i8** %3
%19 = getelementptr inbounds i8, i8* %18, i64 1
%20 = load i8, i8* %19
%21 = sext i8 %20 to i32
%22 = icmp eq i32 %21, 32
br i1 %22, label %23, label %26
23: ; preds = %17
%24 = load i8*, i8** %3
%25 = getelementptr inbounds i8, i8* %24, i32 1
store i8* %25, i8** %3
br label %36
26: ; preds = %17, %12
%27 = load i8*, i8** %3
%28 = getelementptr inbounds i8, i8* %27, i64 1
%29 = load i8, i8* %28
%30 = load i8*, i8** %4
%31 = getelementptr inbounds i8, i8* %30, i64 1
store i8 %29, i8* %31
%32 = load i8*, i8** %3
%33 = getelementptr inbounds i8, i8* %32, i32 1
store i8* %33, i8** %3
%34 = load i8*, i8** %4
%35 = getelementptr inbounds i8, i8* %34, i32 1
store i8* %35, i8** %4
br label %36
36: ; preds = %26, %23
br label %6
37: ; preds = %6
%38 = load i8*, i8** %4
%39 = getelementptr inbounds i8, i8* %38, i64 1
store i8 0, i8* %39
%40 = load i8*, i8** %2
ret i8* %40
}

LLVM IR (-O2):
define i8* @remove_spaces_between_parenthesis(i8* returned %0) {
%2 = getelementptr inbounds i8, i8* %0, i64 1
%3 = load i8, i8* %2
%4 = icmp eq i8 %3, 0
br i1 %4, label %21, label %5
5: ; preds = %1, %16
%6 = phi i8 [ %19, %16 ], [ %3, %1 ]
%7 = phi i8* [ %18, %16 ], [ %2, %1 ]
%8 = phi i8* [ %17, %16 ], [ %0, %1 ]
%9 = phi i8* [ %7, %16 ], [ %0, %1 ]
%10 = load i8, i8* %9
%11 = icmp eq i8 %10, 41
%12 = icmp eq i8 %6, 32
%13 = select i1 %11, i1 %12, i1 false
br i1 %13, label %16, label %14
14: ; preds = %5
%15 = getelementptr inbounds i8, i8* %8, i64 1
store i8 %6, i8* %15
br label %16
16: ; preds = %5, %14
%17 = phi i8* [ %15, %14 ], [ %8, %5 ]
%18 = getelementptr inbounds i8, i8* %7, i64 1
%19 = load i8, i8* %18
%20 = icmp eq i8 %19, 0
br i1 %20, label %21, label %5
21: ; preds = %16, %1
%22 = phi i8* [ %0, %1 ], [ %17, %16 ]
%23 = getelementptr inbounds i8, i8* %22, i64 1
store i8 0, i8* %23
ret i8* %0
}