#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 */
typedef struct TYPE_7__ TYPE_1__;

/* Type definitions */
struct TYPE_7__ {
  int /*<<< orphan*/ *__val;
};
typedef TYPE_1__ sigset_t;

/* Variables and functions */
int /*<<< orphan*/ LOG_INFO;
int /*<<< orphan*/ SIGCHLD;
int /*<<< orphan*/ SIGQUIT;
int /*<<< orphan*/ SIG_SETMASK;
char **calloc(int, int);
int execvp(char *, char **);
int /*<<< orphan*/ memcpy(char **, char **, int);
int pthread_sigmask(int /*<<< orphan*/, TYPE_1__ *, TYPE_1__ *);
int sigaddset(TYPE_1__ *, int /*<<< orphan*/);
int sigemptyset(TYPE_1__ *);
int sigismember(TYPE_1__ *, int /*<<< orphan*/);
char *strdup(char *);
int /*<<< orphan*/ syslog(int /*<<< orphan*/, char *, int /*<<< orphan*/,
                          int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  char **modified_argv;
  sigset_t original_masked_signals;
  sigset_t modified_masked_signals;
  int rc;
  modified_argv = calloc(argc + 1, sizeof(char *));
  memcpy(modified_argv, argv, argc * sizeof(char *));
  modified_argv[0] = strdup("gdb");
  rc = pthread_sigmask(SIG_SETMASK, NULL, &original_masked_signals);
  if (rc == 0) {
    rc = sigismember(&original_masked_signals, SIGCHLD);
    if (rc == 1) {
      rc = sigemptyset(&modified_masked_signals);
      if (rc == 0) {
        rc = sigaddset(&modified_masked_signals, SIGQUIT);
        if (rc == 0) {
          rc = pthread_sigmask(SIG_SETMASK, &modified_masked_signals, NULL);
          if (rc == 0) {
            syslog(LOG_INFO, "Changing SigBlk %016lx -> %016lx",
                   original_masked_signals.__val[0],
                   modified_masked_signals.__val[0]);
          }
        }
      }
    }
  }
  rc = execvp("gdb", modified_argv);
  return rc;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%edi
add    $0x1,%edi
mov    $0x8,%esi
call   1030 <calloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
movslq -0x8(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edx
call   1050 <memcpy@plt>
lea    0xe28(%rip),%rdi
call   10a0 <strdup@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    0x2df2(%rip),%rax
mov    (%rax),%edi
xor    %eax,%eax
mov    %eax,%esi
lea    -0x20(%rbp),%rdx
call   1070 <pthread_sigmask@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jne    12b6 <main+0x126>
mov    0x2dc7(%rip),%rax
mov    (%rax),%esi
lea    -0x20(%rbp),%rdi
call   1090 <sigismember@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x1,-0x2c(%rbp)
jne    12b1 <main+0x121>
lea    -0x28(%rbp),%rdi
call   1040 <sigemptyset@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jne    12ac <main+0x11c>
mov    0x2da2(%rip),%rax
mov    (%rax),%esi
lea    -0x28(%rbp),%rdi
call   10b0 <sigaddset@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jne    12a7 <main+0x117>
mov    0x2d7b(%rip),%rax
mov    (%rax),%edi
lea    -0x28(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1070 <pthread_sigmask@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jne    12a2 <main+0x112>
mov    0x2d40(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rax
mov    (%rax),%edx
mov    -0x28(%rbp),%rax
mov    (%rax),%ecx
lea    0xd67(%rip),%rsi
call   1060 <syslog@plt>
jmp    12a7 <main+0x117>
jmp    12ac <main+0x11c>
jmp    12b1 <main+0x121>
jmp    12b6 <main+0x126>
mov    -0x18(%rbp),%rsi
lea    0xd3f(%rip),%rdi
call   1080 <execvp@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r15
mov    %edi,%ebx
lea    0x1(%rbx),%edi
mov    $0x8,%esi
call   1030 <calloc@plt>
mov    %rax,%r14
shl    $0x3,%ebx
mov    %rax,%rdi
mov    %r15,%rsi
mov    %ebx,%edx
call   1050 <memcpy@plt>
lea    0xe3b(%rip),%rdi
call   10a0 <strdup@plt>
mov    %rax,(%r14)
mov    0x2e0c(%rip),%rbx
mov    (%rbx),%edi
lea    0x8(%rsp),%rdx
xor    %esi,%esi
call   1070 <pthread_sigmask@plt>
test   %eax,%eax
jne    1251 <main+0xc1>
mov    0x2deb(%rip),%rax
mov    (%rax),%esi
lea    0x8(%rsp),%rdi
call   1090 <sigismember@plt>
cmp    $0x1,%eax
jne    1251 <main+0xc1>
mov    %rsp,%rdi
call   1040 <sigemptyset@plt>
test   %eax,%eax
jne    1251 <main+0xc1>
mov    0x2dd7(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rdi
call   10b0 <sigaddset@plt>
test   %eax,%eax
jne    1251 <main+0xc1>
mov    (%rbx),%edi
mov    %rsp,%rsi
xor    %edx,%edx
call   1070 <pthread_sigmask@plt>
test   %eax,%eax
jne    1251 <main+0xc1>
mov    0x2d92(%rip),%rax
mov    (%rax),%edi
mov    0x8(%rsp),%rax
mov    (%rax),%edx
mov    (%rsp),%rax
mov    (%rax),%ecx
lea    0xdb8(%rip),%rsi
call   1060 <syslog@plt>
lea    0xda8(%rip),%rdi
mov    %r14,%rsi
call   1080 <execvp@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.TYPE_7__ = type { i32* }
@.str = [4 x i8] c"gdb\00"
@SIG_SETMASK = global i32 0
@SIGCHLD = global i32 0
@SIGQUIT = global i32 0
@LOG_INFO = global i32 0
@.str.1 = [33 x i8] c"Changing SigBlk %016lx -> %016lx\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8**
%7 = alloca %struct.TYPE_7__
%8 = alloca %struct.TYPE_7__
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = add nsw i32 %10, 1
%12 = call i8** @calloc(i32 %11, i32 8)
store i8** %12, i8*** %6
%13 = load i8**, i8*** %6
%14 = load i8**, i8*** %5
%15 = load i32, i32* %4
%16 = sext i32 %15 to i64
%17 = mul i64 %16, 8
%18 = trunc i64 %17 to i32
%19 = call i32 @memcpy(i8** %13, i8** %14, i32 %18)
%20 = call i8* @strdup(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%21 = load i8**, i8*** %6
%22 = getelementptr inbounds i8*, i8** %21, i64 0
store i8* %20, i8** %22
%23 = load i32, i32* @SIG_SETMASK
%24 = call i32 @pthread_sigmask(i32 %23, %struct.TYPE_7__* null, %struct.TYPE_7__* %7)
store i32 %24, i32* %9
%25 = load i32, i32* %9
%26 = icmp eq i32 %25, 0
br i1 %26, label %27, label %61
27: ; preds = %2
%28 = load i32, i32* @SIGCHLD
%29 = call i32 @sigismember(%struct.TYPE_7__* %7, i32 %28)
store i32 %29, i32* %9
%30 = load i32, i32* %9
%31 = icmp eq i32 %30, 1
br i1 %31, label %32, label %60
32: ; preds = %27
%33 = call i32 @sigemptyset(%struct.TYPE_7__* %8)
store i32 %33, i32* %9
%34 = load i32, i32* %9
%35 = icmp eq i32 %34, 0
br i1 %35, label %36, label %59
36: ; preds = %32
%37 = load i32, i32* @SIGQUIT
%38 = call i32 @sigaddset(%struct.TYPE_7__* %8, i32 %37)
store i32 %38, i32* %9
%39 = load i32, i32* %9
%40 = icmp eq i32 %39, 0
br i1 %40, label %41, label %58
41: ; preds = %36
%42 = load i32, i32* @SIG_SETMASK
%43 = call i32 @pthread_sigmask(i32 %42, %struct.TYPE_7__* %8, %struct.TYPE_7__* null)
store i32 %43, i32* %9
%44 = load i32, i32* %9
%45 = icmp eq i32 %44, 0
br i1 %45, label %46, label %57
46: ; preds = %41
%47 = load i32, i32* @LOG_INFO
%48 = getelementptr inbounds %struct.TYPE_7__, %struct.TYPE_7__* %7, i32 0, i32 0
%49 = load i32*, i32** %48
%50 = getelementptr inbounds i32, i32* %49, i64 0
%51 = load i32, i32* %50
%52 = getelementptr inbounds %struct.TYPE_7__, %struct.TYPE_7__* %8, i32 0, i32 0
%53 = load i32*, i32** %52
%54 = getelementptr inbounds i32, i32* %53, i64 0
%55 = load i32, i32* %54
%56 = call i32 @syslog(i32 %47, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0), i32 %51, i32 %55)
br label %57
57: ; preds = %46, %41
br label %58
58: ; preds = %57, %36
br label %59
59: ; preds = %58, %32
br label %60
60: ; preds = %59, %27
br label %61
61: ; preds = %60, %2
%62 = load i8**, i8*** %6
%63 = call i32 @execvp(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8** %62)
store i32 %63, i32* %9
%64 = load i32, i32* %9
ret i32 %64
}

LLVM IR (-O2):
%struct.TYPE_7__ = type { i32* }
@.str = [4 x i8] c"gdb\00"
@SIG_SETMASK = global i32 0
@SIGCHLD = global i32 0
@SIGQUIT = global i32 0
@LOG_INFO = global i32 0
@.str.1 = [33 x i8] c"Changing SigBlk %016lx -> %016lx\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca %struct.TYPE_7__
%4 = alloca %struct.TYPE_7__
%5 = bitcast %struct.TYPE_7__* %3 to i8*
%6 = bitcast %struct.TYPE_7__* %4 to i8*
%7 = add nsw i32 %0, 1
%8 = tail call i8** @calloc(i32 %7, i32 8)
%9 = shl i32 %0, 3
%10 = tail call i32 @memcpy(i8** %8, i8** %1, i32 %9)
%11 = tail call dereferenceable_or_null(4) i8* @strdup(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
store i8* %11, i8** %8
%12 = load i32, i32* @SIG_SETMASK
%13 = call i32 @pthread_sigmask(i32 %12, %struct.TYPE_7__* null, %struct.TYPE_7__* %3)
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %39
15: ; preds = %2
%16 = load i32, i32* @SIGCHLD
%17 = call i32 @sigismember(%struct.TYPE_7__* %3, i32 %16)
%18 = icmp eq i32 %17, 1
br i1 %18, label %19, label %39
19: ; preds = %15
%20 = call i32 @sigemptyset(%struct.TYPE_7__* %4)
%21 = icmp eq i32 %20, 0
br i1 %21, label %22, label %39
22: ; preds = %19
%23 = load i32, i32* @SIGQUIT
%24 = call i32 @sigaddset(%struct.TYPE_7__* %4, i32 %23)
%25 = icmp eq i32 %24, 0
br i1 %25, label %26, label %39
26: ; preds = %22
%27 = load i32, i32* @SIG_SETMASK
%28 = call i32 @pthread_sigmask(i32 %27, %struct.TYPE_7__* %4, %struct.TYPE_7__* null)
%29 = icmp eq i32 %28, 0
br i1 %29, label %30, label %39
30: ; preds = %26
%31 = load i32, i32* @LOG_INFO
%32 = getelementptr inbounds %struct.TYPE_7__, %struct.TYPE_7__* %3, i64 0, i32 0
%33 = load i32*, i32** %32
%34 = load i32, i32* %33
%35 = getelementptr inbounds %struct.TYPE_7__, %struct.TYPE_7__* %4, i64 0, i32 0
%36 = load i32*, i32** %35
%37 = load i32, i32* %36
%38 = call i32 @syslog(i32 %31, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0), i32 %34, i32 %37)
br label %39
39: ; preds = %15, %22, %30, %26, %19, %2
%40 = call i32 @execvp(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8** %8)
ret i32 %40
}