#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 */
scalar_t__ isprint(char);
int /*<<< orphan*/ memcpy(char *, char *, int);
void string_escape_like_c(char c, char *replstr, int *replstr_len, int *op) {
  char *r = NULL;
  if (isprint(c)) {
    *op = 1;
    r = "\\";
    *replstr_len = 1;
  } else {
    *op = 2;
    switch (c) {
    case '\n':
      r = "\\n";
      break;
    case '\r':
      r = "\\r";
      break;
    case '\b':
      r = "\\b";
      break;
    case '\f':
      r = "\\f";
      break;
    case '\t':
      r = "\\t";
      break;
    case '\a':
      r = "\\a";
      break;
    }
    if (r) {
      *replstr_len = 2;
    } else {
      *replstr_len = 0;
    }
  }
  memcpy(replstr, r, *replstr_len);
}


x86 assembly (clang, -O0):
<string_escape_like_c>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %dil,%al
mov    %al,-0x1(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
movsbl -0x1(%rbp),%edi
call   1040 <isprint@plt>
cmp    $0x0,%rax
je     1179 <string_escape_like_c+0x59>
mov    -0x20(%rbp),%rax
movl   $0x1,(%rax)
lea    0xeb6(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rax
movl   $0x1,(%rax)
jmp    1231 <string_escape_like_c+0x111>
mov    -0x20(%rbp),%rax
movl   $0x2,(%rax)
movsbl -0x1(%rbp),%eax
add    $0xfffffff9,%eax
mov    %eax,%ecx
mov    %rcx,-0x30(%rbp)
sub    $0x6,%eax
ja     1208 <string_escape_like_c+0xe8>
mov    -0x30(%rbp),%rax
lea    0xe5c(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    0xe6a(%rip),%rax
mov    %rax,-0x28(%rbp)
jmp    1208 <string_escape_like_c+0xe8>
lea    0xe5d(%rip),%rax
mov    %rax,-0x28(%rbp)
jmp    1208 <string_escape_like_c+0xe8>
lea    0xe50(%rip),%rax
mov    %rax,-0x28(%rbp)
jmp    1208 <string_escape_like_c+0xe8>
lea    0xe43(%rip),%rax
mov    %rax,-0x28(%rbp)
jmp    1208 <string_escape_like_c+0xe8>
lea    0xe36(%rip),%rax
mov    %rax,-0x28(%rbp)
jmp    1208 <string_escape_like_c+0xe8>
lea    0xe29(%rip),%rax
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     1222 <string_escape_like_c+0x102>
mov    -0x18(%rbp),%rax
movl   $0x2,(%rax)
jmp    122c <string_escape_like_c+0x10c>
mov    -0x18(%rbp),%rax
movl   $0x0,(%rax)
jmp    1231 <string_escape_like_c+0x111>
mov    -0x10(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x18(%rbp),%rax
mov    (%rax),%edx
call   1030 <memcpy@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<string_escape_like_c>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rcx,%rbx
mov    %rdx,%r14
mov    %rsi,%r15
mov    %edi,%ebp
call   1040 <isprint@plt>
test   %rax,%rax
je     1150 <string_escape_like_c+0x30>
movl   $0x1,(%rbx)
lea    0xeb7(%rip),%rsi
mov    $0x1,%edx
jmp    117f <string_escape_like_c+0x5f>
movl   $0x2,(%rbx)
movsbl %bpl,%eax
add    $0xfffffff9,%eax
cmp    $0x6,%eax
ja     117b <string_escape_like_c+0x5b>
cltq
lea    0xea9(%rip),%rcx
mov    (%rcx,%rax,4),%edx
lea    0x2c73(%rip),%rcx
mov    (%rcx,%rax,8),%rsi
jmp    117f <string_escape_like_c+0x5f>
xor    %edx,%edx
xor    %esi,%esi
mov    %edx,(%r14)
mov    %r15,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <memcpy@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"\\\00"
@.str.1 = [3 x i8] c"\\n\00"
@.str.2 = [3 x i8] c"\\r\00"
@.str.3 = [3 x i8] c"\\b\00"
@.str.4 = [3 x i8] c"\\f\00"
@.str.5 = [3 x i8] c"\\t\00"
@.str.6 = [3 x i8] c"\\a\00"
define void @string_escape_like_c(i8 signext %0, i8* %1, i32* %2, i32* %3) {
%5 = alloca i8
%6 = alloca i8*
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca i8*
store i8 %0, i8* %5
store i8* %1, i8** %6
store i32* %2, i32** %7
store i32* %3, i32** %8
store i8* null, i8** %9
%10 = load i8, i8* %5
%11 = call i64 @isprint(i8 signext %10)
%12 = icmp ne i64 %11, 0
br i1 %12, label %13, label %16
13: ; preds = %4
%14 = load i32*, i32** %8
store i32 1, i32* %14
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8** %9
%15 = load i32*, i32** %7
store i32 1, i32* %15
br label %34
16: ; preds = %4
%17 = load i32*, i32** %8
store i32 2, i32* %17
%18 = load i8, i8* %5
%19 = sext i8 %18 to i32
switch i32 %19, label %26 [
i32 10, label %20
i32 13, label %21
i32 8, label %22
i32 12, label %23
i32 9, label %24
i32 7, label %25
]
20: ; preds = %16
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8** %9
br label %26
21: ; preds = %16
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8** %9
br label %26
22: ; preds = %16
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8** %9
br label %26
23: ; preds = %16
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8** %9
br label %26
24: ; preds = %16
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i8** %9
br label %26
25: ; preds = %16
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i8** %9
br label %26
26: ; preds = %16, %25, %24, %23, %22, %21, %20
%27 = load i8*, i8** %9
%28 = icmp ne i8* %27, null
br i1 %28, label %29, label %31
29: ; preds = %26
%30 = load i32*, i32** %7
store i32 2, i32* %30
br label %33
31: ; preds = %26
%32 = load i32*, i32** %7
store i32 0, i32* %32
br label %33
33: ; preds = %31, %29
br label %34
34: ; preds = %33, %13
%35 = load i8*, i8** %6
%36 = load i8*, i8** %9
%37 = load i32*, i32** %7
%38 = load i32, i32* %37
%39 = call i32 @memcpy(i8* %35, i8* %36, i32 %38)
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"\\\00"
@.str.1 = [3 x i8] c"\\n\00"
@.str.2 = [3 x i8] c"\\r\00"
@.str.3 = [3 x i8] c"\\b\00"
@.str.4 = [3 x i8] c"\\f\00"
@.str.5 = [3 x i8] c"\\t\00"
@.str.6 = [3 x i8] c"\\a\00"
@switch.table.string_escape_like_c = [7 x i32] [i32 2, i32 2, i32 2, i32 2, i32 0, i32 2, i32 2]
@switch.table.string_escape_like_c.7 = [7 x i8*] [i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* null, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0)]
define void @string_escape_like_c(i8 signext %0, i8* %1, i32* nocapture %2, i32* nocapture writeonly %3) {
%5 = tail call i64 @isprint(i8 signext %0)
%6 = icmp eq i64 %5, 0
br i1 %6, label %8, label %7
7: ; preds = %4
store i32 1, i32* %3
br label %19
8: ; preds = %4
store i32 2, i32* %3
%9 = sext i8 %0 to i32
%10 = add nsw i32 %9, -7
%11 = icmp ult i32 %10, 7
br i1 %11, label %12, label %19
12: ; preds = %8
%13 = sext i32 %10 to i64
%14 = getelementptr inbounds [7 x i32], [7 x i32]* @switch.table.string_escape_like_c, i64 0, i64 %13
%15 = load i32, i32* %14
%16 = sext i32 %10 to i64
%17 = getelementptr inbounds [7 x i8*], [7 x i8*]* @switch.table.string_escape_like_c.7, i64 0, i64 %16
%18 = load i8*, i8** %17
br label %19
19: ; preds = %8, %12, %7
%20 = phi i32 [ 1, %7 ], [ %15, %12 ], [ 0, %8 ]
%21 = phi i8* [ getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), %7 ], [ %18, %12 ], [ null, %8 ]
store i32 %20, i32* %2
%22 = tail call i32 @memcpy(i8* %1, i8* %21, i32 %20)
ret void
}