#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*/ mygets(char *);
int /*<<< orphan*/ naive_printf(char *, int, int);
int /*<<< orphan*/ naive_scanf(char *, ...);
int program_main() {
  int n, t;
  int d, cnt;
  char buf[150 + 2];
  char *p;
  naive_scanf("%d", &n);
  naive_scanf("%c", buf);
  for (t = 1; t <= n; t++) {
    mygets(buf);
    d = cnt = 0;
    for (p = buf; *p == '[' || *p == ']'; p++)
      if (*p == '[') {
        cnt++;
        if (cnt > d)
          d = cnt;
      } else {
        cnt--;
      }
    naive_printf("%d %d\n", t, 1 << d);
  }
  return 0;
}


x86 assembly (clang, -O0):
<program_main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc0,%rsp
lea    0xebe(%rip),%rdi
lea    -0x4(%rbp),%rsi
mov    $0x0,%al
call   1030 <naive_scanf@plt>
lea    -0xb0(%rbp),%rsi
lea    0xea8(%rip),%rdi
mov    $0x0,%al
call   1030 <naive_scanf@plt>
movl   $0x1,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0x4(%rbp),%eax
jg     1260 <program_main+0x130>
lea    -0xb0(%rbp),%rdi
call   1050 <mygets@plt>
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0xc(%rbp)
lea    -0xb0(%rbp),%rax
mov    %rax,-0xb8(%rbp)
mov    -0xb8(%rbp),%rax
movsbl (%rax),%ecx
mov    $0x1,%al
cmp    $0x5b,%ecx
mov    %al,-0xb9(%rbp)
je     11ce <program_main+0x9e>
mov    -0xb8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x5d,%eax
sete   %al
mov    %al,-0xb9(%rbp)
mov    -0xb9(%rbp),%al
test   $0x1,%al
jne    11e1 <program_main+0xb1>
jmp    1239 <program_main+0x109>
mov    -0xb8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x5b,%eax
jne    1214 <program_main+0xe4>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jle    120f <program_main+0xdf>
mov    -0x10(%rbp),%eax
mov    %eax,-0xc(%rbp)
jmp    121d <program_main+0xed>
mov    -0x10(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x10(%rbp)
jmp    1222 <program_main+0xf2>
mov    -0xb8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0xb8(%rbp)
jmp    119d <program_main+0x6d>
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%ecx
mov    $0x1,%edx
shl    %cl,%edx
lea    0xdb9(%rip),%rdi
call   1040 <naive_printf@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1169 <program_main+0x39>
xor    %eax,%eax
add    $0xc0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<program_main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0xa8,%rsp
lea    0xebb(%rip),%rdi
lea    0xc(%rsp),%rsi
xor    %eax,%eax
call   1030 <naive_scanf@plt>
lea    0xeab(%rip),%rdi
lea    0x10(%rsp),%r15
mov    %r15,%rsi
xor    %eax,%eax
call   1030 <naive_scanf@plt>
cmpl   $0x0,0xc(%rsp)
jle    11ea <program_main+0xba>
mov    $0x1,%r12d
lea    0xe8b(%rip),%r14
nopl   0x0(%rax,%rax,1)
mov    %r15,%rdi
call   1050 <mygets@plt>
xor    %ecx,%ecx
xor    %edx,%edx
mov    %r15,%rax
jmp    11bc <program_main+0x8c>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
cmp    %ecx,%edx
lea    0x1(%rdx),%esi
mov    %esi,%edi
cmovl  %ecx,%edi
cmp    $0x5b,%bl
cmove  %edi,%ecx
lea    -0x1(%rdx),%edx
cmovne %edx,%esi
add    $0x1,%rax
mov    %esi,%edx
movzbl (%rax),%ebx
cmp    $0x5d,%bl
je     11a0 <program_main+0x70>
cmp    $0x5b,%bl
je     11a0 <program_main+0x70>
mov    $0x1,%edx
shl    %cl,%edx
mov    %r14,%rdi
mov    %r12d,%esi
call   1040 <naive_printf@plt>
lea    0x1(%r12),%eax
cmp    0xc(%rsp),%r12d
mov    %eax,%r12d
jl     1180 <program_main+0x50>
xor    %eax,%eax
add    $0xa8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
@.str.1 = [3 x i8] c"%c\00"
@.str.2 = [7 x i8] c"%d %d\0A\00"
define i32 @program_main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca [152 x i8]
%6 = alloca i8*
%7 = call i32 (i8*, ...) @naive_scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %1)
%8 = getelementptr inbounds [152 x i8], [152 x i8]* %5, i64 0, i64 0
%9 = call i32 (i8*, ...) @naive_scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %8)
store i32 1, i32* %2
br label %10
10: ; preds = %56, %0
%11 = load i32, i32* %2
%12 = load i32, i32* %1
%13 = icmp sle i32 %11, %12
br i1 %13, label %14, label %59
14: ; preds = %10
%15 = getelementptr inbounds [152 x i8], [152 x i8]* %5, i64 0, i64 0
%16 = call i32 @mygets(i8* %15)
store i32 0, i32* %4
store i32 0, i32* %3
%17 = getelementptr inbounds [152 x i8], [152 x i8]* %5, i64 0, i64 0
store i8* %17, i8** %6
br label %18
18: ; preds = %48, %14
%19 = load i8*, i8** %6
%20 = load i8, i8* %19
%21 = sext i8 %20 to i32
%22 = icmp eq i32 %21, 91
br i1 %22, label %28, label %23
23: ; preds = %18
%24 = load i8*, i8** %6
%25 = load i8, i8* %24
%26 = sext i8 %25 to i32
%27 = icmp eq i32 %26, 93
br label %28
28: ; preds = %23, %18
%29 = phi i1 [ true, %18 ], [ %27, %23 ]
br i1 %29, label %30, label %51
30: ; preds = %28
%31 = load i8*, i8** %6
%32 = load i8, i8* %31
%33 = sext i8 %32 to i32
%34 = icmp eq i32 %33, 91
br i1 %34, label %35, label %44
35: ; preds = %30
%36 = load i32, i32* %4
%37 = add nsw i32 %36, 1
store i32 %37, i32* %4
%38 = load i32, i32* %4
%39 = load i32, i32* %3
%40 = icmp sgt i32 %38, %39
br i1 %40, label %41, label %43
41: ; preds = %35
%42 = load i32, i32* %4
store i32 %42, i32* %3
br label %43
43: ; preds = %41, %35
br label %47
44: ; preds = %30
%45 = load i32, i32* %4
%46 = add nsw i32 %45, -1
store i32 %46, i32* %4
br label %47
47: ; preds = %44, %43
br label %48
48: ; preds = %47
%49 = load i8*, i8** %6
%50 = getelementptr inbounds i8, i8* %49, i32 1
store i8* %50, i8** %6
br label %18
51: ; preds = %28
%52 = load i32, i32* %2
%53 = load i32, i32* %3
%54 = shl i32 1, %53
%55 = call i32 @naive_printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i32 %52, i32 %54)
br label %56
56: ; preds = %51
%57 = load i32, i32* %2
%58 = add nsw i32 %57, 1
store i32 %58, i32* %2
br label %10
59: ; preds = %10
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@.str.1 = [3 x i8] c"%c\00"
@.str.2 = [7 x i8] c"%d %d\0A\00"
define i32 @program_main() {
%1 = alloca i32
%2 = alloca [152 x i8]
%3 = bitcast i32* %1 to i8*
%4 = getelementptr inbounds [152 x i8], [152 x i8]* %2, i64 0, i64 0
%5 = call i32 (i8*, ...) @naive_scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %1)
%6 = call i32 (i8*, ...) @naive_scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %4)
%7 = load i32, i32* %1
%8 = icmp slt i32 %7, 1
br i1 %8, label %32, label %9
9: ; preds = %0, %26
%10 = phi i32 [ %29, %26 ], [ 1, %0 ]
%11 = call i32 @mygets(i8* %4)
br label %12
12: ; preds = %17, %9
%13 = phi i32 [ 0, %9 ], [ %23, %17 ]
%14 = phi i32 [ 0, %9 ], [ %24, %17 ]
%15 = phi i8* [ %4, %9 ], [ %25, %17 ]
%16 = load i8, i8* %15
switch i8 %16, label %26 [
i8 91, label %17
i8 93, label %17
]
17: ; preds = %12, %12
%18 = icmp eq i8 %16, 91
%19 = add nsw i32 %14, -1
%20 = add nsw i32 %14, 1
%21 = icmp slt i32 %14, %13
%22 = select i1 %21, i32 %13, i32 %20
%23 = select i1 %18, i32 %22, i32 %13
%24 = select i1 %18, i32 %20, i32 %19
%25 = getelementptr inbounds i8, i8* %15, i64 1
br label %12
26: ; preds = %12
%27 = shl nuw i32 1, %13
%28 = call i32 @naive_printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i32 %10, i32 %27)
%29 = add nuw nsw i32 %10, 1
%30 = load i32, i32* %1
%31 = icmp slt i32 %10, %30
br i1 %31, label %9, label %32
32: ; preds = %26, %0
ret i32 0
}