char *subst_prime(char *s) {
  static char b[1024];
  char *t = b;
  while (*s != '\0' && t < b + sizeof(b) - 4) {
    if (*s == '\'') {
      *t++ = 0xe2;
      *t++ = 0x80;
      *t++ = 0xb2;
    } else {
      *t++ = *s;
    }
    s++;
  }
  *t = '\0';
  return b;
}


x86 assembly (clang, -O0):
<subst_prime>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
lea    0x2f21(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x11(%rbp)
je     113f <subst_prime+0x3f>
lea    0x2f01(%rip),%rax
add    $0x3fc,%rax
cmp    %rax,-0x10(%rbp)
setb   %al
mov    %al,-0x11(%rbp)
mov    -0x11(%rbp),%al
test   $0x1,%al
jne    114f <subst_prime+0x4f>
jmp    11c2 <subst_prime+0xc2>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x27,%eax
jne    119a <subst_prime+0x9a>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movb   $0xe2,(%rax)
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movb   $0x80,(%rax)
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movb   $0xb2,(%rax)
jmp    11b1 <subst_prime+0xb1>
mov    -0x8(%rbp),%rax
mov    (%rax),%cl
mov    -0x10(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x10(%rbp)
mov    %cl,(%rax)
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    1113 <subst_prime+0x13>
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
lea    0x2e60(%rip),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<subst_prime>:
mov    (%rdi),%dl
test   %dl,%dl
je     1158 <subst_prime+0x58>
add    $0x1,%rdi
lea    0x2f1f(%rip),%rax
lea    0x3314(%rip),%rcx
nopl   0x0(%rax,%rax,1)
cmp    $0x27,%dl
jne    1140 <subst_prime+0x40>
movw   $0x80e2,(%rax)
movb   $0xb2,0x2(%rax)
add    $0x3,%rax
jmp    1146 <subst_prime+0x46>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %dl,(%rax)
add    $0x1,%rax
movzbl (%rdi),%edx
test   %dl,%dl
je     115f <subst_prime+0x5f>
add    $0x1,%rdi
cmp    %rcx,%rax
jb     1120 <subst_prime+0x20>
jmp    115f <subst_prime+0x5f>
lea    0x2ed1(%rip),%rax
movb   $0x0,(%rax)
lea    0x2ec7(%rip),%rax
ret

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

LLVM IR (-O2):
@subst_prime.b = internal global [1024 x i8] zeroinitializer
define i8* @subst_prime(i8* nocapture %0) {
%2 = load i8, i8* %0
%3 = icmp eq i8 %2, 0
br i1 %3, label %21, label %4
4: ; preds = %1, %14
%5 = phi i8 [ %17, %14 ], [ %2, %1 ]
%6 = phi i8* [ %15, %14 ], [ getelementptr inbounds ([1024 x i8], [1024 x i8]* @subst_prime.b, i64 0, i64 0), %1 ]
%7 = phi i8* [ %16, %14 ], [ %0, %1 ]
%8 = icmp eq i8 %5, 39
%9 = getelementptr inbounds i8, i8* %6, i64 1
br i1 %8, label %10, label %13
10: ; preds = %4
store i8 -30, i8* %6
%11 = getelementptr inbounds i8, i8* %6, i64 2
store i8 -128, i8* %9
%12 = getelementptr inbounds i8, i8* %6, i64 3
store i8 -78, i8* %11
br label %14
13: ; preds = %4
store i8 %5, i8* %6
br label %14
14: ; preds = %13, %10
%15 = phi i8* [ %12, %10 ], [ %9, %13 ]
%16 = getelementptr inbounds i8, i8* %7, i64 1
%17 = load i8, i8* %16
%18 = icmp ne i8 %17, 0
%19 = icmp ult i8* %15, getelementptr inbounds ([1024 x i8], [1024 x i8]* @subst_prime.b, i64 0, i64 1020)
%20 = select i1 %18, i1 %19, i1 false
br i1 %20, label %4, label %21
21: ; preds = %14, %1
%22 = phi i8* [ getelementptr inbounds ([1024 x i8], [1024 x i8]* @subst_prime.b, i64 0, i64 0), %1 ], [ %15, %14 ]
store i8 0, i8* %22
ret i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @subst_prime.b, i64 0, i64 0)
}