#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
char EOF;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
char fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ printf(char *, int);
int main(int args, char **argv) {
  FILE *fp;
  int floors = 0;
  char input;
  fp = fopen("./input.txt", "r");
  while ((input = fgetc(fp)) != EOF) {
    if (input == '(') {
      floors += 1;
    } else if (input == ')') {
      floors -= 1;
    } else {
    }
  }
  fclose(fp);
  printf("Santa is at floor %d.", floors);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x1c(%rbp)
lea    0xe9c(%rip),%rdi
lea    0xea1(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %al,-0x1d(%rbp)
movsbl %al,%eax
mov    0x2e5e(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     11da <main+0x9a>
movsbl -0x1d(%rbp),%eax
cmp    $0x28,%eax
jne    11b0 <main+0x70>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11d5 <main+0x95>
movsbl -0x1d(%rbp),%eax
cmp    $0x29,%eax
jne    11cb <main+0x8b>
mov    -0x1c(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11d0 <main+0x90>
jmp    11d0 <main+0x90>
jmp    11d5 <main+0x95>
jmp    1174 <main+0x34>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x1c(%rbp),%esi
lea    0xe21(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
lea    0xeb5(%rip),%rdi
lea    0xeba(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1050 <fgetc@plt>
mov    0x2e7f(%rip),%r14
xor    %ebp,%ebp
cmp    (%r14),%al
jne    118d <main+0x4d>
mov    %rbx,%rdi
call   1030 <fclose@plt>
lea    0xe8f(%rip),%rdi
mov    %ebp,%esi
call   1040 <printf@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret
xor    %ebp,%ebp
jmp    11b0 <main+0x70>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
add    $0xffffffff,%ebp
mov    %rbx,%rdi
call   1050 <fgetc@plt>
cmp    (%r14),%al
je     1170 <main+0x30>
cmp    $0x29,%al
je     11a0 <main+0x60>
cmp    $0x28,%al
jne    11a3 <main+0x63>
add    $0x1,%ebp
jmp    11a3 <main+0x63>

LLVM IR (-O0):
@.str = [12 x i8] c"./input.txt\00"
@.str.1 = [2 x i8] c"r\00"
@EOF = global i8 0
@.str.2 = [22 x i8] c"Santa is at floor %d.\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i8
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %7
%9 = call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %9, i32** %6
br label %10
10: ; preds = %33, %2
%11 = load i32*, i32** %6
%12 = call signext i8 @fgetc(i32* %11)
store i8 %12, i8* %8
%13 = sext i8 %12 to i32
%14 = load i8, i8* @EOF
%15 = sext i8 %14 to i32
%16 = icmp ne i32 %13, %15
br i1 %16, label %17, label %34
17: ; preds = %10
%18 = load i8, i8* %8
%19 = sext i8 %18 to i32
%20 = icmp eq i32 %19, 40
br i1 %20, label %21, label %24
21: ; preds = %17
%22 = load i32, i32* %7
%23 = add nsw i32 %22, 1
store i32 %23, i32* %7
br label %33
24: ; preds = %17
%25 = load i8, i8* %8
%26 = sext i8 %25 to i32
%27 = icmp eq i32 %26, 41
br i1 %27, label %28, label %31
28: ; preds = %24
%29 = load i32, i32* %7
%30 = sub nsw i32 %29, 1
store i32 %30, i32* %7
br label %32
31: ; preds = %24
br label %32
32: ; preds = %31, %28
br label %33
33: ; preds = %32, %21
br label %10
34: ; preds = %10
%35 = load i32*, i32** %6
%36 = call i32 @fclose(i32* %35)
%37 = load i32, i32* %7
%38 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i32 %37)
ret i32 0
}

LLVM IR (-O2):
@.str = [12 x i8] c"./input.txt\00"
@.str.1 = [2 x i8] c"r\00"
@EOF = global i8 0
@.str.2 = [22 x i8] c"Santa is at floor %d.\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%4 = tail call signext i8 @fgetc(i32* %3)
%5 = load i8, i8* @EOF
%6 = icmp eq i8 %4, %5
br i1 %6, label %19, label %7
7: ; preds = %2, %14
%8 = phi i8 [ %16, %14 ], [ %4, %2 ]
%9 = phi i32 [ %15, %14 ], [ 0, %2 ]
switch i8 %8, label %14 [
i8 40, label %10
i8 41, label %12
]
10: ; preds = %7
%11 = add nsw i32 %9, 1
br label %14
12: ; preds = %7
%13 = add nsw i32 %9, -1
br label %14
14: ; preds = %7, %12, %10
%15 = phi i32 [ %11, %10 ], [ %13, %12 ], [ %9, %7 ]
%16 = tail call signext i8 @fgetc(i32* %3)
%17 = load i8, i8* @EOF
%18 = icmp eq i8 %16, %17
br i1 %18, label %19, label %7
19: ; preds = %14, %2
%20 = phi i32 [ 0, %2 ], [ %15, %14 ]
%21 = tail call i32 @fclose(i32* %3)
%22 = tail call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i32 %20)
ret i32 0
}