#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*/ SIGQUIT;
int /*<<< orphan*/ SIG_BLOCK;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, unsigned int);
int /*<<< orphan*/ pause();
int /*<<< orphan*/ perror_exit(char *);
int /*<<< orphan*/ pthread_exit(int /*<<< orphan*/);
scalar_t__ pthread_self();
int /*<<< orphan*/ sigaddset(int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ sigemptyset(int /*<<< orphan*/ *);
int sigprocmask(int /*<<< orphan*/, int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
void *thread1(void *arg) {
  fprintf(stderr, "thread 1: %u\n", (unsigned)pthread_self());
  sigset_t sigmask;
  sigemptyset(&sigmask);
  sigaddset(&sigmask, SIGQUIT);
  int ret;
  if ((ret = sigprocmask(SIG_BLOCK, &sigmask, NULL)) != 0)
    perror_exit("sigprocmask failed");
  pause();
  pthread_exit(0);
}


x86 assembly (clang, -O0):
<thread1>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    0x2e45(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    $0x0,%al
call   1080 <pthread_self@plt>
mov    -0x1c(%rbp),%edi
mov    %eax,%edx
lea    0xe55(%rip),%rsi
call   1040 <fprintf@plt>
lea    -0x14(%rbp),%rdi
call   1050 <sigemptyset@plt>
mov    0x2e28(%rip),%rax
mov    (%rax),%esi
lea    -0x14(%rbp),%rdi
call   10a0 <sigaddset@plt>
mov    0x2dfe(%rip),%rax
mov    (%rax),%edi
lea    -0x14(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1030 <sigprocmask@plt>
mov    %eax,-0x18(%rbp)
cmp    $0x0,%eax
je     11f9 <thread1+0x79>
lea    0xe1a(%rip),%rdi
call   1090 <perror_exit@plt>
mov    $0x0,%al
call   1060 <pause@plt>
xor    %edi,%edi
call   1070 <pthread_exit@plt>
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<thread1>:
push   %rbx
sub    $0x10,%rsp
mov    0x2e4c(%rip),%rax
mov    (%rax),%ebx
xor    %eax,%eax
call   1080 <pthread_self@plt>
lea    0xe64(%rip),%rsi
mov    %ebx,%edi
mov    %eax,%edx
call   1040 <fprintf@plt>
lea    0xc(%rsp),%rbx
mov    %rbx,%rdi
call   1050 <sigemptyset@plt>
mov    0x2e2f(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   10a0 <sigaddset@plt>
mov    0x2e06(%rip),%rax
mov    (%rax),%edi
mov    %rbx,%rsi
xor    %edx,%edx
call   1030 <sigprocmask@plt>
test   %eax,%eax
je     11e6 <thread1+0x66>
lea    0xe2d(%rip),%rdi
call   1090 <perror_exit@plt>
xor    %eax,%eax
call   1060 <pause@plt>
xor    %edi,%edi
call   1070 <pthread_exit@plt>
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [14 x i8] c"thread 1: %u\0A\00"
@SIGQUIT = global i32 0
@SIG_BLOCK = global i32 0
@.str.1 = [19 x i8] c"sigprocmask failed\00"
define i8* @thread1(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
store i8* %0, i8** %3
%6 = load i32, i32* @stderr
%7 = call i64 (...) @pthread_self()
%8 = trunc i64 %7 to i32
%9 = call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 %8)
%10 = call i32 @sigemptyset(i32* %4)
%11 = load i32, i32* @SIGQUIT
%12 = call i32 @sigaddset(i32* %4, i32 %11)
%13 = load i32, i32* @SIG_BLOCK
%14 = call i32 @sigprocmask(i32 %13, i32* %4, i32* null)
store i32 %14, i32* %5
%15 = icmp ne i32 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %1
%17 = call i32 @perror_exit(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
br label %18
18: ; preds = %16, %1
%19 = call i32 (...) @pause()
%20 = call i32 @pthread_exit(i32 0)
%21 = load i8*, i8** %2
ret i8* %21
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [14 x i8] c"thread 1: %u\0A\00"
@SIGQUIT = global i32 0
@SIG_BLOCK = global i32 0
@.str.1 = [19 x i8] c"sigprocmask failed\00"
define noalias i8* @thread1(i8* nocapture readnone %0) {
%2 = alloca i32
%3 = load i32, i32* @stderr
%4 = tail call i64 (...) @pthread_self()
%5 = trunc i64 %4 to i32
%6 = tail call i32 @fprintf(i32 %3, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 %5)
%7 = bitcast i32* %2 to i8*
%8 = call i32 @sigemptyset(i32* %2)
%9 = load i32, i32* @SIGQUIT
%10 = call i32 @sigaddset(i32* %2, i32 %9)
%11 = load i32, i32* @SIG_BLOCK
%12 = call i32 @sigprocmask(i32 %11, i32* %2, i32* null)
%13 = icmp eq i32 %12, 0
br i1 %13, label %16, label %14
14: ; preds = %1
%15 = call i32 @perror_exit(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
br label %16
16: ; preds = %14, %1
%17 = call i32 (...) @pause()
%18 = call i32 @pthread_exit(i32 0)
ret i8* undef
}