#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*/ SIGUSR1;
int /*<<< orphan*/ blocksig(int /*<<< orphan*/);
int /*<<< orphan*/ pr(char *, ...);
int /*<<< orphan*/ sigaddset(int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ sigemptyset(int /*<<< orphan*/ *);
int /*<<< orphan*/ sigwait(int /*<<< orphan*/ *, int *);
void *thr1(void *arg) {
  pr("thr1 sleeping \n");
  blocksig(SIGUSR1);
  sigset_t sigs;
  sigemptyset(&sigs);
  sigaddset(&sigs, SIGUSR1);
  int err = 0, n = 0;
  sigwait(&sigs, &n);
  pr("thr1 exiting err=%d, n=%d\n", err, n);
  return NULL;
}


x86 assembly (clang, -O0):
<thr1>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
lea    0xe9d(%rip),%rdi
mov    $0x0,%al
call   1030 <pr@plt>
mov    0x2e77(%rip),%rax
mov    (%rax),%edi
call   1050 <blocksig@plt>
lea    -0xc(%rbp),%rdi
call   1040 <sigemptyset@plt>
mov    0x2e60(%rip),%rax
mov    (%rax),%esi
lea    -0xc(%rbp),%rdi
call   1070 <sigaddset@plt>
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
lea    -0xc(%rbp),%rdi
lea    -0x14(%rbp),%rsi
call   1060 <sigwait@plt>
mov    -0x10(%rbp),%esi
mov    -0x14(%rbp),%edx
lea    0xe55(%rip),%rdi
mov    $0x0,%al
call   1030 <pr@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<thr1>:
push   %r14
push   %rbx
push   %rax
lea    0xea5(%rip),%rdi
xor    %eax,%eax
call   1030 <pr@plt>
mov    0x2e7f(%rip),%r14
mov    (%r14),%edi
call   1050 <blocksig@plt>
lea    0x4(%rsp),%rbx
mov    %rbx,%rdi
call   1040 <sigemptyset@plt>
mov    (%r14),%esi
mov    %rbx,%rdi
call   1070 <sigaddset@plt>
movl   $0x0,(%rsp)
mov    %rsp,%rsi
mov    %rbx,%rdi
call   1060 <sigwait@plt>
mov    (%rsp),%edx
lea    0xe6b(%rip),%rdi
xor    %esi,%esi
xor    %eax,%eax
call   1030 <pr@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [16 x i8] c"thr1 sleeping \0A\00"
@SIGUSR1 = global i32 0
@.str.1 = [27 x i8] c"thr1 exiting err=%d, n=%d\0A\00"
define i8* @thr1(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i8* %0, i8** %2
%6 = call i32 (i8*, ...) @pr(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%7 = load i32, i32* @SIGUSR1
%8 = call i32 @blocksig(i32 %7)
%9 = call i32 @sigemptyset(i32* %3)
%10 = load i32, i32* @SIGUSR1
%11 = call i32 @sigaddset(i32* %3, i32 %10)
store i32 0, i32* %4
store i32 0, i32* %5
%12 = call i32 @sigwait(i32* %3, i32* %5)
%13 = load i32, i32* %4
%14 = load i32, i32* %5
%15 = call i32 (i8*, ...) @pr(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i32 %13, i32 %14)
ret i8* null
}

LLVM IR (-O2):
@.str = [16 x i8] c"thr1 sleeping \0A\00"
@SIGUSR1 = global i32 0
@.str.1 = [27 x i8] c"thr1 exiting err=%d, n=%d\0A\00"
define noalias i8* @thr1(i8* nocapture readnone %0) {
%2 = alloca i32
%3 = alloca i32
%4 = tail call i32 (i8*, ...) @pr(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%5 = load i32, i32* @SIGUSR1
%6 = tail call i32 @blocksig(i32 %5)
%7 = bitcast i32* %2 to i8*
%8 = call i32 @sigemptyset(i32* %2)
%9 = load i32, i32* @SIGUSR1
%10 = call i32 @sigaddset(i32* %2, i32 %9)
%11 = bitcast i32* %3 to i8*
store i32 0, i32* %3
%12 = call i32 @sigwait(i32* %2, i32* %3)
%13 = load i32, i32* %3
%14 = call i32 (i8*, ...) @pr(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i32 0, i32 %13)
ret i8* null
}