#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_3__ TYPE_1__;

/* Type definitions */
typedef int /*<<< orphan*/ sigset_t;
struct TYPE_3__ {
  int si_signo;
};
typedef TYPE_1__ siginfo_t;
typedef int /*<<< orphan*/ pthread_t;

/* Variables and functions */
int /*<<< orphan*/ SIGRTMIN;
int /*<<< orphan*/ SIGUSR1;
int errno;
int /*<<< orphan*/ printf(char *, int, ...);
int /*<<< orphan*/ pthread_self();
int /*<<< orphan*/ sig_handler(int);
int /*<<< orphan*/ sigaddset(int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ sigemptyset(int /*<<< orphan*/ *);
int sigwaitinfo(int /*<<< orphan*/ *, TYPE_1__ *);
char *strerror(int);
void *sigmgr_thread() {
  sigset_t waitset;
  siginfo_t info;
  int rc;
  pthread_t ppid = pthread_self();
  sigemptyset(&waitset);
  sigaddset(&waitset, SIGRTMIN);
  sigaddset(&waitset, SIGUSR1);
  while (1) {
    rc = sigwaitinfo(&waitset, &info);
    if (rc != -1) {
      printf("sigwaitinfo() fetch the signal:%d rc:%d\n", info.si_signo, rc);
      sig_handler(info.si_signo);
    } else {
      printf("sigwaitinfo() returned err:%d %s\n", errno, strerror(errno));
    }
  }
}


x86 assembly (clang, -O0):
<sigmgr_thread>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    $0x0,%al
call   1070 <pthread_self@plt>
mov    %eax,-0x10(%rbp)
lea    -0x4(%rbp),%rdi
call   1050 <sigemptyset@plt>
mov    0x2e46(%rip),%rax
mov    (%rax),%esi
lea    -0x4(%rbp),%rdi
call   1090 <sigaddset@plt>
mov    0x2e44(%rip),%rax
mov    (%rax),%esi
lea    -0x4(%rbp),%rdi
call   1090 <sigaddset@plt>
lea    -0x4(%rbp),%rdi
lea    -0x8(%rbp),%rsi
call   1060 <sigwaitinfo@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0xffffffff,-0xc(%rbp)
je     11ea <sigmgr_thread+0x7a>
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
lea    0xe2a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%edi
call   1030 <sig_handler@plt>
jmp    1218 <sigmgr_thread+0xa8>
mov    0x2ddf(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    0x2dd3(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
mov    -0x14(%rbp),%esi
mov    %rax,%rdx
lea    0xe18(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11af <sigmgr_thread+0x3f>

x86 assembly (clang, -O2):
<sigmgr_thread>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
xor    %eax,%eax
call   1070 <pthread_self@plt>
lea    0x4(%rsp),%r14
mov    %r14,%rdi
call   1050 <sigemptyset@plt>
mov    0x2e42(%rip),%rax
mov    (%rax),%esi
mov    %r14,%rdi
call   1090 <sigaddset@plt>
mov    0x2e41(%rip),%rax
mov    (%rax),%esi
mov    %r14,%rdi
call   1090 <sigaddset@plt>
mov    %rsp,%rbx
mov    0x2e15(%rip),%r13
lea    0xe67(%rip),%r15
lea    0xe37(%rip),%r12
jmp    11e7 <sigmgr_thread+0x77>
nopl   0x0(%rax,%rax,1)
mov    (%rsp),%esi
mov    %r12,%rdi
mov    %eax,%edx
xor    %eax,%eax
call   1040 <printf@plt>
mov    (%rsp),%edi
call   1030 <sig_handler@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1060 <sigwaitinfo@plt>
cmp    $0xffffffff,%eax
jne    11d0 <sigmgr_thread+0x60>
mov    0x0(%r13),%ebp
mov    %ebp,%edi
call   1080 <strerror@plt>
mov    %r15,%rdi
mov    %ebp,%esi
mov    %rax,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
jmp    11e7 <sigmgr_thread+0x77>

LLVM IR (-O0):
%struct.TYPE_3__ = type { i32 }
@SIGRTMIN = global i32 0
@SIGUSR1 = global i32 0
@.str = [41 x i8] c"sigwaitinfo() fetch the signal:%d rc:%d\0A\00"
@.str.1 = [34 x i8] c"sigwaitinfo() returned err:%d %s\0A\00"
@errno = global i32 0
define i8* @sigmgr_thread() {
%1 = alloca i32
%2 = alloca %struct.TYPE_3__
%3 = alloca i32
%4 = alloca i32
%5 = call i32 (...) @pthread_self()
store i32 %5, i32* %4
%6 = call i32 @sigemptyset(i32* %1)
%7 = load i32, i32* @SIGRTMIN
%8 = call i32 @sigaddset(i32* %1, i32 %7)
%9 = load i32, i32* @SIGUSR1
%10 = call i32 @sigaddset(i32* %1, i32 %9)
br label %11
11: ; preds = %0, %28
%12 = call i32 @sigwaitinfo(i32* %1, %struct.TYPE_3__* %2)
store i32 %12, i32* %3
%13 = load i32, i32* %3
%14 = icmp ne i32 %13, -1
br i1 %14, label %15, label %23
15: ; preds = %11
%16 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %2, i32 0, i32 0
%17 = load i32, i32* %16
%18 = load i32, i32* %3
%19 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i32 %17, i32 %18)
%20 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %2, i32 0, i32 0
%21 = load i32, i32* %20
%22 = call i32 @sig_handler(i32 %21)
br label %28
23: ; preds = %11
%24 = load i32, i32* @errno
%25 = load i32, i32* @errno
%26 = call i8* @strerror(i32 %25)
%27 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), i32 %24, i8* %26)
br label %28
28: ; preds = %23, %15
br label %11
}

LLVM IR (-O2):
%struct.TYPE_3__ = type { i32 }
@SIGRTMIN = global i32 0
@SIGUSR1 = global i32 0
@.str = [41 x i8] c"sigwaitinfo() fetch the signal:%d rc:%d\0A\00"
@.str.1 = [34 x i8] c"sigwaitinfo() returned err:%d %s\0A\00"
@errno = global i32 0
define noalias i8* @sigmgr_thread() {
%1 = alloca i32
%2 = alloca %struct.TYPE_3__
%3 = bitcast i32* %1 to i8*
%4 = bitcast %struct.TYPE_3__* %2 to i8*
%5 = tail call i32 (...) @pthread_self()
%6 = call i32 @sigemptyset(i32* %1)
%7 = load i32, i32* @SIGRTMIN
%8 = call i32 @sigaddset(i32* %1, i32 %7)
%9 = load i32, i32* @SIGUSR1
%10 = call i32 @sigaddset(i32* %1, i32 %9)
%11 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %2, i64 0, i32 0
br label %12
12: ; preds = %24, %0
%13 = call i32 @sigwaitinfo(i32* %1, %struct.TYPE_3__* %2)
%14 = icmp eq i32 %13, -1
br i1 %14, label %20, label %15
15: ; preds = %12
%16 = load i32, i32* %11
%17 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i32 %16, i32 %13)
%18 = load i32, i32* %11
%19 = call i32 @sig_handler(i32 %18)
br label %24
20: ; preds = %12
%21 = load i32, i32* @errno
%22 = call i8* @strerror(i32 %21)
%23 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), i32 %21, i8* %22)
br label %24
24: ; preds = %20, %15
br label %12
}