#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 SIGCONT;
int SIGINT;
int SIGTSTP;
int SIGWINCH;
void SIG_DFL(int);
int /*<<< orphan*/ exit(scalar_t__);
scalar_t__ exit_ftselect(int);
int /*<<< orphan*/ init_termcaps();
int /*<<< orphan*/ resize_sig();
int /*<<< orphan*/ restore_termcaps();
int /*<<< orphan*/ send_suspend_signal();
int /*<<< orphan*/ signal(int, void (*)(int));
void signal_handler(int sig) {
  if (sig == SIGINT)
    exit(exit_ftselect(sig) + 128);
  else if (sig == SIGTSTP) {
    signal(SIGTSTP, SIG_DFL);
    signal(SIGCONT, signal_handler);
    restore_termcaps();
    send_suspend_signal();
  } else if (sig == SIGCONT) {
    signal(SIGTSTP, signal_handler);
    init_termcaps();
  } else if (sig == SIGWINCH)
    resize_sig();
}


x86 assembly (clang, -O0):
<signal_handler>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    0x2e5b(%rip),%rcx
cmp    (%rcx),%eax
jne    11a4 <signal_handler+0x34>
mov    -0x4(%rbp),%edi
call   1080 <exit_ftselect@plt>
mov    %rax,%rdi
add    $0x80,%rdi
call   1090 <exit@plt>
mov    -0x4(%rbp),%eax
mov    0x2e2a(%rip),%rcx
cmp    (%rcx),%eax
jne    11f3 <signal_handler+0x83>
mov    0x2e1b(%rip),%rax
mov    (%rax),%edi
mov    0x2df2(%rip),%rsi
call   1050 <signal@plt>
mov    0x2e16(%rip),%rax
mov    (%rax),%edi
mov    0x2de5(%rip),%rsi
call   1050 <signal@plt>
mov    $0x0,%al
call   1060 <restore_termcaps@plt>
mov    $0x0,%al
call   1040 <send_suspend_signal@plt>
jmp    1249 <signal_handler+0xd9>
mov    -0x4(%rbp),%eax
mov    0x2deb(%rip),%rcx
cmp    (%rcx),%eax
jne    1226 <signal_handler+0xb6>
mov    0x2dcc(%rip),%rax
mov    (%rax),%edi
mov    0x2dab(%rip),%rsi
call   1050 <signal@plt>
mov    $0x0,%al
call   1070 <init_termcaps@plt>
jmp    1244 <signal_handler+0xd4>
mov    -0x4(%rbp),%eax
mov    0x2da0(%rip),%rcx
cmp    (%rcx),%eax
jne    123f <signal_handler+0xcf>
mov    $0x0,%al
call   1030 <resize_sig@plt>
jmp    1244 <signal_handler+0xd4>
jmp    1249 <signal_handler+0xd9>
jmp    124e <signal_handler+0xde>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<signal_handler>:
push   %rax
mov    0x2e68(%rip),%rax
cmp    %edi,(%rax)
je     11ef <signal_handler+0x7f>
mov    0x2e55(%rip),%rax
mov    (%rax),%eax
cmp    %edi,%eax
jne    11b9 <signal_handler+0x49>
mov    0x2e28(%rip),%rsi
call   1050 <signal@plt>
mov    0x2e4c(%rip),%rax
mov    (%rax),%edi
mov    0x2e1b(%rip),%rsi
call   1050 <signal@plt>
xor    %eax,%eax
call   1060 <restore_termcaps@plt>
xor    %eax,%eax
pop    %rcx
jmp    1040 <send_suspend_signal@plt>
mov    0x2e28(%rip),%rcx
cmp    %edi,(%rcx)
jne    11da <signal_handler+0x6a>
mov    0x2df5(%rip),%rsi
mov    %eax,%edi
call   1050 <signal@plt>
xor    %eax,%eax
pop    %rcx
jmp    1070 <init_termcaps@plt>
mov    0x2def(%rip),%rax
cmp    %edi,(%rax)
jne    11ed <signal_handler+0x7d>
xor    %eax,%eax
pop    %rcx
jmp    1030 <resize_sig@plt>
pop    %rax
ret
call   1080 <exit_ftselect@plt>
lea    0x80(%rax),%rdi
call   1090 <exit@plt>

LLVM IR (-O0):
@SIGINT = global i32 0
@SIGTSTP = global i32 0
@SIGCONT = global i32 0
@SIGWINCH = global i32 0
define void @signal_handler(i32 %0) {
%2 = alloca i32
store i32 %0, i32* %2
%3 = load i32, i32* %2
%4 = load i32, i32* @SIGINT
%5 = icmp eq i32 %3, %4
br i1 %5, label %6, label %11
6: ; preds = %1
%7 = load i32, i32* %2
%8 = call i64 @exit_ftselect(i32 %7)
%9 = add nsw i64 %8, 128
%10 = call i32 @exit(i64 %9)
unreachable
11: ; preds = %1
%12 = load i32, i32* %2
%13 = load i32, i32* @SIGTSTP
%14 = icmp eq i32 %12, %13
br i1 %14, label %15, label %22
15: ; preds = %11
%16 = load i32, i32* @SIGTSTP
%17 = call i32 @signal(i32 %16, void (i32)* @SIG_DFL)
%18 = load i32, i32* @SIGCONT
%19 = call i32 @signal(i32 %18, void (i32)* @signal_handler)
%20 = call i32 (...) @restore_termcaps()
%21 = call i32 (...) @send_suspend_signal()
br label %38
22: ; preds = %11
%23 = load i32, i32* %2
%24 = load i32, i32* @SIGCONT
%25 = icmp eq i32 %23, %24
br i1 %25, label %26, label %30
26: ; preds = %22
%27 = load i32, i32* @SIGTSTP
%28 = call i32 @signal(i32 %27, void (i32)* @signal_handler)
%29 = call i32 (...) @init_termcaps()
br label %37
30: ; preds = %22
%31 = load i32, i32* %2
%32 = load i32, i32* @SIGWINCH
%33 = icmp eq i32 %31, %32
br i1 %33, label %34, label %36
34: ; preds = %30
%35 = call i32 (...) @resize_sig()
br label %36
36: ; preds = %34, %30
br label %37
37: ; preds = %36, %26
br label %38
38: ; preds = %37, %15
br label %39
39: ; preds = %38
ret void
}

LLVM IR (-O2):
@SIGINT = global i32 0
@SIGTSTP = global i32 0
@SIGCONT = global i32 0
@SIGWINCH = global i32 0
define void @signal_handler(i32 %0) {
%2 = load i32, i32* @SIGINT
%3 = icmp eq i32 %2, %0
br i1 %3, label %4, label %8
4: ; preds = %1
%5 = tail call i64 @exit_ftselect(i32 %0)
%6 = add nsw i64 %5, 128
%7 = tail call i32 @exit(i64 %6)
unreachable
8: ; preds = %1
%9 = load i32, i32* @SIGTSTP
%10 = icmp eq i32 %9, %0
br i1 %10, label %11, label %17
11: ; preds = %8
%12 = tail call i32 @signal(i32 %0, void (i32)* @SIG_DFL)
%13 = load i32, i32* @SIGCONT
%14 = tail call i32 @signal(i32 %13, void (i32)* @signal_handler)
%15 = tail call i32 (...) @restore_termcaps()
%16 = tail call i32 (...) @send_suspend_signal()
br label %28
17: ; preds = %8
%18 = load i32, i32* @SIGCONT
%19 = icmp eq i32 %18, %0
br i1 %19, label %20, label %23
20: ; preds = %17
%21 = tail call i32 @signal(i32 %9, void (i32)* @signal_handler)
%22 = tail call i32 (...) @init_termcaps()
br label %28
23: ; preds = %17
%24 = load i32, i32* @SIGWINCH
%25 = icmp eq i32 %24, %0
br i1 %25, label %26, label %28
26: ; preds = %23
%27 = tail call i32 (...) @resize_sig()
br label %28
28: ; preds = %11, %23, %26, %20
ret void
}