#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 EOF;
int /*<<< orphan*/ change_state(int, int);
int check_paren_match(int);
int getchar();
scalar_t__ is_empty_paren();
int /*<<< orphan*/ printf(char *, int);
int main(void) {
  extern int state;
  extern int paren_stack_top;
  int last_char, cur_char;
  int line_num;
  int check_state;
  last_char = ' ';
  state = 0;
  paren_stack_top = 0;
  line_num = 1;
  while ((cur_char = getchar()) != EOF) {
    if (cur_char == '\n') {
      line_num++;
    }
    check_state = check_paren_match(cur_char);
    if (0 == check_state) {
      break;
    }
    change_state(cur_char, last_char);
    last_char = cur_char;
  }
  if (is_empty_paren() == 0 || check_state == 0) {
    printf("line %d: parentheses does not match.\n", line_num);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x20,-0x8(%rbp)
mov    0x2e6b(%rip),%rax
movl   $0x0,(%rax)
mov    0x2e56(%rip),%rax
movl   $0x0,(%rax)
movl   $0x1,-0x10(%rbp)
mov    $0x0,%al
call   1050 <getchar@plt>
mov    %eax,-0xc(%rbp)
mov    0x2e50(%rip),%rcx
cmp    (%rcx),%eax
je     11e4 <main+0x94>
cmpl   $0xa,-0xc(%rbp)
jne    11b3 <main+0x63>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%edi
call   1060 <check_paren_match@plt>
mov    %eax,-0x14(%rbp)
xor    %eax,%eax
cmp    -0x14(%rbp),%eax
jne    11ce <main+0x7e>
jmp    11e4 <main+0x94>
mov    -0xc(%rbp),%edi
mov    -0x8(%rbp),%esi
call   1040 <change_state@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x8(%rbp)
jmp    1187 <main+0x37>
mov    $0x0,%al
call   1070 <is_empty_paren@plt>
cmp    $0x0,%rax
je     11ff <main+0xaf>
cmpl   $0x0,-0x14(%rbp)
jne    120e <main+0xbe>
mov    -0x10(%rbp),%esi
lea    0xdf7(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    0x2e7a(%rip),%rax
movl   $0x0,(%rax)
mov    0x2e65(%rip),%rax
movl   $0x0,(%rax)
xor    %eax,%eax
call   1050 <getchar@plt>
mov    0x2e69(%rip),%r15
mov    $0x1,%ebx
cmp    (%r15),%eax
jne    11ab <main+0x5b>
xor    %eax,%eax
call   1070 <is_empty_paren@plt>
lea    0xe69(%rip),%rdi
mov    %ebx,%esi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    $0x20,%r14d
mov    $0x1,%ebx
cs nopw 0x0(%rax,%rax,1)
mov    %ebx,%ecx
mov    %eax,%ebp
xor    %ebx,%ebx
cmp    $0xa,%eax
sete   %bl
add    %ecx,%ebx
mov    %eax,%edi
call   1060 <check_paren_match@plt>
test   %eax,%eax
je     1189 <main+0x39>
mov    %ebp,%edi
mov    %r14d,%esi
call   1040 <change_state@plt>
xor    %eax,%eax
call   1050 <getchar@plt>
mov    %ebp,%r14d
cmp    (%r15),%eax
jne    11c0 <main+0x70>
xor    %eax,%eax
call   1070 <is_empty_paren@plt>
test   %rax,%rax
jne    119e <main+0x4e>
jmp    1190 <main+0x40>

LLVM IR (-O0):
@state = external global i32
@paren_stack_top = external global i32
@EOF = global i32 0
@.str = [38 x i8] c"line %d: parentheses does not match.\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %1
store i32 32, i32* %2
store i32 0, i32* @state
store i32 0, i32* @paren_stack_top
store i32 1, i32* %4
br label %6
6: ; preds = %22, %0
%7 = call i32 (...) @getchar()
store i32 %7, i32* %3
%8 = load i32, i32* @EOF
%9 = icmp ne i32 %7, %8
br i1 %9, label %10, label %27
10: ; preds = %6
%11 = load i32, i32* %3
%12 = icmp eq i32 %11, 10
br i1 %12, label %13, label %16
13: ; preds = %10
%14 = load i32, i32* %4
%15 = add nsw i32 %14, 1
store i32 %15, i32* %4
br label %16
16: ; preds = %13, %10
%17 = load i32, i32* %3
%18 = call i32 @check_paren_match(i32 %17)
store i32 %18, i32* %5
%19 = load i32, i32* %5
%20 = icmp eq i32 0, %19
br i1 %20, label %21, label %22
21: ; preds = %16
br label %27
22: ; preds = %16
%23 = load i32, i32* %3
%24 = load i32, i32* %2
%25 = call i32 @change_state(i32 %23, i32 %24)
%26 = load i32, i32* %3
store i32 %26, i32* %2
br label %6
27: ; preds = %21, %6
%28 = call i64 (...) @is_empty_paren()
%29 = icmp eq i64 %28, 0
br i1 %29, label %33, label %30
30: ; preds = %27
%31 = load i32, i32* %5
%32 = icmp eq i32 %31, 0
br i1 %32, label %33, label %36
33: ; preds = %30, %27
%34 = load i32, i32* %4
%35 = call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), i32 %34)
br label %36
36: ; preds = %33, %30
ret i32 0
}

LLVM IR (-O2):
@state = external global i32
@paren_stack_top = external global i32
@EOF = global i32 0
@.str = [38 x i8] c"line %d: parentheses does not match.\0A\00"
define i32 @main() {
store i32 0, i32* @state
store i32 0, i32* @paren_stack_top
%1 = tail call i32 (...) @getchar()
%2 = load i32, i32* @EOF
%3 = icmp eq i32 %1, %2
br i1 %3, label %18, label %4
4: ; preds = %0, %13
%5 = phi i32 [ %15, %13 ], [ %1, %0 ]
%6 = phi i32 [ %10, %13 ], [ 1, %0 ]
%7 = phi i32 [ %5, %13 ], [ 32, %0 ]
%8 = icmp eq i32 %5, 10
%9 = zext i1 %8 to i32
%10 = add nuw nsw i32 %6, %9
%11 = tail call i32 @check_paren_match(i32 %5)
%12 = icmp eq i32 %11, 0
br i1 %12, label %18, label %13
13: ; preds = %4
%14 = tail call i32 @change_state(i32 %5, i32 %7)
%15 = tail call i32 (...) @getchar()
%16 = load i32, i32* @EOF
%17 = icmp eq i32 %15, %16
br i1 %17, label %21, label %4
18: ; preds = %4, %0
%19 = phi i32 [ 1, %0 ], [ %10, %4 ]
%20 = tail call i64 (...) @is_empty_paren()
br label %24
21: ; preds = %13
%22 = tail call i64 (...) @is_empty_paren()
%23 = icmp eq i64 %22, 0
br i1 %23, label %24, label %27
24: ; preds = %18, %21
%25 = phi i32 [ %19, %18 ], [ %10, %21 ]
%26 = tail call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), i32 %25)
br label %27
27: ; preds = %21, %24
ret i32 0
}