#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*/ iscntrl(char const);
int /*<<< orphan*/ printf(char *, char const);
int /*<<< orphan*/ putchar(char const);
int json_print_string(const char *string) {
  putchar('"');
  while (*string) {
    switch (*string) {
    case '\b':
      putchar('\\');
      putchar('b');
      break;
    case '\f':
      putchar('\\');
      putchar('f');
      break;
    case '\n':
      putchar('\\');
      putchar('n');
      break;
    case '\r':
      putchar('\\');
      putchar('r');
      break;
    case '\t':
      putchar('\\');
      putchar('t');
      break;
    case '"':
      putchar('\\');
      putchar('"');
      break;
    case '\\':
      putchar('\\');
      putchar('\\');
      break;
    default:
      if (iscntrl(*string))
        printf("\\x%x", *string);
      else
        putchar(*string);
      break;
    }
    ++string;
  }
  putchar('"');
  return 0;
}


x86 assembly (clang, -O0):
<json_print_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x22,%edi
call   1030 <putchar@plt>
mov    -0x8(%rbp),%rax
cmpb   $0x0,(%rax)
je     12cf <json_print_string+0x19f>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
mov    %eax,-0xc(%rbp)
sub    $0x8,%eax
je     11d1 <json_print_string+0xa1>
jmp    116b <json_print_string+0x3b>
mov    -0xc(%rbp),%eax
sub    $0x9,%eax
je     1235 <json_print_string+0x105>
jmp    117c <json_print_string+0x4c>
mov    -0xc(%rbp),%eax
sub    $0xa,%eax
je     1203 <json_print_string+0xd3>
jmp    118d <json_print_string+0x5d>
mov    -0xc(%rbp),%eax
sub    $0xc,%eax
je     11ea <json_print_string+0xba>
jmp    119e <json_print_string+0x6e>
mov    -0xc(%rbp),%eax
sub    $0xd,%eax
je     121c <json_print_string+0xec>
jmp    11af <json_print_string+0x7f>
mov    -0xc(%rbp),%eax
sub    $0x22,%eax
je     124e <json_print_string+0x11e>
jmp    11c0 <json_print_string+0x90>
mov    -0xc(%rbp),%eax
sub    $0x5c,%eax
je     1267 <json_print_string+0x137>
jmp    1280 <json_print_string+0x150>
mov    $0x5c,%edi
call   1030 <putchar@plt>
mov    $0x62,%edi
call   1030 <putchar@plt>
jmp    12be <json_print_string+0x18e>
mov    $0x5c,%edi
call   1030 <putchar@plt>
mov    $0x66,%edi
call   1030 <putchar@plt>
jmp    12be <json_print_string+0x18e>
mov    $0x5c,%edi
call   1030 <putchar@plt>
mov    $0x6e,%edi
call   1030 <putchar@plt>
jmp    12be <json_print_string+0x18e>
mov    $0x5c,%edi
call   1030 <putchar@plt>
mov    $0x72,%edi
call   1030 <putchar@plt>
jmp    12be <json_print_string+0x18e>
mov    $0x5c,%edi
call   1030 <putchar@plt>
mov    $0x74,%edi
call   1030 <putchar@plt>
jmp    12be <json_print_string+0x18e>
mov    $0x5c,%edi
call   1030 <putchar@plt>
mov    $0x22,%edi
call   1030 <putchar@plt>
jmp    12be <json_print_string+0x18e>
mov    $0x5c,%edi
call   1030 <putchar@plt>
mov    $0x5c,%edi
call   1030 <putchar@plt>
jmp    12be <json_print_string+0x18e>
mov    -0x8(%rbp),%rax
movsbl (%rax),%edi
call   1040 <iscntrl@plt>
cmp    $0x0,%eax
je     12ad <json_print_string+0x17d>
mov    -0x8(%rbp),%rax
lea    0xd60(%rip),%rdi
movsbl (%rax),%esi
call   1050 <printf@plt>
jmp    12b9 <json_print_string+0x189>
mov    -0x8(%rbp),%rax
movsbl (%rax),%edi
call   1030 <putchar@plt>
jmp    12be <json_print_string+0x18e>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    1146 <json_print_string+0x16>
mov    $0x22,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<json_print_string>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%rbx
mov    $0x22,%edi
call   1030 <putchar@plt>
mov    (%rbx),%al
test   %al,%al
je     1224 <json_print_string+0xf4>
add    $0x1,%rbx
lea    0xf15(%rip),%r14
lea    0xea2(%rip),%r15
xchg   %ax,%ax
movsbl %al,%edi
lea    -0x8(%rdi),%eax
cmp    $0x1a,%eax
ja     1188 <json_print_string+0x58>
movslq (%r15,%rax,4),%rax
add    %r15,%rax
jmp    *%rax
mov    $0x5c,%edi
call   1030 <putchar@plt>
mov    $0x62,%edi
jmp    1210 <json_print_string+0xe0>
cmp    $0x5c,%edi
jne    119e <json_print_string+0x6e>
mov    $0x5c,%edi
call   1030 <putchar@plt>
mov    $0x5c,%edi
jmp    1210 <json_print_string+0xe0>
call   1040 <iscntrl@plt>
movzbl -0x1(%rbx),%ecx
test   %eax,%eax
je     120d <json_print_string+0xdd>
movsbl %cl,%esi
mov    %r14,%rdi
call   1050 <printf@plt>
jmp    1215 <json_print_string+0xe5>
mov    $0x5c,%edi
call   1030 <putchar@plt>
mov    $0x74,%edi
jmp    1210 <json_print_string+0xe0>
mov    $0x5c,%edi
call   1030 <putchar@plt>
mov    $0x6e,%edi
jmp    1210 <json_print_string+0xe0>
mov    $0x5c,%edi
call   1030 <putchar@plt>
mov    $0x66,%edi
jmp    1210 <json_print_string+0xe0>
mov    $0x5c,%edi
call   1030 <putchar@plt>
mov    $0x72,%edi
jmp    1210 <json_print_string+0xe0>
mov    $0x5c,%edi
call   1030 <putchar@plt>
mov    $0x22,%edi
jmp    1210 <json_print_string+0xe0>
movsbl %cl,%edi
call   1030 <putchar@plt>
movzbl (%rbx),%eax
add    $0x1,%rbx
test   %al,%al
jne    1160 <json_print_string+0x30>
mov    $0x22,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [5 x i8] c"\\x%x\00"
define i32 @json_print_string(i8* %0) {
%2 = alloca i8*
store i8* %0, i8** %2
%3 = call i32 @putchar(i8 signext 34)
br label %4
4: ; preds = %47, %1
%5 = load i8*, i8** %2
%6 = load i8, i8* %5
%7 = icmp ne i8 %6, 0
br i1 %7, label %8, label %50
8: ; preds = %4
%9 = load i8*, i8** %2
%10 = load i8, i8* %9
%11 = sext i8 %10 to i32
switch i32 %11, label %33 [
i32 8, label %12
i32 12, label %15
i32 10, label %18
i32 13, label %21
i32 9, label %24
i32 34, label %27
i32 92, label %30
]
12: ; preds = %8
%13 = call i32 @putchar(i8 signext 92)
%14 = call i32 @putchar(i8 signext 98)
br label %47
15: ; preds = %8
%16 = call i32 @putchar(i8 signext 92)
%17 = call i32 @putchar(i8 signext 102)
br label %47
18: ; preds = %8
%19 = call i32 @putchar(i8 signext 92)
%20 = call i32 @putchar(i8 signext 110)
br label %47
21: ; preds = %8
%22 = call i32 @putchar(i8 signext 92)
%23 = call i32 @putchar(i8 signext 114)
br label %47
24: ; preds = %8
%25 = call i32 @putchar(i8 signext 92)
%26 = call i32 @putchar(i8 signext 116)
br label %47
27: ; preds = %8
%28 = call i32 @putchar(i8 signext 92)
%29 = call i32 @putchar(i8 signext 34)
br label %47
30: ; preds = %8
%31 = call i32 @putchar(i8 signext 92)
%32 = call i32 @putchar(i8 signext 92)
br label %47
33: ; preds = %8
%34 = load i8*, i8** %2
%35 = load i8, i8* %34
%36 = call i32 @iscntrl(i8 signext %35)
%37 = icmp ne i32 %36, 0
br i1 %37, label %38, label %42
38: ; preds = %33
%39 = load i8*, i8** %2
%40 = load i8, i8* %39
%41 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 signext %40)
br label %46
42: ; preds = %33
%43 = load i8*, i8** %2
%44 = load i8, i8* %43
%45 = call i32 @putchar(i8 signext %44)
br label %46
46: ; preds = %42, %38
br label %47
47: ; preds = %46, %30, %27, %24, %21, %18, %15, %12
%48 = load i8*, i8** %2
%49 = getelementptr inbounds i8, i8* %48, i32 1
store i8* %49, i8** %2
br label %4
50: ; preds = %4
%51 = call i32 @putchar(i8 signext 34)
ret i32 0
}

LLVM IR (-O2):
@.str = [5 x i8] c"\\x%x\00"
define i32 @json_print_string(i8* nocapture %0) {
%2 = tail call i32 @putchar(i8 signext 34)
%3 = load i8, i8* %0
%4 = icmp eq i8 %3, 0
br i1 %4, label %42, label %5
5: ; preds = %1, %38
%6 = phi i8 [ %40, %38 ], [ %3, %1 ]
%7 = phi i8* [ %39, %38 ], [ %0, %1 ]
%8 = sext i8 %6 to i32
switch i32 %8, label %30 [
i32 8, label %9
i32 12, label %12
i32 10, label %15
i32 13, label %18
i32 9, label %21
i32 34, label %24
i32 92, label %27
]
9: ; preds = %5
%10 = tail call i32 @putchar(i8 signext 92)
%11 = tail call i32 @putchar(i8 signext 98)
br label %38
12: ; preds = %5
%13 = tail call i32 @putchar(i8 signext 92)
%14 = tail call i32 @putchar(i8 signext 102)
br label %38
15: ; preds = %5
%16 = tail call i32 @putchar(i8 signext 92)
%17 = tail call i32 @putchar(i8 signext 110)
br label %38
18: ; preds = %5
%19 = tail call i32 @putchar(i8 signext 92)
%20 = tail call i32 @putchar(i8 signext 114)
br label %38
21: ; preds = %5
%22 = tail call i32 @putchar(i8 signext 92)
%23 = tail call i32 @putchar(i8 signext 116)
br label %38
24: ; preds = %5
%25 = tail call i32 @putchar(i8 signext 92)
%26 = tail call i32 @putchar(i8 signext 34)
br label %38
27: ; preds = %5
%28 = tail call i32 @putchar(i8 signext 92)
%29 = tail call i32 @putchar(i8 signext 92)
br label %38
30: ; preds = %5
%31 = tail call i32 @iscntrl(i8 signext %6)
%32 = icmp eq i32 %31, 0
%33 = load i8, i8* %7
br i1 %32, label %36, label %34
34: ; preds = %30
%35 = tail call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 signext %33)
br label %38
36: ; preds = %30
%37 = tail call i32 @putchar(i8 signext %33)
br label %38
38: ; preds = %34, %36, %27, %24, %21, %18, %15, %12, %9
%39 = getelementptr inbounds i8, i8* %7, i64 1
%40 = load i8, i8* %39
%41 = icmp eq i8 %40, 0
br i1 %41, label %42, label %5
42: ; preds = %38, %1
%43 = tail call i32 @putchar(i8 signext 34)
ret i32 0
}