#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 */
struct sched_param {
  int sched_priority;
};
typedef int /*<<< orphan*/ sigset_t;
typedef int /*<<< orphan*/ pthread_t;
typedef int /*<<< orphan*/ pthread_attr_t;

/* Variables and functions */
int /*<<< orphan*/ PTHREAD_CREATE_JOINABLE;
int /*<<< orphan*/ PTHREAD_EXPLICIT_SCHED;
int /*<<< orphan*/ SCHED_FIFO;
int /*<<< orphan*/ SIGHUP;
int /*<<< orphan*/ SIGINT;
int /*<<< orphan*/ SIGTERM;
int /*<<< orphan*/ SIG_BLOCK;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ pthread_attr_init(int /*<<< orphan*/ *);
int /*<<< orphan*/ pthread_attr_setdetachstate(int /*<<< orphan*/ *,
                                               int /*<<< orphan*/);
int /*<<< orphan*/ pthread_attr_setinheritsched(int /*<<< orphan*/ *,
                                                int /*<<< orphan*/);
int /*<<< orphan*/ pthread_attr_setschedparam(int /*<<< orphan*/ *,
                                              struct sched_param *);
int /*<<< orphan*/ pthread_attr_setschedpolicy(int /*<<< orphan*/ *,
                                               int /*<<< orphan*/);
int /*<<< orphan*/ pthread_create(int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                                  void *(*)(void *), int /*<<< orphan*/ *);
int /*<<< orphan*/ pthread_join(int /*<<< orphan*/, int /*<<< orphan*/ *);
int /*<<< orphan*/ pthread_sigmask(int /*<<< orphan*/, int /*<<< orphan*/ *,
                                   int /*<<< orphan*/ *);
int /*<<< orphan*/ sigaddset(int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ sigemptyset(int /*<<< orphan*/ *);
void goPosixRT(void *(*work)(void *)) {
  struct sched_param svparam = {.sched_priority = 90};
  pthread_t svtid;
  pthread_attr_t svattr, clattr;
  sigset_t set;
  int sig;
  sigemptyset(&set);
  sigaddset(&set, SIGINT);
  sigaddset(&set, SIGTERM);
  sigaddset(&set, SIGHUP);
  pthread_sigmask(SIG_BLOCK, &set, NULL);
  pthread_attr_init(&svattr);
  pthread_attr_setdetachstate(&svattr, PTHREAD_CREATE_JOINABLE);
  pthread_attr_setinheritsched(&svattr, PTHREAD_EXPLICIT_SCHED);
  pthread_attr_setschedpolicy(&svattr, SCHED_FIFO);
  pthread_attr_setschedparam(&svattr, &svparam);
  errno = pthread_create(&svtid, &svattr, work, NULL);
  pthread_join(svtid, NULL);
}


x86 assembly (clang, -O0):
<goPosixRT>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    0xe4e(%rip),%eax
mov    %eax,-0x10(%rbp)
lea    -0x20(%rbp),%rdi
call   1060 <sigemptyset@plt>
mov    0x2e13(%rip),%rax
mov    (%rax),%esi
lea    -0x20(%rbp),%rdi
call   10c0 <sigaddset@plt>
mov    0x2df9(%rip),%rax
mov    (%rax),%esi
lea    -0x20(%rbp),%rdi
call   10c0 <sigaddset@plt>
mov    0x2e07(%rip),%rax
mov    (%rax),%esi
lea    -0x20(%rbp),%rdi
call   10c0 <sigaddset@plt>
mov    0x2dad(%rip),%rax
mov    (%rax),%edi
lea    -0x20(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1080 <pthread_sigmask@plt>
lea    -0x18(%rbp),%rdi
call   1050 <pthread_attr_init@plt>
mov    0x2dc6(%rip),%rax
mov    (%rax),%esi
lea    -0x18(%rbp),%rdi
call   1070 <pthread_attr_setdetachstate@plt>
mov    0x2d9c(%rip),%rax
mov    (%rax),%esi
lea    -0x18(%rbp),%rdi
call   1030 <pthread_attr_setinheritsched@plt>
mov    0x2d82(%rip),%rax
mov    (%rax),%esi
lea    -0x18(%rbp),%rdi
call   1040 <pthread_attr_setschedpolicy@plt>
lea    -0x18(%rbp),%rdi
lea    -0x10(%rbp),%rsi
call   10a0 <pthread_attr_setschedparam@plt>
mov    -0x8(%rbp),%rdx
lea    -0x14(%rbp),%rdi
lea    -0x18(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%ecx
call   1090 <pthread_create@plt>
mov    %eax,%ecx
mov    0x2d3c(%rip),%rax
mov    %ecx,(%rax)
mov    -0x14(%rbp),%edi
xor    %eax,%eax
mov    %eax,%esi
call   10b0 <pthread_join@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<goPosixRT>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%r14
movl   $0x5a,0x8(%rsp)
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
call   1060 <sigemptyset@plt>
mov    0x2e12(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   10c0 <sigaddset@plt>
mov    0x2df9(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   10c0 <sigaddset@plt>
mov    0x2e08(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   10c0 <sigaddset@plt>
mov    0x2daf(%rip),%rax
mov    (%rax),%edi
mov    %rbx,%rsi
xor    %edx,%edx
call   1080 <pthread_sigmask@plt>
lea    0x14(%rsp),%rbx
mov    %rbx,%rdi
call   1050 <pthread_attr_init@plt>
mov    0x2dc7(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1070 <pthread_attr_setdetachstate@plt>
mov    0x2d9e(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1030 <pthread_attr_setinheritsched@plt>
mov    0x2d85(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1040 <pthread_attr_setschedpolicy@plt>
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
call   10a0 <pthread_attr_setschedparam@plt>
lea    0xc(%rsp),%rdi
mov    %rbx,%rsi
mov    %r14,%rdx
xor    %ecx,%ecx
call   1090 <pthread_create@plt>
mov    0x2d45(%rip),%rcx
mov    %eax,(%rcx)
mov    0xc(%rsp),%edi
xor    %esi,%esi
call   10b0 <pthread_join@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.sched_param = type { i32 }
@__const.goPosixRT.svparam = %struct.sched_param { i32 90 }
@SIGINT = global i32 0
@SIGTERM = global i32 0
@SIGHUP = global i32 0
@SIG_BLOCK = global i32 0
@PTHREAD_CREATE_JOINABLE = global i32 0
@PTHREAD_EXPLICIT_SCHED = global i32 0
@SCHED_FIFO = global i32 0
@errno = global i32 0
define void @goPosixRT(i8* (i8*)* %0) {
%2 = alloca i8* (i8*)*
%3 = alloca %struct.sched_param
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i8* (i8*)* %0, i8* (i8*)** %2
%9 = bitcast %struct.sched_param* %3 to i8*
%10 = call i32 @sigemptyset(i32* %7)
%11 = load i32, i32* @SIGINT
%12 = call i32 @sigaddset(i32* %7, i32 %11)
%13 = load i32, i32* @SIGTERM
%14 = call i32 @sigaddset(i32* %7, i32 %13)
%15 = load i32, i32* @SIGHUP
%16 = call i32 @sigaddset(i32* %7, i32 %15)
%17 = load i32, i32* @SIG_BLOCK
%18 = call i32 @pthread_sigmask(i32 %17, i32* %7, i32* null)
%19 = call i32 @pthread_attr_init(i32* %5)
%20 = load i32, i32* @PTHREAD_CREATE_JOINABLE
%21 = call i32 @pthread_attr_setdetachstate(i32* %5, i32 %20)
%22 = load i32, i32* @PTHREAD_EXPLICIT_SCHED
%23 = call i32 @pthread_attr_setinheritsched(i32* %5, i32 %22)
%24 = load i32, i32* @SCHED_FIFO
%25 = call i32 @pthread_attr_setschedpolicy(i32* %5, i32 %24)
%26 = call i32 @pthread_attr_setschedparam(i32* %5, %struct.sched_param* %3)
%27 = load i8* (i8*)*, i8* (i8*)** %2
%28 = call i32 @pthread_create(i32* %4, i32* %5, i8* (i8*)* %27, i32* null)
store i32 %28, i32* @errno
%29 = load i32, i32* %4
%30 = call i32 @pthread_join(i32 %29, i32* null)
ret void
}

LLVM IR (-O2):
%struct.sched_param = type { i32 }
@SIGINT = global i32 0
@SIGTERM = global i32 0
@SIGHUP = global i32 0
@SIG_BLOCK = global i32 0
@PTHREAD_CREATE_JOINABLE = global i32 0
@PTHREAD_EXPLICIT_SCHED = global i32 0
@SCHED_FIFO = global i32 0
@errno = global i32 0
define void @goPosixRT(i8* (i8*)* %0) {
%2 = alloca %struct.sched_param
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = bitcast %struct.sched_param* %2 to i8*
%7 = getelementptr inbounds %struct.sched_param, %struct.sched_param* %2, i64 0, i32 0
store i32 90, i32* %7
%8 = bitcast i32* %3 to i8*
%9 = bitcast i32* %4 to i8*
%10 = bitcast i32* %5 to i8*
%11 = call i32 @sigemptyset(i32* %5)
%12 = load i32, i32* @SIGINT
%13 = call i32 @sigaddset(i32* %5, i32 %12)
%14 = load i32, i32* @SIGTERM
%15 = call i32 @sigaddset(i32* %5, i32 %14)
%16 = load i32, i32* @SIGHUP
%17 = call i32 @sigaddset(i32* %5, i32 %16)
%18 = load i32, i32* @SIG_BLOCK
%19 = call i32 @pthread_sigmask(i32 %18, i32* %5, i32* null)
%20 = call i32 @pthread_attr_init(i32* %4)
%21 = load i32, i32* @PTHREAD_CREATE_JOINABLE
%22 = call i32 @pthread_attr_setdetachstate(i32* %4, i32 %21)
%23 = load i32, i32* @PTHREAD_EXPLICIT_SCHED
%24 = call i32 @pthread_attr_setinheritsched(i32* %4, i32 %23)
%25 = load i32, i32* @SCHED_FIFO
%26 = call i32 @pthread_attr_setschedpolicy(i32* %4, i32 %25)
%27 = call i32 @pthread_attr_setschedparam(i32* %4, %struct.sched_param* %2)
%28 = call i32 @pthread_create(i32* %3, i32* %4, i8* (i8*)* %0, i32* null)
store i32 %28, i32* @errno
%29 = load i32, i32* %3
%30 = call i32 @pthread_join(i32 %29, i32* null)
ret void
}