char *decodeFilename(const char *name) {
  static char decodedName[256];
  char *str = decodedName;
  int i = 0;
  while ((*name & 0x80) == 0) {
    i++;
    if (i >= 256) {
      decodedName[256 - 1] = '\0';
      return decodedName;
    }
    *str++ = *name++;
  }
  *str++ = *name & 0x7f;
  *str = '\0';
  return decodedName;
}


x86 assembly (clang, -O0):
<decodeFilename>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x10(%rbp)
lea    0x2f21(%rip),%rax
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
and    $0x80,%eax
cmp    $0x0,%eax
jne    1183 <decodeFilename+0x83>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
cmpl   $0x100,-0x1c(%rbp)
jl     115c <decodeFilename+0x5c>
movb   $0x0,0x2fe3(%rip)
lea    0x2edd(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11b2 <decodeFilename+0xb2>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
mov    (%rax),%cl
mov    -0x18(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x18(%rbp)
mov    %cl,(%rax)
jmp    111a <decodeFilename+0x1a>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
and    $0x7f,%eax
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x18(%rbp)
mov    %cl,(%rax)
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
lea    0x2e82(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<decodeFilename>:
mov    (%rdi),%al
test   %al,%al
js     1167 <decodeFilename+0x67>
xor    %edx,%edx
lea    0x2f21(%rip),%rsi
lea    0x3019(%rip),%rcx
cs nopw 0x0(%rax,%rax,1)
mov    %al,(%rdx,%rsi,1)
movzbl 0x1(%rdi,%rdx,1),%eax
test   %al,%al
js     1170 <decodeFilename+0x70>
mov    %al,0x1(%rdx,%rsi,1)
movzbl 0x2(%rdi,%rdx,1),%eax
test   %al,%al
js     117a <decodeFilename+0x7a>
mov    %al,0x2(%rdx,%rsi,1)
movzbl 0x3(%rdi,%rdx,1),%eax
test   %al,%al
js     1184 <decodeFilename+0x84>
cmp    $0xfc,%edx
je     1194 <decodeFilename+0x94>
mov    %al,0x3(%rdx,%rsi,1)
movzbl 0x4(%rdi,%rdx,1),%eax
add    $0x4,%rdx
test   %al,%al
jns    1120 <decodeFilename+0x20>
add    %rdx,%rsi
mov    %rsi,%rcx
jmp    118c <decodeFilename+0x8c>
lea    0x2ec2(%rip),%rcx
jmp    118c <decodeFilename+0x8c>
lea    (%rdx,%rsi,1),%rcx
add    $0x1,%rcx
jmp    118c <decodeFilename+0x8c>
lea    (%rdx,%rsi,1),%rcx
add    $0x2,%rcx
jmp    118c <decodeFilename+0x8c>
lea    (%rdx,%rsi,1),%rcx
add    $0x3,%rcx
and    $0x7f,%al
mov    %al,(%rcx)
add    $0x1,%rcx
movb   $0x0,(%rcx)
lea    0x2e92(%rip),%rax
ret

LLVM IR (-O0):
@decodeFilename.decodedName = internal global [256 x i8] zeroinitializer
define i8* @decodeFilename(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
store i8* %0, i8** %3
store i8* getelementptr inbounds ([256 x i8], [256 x i8]* @decodeFilename.decodedName, i64 0, i64 0), i8** %4
store i32 0, i32* %5
br label %6
6: ; preds = %18, %1
%7 = load i8*, i8** %3
%8 = load i8, i8* %7
%9 = sext i8 %8 to i32
%10 = and i32 %9, 128
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %24
12: ; preds = %6
%13 = load i32, i32* %5
%14 = add nsw i32 %13, 1
store i32 %14, i32* %5
%15 = load i32, i32* %5
%16 = icmp sge i32 %15, 256
br i1 %16, label %17, label %18
17: ; preds = %12
store i8 0, i8* getelementptr inbounds ([256 x i8], [256 x i8]* @decodeFilename.decodedName, i64 0, i64 255)
store i8* getelementptr inbounds ([256 x i8], [256 x i8]* @decodeFilename.decodedName, i64 0, i64 0), i8** %2
br label %33
18: ; preds = %12
%19 = load i8*, i8** %3
%20 = getelementptr inbounds i8, i8* %19, i32 1
store i8* %20, i8** %3
%21 = load i8, i8* %19
%22 = load i8*, i8** %4
%23 = getelementptr inbounds i8, i8* %22, i32 1
store i8* %23, i8** %4
store i8 %21, i8* %22
br label %6
24: ; preds = %6
%25 = load i8*, i8** %3
%26 = load i8, i8* %25
%27 = sext i8 %26 to i32
%28 = and i32 %27, 127
%29 = trunc i32 %28 to i8
%30 = load i8*, i8** %4
%31 = getelementptr inbounds i8, i8* %30, i32 1
store i8* %31, i8** %4
store i8 %29, i8* %30
%32 = load i8*, i8** %4
store i8 0, i8* %32
store i8* getelementptr inbounds ([256 x i8], [256 x i8]* @decodeFilename.decodedName, i64 0, i64 0), i8** %2
br label %33
33: ; preds = %24, %17
%34 = load i8*, i8** %2
ret i8* %34
}

LLVM IR (-O2):
@decodeFilename.decodedName = internal global [256 x i8] zeroinitializer
define i8* @decodeFilename(i8* nocapture %0) {
%2 = load i8, i8* %0
%3 = icmp sgt i8 %2, -1
br i1 %3, label %4, label %31
4: ; preds = %1, %25
%5 = phi i8 [ %29, %25 ], [ %2, %1 ]
%6 = phi i32 [ %26, %25 ], [ 0, %1 ]
%7 = phi i8* [ %28, %25 ], [ getelementptr inbounds ([256 x i8], [256 x i8]* @decodeFilename.decodedName, i64 0, i64 0), %1 ]
%8 = phi i8* [ %27, %25 ], [ %0, %1 ]
%9 = getelementptr inbounds i8, i8* %8, i64 1
%10 = getelementptr inbounds i8, i8* %7, i64 1
store i8 %5, i8* %7
%11 = load i8, i8* %9
%12 = icmp sgt i8 %11, -1
br i1 %12, label %13, label %31
13: ; preds = %4
%14 = getelementptr inbounds i8, i8* %8, i64 2
%15 = getelementptr inbounds i8, i8* %7, i64 2
store i8 %11, i8* %10
%16 = load i8, i8* %14
%17 = icmp sgt i8 %16, -1
br i1 %17, label %18, label %31
18: ; preds = %13
%19 = getelementptr inbounds i8, i8* %8, i64 3
%20 = getelementptr inbounds i8, i8* %7, i64 3
store i8 %16, i8* %15
%21 = load i8, i8* %19
%22 = icmp sgt i8 %21, -1
br i1 %22, label %23, label %31
23: ; preds = %18
%24 = icmp eq i32 %6, 252
br i1 %24, label %36, label %25
25: ; preds = %23
%26 = add nuw nsw i32 %6, 4
%27 = getelementptr inbounds i8, i8* %8, i64 4
%28 = getelementptr inbounds i8, i8* %7, i64 4
store i8 %21, i8* %20
%29 = load i8, i8* %27
%30 = icmp sgt i8 %29, -1
br i1 %30, label %4, label %31
31: ; preds = %4, %13, %18, %25, %1
%32 = phi i8* [ getelementptr inbounds ([256 x i8], [256 x i8]* @decodeFilename.decodedName, i64 0, i64 0), %1 ], [ %10, %4 ], [ %15, %13 ], [ %20, %18 ], [ %28, %25 ]
%33 = phi i8 [ %2, %1 ], [ %11, %4 ], [ %16, %13 ], [ %21, %18 ], [ %29, %25 ]
%34 = and i8 %33, 127
%35 = getelementptr inbounds i8, i8* %32, i64 1
store i8 %34, i8* %32
br label %36
36: ; preds = %23, %31
%37 = phi i8* [ %35, %31 ], [ getelementptr inbounds ([256 x i8], [256 x i8]* @decodeFilename.decodedName, i64 0, i64 255), %23 ]
store i8 0, i8* %37
ret i8* getelementptr inbounds ([256 x i8], [256 x i8]* @decodeFilename.decodedName, i64 0, i64 0)
}