#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*/ PF_LOCAL;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ err(int, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
scalar_t__ socketpair(int /*<<< orphan*/, int /*<<< orphan*/,
                      int /*<<< orphan*/, int *);
int /*<<< orphan*/ stderr;
long strtol(char *, char **, int);
int /*<<< orphan*/ tcp_pair(long, int *);
int /*<<< orphan*/ tcp_setup(long);
int /*<<< orphan*/ tcp_teardown();
int /*<<< orphan*/ test_send_wantsignal(char *, int, int);
int /*<<< orphan*/ test_write_wantsignal(char *, int, int);
int /*<<< orphan*/ usage();
int /*<<< orphan*/ warnx(char *);
int main(int argc, char *argv[]) {
  char *dummy;
  int sock[2];
  long port;
  if (argc != 2)
    usage();
  port = strtol(argv[1], &dummy, 10);
  if (port < 0 || port > 65535 || *dummy != '\0')
    usage();
  warnx("sigpipe: SO_NOSIGPIPE not defined, skipping some tests");
  if (socketpair(PF_LOCAL, SOCK_STREAM, 0, sock) < 0)
    err(-1, "socketpair(PF_LOCAL, SOCK_STREAM)");
  test_send_wantsignal("test_send_wantsignal(PF_LOCAL)", sock[0], sock[1]);
  if (socketpair(PF_LOCAL, SOCK_STREAM, 0, sock) < 0)
    err(-1, "socketpair(PF_LOCAL, SOCK_STREAM)");
  test_write_wantsignal("test_write_wantsignal(PF_LOCAL)", sock[0], sock[1]);
  tcp_setup(port);
  tcp_pair(port, sock);
  test_send_wantsignal("test_send_wantsignal(PF_INET)", sock[0], sock[1]);
  tcp_pair(port, sock);
  test_write_wantsignal("test_write_wantsignal(PF_INET)", sock[0], sock[1]);
  tcp_teardown();
  fprintf(stderr, "PASS\n");
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11d7 <main+0x27>
mov    $0x0,%al
call   10b0 <usage@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x18(%rbp),%rsi
mov    $0xa,%edx
call   1060 <strtol@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jl     121a <main+0x6a>
cmpq   $0xffff,-0x28(%rbp)
jg     121a <main+0x6a>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1221 <main+0x71>
mov    $0x0,%al
call   10b0 <usage@plt>
lea    0xdd8(%rip),%rdi
call   1030 <warnx@plt>
mov    0x2d9c(%rip),%rax
mov    (%rax),%edi
mov    0x2d9b(%rip),%rax
mov    (%rax),%esi
lea    -0x20(%rbp),%rcx
xor    %edx,%edx
call   1070 <socketpair@plt>
cmp    $0x0,%rax
jge    1265 <main+0xb5>
mov    $0xffffffff,%edi
lea    0xdd7(%rip),%rsi
call   1090 <err@plt>
mov    -0x20(%rbp),%esi
mov    -0x1c(%rbp),%edx
lea    0xde7(%rip),%rdi
call   10a0 <test_send_wantsignal@plt>
mov    0x2d52(%rip),%rax
mov    (%rax),%edi
mov    0x2d51(%rip),%rax
mov    (%rax),%esi
lea    -0x20(%rbp),%rcx
xor    %edx,%edx
call   1070 <socketpair@plt>
cmp    $0x0,%rax
jge    12af <main+0xff>
mov    $0xffffffff,%edi
lea    0xd8d(%rip),%rsi
call   1090 <err@plt>
mov    -0x20(%rbp),%esi
mov    -0x1c(%rbp),%edx
lea    0xdbc(%rip),%rdi
call   1080 <test_write_wantsignal@plt>
mov    -0x28(%rbp),%rdi
call   1040 <tcp_setup@plt>
mov    -0x28(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   10d0 <tcp_pair@plt>
mov    -0x20(%rbp),%esi
mov    -0x1c(%rbp),%edx
lea    0xdb4(%rip),%rdi
call   10a0 <test_send_wantsignal@plt>
mov    -0x28(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   10d0 <tcp_pair@plt>
mov    -0x20(%rbp),%esi
mov    -0x1c(%rbp),%edx
lea    0xdb3(%rip),%rdi
call   1080 <test_write_wantsignal@plt>
mov    $0x0,%al
call   10c0 <tcp_teardown@plt>
mov    0x2cca(%rip),%rax
mov    (%rax),%edi
lea    0xdb6(%rip),%rsi
call   1050 <fprintf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
cmp    $0x2,%edi
je     11c8 <main+0x18>
xor    %eax,%eax
call   10b0 <usage@plt>
mov    0x8(%rbx),%rdi
lea    0x8(%rsp),%rsi
mov    $0xa,%edx
call   1060 <strtol@plt>
mov    %rax,%rbx
cmp    $0xffff,%rax
ja     11f0 <main+0x40>
mov    0x8(%rsp),%rax
cmpb   $0x0,(%rax)
je     11f7 <main+0x47>
xor    %eax,%eax
call   10b0 <usage@plt>
lea    0xe02(%rip),%rdi
call   1030 <warnx@plt>
mov    0x2dc6(%rip),%r14
mov    (%r14),%edi
mov    0x2dc4(%rip),%r15
mov    (%r15),%esi
mov    %rsp,%rcx
xor    %edx,%edx
call   1070 <socketpair@plt>
test   %rax,%rax
jns    1237 <main+0x87>
lea    0xe0a(%rip),%rsi
mov    $0xffffffff,%edi
call   1090 <err@plt>
mov    (%rsp),%esi
mov    0x4(%rsp),%edx
lea    0xe14(%rip),%rdi
call   10a0 <test_send_wantsignal@plt>
mov    (%r14),%edi
mov    (%r15),%esi
mov    %rsp,%rcx
xor    %edx,%edx
call   1070 <socketpair@plt>
test   %rax,%rax
jns    1270 <main+0xc0>
lea    0xdd1(%rip),%rsi
mov    $0xffffffff,%edi
call   1090 <err@plt>
mov    (%rsp),%esi
mov    0x4(%rsp),%edx
lea    0xdfa(%rip),%rdi
call   1080 <test_write_wantsignal@plt>
mov    %rbx,%rdi
call   1040 <tcp_setup@plt>
mov    %rsp,%r14
mov    %rbx,%rdi
mov    %r14,%rsi
call   10d0 <tcp_pair@plt>
mov    (%rsp),%esi
mov    0x4(%rsp),%edx
lea    0xdf1(%rip),%rdi
call   10a0 <test_send_wantsignal@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   10d0 <tcp_pair@plt>
mov    (%rsp),%esi
mov    0x4(%rsp),%edx
lea    0xdf1(%rip),%rdi
call   1080 <test_write_wantsignal@plt>
xor    %eax,%eax
call   10c0 <tcp_teardown@plt>
mov    0x2d08(%rip),%rax
mov    (%rax),%edi
lea    0xdf4(%rip),%rsi
call   1050 <fprintf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [55 x i8] c"sigpipe: SO_NOSIGPIPE not defined, skipping some tests\00"
@PF_LOCAL = global i32 0
@SOCK_STREAM = global i32 0
@.str.1 = [34 x i8] c"socketpair(PF_LOCAL, SOCK_STREAM)\00"
@.str.2 = [31 x i8] c"test_send_wantsignal(PF_LOCAL)\00"
@.str.3 = [32 x i8] c"test_write_wantsignal(PF_LOCAL)\00"
@.str.4 = [30 x i8] c"test_send_wantsignal(PF_INET)\00"
@.str.5 = [31 x i8] c"test_write_wantsignal(PF_INET)\00"
@stderr = global i32 0
@.str.6 = [6 x i8] c"PASS\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca [2 x i32]
%8 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp ne i32 %9, 2
br i1 %10, label %11, label %13
11: ; preds = %2
%12 = call i32 (...) @usage()
br label %13
13: ; preds = %11, %2
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 1
%16 = load i8*, i8** %15
%17 = call i64 @strtol(i8* %16, i8** %6, i32 10)
store i64 %17, i64* %8
%18 = load i64, i64* %8
%19 = icmp slt i64 %18, 0
br i1 %19, label %28, label %20
20: ; preds = %13
%21 = load i64, i64* %8
%22 = icmp sgt i64 %21, 65535
br i1 %22, label %28, label %23
23: ; preds = %20
%24 = load i8*, i8** %6
%25 = load i8, i8* %24
%26 = sext i8 %25 to i32
%27 = icmp ne i32 %26, 0
br i1 %27, label %28, label %30
28: ; preds = %23, %20, %13
%29 = call i32 (...) @usage()
br label %30
30: ; preds = %28, %23
%31 = call i32 @warnx(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str, i64 0, i64 0))
%32 = load i32, i32* @PF_LOCAL
%33 = load i32, i32* @SOCK_STREAM
%34 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 0
%35 = call i64 @socketpair(i32 %32, i32 %33, i32 0, i32* %34)
%36 = icmp slt i64 %35, 0
br i1 %36, label %37, label %39
37: ; preds = %30
%38 = call i32 @err(i32 -1, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0))
br label %39
39: ; preds = %37, %30
%40 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 0
%41 = load i32, i32* %40
%42 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 1
%43 = load i32, i32* %42
%44 = call i32 @test_send_wantsignal(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), i32 %41, i32 %43)
%45 = load i32, i32* @PF_LOCAL
%46 = load i32, i32* @SOCK_STREAM
%47 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 0
%48 = call i64 @socketpair(i32 %45, i32 %46, i32 0, i32* %47)
%49 = icmp slt i64 %48, 0
br i1 %49, label %50, label %52
50: ; preds = %39
%51 = call i32 @err(i32 -1, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0))
br label %52
52: ; preds = %50, %39
%53 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 0
%54 = load i32, i32* %53
%55 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 1
%56 = load i32, i32* %55
%57 = call i32 @test_write_wantsignal(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0), i32 %54, i32 %56)
%58 = load i64, i64* %8
%59 = call i32 @tcp_setup(i64 %58)
%60 = load i64, i64* %8
%61 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 0
%62 = call i32 @tcp_pair(i64 %60, i32* %61)
%63 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 0
%64 = load i32, i32* %63
%65 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 1
%66 = load i32, i32* %65
%67 = call i32 @test_send_wantsignal(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.4, i64 0, i64 0), i32 %64, i32 %66)
%68 = load i64, i64* %8
%69 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 0
%70 = call i32 @tcp_pair(i64 %68, i32* %69)
%71 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 0
%72 = load i32, i32* %71
%73 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 1
%74 = load i32, i32* %73
%75 = call i32 @test_write_wantsignal(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.5, i64 0, i64 0), i32 %72, i32 %74)
%76 = call i32 (...) @tcp_teardown()
%77 = load i32, i32* @stderr
%78 = call i32 @fprintf(i32 %77, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str = [55 x i8] c"sigpipe: SO_NOSIGPIPE not defined, skipping some tests\00"
@PF_LOCAL = global i32 0
@SOCK_STREAM = global i32 0
@.str.1 = [34 x i8] c"socketpair(PF_LOCAL, SOCK_STREAM)\00"
@.str.2 = [31 x i8] c"test_send_wantsignal(PF_LOCAL)\00"
@.str.3 = [32 x i8] c"test_write_wantsignal(PF_LOCAL)\00"
@.str.4 = [30 x i8] c"test_send_wantsignal(PF_INET)\00"
@.str.5 = [31 x i8] c"test_write_wantsignal(PF_INET)\00"
@stderr = global i32 0
@.str.6 = [6 x i8] c"PASS\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i8*
%4 = alloca [2 x i32]
%5 = bitcast i8** %3 to i8*
%6 = bitcast [2 x i32]* %4 to i8*
%7 = icmp eq i32 %0, 2
br i1 %7, label %10, label %8
8: ; preds = %2
%9 = tail call i32 (...) @usage()
br label %10
10: ; preds = %8, %2
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = call i64 @strtol(i8* %12, i8** %3, i32 10)
%14 = icmp ugt i64 %13, 65535
br i1 %14, label %19, label %15
15: ; preds = %10
%16 = load i8*, i8** %3
%17 = load i8, i8* %16
%18 = icmp eq i8 %17, 0
br i1 %18, label %21, label %19
19: ; preds = %15, %10
%20 = tail call i32 (...) @usage()
br label %21
21: ; preds = %19, %15
%22 = tail call i32 @warnx(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str, i64 0, i64 0))
%23 = load i32, i32* @PF_LOCAL
%24 = load i32, i32* @SOCK_STREAM
%25 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 0
%26 = call i64 @socketpair(i32 %23, i32 %24, i32 0, i32* %25)
%27 = icmp slt i64 %26, 0
br i1 %27, label %28, label %30
28: ; preds = %21
%29 = call i32 @err(i32 -1, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0))
br label %30
30: ; preds = %28, %21
%31 = load i32, i32* %25
%32 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 1
%33 = load i32, i32* %32
%34 = call i32 @test_send_wantsignal(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), i32 %31, i32 %33)
%35 = load i32, i32* @PF_LOCAL
%36 = load i32, i32* @SOCK_STREAM
%37 = call i64 @socketpair(i32 %35, i32 %36, i32 0, i32* %25)
%38 = icmp slt i64 %37, 0
br i1 %38, label %39, label %41
39: ; preds = %30
%40 = call i32 @err(i32 -1, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0))
br label %41
41: ; preds = %39, %30
%42 = load i32, i32* %25
%43 = load i32, i32* %32
%44 = call i32 @test_write_wantsignal(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0), i32 %42, i32 %43)
%45 = call i32 @tcp_setup(i64 %13)
%46 = call i32 @tcp_pair(i64 %13, i32* %25)
%47 = load i32, i32* %25
%48 = load i32, i32* %32
%49 = call i32 @test_send_wantsignal(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.4, i64 0, i64 0), i32 %47, i32 %48)
%50 = call i32 @tcp_pair(i64 %13, i32* %25)
%51 = load i32, i32* %25
%52 = load i32, i32* %32
%53 = call i32 @test_write_wantsignal(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.5, i64 0, i64 0), i32 %51, i32 %52)
%54 = call i32 (...) @tcp_teardown()
%55 = load i32, i32* @stderr
%56 = call i32 @fprintf(i32 %55, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0))
ret i32 0
}