#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*/ SIGINT;
int /*<<< orphan*/ SIG_BLOCK;
int getpid();
int /*<<< orphan*/ pause();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sigaddset(int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ sigemptyset(int /*<<< orphan*/ *);
scalar_t__ sigismember(int /*<<< orphan*/ *, int /*<<< orphan*/);
int sigpending(int /*<<< orphan*/ *);
int sigprocmask(int /*<<< orphan*/, int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ sleep(int);
char *strsignal(int /*<<< orphan*/);
int /*<<< orphan*/ syserr(char *);
int main(void) {
  sigset_t block_mask, pending_mask;
  sigemptyset(&block_mask);
  sigaddset(&block_mask, SIGINT);
  if (sigprocmask(SIG_BLOCK, &block_mask, 0) == -1)
    syserr("sigprocmask block");
  printf("Mój pid to %d\n", getpid());
  printf("Przez 5 sekund będę blokował sygnał %s\n", strsignal(SIGINT));
  printf("Wciśnięcie Ctrl + c spowoduje wysłanie tego sygnału.\n");
  sleep(5);
  printf("Zakończyłem blokowanie.\n");
  if (sigpending(&pending_mask) == -1)
    syserr("sigpendind");
  if (sigismember(&pending_mask, SIGINT)) {
    printf("Wysłano sygnał %s\n", strsignal(SIGINT));
    printf("Teraz go odblokuję i zakończę działanie\n");
  }
  printf("Nie otrzymałem sygnału, wyślij sygnał by zakończyć\n");
  pause();
  printf("Pause zostało odebrane\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x8(%rbp),%rdi
call   1070 <sigemptyset@plt>
mov    0x2e19(%rip),%rax
mov    (%rax),%esi
lea    -0x8(%rbp),%rdi
call   10d0 <sigaddset@plt>
mov    0x2df7(%rip),%rax
mov    (%rax),%edi
lea    -0x8(%rbp),%rsi
xor    %edx,%edx
call   1030 <sigprocmask@plt>
cmp    $0xffffffff,%eax
jne    1203 <main+0x53>
lea    0xe02(%rip),%rdi
call   1060 <syserr@plt>
mov    $0x0,%al
call   1040 <getpid@plt>
mov    %eax,%esi
lea    0xdff(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    0x2dc7(%rip),%rax
mov    (%rax),%edi
call   1090 <strsignal@plt>
mov    %rax,%rsi
lea    0xdf0(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe0f(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x5,%edi
call   10c0 <sleep@plt>
lea    0xe31(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0xc(%rbp),%rdi
call   10a0 <sigpending@plt>
cmp    $0xffffffff,%eax
jne    127d <main+0xcd>
lea    0xe2c(%rip),%rdi
call   1060 <syserr@plt>
mov    0x2d64(%rip),%rax
mov    (%rax),%esi
lea    -0xc(%rbp),%rdi
call   10b0 <sigismember@plt>
cmp    $0x0,%rax
je     12c6 <main+0x116>
mov    0x2d48(%rip),%rax
mov    (%rax),%edi
call   1090 <strsignal@plt>
mov    %rax,%rsi
lea    0xdfe(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe05(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe24(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x0,%al
call   1080 <pause@plt>
lea    0xe49(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
lea    0x4(%rsp),%rbx
mov    %rbx,%rdi
call   1080 <sigemptyset@plt>
mov    0x2e10(%rip),%r14
mov    (%r14),%esi
mov    %rbx,%rdi
call   10e0 <sigaddset@plt>
mov    0x2dee(%rip),%rax
mov    (%rax),%edi
mov    %rbx,%rsi
xor    %edx,%edx
call   1030 <sigprocmask@plt>
cmp    $0xffffffff,%eax
jne    1207 <main+0x47>
lea    0xdfe(%rip),%rdi
call   1070 <syserr@plt>
xor    %eax,%eax
call   1050 <getpid@plt>
lea    0xdfd(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    (%r14),%edi
call   10a0 <strsignal@plt>
lea    0xdf5(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xe31(%rip),%rdi
call   1040 <puts@plt>
mov    $0x5,%edi
call   10d0 <sleep@plt>
lea    0xe54(%rip),%rdi
call   1040 <puts@plt>
mov    %rsp,%rdi
call   10b0 <sigpending@plt>
cmp    $0xffffffff,%eax
jne    1272 <main+0xb2>
lea    0xde2(%rip),%rdi
call   1070 <syserr@plt>
mov    (%r14),%esi
mov    %rsp,%rdi
call   10c0 <sigismember@plt>
test   %rax,%rax
je     12a7 <main+0xe7>
mov    (%r14),%edi
call   10a0 <strsignal@plt>
lea    0xdc9(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xe71(%rip),%rdi
call   1040 <puts@plt>
lea    0xe14(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
call   1090 <pause@plt>
lea    0xe3a(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@SIGINT = global i32 0
@SIG_BLOCK = global i32 0
@.str = [18 x i8] c"sigprocmask block\00"
@.str.1 = [16 x i8] c"M\C3\B3j pid to %d\0A\00"
@.str.2 = [45 x i8] c"Przez 5 sekund b\C4\99d\C4\99\C2\A0blokowa\C5\82 sygna\C5\82 %s\0A\00"
@.str.3 = [58 x i8] c"Wci\C5\9Bni\C4\99cie Ctrl + c spowoduje wys\C5\82anie tego sygna\C5\82u.\0A\00"
@.str.4 = [27 x i8] c"Zako\C5\84czy\C5\82em blokowanie.\0A\00"
@.str.5 = [11 x i8] c"sigpendind\00"
@.str.6 = [21 x i8] c"Wys\C5\82ano sygna\C5\82 %s\0A\00"
@.str.7 = [45 x i8] c"Teraz go odblokuj\C4\99 i zako\C5\84cz\C4\99 dzia\C5\82anie\0A\00"
@.str.8 = [58 x i8] c"Nie otrzyma\C5\82em sygna\C5\82u, wy\C5\9Blij sygna\C5\82 by zako\C5\84czy\C4\87\0A\00"
@.str.9 = [25 x i8] c"Pause zosta\C5\82o odebrane\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
store i32 0, i32* %1
%4 = call i32 @sigemptyset(i32* %2)
%5 = load i32, i32* @SIGINT
%6 = call i32 @sigaddset(i32* %2, i32 %5)
%7 = load i32, i32* @SIG_BLOCK
%8 = call i32 @sigprocmask(i32 %7, i32* %2, i32 0)
%9 = icmp eq i32 %8, -1
br i1 %9, label %10, label %12
10: ; preds = %0
%11 = call i32 @syserr(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
br label %12
12: ; preds = %10, %0
%13 = call i32 (...) @getpid()
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i32 %13)
%15 = load i32, i32* @SIGINT
%16 = call i8* @strsignal(i32 %15)
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.2, i64 0, i64 0), i8* %16)
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.3, i64 0, i64 0))
%19 = call i32 @sleep(i32 5)
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0))
%21 = call i32 @sigpending(i32* %3)
%22 = icmp eq i32 %21, -1
br i1 %22, label %23, label %25
23: ; preds = %12
%24 = call i32 @syserr(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0))
br label %25
25: ; preds = %23, %12
%26 = load i32, i32* @SIGINT
%27 = call i64 @sigismember(i32* %3, i32 %26)
%28 = icmp ne i64 %27, 0
br i1 %28, label %29, label %34
29: ; preds = %25
%30 = load i32, i32* @SIGINT
%31 = call i8* @strsignal(i32 %30)
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.6, i64 0, i64 0), i8* %31)
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.7, i64 0, i64 0))
br label %34
34: ; preds = %29, %25
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.8, i64 0, i64 0))
%36 = call i32 (...) @pause()
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.9, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@SIGINT = global i32 0
@SIG_BLOCK = global i32 0
@.str = [18 x i8] c"sigprocmask block\00"
@.str.1 = [16 x i8] c"M\C3\B3j pid to %d\0A\00"
@.str.2 = [45 x i8] c"Przez 5 sekund b\C4\99d\C4\99\C2\A0blokowa\C5\82 sygna\C5\82 %s\0A\00"
@.str.5 = [11 x i8] c"sigpendind\00"
@.str.6 = [21 x i8] c"Wys\C5\82ano sygna\C5\82 %s\0A\00"
@str = [57 x i8] c"Wci\C5\9Bni\C4\99cie Ctrl + c spowoduje wys\C5\82anie tego sygna\C5\82u.\00"
@str.10 = [26 x i8] c"Zako\C5\84czy\C5\82em blokowanie.\00"
@str.11 = [57 x i8] c"Nie otrzyma\C5\82em sygna\C5\82u, wy\C5\9Blij sygna\C5\82 by zako\C5\84czy\C4\87\00"
@str.12 = [24 x i8] c"Pause zosta\C5\82o odebrane\00"
@str.13 = [44 x i8] c"Teraz go odblokuj\C4\99 i zako\C5\84cz\C4\99 dzia\C5\82anie\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = bitcast i32* %1 to i8*
%4 = bitcast i32* %2 to i8*
%5 = call i32 @sigemptyset(i32* %1)
%6 = load i32, i32* @SIGINT
%7 = call i32 @sigaddset(i32* %1, i32 %6)
%8 = load i32, i32* @SIG_BLOCK
%9 = call i32 @sigprocmask(i32 %8, i32* %1, i32 0)
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %13
11: ; preds = %0
%12 = call i32 @syserr(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
br label %13
13: ; preds = %11, %0
%14 = call i32 (...) @getpid()
%15 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i32 %14)
%16 = load i32, i32* @SIGINT
%17 = call i8* @strsignal(i32 %16)
%18 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @.str.2, i64 0, i64 0), i8* %17)
%19 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([57 x i8], [57 x i8]* @str, i64 0, i64 0))
%20 = call i32 @sleep(i32 5)
%21 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str.10, i64 0, i64 0))
%22 = call i32 @sigpending(i32* %2)
%23 = icmp eq i32 %22, -1
br i1 %23, label %24, label %26
24: ; preds = %13
%25 = call i32 @syserr(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0))
br label %26
26: ; preds = %24, %13
%27 = load i32, i32* @SIGINT
%28 = call i64 @sigismember(i32* %2, i32 %27)
%29 = icmp eq i64 %28, 0
br i1 %29, label %35, label %30
30: ; preds = %26
%31 = load i32, i32* @SIGINT
%32 = call i8* @strsignal(i32 %31)
%33 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.6, i64 0, i64 0), i8* %32)
%34 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 x i8]* @str.13, i64 0, i64 0))
br label %35
35: ; preds = %30, %26
%36 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([57 x i8], [57 x i8]* @str.11, i64 0, i64 0))
%37 = call i32 (...) @pause()
%38 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str.12, i64 0, i64 0))
ret i32 0
}