#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 getchar();
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ puts(char *);
int main(void) {
  int ch;
  int brackets = 0;
  while ((ch = getchar()) != EOF) {
    if (ch == '{')
      brackets++;
    if (ch == '}') {
      if (brackets == 0)
        puts("Error: Extra closing brace!");
      else
        brackets--;
    }
  }
  if (brackets > 0)
    printf("Error: Unmatched opening braces - %d", brackets);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0xc(%rbp)
mov    $0x0,%al
call   1050 <getchar@plt>
mov    %eax,-0x8(%rbp)
mov    0x2e91(%rip),%rcx
cmp    (%rcx),%eax
je     11aa <main+0x7a>
cmpl   $0x7b,-0x8(%rbp)
jne    1172 <main+0x42>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
cmpl   $0x7d,-0x8(%rbp)
jne    11a5 <main+0x75>
cmpl   $0x0,-0xc(%rbp)
jne    1197 <main+0x67>
lea    0xe73(%rip),%rdi
call   1030 <puts@plt>
jmp    11a0 <main+0x70>
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xc(%rbp)
jmp    11a5 <main+0x75>
jmp    1146 <main+0x16>
cmpl   $0x0,-0xc(%rbp)
jle    11c3 <main+0x93>
mov    -0xc(%rbp),%esi
lea    0xe5e(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
xor    %eax,%eax
call   1050 <getchar@plt>
mov    0x2ea6(%rip),%rbx
cmp    (%rbx),%eax
je     11a2 <main+0x72>
lea    0xeb3(%rip),%r14
xor    %ebp,%ebp
jmp    116e <main+0x3e>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
add    $0xffffffff,%ebp
xor    %eax,%eax
call   1050 <getchar@plt>
cmp    (%rbx),%eax
je     1190 <main+0x60>
mov    %ebp,%ecx
xor    %ebp,%ebp
cmp    $0x7b,%eax
sete   %bpl
add    %ecx,%ebp
cmp    $0x7d,%eax
jne    1163 <main+0x33>
test   %ebp,%ebp
jne    1160 <main+0x30>
mov    %r14,%rdi
call   1030 <puts@plt>
xor    %ebp,%ebp
jmp    1163 <main+0x33>
test   %ebp,%ebp
jle    11a2 <main+0x72>
lea    0xe81(%rip),%rdi
mov    %ebp,%esi
call   1040 <printf@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@EOF = global i32 0
@.str = [28 x i8] c"Error: Extra closing brace!\00"
@.str.1 = [37 x i8] c"Error: Unmatched opening braces - %d\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %3
br label %4
4: ; preds = %26, %0
%5 = call i32 (...) @getchar()
store i32 %5, i32* %2
%6 = load i32, i32* @EOF
%7 = icmp ne i32 %5, %6
br i1 %7, label %8, label %27
8: ; preds = %4
%9 = load i32, i32* %2
%10 = icmp eq i32 %9, 123
br i1 %10, label %11, label %14
11: ; preds = %8
%12 = load i32, i32* %3
%13 = add nsw i32 %12, 1
store i32 %13, i32* %3
br label %14
14: ; preds = %11, %8
%15 = load i32, i32* %2
%16 = icmp eq i32 %15, 125
br i1 %16, label %17, label %26
17: ; preds = %14
%18 = load i32, i32* %3
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %17
%21 = call i32 @puts(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
br label %25
22: ; preds = %17
%23 = load i32, i32* %3
%24 = add nsw i32 %23, -1
store i32 %24, i32* %3
br label %25
25: ; preds = %22, %20
br label %26
26: ; preds = %25, %14
br label %4
27: ; preds = %4
%28 = load i32, i32* %3
%29 = icmp sgt i32 %28, 0
br i1 %29, label %30, label %33
30: ; preds = %27
%31 = load i32, i32* %3
%32 = call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), i32 %31)
br label %33
33: ; preds = %30, %27
ret i32 0
}

LLVM IR (-O2):
@EOF = global i32 0
@.str = [28 x i8] c"Error: Extra closing brace!\00"
@.str.1 = [37 x i8] c"Error: Unmatched opening braces - %d\00"
define i32 @main() {
%1 = tail call i32 (...) @getchar()
%2 = load i32, i32* @EOF
%3 = icmp eq i32 %1, %2
br i1 %3, label %26, label %4
4: ; preds = %0, %17
%5 = phi i32 [ %19, %17 ], [ %1, %0 ]
%6 = phi i32 [ %18, %17 ], [ 0, %0 ]
%7 = icmp eq i32 %5, 123
%8 = zext i1 %7 to i32
%9 = add nsw i32 %6, %8
%10 = icmp eq i32 %5, 125
br i1 %10, label %11, label %17
11: ; preds = %4
%12 = icmp eq i32 %9, 0
br i1 %12, label %13, label %15
13: ; preds = %11
%14 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
br label %17
15: ; preds = %11
%16 = add nsw i32 %9, -1
br label %17
17: ; preds = %13, %15, %4
%18 = phi i32 [ 0, %13 ], [ %16, %15 ], [ %9, %4 ]
%19 = tail call i32 (...) @getchar()
%20 = load i32, i32* @EOF
%21 = icmp eq i32 %19, %20
br i1 %21, label %22, label %4
22: ; preds = %17
%23 = icmp sgt i32 %18, 0
br i1 %23, label %24, label %26
24: ; preds = %22
%25 = tail call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), i32 %18)
br label %26
26: ; preds = %0, %24, %22
ret i32 0
}