#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;
scalar_t__ strchr(char *, char);
int libqwaitclient_login_information_nul_terminate(char *restrict data) {
  size_t i;
  int brackets = 0, escape = 0;
  char quote = '\0';
  for (i = 0;;) {
    char c = data[i++];
    if (c == '\0')
      return errno = EBADMSG, -1;
    if (quote != '\0') {
      if (escape)
        escape = 0;
      else if (c == '\\')
        escape = 1;
      else if (c == quote)
        quote = '\0';
    } else if (strchr("\'\"", c))
      quote = c;
    else if (strchr("{[", c))
      brackets++;
    else if (strchr("]}", c))
      if (--brackets == 0)
        break;
  }
  data[i] = '\0';
  return 0;
}


x86 assembly (clang, -O0):
<libqwaitclient_login_information_nul_terminate>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
movb   $0x0,-0x21(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    %rcx,%rdx
add    $0x1,%rdx
mov    %rdx,-0x18(%rbp)
mov    (%rax,%rcx,1),%al
mov    %al,-0x22(%rbp)
movsbl -0x22(%rbp),%eax
cmp    $0x0,%eax
jne    117a <libqwaitclient_login_information_nul_terminate+0x6a>
mov    0x2e85(%rip),%rax
mov    (%rax),%ecx
mov    0x2e6c(%rip),%rax
mov    %ecx,(%rax)
movl   $0xffffffff,-0x4(%rbp)
jmp    1283 <libqwaitclient_login_information_nul_terminate+0x173>
movsbl -0x21(%rbp),%eax
cmp    $0x0,%eax
je     11d9 <libqwaitclient_login_information_nul_terminate+0xc9>
cmpl   $0x0,-0x20(%rbp)
je     119d <libqwaitclient_login_information_nul_terminate+0x8d>
movl   $0x0,-0x20(%rbp)
jmp    11d4 <libqwaitclient_login_information_nul_terminate+0xc4>
movsbl -0x22(%rbp),%eax
cmp    $0x5c,%eax
jne    11b6 <libqwaitclient_login_information_nul_terminate+0xa6>
movl   $0x1,-0x20(%rbp)
jmp    11cf <libqwaitclient_login_information_nul_terminate+0xbf>
movsbl -0x22(%rbp),%eax
movsbl -0x21(%rbp),%ecx
cmp    %ecx,%eax
jne    11ca <libqwaitclient_login_information_nul_terminate+0xba>
movb   $0x0,-0x21(%rbp)
jmp    11cf <libqwaitclient_login_information_nul_terminate+0xbf>
jmp    11d4 <libqwaitclient_login_information_nul_terminate+0xc4>
jmp    126b <libqwaitclient_login_information_nul_terminate+0x15b>
lea    0xe20(%rip),%rdi
movsbl -0x22(%rbp),%esi
call   1030 <strchr@plt>
cmp    $0x0,%rax
je     11fe <libqwaitclient_login_information_nul_terminate+0xee>
mov    -0x22(%rbp),%al
mov    %al,-0x21(%rbp)
jmp    1266 <libqwaitclient_login_information_nul_terminate+0x156>
lea    0xdfe(%rip),%rdi
movsbl -0x22(%rbp),%esi
call   1030 <strchr@plt>
cmp    $0x0,%rax
je     1226 <libqwaitclient_login_information_nul_terminate+0x116>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1261 <libqwaitclient_login_information_nul_terminate+0x151>
lea    0xdd9(%rip),%rdi
movsbl -0x22(%rbp),%esi
call   1030 <strchr@plt>
cmp    $0x0,%rax
je     125c <libqwaitclient_login_information_nul_terminate+0x14c>
mov    -0x1c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
jne    1257 <libqwaitclient_login_information_nul_terminate+0x147>
jmp    1270 <libqwaitclient_login_information_nul_terminate+0x160>
jmp    125c <libqwaitclient_login_information_nul_terminate+0x14c>
jmp    1261 <libqwaitclient_login_information_nul_terminate+0x151>
jmp    1266 <libqwaitclient_login_information_nul_terminate+0x156>
jmp    126b <libqwaitclient_login_information_nul_terminate+0x15b>
jmp    1136 <libqwaitclient_login_information_nul_terminate+0x26>
mov    -0x10(%rbp),%rax
mov    -0x18(%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_nul_terminate>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    (%rdi),%r15b
test   %r15b,%r15b
je     11db <libqwaitclient_login_information_nul_terminate+0xcb>
mov    %rdi,%rbx
add    $0x1,%rbx
xor    %eax,%eax
lea    0xec9(%rip),%r14
xor    %r12d,%r12d
xor    %r13d,%r13d
jmp    1154 <libqwaitclient_login_information_nul_terminate+0x44>
nop
xor    %r12d,%r12d
movzbl (%rbx),%r15d
add    $0x1,%rbx
test   %r15b,%r15b
je     11db <libqwaitclient_login_information_nul_terminate+0xcb>
test   %al,%al
je     1180 <libqwaitclient_login_information_nul_terminate+0x70>
test   %r12d,%r12d
jne    1140 <libqwaitclient_login_information_nul_terminate+0x30>
mov    $0x1,%r12d
cmp    $0x5c,%r15b
je     1143 <libqwaitclient_login_information_nul_terminate+0x33>
xor    %r12d,%r12d
cmp    %al,%r15b
movzbl %al,%eax
cmove  %r12d,%eax
jmp    1143 <libqwaitclient_login_information_nul_terminate+0x33>
nopl   0x0(%rax,%rax,1)
movsbl %r15b,%ebp
mov    %r14,%rdi
mov    %ebp,%esi
call   1030 <strchr@plt>
test   %rax,%rax
je     1198 <libqwaitclient_login_information_nul_terminate+0x88>
mov    %r15d,%eax
jmp    1143 <libqwaitclient_login_information_nul_terminate+0x33>
lea    0xe64(%rip),%rdi
mov    %ebp,%esi
call   1030 <strchr@plt>
test   %rax,%rax
je     11b3 <libqwaitclient_login_information_nul_terminate+0xa3>
add    $0x1,%r13d
xor    %eax,%eax
jmp    1143 <libqwaitclient_login_information_nul_terminate+0x33>
lea    0xe4c(%rip),%rdi
mov    %ebp,%esi
call   1030 <strchr@plt>
test   %rax,%rax
je     11d4 <libqwaitclient_login_information_nul_terminate+0xc4>
xor    %eax,%eax
add    $0xffffffff,%r13d
jne    1143 <libqwaitclient_login_information_nul_terminate+0x33>
jmp    1201 <libqwaitclient_login_information_nul_terminate+0xf1>
xor    %eax,%eax
jmp    1143 <libqwaitclient_login_information_nul_terminate+0x33>
mov    0x2e06(%rip),%rax
mov    (%rax),%eax
mov    0x2ded(%rip),%rcx
mov    %eax,(%rcx)
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
movb   $0x0,(%rbx)
jmp    11f2 <libqwaitclient_login_information_nul_terminate+0xe2>

LLVM IR (-O0):
@EBADMSG = global i32 0
@errno = global i32 0
@.str = [3 x i8] c"'\22\00"
@.str.1 = [3 x i8] c"{[\00"
@.str.2 = [3 x i8] c"]}\00"
define i32 @libqwaitclient_login_information_nul_terminate(i8* noalias %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8
%8 = alloca i8
store i8* %0, i8** %3
store i32 0, i32* %5
store i32 0, i32* %6
store i8 0, i8* %7
store i64 0, i64* %4
br label %9
9: ; preds = %69, %1
%10 = load i8*, i8** %3
%11 = load i64, i64* %4
%12 = add i64 %11, 1
store i64 %12, i64* %4
%13 = getelementptr inbounds i8, i8* %10, i64 %11
%14 = load i8, i8* %13
store i8 %14, i8* %8
%15 = load i8, i8* %8
%16 = sext i8 %15 to i32
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %9
%19 = load i32, i32* @EBADMSG
store i32 %19, i32* @errno
store i32 -1, i32* %2
br label %74
20: ; preds = %9
%21 = load i8, i8* %7
%22 = sext i8 %21 to i32
%23 = icmp ne i32 %22, 0
br i1 %23, label %24, label %43
24: ; preds = %20
%25 = load i32, i32* %6
%26 = icmp ne i32 %25, 0
br i1 %26, label %27, label %28
27: ; preds = %24
store i32 0, i32* %6
br label %42
28: ; preds = %24
%29 = load i8, i8* %8
%30 = sext i8 %29 to i32
%31 = icmp eq i32 %30, 92
br i1 %31, label %32, label %33
32: ; preds = %28
store i32 1, i32* %6
br label %41
33: ; preds = %28
%34 = load i8, i8* %8
%35 = sext i8 %34 to i32
%36 = load i8, i8* %7
%37 = sext i8 %36 to i32
%38 = icmp eq i32 %35, %37
br i1 %38, label %39, label %40
39: ; preds = %33
store i8 0, i8* %7
br label %40
40: ; preds = %39, %33
br label %41
41: ; preds = %40, %32
br label %42
42: ; preds = %41, %27
br label %69
43: ; preds = %20
%44 = load i8, i8* %8
%45 = call i64 @strchr(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8 signext %44)
%46 = icmp ne i64 %45, 0
br i1 %46, label %47, label %49
47: ; preds = %43
%48 = load i8, i8* %8
store i8 %48, i8* %7
br label %68
49: ; preds = %43
%50 = load i8, i8* %8
%51 = call i64 @strchr(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8 signext %50)
%52 = icmp ne i64 %51, 0
br i1 %52, label %53, label %56
53: ; preds = %49
%54 = load i32, i32* %5
%55 = add nsw i32 %54, 1
store i32 %55, i32* %5
br label %67
56: ; preds = %49
%57 = load i8, i8* %8
%58 = call i64 @strchr(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8 signext %57)
%59 = icmp ne i64 %58, 0
br i1 %59, label %60, label %66
60: ; preds = %56
%61 = load i32, i32* %5
%62 = add nsw i32 %61, -1
store i32 %62, i32* %5
%63 = icmp eq i32 %62, 0
br i1 %63, label %64, label %65
64: ; preds = %60
br label %70
65: ; preds = %60
br label %66
66: ; preds = %65, %56
br label %67
67: ; preds = %66, %53
br label %68
68: ; preds = %67, %47
br label %69
69: ; preds = %68, %42
br label %9
70: ; preds = %64
%71 = load i8*, i8** %3
%72 = load i64, i64* %4
%73 = getelementptr inbounds i8, i8* %71, i64 %72
store i8 0, i8* %73
store i32 0, i32* %2
br label %74
74: ; preds = %70, %18
%75 = load i32, i32* %2
ret i32 %75
}

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