#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 *strstr(char *, char *);
char *decruft_filename(char *buffer) {
  char *match, *match_end;
  while ((match = strstr(buffer, "%20"))) {
    match_end = match + 3;
    *match++ = ' ';
    while (*match_end)
      *match++ = *match_end++;
    *match = 0;
  }
  return buffer;
}


x86 assembly (clang, -O0):
<decruft_filename>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xed9(%rip),%rsi
call   1030 <strstr@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
je     1198 <decruft_filename+0x88>
mov    -0x10(%rbp),%rax
add    $0x3,%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movb   $0x20,(%rax)
mov    -0x18(%rbp),%rax
cmpb   $0x0,(%rax)
je     118c <decruft_filename+0x7c>
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
mov    (%rax),%cl
mov    -0x10(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x10(%rbp)
mov    %cl,(%rax)
jmp    1158 <decruft_filename+0x48>
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
jmp    111c <decruft_filename+0xc>
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<decruft_filename>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
lea    0xee2(%rip),%rsi
call   1030 <strstr@plt>
test   %rax,%rax
je     1170 <decruft_filename+0x60>
lea    0xed1(%rip),%r14
jmp    1153 <decruft_filename+0x43>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movb   $0x0,(%rax)
mov    %rbx,%rdi
mov    %r14,%rsi
call   1030 <strstr@plt>
test   %rax,%rax
je     1170 <decruft_filename+0x60>
movb   $0x20,(%rax)
cs nopw 0x0(%rax,%rax,1)
movzbl 0x3(%rax),%ecx
add    $0x1,%rax
test   %cl,%cl
je     1140 <decruft_filename+0x30>
mov    %cl,(%rax)
jmp    1160 <decruft_filename+0x50>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%20\00"
define i8* @decruft_filename(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
store i8* %0, i8** %2
br label %5
5: ; preds = %24, %1
%6 = load i8*, i8** %2
%7 = call i8* @strstr(i8* %6, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
store i8* %7, i8** %3
%8 = icmp ne i8* %7, null
br i1 %8, label %9, label %26
9: ; preds = %5
%10 = load i8*, i8** %3
%11 = getelementptr inbounds i8, i8* %10, i64 3
store i8* %11, i8** %4
%12 = load i8*, i8** %3
%13 = getelementptr inbounds i8, i8* %12, i32 1
store i8* %13, i8** %3
store i8 32, i8* %12
br label %14
14: ; preds = %18, %9
%15 = load i8*, i8** %4
%16 = load i8, i8* %15
%17 = icmp ne i8 %16, 0
br i1 %17, label %18, label %24
18: ; preds = %14
%19 = load i8*, i8** %4
%20 = getelementptr inbounds i8, i8* %19, i32 1
store i8* %20, i8** %4
%21 = load i8, i8* %19
%22 = load i8*, i8** %3
%23 = getelementptr inbounds i8, i8* %22, i32 1
store i8* %23, i8** %3
store i8 %21, i8* %22
br label %14
24: ; preds = %14
%25 = load i8*, i8** %3
store i8 0, i8* %25
br label %5
26: ; preds = %5
%27 = load i8*, i8** %2
ret i8* %27
}

LLVM IR (-O2):
@.str = [4 x i8] c"%20\00"
define i8* @decruft_filename(i8* returned %0) {
%2 = tail call i8* @strstr(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%3 = icmp eq i8* %2, null
br i1 %3, label %22, label %4
4: ; preds = %1, %18
%5 = phi i8* [ %20, %18 ], [ %2, %1 ]
%6 = getelementptr inbounds i8, i8* %5, i64 3
store i8 32, i8* %5
%7 = getelementptr inbounds i8, i8* %5, i64 1
%8 = load i8, i8* %6
%9 = icmp eq i8 %8, 0
br i1 %9, label %18, label %10
10: ; preds = %4, %10
%11 = phi i8 [ %16, %10 ], [ %8, %4 ]
%12 = phi i8* [ %15, %10 ], [ %7, %4 ]
%13 = phi i8* [ %14, %10 ], [ %6, %4 ]
%14 = getelementptr inbounds i8, i8* %13, i64 1
store i8 %11, i8* %12
%15 = getelementptr inbounds i8, i8* %12, i64 1
%16 = load i8, i8* %14
%17 = icmp eq i8 %16, 0
br i1 %17, label %18, label %10
18: ; preds = %10, %4
%19 = phi i8* [ %7, %4 ], [ %15, %10 ]
store i8 0, i8* %19
%20 = tail call i8* @strstr(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%21 = icmp eq i8* %20, null
br i1 %21, label %22, label %4
22: ; preds = %18, %1
ret i8* %0
}