#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;
typedef int /*<<< orphan*/ sigset;
typedef int int8_t;

/* Variables and functions */
int /*<<< orphan*/ SIGPIPE;
int /*<<< orphan*/ SIG_BLOCK;
int /*<<< orphan*/ memset(int /*<<< orphan*/ *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int sigaddset(int /*<<< orphan*/ *, int /*<<< orphan*/);
int sigprocmask(int /*<<< orphan*/, int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int8_t block_sigpipe() {
  sigset_t sigset;
  memset(&sigset, 0, sizeof(sigset));
  if (sigprocmask(SIG_BLOCK, NULL, &sigset) == -1) {
    perror("sigprocmask (get)");
    return -1;
  }
  if (sigaddset(&sigset, SIGPIPE) == -1) {
    perror("sigaddset");
    return -1;
  }
  if (sigprocmask(SIG_BLOCK, &sigset, NULL) == -1) {
    perror("sigprocmask (set)");
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<block_sigpipe>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    -0x8(%rbp),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1040 <memset@plt>
mov    0x2e79(%rip),%rax
mov    (%rax),%edi
xor    %eax,%eax
mov    %eax,%esi
lea    -0x8(%rbp),%rdx
call   1030 <sigprocmask@plt>
cmp    $0xffffffff,%eax
jne    118f <block_sigpipe+0x4f>
lea    0xe82(%rip),%rdi
call   1050 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1200 <block_sigpipe+0xc0>
mov    0x2e4a(%rip),%rax
mov    (%rax),%esi
lea    -0x8(%rbp),%rdi
call   1060 <sigaddset@plt>
cmp    $0xffffffff,%eax
jne    11c2 <block_sigpipe+0x82>
lea    0xe61(%rip),%rdi
call   1050 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1200 <block_sigpipe+0xc0>
mov    0x2e0f(%rip),%rax
mov    (%rax),%edi
lea    -0x8(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1030 <sigprocmask@plt>
cmp    $0xffffffff,%eax
jne    11f9 <block_sigpipe+0xb9>
lea    0xe34(%rip),%rdi
call   1050 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1200 <block_sigpipe+0xc0>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<block_sigpipe>:
push   %r14
push   %rbx
push   %rax
lea    0x4(%rsp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1040 <memset@plt>
mov    0x2e79(%rip),%r14
mov    (%r14),%edi
xor    %esi,%esi
mov    %rbx,%rdx
call   1030 <sigprocmask@plt>
cmp    $0xffffffff,%eax
je     11a9 <block_sigpipe+0x69>
mov    0x2e68(%rip),%rax
mov    (%rax),%esi
lea    0x4(%rsp),%rdi
call   1060 <sigaddset@plt>
cmp    $0xffffffff,%eax
je     11b2 <block_sigpipe+0x72>
mov    (%r14),%edi
xor    %ebx,%ebx
lea    0x4(%rsp),%rsi
xor    %edx,%edx
call   1030 <sigprocmask@plt>
cmp    $0xffffffff,%eax
je     11bb <block_sigpipe+0x7b>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe50(%rip),%rdi
jmp    11c2 <block_sigpipe+0x82>
lea    0xe59(%rip),%rdi
jmp    11c2 <block_sigpipe+0x82>
lea    0xe5a(%rip),%rdi
call   1050 <perror@plt>
mov    $0xffffffff,%ebx
jmp    119f <block_sigpipe+0x5f>

LLVM IR (-O0):
@SIG_BLOCK = global i32 0
@.str = [18 x i8] c"sigprocmask (get)\00"
@SIGPIPE = global i32 0
@.str.1 = [10 x i8] c"sigaddset\00"
@.str.2 = [18 x i8] c"sigprocmask (set)\00"
define i32 @block_sigpipe() {
%1 = alloca i32
%2 = alloca i32
%3 = call i32 @memset(i32* %2, i32 0, i32 4)
%4 = load i32, i32* @SIG_BLOCK
%5 = call i32 @sigprocmask(i32 %4, i32* null, i32* %2)
%6 = icmp eq i32 %5, -1
br i1 %6, label %7, label %9
7: ; preds = %0
%8 = call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %1
br label %22
9: ; preds = %0
%10 = load i32, i32* @SIGPIPE
%11 = call i32 @sigaddset(i32* %2, i32 %10)
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %15
13: ; preds = %9
%14 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %1
br label %22
15: ; preds = %9
%16 = load i32, i32* @SIG_BLOCK
%17 = call i32 @sigprocmask(i32 %16, i32* %2, i32* null)
%18 = icmp eq i32 %17, -1
br i1 %18, label %19, label %21
19: ; preds = %15
%20 = call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %1
br label %22
21: ; preds = %15
store i32 0, i32* %1
br label %22
22: ; preds = %21, %19, %13, %7
%23 = load i32, i32* %1
ret i32 %23
}

LLVM IR (-O2):
@SIG_BLOCK = global i32 0
@.str = [18 x i8] c"sigprocmask (get)\00"
@SIGPIPE = global i32 0
@.str.1 = [10 x i8] c"sigaddset\00"
@.str.2 = [18 x i8] c"sigprocmask (set)\00"
define i32 @block_sigpipe() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = call i32 @memset(i32* %1, i32 0, i32 4)
%4 = load i32, i32* @SIG_BLOCK
%5 = call i32 @sigprocmask(i32 %4, i32* null, i32* %1)
%6 = icmp eq i32 %5, -1
br i1 %6, label %15, label %7
7: ; preds = %0
%8 = load i32, i32* @SIGPIPE
%9 = call i32 @sigaddset(i32* %1, i32 %8)
%10 = icmp eq i32 %9, -1
br i1 %10, label %15, label %11
11: ; preds = %7
%12 = load i32, i32* @SIG_BLOCK
%13 = call i32 @sigprocmask(i32 %12, i32* %1, i32* null)
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %18
15: ; preds = %11, %7, %0
%16 = phi i8* [ getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), %0 ], [ getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), %7 ], [ getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), %11 ]
%17 = call i32 @perror(i8* %16)
br label %18
18: ; preds = %15, %11
%19 = phi i32 [ 0, %11 ], [ -1, %15 ]
ret i32 %19
}