#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 {
  scalar_t__ sa_handler;
};

/* Variables and functions */
int /*<<< orphan*/ SIGPIPE;
scalar_t__ SIG_DFL;
scalar_t__ SIG_IGN;
int sigaction(int /*<<< orphan*/, struct sigaction *, struct sigaction *);
int u_ignore_sigpipe() {
  struct sigaction act;
  if (sigaction(SIGPIPE, (struct sigaction *)NULL, &act) == -1)
    return -1;
  if (act.sa_handler == SIG_DFL) {
    act.sa_handler = SIG_IGN;
    if (sigaction(SIGPIPE, &act, (struct sigaction *)NULL) == -1)
      return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<u_ignore_sigpipe>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    0x2eb9(%rip),%rax
mov    (%rax),%edi
xor    %eax,%eax
mov    %eax,%esi
lea    -0x10(%rbp),%rdx
call   1030 <sigaction@plt>
cmp    $0xffffffff,%eax
jne    1143 <u_ignore_sigpipe+0x33>
movl   $0xffffffff,-0x4(%rbp)
jmp    119c <u_ignore_sigpipe+0x8c>
mov    -0x10(%rbp),%rax
mov    0x2e82(%rip),%rcx
cmp    (%rcx),%rax
jne    1195 <u_ignore_sigpipe+0x85>
mov    0x2e8a(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x10(%rbp)
mov    0x2e6c(%rip),%rax
mov    (%rax),%edi
lea    -0x10(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1030 <sigaction@plt>
cmp    $0xffffffff,%eax
jne    1190 <u_ignore_sigpipe+0x80>
movl   $0xffffffff,-0x4(%rbp)
jmp    119c <u_ignore_sigpipe+0x8c>
jmp    1195 <u_ignore_sigpipe+0x85>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<u_ignore_sigpipe>:
push   %r14
push   %rbx
push   %rax
mov    0x2ebd(%rip),%r14
mov    (%r14),%edi
mov    %rsp,%rdx
xor    %esi,%esi
call   1030 <sigaction@plt>
mov    $0xffffffff,%ebx
cmp    $0xffffffff,%eax
je     1164 <u_ignore_sigpipe+0x54>
mov    (%rsp),%rax
mov    0x2e93(%rip),%rcx
cmp    (%rcx),%rax
jne    1162 <u_ignore_sigpipe+0x52>
mov    0x2e9f(%rip),%rax
mov    (%rax),%rax
mov    %rax,(%rsp)
mov    (%r14),%edi
mov    %rsp,%rsi
xor    %edx,%edx
call   1030 <sigaction@plt>
cmp    $0xffffffff,%eax
je     1164 <u_ignore_sigpipe+0x54>
xor    %ebx,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.sigaction = type { i64 }
@SIGPIPE = global i32 0
@SIG_DFL = global i64 0
@SIG_IGN = global i64 0
define i32 @u_ignore_sigpipe() {
%1 = alloca i32
%2 = alloca %struct.sigaction
%3 = load i32, i32* @SIGPIPE
%4 = call i32 @sigaction(i32 %3, %struct.sigaction* null, %struct.sigaction* %2)
%5 = icmp eq i32 %4, -1
br i1 %5, label %6, label %7
6: ; preds = %0
store i32 -1, i32* %1
br label %21
7: ; preds = %0
%8 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %2, i32 0, i32 0
%9 = load i64, i64* %8
%10 = load i64, i64* @SIG_DFL
%11 = icmp eq i64 %9, %10
br i1 %11, label %12, label %20
12: ; preds = %7
%13 = load i64, i64* @SIG_IGN
%14 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %2, i32 0, i32 0
store i64 %13, i64* %14
%15 = load i32, i32* @SIGPIPE
%16 = call i32 @sigaction(i32 %15, %struct.sigaction* %2, %struct.sigaction* null)
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %19
18: ; preds = %12
store i32 -1, i32* %1
br label %21
19: ; preds = %12
br label %20
20: ; preds = %19, %7
store i32 0, i32* %1
br label %21
21: ; preds = %20, %18, %6
%22 = load i32, i32* %1
ret i32 %22
}

LLVM IR (-O2):
%struct.sigaction = type { i64 }
@SIGPIPE = global i32 0
@SIG_DFL = global i64 0
@SIG_IGN = global i64 0
define i32 @u_ignore_sigpipe() {
%1 = alloca %struct.sigaction
%2 = bitcast %struct.sigaction* %1 to i8*
%3 = load i32, i32* @SIGPIPE
%4 = call i32 @sigaction(i32 %3, %struct.sigaction* null, %struct.sigaction* %1)
%5 = icmp eq i32 %4, -1
br i1 %5, label %17, label %6
6: ; preds = %0
%7 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %1, i64 0, i32 0
%8 = load i64, i64* %7
%9 = load i64, i64* @SIG_DFL
%10 = icmp eq i64 %8, %9
br i1 %10, label %11, label %16
11: ; preds = %6
%12 = load i64, i64* @SIG_IGN
store i64 %12, i64* %7
%13 = load i32, i32* @SIGPIPE
%14 = call i32 @sigaction(i32 %13, %struct.sigaction* %1, %struct.sigaction* null)
%15 = icmp eq i32 %14, -1
br i1 %15, label %17, label %16
16: ; preds = %11, %6
br label %17
17: ; preds = %11, %0, %16
%18 = phi i32 [ 0, %16 ], [ -1, %0 ], [ -1, %11 ]
ret i32 %18
}