#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);
int /*<<< orphan*/ *strchr(char *, char);
size_t strlen(char *);
int libqwaitclient_login_information_jsonify_keys(char *restrict data) {
  size_t i, j, n, end;
  int quote = 0, stage = 0;
  n = strlen(data);
  end = strlen(data + n + 1) + n + 1;
  if (n + n > end)
    return errno = EBADMSG, -1;
  for (i = n, j = end - 1;; j--, i--) {
    char c = data[i];
    if (stage == 1) {
      if (strchr(" \t\n\r", c) == NULL)
        data[j--] = '\"', stage = 2;
    } else if (stage == 2) {
      if (strchr(" \t\n\r", c) != NULL)
        data[j--] = '\"', stage = 0;
    } else if (quote) {
      if ((c == '\"') && (data[i - 1] != '\\'))
        quote = 0;
    } else if (c == '\"')
      quote = 1;
    else if (c == ':')
      stage = 1;
    data[j] = c;
    if (i == 0)
      break;
  }
  memmove(data, data + j, (end - j) * sizeof(char));
  data[end - j] = '\0';
  return 0;
}


x86 assembly (clang, -O0):
<libqwaitclient_login_information_jsonify_keys>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x34(%rbp)
movl   $0x0,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
add    -0x28(%rbp),%rdi
add    $0x1,%rdi
call   1030 <strlen@plt>
add    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rax
add    -0x28(%rbp),%rax
cmp    -0x30(%rbp),%rax
jbe    11a4 <libqwaitclient_login_information_jsonify_keys+0x74>
mov    0x2e5b(%rip),%rax
mov    (%rax),%ecx
mov    0x2e42(%rip),%rax
mov    %ecx,(%rax)
movl   $0xffffffff,-0x4(%rbp)
jmp    1345 <libqwaitclient_login_information_jsonify_keys+0x215>
mov    -0x28(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x30(%rbp),%rax
sub    $0x1,%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x39(%rbp)
cmpl   $0x1,-0x38(%rbp)
jne    120d <libqwaitclient_login_information_jsonify_keys+0xdd>
lea    0xe29(%rip),%rdi
movsbl -0x39(%rbp),%esi
call   1040 <strchr@plt>
cmp    $0x0,%rax
jne    1208 <libqwaitclient_login_information_jsonify_keys+0xd8>
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    %rcx,%rdx
add    $0xffffffffffffffff,%rdx
mov    %rdx,-0x20(%rbp)
movb   $0x22,(%rax,%rcx,1)
movl   $0x2,-0x38(%rbp)
jmp    12d1 <libqwaitclient_login_information_jsonify_keys+0x1a1>
cmpl   $0x2,-0x38(%rbp)
jne    1254 <libqwaitclient_login_information_jsonify_keys+0x124>
lea    0xde2(%rip),%rdi
movsbl -0x39(%rbp),%esi
call   1040 <strchr@plt>
cmp    $0x0,%rax
je     124f <libqwaitclient_login_information_jsonify_keys+0x11f>
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    %rcx,%rdx
add    $0xffffffffffffffff,%rdx
mov    %rdx,-0x20(%rbp)
movb   $0x22,(%rax,%rcx,1)
movl   $0x0,-0x38(%rbp)
jmp    12cc <libqwaitclient_login_information_jsonify_keys+0x19c>
cmpl   $0x0,-0x34(%rbp)
je     1290 <libqwaitclient_login_information_jsonify_keys+0x160>
movsbl -0x39(%rbp),%eax
cmp    $0x22,%eax
jne    128b <libqwaitclient_login_information_jsonify_keys+0x15b>
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
sub    $0x1,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x5c,%eax
je     128b <libqwaitclient_login_information_jsonify_keys+0x15b>
movl   $0x0,-0x34(%rbp)
jmp    12c7 <libqwaitclient_login_information_jsonify_keys+0x197>
movsbl -0x39(%rbp),%eax
cmp    $0x22,%eax
jne    12a9 <libqwaitclient_login_information_jsonify_keys+0x179>
movl   $0x1,-0x34(%rbp)
jmp    12c2 <libqwaitclient_login_information_jsonify_keys+0x192>
movsbl -0x39(%rbp),%eax
cmp    $0x3a,%eax
jne    12bd <libqwaitclient_login_information_jsonify_keys+0x18d>
movl   $0x1,-0x38(%rbp)
jmp    12c2 <libqwaitclient_login_information_jsonify_keys+0x192>
jmp    12c7 <libqwaitclient_login_information_jsonify_keys+0x197>
jmp    12cc <libqwaitclient_login_information_jsonify_keys+0x19c>
jmp    12d1 <libqwaitclient_login_information_jsonify_keys+0x1a1>
mov    -0x39(%rbp),%dl
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
cmpq   $0x0,-0x18(%rbp)
jne    12ef <libqwaitclient_login_information_jsonify_keys+0x1bf>
jmp    1311 <libqwaitclient_login_information_jsonify_keys+0x1e1>
jmp    12f4 <libqwaitclient_login_information_jsonify_keys+0x1c4>
mov    -0x20(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
jmp    11b8 <libqwaitclient_login_information_jsonify_keys+0x88>
mov    -0x10(%rbp),%rdi
mov    -0x10(%rbp),%rsi
add    -0x20(%rbp),%rsi
mov    -0x30(%rbp),%rdx
sub    -0x20(%rbp),%rdx
shl    $0x0,%rdx
call   1050 <memmove@plt>
mov    -0x10(%rbp),%rax
mov    -0x30(%rbp),%rcx
sub    -0x20(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<libqwaitclient_login_information_jsonify_keys>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r15
call   1030 <strlen@plt>
mov    %rax,%rbx
lea    (%r15,%rax,1),%rdi
add    $0x1,%rdi
call   1030 <strlen@plt>
mov    %rax,%r12
lea    (%rax,%rbx,1),%rcx
add    $0x1,%rcx
lea    (%rbx,%rbx,1),%rax
cmp    %rcx,%rax
jbe    1183 <libqwaitclient_login_information_jsonify_keys+0x53>
mov    0x2e7a(%rip),%rax
mov    (%rax),%eax
mov    0x2e61(%rip),%rcx
mov    %eax,(%rcx)
mov    $0xffffffff,%eax
jmp    1270 <libqwaitclient_login_information_jsonify_keys+0x140>
mov    %rcx,(%rsp)
add    %rbx,%r12
xor    %ebp,%ebp
lea    0xe6d(%rip),%r13
xor    %ecx,%ecx
cs nopw 0x0(%rax,%rax,1)
nop
movzbl (%r15,%rbx,1),%r14d
cmp    $0x2,%ecx
je     11e0 <libqwaitclient_login_information_jsonify_keys+0xb0>
cmp    $0x1,%ecx
jne    1200 <libqwaitclient_login_information_jsonify_keys+0xd0>
movsbl %r14b,%esi
mov    %r13,%rdi
call   1040 <strchr@plt>
mov    $0x1,%ecx
test   %rax,%rax
jne    1240 <libqwaitclient_login_information_jsonify_keys+0x110>
movb   $0x22,(%r15,%r12,1)
add    $0xffffffffffffffff,%r12
mov    $0x2,%ecx
jmp    1240 <libqwaitclient_login_information_jsonify_keys+0x110>
cs nopw 0x0(%rax,%rax,1)
nop
movsbl %r14b,%esi
mov    %r13,%rdi
call   1040 <strchr@plt>
test   %rax,%rax
je     121d <libqwaitclient_login_information_jsonify_keys+0xed>
movb   $0x22,(%r15,%r12,1)
add    $0xffffffffffffffff,%r12
xor    %ecx,%ecx
jmp    1240 <libqwaitclient_login_information_jsonify_keys+0x110>
xchg   %ax,%ax
test   %ebp,%ebp
je     1224 <libqwaitclient_login_information_jsonify_keys+0xf4>
mov    $0x1,%ebp
cmp    $0x22,%r14b
jne    1240 <libqwaitclient_login_information_jsonify_keys+0x110>
xor    %ebp,%ebp
cmpb   $0x5c,-0x1(%r15,%rbx,1)
sete   %bpl
jmp    1240 <libqwaitclient_login_information_jsonify_keys+0x110>
mov    $0x2,%ecx
jmp    1240 <libqwaitclient_login_information_jsonify_keys+0x110>
cmp    $0x22,%r14b
je     1239 <libqwaitclient_login_information_jsonify_keys+0x109>
cmp    $0x3a,%r14b
jne    1235 <libqwaitclient_login_information_jsonify_keys+0x105>
mov    $0x1,%ecx
xor    %ebp,%ebp
jmp    1240 <libqwaitclient_login_information_jsonify_keys+0x110>
mov    $0x1,%ebp
xchg   %ax,%ax
mov    %r14b,(%r15,%r12,1)
sub    $0x1,%rbx
jb     1253 <libqwaitclient_login_information_jsonify_keys+0x123>
add    $0xffffffffffffffff,%r12
jmp    11a0 <libqwaitclient_login_information_jsonify_keys+0x70>
lea    (%r15,%r12,1),%rsi
mov    (%rsp),%rbx
sub    %r12,%rbx
mov    %r15,%rdi
mov    %rbx,%rdx
call   1050 <memmove@plt>
movb   $0x0,(%r15,%rbx,1)
xor    %eax,%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 = [5 x i8] c" \09\0A\0D\00"
define i32 @libqwaitclient_login_information_jsonify_keys(i8* noalias %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i64
%6 = alloca i64
%7 = alloca i64
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8
store i8* %0, i8** %3
store i32 0, i32* %8
store i32 0, i32* %9
%11 = load i8*, i8** %3
%12 = call i64 @strlen(i8* %11)
store i64 %12, i64* %6
%13 = load i8*, i8** %3
%14 = load i64, i64* %6
%15 = getelementptr inbounds i8, i8* %13, i64 %14
%16 = getelementptr inbounds i8, i8* %15, i64 1
%17 = call i64 @strlen(i8* %16)
%18 = load i64, i64* %6
%19 = add i64 %17, %18
%20 = add i64 %19, 1
store i64 %20, i64* %7
%21 = load i64, i64* %6
%22 = load i64, i64* %6
%23 = add i64 %21, %22
%24 = load i64, i64* %7
%25 = icmp ugt i64 %23, %24
br i1 %25, label %26, label %28
26: ; preds = %1
%27 = load i32, i32* @EBADMSG
store i32 %27, i32* @errno
store i32 -1, i32* %2
br label %122
28: ; preds = %1
%29 = load i64, i64* %6
store i64 %29, i64* %4
%30 = load i64, i64* %7
%31 = sub i64 %30, 1
store i64 %31, i64* %5
br label %32
32: ; preds = %102, %28
%33 = load i8*, i8** %3
%34 = load i64, i64* %4
%35 = getelementptr inbounds i8, i8* %33, i64 %34
%36 = load i8, i8* %35
store i8 %36, i8* %10
%37 = load i32, i32* %9
%38 = icmp eq i32 %37, 1
br i1 %38, label %39, label %49
39: ; preds = %32
%40 = load i8, i8* %10
%41 = call i32* @strchr(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 signext %40)
%42 = icmp eq i32* %41, null
br i1 %42, label %43, label %48
43: ; preds = %39
%44 = load i8*, i8** %3
%45 = load i64, i64* %5
%46 = add i64 %45, -1
store i64 %46, i64* %5
%47 = getelementptr inbounds i8, i8* %44, i64 %45
store i8 34, i8* %47
store i32 2, i32* %9
br label %48
48: ; preds = %43, %39
br label %93
49: ; preds = %32
%50 = load i32, i32* %9
%51 = icmp eq i32 %50, 2
br i1 %51, label %52, label %62
52: ; preds = %49
%53 = load i8, i8* %10
%54 = call i32* @strchr(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 signext %53)
%55 = icmp ne i32* %54, null
br i1 %55, label %56, label %61
56: ; preds = %52
%57 = load i8*, i8** %3
%58 = load i64, i64* %5
%59 = add i64 %58, -1
store i64 %59, i64* %5
%60 = getelementptr inbounds i8, i8* %57, i64 %58
store i8 34, i8* %60
store i32 0, i32* %9
br label %61
61: ; preds = %56, %52
br label %92
62: ; preds = %49
%63 = load i32, i32* %8
%64 = icmp ne i32 %63, 0
br i1 %64, label %65, label %79
65: ; preds = %62
%66 = load i8, i8* %10
%67 = sext i8 %66 to i32
%68 = icmp eq i32 %67, 34
br i1 %68, label %69, label %78
69: ; preds = %65
%70 = load i8*, i8** %3
%71 = load i64, i64* %4
%72 = sub i64 %71, 1
%73 = getelementptr inbounds i8, i8* %70, i64 %72
%74 = load i8, i8* %73
%75 = sext i8 %74 to i32
%76 = icmp ne i32 %75, 92
br i1 %76, label %77, label %78
77: ; preds = %69
store i32 0, i32* %8
br label %78
78: ; preds = %77, %69, %65
br label %91
79: ; preds = %62
%80 = load i8, i8* %10
%81 = sext i8 %80 to i32
%82 = icmp eq i32 %81, 34
br i1 %82, label %83, label %84
83: ; preds = %79
store i32 1, i32* %8
br label %90
84: ; preds = %79
%85 = load i8, i8* %10
%86 = sext i8 %85 to i32
%87 = icmp eq i32 %86, 58
br i1 %87, label %88, label %89
88: ; preds = %84
store i32 1, i32* %9
br label %89
89: ; preds = %88, %84
br label %90
90: ; preds = %89, %83
br label %91
91: ; preds = %90, %78
br label %92
92: ; preds = %91, %61
br label %93
93: ; preds = %92, %48
%94 = load i8, i8* %10
%95 = load i8*, i8** %3
%96 = load i64, i64* %5
%97 = getelementptr inbounds i8, i8* %95, i64 %96
store i8 %94, i8* %97
%98 = load i64, i64* %4
%99 = icmp eq i64 %98, 0
br i1 %99, label %100, label %101
100: ; preds = %93
br label %107
101: ; preds = %93
br label %102
102: ; preds = %101
%103 = load i64, i64* %5
%104 = add i64 %103, -1
store i64 %104, i64* %5
%105 = load i64, i64* %4
%106 = add i64 %105, -1
store i64 %106, i64* %4
br label %32
107: ; preds = %100
%108 = load i8*, i8** %3
%109 = load i8*, i8** %3
%110 = load i64, i64* %5
%111 = getelementptr inbounds i8, i8* %109, i64 %110
%112 = load i64, i64* %7
%113 = load i64, i64* %5
%114 = sub i64 %112, %113
%115 = mul i64 %114, 1
%116 = call i32 @memmove(i8* %108, i8* %111, i64 %115)
%117 = load i8*, i8** %3
%118 = load i64, i64* %7
%119 = load i64, i64* %5
%120 = sub i64 %118, %119
%121 = getelementptr inbounds i8, i8* %117, i64 %120
store i8 0, i8* %121
store i32 0, i32* %2
br label %122
122: ; preds = %107, %26
%123 = load i32, i32* %2
ret i32 %123
}

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