#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*/ EXIT_FAILURE;
int errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, int);
int sigwait(int /*<<< orphan*/ *, int *);
void *sig_thread(void *arg) {
  sigset_t *set = arg;
  int s, sig;
  for (;;) {
    s = sigwait(set, &sig);
    if (s != 0)
      do {
        errno = s;
        perror("sigwait");
        exit(EXIT_FAILURE);
      } while (0);
    printf("Signal handling thread got signal %d\n", sig);
  }
}


x86 assembly (clang, -O0):
<sig_thread>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1050 <sigwait@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     1199 <sig_thread+0x59>
jmp    1173 <sig_thread+0x33>
mov    -0x14(%rbp),%ecx
mov    0x2e63(%rip),%rax
mov    %ecx,(%rax)
lea    0xe7a(%rip),%rdi
call   1040 <perror@plt>
mov    0x2e46(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
mov    -0x18(%rbp),%esi
lea    0xe65(%rip),%rdi
call   1030 <printf@plt>
jmp    1154 <sig_thread+0x14>

x86 assembly (clang, -O2):
<sig_thread>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
lea    0xc(%rsp),%rsi
call   1050 <sigwait@plt>
test   %eax,%eax
jne    118b <sig_thread+0x4b>
lea    0xea7(%rip),%r14
lea    0xc(%rsp),%r15
cs nopw 0x0(%rax,%rax,1)
mov    0xc(%rsp),%esi
mov    %r14,%rdi
call   1030 <printf@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1050 <sigwait@plt>
test   %eax,%eax
je     1170 <sig_thread+0x30>
mov    0x2e4e(%rip),%rcx
mov    %eax,(%rcx)
lea    0xe65(%rip),%rdi
call   1040 <perror@plt>
mov    0x2e31(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@errno = global i32 0
@.str = [8 x i8] c"sigwait\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [38 x i8] c"Signal handling thread got signal %d\0A\00"
define i8* @sig_thread(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
store i8* %0, i8** %2
%6 = load i8*, i8** %2
%7 = bitcast i8* %6 to i32*
store i32* %7, i32** %3
br label %8
8: ; preds = %20, %1
%9 = load i32*, i32** %3
%10 = call i32 @sigwait(i32* %9, i32* %5)
store i32 %10, i32* %4
%11 = load i32, i32* %4
%12 = icmp ne i32 %11, 0
br i1 %12, label %13, label %20
13: ; preds = %8
br label %14
14: ; preds = %13
%15 = load i32, i32* %4
store i32 %15, i32* @errno
%16 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%17 = load i32, i32* @EXIT_FAILURE
%18 = call i32 @exit(i32 %17)
unreachable
19: ; No predecessors!
br label %20
20: ; preds = %19, %8
%21 = load i32, i32* %5
%22 = call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i32 %21)
br label %8
}

LLVM IR (-O2):
@errno = global i32 0
@.str = [8 x i8] c"sigwait\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [38 x i8] c"Signal handling thread got signal %d\0A\00"
define noalias i8* @sig_thread(i8* %0) {
%2 = alloca i32
%3 = bitcast i8* %0 to i32*
%4 = bitcast i32* %2 to i8*
%5 = call i32 @sigwait(i32* %3, i32* %2)
%6 = icmp eq i32 %5, 0
br i1 %6, label %12, label %7
7: ; preds = %12, %1
%8 = phi i32 [ %5, %1 ], [ %15, %12 ]
store i32 %8, i32* @errno
%9 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%10 = load i32, i32* @EXIT_FAILURE
%11 = call i32 @exit(i32 %10)
unreachable
12: ; preds = %1, %12
%13 = load i32, i32* %2
%14 = call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i32 %13)
%15 = call i32 @sigwait(i32* %3, i32* %2)
%16 = icmp eq i32 %15, 0
br i1 %16, label %12, label %7
}