#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 /*<<< orphan*/ CU_ASSERT(int);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ strcmp(char *, char *);
char *strdup(char *);
int /*<<< orphan*/ string_escape(char **, int *, int *, char *, int, int);
int strlen(char *);
void test_string_escape_c(void) {
  struct {
    char *input;
    char *output;
  } data[] = {
      {"no change", "no change"},
      {"quoty \" ?", "quoty \\\" ?"},
      {"test \n", "test \\n"},
      {"test \r", "test \\r"},
      {"test \f", "test \\f"},
      {"test \a", "test \\a"},
      {"test \b", "test \\b"},
      {"test \\", "test \\\\"},
      {NULL, NULL},
  };
  int i = 0;
  for (i = 0; data[i].input != NULL; i++) {
    int len, size;
    char *s = strdup(data[i].input);
    len = strlen(s);
    size = len + 1;
    string_escape(&s, &len, &size, "\\\"", 2, 0x0001);
    string_escape(&s, &len, &size, "", 0, 0x0001 | 0x0008);
    if (strcmp(s, data[i].output)) {
      printf("\n");
      printf("'%s' vs '%s' ('%s')\n", data[i].input, s, data[i].output);
      printf("\n");
    }
    CU_ASSERT(!strcmp(s, data[i].output));
    free(s);
  }
}


x86 assembly (clang, -O0):
<test_string_escape_c>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
lea    -0x90(%rbp),%rdi
lea    0x2bf7(%rip),%rsi
mov    $0x90,%edx
call   1090 <memcpy@plt>
movl   $0x0,-0x94(%rbp)
movl   $0x0,-0x94(%rbp)
movslq -0x94(%rbp),%rcx
lea    -0x90(%rbp),%rax
shl    $0x4,%rcx
add    %rcx,%rax
cmpq   $0x0,(%rax)
je     135b <test_string_escape_c+0x1db>
movslq -0x94(%rbp),%rcx
lea    -0x90(%rbp),%rax
shl    $0x4,%rcx
add    %rcx,%rax
mov    (%rax),%rdi
call   10a0 <strdup@plt>
mov    %rax,-0xa8(%rbp)
mov    -0xa8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x98(%rbp)
mov    -0x98(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x9c(%rbp)
lea    -0xa8(%rbp),%rdi
lea    -0x98(%rbp),%rsi
lea    -0x9c(%rbp),%rdx
lea    0xe42(%rip),%rcx
mov    $0x2,%r8d
mov    $0x1,%r9d
call   1060 <string_escape@plt>
lea    -0xa8(%rbp),%rdi
lea    -0x98(%rbp),%rsi
lea    -0x9c(%rbp),%rdx
lea    0xdee(%rip),%rcx
xor    %r8d,%r8d
mov    $0x9,%r9d
call   1060 <string_escape@plt>
mov    -0xa8(%rbp),%rdi
movslq -0x94(%rbp),%rcx
lea    -0x90(%rbp),%rax
shl    $0x4,%rcx
add    %rcx,%rax
mov    0x8(%rax),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
je     1303 <test_string_escape_c+0x183>
lea    0xd7c(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movslq -0x94(%rbp),%rcx
lea    -0x90(%rbp),%rax
shl    $0x4,%rcx
add    %rcx,%rax
mov    (%rax),%rsi
mov    -0xa8(%rbp),%rdx
movslq -0x94(%rbp),%rcx
lea    -0x90(%rbp),%rax
shl    $0x4,%rcx
add    %rcx,%rax
mov    0x8(%rax),%rcx
lea    0xd8e(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xd28(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0xa8(%rbp),%rdi
movslq -0x94(%rbp),%rcx
lea    -0x90(%rbp),%rax
shl    $0x4,%rcx
add    %rcx,%rax
mov    0x8(%rax),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%edi
call   1080 <CU_ASSERT@plt>
mov    -0xa8(%rbp),%rdi
call   1030 <free@plt>
mov    -0x94(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x94(%rbp)
jmp    11b7 <test_string_escape_c+0x37>
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_string_escape_c>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
lea    0x8(%rsp),%r15
lea    0x14(%rsp),%r12
lea    0x10(%rsp),%rbx
xor    %r13d,%r13d
jmp    11e6 <test_string_escape_c+0x66>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    0x8(%rsp),%rdi
mov    %rbp,%rsi
call   1080 <strcmp@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1090 <CU_ASSERT@plt>
mov    0x8(%rsp),%rdi
call   1030 <free@plt>
add    $0x10,%r13
cmp    $0x80,%r13
je     129e <test_string_escape_c+0x11e>
lea    0x2ba3(%rip),%rax
mov    0x0(%r13,%rax,1),%r14
mov    0x8(%r13,%rax,1),%rbp
mov    %r14,%rdi
call   10a0 <strdup@plt>
mov    %rax,0x8(%rsp)
mov    %rax,%rdi
call   1050 <strlen@plt>
mov    %eax,0x14(%rsp)
add    $0x1,%eax
mov    %eax,0x10(%rsp)
mov    %r15,%rdi
mov    %r12,%rsi
mov    %rbx,%rdx
lea    0xe52(%rip),%rcx
mov    $0x2,%r8d
mov    $0x1,%r9d
call   1070 <string_escape@plt>
mov    %r15,%rdi
mov    %r12,%rsi
mov    %rbx,%rdx
lea    0xe0a(%rip),%rcx
xor    %r8d,%r8d
mov    $0x9,%r9d
call   1070 <string_escape@plt>
mov    0x8(%rsp),%rdi
mov    %rbp,%rsi
call   1080 <strcmp@plt>
test   %rax,%rax
je     11b0 <test_string_escape_c+0x30>
mov    $0xa,%edi
call   1040 <putchar@plt>
mov    0x8(%rsp),%rdx
lea    0xdfa(%rip),%rdi
mov    %r14,%rsi
mov    %rbp,%rcx
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0xa,%edi
call   1040 <putchar@plt>
jmp    11b0 <test_string_escape_c+0x30>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.anon = type { i8*, i8* }
@.str = [10 x i8] c"no change\00"
@.str.1 = [10 x i8] c"quoty \22 ?\00"
@.str.2 = [11 x i8] c"quoty \\\22 ?\00"
@.str.3 = [7 x i8] c"test \0A\00"
@.str.4 = [8 x i8] c"test \\n\00"
@.str.5 = [7 x i8] c"test \0D\00"
@.str.6 = [8 x i8] c"test \\r\00"
@.str.7 = [7 x i8] c"test \0C\00"
@.str.8 = [8 x i8] c"test \\f\00"
@.str.9 = [7 x i8] c"test \07\00"
@.str.10 = [8 x i8] c"test \\a\00"
@.str.11 = [7 x i8] c"test \08\00"
@.str.12 = [8 x i8] c"test \\b\00"
@.str.13 = [7 x i8] c"test \\\00"
@.str.14 = [8 x i8] c"test \\\\\00"
@__const.test_string_escape_c.data = [9 x %struct.anon] [%struct.anon { i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i32 0, i32 0) }, %struct.anon { i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i32 0, i32 0) }, %struct.anon { i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i32 0, i32 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i32 0, i32 0) }, %struct.anon { i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i32 0, i32 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i32 0, i32 0) }, %struct.anon { i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.7, i32 0, i32 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.8, i32 0, i32 0) }, %struct.anon { i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.9, i32 0, i32 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.10, i32 0, i32 0) }, %struct.anon { i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.11, i32 0, i32 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.12, i32 0, i32 0) }, %struct.anon { i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.13, i32 0, i32 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.14, i32 0, i32 0) }, %struct.anon zeroinitializer]
@.str.15 = [3 x i8] c"\\\22\00"
@.str.16 = [1 x i8] zeroinitializer
@.str.17 = [2 x i8] c"\0A\00"
@.str.18 = [21 x i8] c"'%s' vs '%s' ('%s')\0A\00"
define void @test_string_escape_c() {
%1 = alloca [9 x %struct.anon]
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
%6 = bitcast [9 x %struct.anon]* %1 to i8*
store i32 0, i32* %2
store i32 0, i32* %2
br label %7
7: ; preds = %64, %0
%8 = load i32, i32* %2
%9 = sext i32 %8 to i64
%10 = getelementptr inbounds [9 x %struct.anon], [9 x %struct.anon]* %1, i64 0, i64 %9
%11 = getelementptr inbounds %struct.anon, %struct.anon* %10, i32 0, i32 0
%12 = load i8*, i8** %11
%13 = icmp ne i8* %12, null
br i1 %13, label %14, label %67
14: ; preds = %7
%15 = load i32, i32* %2
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds [9 x %struct.anon], [9 x %struct.anon]* %1, i64 0, i64 %16
%18 = getelementptr inbounds %struct.anon, %struct.anon* %17, i32 0, i32 0
%19 = load i8*, i8** %18
%20 = call i8* @strdup(i8* %19)
store i8* %20, i8** %5
%21 = load i8*, i8** %5
%22 = call i32 @strlen(i8* %21)
store i32 %22, i32* %3
%23 = load i32, i32* %3
%24 = add nsw i32 %23, 1
store i32 %24, i32* %4
%25 = call i32 @string_escape(i8** %5, i32* %3, i32* %4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.15, i64 0, i64 0), i32 2, i32 1)
%26 = call i32 @string_escape(i8** %5, i32* %3, i32* %4, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.16, i64 0, i64 0), i32 0, i32 9)
%27 = load i8*, i8** %5
%28 = load i32, i32* %2
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds [9 x %struct.anon], [9 x %struct.anon]* %1, i64 0, i64 %29
%31 = getelementptr inbounds %struct.anon, %struct.anon* %30, i32 0, i32 1
%32 = load i8*, i8** %31
%33 = call i64 @strcmp(i8* %27, i8* %32)
%34 = icmp ne i64 %33, 0
br i1 %34, label %35, label %50
35: ; preds = %14
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.17, i64 0, i64 0))
%37 = load i32, i32* %2
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds [9 x %struct.anon], [9 x %struct.anon]* %1, i64 0, i64 %38
%40 = getelementptr inbounds %struct.anon, %struct.anon* %39, i32 0, i32 0
%41 = load i8*, i8** %40
%42 = load i8*, i8** %5
%43 = load i32, i32* %2
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds [9 x %struct.anon], [9 x %struct.anon]* %1, i64 0, i64 %44
%46 = getelementptr inbounds %struct.anon, %struct.anon* %45, i32 0, i32 1
%47 = load i8*, i8** %46
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.18, i64 0, i64 0), i8* %41, i8* %42, i8* %47)
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.17, i64 0, i64 0))
br label %50
50: ; preds = %35, %14
%51 = load i8*, i8** %5
%52 = load i32, i32* %2
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds [9 x %struct.anon], [9 x %struct.anon]* %1, i64 0, i64 %53
%55 = getelementptr inbounds %struct.anon, %struct.anon* %54, i32 0, i32 1
%56 = load i8*, i8** %55
%57 = call i64 @strcmp(i8* %51, i8* %56)
%58 = icmp ne i64 %57, 0
%59 = xor i1 %58, true
%60 = zext i1 %59 to i32
%61 = call i32 @CU_ASSERT(i32 %60)
%62 = load i8*, i8** %5
%63 = call i32 @free(i8* %62)
br label %64
64: ; preds = %50
%65 = load i32, i32* %2
%66 = add nsw i32 %65, 1
store i32 %66, i32* %2
br label %7
67: ; preds = %7
ret void
}

LLVM IR (-O2):
%struct.anon = type { i8*, i8* }
@.str = [10 x i8] c"no change\00"
@.str.1 = [10 x i8] c"quoty \22 ?\00"
@.str.2 = [11 x i8] c"quoty \\\22 ?\00"
@.str.3 = [7 x i8] c"test \0A\00"
@.str.4 = [8 x i8] c"test \\n\00"
@.str.5 = [7 x i8] c"test \0D\00"
@.str.6 = [8 x i8] c"test \\r\00"
@.str.7 = [7 x i8] c"test \0C\00"
@.str.8 = [8 x i8] c"test \\f\00"
@.str.9 = [7 x i8] c"test \07\00"
@.str.10 = [8 x i8] c"test \\a\00"
@.str.11 = [7 x i8] c"test \08\00"
@.str.12 = [8 x i8] c"test \\b\00"
@.str.13 = [7 x i8] c"test \\\00"
@.str.14 = [8 x i8] c"test \\\\\00"
@__const.test_string_escape_c.data = [9 x %struct.anon] [%struct.anon { i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i32 0, i32 0) }, %struct.anon { i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i32 0, i32 0) }, %struct.anon { i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i32 0, i32 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i32 0, i32 0) }, %struct.anon { i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i32 0, i32 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i32 0, i32 0) }, %struct.anon { i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.7, i32 0, i32 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.8, i32 0, i32 0) }, %struct.anon { i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.9, i32 0, i32 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.10, i32 0, i32 0) }, %struct.anon { i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.11, i32 0, i32 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.12, i32 0, i32 0) }, %struct.anon { i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.13, i32 0, i32 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.14, i32 0, i32 0) }, %struct.anon zeroinitializer]
@.str.15 = [3 x i8] c"\\\22\00"
@.str.16 = [1 x i8] zeroinitializer
@.str.18 = [21 x i8] c"'%s' vs '%s' ('%s')\0A\00"
define void @test_string_escape_c() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i8*
%4 = bitcast i32* %1 to i8*
%5 = bitcast i32* %2 to i8*
%6 = bitcast i8** %3 to i8*
br label %7
7: ; preds = %0, %26
%8 = phi i64 [ 0, %0 ], [ %34, %26 ]
%9 = getelementptr inbounds [9 x %struct.anon], [9 x %struct.anon]* @__const.test_string_escape_c.data, i64 0, i64 %8, i32 0
%10 = load i8*, i8** %9
%11 = call i8* @strdup(i8* %10)
store i8* %11, i8** %3
%12 = call i32 @strlen(i8* %11)
store i32 %12, i32* %1
%13 = add nsw i32 %12, 1
store i32 %13, i32* %2
%14 = call i32 @string_escape(i8** %3, i32* %1, i32* %2, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.15, i64 0, i64 0), i32 2, i32 1)
%15 = call i32 @string_escape(i8** %3, i32* %1, i32* %2, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.16, i64 0, i64 0), i32 0, i32 9)
%16 = load i8*, i8** %3
%17 = getelementptr inbounds [9 x %struct.anon], [9 x %struct.anon]* @__const.test_string_escape_c.data, i64 0, i64 %8, i32 1
%18 = load i8*, i8** %17
%19 = call i64 @strcmp(i8* %16, i8* %18)
%20 = icmp eq i64 %19, 0
br i1 %20, label %26, label %21
21: ; preds = %7
%22 = call i32 @putchar(i32 10)
%23 = load i8*, i8** %3
%24 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.18, i64 0, i64 0), i8* %10, i8* %23, i8* %18)
%25 = call i32 @putchar(i32 10)
br label %26
26: ; preds = %21, %7
%27 = load i8*, i8** %3
%28 = call i64 @strcmp(i8* %27, i8* %18)
%29 = icmp eq i64 %28, 0
%30 = zext i1 %29 to i32
%31 = call i32 @CU_ASSERT(i32 %30)
%32 = load i8*, i8** %3
%33 = call i32 @free(i8* %32)
%34 = add nuw nsw i64 %8, 1
%35 = icmp eq i64 %34, 8
br i1 %35, label %36, label %7
36: ; preds = %26
ret void
}