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

/* Variables and functions */
int /*<<< orphan*/ SIGALRM;
int /*<<< orphan*/ SIG_BLOCK;
int /*<<< orphan*/ alarm(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sigaddset(int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ sigemptyset(int /*<<< orphan*/ *);
int /*<<< orphan*/ sigprocmask(int /*<<< orphan*/, int /*<<< orphan*/ *,
                               int /*<<< orphan*/ *);
int sigwaitinfo(int /*<<< orphan*/ *, TYPE_1__ *);
int /*<<< orphan*/ timestamp(char *);
int main() {
  int result = 0;
  sigset_t waitset;
  siginfo_t info;
  sigemptyset(&waitset);
  sigaddset(&waitset, SIGALRM);
  sigprocmask(SIG_BLOCK, &waitset, NULL);
  alarm(5);
  timestamp("before sigwaitinfo()");
  result = sigwaitinfo(&waitset, &info);
  if (result < 0)
    printf("sigwaitinfo failed : \n");
  printf("sigwaitinfo() returned for signal %d\n", info.si_signo);
  timestamp("after sigwaitinfo()");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
lea    -0xc(%rbp),%rdi
call   1070 <sigemptyset@plt>
mov    0x2e52(%rip),%rax
mov    (%rax),%esi
lea    -0xc(%rbp),%rdi
call   1090 <sigaddset@plt>
mov    0x2e30(%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    0xe38(%rip),%rdi
call   1040 <timestamp@plt>
lea    -0xc(%rbp),%rdi
lea    -0x10(%rbp),%rsi
call   1080 <sigwaitinfo@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    11f5 <main+0x85>
lea    0xe27(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x10(%rbp),%esi
lea    0xe2d(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe45(%rip),%rdi
call   1040 <timestamp@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
lea    0xc(%rsp),%rbx
mov    %rbx,%rdi
call   1080 <sigemptyset@plt>
mov    0x2e4f(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   10a0 <sigaddset@plt>
mov    0x2e2e(%rip),%rax
mov    (%rax),%edi
mov    %rbx,%rsi
xor    %edx,%edx
call   1030 <sigprocmask@plt>
mov    $0x5,%edi
call   1070 <alarm@plt>
lea    0xe39(%rip),%rdi
call   1050 <timestamp@plt>
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
call   1090 <sigwaitinfo@plt>
test   %eax,%eax
jns    11e9 <main+0x69>
lea    0xe6b(%rip),%rdi
call   1040 <puts@plt>
mov    0x8(%rsp),%esi
lea    0xe21(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xe39(%rip),%rdi
call   1050 <timestamp@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

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

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