#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 */

/* Variables and functions */
int /*<<< orphan*/ SHUT_WR;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ err(int, char *, char const *);
int /*<<< orphan*/ errx(int, char *, char const *);
int /*<<< orphan*/ got_signal();
scalar_t__ shutdown(int, int /*<<< orphan*/);
int /*<<< orphan*/ signal_setup(char const *);
int /*<<< orphan*/ test_send(char const *, int);
void test_send_wantsignal(const char *testname, int sock1, int sock2) {
  if (shutdown(sock2, SHUT_WR) < 0)
    err(-1, "%s: shutdown", testname);
  signal_setup(testname);
  test_send(testname, sock2);
  if (!got_signal())
    errx(-1, "%s: send: didn't receive SIGPIPE", testname);
  close(sock1);
  close(sock2);
}


x86 assembly (clang, -O0):
<test_send_wantsignal>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    -0x10(%rbp),%edi
mov    0x2e5c(%rip),%rax
mov    (%rax),%esi
call   1050 <shutdown@plt>
cmp    $0x0,%rax
jge    11b2 <test_send_wantsignal+0x42>
mov    -0x8(%rbp),%rdx
mov    $0xffffffff,%edi
lea    0xe53(%rip),%rsi
call   1080 <err@plt>
mov    -0x8(%rbp),%rdi
call   1090 <signal_setup@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%esi
call   1040 <test_send@plt>
mov    $0x0,%al
call   1030 <got_signal@plt>
cmp    $0x0,%eax
jne    11ec <test_send_wantsignal+0x7c>
mov    -0x8(%rbp),%rdx
mov    $0xffffffff,%edi
lea    0xe26(%rip),%rsi
call   1060 <errx@plt>
mov    -0xc(%rbp),%edi
call   1070 <close@plt>
mov    -0x10(%rbp),%edi
call   1070 <close@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_send_wantsignal>:
push   %rbp
push   %r14
push   %rbx
mov    %edx,%ebx
mov    %esi,%r14d
mov    %rdi,%rbp
mov    0x2e65(%rip),%rax
mov    (%rax),%esi
mov    %edx,%edi
call   1050 <shutdown@plt>
test   %rax,%rax
jns    11a5 <test_send_wantsignal+0x35>
lea    0xe68(%rip),%rsi
mov    $0xffffffff,%edi
mov    %rbp,%rdx
call   1080 <err@plt>
mov    %rbp,%rdi
call   1090 <signal_setup@plt>
mov    %rbp,%rdi
mov    %ebx,%esi
call   1040 <test_send@plt>
xor    %eax,%eax
call   1030 <got_signal@plt>
test   %eax,%eax
jne    11d6 <test_send_wantsignal+0x66>
lea    0xe44(%rip),%rsi
mov    $0xffffffff,%edi
mov    %rbp,%rdx
call   1060 <errx@plt>
mov    %r14d,%edi
call   1070 <close@plt>
mov    %ebx,%edi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1070 <close@plt>

LLVM IR (-O0):
@SHUT_WR = global i32 0
@.str = [13 x i8] c"%s: shutdown\00"
@.str.1 = [33 x i8] c"%s: send: didn't receive SIGPIPE\00"
define void @test_send_wantsignal(i8* %0, i32 %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%7 = load i32, i32* %6
%8 = load i32, i32* @SHUT_WR
%9 = call i64 @shutdown(i32 %7, i32 %8)
%10 = icmp slt i64 %9, 0
br i1 %10, label %11, label %14
11: ; preds = %3
%12 = load i8*, i8** %4
%13 = call i32 @err(i32 -1, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* %12)
br label %14
14: ; preds = %11, %3
%15 = load i8*, i8** %4
%16 = call i32 @signal_setup(i8* %15)
%17 = load i8*, i8** %4
%18 = load i32, i32* %6
%19 = call i32 @test_send(i8* %17, i32 %18)
%20 = call i32 (...) @got_signal()
%21 = icmp ne i32 %20, 0
br i1 %21, label %25, label %22
22: ; preds = %14
%23 = load i8*, i8** %4
%24 = call i32 @errx(i32 -1, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0), i8* %23)
br label %25
25: ; preds = %22, %14
%26 = load i32, i32* %5
%27 = call i32 @close(i32 %26)
%28 = load i32, i32* %6
%29 = call i32 @close(i32 %28)
ret void
}

LLVM IR (-O2):
@SHUT_WR = global i32 0
@.str = [13 x i8] c"%s: shutdown\00"
@.str.1 = [33 x i8] c"%s: send: didn't receive SIGPIPE\00"
define void @test_send_wantsignal(i8* %0, i32 %1, i32 %2) {
%4 = load i32, i32* @SHUT_WR
%5 = tail call i64 @shutdown(i32 %2, i32 %4)
%6 = icmp slt i64 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %3
%8 = tail call i32 @err(i32 -1, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %9
9: ; preds = %7, %3
%10 = tail call i32 @signal_setup(i8* %0)
%11 = tail call i32 @test_send(i8* %0, i32 %2)
%12 = tail call i32 (...) @got_signal()
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %9
%15 = tail call i32 @errx(i32 -1, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %16
16: ; preds = %14, %9
%17 = tail call i32 @close(i32 %1)
%18 = tail call i32 @close(i32 %2)
ret void
}