#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 sockaddr {
  int /*<<< orphan*/ sa_family;
};
typedef int /*<<< orphan*/ socklen_t;

/* Variables and functions */
int /*<<< orphan*/ SOCK_DGRAM;
scalar_t__ connect(int, struct sockaddr *, int /*<<< orphan*/);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ error(int, int /*<<< orphan*/, char *);
int /*<<< orphan*/ setsockopt_txtime(int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int setup_tx(struct sockaddr *addr, socklen_t alen) {
  int fd;
  fd = socket(addr->sa_family, SOCK_DGRAM, 0);
  if (fd == -1)
    error(1, errno, "socket t");
  if (connect(fd, addr, alen))
    error(1, errno, "connect");
  setsockopt_txtime(fd);
  return fd;
}


x86 assembly (clang, -O0):
<setup_tx>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%edi
mov    0x2e8c(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1060 <socket@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0xffffffff,-0x10(%rbp)
jne    118c <setup_tx+0x4c>
mov    0x2e5f(%rip),%rax
mov    (%rax),%esi
mov    $0x1,%edi
lea    0xe79(%rip),%rdx
call   1040 <error@plt>
mov    -0x10(%rbp),%edi
mov    -0x8(%rbp),%rsi
mov    -0xc(%rbp),%edx
call   1050 <connect@plt>
cmp    $0x0,%rax
je     11bf <setup_tx+0x7f>
mov    0x2e2c(%rip),%rax
mov    (%rax),%esi
mov    $0x1,%edi
lea    0xe4f(%rip),%rdx
call   1040 <error@plt>
mov    -0x10(%rbp),%edi
call   1030 <setsockopt_txtime@plt>
mov    -0x10(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<setup_tx>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%r14d
mov    %rdi,%rbp
mov    (%rdi),%edi
mov    0x2e95(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1060 <socket@plt>
mov    %eax,%ebx
cmp    $0xffffffff,%eax
jne    117d <setup_tx+0x3d>
mov    0x2e6e(%rip),%rax
mov    (%rax),%esi
lea    0xe8d(%rip),%rdx
mov    $0x1,%edi
call   1040 <error@plt>
mov    %ebx,%edi
mov    %rbp,%rsi
mov    %r14d,%edx
call   1050 <connect@plt>
test   %rax,%rax
je     11a9 <setup_tx+0x69>
mov    0x2e42(%rip),%rax
mov    (%rax),%esi
lea    0xe6a(%rip),%rdx
mov    $0x1,%edi
call   1040 <error@plt>
mov    %ebx,%edi
call   1030 <setsockopt_txtime@plt>
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr = type { i32 }
@SOCK_DGRAM = global i32 0
@errno = global i32 0
@.str = [9 x i8] c"socket t\00"
@.str.1 = [8 x i8] c"connect\00"
define i32 @setup_tx(%struct.sockaddr* %0, i32 %1) {
%3 = alloca %struct.sockaddr*
%4 = alloca i32
%5 = alloca i32
store %struct.sockaddr* %0, %struct.sockaddr** %3
store i32 %1, i32* %4
%6 = load %struct.sockaddr*, %struct.sockaddr** %3
%7 = getelementptr inbounds %struct.sockaddr, %struct.sockaddr* %6, i32 0, i32 0
%8 = load i32, i32* %7
%9 = load i32, i32* @SOCK_DGRAM
%10 = call i32 @socket(i32 %8, i32 %9, i32 0)
store i32 %10, i32* %5
%11 = load i32, i32* %5
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %16
13: ; preds = %2
%14 = load i32, i32* @errno
%15 = call i32 @error(i32 1, i32 %14, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
br label %16
16: ; preds = %13, %2
%17 = load i32, i32* %5
%18 = load %struct.sockaddr*, %struct.sockaddr** %3
%19 = load i32, i32* %4
%20 = call i64 @connect(i32 %17, %struct.sockaddr* %18, i32 %19)
%21 = icmp ne i64 %20, 0
br i1 %21, label %22, label %25
22: ; preds = %16
%23 = load i32, i32* @errno
%24 = call i32 @error(i32 1, i32 %23, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
br label %25
25: ; preds = %22, %16
%26 = load i32, i32* %5
%27 = call i32 @setsockopt_txtime(i32 %26)
%28 = load i32, i32* %5
ret i32 %28
}

LLVM IR (-O2):
%struct.sockaddr = type { i32 }
@SOCK_DGRAM = global i32 0
@errno = global i32 0
@.str = [9 x i8] c"socket t\00"
@.str.1 = [8 x i8] c"connect\00"
define i32 @setup_tx(%struct.sockaddr* %0, i32 %1) {
%3 = getelementptr inbounds %struct.sockaddr, %struct.sockaddr* %0, i64 0, i32 0
%4 = load i32, i32* %3
%5 = load i32, i32* @SOCK_DGRAM
%6 = tail call i32 @socket(i32 %4, i32 %5, i32 0)
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %11
8: ; preds = %2
%9 = load i32, i32* @errno
%10 = tail call i32 @error(i32 1, i32 %9, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
br label %11
11: ; preds = %8, %2
%12 = tail call i64 @connect(i32 %6, %struct.sockaddr* %0, i32 %1)
%13 = icmp eq i64 %12, 0
br i1 %13, label %17, label %14
14: ; preds = %11
%15 = load i32, i32* @errno
%16 = tail call i32 @error(i32 1, i32 %15, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
br label %17
17: ; preds = %14, %11
%18 = tail call i32 @setsockopt_txtime(i32 %6)
ret i32 %6
}