#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 */
scalar_t__ EFAULT;
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ SIGINT;
scalar_t__ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int getpid();
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sigdelset(int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ sigfillset(int /*<<< orphan*/ *);
int /*<<< orphan*/ sigsuspend(int /*<<< orphan*/ *);
int main(void) {
  printf("Pausing until we receive a SIGINT signal (Ctrl+C).\n");
  printf("This process has pid %d\n", getpid());
  sigset_t set;
  sigfillset(&set);
  sigdelset(&set, SIGINT);
  errno = 0;
  sigsuspend(&set);
  if (errno == EFAULT) {
    perror("sigsuspend:");
    exit(EXIT_FAILURE);
  }
  printf("Returned from sigsuspend(), exiting.\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe7a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,%esi
lea    0xe97(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x8(%rbp),%rdi
call   1050 <sigfillset@plt>
mov    0x2e2c(%rip),%rax
mov    (%rax),%esi
lea    -0x8(%rbp),%rdi
call   1070 <sigdelset@plt>
mov    0x2e0a(%rip),%rax
movq   $0x0,(%rax)
lea    -0x8(%rbp),%rdi
call   1060 <sigsuspend@plt>
mov    0x2df3(%rip),%rax
mov    (%rax),%rax
mov    0x2e11(%rip),%rcx
cmp    (%rcx),%rax
jne    120a <main+0x9a>
lea    0xe56(%rip),%rdi
call   1080 <perror@plt>
mov    0x2dc5(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
lea    0xe48(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
lea    0xe9a(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   1040 <getpid@plt>
lea    0xe62(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0x4(%rsp),%rbx
mov    %rbx,%rdi
call   1060 <sigfillset@plt>
mov    0x2e25(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1080 <sigdelset@plt>
mov    0x2e04(%rip),%r14
movq   $0x0,(%r14)
mov    %rbx,%rdi
call   1070 <sigsuspend@plt>
mov    (%r14),%rax
mov    0x2e13(%rip),%rcx
cmp    (%rcx),%rax
je     1200 <main+0x80>
lea    0xe67(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe12(%rip),%rdi
call   1090 <perror@plt>
mov    0x2db5(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [52 x i8] c"Pausing until we receive a SIGINT signal (Ctrl+C).\0A\00"
@.str.1 = [25 x i8] c"This process has pid %d\0A\00"
@SIGINT = global i32 0
@errno = global i64 0
@EFAULT = global i64 0
@.str.2 = [12 x i8] c"sigsuspend:\00"
@EXIT_FAILURE = global i32 0
@.str.3 = [38 x i8] c"Returned from sigsuspend(), exiting.\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
store i32 0, i32* %1
%3 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str, i64 0, i64 0))
%4 = call i32 (...) @getpid()
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i32 %4)
%6 = call i32 @sigfillset(i32* %2)
%7 = load i32, i32* @SIGINT
%8 = call i32 @sigdelset(i32* %2, i32 %7)
store i64 0, i64* @errno
%9 = call i32 @sigsuspend(i32* %2)
%10 = load i64, i64* @errno
%11 = load i64, i64* @EFAULT
%12 = icmp eq i64 %10, %11
br i1 %12, label %13, label %17
13: ; preds = %0
%14 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
%15 = load i32, i32* @EXIT_FAILURE
%16 = call i32 @exit(i32 %15)
unreachable
17: ; preds = %0
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.3, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [25 x i8] c"This process has pid %d\0A\00"
@SIGINT = global i32 0
@errno = global i64 0
@EFAULT = global i64 0
@.str.2 = [12 x i8] c"sigsuspend:\00"
@EXIT_FAILURE = global i32 0
@str = [51 x i8] c"Pausing until we receive a SIGINT signal (Ctrl+C).\00"
@str.4 = [37 x i8] c"Returned from sigsuspend(), exiting.\00"
define i32 @main() {
%1 = alloca i32
%2 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([51 x i8], [51 x i8]* @str, i64 0, i64 0))
%3 = tail call i32 (...) @getpid()
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i32 %3)
%5 = bitcast i32* %1 to i8*
%6 = call i32 @sigfillset(i32* %1)
%7 = load i32, i32* @SIGINT
%8 = call i32 @sigdelset(i32* %1, i32 %7)
store i64 0, i64* @errno
%9 = call i32 @sigsuspend(i32* %1)
%10 = load i64, i64* @errno
%11 = load i64, i64* @EFAULT
%12 = icmp eq i64 %10, %11
br i1 %12, label %13, label %17
13: ; preds = %0
%14 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
%15 = load i32, i32* @EXIT_FAILURE
%16 = call i32 @exit(i32 %15)
unreachable
17: ; preds = %0
%18 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @str.4, i64 0, i64 0))
ret i32 0
}