#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*/ SIGALRM;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ sigismember(int /*<<< orphan*/ *, int /*<<< orphan*/);
scalar_t__ sigpending(int /*<<< orphan*/ *);
char *strerror(int /*<<< orphan*/);
void alrm_is_pending(const char *str) {
  sigset_t pendingsigset;
  printf("%s: ", str);
  if (sigpending(&pendingsigset) < 0) {
    printf("sigpending error: %s\n", strerror(errno));
    exit(-1);
  }
  if (sigismember(&pendingsigset, SIGALRM)) {
    printf("SIGALRM is pending\n");
  } else {
    printf("SIGALRM is not pending\n");
  }
}


x86 assembly (clang, -O0):
<alrm_is_pending>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rsi
lea    0xe99(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0xc(%rbp),%rdi
call   1040 <sigpending@plt>
cmp    $0x0,%rax
jge    11aa <alrm_is_pending+0x5a>
mov    0x2e50(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    %rax,%rsi
lea    0xe6c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0xffffffff,%edi
call   1060 <exit@plt>
mov    0x2e37(%rip),%rax
mov    (%rax),%esi
lea    -0xc(%rbp),%rdi
call   1050 <sigismember@plt>
cmp    $0x0,%rax
je     11d9 <alrm_is_pending+0x89>
lea    0xe4e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11e7 <alrm_is_pending+0x97>
lea    0xe4f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<alrm_is_pending>:
push   %rax
mov    %rdi,%rsi
lea    0xe95(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0x4(%rsp),%rdi
call   1050 <sigpending@plt>
test   %rax,%rax
js     11b0 <alrm_is_pending+0x50>
mov    0x2e60(%rip),%rax
mov    (%rax),%esi
lea    0x4(%rsp),%rdi
call   1060 <sigismember@plt>
test   %rax,%rax
lea    0xe7d(%rip),%rax
lea    0xe8d(%rip),%rdi
cmove  %rax,%rdi
call   1030 <puts@plt>
pop    %rax
ret
mov    0x2e21(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
lea    0xe40(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0xffffffff,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [5 x i8] c"%s: \00"
@.str.1 = [22 x i8] c"sigpending error: %s\0A\00"
@errno = global i32 0
@SIGALRM = global i32 0
@.str.2 = [20 x i8] c"SIGALRM is pending\0A\00"
@.str.3 = [24 x i8] c"SIGALRM is not pending\0A\00"
define void @alrm_is_pending(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
store i8* %0, i8** %2
%4 = load i8*, i8** %2
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %4)
%6 = call i64 @sigpending(i32* %3)
%7 = icmp slt i64 %6, 0
br i1 %7, label %8, label %13
8: ; preds = %1
%9 = load i32, i32* @errno
%10 = call i8* @strerror(i32 %9)
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i8* %10)
%12 = call i32 @exit(i32 -1)
unreachable
13: ; preds = %1
%14 = load i32, i32* @SIGALRM
%15 = call i64 @sigismember(i32* %3, i32 %14)
%16 = icmp ne i64 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %13
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
br label %21
19: ; preds = %13
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0))
br label %21
21: ; preds = %19, %17
ret void
}

LLVM IR (-O2):
@.str = [5 x i8] c"%s: \00"
@.str.1 = [22 x i8] c"sigpending error: %s\0A\00"
@errno = global i32 0
@SIGALRM = global i32 0
@str = [23 x i8] c"SIGALRM is not pending\00"
@str.4 = [19 x i8] c"SIGALRM is pending\00"
define void @alrm_is_pending(i8* %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %0)
%5 = call i64 @sigpending(i32* %2)
%6 = icmp slt i64 %5, 0
br i1 %6, label %7, label %12
7: ; preds = %1
%8 = load i32, i32* @errno
%9 = call i8* @strerror(i32 %8)
%10 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i8* %9)
%11 = call i32 @exit(i32 -1)
unreachable
12: ; preds = %1
%13 = load i32, i32* @SIGALRM
%14 = call i64 @sigismember(i32* %2, i32 %13)
%15 = icmp eq i64 %14, 0
%16 = select i1 %15, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @str, i64 0, i64 0), i8* getelementptr inbounds ([19 x i8], [19 x i8]* @str.4, i64 0, i64 0)
%17 = call i32 @puts(i8* dereferenceable(1) %16)
ret void
}