#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 EXIT_SUCCESS;
int getchar();
int /*<<< orphan*/ printf(char *, ...);
int main() {
  int ch;
  int braces;
  braces = 0;
  while ((ch = getchar()) != EOF) {
    if (ch == '{')
      braces += 1;
    if (ch == '}')
      if (braces == 0)
        printf("Extra closing brace!\n");
      else
        braces -= 1;
  }
  if (braces > 0)
    printf("%d unmatched opening brace(s)!\n", braces);
  return EXIT_SUCCESS;
}


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   1040 <getchar@plt>
mov    %eax,-0x8(%rbp)
mov    0x2ea1(%rip),%rcx
cmp    (%rcx),%eax
je     119c <main+0x7c>
cmpl   $0x7b,-0x8(%rbp)
jne    1162 <main+0x42>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
cmpl   $0x7d,-0x8(%rbp)
jne    1197 <main+0x77>
cmpl   $0x0,-0xc(%rbp)
jne    1189 <main+0x69>
lea    0xe83(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1192 <main+0x72>
mov    -0xc(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1197 <main+0x77>
jmp    1136 <main+0x16>
cmpl   $0x0,-0xc(%rbp)
jle    11b7 <main+0x97>
mov    -0xc(%rbp),%esi
lea    0xe66(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2e1a(%rip),%rax
mov    (%rax),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
xor    %eax,%eax
call   1050 <getchar@plt>
mov    0x2ea5(%rip),%r15
cmp    (%r15),%eax
je     11a4 <main+0x74>
lea    0xed1(%rip),%r14
xor    %ebx,%ebx
jmp    116f <main+0x3f>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
add    $0xffffffff,%ebx
xor    %eax,%eax
call   1050 <getchar@plt>
cmp    (%r15),%eax
je     1190 <main+0x60>
mov    %ebx,%ecx
xor    %ebx,%ebx
cmp    $0x7b,%eax
sete   %bl
add    %ecx,%ebx
cmp    $0x7d,%eax
jne    1163 <main+0x33>
test   %ebx,%ebx
jne    1160 <main+0x30>
mov    %r14,%rdi
call   1030 <puts@plt>
xor    %ebx,%ebx
jmp    1163 <main+0x33>
test   %ebx,%ebx
jle    11a4 <main+0x74>
lea    0xe65(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x2e2d(%rip),%rax
mov    (%rax),%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@EOF = global i32 0
@.str = [22 x i8] c"Extra closing brace!\0A\00"
@.str.1 = [32 x i8] c"%d unmatched opening brace(s)!\0A\00"
@EXIT_SUCCESS = global i32 0
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 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
br label %25
22: ; preds = %17
%23 = load i32, i32* %3
%24 = sub 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 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i32 %31)
br label %33
33: ; preds = %30, %27
%34 = load i32, i32* @EXIT_SUCCESS
ret i32 %34
}

LLVM IR (-O2):
@EOF = global i32 0
@.str.1 = [32 x i8] c"%d unmatched opening brace(s)!\0A\00"
@EXIT_SUCCESS = global i32 0
@str = [21 x i8] c"Extra closing brace!\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 ([21 x i8], [21 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 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i32 %18)
br label %26
26: ; preds = %0, %24, %22
%27 = load i32, i32* @EXIT_SUCCESS
ret i32 %27
}