#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);
int main() {
  int c, step = 1, floor = 0, basement = 0;
  while ((c = getchar()) != EOF) {
    switch (c) {
    case '(':
      ++floor;
      break;
    case ')':
      --floor;
      if (floor < 0 && !basement) {
        basement = step;
      }
      break;
    default:
      continue;
    }
    ++step;
  }
  printf("Floor: %d\nFirst basement visit: %d\n", floor, basement);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    $0x0,%al
call   1040 <getchar@plt>
mov    %eax,-0x8(%rbp)
mov    0x2e93(%rip),%rcx
cmp    (%rcx),%eax
je     11cb <main+0xab>
mov    -0x8(%rbp),%eax
mov    %eax,-0x18(%rbp)
sub    $0x28,%eax
je     1182 <main+0x62>
jmp    1171 <main+0x51>
mov    -0x18(%rbp),%eax
sub    $0x29,%eax
je     1190 <main+0x70>
jmp    11b8 <main+0x98>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    11bd <main+0x9d>
mov    -0x10(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jge    11b3 <main+0x93>
cmpl   $0x0,-0x14(%rbp)
jne    11b3 <main+0x93>
mov    -0xc(%rbp),%eax
mov    %eax,-0x14(%rbp)
jmp    11bd <main+0x9d>
jmp    1144 <main+0x24>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1144 <main+0x24>
mov    -0x10(%rbp),%esi
mov    -0x14(%rbp),%edx
lea    0xe28(%rip),%rdi
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    $0x1,%r15d
mov    0x2eb4(%rip),%rbp
xor    %ebx,%ebx
xor    %r14d,%r14d
nopl   0x0(%rax)
xor    %eax,%eax
call   1040 <getchar@plt>
cmp    0x0(%rbp),%eax
je     117a <main+0x5a>
cmp    $0x29,%eax
je     115f <main+0x3f>
cmp    $0x28,%eax
jne    1140 <main+0x20>
add    $0x1,%ebx
add    $0x1,%r15d
jmp    1140 <main+0x20>
test   %r14d,%r14d
mov    %r15d,%eax
cmovne %r14d,%eax
test   %ebx,%ebx
lea    -0x1(%rbx),%ecx
cmovle %eax,%r14d
add    $0x1,%r15d
mov    %ecx,%ebx
jmp    1140 <main+0x20>
lea    0xe7f(%rip),%rdi
mov    %ebx,%esi
mov    %r14d,%edx
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@EOF = global i32 0
@.str = [36 x i8] c"Floor: %d\0AFirst basement visit: %d\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 1, i32* %3
store i32 0, i32* %4
store i32 0, i32* %5
br label %6
6: ; preds = %27, %26, %0
%7 = call i32 (...) @getchar()
store i32 %7, i32* %2
%8 = load i32, i32* @EOF
%9 = icmp ne i32 %7, %8
br i1 %9, label %10, label %30
10: ; preds = %6
%11 = load i32, i32* %2
switch i32 %11, label %26 [
i32 40, label %12
i32 41, label %15
]
12: ; preds = %10
%13 = load i32, i32* %4
%14 = add nsw i32 %13, 1
store i32 %14, i32* %4
br label %27
15: ; preds = %10
%16 = load i32, i32* %4
%17 = add nsw i32 %16, -1
store i32 %17, i32* %4
%18 = load i32, i32* %4
%19 = icmp slt i32 %18, 0
br i1 %19, label %20, label %25
20: ; preds = %15
%21 = load i32, i32* %5
%22 = icmp ne i32 %21, 0
br i1 %22, label %25, label %23
23: ; preds = %20
%24 = load i32, i32* %3
store i32 %24, i32* %5
br label %25
25: ; preds = %23, %20, %15
br label %27
26: ; preds = %10
br label %6
27: ; preds = %25, %12
%28 = load i32, i32* %3
%29 = add nsw i32 %28, 1
store i32 %29, i32* %3
br label %6
30: ; preds = %6
%31 = load i32, i32* %4
%32 = load i32, i32* %5
%33 = call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), i32 %31, i32 %32)
%34 = load i32, i32* %1
ret i32 %34
}

LLVM IR (-O2):
@EOF = global i32 0
@.str = [36 x i8] c"Floor: %d\0AFirst basement visit: %d\0A\00"
define i32 @main() {
br label %1
1: ; preds = %18, %0
%2 = phi i32 [ %21, %18 ], [ 1, %0 ]
%3 = phi i32 [ %19, %18 ], [ 0, %0 ]
%4 = phi i32 [ %20, %18 ], [ 0, %0 ]
br label %5
5: ; preds = %1, %9
%6 = tail call i32 (...) @getchar()
%7 = load i32, i32* @EOF
%8 = icmp eq i32 %6, %7
br i1 %8, label %22, label %9
9: ; preds = %5
switch i32 %6, label %5 [
i32 40, label %10
i32 41, label %12
]
10: ; preds = %9
%11 = add nsw i32 %3, 1
br label %18
12: ; preds = %9
%13 = add nsw i32 %3, -1
%14 = icmp sgt i32 %3, 0
%15 = icmp ne i32 %4, 0
%16 = select i1 %14, i1 true, i1 %15
%17 = select i1 %16, i32 %4, i32 %2
br label %18
18: ; preds = %12, %10
%19 = phi i32 [ %11, %10 ], [ %13, %12 ]
%20 = phi i32 [ %4, %10 ], [ %17, %12 ]
%21 = add nuw nsw i32 %2, 1
br label %1
22: ; preds = %5
%23 = tail call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), i32 %3, i32 %4)
ret i32 0
}