char *Cvar_ClearForeignCharacters(const char *value) {
  static char clean[256];
  int i, j;
  j = 0;
  for (i = 0; value[i] != '\0'; i++) {
    if (!(value[i] & 128)) {
      clean[j] = value[i];
      j++;
    }
  }
  clean[j] = '\0';
  return clean;
}


x86 assembly (clang, -O0):
<Cvar_ClearForeignCharacters>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
je     117a <Cvar_ClearForeignCharacters+0x7a>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
and    $0x80,%eax
cmp    $0x0,%eax
jne    1167 <Cvar_ClearForeignCharacters+0x67>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    (%rax,%rcx,1),%dl
movslq -0x10(%rbp),%rcx
lea    0x2ed5(%rip),%rax
mov    %dl,(%rax,%rcx,1)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    116c <Cvar_ClearForeignCharacters+0x6c>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1116 <Cvar_ClearForeignCharacters+0x16>
movslq -0x10(%rbp),%rcx
lea    0x2eab(%rip),%rax
movb   $0x0,(%rax,%rcx,1)
lea    0x2ea0(%rip),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<Cvar_ClearForeignCharacters>:
mov    (%rdi),%dl
test   %dl,%dl
je     1139 <Cvar_ClearForeignCharacters+0x39>
add    $0x1,%rdi
xor    %eax,%eax
lea    0x2f1d(%rip),%rcx
jmp    112b <Cvar_ClearForeignCharacters+0x2b>
cs nopw 0x0(%rax,%rax,1)
nop
movzbl (%rdi),%edx
add    $0x1,%rdi
test   %dl,%dl
je     113b <Cvar_ClearForeignCharacters+0x3b>
test   %dl,%dl
js     1120 <Cvar_ClearForeignCharacters+0x20>
cltq
mov    %dl,(%rax,%rcx,1)
add    $0x1,%eax
jmp    1120 <Cvar_ClearForeignCharacters+0x20>
xor    %eax,%eax
movslq %eax,%rcx
lea    0x2eeb(%rip),%rax
movb   $0x0,(%rcx,%rax,1)
ret

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

LLVM IR (-O2):
@Cvar_ClearForeignCharacters.clean = internal global [256 x i8] zeroinitializer
define i8* @Cvar_ClearForeignCharacters(i8* nocapture %0) {
%2 = load i8, i8* %0
%3 = icmp eq i8 %2, 0
br i1 %3, label %19, label %4
4: ; preds = %1, %13
%5 = phi i64 [ %15, %13 ], [ 0, %1 ]
%6 = phi i8 [ %17, %13 ], [ %2, %1 ]
%7 = phi i32 [ %14, %13 ], [ 0, %1 ]
%8 = icmp sgt i8 %6, -1
br i1 %8, label %9, label %13
9: ; preds = %4
%10 = sext i32 %7 to i64
%11 = getelementptr inbounds [256 x i8], [256 x i8]* @Cvar_ClearForeignCharacters.clean, i64 0, i64 %10
store i8 %6, i8* %11
%12 = add nsw i32 %7, 1
br label %13
13: ; preds = %4, %9
%14 = phi i32 [ %7, %4 ], [ %12, %9 ]
%15 = add nuw i64 %5, 1
%16 = getelementptr inbounds i8, i8* %0, i64 %15
%17 = load i8, i8* %16
%18 = icmp eq i8 %17, 0
br i1 %18, label %19, label %4
19: ; preds = %13, %1
%20 = phi i32 [ 0, %1 ], [ %14, %13 ]
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds [256 x i8], [256 x i8]* @Cvar_ClearForeignCharacters.clean, i64 0, i64 %21
store i8 0, i8* %22
ret i8* getelementptr inbounds ([256 x i8], [256 x i8]* @Cvar_ClearForeignCharacters.clean, i64 0, i64 0)
}