#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 EBADMSG;
int errno;
int /*<<< orphan*/ memmove(char *, char *, size_t);
scalar_t__ strchr(char *, char);
size_t strlen(char *);
int libqwaitclient_login_information_jsonify_strings(char *restrict data) {
  size_t i, j, n = strlen(data);
  int escape = 0;
  char quote = '\0';
  for (i = 0, j = n + 1; i < n; i++) {
    char c = data[i];
    if (quote != '\0') {
      if (escape)
        escape = 0;
      else if (c == '\\')
        escape = 1;
      else if (c == quote)
        quote = '\0', c = '\"';
      else if (c == '"') {
        if (data[j] == '\0')
          return errno = EBADMSG, -1;
        data[j++] = '\\';
      }
    } else if (strchr("\'\"", c))
      quote = c, c = '"';
    if (data[j] == '\0')
      return errno = EBADMSG, -1;
    data[j++] = c;
  }
  j--;
  memmove(data, data + n + 1, (j - n) * sizeof(char));
  data[j - n] = '\0';
  return 0;
}


x86 assembly (clang, -O0):
<libqwaitclient_login_information_jsonify_strings>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
movb   $0x0,-0x2d(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x28(%rbp),%rax
jae    12ce <libqwaitclient_login_information_jsonify_strings+0x19e>
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x2e(%rbp)
movsbl -0x2d(%rbp),%eax
cmp    $0x0,%eax
je     1248 <libqwaitclient_login_information_jsonify_strings+0x118>
cmpl   $0x0,-0x2c(%rbp)
je     11a7 <libqwaitclient_login_information_jsonify_strings+0x77>
movl   $0x0,-0x2c(%rbp)
jmp    1243 <libqwaitclient_login_information_jsonify_strings+0x113>
movsbl -0x2e(%rbp),%eax
cmp    $0x5c,%eax
jne    11c0 <libqwaitclient_login_information_jsonify_strings+0x90>
movl   $0x1,-0x2c(%rbp)
jmp    123e <libqwaitclient_login_information_jsonify_strings+0x10e>
movsbl -0x2e(%rbp),%eax
movsbl -0x2d(%rbp),%ecx
cmp    %ecx,%eax
jne    11dd <libqwaitclient_login_information_jsonify_strings+0xad>
movb   $0x0,-0x2d(%rbp)
movb   $0x22,-0x2e(%rbp)
jmp    1239 <libqwaitclient_login_information_jsonify_strings+0x109>
movsbl -0x2e(%rbp),%eax
cmp    $0x22,%eax
jne    1234 <libqwaitclient_login_information_jsonify_strings+0x104>
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
jne    121d <libqwaitclient_login_information_jsonify_strings+0xed>
mov    0x2de2(%rip),%rax
mov    (%rax),%ecx
mov    0x2dc9(%rip),%rax
mov    %ecx,(%rax)
movl   $0xffffffff,-0x4(%rbp)
jmp    1312 <libqwaitclient_login_information_jsonify_strings+0x1e2>
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    %rcx,%rdx
add    $0x1,%rdx
mov    %rdx,-0x20(%rbp)
movb   $0x5c,(%rax,%rcx,1)
jmp    1239 <libqwaitclient_login_information_jsonify_strings+0x109>
jmp    123e <libqwaitclient_login_information_jsonify_strings+0x10e>
jmp    1243 <libqwaitclient_login_information_jsonify_strings+0x113>
jmp    1271 <libqwaitclient_login_information_jsonify_strings+0x141>
lea    0xdb1(%rip),%rdi
movsbl -0x2e(%rbp),%esi
call   1040 <strchr@plt>
cmp    $0x0,%rax
je     126c <libqwaitclient_login_information_jsonify_strings+0x13c>
mov    -0x2e(%rbp),%al
mov    %al,-0x2d(%rbp)
movb   $0x22,-0x2e(%rbp)
jmp    1271 <libqwaitclient_login_information_jsonify_strings+0x141>
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
jne    12a4 <libqwaitclient_login_information_jsonify_strings+0x174>
mov    0x2d5b(%rip),%rax
mov    (%rax),%ecx
mov    0x2d42(%rip),%rax
mov    %ecx,(%rax)
movl   $0xffffffff,-0x4(%rbp)
jmp    1312 <libqwaitclient_login_information_jsonify_strings+0x1e2>
mov    -0x2e(%rbp),%dl
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    %rcx,%rsi
add    $0x1,%rsi
mov    %rsi,-0x20(%rbp)
mov    %dl,(%rax,%rcx,1)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1168 <libqwaitclient_login_information_jsonify_strings+0x38>
mov    -0x20(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x10(%rbp),%rsi
add    -0x28(%rbp),%rsi
add    $0x1,%rsi
mov    -0x20(%rbp),%rdx
sub    -0x28(%rbp),%rdx
shl    $0x0,%rdx
call   1050 <memmove@plt>
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%rcx
sub    -0x28(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<libqwaitclient_login_information_jsonify_strings>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r12
call   1030 <strlen@plt>
mov    %rax,%rdx
test   %rax,%rax
je     121d <libqwaitclient_login_information_jsonify_strings+0xed>
xor    %eax,%eax
xor    %r15d,%r15d
mov    %rdx,%rbx
xor    %ebp,%ebp
nopl   0x0(%rax)
lea    0x1(%rbx),%r13
movzbl (%r12,%rbp,1),%r14d
test   %al,%al
je     1180 <libqwaitclient_login_information_jsonify_strings+0x50>
test   %r15d,%r15d
je     11c0 <libqwaitclient_login_information_jsonify_strings+0x90>
mov    %r13,%rbx
xor    %r15d,%r15d
mov    %r14d,%ecx
jmp    11d1 <libqwaitclient_login_information_jsonify_strings+0xa1>
nopl   (%rax)
movsbl %r14b,%esi
lea    0xe75(%rip),%rdi
mov    %rdx,%rbx
call   1040 <strchr@plt>
mov    %rbx,%rdx
test   %rax,%rax
movzbl %r14b,%ecx
mov    %ecx,%eax
mov    $0x0,%esi
cmove  %esi,%eax
mov    $0x22,%esi
cmovne %esi,%ecx
jmp    11ce <libqwaitclient_login_information_jsonify_strings+0x9e>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
cmp    $0x5c,%r14b
jne    11eb <libqwaitclient_login_information_jsonify_strings+0xbb>
mov    $0x5c,%cl
mov    $0x1,%r15d
mov    %r13,%rbx
cmpb   $0x0,(%r12,%rbx,1)
je     123e <libqwaitclient_login_information_jsonify_strings+0x10e>
mov    %cl,(%r12,%rbx,1)
add    $0x1,%rbp
cmp    %rbp,%rdx
jne    1160 <libqwaitclient_login_information_jsonify_strings+0x30>
jmp    121f <libqwaitclient_login_information_jsonify_strings+0xef>
mov    $0x22,%cl
xor    %r15d,%r15d
cmp    %al,%r14b
jne    11fc <libqwaitclient_login_information_jsonify_strings+0xcc>
mov    %r13,%rbx
xor    %eax,%eax
jmp    11d1 <libqwaitclient_login_information_jsonify_strings+0xa1>
cmp    $0x22,%r14b
jne    1215 <libqwaitclient_login_information_jsonify_strings+0xe5>
cmpb   $0x0,(%r12,%r13,1)
je     123e <libqwaitclient_login_information_jsonify_strings+0x10e>
movb   $0x5c,0x1(%r12,%rbx,1)
add    $0x2,%rbx
jmp    11d1 <libqwaitclient_login_information_jsonify_strings+0xa1>
mov    %r13,%rbx
mov    %r14d,%ecx
jmp    11d1 <libqwaitclient_login_information_jsonify_strings+0xa1>
xor    %ebx,%ebx
lea    (%r12,%rdx,1),%rsi
add    $0x1,%rsi
sub    %rdx,%rbx
mov    %r12,%rdi
mov    %rbx,%rdx
call   1050 <memmove@plt>
movb   $0x0,(%r12,%rbx,1)
xor    %eax,%eax
jmp    1255 <libqwaitclient_login_information_jsonify_strings+0x125>
mov    0x2da3(%rip),%rax
mov    (%rax),%eax
mov    0x2d8a(%rip),%rcx
mov    %eax,(%rcx)
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@EBADMSG = global i32 0
@errno = global i32 0
@.str = [3 x i8] c"'\22\00"
define i32 @libqwaitclient_login_information_jsonify_strings(i8* noalias %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i64
%6 = alloca i64
%7 = alloca i32
%8 = alloca i8
%9 = alloca i8
store i8* %0, i8** %3
%10 = load i8*, i8** %3
%11 = call i64 @strlen(i8* %10)
store i64 %11, i64* %6
store i32 0, i32* %7
store i8 0, i8* %8
store i64 0, i64* %4
%12 = load i64, i64* %6
%13 = add i64 %12, 1
store i64 %13, i64* %5
br label %14
14: ; preds = %86, %1
%15 = load i64, i64* %4
%16 = load i64, i64* %6
%17 = icmp ult i64 %15, %16
br i1 %17, label %18, label %89
18: ; preds = %14
%19 = load i8*, i8** %3
%20 = load i64, i64* %4
%21 = getelementptr inbounds i8, i8* %19, i64 %20
%22 = load i8, i8* %21
store i8 %22, i8* %9
%23 = load i8, i8* %8
%24 = sext i8 %23 to i32
%25 = icmp ne i32 %24, 0
br i1 %25, label %26, label %64
26: ; preds = %18
%27 = load i32, i32* %7
%28 = icmp ne i32 %27, 0
br i1 %28, label %29, label %30
29: ; preds = %26
store i32 0, i32* %7
br label %63
30: ; preds = %26
%31 = load i8, i8* %9
%32 = sext i8 %31 to i32
%33 = icmp eq i32 %32, 92
br i1 %33, label %34, label %35
34: ; preds = %30
store i32 1, i32* %7
br label %62
35: ; preds = %30
%36 = load i8, i8* %9
%37 = sext i8 %36 to i32
%38 = load i8, i8* %8
%39 = sext i8 %38 to i32
%40 = icmp eq i32 %37, %39
br i1 %40, label %41, label %42
41: ; preds = %35
store i8 0, i8* %8
store i8 34, i8* %9
br label %61
42: ; preds = %35
%43 = load i8, i8* %9
%44 = sext i8 %43 to i32
%45 = icmp eq i32 %44, 34
br i1 %45, label %46, label %60
46: ; preds = %42
%47 = load i8*, i8** %3
%48 = load i64, i64* %5
%49 = getelementptr inbounds i8, i8* %47, i64 %48
%50 = load i8, i8* %49
%51 = sext i8 %50 to i32
%52 = icmp eq i32 %51, 0
br i1 %52, label %53, label %55
53: ; preds = %46
%54 = load i32, i32* @EBADMSG
store i32 %54, i32* @errno
store i32 -1, i32* %2
br label %107
55: ; preds = %46
%56 = load i8*, i8** %3
%57 = load i64, i64* %5
%58 = add i64 %57, 1
store i64 %58, i64* %5
%59 = getelementptr inbounds i8, i8* %56, i64 %57
store i8 92, i8* %59
br label %60
60: ; preds = %55, %42
br label %61
61: ; preds = %60, %41
br label %62
62: ; preds = %61, %34
br label %63
63: ; preds = %62, %29
br label %71
64: ; preds = %18
%65 = load i8, i8* %9
%66 = call i64 @strchr(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8 signext %65)
%67 = icmp ne i64 %66, 0
br i1 %67, label %68, label %70
68: ; preds = %64
%69 = load i8, i8* %9
store i8 %69, i8* %8
store i8 34, i8* %9
br label %70
70: ; preds = %68, %64
br label %71
71: ; preds = %70, %63
%72 = load i8*, i8** %3
%73 = load i64, i64* %5
%74 = getelementptr inbounds i8, i8* %72, i64 %73
%75 = load i8, i8* %74
%76 = sext i8 %75 to i32
%77 = icmp eq i32 %76, 0
br i1 %77, label %78, label %80
78: ; preds = %71
%79 = load i32, i32* @EBADMSG
store i32 %79, i32* @errno
store i32 -1, i32* %2
br label %107
80: ; preds = %71
%81 = load i8, i8* %9
%82 = load i8*, i8** %3
%83 = load i64, i64* %5
%84 = add i64 %83, 1
store i64 %84, i64* %5
%85 = getelementptr inbounds i8, i8* %82, i64 %83
store i8 %81, i8* %85
br label %86
86: ; preds = %80
%87 = load i64, i64* %4
%88 = add i64 %87, 1
store i64 %88, i64* %4
br label %14
89: ; preds = %14
%90 = load i64, i64* %5
%91 = add i64 %90, -1
store i64 %91, i64* %5
%92 = load i8*, i8** %3
%93 = load i8*, i8** %3
%94 = load i64, i64* %6
%95 = getelementptr inbounds i8, i8* %93, i64 %94
%96 = getelementptr inbounds i8, i8* %95, i64 1
%97 = load i64, i64* %5
%98 = load i64, i64* %6
%99 = sub i64 %97, %98
%100 = mul i64 %99, 1
%101 = call i32 @memmove(i8* %92, i8* %96, i64 %100)
%102 = load i8*, i8** %3
%103 = load i64, i64* %5
%104 = load i64, i64* %6
%105 = sub i64 %103, %104
%106 = getelementptr inbounds i8, i8* %102, i64 %105
store i8 0, i8* %106
store i32 0, i32* %2
br label %107
107: ; preds = %89, %78, %53
%108 = load i32, i32* %2
ret i32 %108
}

LLVM IR (-O2):
@EBADMSG = global i32 0
@errno = global i32 0
@.str = [3 x i8] c"'\22\00"
define i32 @libqwaitclient_login_information_jsonify_strings(i8* noalias %0) {
%2 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%3 = icmp eq i64 %2, 0
br i1 %3, label %47, label %4
4: ; preds = %1, %44
%5 = phi i8 [ %37, %44 ], [ 0, %1 ]
%6 = phi i32 [ %36, %44 ], [ 0, %1 ]
%7 = phi i64 [ %35, %44 ], [ %2, %1 ]
%8 = phi i64 [ %45, %44 ], [ 0, %1 ]
%9 = add i64 %7, 1
%10 = getelementptr inbounds i8, i8* %0, i64 %8
%11 = load i8, i8* %10
%12 = icmp eq i8 %5, 0
br i1 %12, label %29, label %13
13: ; preds = %4
%14 = icmp eq i32 %6, 0
br i1 %14, label %15, label %34
15: ; preds = %13
%16 = icmp eq i8 %11, 92
br i1 %16, label %34, label %17
17: ; preds = %15
%18 = icmp eq i8 %11, %5
br i1 %18, label %34, label %19
19: ; preds = %17
%20 = icmp eq i8 %11, 34
br i1 %20, label %21, label %34
21: ; preds = %19
%22 = getelementptr inbounds i8, i8* %0, i64 %9
%23 = load i8, i8* %22
%24 = icmp eq i8 %23, 0
br i1 %24, label %25, label %27
25: ; preds = %21
%26 = load i32, i32* @EBADMSG
store i32 %26, i32* @errno
br label %54
27: ; preds = %21
%28 = add i64 %7, 2
store i8 92, i8* %22
br label %34
29: ; preds = %4
%30 = tail call i64 @strchr(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8 signext %11)
%31 = icmp eq i64 %30, 0
%32 = select i1 %31, i8 0, i8 %11
%33 = select i1 %31, i8 %11, i8 34
br label %34
34: ; preds = %29, %17, %15, %13, %27, %19
%35 = phi i64 [ %28, %27 ], [ %9, %19 ], [ %9, %13 ], [ %9, %15 ], [ %9, %17 ], [ %9, %29 ]
%36 = phi i32 [ 0, %27 ], [ 0, %19 ], [ 0, %13 ], [ 1, %15 ], [ 0, %17 ], [ %6, %29 ]
%37 = phi i8 [ %5, %27 ], [ %5, %19 ], [ %5, %13 ], [ %5, %15 ], [ 0, %17 ], [ %32, %29 ]
%38 = phi i8 [ 34, %27 ], [ %11, %19 ], [ %11, %13 ], [ 92, %15 ], [ 34, %17 ], [ %33, %29 ]
%39 = getelementptr inbounds i8, i8* %0, i64 %35
%40 = load i8, i8* %39
%41 = icmp eq i8 %40, 0
br i1 %41, label %42, label %44
42: ; preds = %34
%43 = load i32, i32* @EBADMSG
store i32 %43, i32* @errno
br label %54
44: ; preds = %34
store i8 %38, i8* %39
%45 = add nuw i64 %8, 1
%46 = icmp eq i64 %45, %2
br i1 %46, label %47, label %4
47: ; preds = %44, %1
%48 = phi i64 [ 0, %1 ], [ %35, %44 ]
%49 = getelementptr inbounds i8, i8* %0, i64 %2
%50 = getelementptr inbounds i8, i8* %49, i64 1
%51 = sub i64 %48, %2
%52 = tail call i32 @memmove(i8* %0, i8* %50, i64 %51)
%53 = getelementptr inbounds i8, i8* %0, i64 %51
store i8 0, i8* %53
br label %54
54: ; preds = %25, %42, %47
%55 = phi i32 [ 0, %47 ], [ -1, %42 ], [ -1, %25 ]
ret i32 %55
}