#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 SIGUSR2;
int /*<<< orphan*/ STDIN_FILENO;
int /*<<< orphan*/ doLeft();
int /*<<< orphan*/ doRight();
int /*<<< orphan*/ doRotate();
int /*<<< orphan*/ read(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ signal(int, void (*)(int));
int /*<<< orphan*/ updateBrickLocation();
void handleSignal(int sigint) {
  char selectedChar = 0;
  signal(SIGUSR2, handleSignal);
  if (sigint == SIGUSR2) {
    read(STDIN_FILENO, &selectedChar, 1);
    switch (selectedChar) {
    case 'a':
      doLeft();
      break;
    case 'd':
      doRight();
      break;
    case 'w':
      doRotate();
      break;
    case 's':
      updateBrickLocation();
      break;
    }
  }
}


x86 assembly (clang, -O0):
<handleSignal>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
movb   $0x0,-0x5(%rbp)
mov    0x2e62(%rip),%rax
mov    (%rax),%edi
mov    0x2e69(%rip),%rsi
call   1060 <signal@plt>
mov    -0x4(%rbp),%eax
mov    0x2e4a(%rip),%rcx
cmp    (%rcx),%eax
jne    1207 <handleSignal+0xa7>
mov    0x2e33(%rip),%rax
mov    (%rax),%edi
lea    -0x5(%rbp),%rsi
mov    $0x1,%edx
call   1050 <read@plt>
movsbl -0x5(%rbp),%eax
add    $0xffffff9f,%eax
mov    %eax,%ecx
mov    %rcx,-0x10(%rbp)
sub    $0x16,%eax
ja     1202 <handleSignal+0xa2>
mov    -0x10(%rbp),%rax
lea    0xe32(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    $0x0,%al
call   1040 <doLeft@plt>
jmp    1202 <handleSignal+0xa2>
mov    $0x0,%al
call   1030 <doRight@plt>
jmp    1202 <handleSignal+0xa2>
mov    $0x0,%al
call   1070 <doRotate@plt>
jmp    1202 <handleSignal+0xa2>
mov    $0x0,%al
call   1080 <updateBrickLocation@plt>
jmp    1207 <handleSignal+0xa7>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<handleSignal>:
push   %r14
push   %rbx
push   %rax
mov    %edi,%ebx
movb   $0x0,0x7(%rsp)
mov    0x2e66(%rip),%r14
mov    (%r14),%edi
mov    0x2e6c(%rip),%rsi
call   1060 <signal@plt>
cmp    %ebx,(%r14)
jne    11c9 <handleSignal+0x69>
mov    0x2e43(%rip),%rax
mov    (%rax),%edi
lea    0x7(%rsp),%rsi
mov    $0x1,%edx
call   1050 <read@plt>
movsbl 0x7(%rsp),%eax
add    $0xffffff9f,%eax
cmp    $0x16,%eax
ja     11c9 <handleSignal+0x69>
lea    0xe4e(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1040 <doLeft@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <doRight@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1080 <updateBrickLocation@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1070 <doRotate@plt>

LLVM IR (-O0):
@SIGUSR2 = global i32 0
@STDIN_FILENO = global i32 0
define void @handleSignal(i32 %0) {
%2 = alloca i32
%3 = alloca i8
store i32 %0, i32* %2
store i8 0, i8* %3
%4 = load i32, i32* @SIGUSR2
%5 = call i32 @signal(i32 %4, void (i32)* @handleSignal)
%6 = load i32, i32* %2
%7 = load i32, i32* @SIGUSR2
%8 = icmp eq i32 %6, %7
br i1 %8, label %9, label %23
9: ; preds = %1
%10 = load i32, i32* @STDIN_FILENO
%11 = call i32 @read(i32 %10, i8* %3, i32 1)
%12 = load i8, i8* %3
%13 = sext i8 %12 to i32
switch i32 %13, label %22 [
i32 97, label %14
i32 100, label %16
i32 119, label %18
i32 115, label %20
]
14: ; preds = %9
%15 = call i32 (...) @doLeft()
br label %22
16: ; preds = %9
%17 = call i32 (...) @doRight()
br label %22
18: ; preds = %9
%19 = call i32 (...) @doRotate()
br label %22
20: ; preds = %9
%21 = call i32 (...) @updateBrickLocation()
br label %22
22: ; preds = %9, %20, %18, %16, %14
br label %23
23: ; preds = %22, %1
ret void
}

LLVM IR (-O2):
@SIGUSR2 = global i32 0
@STDIN_FILENO = global i32 0
define void @handleSignal(i32 %0) {
%2 = alloca i8
store i8 0, i8* %2
%3 = load i32, i32* @SIGUSR2
%4 = tail call i32 @signal(i32 %3, void (i32)* @handleSignal)
%5 = load i32, i32* @SIGUSR2
%6 = icmp eq i32 %5, %0
br i1 %6, label %7, label %20
7: ; preds = %1
%8 = load i32, i32* @STDIN_FILENO
%9 = call i32 @read(i32 %8, i8* %2, i32 1)
%10 = load i8, i8* %2
%11 = sext i8 %10 to i32
switch i32 %11, label %20 [
i32 97, label %12
i32 100, label %14
i32 119, label %16
i32 115, label %18
]
12: ; preds = %7
%13 = tail call i32 (...) @doLeft()
br label %20
14: ; preds = %7
%15 = tail call i32 (...) @doRight()
br label %20
16: ; preds = %7
%17 = tail call i32 (...) @doRotate()
br label %20
18: ; preds = %7
%19 = tail call i32 (...) @updateBrickLocation()
br label %20
20: ; preds = %12, %14, %16, %18, %7, %1
ret void
}