#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*/ printf(char *, int /*<<< orphan*/, ...);
int /*<<< orphan*/ pthread_exit(int /*<<< orphan*/ *);
int /*<<< orphan*/ pthread_self();
int /*<<< orphan*/ sigfillset(int /*<<< orphan*/ *);
int /*<<< orphan*/ sigwait(int /*<<< orphan*/ *, int *);
void *sigfun(void *arg) {
  int sigreceived;
  sigset_t sigmask;
  sigfillset(&sigmask);
  printf(" Signal Handling Thread %ld starting\n", pthread_self());
  while (1) {
    sigwait(&sigmask, &sigreceived);
    printf(" Signal Handling Thread %ld received signal %d\n", pthread_self(),
           sigreceived);
  }
  printf(" Signal Handling Thread %ld exiting\n", pthread_self());
  pthread_exit(NULL);
}


x86 assembly (clang, -O0):
<sigfun>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
lea    -0x10(%rbp),%rdi
call   1040 <sigfillset@plt>
mov    $0x0,%al
call   1050 <pthread_self@plt>
mov    %eax,%esi
lea    0xe9b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x10(%rbp),%rdi
lea    -0xc(%rbp),%rsi
call   1060 <sigwait@plt>
mov    $0x0,%al
call   1050 <pthread_self@plt>
mov    %eax,%esi
mov    -0xc(%rbp),%edx
lea    0xe9a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    116c <sigfun+0x2c>

x86 assembly (clang, -O2):
<sigfun>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
lea    0xc(%rsp),%r14
mov    %r14,%rdi
call   1040 <sigfillset@plt>
xor    %eax,%eax
call   1050 <pthread_self@plt>
lea    0xe9c(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0x8(%rsp),%r15
lea    0xead(%rip),%rbx
nopl   0x0(%rax)
mov    %r14,%rdi
mov    %r15,%rsi
call   1060 <sigwait@plt>
xor    %eax,%eax
call   1050 <pthread_self@plt>
mov    0x8(%rsp),%edx
mov    %rbx,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1030 <printf@plt>
jmp    1180 <sigfun+0x40>

LLVM IR (-O0):
@.str = [38 x i8] c" Signal Handling Thread %ld starting\0A\00"
@.str.1 = [48 x i8] c" Signal Handling Thread %ld received signal %d\0A\00"
define i8* @sigfun(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
store i8* %0, i8** %2
%5 = call i32 @sigfillset(i32* %4)
%6 = call i32 (...) @pthread_self()
%7 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), i32 %6)
br label %8
8: ; preds = %1, %8
%9 = call i32 @sigwait(i32* %4, i32* %3)
%10 = call i32 (...) @pthread_self()
%11 = load i32, i32* %3
%12 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.1, i64 0, i64 0), i32 %10, i32 %11)
br label %8
}

LLVM IR (-O2):
@.str = [38 x i8] c" Signal Handling Thread %ld starting\0A\00"
@.str.1 = [48 x i8] c" Signal Handling Thread %ld received signal %d\0A\00"
define noalias i8* @sigfun(i8* nocapture readnone %0) {
%2 = alloca i32
%3 = alloca i32
%4 = bitcast i32* %2 to i8*
%5 = bitcast i32* %3 to i8*
%6 = call i32 @sigfillset(i32* %3)
%7 = call i32 (...) @pthread_self()
%8 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), i32 %7)
br label %9
9: ; preds = %9, %1
%10 = call i32 @sigwait(i32* %3, i32* %2)
%11 = call i32 (...) @pthread_self()
%12 = load i32, i32* %2
%13 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.1, i64 0, i64 0), i32 %11, i32 %12)
br label %9
}