#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 EINVAL;
int pthread_sigmask(int, int /*<<< orphan*/ const *, int /*<<< orphan*/ *);
scalar_t__ sigprocmask(int, int /*<<< orphan*/ const *, int /*<<< orphan*/ *);
int uv__pthread_sigmask(int how, const sigset_t *set, sigset_t *oset) {
  static int workaround;
  int err;
  if (workaround) {
    return sigprocmask(how, set, oset);
  } else {
    err = pthread_sigmask(how, set, oset);
    if (err) {
      if (err == EINVAL && sigprocmask(how, set, oset) == 0) {
        workaround = 1;
        return 0;
      } else {
        return -1;
      }
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<uv__pthread_sigmask>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
cmpl   $0x0,0x2efa(%rip)
je     1158 <uv__pthread_sigmask+0x38>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1030 <sigprocmask@plt>
mov    %eax,-0x4(%rbp)
jmp    11cf <uv__pthread_sigmask+0xaf>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1040 <pthread_sigmask@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     11c3 <uv__pthread_sigmask+0xa3>
mov    -0x1c(%rbp),%eax
mov    0x2e61(%rip),%rcx
cmp    (%rcx),%eax
jne    11b7 <uv__pthread_sigmask+0x97>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1030 <sigprocmask@plt>
cmp    $0x0,%rax
jne    11b7 <uv__pthread_sigmask+0x97>
movl   $0x1,0x2e89(%rip)
movl   $0x0,-0x4(%rbp)
jmp    11cf <uv__pthread_sigmask+0xaf>
movl   $0xffffffff,-0x4(%rbp)
jmp    11cf <uv__pthread_sigmask+0xaf>
jmp    11c8 <uv__pthread_sigmask+0xa8>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<uv__pthread_sigmask>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%r15
mov    %edi,%ebp
cmpb   $0x1,0x2efe(%rip)
jne    114a <uv__pthread_sigmask+0x2a>
mov    %ebp,%edi
mov    %r15,%rsi
mov    %r14,%rdx
call   1030 <sigprocmask@plt>
mov    %rax,%rbx
jmp    1188 <uv__pthread_sigmask+0x68>
mov    %ebp,%edi
mov    %r15,%rsi
mov    %r14,%rdx
call   1040 <pthread_sigmask@plt>
xor    %ebx,%ebx
test   %eax,%eax
je     1188 <uv__pthread_sigmask+0x68>
mov    0x2e7c(%rip),%rcx
mov    $0xffffffff,%ebx
cmp    (%rcx),%eax
jne    1188 <uv__pthread_sigmask+0x68>
mov    %ebp,%edi
mov    %r15,%rsi
mov    %r14,%rdx
call   1030 <sigprocmask@plt>
test   %rax,%rax
jne    1188 <uv__pthread_sigmask+0x68>
movb   $0x1,0x2eae(%rip)
xor    %ebx,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@uv__pthread_sigmask.workaround = internal global i32 0
@EINVAL = global i32 0
define i32 @uv__pthread_sigmask(i32 %0, i32* %1, i32* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i32
store i32 %0, i32* %5
store i32* %1, i32** %6
store i32* %2, i32** %7
%9 = load i32, i32* @uv__pthread_sigmask.workaround
%10 = icmp ne i32 %9, 0
br i1 %10, label %11, label %17
11: ; preds = %3
%12 = load i32, i32* %5
%13 = load i32*, i32** %6
%14 = load i32*, i32** %7
%15 = call i64 @sigprocmask(i32 %12, i32* %13, i32* %14)
%16 = trunc i64 %15 to i32
store i32 %16, i32* %4
br label %38
17: ; preds = %3
%18 = load i32, i32* %5
%19 = load i32*, i32** %6
%20 = load i32*, i32** %7
%21 = call i32 @pthread_sigmask(i32 %18, i32* %19, i32* %20)
store i32 %21, i32* %8
%22 = load i32, i32* %8
%23 = icmp ne i32 %22, 0
br i1 %23, label %24, label %36
24: ; preds = %17
%25 = load i32, i32* %8
%26 = load i32, i32* @EINVAL
%27 = icmp eq i32 %25, %26
br i1 %27, label %28, label %35
28: ; preds = %24
%29 = load i32, i32* %5
%30 = load i32*, i32** %6
%31 = load i32*, i32** %7
%32 = call i64 @sigprocmask(i32 %29, i32* %30, i32* %31)
%33 = icmp eq i64 %32, 0
br i1 %33, label %34, label %35
34: ; preds = %28
store i32 1, i32* @uv__pthread_sigmask.workaround
store i32 0, i32* %4
br label %38
35: ; preds = %28, %24
store i32 -1, i32* %4
br label %38
36: ; preds = %17
br label %37
37: ; preds = %36
store i32 0, i32* %4
br label %38
38: ; preds = %37, %35, %34, %11
%39 = load i32, i32* %4
ret i32 %39
}

LLVM IR (-O2):
@uv__pthread_sigmask.workaround = internal unnamed_addr global i1 false
@EINVAL = global i32 0
define i32 @uv__pthread_sigmask(i32 %0, i32* %1, i32* %2) {
%4 = load i1, i1* @uv__pthread_sigmask.workaround
br i1 %4, label %5, label %8
5: ; preds = %3
%6 = tail call i64 @sigprocmask(i32 %0, i32* %1, i32* %2)
%7 = trunc i64 %6 to i32
br label %18
8: ; preds = %3
%9 = tail call i32 @pthread_sigmask(i32 %0, i32* %1, i32* %2)
%10 = icmp eq i32 %9, 0
br i1 %10, label %18, label %11
11: ; preds = %8
%12 = load i32, i32* @EINVAL
%13 = icmp eq i32 %9, %12
br i1 %13, label %14, label %18
14: ; preds = %11
%15 = tail call i64 @sigprocmask(i32 %0, i32* %1, i32* %2)
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %18
17: ; preds = %14
store i1 true, i1* @uv__pthread_sigmask.workaround
br label %18
18: ; preds = %8, %11, %14, %17, %5
%19 = phi i32 [ %7, %5 ], [ 0, %17 ], [ -1, %14 ], [ -1, %11 ], [ 0, %8 ]
ret i32 %19
}