#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 SIGTSTP;
int /*<<< orphan*/ STDOUT_FILENO;
int /*<<< orphan*/ catchSignal(int, int);
int /*<<< orphan*/ getpid();
int /*<<< orphan*/ kill(int /*<<< orphan*/, int);
int /*<<< orphan*/ write(int /*<<< orphan*/, char *, int);
void handler(int signum) {
  if (signum == SIGTSTP) {
    write(STDOUT_FILENO, "got SIGTSTP\n", 12);
    catchSignal(SIGTSTP, 1);
    kill(getpid(), SIGTSTP);
  } else {
    write(STDOUT_FILENO, "got SIGCONT\n", 12);
    catchSignal(SIGTSTP, 0);
  }
}


x86 assembly (clang, -O0):
<handler>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    0x2e8b(%rip),%rcx
cmp    (%rcx),%eax
jne    11a6 <handler+0x66>
mov    0x2e8c(%rip),%rax
mov    (%rax),%edi
lea    0xe93(%rip),%rsi
mov    $0xc,%edx
call   1030 <write@plt>
mov    0x2e62(%rip),%rax
mov    (%rax),%edi
mov    $0x1,%esi
call   1050 <catchSignal@plt>
mov    $0x0,%al
call   1040 <getpid@plt>
mov    %eax,%edi
mov    0x2e46(%rip),%rax
mov    (%rax),%esi
call   1060 <kill@plt>
jmp    11d0 <handler+0x90>
mov    0x2e43(%rip),%rax
mov    (%rax),%edi
lea    0xe57(%rip),%rsi
mov    $0xc,%edx
call   1030 <write@plt>
mov    0x2e19(%rip),%rax
mov    (%rax),%edi
xor    %esi,%esi
call   1050 <catchSignal@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<handler>:
push   %rbx
mov    %edi,%eax
mov    0x2e96(%rip),%rbx
mov    0x2e9f(%rip),%rcx
mov    (%rcx),%edi
cmp    %eax,(%rbx)
jne    1185 <handler+0x45>
lea    0xea2(%rip),%rsi
mov    $0xc,%edx
call   1030 <write@plt>
mov    (%rbx),%edi
mov    $0x1,%esi
call   1050 <catchSignal@plt>
xor    %eax,%eax
call   1040 <getpid@plt>
mov    (%rbx),%esi
mov    %eax,%edi
pop    %rbx
jmp    1060 <kill@plt>
lea    0xe81(%rip),%rsi
mov    $0xc,%edx
call   1030 <write@plt>
mov    (%rbx),%edi
xor    %esi,%esi
pop    %rbx
jmp    1050 <catchSignal@plt>

LLVM IR (-O0):
@SIGTSTP = global i32 0
@STDOUT_FILENO = global i32 0
@.str = [13 x i8] c"got SIGTSTP\0A\00"
@.str.1 = [13 x i8] c"got SIGCONT\0A\00"
define void @handler(i32 %0) {
%2 = alloca i32
store i32 %0, i32* %2
%3 = load i32, i32* %2
%4 = load i32, i32* @SIGTSTP
%5 = icmp eq i32 %3, %4
br i1 %5, label %6, label %14
6: ; preds = %1
%7 = load i32, i32* @STDOUT_FILENO
%8 = call i32 @write(i32 %7, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 12)
%9 = load i32, i32* @SIGTSTP
%10 = call i32 @catchSignal(i32 %9, i32 1)
%11 = call i32 (...) @getpid()
%12 = load i32, i32* @SIGTSTP
%13 = call i32 @kill(i32 %11, i32 %12)
br label %19
14: ; preds = %1
%15 = load i32, i32* @STDOUT_FILENO
%16 = call i32 @write(i32 %15, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i32 12)
%17 = load i32, i32* @SIGTSTP
%18 = call i32 @catchSignal(i32 %17, i32 0)
br label %19
19: ; preds = %14, %6
ret void
}

LLVM IR (-O2):
@SIGTSTP = global i32 0
@STDOUT_FILENO = global i32 0
@.str = [13 x i8] c"got SIGTSTP\0A\00"
@.str.1 = [13 x i8] c"got SIGCONT\0A\00"
define void @handler(i32 %0) {
%2 = load i32, i32* @SIGTSTP
%3 = icmp eq i32 %2, %0
%4 = load i32, i32* @STDOUT_FILENO
br i1 %3, label %5, label %12
5: ; preds = %1
%6 = tail call i32 @write(i32 %4, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 12)
%7 = load i32, i32* @SIGTSTP
%8 = tail call i32 @catchSignal(i32 %7, i32 1)
%9 = tail call i32 (...) @getpid()
%10 = load i32, i32* @SIGTSTP
%11 = tail call i32 @kill(i32 %9, i32 %10)
br label %16
12: ; preds = %1
%13 = tail call i32 @write(i32 %4, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i32 12)
%14 = load i32, i32* @SIGTSTP
%15 = tail call i32 @catchSignal(i32 %14, i32 0)
br label %16
16: ; preds = %12, %5
ret void
}