#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 */
struct timespec {
  int tv_sec;
  scalar_t__ tv_nsec;
};
typedef int /*<<< orphan*/ sigset_t;
struct TYPE_3__ {
  int si_signo;
};
typedef TYPE_1__ siginfo_t;

/* Variables and functions */
int /*<<< orphan*/ SIGALRM;
int /*<<< orphan*/ SIG_BLOCK;
int /*<<< orphan*/ alarm(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ sigaddset(int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ sigemptyset(int /*<<< orphan*/ *);
int /*<<< orphan*/ sigprocmask(int /*<<< orphan*/, int /*<<< orphan*/ *,
                               int /*<<< orphan*/ *);
int sigtimedwait(int /*<<< orphan*/ *, TYPE_1__ *, struct timespec *);
int /*<<< orphan*/ timestamp(char *);
int main() {
  int result = 0;
  sigset_t waitset;
  struct timespec timeout;
  siginfo_t info;
  sigemptyset(&waitset);
  sigaddset(&waitset, SIGALRM);
  sigprocmask(SIG_BLOCK, &waitset, NULL);
  alarm(5);
  timestamp("before sigwaitinfo()");
  timeout.tv_sec = 6;
  timeout.tv_nsec = 0;
  result = sigtimedwait(&waitset, &info, &timeout);
  if (result < 0) {
    perror("Timeout Reached: ");
    exit(1);
  }
  printf("sigtimedwait() returned for signal %d\n", info.si_signo);
  timestamp("after sigtimedwait()");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
lea    -0xc(%rbp),%rdi
call   1080 <sigemptyset@plt>
mov    0x2e32(%rip),%rax
mov    (%rax),%esi
lea    -0xc(%rbp),%rdi
call   10b0 <sigaddset@plt>
mov    0x2e10(%rip),%rax
mov    (%rax),%edi
lea    -0xc(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1030 <sigprocmask@plt>
mov    $0x5,%edi
call   1060 <alarm@plt>
lea    0xe18(%rip),%rdi
call   1040 <timestamp@plt>
movl   $0x6,-0x20(%rbp)
movq   $0x0,-0x18(%rbp)
lea    -0xc(%rbp),%rdi
lea    -0x28(%rbp),%rsi
lea    -0x20(%rbp),%rdx
call   1070 <sigtimedwait@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    1230 <main+0xa0>
lea    0xdf4(%rip),%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    -0x28(%rbp),%esi
lea    0xded(%rip),%rdi
call   1050 <printf@plt>
lea    0xe08(%rip),%rdi
call   1040 <timestamp@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x20,%rsp
lea    0xc(%rsp),%rbx
mov    %rbx,%rdi
call   1080 <sigemptyset@plt>
mov    0x2e3f(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   10b0 <sigaddset@plt>
mov    0x2e1e(%rip),%rax
mov    (%rax),%edi
mov    %rbx,%rsi
xor    %edx,%edx
call   1030 <sigprocmask@plt>
mov    $0x5,%edi
call   1060 <alarm@plt>
lea    0xe29(%rip),%rdi
call   1040 <timestamp@plt>
movl   $0x6,0x10(%rsp)
movq   $0x0,0x18(%rsp)
lea    0x8(%rsp),%rsi
lea    0x10(%rsp),%rdx
mov    %rbx,%rdi
call   1070 <sigtimedwait@plt>
test   %eax,%eax
js     1227 <main+0x97>
mov    0x8(%rsp),%esi
lea    0xe19(%rip),%rdi
call   1050 <printf@plt>
lea    0xe34(%rip),%rdi
call   1040 <timestamp@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
ret
lea    0xde7(%rip),%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
%struct.timespec = type { i32, i64 }
%struct.TYPE_3__ = type { i32 }
@SIGALRM = global i32 0
@SIG_BLOCK = global i32 0
@.str = [21 x i8] c"before sigwaitinfo()\00"
@.str.1 = [18 x i8] c"Timeout Reached: \00"
@.str.2 = [39 x i8] c"sigtimedwait() returned for signal %d\0A\00"
@.str.3 = [21 x i8] c"after sigtimedwait()\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca %struct.timespec
%5 = alloca %struct.TYPE_3__
store i32 0, i32* %1
store i32 0, i32* %2
%6 = call i32 @sigemptyset(i32* %3)
%7 = load i32, i32* @SIGALRM
%8 = call i32 @sigaddset(i32* %3, i32 %7)
%9 = load i32, i32* @SIG_BLOCK
%10 = call i32 @sigprocmask(i32 %9, i32* %3, i32* null)
%11 = call i32 @alarm(i32 5)
%12 = call i32 @timestamp(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
%13 = getelementptr inbounds %struct.timespec, %struct.timespec* %4, i32 0, i32 0
store i32 6, i32* %13
%14 = getelementptr inbounds %struct.timespec, %struct.timespec* %4, i32 0, i32 1
store i64 0, i64* %14
%15 = call i32 @sigtimedwait(i32* %3, %struct.TYPE_3__* %5, %struct.timespec* %4)
store i32 %15, i32* %2
%16 = load i32, i32* %2
%17 = icmp slt i32 %16, 0
br i1 %17, label %18, label %21
18: ; preds = %0
%19 = call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
%20 = call i32 @exit(i32 1)
unreachable
21: ; preds = %0
%22 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %5, i32 0, i32 0
%23 = load i32, i32* %22
%24 = call i32 @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.2, i64 0, i64 0), i32 %23)
%25 = call i32 @timestamp(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
%struct.timespec = type { i32, i64 }
%struct.TYPE_3__ = type { i32 }
@SIGALRM = global i32 0
@SIG_BLOCK = global i32 0
@.str = [21 x i8] c"before sigwaitinfo()\00"
@.str.1 = [18 x i8] c"Timeout Reached: \00"
@.str.2 = [39 x i8] c"sigtimedwait() returned for signal %d\0A\00"
@.str.3 = [21 x i8] c"after sigtimedwait()\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.timespec
%3 = alloca %struct.TYPE_3__
%4 = bitcast i32* %1 to i8*
%5 = bitcast %struct.timespec* %2 to i8*
%6 = bitcast %struct.TYPE_3__* %3 to i8*
%7 = call i32 @sigemptyset(i32* %1)
%8 = load i32, i32* @SIGALRM
%9 = call i32 @sigaddset(i32* %1, i32 %8)
%10 = load i32, i32* @SIG_BLOCK
%11 = call i32 @sigprocmask(i32 %10, i32* %1, i32* null)
%12 = call i32 @alarm(i32 5)
%13 = call i32 @timestamp(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
%14 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i64 0, i32 0
store i32 6, i32* %14
%15 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i64 0, i32 1
store i64 0, i64* %15
%16 = call i32 @sigtimedwait(i32* %1, %struct.TYPE_3__* %3, %struct.timespec* %2)
%17 = icmp slt i32 %16, 0
br i1 %17, label %18, label %21
18: ; preds = %0
%19 = call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
%20 = call i32 @exit(i32 1)
unreachable
21: ; preds = %0
%22 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %3, i64 0, i32 0
%23 = load i32, i32* %22
%24 = call i32 @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.2, i64 0, i64 0), i32 %23)
%25 = call i32 @timestamp(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0))
ret i32 0
}