#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 */
int simple_escape_str(char *dst, const char *src, size_t n) {
  unsigned char c;
  size_t i;
  const char *codes = "Z-------------------------------"
                      "********************************"
                      "********************************"
                      "*******************************-"
                      "--------------------------------"
                      "********************************"
                      "********************************"
                      "********************************";
  for (i = 0; i < n;) {
    c = (unsigned char)*(src++);
    switch (codes[c]) {
    case 'Z':
      goto leave;
    case '*':
      i++;
      *(dst++) = c;
      break;
    case '-':
      i++;
      *(dst++) = '?';
      break;
    }
  }
leave:
  *(dst++) = '\0';
  return i;
}


x86 assembly (clang, -O0):
<simple_escape_str>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
lea    0xee9(%rip),%rax
mov    %rax,-0x30(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    11d1 <simple_escape_str+0xd1>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
mov    (%rax),%al
mov    %al,-0x19(%rbp)
mov    -0x30(%rbp),%rax
movzbl -0x19(%rbp),%ecx
movsbl (%rax,%rcx,1),%eax
mov    %eax,-0x34(%rbp)
sub    $0x2a,%eax
je     1189 <simple_escape_str+0x89>
jmp    1162 <simple_escape_str+0x62>
mov    -0x34(%rbp),%eax
sub    $0x2d,%eax
je     11ae <simple_escape_str+0xae>
jmp    1173 <simple_escape_str+0x73>
mov    -0x34(%rbp),%eax
sub    $0x5a,%eax
jne    11cc <simple_escape_str+0xcc>
jmp    1184 <simple_escape_str+0x84>
jmp    11d6 <simple_escape_str+0xd6>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
mov    -0x19(%rbp),%cl
mov    -0x8(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x8(%rbp)
mov    %cl,(%rax)
jmp    11cc <simple_escape_str+0xcc>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
movb   $0x3f,(%rax)
jmp    1123 <simple_escape_str+0x23>
jmp    11d6 <simple_escape_str+0xd6>
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
movb   $0x0,(%rax)
mov    -0x28(%rbp),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<simple_escape_str>:
xor    %eax,%eax
test   %rdx,%rdx
je     113f <simple_escape_str+0x3f>
lea    0xef2(%rip),%r8
jmp    1127 <simple_escape_str+0x27>
mov    $0x3f,%r9b
add    $0x1,%rax
mov    %r9b,(%rdi)
add    $0x1,%rdi
add    $0x1,%rsi
cmp    %rdx,%rax
jae    113f <simple_escape_str+0x3f>
movzbl (%rsi),%r9d
movsbl (%r9,%r8,1),%ecx
cmp    $0x2a,%ecx
je     1113 <simple_escape_str+0x13>
cmp    $0x2d,%ecx
je     1110 <simple_escape_str+0x10>
cmp    $0x5a,%ecx
jne    111e <simple_escape_str+0x1e>
movb   $0x0,(%rdi)
ret

LLVM IR (-O0):
@.str = [257 x i8] c"Z-------------------------------***********************************************************************************************---------------------------------************************************************************************************************\00"
define i32 @simple_escape_str(i8* %0, i8* %1, i64 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i8
%8 = alloca i64
%9 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
store i64 %2, i64* %6
store i8* getelementptr inbounds ([257 x i8], [257 x i8]* @.str, i64 0, i64 0), i8** %9
store i64 0, i64* %8
br label %10
10: ; preds = %36, %3
%11 = load i64, i64* %8
%12 = load i64, i64* %6
%13 = icmp ult i64 %11, %12
br i1 %13, label %14, label %37
14: ; preds = %10
%15 = load i8*, i8** %5
%16 = getelementptr inbounds i8, i8* %15, i32 1
store i8* %16, i8** %5
%17 = load i8, i8* %15
store i8 %17, i8* %7
%18 = load i8*, i8** %9
%19 = load i8, i8* %7
%20 = zext i8 %19 to i64
%21 = getelementptr inbounds i8, i8* %18, i64 %20
%22 = load i8, i8* %21
%23 = sext i8 %22 to i32
switch i32 %23, label %36 [
i32 90, label %24
i32 42, label %25
i32 45, label %31
]
24: ; preds = %14
br label %38
25: ; preds = %14
%26 = load i64, i64* %8
%27 = add i64 %26, 1
store i64 %27, i64* %8
%28 = load i8, i8* %7
%29 = load i8*, i8** %4
%30 = getelementptr inbounds i8, i8* %29, i32 1
store i8* %30, i8** %4
store i8 %28, i8* %29
br label %36
31: ; preds = %14
%32 = load i64, i64* %8
%33 = add i64 %32, 1
store i64 %33, i64* %8
%34 = load i8*, i8** %4
%35 = getelementptr inbounds i8, i8* %34, i32 1
store i8* %35, i8** %4
store i8 63, i8* %34
br label %36
36: ; preds = %14, %31, %25
br label %10
37: ; preds = %10
br label %38
38: ; preds = %37, %24
%39 = load i8*, i8** %4
%40 = getelementptr inbounds i8, i8* %39, i32 1
store i8* %40, i8** %4
store i8 0, i8* %39
%41 = load i64, i64* %8
%42 = trunc i64 %41 to i32
ret i32 %42
}

LLVM IR (-O2):
@.str = [257 x i8] c"Z-------------------------------***********************************************************************************************---------------------------------************************************************************************************************\00"
define i32 @simple_escape_str(i8* nocapture writeonly %0, i8* nocapture %1, i64 %2) {
%4 = icmp eq i64 %2, 0
br i1 %4, label %24, label %5
5: ; preds = %3, %20
%6 = phi i8* [ %22, %20 ], [ %0, %3 ]
%7 = phi i64 [ %21, %20 ], [ 0, %3 ]
%8 = phi i8* [ %9, %20 ], [ %1, %3 ]
%9 = getelementptr inbounds i8, i8* %8, i64 1
%10 = load i8, i8* %8
%11 = zext i8 %10 to i64
%12 = getelementptr inbounds [257 x i8], [257 x i8]* @.str, i64 0, i64 %11
%13 = load i8, i8* %12
%14 = sext i8 %13 to i32
switch i32 %14, label %20 [
i32 90, label %24
i32 42, label %16
i32 45, label %15
]
15: ; preds = %5
br label %16
16: ; preds = %5, %15
%17 = phi i8 [ 63, %15 ], [ %10, %5 ]
%18 = add nuw i64 %7, 1
%19 = getelementptr inbounds i8, i8* %6, i64 1
store i8 %17, i8* %6
br label %20
20: ; preds = %16, %5
%21 = phi i64 [ %7, %5 ], [ %18, %16 ]
%22 = phi i8* [ %6, %5 ], [ %19, %16 ]
%23 = icmp ult i64 %21, %2
br i1 %23, label %5, label %24
24: ; preds = %5, %20, %3
%25 = phi i64 [ 0, %3 ], [ %21, %20 ], [ %7, %5 ]
%26 = phi i8* [ %0, %3 ], [ %22, %20 ], [ %6, %5 ]
store i8 0, i8* %26
%27 = trunc i64 %25 to i32
ret i32 %27
}