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

/* Variables and functions */
int /*<<< orphan*/ SIG_SETMASK;
int /*<<< orphan*/ lprintf(int, char *, int, int);
int /*<<< orphan*/ repeater_rm_by_pid(int);
int /*<<< orphan*/ sigfillset(int /*<<< orphan*/ *);
int /*<<< orphan*/ sigprocmask(int /*<<< orphan*/, int /*<<< orphan*/ *,
                               int /*<<< orphan*/ *);
int wait(int *);
void son_sig_handler(int signo) {
  sigset_t allsigmask, backupsigmask;
  sigfillset(&allsigmask);
  sigprocmask(SIG_SETMASK, &allsigmask, &backupsigmask);
  int status;
  int pid = wait(&status);
  repeater_rm_by_pid(pid);
  if (status != 0) {
    lprintf(3, "Process %i quit with status %i", pid, status);
  }
  sigprocmask(SIG_SETMASK, &backupsigmask, NULL);
}


x86 assembly (clang, -O0):
<son_sig_handler>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
lea    -0x8(%rbp),%rdi
call   1050 <sigfillset@plt>
mov    0x2e7d(%rip),%rax
mov    (%rax),%edi
lea    -0x8(%rbp),%rsi
lea    -0xc(%rbp),%rdx
call   1030 <sigprocmask@plt>
lea    -0x10(%rbp),%rdi
call   1070 <wait@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
call   1040 <repeater_rm_by_pid@plt>
cmpl   $0x0,-0x10(%rbp)
je     11af <son_sig_handler+0x5f>
mov    -0x14(%rbp),%edx
mov    -0x10(%rbp),%ecx
mov    $0x3,%edi
lea    0xe56(%rip),%rsi
call   1060 <lprintf@plt>
mov    0x2e32(%rip),%rax
mov    (%rax),%edi
lea    -0xc(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1030 <sigprocmask@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<son_sig_handler>:
push   %r14
push   %rbx
sub    $0x18,%rsp
lea    0x14(%rsp),%rbx
mov    %rbx,%rdi
call   1050 <sigfillset@plt>
mov    0x2e7d(%rip),%r14
mov    (%r14),%edi
lea    0x10(%rsp),%rdx
mov    %rbx,%rsi
call   1030 <sigprocmask@plt>
lea    0xc(%rsp),%rdi
call   1070 <wait@plt>
mov    %eax,%ebx
mov    %eax,%edi
call   1040 <repeater_rm_by_pid@plt>
mov    0xc(%rsp),%ecx
test   %ecx,%ecx
je     11a9 <son_sig_handler+0x59>
lea    0xe63(%rip),%rsi
mov    $0x3,%edi
mov    %ebx,%edx
call   1060 <lprintf@plt>
mov    (%r14),%edi
lea    0x10(%rsp),%rsi
xor    %edx,%edx
call   1030 <sigprocmask@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@SIG_SETMASK = global i32 0
@.str = [31 x i8] c"Process %i quit with status %i\00"
define void @son_sig_handler(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 %0, i32* %2
%7 = call i32 @sigfillset(i32* %3)
%8 = load i32, i32* @SIG_SETMASK
%9 = call i32 @sigprocmask(i32 %8, i32* %3, i32* %4)
%10 = call i32 @wait(i32* %5)
store i32 %10, i32* %6
%11 = load i32, i32* %6
%12 = call i32 @repeater_rm_by_pid(i32 %11)
%13 = load i32, i32* %5
%14 = icmp ne i32 %13, 0
br i1 %14, label %15, label %19
15: ; preds = %1
%16 = load i32, i32* %6
%17 = load i32, i32* %5
%18 = call i32 @lprintf(i32 3, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i32 %16, i32 %17)
br label %19
19: ; preds = %15, %1
%20 = load i32, i32* @SIG_SETMASK
%21 = call i32 @sigprocmask(i32 %20, i32* %4, i32* null)
ret void
}

LLVM IR (-O2):
@SIG_SETMASK = global i32 0
@.str = [31 x i8] c"Process %i quit with status %i\00"
define void @son_sig_handler(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = bitcast i32* %2 to i8*
%6 = bitcast i32* %3 to i8*
%7 = call i32 @sigfillset(i32* %2)
%8 = load i32, i32* @SIG_SETMASK
%9 = call i32 @sigprocmask(i32 %8, i32* %2, i32* %3)
%10 = bitcast i32* %4 to i8*
%11 = call i32 @wait(i32* %4)
%12 = call i32 @repeater_rm_by_pid(i32 %11)
%13 = load i32, i32* %4
%14 = icmp eq i32 %13, 0
br i1 %14, label %17, label %15
15: ; preds = %1
%16 = call i32 @lprintf(i32 3, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i32 %11, i32 %13)
br label %17
17: ; preds = %15, %1
%18 = load i32, i32* @SIG_SETMASK
%19 = call i32 @sigprocmask(i32 %18, i32* %3, i32* null)
ret void
}