#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*/ WINDOW;

/* Variables and functions */
int /*<<< orphan*/ EXIT_SUCCESS;
int /*<<< orphan*/ FreeWorm();
int /*<<< orphan*/ MoveWorm();
#define SIGALRM 130
#define SIGINT 129
#define SIGTERM 128
int /*<<< orphan*/ curs_set(int);
int /*<<< orphan*/ delwin(int /*<<< orphan*/ *);
int /*<<< orphan*/ endwin();
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ refresh();
void handler(int signum) {
  extern WINDOW *mainwin;
  extern int oldcur;
  switch (signum) {
  case SIGALRM:
    MoveWorm();
    return;
  case SIGTERM:
  case SIGINT:
    delwin(mainwin);
    curs_set(oldcur);
    endwin();
    refresh();
    FreeWorm();
    exit(EXIT_SUCCESS);
  }
}


x86 assembly (clang, -O0):
<handler>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x8(%rbp)
add    $0xffffff80,%eax
sub    $0x2,%eax
jb     11b1 <handler+0x41>
jmp    1192 <handler+0x22>
mov    -0x8(%rbp),%eax
sub    $0x82,%eax
jne    11f1 <handler+0x81>
jmp    11a5 <handler+0x35>
mov    $0x0,%al
call   1030 <MoveWorm@plt>
jmp    11f1 <handler+0x81>
mov    0x2e30(%rip),%rax
mov    (%rax),%rdi
call   1050 <delwin@plt>
mov    0x2e19(%rip),%rax
mov    (%rax),%edi
call   1090 <curs_set@plt>
mov    $0x0,%al
call   1070 <endwin@plt>
mov    $0x0,%al
call   1060 <refresh@plt>
mov    $0x0,%al
call   1040 <FreeWorm@plt>
mov    0x2de6(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<handler>:
cmp    $0x82,%edi
je     1181 <handler+0x11>
add    $0xffffff80,%edi
cmp    $0x2,%edi
jb     1188 <handler+0x18>
ret
xor    %eax,%eax
jmp    1030 <MoveWorm@plt>
push   %rax
mov    0x2e58(%rip),%rax
mov    (%rax),%rdi
call   1050 <delwin@plt>
mov    0x2e41(%rip),%rax
mov    (%rax),%edi
call   1090 <curs_set@plt>
xor    %eax,%eax
call   1070 <endwin@plt>
xor    %eax,%eax
call   1060 <refresh@plt>
xor    %eax,%eax
call   1040 <FreeWorm@plt>
mov    0x2e0e(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@mainwin = external global i32*
@oldcur = external global i32
@EXIT_SUCCESS = global i32 0
define void @handler(i32 %0) {
%2 = alloca i32
store i32 %0, i32* %2
%3 = load i32, i32* %2
switch i32 %3, label %16 [
i32 130, label %4
i32 128, label %6
i32 129, label %6
]
4: ; preds = %1
%5 = call i32 (...) @MoveWorm()
br label %16
6: ; preds = %1, %1
%7 = load i32*, i32** @mainwin
%8 = call i32 @delwin(i32* %7)
%9 = load i32, i32* @oldcur
%10 = call i32 @curs_set(i32 %9)
%11 = call i32 (...) @endwin()
%12 = call i32 (...) @refresh()
%13 = call i32 (...) @FreeWorm()
%14 = load i32, i32* @EXIT_SUCCESS
%15 = call i32 @exit(i32 %14)
unreachable
16: ; preds = %4, %1
ret void
}

LLVM IR (-O2):
@mainwin = external global i32*
@oldcur = external global i32
@EXIT_SUCCESS = global i32 0
define void @handler(i32 %0) {
switch i32 %0, label %14 [
i32 130, label %2
i32 128, label %4
i32 129, label %4
]
2: ; preds = %1
%3 = tail call i32 (...) @MoveWorm()
br label %14
4: ; preds = %1, %1
%5 = load i32*, i32** @mainwin
%6 = tail call i32 @delwin(i32* %5)
%7 = load i32, i32* @oldcur
%8 = tail call i32 @curs_set(i32 %7)
%9 = tail call i32 (...) @endwin()
%10 = tail call i32 (...) @refresh()
%11 = tail call i32 (...) @FreeWorm()
%12 = load i32, i32* @EXIT_SUCCESS
%13 = tail call i32 @exit(i32 %12)
unreachable
14: ; preds = %2, %1
ret void
}