char *subst_prime(char *s) {
  static char *p = "&#x2032;";
  static char b[1024];
  char *t = b;
  while (*s != '\0' && t < b + sizeof(b) - strlen(p) - 1) {
    if (*s == '\'') {
      strcpy(t, p);
      t += strlen(p);
    } else {
      *t++ = *s;
    }
    s++;
  }
  *t = '\0';
  return b;
}


x86 assembly (clang, -O0):
<subst_prime>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
lea    0x2f1d(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x11(%rbp)
je     118a <subst_prime+0x6a>
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    0x2ed5(%rip),%rdi
call   1040 <strlen@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
xor    %edx,%edx
sub    %rcx,%rdx
lea    0x2edd(%rip),%rcx
add    $0x400,%rcx
add    %rdx,%rcx
add    $0xffffffffffffffff,%rcx
cmp    %rcx,%rax
setb   %al
mov    %al,-0x11(%rbp)
mov    -0x11(%rbp),%al
test   $0x1,%al
jne    119a <subst_prime+0x7a>
jmp    11fb <subst_prime+0xdb>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x27,%eax
jne    11d3 <subst_prime+0xb3>
mov    -0x10(%rbp),%rdi
mov    0x2e7b(%rip),%rsi
call   1030 <strcpy@plt>
mov    0x2e6f(%rip),%rdi
call   1040 <strlen@plt>
add    -0x10(%rbp),%rax
mov    %rax,-0x10(%rbp)
jmp    11ea <subst_prime+0xca>
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    1137 <subst_prime+0x17>
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
lea    0x2e47(%rip),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<subst_prime>:
mov    (%rdi),%cl
test   %cl,%cl
je     1168 <subst_prime+0x68>
add    $0x1,%rdi
lea    0x2f1f(%rip),%rax
movabs $0x3b32333032782326,%rsi
33 32 3b
lea    0x3305(%rip),%rdx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
cmp    $0x27,%cl
jne    1150 <subst_prime+0x50>
mov    %rsi,(%rax)
movb   $0x0,0x8(%rax)
add    $0x8,%rax
jmp    1156 <subst_prime+0x56>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %cl,(%rax)
add    $0x1,%rax
movzbl (%rdi),%ecx
test   %cl,%cl
je     116f <subst_prime+0x6f>
add    $0x1,%rdi
cmp    %rdx,%rax
jb     1130 <subst_prime+0x30>
jmp    116f <subst_prime+0x6f>
lea    0x2ec1(%rip),%rax
movb   $0x0,(%rax)
lea    0x2eb7(%rip),%rax
ret

LLVM IR (-O0):
@subst_prime.p = internal global i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i32 0, i32 0)
@.str = [9 x i8] c"&#x2032;\00"
@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 = %37, %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 %17
9: ; preds = %4
%10 = load i8*, i8** %3
%11 = load i8*, i8** @subst_prime.p
%12 = call i64 @strlen(i8* %11)
%13 = sub i64 0, %12
%14 = getelementptr inbounds i8, i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @subst_prime.b, i64 1, i64 0), i64 %13
%15 = getelementptr inbounds i8, i8* %14, i64 -1
%16 = icmp ult i8* %10, %15
br label %17
17: ; preds = %9, %4
%18 = phi i1 [ false, %4 ], [ %16, %9 ]
br i1 %18, label %19, label %40
19: ; preds = %17
%20 = load i8*, i8** %2
%21 = load i8, i8* %20
%22 = sext i8 %21 to i32
%23 = icmp eq i32 %22, 39
br i1 %23, label %24, label %32
24: ; preds = %19
%25 = load i8*, i8** %3
%26 = load i8*, i8** @subst_prime.p
%27 = call i8* @strcpy(i8* %25, i8* %26)
%28 = load i8*, i8** @subst_prime.p
%29 = call i64 @strlen(i8* %28)
%30 = load i8*, i8** %3
%31 = getelementptr inbounds i8, i8* %30, i64 %29
store i8* %31, i8** %3
br label %37
32: ; preds = %19
%33 = load i8*, i8** %2
%34 = load i8, i8* %33
%35 = load i8*, i8** %3
%36 = getelementptr inbounds i8, i8* %35, i32 1
store i8* %36, i8** %3
store i8 %34, i8* %35
br label %37
37: ; preds = %32, %24
%38 = load i8*, i8** %2
%39 = getelementptr inbounds i8, i8* %38, i32 1
store i8* %39, i8** %2
br label %4
40: ; preds = %17
%41 = load i8*, i8** %3
store i8 0, i8* %41
ret i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @subst_prime.b, i64 0, i64 0)
}

LLVM IR (-O2):
@.str = [9 x i8] c"&#x2032;\00"
@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 %20, label %4
4: ; preds = %1, %13
%5 = phi i8 [ %16, %13 ], [ %2, %1 ]
%6 = phi i8* [ %14, %13 ], [ getelementptr inbounds ([1024 x i8], [1024 x i8]* @subst_prime.b, i64 0, i64 0), %1 ]
%7 = phi i8* [ %15, %13 ], [ %0, %1 ]
%8 = icmp eq i8 %5, 39
br i1 %8, label %9, label %11
9: ; preds = %4
tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 1 dereferenceable(9) %6, i8* align 1 dereferenceable(9) getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i64 9, i1 false)
%10 = getelementptr inbounds i8, i8* %6, i64 8
br label %13
11: ; preds = %4
%12 = getelementptr inbounds i8, i8* %6, i64 1
store i8 %5, i8* %6
br label %13
13: ; preds = %11, %9
%14 = phi i8* [ %10, %9 ], [ %12, %11 ]
%15 = getelementptr inbounds i8, i8* %7, i64 1
%16 = load i8, i8* %15
%17 = icmp ne i8 %16, 0
%18 = icmp ult i8* %14, getelementptr inbounds ([1024 x i8], [1024 x i8]* @subst_prime.b, i64 0, i64 1015)
%19 = select i1 %17, i1 %18, i1 false
br i1 %19, label %4, label %20
20: ; preds = %13, %1
%21 = phi i8* [ getelementptr inbounds ([1024 x i8], [1024 x i8]* @subst_prime.b, i64 0, i64 0), %1 ], [ %14, %13 ]
store i8 0, i8* %21
ret i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @subst_prime.b, i64 0, i64 0)
}