#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 */
typedef struct TYPE_2__ TYPE_1__;

/* Type definitions */
typedef scalar_t__ uint16_t;
struct TYPE_2__ {
  void *s_addr;
};
struct sockaddr_in {
  TYPE_1__ sin_addr;
  void *sin_port;
  void *sin_family;
};
typedef int /*<<< orphan*/ saddr;
typedef int /*<<< orphan*/ daddr;

/* Variables and functions */
void *AF_INET;
int /*<<< orphan*/ INADDR_LOOPBACK;
int /*<<< orphan*/ PF_INET;
int /*<<< orphan*/ SOCK_DGRAM;
scalar_t__ bind(int, void *, int);
scalar_t__ connect(int, void *, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
void *htonl(int /*<<< orphan*/);
void *htons(scalar_t__);
int /*<<< orphan*/ memset(struct sockaddr_in *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
__attribute__((__unused__)) void pair_udp_open(int fds[], uint16_t port) {
  struct sockaddr_in saddr, daddr;
  fds[0] = socket(PF_INET, SOCK_DGRAM, 0);
  fds[1] = socket(PF_INET, SOCK_DGRAM, 0);
  if (fds[0] == -1 || fds[1] == -1) {
    fprintf(stderr, "ERROR: socket dgram\n");
    exit(1);
  }
  memset(&saddr, 0, sizeof(saddr));
  saddr.sin_family = AF_INET;
  saddr.sin_port = htons(port);
  saddr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
  memset(&daddr, 0, sizeof(daddr));
  daddr.sin_family = AF_INET;
  daddr.sin_port = htons(port + 1);
  daddr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
  if (bind(fds[1], (void *)&daddr, sizeof(daddr))) {
    perror("bind");
    exit(1);
  }
  if (bind(fds[0], (void *)&saddr, sizeof(saddr))) {
    perror("bind");
    exit(1);
  }
  if (connect(fds[0], (void *)&daddr, sizeof(daddr))) {
    perror("connect");
    exit(1);
  }
}


x86 assembly (clang, -O0):
<pair_udp_open>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e19(%rip),%rax
mov    (%rax),%edi
mov    0x2e30(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10b0 <socket@plt>
mov    %eax,%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,(%rax)
mov    0x2df8(%rip),%rax
mov    (%rax),%edi
mov    0x2e0f(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10b0 <socket@plt>
mov    %eax,%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,0x4(%rax)
mov    -0x8(%rbp),%rax
cmpl   $0xffffffff,(%rax)
je     11fe <pair_udp_open+0x6e>
mov    -0x8(%rbp),%rax
cmpl   $0xffffffff,0x4(%rax)
jne    121d <pair_udp_open+0x8d>
mov    0x2dc3(%rip),%rax
mov    (%rax),%edi
lea    0xdf2(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
lea    -0x28(%rbp),%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1050 <memset@plt>
mov    0x2db4(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <htons@plt>
mov    %rax,-0x20(%rbp)
mov    0x2d89(%rip),%rax
mov    (%rax),%edi
call   1040 <htonl@plt>
mov    %rax,-0x28(%rbp)
lea    -0x40(%rbp),%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1050 <memset@plt>
mov    0x2d77(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
add    $0x1,%rdi
call   1030 <htons@plt>
mov    %rax,-0x38(%rbp)
mov    0x2d48(%rip),%rax
mov    (%rax),%edi
call   1040 <htonl@plt>
mov    %rax,-0x40(%rbp)
mov    -0x8(%rbp),%rax
mov    0x4(%rax),%edi
lea    -0x40(%rbp),%rsi
mov    $0x18,%edx
call   1070 <bind@plt>
cmp    $0x0,%rax
je     12d0 <pair_udp_open+0x140>
lea    0xd54(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%edi
lea    -0x28(%rbp),%rsi
mov    $0x18,%edx
call   1070 <bind@plt>
cmp    $0x0,%rax
je     1304 <pair_udp_open+0x174>
lea    0xd20(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%edi
lea    -0x40(%rbp),%rsi
mov    $0x18,%edx
call   10a0 <connect@plt>
cmp    $0x0,%rax
je     1338 <pair_udp_open+0x1a8>
lea    0xcf1(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pair_udp_open>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x30,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
mov    0x2e16(%rip),%r15
mov    (%r15),%edi
mov    0x2e2c(%rip),%r12
mov    (%r12),%esi
xor    %edx,%edx
call   10b0 <socket@plt>
mov    %eax,(%rbx)
mov    (%r15),%edi
mov    (%r12),%esi
xor    %edx,%edx
call   10b0 <socket@plt>
mov    %eax,0x4(%rbx)
cmpl   $0xffffffff,(%rbx)
je     12b6 <pair_udp_open+0x126>
cmp    $0xffffffff,%eax
je     12b6 <pair_udp_open+0x126>
lea    0x18(%rsp),%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1050 <memset@plt>
mov    0x2dec(%rip),%r12
mov    (%r12),%rax
mov    %rax,0x28(%rsp)
mov    %r14,%rdi
call   1030 <htons@plt>
mov    %rax,0x20(%rsp)
mov    0x2dbf(%rip),%r13
mov    0x0(%r13),%edi
call   1040 <htonl@plt>
mov    %rax,0x18(%rsp)
mov    %rsp,%r15
mov    %r15,%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1050 <memset@plt>
mov    (%r12),%rax
mov    %rax,0x10(%rsp)
add    $0x1,%r14
mov    %r14,%rdi
call   1030 <htons@plt>
mov    %rax,0x8(%rsp)
mov    0x0(%r13),%edi
call   1040 <htonl@plt>
mov    %rax,(%rsp)
mov    0x4(%rbx),%edi
mov    %r15,%rsi
mov    $0x18,%edx
call   1070 <bind@plt>
test   %rax,%rax
jne    12ad <pair_udp_open+0x11d>
mov    (%rbx),%edi
lea    0x18(%rsp),%rsi
mov    $0x18,%edx
call   1070 <bind@plt>
test   %rax,%rax
jne    12ad <pair_udp_open+0x11d>
mov    (%rbx),%edi
mov    %rsp,%rsi
mov    $0x18,%edx
call   10a0 <connect@plt>
test   %rax,%rax
jne    12d5 <pair_udp_open+0x145>
add    $0x30,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret
lea    0xd61(%rip),%rdi
jmp    12dc <pair_udp_open+0x14c>
mov    0x2d0b(%rip),%rax
mov    (%rax),%edi
lea    0xd3a(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
lea    0xd3e(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { %struct.TYPE_2__, i8*, i8* }
%struct.TYPE_2__ = type { i8* }
@PF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@stderr = global i32 0
@.str = [21 x i8] c"ERROR: socket dgram\0A\00"
@AF_INET = global i8* null
@INADDR_LOOPBACK = global i32 0
@.str.1 = [5 x i8] c"bind\00"
@.str.2 = [8 x i8] c"connect\00"
define void @pair_udp_open(i32* %0, i64 %1) {
%3 = alloca i32*
%4 = alloca i64
%5 = alloca %struct.sockaddr_in
%6 = alloca %struct.sockaddr_in
store i32* %0, i32** %3
store i64 %1, i64* %4
%7 = load i32, i32* @PF_INET
%8 = load i32, i32* @SOCK_DGRAM
%9 = call i32 @socket(i32 %7, i32 %8, i32 0)
%10 = load i32*, i32** %3
%11 = getelementptr inbounds i32, i32* %10, i64 0
store i32 %9, i32* %11
%12 = load i32, i32* @PF_INET
%13 = load i32, i32* @SOCK_DGRAM
%14 = call i32 @socket(i32 %12, i32 %13, i32 0)
%15 = load i32*, i32** %3
%16 = getelementptr inbounds i32, i32* %15, i64 1
store i32 %14, i32* %16
%17 = load i32*, i32** %3
%18 = getelementptr inbounds i32, i32* %17, i64 0
%19 = load i32, i32* %18
%20 = icmp eq i32 %19, -1
br i1 %20, label %26, label %21
21: ; preds = %2
%22 = load i32*, i32** %3
%23 = getelementptr inbounds i32, i32* %22, i64 1
%24 = load i32, i32* %23
%25 = icmp eq i32 %24, -1
br i1 %25, label %26, label %30
26: ; preds = %21, %2
%27 = load i32, i32* @stderr
%28 = call i32 @fprintf(i32 %27, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
%29 = call i32 @exit(i32 1)
unreachable
30: ; preds = %21
%31 = call i32 @memset(%struct.sockaddr_in* %5, i32 0, i32 24)
%32 = load i8*, i8** @AF_INET
%33 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i32 0, i32 2
store i8* %32, i8** %33
%34 = load i64, i64* %4
%35 = call i8* @htons(i64 %34)
%36 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i32 0, i32 1
store i8* %35, i8** %36
%37 = load i32, i32* @INADDR_LOOPBACK
%38 = call i8* @htonl(i32 %37)
%39 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i32 0, i32 0
%40 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %39, i32 0, i32 0
store i8* %38, i8** %40
%41 = call i32 @memset(%struct.sockaddr_in* %6, i32 0, i32 24)
%42 = load i8*, i8** @AF_INET
%43 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 2
store i8* %42, i8** %43
%44 = load i64, i64* %4
%45 = add nsw i64 %44, 1
%46 = call i8* @htons(i64 %45)
%47 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 1
store i8* %46, i8** %47
%48 = load i32, i32* @INADDR_LOOPBACK
%49 = call i8* @htonl(i32 %48)
%50 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 0
%51 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %50, i32 0, i32 0
store i8* %49, i8** %51
%52 = load i32*, i32** %3
%53 = getelementptr inbounds i32, i32* %52, i64 1
%54 = load i32, i32* %53
%55 = bitcast %struct.sockaddr_in* %6 to i8*
%56 = call i64 @bind(i32 %54, i8* %55, i32 24)
%57 = icmp ne i64 %56, 0
br i1 %57, label %58, label %61
58: ; preds = %30
%59 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%60 = call i32 @exit(i32 1)
unreachable
61: ; preds = %30
%62 = load i32*, i32** %3
%63 = getelementptr inbounds i32, i32* %62, i64 0
%64 = load i32, i32* %63
%65 = bitcast %struct.sockaddr_in* %5 to i8*
%66 = call i64 @bind(i32 %64, i8* %65, i32 24)
%67 = icmp ne i64 %66, 0
br i1 %67, label %68, label %71
68: ; preds = %61
%69 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%70 = call i32 @exit(i32 1)
unreachable
71: ; preds = %61
%72 = load i32*, i32** %3
%73 = getelementptr inbounds i32, i32* %72, i64 0
%74 = load i32, i32* %73
%75 = bitcast %struct.sockaddr_in* %6 to i8*
%76 = call i64 @connect(i32 %74, i8* %75, i32 24)
%77 = icmp ne i64 %76, 0
br i1 %77, label %78, label %81
78: ; preds = %71
%79 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%80 = call i32 @exit(i32 1)
unreachable
81: ; preds = %71
ret void
}

LLVM IR (-O2):
%struct.sockaddr_in = type { %struct.TYPE_2__, i8*, i8* }
%struct.TYPE_2__ = type { i8* }
@PF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@stderr = global i32 0
@.str = [21 x i8] c"ERROR: socket dgram\0A\00"
@AF_INET = global i8* null
@INADDR_LOOPBACK = global i32 0
@.str.1 = [5 x i8] c"bind\00"
@.str.2 = [8 x i8] c"connect\00"
define void @pair_udp_open(i32* nocapture %0, i64 %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca %struct.sockaddr_in
%5 = bitcast %struct.sockaddr_in* %3 to i8*
%6 = bitcast %struct.sockaddr_in* %4 to i8*
%7 = load i32, i32* @PF_INET
%8 = load i32, i32* @SOCK_DGRAM
%9 = tail call i32 @socket(i32 %7, i32 %8, i32 0)
store i32 %9, i32* %0
%10 = load i32, i32* @PF_INET
%11 = load i32, i32* @SOCK_DGRAM
%12 = tail call i32 @socket(i32 %10, i32 %11, i32 0)
%13 = getelementptr inbounds i32, i32* %0, i64 1
store i32 %12, i32* %13
%14 = load i32, i32* %0
%15 = icmp eq i32 %14, -1
%16 = icmp eq i32 %12, -1
%17 = select i1 %15, i1 true, i1 %16
br i1 %17, label %18, label %22
18: ; preds = %2
%19 = load i32, i32* @stderr
%20 = tail call i32 @fprintf(i32 %19, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
%21 = tail call i32 @exit(i32 1)
unreachable
22: ; preds = %2
%23 = call i32 @memset(%struct.sockaddr_in* %3, i32 0, i32 24)
%24 = load i8*, i8** @AF_INET
%25 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i8* %24, i8** %25
%26 = call i8* @htons(i64 %1)
%27 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1
store i8* %26, i8** %27
%28 = load i32, i32* @INADDR_LOOPBACK
%29 = call i8* @htonl(i32 %28)
%30 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0, i32 0
store i8* %29, i8** %30
%31 = call i32 @memset(%struct.sockaddr_in* %4, i32 0, i32 24)
%32 = load i8*, i8** @AF_INET
%33 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 2
store i8* %32, i8** %33
%34 = add nsw i64 %1, 1
%35 = call i8* @htons(i64 %34)
%36 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 1
store i8* %35, i8** %36
%37 = load i32, i32* @INADDR_LOOPBACK
%38 = call i8* @htonl(i32 %37)
%39 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 0, i32 0
store i8* %38, i8** %39
%40 = load i32, i32* %13
%41 = call i64 @bind(i32 %40, i8* %6, i32 24)
%42 = icmp eq i64 %41, 0
br i1 %42, label %46, label %43
43: ; preds = %22
%44 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%45 = call i32 @exit(i32 1)
unreachable
46: ; preds = %22
%47 = load i32, i32* %0
%48 = call i64 @bind(i32 %47, i8* %5, i32 24)
%49 = icmp eq i64 %48, 0
br i1 %49, label %53, label %50
50: ; preds = %46
%51 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%52 = call i32 @exit(i32 1)
unreachable
53: ; preds = %46
%54 = load i32, i32* %0
%55 = call i64 @connect(i32 %54, i8* %6, i32 24)
%56 = icmp eq i64 %55, 0
br i1 %56, label %60, label %57
57: ; preds = %53
%58 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%59 = call i32 @exit(i32 1)
unreachable
60: ; preds = %53
ret void
}