#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*/ SIGTERM;
int /*<<< orphan*/ SIG_BLOCK;
int /*<<< orphan*/ SIG_UNBLOCK;
int /*<<< orphan*/ pq_quit_state();
int /*<<< orphan*/ sigaddset(int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ sigemptyset(int /*<<< orphan*/ *);
int /*<<< orphan*/ sigprocmask(int /*<<< orphan*/, int /*<<< orphan*/ *,
                               int /*<<< orphan*/ *);
int /*<<< orphan*/ sigsuspend(int /*<<< orphan*/ *);
int pq_implementation_wait(void) {
  sigset_t mask, oldmask;
  sigemptyset(&mask);
  sigaddset(&mask, SIGINT);
  sigaddset(&mask, SIGTERM);
  sigprocmask(SIG_BLOCK, &mask, &oldmask);
  while (!pq_quit_state()) {
    sigsuspend(&oldmask);
  }
  sigprocmask(SIG_UNBLOCK, &mask, NULL);
  return 1;
}


x86 assembly (clang, -O0):
<pq_implementation_wait>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    -0x4(%rbp),%rdi
call   1040 <sigemptyset@plt>
mov    0x2e78(%rip),%rax
mov    (%rax),%esi
lea    -0x4(%rbp),%rdi
call   1070 <sigaddset@plt>
mov    0x2e5e(%rip),%rax
mov    (%rax),%esi
lea    -0x4(%rbp),%rdi
call   1070 <sigaddset@plt>
mov    0x2e3c(%rip),%rax
mov    (%rax),%edi
lea    -0x4(%rbp),%rsi
lea    -0x8(%rbp),%rdx
call   1030 <sigprocmask@plt>
mov    $0x0,%al
call   1060 <pq_quit_state@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11b7 <pq_implementation_wait+0x67>
jmp    11c5 <pq_implementation_wait+0x75>
lea    -0x8(%rbp),%rdi
call   1050 <sigsuspend@plt>
jmp    119b <pq_implementation_wait+0x4b>
mov    0x2e1c(%rip),%rax
mov    (%rax),%edi
lea    -0x4(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1030 <sigprocmask@plt>
mov    $0x1,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pq_implementation_wait>:
push   %rbx
sub    $0x10,%rsp
lea    0xc(%rsp),%rbx
mov    %rbx,%rdi
call   1040 <sigemptyset@plt>
mov    0x2e77(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1070 <sigaddset@plt>
mov    0x2e5e(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1070 <sigaddset@plt>
mov    0x2e3d(%rip),%rax
mov    (%rax),%edi
lea    0x8(%rsp),%rdx
mov    %rbx,%rsi
call   1030 <sigprocmask@plt>
xor    %eax,%eax
call   1060 <pq_quit_state@plt>
test   %eax,%eax
jne    11c3 <pq_implementation_wait+0x73>
lea    0x8(%rsp),%rbx
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1050 <sigsuspend@plt>
xor    %eax,%eax
call   1060 <pq_quit_state@plt>
test   %eax,%eax
je     11b0 <pq_implementation_wait+0x60>
mov    0x2e1e(%rip),%rax
mov    (%rax),%edi
lea    0xc(%rsp),%rsi
xor    %edx,%edx
call   1030 <sigprocmask@plt>
mov    $0x1,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@SIGINT = global i32 0
@SIGTERM = global i32 0
@SIG_BLOCK = global i32 0
@SIG_UNBLOCK = global i32 0
define i32 @pq_implementation_wait() {
%1 = alloca i32
%2 = alloca i32
%3 = call i32 @sigemptyset(i32* %1)
%4 = load i32, i32* @SIGINT
%5 = call i32 @sigaddset(i32* %1, i32 %4)
%6 = load i32, i32* @SIGTERM
%7 = call i32 @sigaddset(i32* %1, i32 %6)
%8 = load i32, i32* @SIG_BLOCK
%9 = call i32 @sigprocmask(i32 %8, i32* %1, i32* %2)
br label %10
10: ; preds = %14, %0
%11 = call i32 (...) @pq_quit_state()
%12 = icmp ne i32 %11, 0
%13 = xor i1 %12, true
br i1 %13, label %14, label %16
14: ; preds = %10
%15 = call i32 @sigsuspend(i32* %2)
br label %10
16: ; preds = %10
%17 = load i32, i32* @SIG_UNBLOCK
%18 = call i32 @sigprocmask(i32 %17, i32* %1, i32* null)
ret i32 1
}

LLVM IR (-O2):
@SIGINT = global i32 0
@SIGTERM = global i32 0
@SIG_BLOCK = global i32 0
@SIG_UNBLOCK = global i32 0
define i32 @pq_implementation_wait() {
%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* @SIGTERM
%9 = call i32 @sigaddset(i32* %1, i32 %8)
%10 = load i32, i32* @SIG_BLOCK
%11 = call i32 @sigprocmask(i32 %10, i32* %1, i32* %2)
%12 = call i32 (...) @pq_quit_state()
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %18
14: ; preds = %0, %14
%15 = call i32 @sigsuspend(i32* %2)
%16 = call i32 (...) @pq_quit_state()
%17 = icmp eq i32 %16, 0
br i1 %17, label %14, label %18
18: ; preds = %14, %0
%19 = load i32, i32* @SIG_UNBLOCK
%20 = call i32 @sigprocmask(i32 %19, i32* %1, i32* null)
ret i32 1
}