void expand_percent_escaping(char s[]) {
  char *p;
  p = s;
  while (s[0] != '\0') {
    if (s[0] == '%' && s[1] == '%') {
      ++s;
    }
    *p++ = *s++;
  }
  *p = '\0';
}


x86 assembly (clang, -O0):
<expand_percent_escaping>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1174 <expand_percent_escaping+0x74>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x25,%eax
jne    114d <expand_percent_escaping+0x4d>
mov    -0x8(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x25,%eax
jne    114d <expand_percent_escaping+0x4d>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
mov    (%rax),%cl
mov    -0x10(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x10(%rbp)
mov    %cl,(%rax)
jmp    1110 <expand_percent_escaping+0x10>
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
pop    %rbp
ret

x86 assembly (clang, -O2):
<expand_percent_escaping>:
mov    %rdi,%rax
jmp    111e <expand_percent_escaping+0x1e>
cs nopw 0x0(%rax,%rax,1)
nop
test   %cl,%cl
je     1135 <expand_percent_escaping+0x35>
add    $0x1,%rdi
mov    %cl,(%rax)
add    $0x1,%rax
movzbl (%rdi),%ecx
cmp    $0x25,%cl
jne    1110 <expand_percent_escaping+0x10>
cmpb   $0x25,0x1(%rdi)
jne    1130 <expand_percent_escaping+0x30>
add    $0x1,%rdi
movzbl (%rdi),%ecx
jmp    1114 <expand_percent_escaping+0x14>
movb   $0x0,(%rax)
ret

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

LLVM IR (-O2):
define void @expand_percent_escaping(i8* nocapture %0) {
br label %2
2: ; preds = %12, %1
%3 = phi i8* [ %0, %1 ], [ %15, %12 ]
%4 = phi i8* [ %0, %1 ], [ %16, %12 ]
%5 = load i8, i8* %3
switch i8 %5, label %12 [
i8 0, label %17
i8 37, label %6
]
6: ; preds = %2
%7 = getelementptr inbounds i8, i8* %3, i64 1
%8 = load i8, i8* %7
%9 = icmp eq i8 %8, 37
%10 = select i1 %9, i8* %7, i8* %3
%11 = load i8, i8* %10
br label %12
12: ; preds = %6, %2
%13 = phi i8 [ %5, %2 ], [ %11, %6 ]
%14 = phi i8* [ %3, %2 ], [ %10, %6 ]
%15 = getelementptr inbounds i8, i8* %14, i64 1
%16 = getelementptr inbounds i8, i8* %4, i64 1
store i8 %13, i8* %4
br label %2
17: ; preds = %2
store i8 0, i8* %4
ret void
}