#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 */
struct string_node {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ append(struct string_node **, char);
int /*<<< orphan*/ deleteAt(struct string_node **, int);
char getchar();
int length(struct string_node *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ show(struct string_node *);
char valueAt(struct string_node *, int);
int main(void) {
  struct string_node *head = NULL;
  char c;
  int is_break;
  int i, j;
  while ((c = getchar()) != '\n') {
    append(&head, c);
  }
  while (1) {
    is_break = 1;
    for (i = length(head) - 2; 0 <= i; i--) {
      show(head);
      for (j = 0; j < i; j++) {
        printf(" ");
      }
      printf("^^\n");
      if ((valueAt(head, i) == '(' && valueAt(head, i + 1) == ')') ||
          (valueAt(head, i) == '[' && valueAt(head, i + 1) == ']') ||
          (valueAt(head, i) == '{' && valueAt(head, i + 1) == '}')) {
        deleteAt(&head, i + 1);
        deleteAt(&head, i);
        is_break = 0;
        i--;
      }
    }
    if (is_break)
      break;
  }
  show(head);
  if (length(head) == 0) {
    printf("correct\n");
  } else {
    printf("wrong\n");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0x0,-0x10(%rbp)
mov    $0x0,%al
call   1070 <getchar@plt>
mov    %al,-0x11(%rbp)
movsbl %al,%eax
cmp    $0xa,%eax
je     11af <main+0x3f>
lea    -0x10(%rbp),%rdi
movsbl -0x11(%rbp),%esi
call   1030 <append@plt>
jmp    1187 <main+0x17>
jmp    11b4 <main+0x44>
movl   $0x1,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <length@plt>
sub    $0x2,%eax
mov    %eax,-0x1c(%rbp)
xor    %eax,%eax
cmp    -0x1c(%rbp),%eax
jg     12ee <main+0x17e>
mov    -0x10(%rbp),%rdi
call   1060 <show@plt>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    120b <main+0x9b>
lea    0xe08(%rip),%rdi
call   1050 <printf@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    11e5 <main+0x75>
lea    0xdf0(%rip),%rdi
call   1050 <printf@plt>
mov    -0x10(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   1080 <valueAt@plt>
movsbl %al,%eax
cmp    $0x28,%eax
jne    124a <main+0xda>
mov    -0x10(%rbp),%rdi
mov    -0x1c(%rbp),%esi
add    $0x1,%esi
call   1080 <valueAt@plt>
movsbl %al,%eax
cmp    $0x29,%eax
je     12b0 <main+0x140>
mov    -0x10(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   1080 <valueAt@plt>
movsbl %al,%eax
cmp    $0x5b,%eax
jne    127d <main+0x10d>
mov    -0x10(%rbp),%rdi
mov    -0x1c(%rbp),%esi
add    $0x1,%esi
call   1080 <valueAt@plt>
movsbl %al,%eax
cmp    $0x5d,%eax
je     12b0 <main+0x140>
mov    -0x10(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   1080 <valueAt@plt>
movsbl %al,%eax
cmp    $0x7b,%eax
jne    12db <main+0x16b>
mov    -0x10(%rbp),%rdi
mov    -0x1c(%rbp),%esi
add    $0x1,%esi
call   1080 <valueAt@plt>
movsbl %al,%eax
cmp    $0x7d,%eax
jne    12db <main+0x16b>
mov    -0x1c(%rbp),%esi
add    $0x1,%esi
lea    -0x10(%rbp),%rdi
call   1090 <deleteAt@plt>
mov    -0x1c(%rbp),%esi
lea    -0x10(%rbp),%rdi
call   1090 <deleteAt@plt>
movl   $0x0,-0x18(%rbp)
mov    -0x1c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x1c(%rbp)
jmp    12e0 <main+0x170>
mov    -0x1c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x1c(%rbp)
jmp    11ca <main+0x5a>
cmpl   $0x0,-0x18(%rbp)
je     12fd <main+0x18d>
jmp    1302 <main+0x192>
jmp    11b4 <main+0x44>
mov    -0x10(%rbp),%rdi
call   1060 <show@plt>
mov    -0x10(%rbp),%rdi
call   1040 <length@plt>
cmp    $0x0,%eax
jne    132e <main+0x1be>
lea    0xce2(%rip),%rdi
call   1050 <printf@plt>
jmp    133a <main+0x1ca>
lea    0xcda(%rip),%rdi
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
movq   $0x0,0x8(%rsp)
xor    %eax,%eax
call   1080 <getchar@plt>
cmp    $0xa,%al
je     11c6 <main+0x46>
lea    0x8(%rsp),%rbx
cs nopw 0x0(%rax,%rax,1)
nop
movsbl %al,%esi
mov    %rbx,%rdi
call   1040 <append@plt>
xor    %eax,%eax
call   1080 <getchar@plt>
cmp    $0xa,%al
jne    11b0 <main+0x30>
lea    0xe41(%rip),%r14
lea    0x8(%rsp),%r15
jmp    11e9 <main+0x69>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
test   %r12d,%r12d
jne    12e1 <main+0x161>
mov    0x8(%rsp),%rdi
call   1050 <length@plt>
cmp    $0x2,%eax
jl     12e1 <main+0x161>
mov    %eax,%ebx
add    $0xfffffffe,%ebx
mov    $0x1,%r12d
jmp    1233 <main+0xb3>
nopl   0x0(%rax)
mov    %r15,%rdi
mov    %ebp,%esi
call   10a0 <deleteAt@plt>
mov    %r15,%rdi
mov    %ebx,%esi
call   10a0 <deleteAt@plt>
add    $0xffffffff,%ebx
xor    %r12d,%r12d
lea    -0x1(%rbx),%eax
test   %ebx,%ebx
mov    %eax,%ebx
jle    11e0 <main+0x60>
mov    0x8(%rsp),%rdi
call   1070 <show@plt>
test   %ebx,%ebx
je     125f <main+0xdf>
mov    %ebx,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    $0x20,%edi
call   1030 <putchar@plt>
add    $0xffffffff,%ebp
jne    1250 <main+0xd0>
mov    %r14,%rdi
call   1060 <puts@plt>
mov    0x8(%rsp),%rdi
mov    %ebx,%esi
call   1090 <valueAt@plt>
cmp    $0x28,%al
jne    128a <main+0x10a>
mov    0x8(%rsp),%rdi
lea    0x1(%rbx),%ebp
mov    %ebp,%esi
call   1090 <valueAt@plt>
cmp    $0x29,%al
je     1210 <main+0x90>
mov    0x8(%rsp),%rdi
mov    %ebx,%esi
call   1090 <valueAt@plt>
cmp    $0x5b,%al
jne    12b1 <main+0x131>
mov    0x8(%rsp),%rdi
lea    0x1(%rbx),%ebp
mov    %ebp,%esi
call   1090 <valueAt@plt>
cmp    $0x5d,%al
je     1210 <main+0x90>
mov    0x8(%rsp),%rdi
mov    %ebx,%esi
call   1090 <valueAt@plt>
cmp    $0x7b,%al
jne    122a <main+0xaa>
mov    0x8(%rsp),%rdi
lea    0x1(%rbx),%ebp
mov    %ebp,%esi
call   1090 <valueAt@plt>
cmp    $0x7d,%al
je     1210 <main+0x90>
jmp    122a <main+0xaa>
mov    0x8(%rsp),%rdi
call   1070 <show@plt>
mov    0x8(%rsp),%rdi
call   1050 <length@plt>
test   %eax,%eax
lea    0xd08(%rip),%rax
lea    0xcfb(%rip),%rdi
cmove  %rax,%rdi
call   1060 <puts@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.string_node = type { i32 }
@.str = [2 x i8] c" \00"
@.str.1 = [4 x i8] c"^^\0A\00"
@.str.2 = [9 x i8] c"correct\0A\00"
@.str.3 = [7 x i8] c"wrong\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.string_node*
%3 = alloca i8
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 0, i32* %1
store %struct.string_node* null, %struct.string_node** %2
br label %7
7: ; preds = %11, %0
%8 = call signext i8 (...) @getchar()
store i8 %8, i8* %3
%9 = sext i8 %8 to i32
%10 = icmp ne i32 %9, 10
br i1 %10, label %11, label %14
11: ; preds = %7
%12 = load i8, i8* %3
%13 = call i32 @append(%struct.string_node** %2, i8 signext %12)
br label %7
14: ; preds = %7
br label %15
15: ; preds = %14, %90
store i32 1, i32* %4
%16 = load %struct.string_node*, %struct.string_node** %2
%17 = call i32 @length(%struct.string_node* %16)
%18 = sub nsw i32 %17, 2
store i32 %18, i32* %5
br label %19
19: ; preds = %83, %15
%20 = load i32, i32* %5
%21 = icmp sle i32 0, %20
br i1 %21, label %22, label %86
22: ; preds = %19
%23 = load %struct.string_node*, %struct.string_node** %2
%24 = call i32 @show(%struct.string_node* %23)
store i32 0, i32* %6
br label %25
25: ; preds = %31, %22
%26 = load i32, i32* %6
%27 = load i32, i32* %5
%28 = icmp slt i32 %26, %27
br i1 %28, label %29, label %34
29: ; preds = %25
%30 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %31
31: ; preds = %29
%32 = load i32, i32* %6
%33 = add nsw i32 %32, 1
store i32 %33, i32* %6
br label %25
34: ; preds = %25
%35 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%36 = load %struct.string_node*, %struct.string_node** %2
%37 = load i32, i32* %5
%38 = call signext i8 @valueAt(%struct.string_node* %36, i32 %37)
%39 = sext i8 %38 to i32
%40 = icmp eq i32 %39, 40
br i1 %40, label %41, label %48
41: ; preds = %34
%42 = load %struct.string_node*, %struct.string_node** %2
%43 = load i32, i32* %5
%44 = add nsw i32 %43, 1
%45 = call signext i8 @valueAt(%struct.string_node* %42, i32 %44)
%46 = sext i8 %45 to i32
%47 = icmp eq i32 %46, 41
br i1 %47, label %74, label %48
48: ; preds = %41, %34
%49 = load %struct.string_node*, %struct.string_node** %2
%50 = load i32, i32* %5
%51 = call signext i8 @valueAt(%struct.string_node* %49, i32 %50)
%52 = sext i8 %51 to i32
%53 = icmp eq i32 %52, 91
br i1 %53, label %54, label %61
54: ; preds = %48
%55 = load %struct.string_node*, %struct.string_node** %2
%56 = load i32, i32* %5
%57 = add nsw i32 %56, 1
%58 = call signext i8 @valueAt(%struct.string_node* %55, i32 %57)
%59 = sext i8 %58 to i32
%60 = icmp eq i32 %59, 93
br i1 %60, label %74, label %61
61: ; preds = %54, %48
%62 = load %struct.string_node*, %struct.string_node** %2
%63 = load i32, i32* %5
%64 = call signext i8 @valueAt(%struct.string_node* %62, i32 %63)
%65 = sext i8 %64 to i32
%66 = icmp eq i32 %65, 123
br i1 %66, label %67, label %82
67: ; preds = %61
%68 = load %struct.string_node*, %struct.string_node** %2
%69 = load i32, i32* %5
%70 = add nsw i32 %69, 1
%71 = call signext i8 @valueAt(%struct.string_node* %68, i32 %70)
%72 = sext i8 %71 to i32
%73 = icmp eq i32 %72, 125
br i1 %73, label %74, label %82
74: ; preds = %67, %54, %41
%75 = load i32, i32* %5
%76 = add nsw i32 %75, 1
%77 = call i32 @deleteAt(%struct.string_node** %2, i32 %76)
%78 = load i32, i32* %5
%79 = call i32 @deleteAt(%struct.string_node** %2, i32 %78)
store i32 0, i32* %4
%80 = load i32, i32* %5
%81 = add nsw i32 %80, -1
store i32 %81, i32* %5
br label %82
82: ; preds = %74, %67, %61
br label %83
83: ; preds = %82
%84 = load i32, i32* %5
%85 = add nsw i32 %84, -1
store i32 %85, i32* %5
br label %19
86: ; preds = %19
%87 = load i32, i32* %4
%88 = icmp ne i32 %87, 0
br i1 %88, label %89, label %90
89: ; preds = %86
br label %91
90: ; preds = %86
br label %15
91: ; preds = %89
%92 = load %struct.string_node*, %struct.string_node** %2
%93 = call i32 @show(%struct.string_node* %92)
%94 = load %struct.string_node*, %struct.string_node** %2
%95 = call i32 @length(%struct.string_node* %94)
%96 = icmp eq i32 %95, 0
br i1 %96, label %97, label %99
97: ; preds = %91
%98 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
br label %101
99: ; preds = %91
%100 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
br label %101
101: ; preds = %99, %97
ret i32 0
}

LLVM IR (-O2):
%struct.string_node = type { i32 }
@str = [6 x i8] c"wrong\00"
@str.4 = [8 x i8] c"correct\00"
@str.5 = [3 x i8] c"^^\00"
define i32 @main() {
%1 = alloca %struct.string_node*
%2 = bitcast %struct.string_node** %1 to i8*
store %struct.string_node* null, %struct.string_node** %1
%3 = call signext i8 (...) @getchar()
%4 = icmp eq i8 %3, 10
br i1 %4, label %10, label %5
5: ; preds = %0, %5
%6 = phi i8 [ %8, %5 ], [ %3, %0 ]
%7 = call i32 @append(%struct.string_node** %1, i8 signext %6)
%8 = call signext i8 (...) @getchar()
%9 = icmp eq i8 %8, 10
br i1 %9, label %10, label %5
10: ; preds = %5, %0
br label %11
11: ; preds = %10, %66
%12 = load %struct.string_node*, %struct.string_node** %1
%13 = call i32 @length(%struct.string_node* %12)
%14 = icmp sgt i32 %13, 1
br i1 %14, label %15, label %68
15: ; preds = %11
%16 = add nsw i32 %13, -2
br label %17
17: ; preds = %15, %61
%18 = phi i32 [ %64, %61 ], [ %16, %15 ]
%19 = phi i32 [ %62, %61 ], [ 1, %15 ]
%20 = load %struct.string_node*, %struct.string_node** %1
%21 = call i32 @show(%struct.string_node* %20)
%22 = icmp eq i32 %18, 0
br i1 %22, label %28, label %23
23: ; preds = %17, %23
%24 = phi i32 [ %26, %23 ], [ 0, %17 ]
%25 = call i32 @putchar(i32 32)
%26 = add nuw nsw i32 %24, 1
%27 = icmp eq i32 %26, %18
br i1 %27, label %28, label %23
28: ; preds = %23, %17
%29 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @str.5, i64 0, i64 0))
%30 = load %struct.string_node*, %struct.string_node** %1
%31 = call signext i8 @valueAt(%struct.string_node* %30, i32 %18)
%32 = icmp eq i8 %31, 40
br i1 %32, label %33, label %38
33: ; preds = %28
%34 = load %struct.string_node*, %struct.string_node** %1
%35 = add nsw i32 %18, 1
%36 = call signext i8 @valueAt(%struct.string_node* %34, i32 %35)
%37 = icmp eq i8 %36, 41
br i1 %37, label %56, label %38
38: ; preds = %33, %28
%39 = load %struct.string_node*, %struct.string_node** %1
%40 = call signext i8 @valueAt(%struct.string_node* %39, i32 %18)
%41 = icmp eq i8 %40, 91
br i1 %41, label %42, label %47
42: ; preds = %38
%43 = load %struct.string_node*, %struct.string_node** %1
%44 = add nsw i32 %18, 1
%45 = call signext i8 @valueAt(%struct.string_node* %43, i32 %44)
%46 = icmp eq i8 %45, 93
br i1 %46, label %56, label %47
47: ; preds = %42, %38
%48 = load %struct.string_node*, %struct.string_node** %1
%49 = call signext i8 @valueAt(%struct.string_node* %48, i32 %18)
%50 = icmp eq i8 %49, 123
br i1 %50, label %51, label %61
51: ; preds = %47
%52 = load %struct.string_node*, %struct.string_node** %1
%53 = add nsw i32 %18, 1
%54 = call signext i8 @valueAt(%struct.string_node* %52, i32 %53)
%55 = icmp eq i8 %54, 125
br i1 %55, label %56, label %61
56: ; preds = %51, %42, %33
%57 = phi i32 [ %53, %51 ], [ %44, %42 ], [ %35, %33 ]
%58 = call i32 @deleteAt(%struct.string_node** %1, i32 %57)
%59 = call i32 @deleteAt(%struct.string_node** %1, i32 %18)
%60 = add nsw i32 %18, -1
br label %61
61: ; preds = %47, %51, %56
%62 = phi i32 [ 0, %56 ], [ %19, %51 ], [ %19, %47 ]
%63 = phi i32 [ %60, %56 ], [ %18, %51 ], [ %18, %47 ]
%64 = add nsw i32 %63, -1
%65 = icmp sgt i32 %63, 0
br i1 %65, label %17, label %66
66: ; preds = %61
%67 = icmp eq i32 %62, 0
br i1 %67, label %11, label %68
68: ; preds = %11, %66
%69 = load %struct.string_node*, %struct.string_node** %1
%70 = call i32 @show(%struct.string_node* %69)
%71 = load %struct.string_node*, %struct.string_node** %1
%72 = call i32 @length(%struct.string_node* %71)
%73 = icmp eq i32 %72, 0
%74 = select i1 %73, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @str.4, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @str, i64 0, i64 0)
%75 = call i32 @puts(i8* dereferenceable(1) %74)
ret i32 0
}