#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 */
char getchar();
int /*<<< orphan*/ is_empty();
char pop();
int /*<<< orphan*/ push(char);
bool is_matched(void) {
  char ch = getchar();
  while (ch != '\n') {
    if (ch == '{' || ch == '(') {
      push(ch);
      ch = getchar();
    } else if (ch == '}') {
      if (pop() != '{') {
        return false;
      } else {
        ch = getchar();
      }
    } else if (ch == ')') {
      if (pop() != '(') {
        return false;
      } else {
        ch = getchar();
      }
    }
  }
  if (!is_empty()) {
    return false;
  } else {
    return true;
  }
}


x86 assembly (clang, -O0):
<is_matched>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x0,%al
call   1050 <getchar@plt>
mov    %al,-0x5(%rbp)
movsbl -0x5(%rbp),%eax
cmp    $0xa,%eax
je     1216 <is_matched+0xd6>
movsbl -0x5(%rbp),%eax
cmp    $0x7b,%eax
je     1179 <is_matched+0x39>
movsbl -0x5(%rbp),%eax
cmp    $0x28,%eax
jne    1191 <is_matched+0x51>
movsbl -0x5(%rbp),%edi
call   1060 <push@plt>
mov    $0x0,%al
call   1050 <getchar@plt>
mov    %al,-0x5(%rbp)
jmp    1211 <is_matched+0xd1>
movsbl -0x5(%rbp),%eax
cmp    $0x7d,%eax
jne    11cc <is_matched+0x8c>
mov    $0x0,%al
call   1040 <pop@plt>
movsbl %al,%eax
cmp    $0x7b,%eax
je     11bd <is_matched+0x7d>
movl   $0x0,-0x4(%rbp)
jmp    1239 <is_matched+0xf9>
mov    $0x0,%al
call   1050 <getchar@plt>
mov    %al,-0x5(%rbp)
jmp    120c <is_matched+0xcc>
movsbl -0x5(%rbp),%eax
cmp    $0x29,%eax
jne    1207 <is_matched+0xc7>
mov    $0x0,%al
call   1040 <pop@plt>
movsbl %al,%eax
cmp    $0x28,%eax
je     11f8 <is_matched+0xb8>
movl   $0x0,-0x4(%rbp)
jmp    1239 <is_matched+0xf9>
mov    $0x0,%al
call   1050 <getchar@plt>
mov    %al,-0x5(%rbp)
jmp    1207 <is_matched+0xc7>
jmp    120c <is_matched+0xcc>
jmp    1211 <is_matched+0xd1>
jmp    1152 <is_matched+0x12>
mov    $0x0,%al
call   1030 <is_empty@plt>
cmp    $0x0,%eax
jne    1232 <is_matched+0xf2>
movl   $0x0,-0x4(%rbp)
jmp    1239 <is_matched+0xf9>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<is_matched>:
push   %rbx
xor    %eax,%eax
call   1050 <getchar@plt>
nopl   0x0(%rax,%rax,1)
cmp    $0x28,%al
jle    1170 <is_matched+0x30>
cmp    $0x29,%al
je     1190 <is_matched+0x50>
cmp    $0x7d,%al
je     11a0 <is_matched+0x60>
cmp    $0x7b,%al
jne    1150 <is_matched+0x10>
jmp    1178 <is_matched+0x38>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
cmp    $0xa,%al
je     11af <is_matched+0x6f>
cmp    $0x28,%al
jne    1150 <is_matched+0x10>
movsbl %al,%edi
call   1060 <push@plt>
jmp    1141 <is_matched+0x1>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
xor    %ebx,%ebx
xor    %eax,%eax
call   1040 <pop@plt>
cmp    $0x28,%al
je     1141 <is_matched+0x1>
jmp    11bd <is_matched+0x7d>
nop
xor    %ebx,%ebx
xor    %eax,%eax
call   1040 <pop@plt>
cmp    $0x7b,%al
je     1141 <is_matched+0x1>
jmp    11bd <is_matched+0x7d>
xor    %eax,%eax
call   1030 <is_empty@plt>
xor    %ebx,%ebx
test   %eax,%eax
setne  %bl
mov    %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
define i32 @is_matched() {
%1 = alloca i32
%2 = alloca i8
%3 = call signext i8 (...) @getchar()
store i8 %3, i8* %2
br label %4
4: ; preds = %46, %0
%5 = load i8, i8* %2
%6 = sext i8 %5 to i32
%7 = icmp ne i32 %6, 10
br i1 %7, label %8, label %47
8: ; preds = %4
%9 = load i8, i8* %2
%10 = sext i8 %9 to i32
%11 = icmp eq i32 %10, 123
br i1 %11, label %16, label %12
12: ; preds = %8
%13 = load i8, i8* %2
%14 = sext i8 %13 to i32
%15 = icmp eq i32 %14, 40
br i1 %15, label %16, label %20
16: ; preds = %12, %8
%17 = load i8, i8* %2
%18 = call i32 @push(i8 signext %17)
%19 = call signext i8 (...) @getchar()
store i8 %19, i8* %2
br label %46
20: ; preds = %12
%21 = load i8, i8* %2
%22 = sext i8 %21 to i32
%23 = icmp eq i32 %22, 125
br i1 %23, label %24, label %32
24: ; preds = %20
%25 = call signext i8 (...) @pop()
%26 = sext i8 %25 to i32
%27 = icmp ne i32 %26, 123
br i1 %27, label %28, label %29
28: ; preds = %24
store i32 0, i32* %1
br label %52
29: ; preds = %24
%30 = call signext i8 (...) @getchar()
store i8 %30, i8* %2
br label %31
31: ; preds = %29
br label %45
32: ; preds = %20
%33 = load i8, i8* %2
%34 = sext i8 %33 to i32
%35 = icmp eq i32 %34, 41
br i1 %35, label %36, label %44
36: ; preds = %32
%37 = call signext i8 (...) @pop()
%38 = sext i8 %37 to i32
%39 = icmp ne i32 %38, 40
br i1 %39, label %40, label %41
40: ; preds = %36
store i32 0, i32* %1
br label %52
41: ; preds = %36
%42 = call signext i8 (...) @getchar()
store i8 %42, i8* %2
br label %43
43: ; preds = %41
br label %44
44: ; preds = %43, %32
br label %45
45: ; preds = %44, %31
br label %46
46: ; preds = %45, %16
br label %4
47: ; preds = %4
%48 = call i32 (...) @is_empty()
%49 = icmp ne i32 %48, 0
br i1 %49, label %51, label %50
50: ; preds = %47
store i32 0, i32* %1
br label %52
51: ; preds = %47
store i32 1, i32* %1
br label %52
52: ; preds = %51, %50, %40, %28
%53 = load i32, i32* %1
ret i32 %53
}

LLVM IR (-O2):
define i32 @is_matched() {
br label %1
1: ; preds = %12, %0
%2 = tail call signext i8 (...) @getchar()
br label %3
3: ; preds = %1, %3
switch i8 %2, label %3 [
i8 10, label %13
i8 123, label %4
i8 40, label %4
i8 125, label %6
i8 41, label %9
]
4: ; preds = %3, %3
%5 = tail call i32 @push(i8 signext %2)
br label %12
6: ; preds = %3
%7 = tail call signext i8 (...) @pop()
%8 = icmp eq i8 %7, 123
br i1 %8, label %12, label %17
9: ; preds = %3
%10 = tail call signext i8 (...) @pop()
%11 = icmp eq i8 %10, 40
br i1 %11, label %12, label %17
12: ; preds = %9, %6, %4
br label %1
13: ; preds = %3
%14 = tail call i32 (...) @is_empty()
%15 = icmp ne i32 %14, 0
%16 = zext i1 %15 to i32
br label %17
17: ; preds = %9, %6, %13
%18 = phi i32 [ %16, %13 ], [ 0, %6 ], [ 0, %9 ]
ret i32 %18
}