#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 */
struct sigaction {
  int /*<<< orphan*/ sa_mask;
  int /*<<< orphan*/ sa_handler;
};
typedef int /*<<< orphan*/ sa;

/* Variables and functions */
int /*<<< orphan*/ SIGPIPE;
int /*<<< orphan*/ SIG_IGN;
int /*<<< orphan*/ die(char *);
int /*<<< orphan*/ memset(struct sigaction *, int /*<<< orphan*/, int);
scalar_t__ sigaction(int /*<<< orphan*/, struct sigaction *,
                     int /*<<< orphan*/);
scalar_t__ sigemptyset(int /*<<< orphan*/ *);
void ignore_sigpipe(void) {
  struct sigaction sa;
  memset(&sa, 0, sizeof(sa));
  sa.sa_handler = SIG_IGN;
  if (sigemptyset(&sa.sa_mask) < 0 || sigaction(SIGPIPE, &sa, 0) < 0)
    die("Unable to block SIGPIPE");
}


x86 assembly (clang, -O0):
<ignore_sigpipe>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    -0x8(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1040 <memset@plt>
mov    0x2e89(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
lea    -0x8(%rbp),%rdi
call   1050 <sigemptyset@plt>
cmp    $0x0,%rax
jl     1195 <ignore_sigpipe+0x55>
mov    0x2e5a(%rip),%rax
mov    (%rax),%edi
lea    -0x8(%rbp),%rsi
xor    %edx,%edx
call   1030 <sigaction@plt>
cmp    $0x0,%rax
jge    11a1 <ignore_sigpipe+0x61>
lea    0xe64(%rip),%rdi
call   1060 <die@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ignore_sigpipe>:
push   %rbx
sub    $0x10,%rsp
lea    0x8(%rsp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1040 <memset@plt>
mov    0x2e88(%rip),%rax
mov    (%rax),%eax
mov    %eax,0xc(%rsp)
mov    %rbx,%rdi
call   1050 <sigemptyset@plt>
test   %rax,%rax
js     118d <ignore_sigpipe+0x4d>
mov    0x2e5e(%rip),%rax
mov    (%rax),%edi
lea    0x8(%rsp),%rsi
xor    %edx,%edx
call   1030 <sigaction@plt>
test   %rax,%rax
jns    1199 <ignore_sigpipe+0x59>
lea    0xe6c(%rip),%rdi
call   1060 <die@plt>
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.sigaction = type { i32, i32 }
@SIG_IGN = global i32 0
@SIGPIPE = global i32 0
@.str = [24 x i8] c"Unable to block SIGPIPE\00"
define void @ignore_sigpipe() {
%1 = alloca %struct.sigaction
%2 = call i32 @memset(%struct.sigaction* %1, i32 0, i32 8)
%3 = load i32, i32* @SIG_IGN
%4 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %1, i32 0, i32 1
store i32 %3, i32* %4
%5 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %1, i32 0, i32 0
%6 = call i64 @sigemptyset(i32* %5)
%7 = icmp slt i64 %6, 0
br i1 %7, label %12, label %8
8: ; preds = %0
%9 = load i32, i32* @SIGPIPE
%10 = call i64 @sigaction(i32 %9, %struct.sigaction* %1, i32 0)
%11 = icmp slt i64 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %8, %0
%13 = call i32 @die(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
br label %14
14: ; preds = %12, %8
ret void
}

LLVM IR (-O2):
%struct.sigaction = type { i32, i32 }
@SIG_IGN = global i32 0
@SIGPIPE = global i32 0
@.str = [24 x i8] c"Unable to block SIGPIPE\00"
define void @ignore_sigpipe() {
%1 = alloca %struct.sigaction
%2 = bitcast %struct.sigaction* %1 to i8*
%3 = call i32 @memset(%struct.sigaction* %1, i32 0, i32 8)
%4 = load i32, i32* @SIG_IGN
%5 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %1, i64 0, i32 1
store i32 %4, i32* %5
%6 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %1, i64 0, i32 0
%7 = call i64 @sigemptyset(i32* %6)
%8 = icmp slt i64 %7, 0
br i1 %8, label %13, label %9
9: ; preds = %0
%10 = load i32, i32* @SIGPIPE
%11 = call i64 @sigaction(i32 %10, %struct.sigaction* %1, i32 0)
%12 = icmp slt i64 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %9, %0
%14 = call i32 @die(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
br label %15
15: ; preds = %13, %9
ret void
}