#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 */
struct sigaction {
  int sa_handler;
};
typedef int /*<<< orphan*/ sigset_t;

/* Variables and functions */
int NSIG;
int /*<<< orphan*/ SIG_BLOCK;
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sigaction(int, int /*<<< orphan*/ *, struct sigaction *);
scalar_t__ sigismember(int /*<<< orphan*/ *, int);
int /*<<< orphan*/ sigpending(int /*<<< orphan*/ *);
int /*<<< orphan*/ sigprocmask(int /*<<< orphan*/, int /*<<< orphan*/ *,
                               int /*<<< orphan*/ *);
void display_state() {
  sigset_t pending;
  sigset_t mask;
  struct sigaction oact;
  int i;
  printf("signal\tpending\tblocked\thandler\n");
  sigpending(&pending);
  sigprocmask(SIG_BLOCK, NULL, &mask);
  for (i = 1; i < NSIG; i++) {
    printf("%d\t", i);
    if (sigismember(&pending, i)) {
      printf("P\t");
    } else {
      printf("\t");
    }
    if (sigismember(&mask, i)) {
      printf("B\t");
    } else {
      printf("\t");
    }
    sigaction(i, NULL, &oact);
    printf("%p\n", oact.sa_handler);
  }
}


x86 assembly (clang, -O0):
<display_state>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    0xea1(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x4(%rbp),%rdi
call   1060 <sigpending@plt>
mov    0x2e6a(%rip),%rax
mov    (%rax),%edi
xor    %eax,%eax
mov    %eax,%esi
lea    -0x8(%rbp),%rdx
call   1030 <sigprocmask@plt>
movl   $0x1,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    0x2e42(%rip),%rcx
cmp    (%rcx),%eax
jge    124c <display_state+0xfc>
mov    -0x14(%rbp),%esi
lea    0xe78(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x14(%rbp),%esi
lea    -0x4(%rbp),%rdi
call   1070 <sigismember@plt>
cmp    $0x0,%rax
je     11d8 <display_state+0x88>
lea    0xe58(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    11e6 <display_state+0x96>
lea    0xe49(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x14(%rbp),%esi
lea    -0x8(%rbp),%rdi
call   1070 <sigismember@plt>
cmp    $0x0,%rax
je     120f <display_state+0xbf>
lea    0xe24(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    121d <display_state+0xcd>
lea    0xe12(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x14(%rbp),%edi
xor    %eax,%eax
mov    %eax,%esi
lea    -0x10(%rbp),%rdx
call   1040 <sigaction@plt>
mov    -0x10(%rbp),%esi
lea    0xdf3(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    118c <display_state+0x3c>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<display_state>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
lea    0xe89(%rip),%rdi
call   1050 <puts@plt>
lea    0x14(%rsp),%rdi
call   1080 <sigpending@plt>
mov    0x2e45(%rip),%rax
mov    (%rax),%edi
lea    0x10(%rsp),%rdx
xor    %esi,%esi
call   1030 <sigprocmask@plt>
mov    0x2e28(%rip),%r14
cmpl   $0x2,(%r14)
jl     1269 <display_state+0xf9>
mov    $0x1,%ebx
lea    0x14(%rsp),%r15
lea    0x10(%rsp),%r12
lea    0x8(%rsp),%r13
lea    0xe35(%rip),%rbp
jmp    120c <display_state+0x9c>
nopw   0x0(%rax,%rax,1)
mov    $0x9,%edi
call   1040 <putchar@plt>
mov    %ebx,%edi
xor    %esi,%esi
mov    %r13,%rdx
call   1060 <sigaction@plt>
mov    0x8(%rsp),%esi
mov    %rbp,%rdi
xor    %eax,%eax
call   1070 <printf@plt>
add    $0x1,%ebx
cmp    (%r14),%ebx
jge    1269 <display_state+0xf9>
lea    0xded(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %r15,%rdi
mov    %ebx,%esi
call   1090 <sigismember@plt>
test   %rax,%rax
je     1240 <display_state+0xd0>
lea    0xdd2(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
jmp    124a <display_state+0xda>
nopl   0x0(%rax,%rax,1)
mov    $0x9,%edi
call   1040 <putchar@plt>
mov    %r12,%rdi
mov    %ebx,%esi
call   1090 <sigismember@plt>
test   %rax,%rax
je     11e0 <display_state+0x70>
lea    0xda7(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
jmp    11ea <display_state+0x7a>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sigaction = type { i32 }
@.str = [32 x i8] c"signal\09pending\09blocked\09handler\0A\00"
@SIG_BLOCK = global i32 0
@NSIG = global i32 0
@.str.1 = [4 x i8] c"%d\09\00"
@.str.2 = [3 x i8] c"P\09\00"
@.str.3 = [2 x i8] c"\09\00"
@.str.4 = [3 x i8] c"B\09\00"
@.str.5 = [4 x i8] c"%p\0A\00"
define void @display_state() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca %struct.sigaction
%4 = alloca i32
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
%6 = call i32 @sigpending(i32* %1)
%7 = load i32, i32* @SIG_BLOCK
%8 = call i32 @sigprocmask(i32 %7, i32* null, i32* %2)
store i32 1, i32* %4
br label %9
9: ; preds = %37, %0
%10 = load i32, i32* %4
%11 = load i32, i32* @NSIG
%12 = icmp slt i32 %10, %11
br i1 %12, label %13, label %40
13: ; preds = %9
%14 = load i32, i32* %4
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %14)
%16 = load i32, i32* %4
%17 = call i64 @sigismember(i32* %1, i32 %16)
%18 = icmp ne i64 %17, 0
br i1 %18, label %19, label %21
19: ; preds = %13
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
br label %23
21: ; preds = %13
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %23
23: ; preds = %21, %19
%24 = load i32, i32* %4
%25 = call i64 @sigismember(i32* %2, i32 %24)
%26 = icmp ne i64 %25, 0
br i1 %26, label %27, label %29
27: ; preds = %23
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
br label %31
29: ; preds = %23
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %31
31: ; preds = %29, %27
%32 = load i32, i32* %4
%33 = call i32 @sigaction(i32 %32, i32* null, %struct.sigaction* %3)
%34 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %3, i32 0, i32 0
%35 = load i32, i32* %34
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i32 %35)
br label %37
37: ; preds = %31
%38 = load i32, i32* %4
%39 = add nsw i32 %38, 1
store i32 %39, i32* %4
br label %9
40: ; preds = %9
ret void
}

LLVM IR (-O2):
%struct.sigaction = type { i32 }
@SIG_BLOCK = global i32 0
@NSIG = global i32 0
@.str.1 = [4 x i8] c"%d\09\00"
@.str.2 = [3 x i8] c"P\09\00"
@.str.4 = [3 x i8] c"B\09\00"
@.str.5 = [4 x i8] c"%p\0A\00"
@str = [31 x i8] c"signal\09pending\09blocked\09handler\00"
define void @display_state() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca %struct.sigaction
%4 = bitcast i32* %1 to i8*
%5 = bitcast i32* %2 to i8*
%6 = bitcast %struct.sigaction* %3 to i8*
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @str, i64 0, i64 0))
%8 = call i32 @sigpending(i32* %1)
%9 = load i32, i32* @SIG_BLOCK
%10 = call i32 @sigprocmask(i32 %9, i32* null, i32* %2)
%11 = load i32, i32* @NSIG
%12 = icmp sgt i32 %11, 1
br i1 %12, label %13, label %38
13: ; preds = %0
%14 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %3, i64 0, i32 0
br label %15
15: ; preds = %13, %31
%16 = phi i32 [ 1, %13 ], [ %35, %31 ]
%17 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %16)
%18 = call i64 @sigismember(i32* %1, i32 %16)
%19 = icmp eq i64 %18, 0
br i1 %19, label %22, label %20
20: ; preds = %15
%21 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
br label %24
22: ; preds = %15
%23 = call i32 @putchar(i32 9)
br label %24
24: ; preds = %22, %20
%25 = call i64 @sigismember(i32* %2, i32 %16)
%26 = icmp eq i64 %25, 0
br i1 %26, label %29, label %27
27: ; preds = %24
%28 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
br label %31
29: ; preds = %24
%30 = call i32 @putchar(i32 9)
br label %31
31: ; preds = %29, %27
%32 = call i32 @sigaction(i32 %16, i32* null, %struct.sigaction* %3)
%33 = load i32, i32* %14
%34 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i32 %33)
%35 = add nuw nsw i32 %16, 1
%36 = load i32, i32* @NSIG
%37 = icmp slt i32 %35, %36
br i1 %37, label %15, label %38
38: ; preds = %31, %0
ret void
}