int main() {
  while (1) {
    int n;
    scanf("%d", &n);
    if (!n)
      break;
    int bits = 0;
    int known = 0;
    while (n--) {
      char buffer[6];
      scanf("%s", buffer);
      if (buffer[0] == 'C')
        clear(&bits, &known);
      else if (buffer[0] == 'S')
        set(&bits, &known);
      else if (buffer[0] == 'O')
        or (&bits, &known);
      else
        and(&bits, &known);
    }
    print(&bits, &known);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe8a(%rip),%rdi
lea    -0x8(%rbp),%rsi
mov    $0x0,%al
call   1060 <scanf@plt>
cmpl   $0x0,-0x8(%rbp)
jne    1190 <main+0x30>
jmp    1259 <main+0xf9>
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x8(%rbp)
cmp    $0x0,%eax
je     1245 <main+0xe5>
lea    -0x16(%rbp),%rsi
lea    0xe46(%rip),%rdi
mov    $0x0,%al
call   1060 <scanf@plt>
movsbl -0x16(%rbp),%eax
cmp    $0x43,%eax
jne    11e5 <main+0x85>
lea    -0xc(%rbp),%rdi
lea    -0x10(%rbp),%rsi
mov    $0x0,%al
call   1070 <clear@plt>
jmp    1240 <main+0xe0>
movsbl -0x16(%rbp),%eax
cmp    $0x53,%eax
jne    1206 <main+0xa6>
lea    -0xc(%rbp),%rdi
lea    -0x10(%rbp),%rsi
mov    $0x0,%al
call   1080 <set@plt>
jmp    123b <main+0xdb>
movsbl -0x16(%rbp),%eax
cmp    $0x4f,%eax
jne    1227 <main+0xc7>
lea    -0xc(%rbp),%rdi
lea    -0x10(%rbp),%rsi
mov    $0x0,%al
call   1050 <or@plt>
jmp    1236 <main+0xd6>
lea    -0xc(%rbp),%rdi
lea    -0x10(%rbp),%rsi
mov    $0x0,%al
call   1030 <and@plt>
jmp    123b <main+0xdb>
jmp    1240 <main+0xe0>
jmp    119e <main+0x3e>
lea    -0xc(%rbp),%rdi
lea    -0x10(%rbp),%rsi
mov    $0x0,%al
call   1040 <print@plt>
jmp    116f <main+0xf>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
lea    0xe8b(%rip),%rdi
lea    0x4(%rsp),%rsi
xor    %eax,%eax
call   1060 <scanf@plt>
mov    0x4(%rsp),%eax
test   %eax,%eax
je     1259 <main+0xf9>
lea    0xe6f(%rip),%r14
lea    0x12(%rsp),%r15
lea    0xc(%rsp),%r12
lea    0x8(%rsp),%rbx
lea    0xe56(%rip),%r13
lea    0x4(%rsp),%rbp
jmp    11e2 <main+0x82>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r12,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <print@plt>
mov    %r13,%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   1060 <scanf@plt>
mov    0x4(%rsp),%eax
test   %eax,%eax
je     1259 <main+0xf9>
movl   $0x0,0xc(%rsp)
movl   $0x0,0x8(%rsp)
add    $0xffffffff,%eax
mov    %eax,0x4(%rsp)
jmp    120e <main+0xae>
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1050 <or@plt>
subl   $0x1,0x4(%rsp)
jb     11c0 <main+0x60>
mov    %r14,%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1060 <scanf@plt>
movzbl 0x12(%rsp),%eax
mov    %r12,%rdi
mov    %rbx,%rsi
cmp    $0x53,%al
je     1240 <main+0xe0>
cmp    $0x4f,%al
je     1200 <main+0xa0>
cmp    $0x43,%al
jne    1250 <main+0xf0>
xor    %eax,%eax
call   1070 <clear@plt>
jmp    1207 <main+0xa7>
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1080 <set@plt>
jmp    1207 <main+0xa7>
nopl   0x0(%rax)
xor    %eax,%eax
call   1030 <and@plt>
jmp    1207 <main+0xa7>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
@.str.1 = [3 x i8] c"%s\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca [6 x i8]
store i32 0, i32* %1
br label %6
6: ; preds = %0, %44
%7 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
%8 = load i32, i32* %2
%9 = icmp ne i32 %8, 0
br i1 %9, label %11, label %10
10: ; preds = %6
br label %46
11: ; preds = %6
store i32 0, i32* %3
store i32 0, i32* %4
br label %12
12: ; preds = %43, %11
%13 = load i32, i32* %2
%14 = add nsw i32 %13, -1
store i32 %14, i32* %2
%15 = icmp ne i32 %13, 0
br i1 %15, label %16, label %44
16: ; preds = %12
%17 = getelementptr inbounds [6 x i8], [6 x i8]* %5, i64 0, i64 0
%18 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %17)
%19 = getelementptr inbounds [6 x i8], [6 x i8]* %5, i64 0, i64 0
%20 = load i8, i8* %19
%21 = sext i8 %20 to i32
%22 = icmp eq i32 %21, 67
br i1 %22, label %23, label %25
23: ; preds = %16
%24 = call i32 (i32*, i32*, ...) bitcast (i32 (...)* @clear to i32 (i32*, i32*, ...)*)(i32* %3, i32* %4)
br label %43
25: ; preds = %16
%26 = getelementptr inbounds [6 x i8], [6 x i8]* %5, i64 0, i64 0
%27 = load i8, i8* %26
%28 = sext i8 %27 to i32
%29 = icmp eq i32 %28, 83
br i1 %29, label %30, label %32
30: ; preds = %25
%31 = call i32 (i32*, i32*, ...) bitcast (i32 (...)* @set to i32 (i32*, i32*, ...)*)(i32* %3, i32* %4)
br label %42
32: ; preds = %25
%33 = getelementptr inbounds [6 x i8], [6 x i8]* %5, i64 0, i64 0
%34 = load i8, i8* %33
%35 = sext i8 %34 to i32
%36 = icmp eq i32 %35, 79
br i1 %36, label %37, label %39
37: ; preds = %32
%38 = call i32 (i32*, i32*, ...) bitcast (i32 (...)* @or to i32 (i32*, i32*, ...)*)(i32* %3, i32* %4)
br label %41
39: ; preds = %32
%40 = call i32 (i32*, i32*, ...) bitcast (i32 (...)* @and to i32 (i32*, i32*, ...)*)(i32* %3, i32* %4)
br label %41
41: ; preds = %39, %37
br label %42
42: ; preds = %41, %30
br label %43
43: ; preds = %42, %23
br label %12
44: ; preds = %12
%45 = call i32 (i32*, i32*, ...) bitcast (i32 (...)* @print to i32 (i32*, i32*, ...)*)(i32* %3, i32* %4)
br label %6
46: ; preds = %10
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@.str.1 = [3 x i8] c"%s\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca [6 x i8]
%5 = bitcast i32* %1 to i8*
%6 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %1)
%7 = load i32, i32* %1
%8 = icmp eq i32 %7, 0
br i1 %8, label %36, label %9
9: ; preds = %0
%10 = bitcast i32* %2 to i8*
%11 = bitcast i32* %3 to i8*
%12 = getelementptr inbounds [6 x i8], [6 x i8]* %4, i64 0, i64 0
br label %13
13: ; preds = %31, %9
%14 = phi i32 [ %7, %9 ], [ %34, %31 ]
store i32 0, i32* %2
store i32 0, i32* %3
%15 = add nsw i32 %14, -1
store i32 %15, i32* %1
br label %16
16: ; preds = %13, %27
%17 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %12)
%18 = load i8, i8* %12
switch i8 %18, label %25 [
i8 67, label %19
i8 83, label %21
i8 79, label %23
]
19: ; preds = %16
%20 = call i32 (i32*, i32*, ...) bitcast (i32 (...)* @clear to i32 (i32*, i32*, ...)*)(i32* %2, i32* %3)
br label %27
21: ; preds = %16
%22 = call i32 (i32*, i32*, ...) bitcast (i32 (...)* @set to i32 (i32*, i32*, ...)*)(i32* %2, i32* %3)
br label %27
23: ; preds = %16
%24 = call i32 (i32*, i32*, ...) bitcast (i32 (...)* @or to i32 (i32*, i32*, ...)*)(i32* %2, i32* %3)
br label %27
25: ; preds = %16
%26 = call i32 (i32*, i32*, ...) bitcast (i32 (...)* @and to i32 (i32*, i32*, ...)*)(i32* %2, i32* %3)
br label %27
27: ; preds = %21, %25, %23, %19
%28 = load i32, i32* %1
%29 = add nsw i32 %28, -1
store i32 %29, i32* %1
%30 = icmp eq i32 %28, 0
br i1 %30, label %31, label %16
31: ; preds = %27
%32 = call i32 (i32*, i32*, ...) bitcast (i32 (...)* @print to i32 (i32*, i32*, ...)*)(i32* %2, i32* %3)
%33 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %1)
%34 = load i32, i32* %1
%35 = icmp eq i32 %34, 0
br i1 %35, label %36, label %13
36: ; preds = %31, %0
ret i32 0
}