#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 dummy;
};
struct addrinfo {
  int /*<<< orphan*/ ai_protocol;
  int /*<<< orphan*/ ai_socktype;
  int /*<<< orphan*/ ai_family;
};

/* Variables and functions */
int /*<<< orphan*/ IPPROTO_IP;
int /*<<< orphan*/ IPPROTO_TCP;
int /*<<< orphan*/ IP_TOS;
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ SO_PRIORITY;
int /*<<< orphan*/ SO_RCVBUF;
int /*<<< orphan*/ SO_REUSEADDR;
int /*<<< orphan*/ SO_SNDBUF;
int /*<<< orphan*/ TCP_MAXSEG;
int bind(int, struct sockaddr *, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ gettext(char *);
int /*<<< orphan*/ set_error(int /*<<< orphan*/, ...);
int set_no_delay(int);
int setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/, ...);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
int create_socket(struct sockaddr *bind_to, struct addrinfo *ai,
                  int recv_buffer_size, int tx_buffer_size, int max_mtu,
                  char use_no_delay, int priority, int tos) {
  int fd = -1;
  fd = socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol);
  if (fd == -1) {
    set_error(gettext("problem creating socket (%s)"), strerror(errno));
    return -4;
  }
  if (bind_to) {
    int set = 1;
    if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &set, sizeof set) == -1) {
      set_error(gettext("error setting sockopt to interface (%s)"),
                strerror(errno));
      close(fd);
      return -4;
    }
    if (bind(fd, bind_to, sizeof *bind_to) == -1) {
      set_error(gettext("error binding to interface (%s)"), strerror(errno));
      close(fd);
      return -4;
    }
  }
  if (max_mtu >= 0) {
    if (setsockopt(fd, IPPROTO_TCP, TCP_MAXSEG, &max_mtu, sizeof max_mtu) ==
        -1) {
      set_error(gettext("error setting MTU size (%s)"), strerror(errno));
      close(fd);
      return -4;
    }
  }
  if (use_no_delay) {
    int rc = -1;
    if ((rc = set_no_delay(fd)) != 0)
      return rc;
  }
  if (tx_buffer_size > 0) {
    if (setsockopt(fd, SOL_SOCKET, SO_SNDBUF, (char *)&tx_buffer_size,
                   sizeof tx_buffer_size) == -1) {
      set_error(gettext("error setting transmit buffer size (%s)"),
                strerror(errno));
      close(fd);
      return -4;
    }
  }
  if (recv_buffer_size > 0) {
    if (setsockopt(fd, SOL_SOCKET, SO_RCVBUF, (char *)&recv_buffer_size,
                   sizeof recv_buffer_size) == -1) {
      set_error(gettext("error setting receive buffer size (%s)"),
                strerror(errno));
      close(fd);
      return -4;
    }
  }
  if (priority >= 0) {
    if (setsockopt(fd, SOL_SOCKET, SO_PRIORITY, (char *)&priority,
                   sizeof priority) == -1) {
      set_error(gettext("error setting priority (%s)"), strerror(errno));
      close(fd);
      return -4;
    }
  }
  if (tos >= 0) {
    if (setsockopt(fd, IPPROTO_IP, IP_TOS, (char *)&tos, sizeof tos) == -1) {
      set_error(gettext("failed to set TOS info"));
      close(fd);
      return -4;
    }
  }
  return fd;
}


x86 assembly (clang, -O0):
<create_socket>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %r9b,%al
mov    0x18(%rbp),%r9d
mov    0x10(%rbp),%r9d
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %ecx,-0x20(%rbp)
mov    %r8d,-0x24(%rbp)
mov    %al,-0x25(%rbp)
movl   $0xffffffff,-0x2c(%rbp)
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%edi
mov    -0x18(%rbp),%rax
mov    0x4(%rax),%esi
mov    -0x18(%rbp),%rax
mov    (%rax),%edx
call   10a0 <socket@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0xffffffff,-0x2c(%rbp)
jne    120a <create_socket+0x8a>
lea    0xe24(%rip),%rdi
call   1040 <gettext@plt>
mov    %eax,-0x38(%rbp)
mov    0x2db5(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    -0x38(%rbp),%edi
mov    %eax,%esi
mov    $0x0,%al
call   1050 <set_error@plt>
movl   $0xfffffffc,-0x4(%rbp)
jmp    1572 <create_socket+0x3f2>
cmpq   $0x0,-0x10(%rbp)
je     12e4 <create_socket+0x164>
movl   $0x1,-0x30(%rbp)
mov    -0x2c(%rbp),%edi
mov    0x2dba(%rip),%rax
mov    (%rax),%esi
mov    0x2d69(%rip),%rax
mov    (%rax),%edx
lea    -0x30(%rbp),%rcx
mov    $0x4,%r8d
mov    $0x0,%al
call   1030 <setsockopt@plt>
cmp    $0xffffffff,%eax
jne    1288 <create_socket+0x108>
lea    0xdcb(%rip),%rdi
call   1040 <gettext@plt>
mov    %eax,-0x3c(%rbp)
mov    0x2d3f(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    -0x3c(%rbp),%edi
mov    %eax,%esi
mov    $0x0,%al
call   1050 <set_error@plt>
mov    -0x2c(%rbp),%edi
call   1060 <close@plt>
movl   $0xfffffffc,-0x4(%rbp)
jmp    1572 <create_socket+0x3f2>
mov    -0x2c(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    $0x4,%edx
call   1080 <bind@plt>
cmp    $0xffffffff,%eax
jne    12df <create_socket+0x15f>
lea    0xd9c(%rip),%rdi
call   1040 <gettext@plt>
mov    %eax,-0x40(%rbp)
mov    0x2ce8(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    -0x40(%rbp),%edi
mov    %eax,%esi
mov    $0x0,%al
call   1050 <set_error@plt>
mov    -0x2c(%rbp),%edi
call   1060 <close@plt>
movl   $0xfffffffc,-0x4(%rbp)
jmp    1572 <create_socket+0x3f2>
jmp    12e4 <create_socket+0x164>
cmpl   $0x0,-0x24(%rbp)
jl     135f <create_socket+0x1df>
mov    -0x2c(%rbp),%edi
mov    0x2cc8(%rip),%rax
mov    (%rax),%esi
mov    0x2cb7(%rip),%rax
mov    (%rax),%edx
lea    -0x24(%rbp),%rcx
mov    $0x4,%r8d
mov    $0x0,%al
call   1030 <setsockopt@plt>
cmp    $0xffffffff,%eax
jne    135a <create_socket+0x1da>
lea    0xd41(%rip),%rdi
call   1040 <gettext@plt>
mov    %eax,-0x44(%rbp)
mov    0x2c6d(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    -0x44(%rbp),%edi
mov    %eax,%esi
mov    $0x0,%al
call   1050 <set_error@plt>
mov    -0x2c(%rbp),%edi
call   1060 <close@plt>
movl   $0xfffffffc,-0x4(%rbp)
jmp    1572 <create_socket+0x3f2>
jmp    135f <create_socket+0x1df>
cmpb   $0x0,-0x25(%rbp)
je     1394 <create_socket+0x214>
movl   $0xffffffff,-0x34(%rbp)
mov    -0x2c(%rbp),%edi
call   1070 <set_no_delay@plt>
mov    %eax,-0x34(%rbp)
cmp    $0x0,%eax
je     138f <create_socket+0x20f>
mov    -0x34(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1572 <create_socket+0x3f2>
jmp    1394 <create_socket+0x214>
cmpl   $0x0,-0x20(%rbp)
jle    140f <create_socket+0x28f>
mov    -0x2c(%rbp),%edi
mov    0x2c38(%rip),%rax
mov    (%rax),%esi
mov    0x2c27(%rip),%rax
mov    (%rax),%edx
lea    -0x20(%rbp),%rcx
mov    $0x4,%r8d
mov    $0x0,%al
call   1030 <setsockopt@plt>
cmp    $0xffffffff,%eax
jne    140a <create_socket+0x28a>
lea    0xcad(%rip),%rdi
call   1040 <gettext@plt>
mov    %eax,-0x48(%rbp)
mov    0x2bbd(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    -0x48(%rbp),%edi
mov    %eax,%esi
mov    $0x0,%al
call   1050 <set_error@plt>
mov    -0x2c(%rbp),%edi
call   1060 <close@plt>
movl   $0xfffffffc,-0x4(%rbp)
jmp    1572 <create_socket+0x3f2>
jmp    140f <create_socket+0x28f>
cmpl   $0x0,-0x1c(%rbp)
jle    148a <create_socket+0x30a>
mov    -0x2c(%rbp),%edi
mov    0x2bbd(%rip),%rax
mov    (%rax),%esi
mov    0x2b7c(%rip),%rax
mov    (%rax),%edx
lea    -0x1c(%rbp),%rcx
mov    $0x4,%r8d
mov    $0x0,%al
call   1030 <setsockopt@plt>
cmp    $0xffffffff,%eax
jne    1485 <create_socket+0x305>
lea    0xc5a(%rip),%rdi
call   1040 <gettext@plt>
mov    %eax,-0x4c(%rbp)
mov    0x2b42(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    -0x4c(%rbp),%edi
mov    %eax,%esi
mov    $0x0,%al
call   1050 <set_error@plt>
mov    -0x2c(%rbp),%edi
call   1060 <close@plt>
movl   $0xfffffffc,-0x4(%rbp)
jmp    1572 <create_socket+0x3f2>
jmp    148a <create_socket+0x30a>
cmpl   $0x0,0x10(%rbp)
jl     1505 <create_socket+0x385>
mov    -0x2c(%rbp),%edi
mov    0x2b42(%rip),%rax
mov    (%rax),%esi
mov    0x2b49(%rip),%rax
mov    (%rax),%edx
lea    0x10(%rbp),%rcx
mov    $0x4,%r8d
mov    $0x0,%al
call   1030 <setsockopt@plt>
cmp    $0xffffffff,%eax
jne    1500 <create_socket+0x380>
lea    0xc06(%rip),%rdi
call   1040 <gettext@plt>
mov    %eax,-0x50(%rbp)
mov    0x2ac7(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    -0x50(%rbp),%edi
mov    %eax,%esi
mov    $0x0,%al
call   1050 <set_error@plt>
mov    -0x2c(%rbp),%edi
call   1060 <close@plt>
movl   $0xfffffffc,-0x4(%rbp)
jmp    1572 <create_socket+0x3f2>
jmp    1505 <create_socket+0x385>
cmpl   $0x0,0x18(%rbp)
jl     156c <create_socket+0x3ec>
mov    -0x2c(%rbp),%edi
mov    0x2ab7(%rip),%rax
mov    (%rax),%esi
mov    0x2aa6(%rip),%rax
mov    (%rax),%edx
lea    0x18(%rbp),%rcx
mov    $0x4,%r8d
mov    $0x0,%al
call   1030 <setsockopt@plt>
cmp    $0xffffffff,%eax
jne    1567 <create_socket+0x3e7>
lea    0xba7(%rip),%rdi
call   1040 <gettext@plt>
mov    %eax,%edi
mov    $0x0,%al
call   1050 <set_error@plt>
mov    -0x2c(%rbp),%edi
call   1060 <close@plt>
movl   $0xfffffffc,-0x4(%rbp)
jmp    1572 <create_socket+0x3f2>
jmp    156c <create_socket+0x3ec>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<create_socket>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r9d,%r15d
mov    %r8d,%ebp
mov    %ecx,%r13d
mov    %edx,%r12d
mov    %rdi,%rbx
mov    0x58(%rsp),%eax
mov    %eax,(%rsp)
mov    0x50(%rsp),%eax
mov    %eax,0x4(%rsp)
mov    %edx,0x14(%rsp)
mov    %ecx,0x10(%rsp)
mov    %r8d,0xc(%rsp)
mov    0x8(%rsi),%edi
mov    (%rsi),%edx
mov    0x4(%rsi),%esi
call   10a0 <socket@plt>
cmp    $0xffffffff,%eax
je     1350 <create_socket+0x1d0>
mov    %eax,%r14d
test   %rbx,%rbx
je     1228 <create_socket+0xa8>
movl   $0x1,0x8(%rsp)
mov    0x2dfa(%rip),%rax
mov    (%rax),%esi
mov    0x2da9(%rip),%rax
mov    (%rax),%edx
lea    0x8(%rsp),%rcx
mov    $0x4,%r8d
mov    %r14d,%edi
xor    %eax,%eax
call   1030 <setsockopt@plt>
cmp    $0xffffffff,%eax
je     1379 <create_socket+0x1f9>
mov    %r14d,%edi
mov    %rbx,%rsi
mov    $0x4,%edx
call   1080 <bind@plt>
cmp    $0xffffffff,%eax
je     1382 <create_socket+0x202>
test   %ebp,%ebp
js     125c <create_socket+0xdc>
mov    0x2d8d(%rip),%rax
mov    (%rax),%esi
mov    0x2d7c(%rip),%rax
mov    (%rax),%edx
lea    0xc(%rsp),%rcx
mov    $0x4,%r8d
mov    %r14d,%edi
xor    %eax,%eax
call   1030 <setsockopt@plt>
cmp    $0xffffffff,%eax
je     138b <create_socket+0x20b>
test   %r15b,%r15b
je     1271 <create_socket+0xf1>
mov    %r14d,%edi
call   1070 <set_no_delay@plt>
test   %eax,%eax
jne    13da <create_socket+0x25a>
test   %r13d,%r13d
jle    12a6 <create_socket+0x126>
mov    0x2d63(%rip),%rax
mov    (%rax),%esi
mov    0x2d52(%rip),%rax
mov    (%rax),%edx
lea    0x10(%rsp),%rcx
mov    $0x4,%r8d
mov    %r14d,%edi
xor    %eax,%eax
call   1030 <setsockopt@plt>
cmp    $0xffffffff,%eax
je     1394 <create_socket+0x214>
test   %r12d,%r12d
jle    12db <create_socket+0x15b>
mov    0x2d2e(%rip),%rax
mov    (%rax),%esi
mov    0x2ced(%rip),%rax
mov    (%rax),%edx
lea    0x14(%rsp),%rcx
mov    $0x4,%r8d
mov    %r14d,%edi
xor    %eax,%eax
call   1030 <setsockopt@plt>
cmp    $0xffffffff,%eax
je     139d <create_socket+0x21d>
cmpl   $0x0,0x4(%rsp)
js     1312 <create_socket+0x192>
mov    0x2cf7(%rip),%rax
mov    (%rax),%esi
mov    0x2cfe(%rip),%rax
mov    (%rax),%edx
lea    0x50(%rsp),%rcx
mov    $0x4,%r8d
mov    %r14d,%edi
xor    %eax,%eax
call   1030 <setsockopt@plt>
cmp    $0xffffffff,%eax
je     13a6 <create_socket+0x226>
cmpl   $0x0,(%rsp)
js     1348 <create_socket+0x1c8>
mov    0x2cb1(%rip),%rax
mov    (%rax),%esi
mov    0x2ca0(%rip),%rax
mov    (%rax),%edx
lea    0x58(%rsp),%rcx
mov    $0x4,%r8d
mov    %r14d,%edi
xor    %eax,%eax
call   1030 <setsockopt@plt>
cmp    $0xffffffff,%eax
je     13e9 <create_socket+0x269>
mov    %r14d,%eax
jmp    13da <create_socket+0x25a>
lea    0xca9(%rip),%rdi
call   1040 <gettext@plt>
mov    %eax,%ebx
mov    0x2c3b(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    %ebx,%edi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <set_error@plt>
jmp    13d5 <create_socket+0x255>
lea    0xc9d(%rip),%rdi
jmp    13ad <create_socket+0x22d>
lea    0xcbc(%rip),%rdi
jmp    13ad <create_socket+0x22d>
lea    0xcd3(%rip),%rdi
jmp    13ad <create_socket+0x22d>
lea    0xce6(%rip),%rdi
jmp    13ad <create_socket+0x22d>
lea    0xd05(%rip),%rdi
jmp    13ad <create_socket+0x22d>
lea    0xd23(%rip),%rdi
call   1040 <gettext@plt>
mov    %eax,%ebx
mov    0x2be5(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    %ebx,%edi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <set_error@plt>
mov    %r14d,%edi
call   1060 <close@plt>
mov    $0xfffffffc,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xcfc(%rip),%rdi
call   1040 <gettext@plt>
mov    %eax,%edi
xor    %eax,%eax
call   1050 <set_error@plt>
jmp    13cd <create_socket+0x24d>

LLVM IR (-O0):
%struct.sockaddr = type { i32 }
%struct.addrinfo = type { i32, i32, i32 }
@.str = [29 x i8] c"problem creating socket (%s)\00"
@errno = global i32 0
@SOL_SOCKET = global i32 0
@SO_REUSEADDR = global i32 0
@.str.1 = [40 x i8] c"error setting sockopt to interface (%s)\00"
@.str.2 = [32 x i8] c"error binding to interface (%s)\00"
@IPPROTO_TCP = global i32 0
@TCP_MAXSEG = global i32 0
@.str.3 = [28 x i8] c"error setting MTU size (%s)\00"
@SO_SNDBUF = global i32 0
@.str.4 = [40 x i8] c"error setting transmit buffer size (%s)\00"
@SO_RCVBUF = global i32 0
@.str.5 = [39 x i8] c"error setting receive buffer size (%s)\00"
@SO_PRIORITY = global i32 0
@.str.6 = [28 x i8] c"error setting priority (%s)\00"
@IPPROTO_IP = global i32 0
@IP_TOS = global i32 0
@.str.7 = [23 x i8] c"failed to set TOS info\00"
define i32 @create_socket(%struct.sockaddr* %0, %struct.addrinfo* %1, i32 %2, i32 %3, i32 %4, i8 signext %5, i32 %6, i32 %7) {
%9 = alloca i32
%10 = alloca %struct.sockaddr*
%11 = alloca %struct.addrinfo*
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i8
%16 = alloca i32
%17 = alloca i32
%18 = alloca i32
%19 = alloca i32
%20 = alloca i32
store %struct.sockaddr* %0, %struct.sockaddr** %10
store %struct.addrinfo* %1, %struct.addrinfo** %11
store i32 %2, i32* %12
store i32 %3, i32* %13
store i32 %4, i32* %14
store i8 %5, i8* %15
store i32 %6, i32* %16
store i32 %7, i32* %17
store i32 -1, i32* %18
%21 = load %struct.addrinfo*, %struct.addrinfo** %11
%22 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %21, i32 0, i32 2
%23 = load i32, i32* %22
%24 = load %struct.addrinfo*, %struct.addrinfo** %11
%25 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %24, i32 0, i32 1
%26 = load i32, i32* %25
%27 = load %struct.addrinfo*, %struct.addrinfo** %11
%28 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %27, i32 0, i32 0
%29 = load i32, i32* %28
%30 = call i32 @socket(i32 %23, i32 %26, i32 %29)
store i32 %30, i32* %18
%31 = load i32, i32* %18
%32 = icmp eq i32 %31, -1
br i1 %32, label %33, label %38
33: ; preds = %8
%34 = call i32 @gettext(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
%35 = load i32, i32* @errno
%36 = call i32 @strerror(i32 %35)
%37 = call i32 (i32, ...) @set_error(i32 %34, i32 %36)
store i32 -4, i32* %9
br label %166
38: ; preds = %8
%39 = load %struct.sockaddr*, %struct.sockaddr** %10
%40 = icmp ne %struct.sockaddr* %39, null
br i1 %40, label %41, label %67
41: ; preds = %38
store i32 1, i32* %19
%42 = load i32, i32* %18
%43 = load i32, i32* @SOL_SOCKET
%44 = load i32, i32* @SO_REUSEADDR
%45 = call i32 (i32, i32, i32, ...) @setsockopt(i32 %42, i32 %43, i32 %44, i32* %19, i64 4)
%46 = icmp eq i32 %45, -1
br i1 %46, label %47, label %54
47: ; preds = %41
%48 = call i32 @gettext(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0))
%49 = load i32, i32* @errno
%50 = call i32 @strerror(i32 %49)
%51 = call i32 (i32, ...) @set_error(i32 %48, i32 %50)
%52 = load i32, i32* %18
%53 = call i32 @close(i32 %52)
store i32 -4, i32* %9
br label %166
54: ; preds = %41
%55 = load i32, i32* %18
%56 = load %struct.sockaddr*, %struct.sockaddr** %10
%57 = call i32 @bind(i32 %55, %struct.sockaddr* %56, i32 4)
%58 = icmp eq i32 %57, -1
br i1 %58, label %59, label %66
59: ; preds = %54
%60 = call i32 @gettext(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0))
%61 = load i32, i32* @errno
%62 = call i32 @strerror(i32 %61)
%63 = call i32 (i32, ...) @set_error(i32 %60, i32 %62)
%64 = load i32, i32* %18
%65 = call i32 @close(i32 %64)
store i32 -4, i32* %9
br label %166
66: ; preds = %54
br label %67
67: ; preds = %66, %38
%68 = load i32, i32* %14
%69 = icmp sge i32 %68, 0
br i1 %69, label %70, label %84
70: ; preds = %67
%71 = load i32, i32* %18
%72 = load i32, i32* @IPPROTO_TCP
%73 = load i32, i32* @TCP_MAXSEG
%74 = call i32 (i32, i32, i32, ...) @setsockopt(i32 %71, i32 %72, i32 %73, i32* %14, i64 4)
%75 = icmp eq i32 %74, -1
br i1 %75, label %76, label %83
76: ; preds = %70
%77 = call i32 @gettext(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0))
%78 = load i32, i32* @errno
%79 = call i32 @strerror(i32 %78)
%80 = call i32 (i32, ...) @set_error(i32 %77, i32 %79)
%81 = load i32, i32* %18
%82 = call i32 @close(i32 %81)
store i32 -4, i32* %9
br label %166
83: ; preds = %70
br label %84
84: ; preds = %83, %67
%85 = load i8, i8* %15
%86 = icmp ne i8 %85, 0
br i1 %86, label %87, label %94
87: ; preds = %84
store i32 -1, i32* %20
%88 = load i32, i32* %18
%89 = call i32 @set_no_delay(i32 %88)
store i32 %89, i32* %20
%90 = icmp ne i32 %89, 0
br i1 %90, label %91, label %93
91: ; preds = %87
%92 = load i32, i32* %20
store i32 %92, i32* %9
br label %166
93: ; preds = %87
br label %94
94: ; preds = %93, %84
%95 = load i32, i32* %13
%96 = icmp sgt i32 %95, 0
br i1 %96, label %97, label %112
97: ; preds = %94
%98 = load i32, i32* %18
%99 = load i32, i32* @SOL_SOCKET
%100 = load i32, i32* @SO_SNDBUF
%101 = bitcast i32* %13 to i8*
%102 = call i32 (i32, i32, i32, ...) @setsockopt(i32 %98, i32 %99, i32 %100, i8* %101, i64 4)
%103 = icmp eq i32 %102, -1
br i1 %103, label %104, label %111
104: ; preds = %97
%105 = call i32 @gettext(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.4, i64 0, i64 0))
%106 = load i32, i32* @errno
%107 = call i32 @strerror(i32 %106)
%108 = call i32 (i32, ...) @set_error(i32 %105, i32 %107)
%109 = load i32, i32* %18
%110 = call i32 @close(i32 %109)
store i32 -4, i32* %9
br label %166
111: ; preds = %97
br label %112
112: ; preds = %111, %94
%113 = load i32, i32* %12
%114 = icmp sgt i32 %113, 0
br i1 %114, label %115, label %130
115: ; preds = %112
%116 = load i32, i32* %18
%117 = load i32, i32* @SOL_SOCKET
%118 = load i32, i32* @SO_RCVBUF
%119 = bitcast i32* %12 to i8*
%120 = call i32 (i32, i32, i32, ...) @setsockopt(i32 %116, i32 %117, i32 %118, i8* %119, i64 4)
%121 = icmp eq i32 %120, -1
br i1 %121, label %122, label %129
122: ; preds = %115
%123 = call i32 @gettext(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.5, i64 0, i64 0))
%124 = load i32, i32* @errno
%125 = call i32 @strerror(i32 %124)
%126 = call i32 (i32, ...) @set_error(i32 %123, i32 %125)
%127 = load i32, i32* %18
%128 = call i32 @close(i32 %127)
store i32 -4, i32* %9
br label %166
129: ; preds = %115
br label %130
130: ; preds = %129, %112
%131 = load i32, i32* %16
%132 = icmp sge i32 %131, 0
br i1 %132, label %133, label %148
133: ; preds = %130
%134 = load i32, i32* %18
%135 = load i32, i32* @SOL_SOCKET
%136 = load i32, i32* @SO_PRIORITY
%137 = bitcast i32* %16 to i8*
%138 = call i32 (i32, i32, i32, ...) @setsockopt(i32 %134, i32 %135, i32 %136, i8* %137, i64 4)
%139 = icmp eq i32 %138, -1
br i1 %139, label %140, label %147
140: ; preds = %133
%141 = call i32 @gettext(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.6, i64 0, i64 0))
%142 = load i32, i32* @errno
%143 = call i32 @strerror(i32 %142)
%144 = call i32 (i32, ...) @set_error(i32 %141, i32 %143)
%145 = load i32, i32* %18
%146 = call i32 @close(i32 %145)
store i32 -4, i32* %9
br label %166
147: ; preds = %133
br label %148
148: ; preds = %147, %130
%149 = load i32, i32* %17
%150 = icmp sge i32 %149, 0
br i1 %150, label %151, label %164
151: ; preds = %148
%152 = load i32, i32* %18
%153 = load i32, i32* @IPPROTO_IP
%154 = load i32, i32* @IP_TOS
%155 = bitcast i32* %17 to i8*
%156 = call i32 (i32, i32, i32, ...) @setsockopt(i32 %152, i32 %153, i32 %154, i8* %155, i64 4)
%157 = icmp eq i32 %156, -1
br i1 %157, label %158, label %163
158: ; preds = %151
%159 = call i32 @gettext(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.7, i64 0, i64 0))
%160 = call i32 (i32, ...) @set_error(i32 %159)
%161 = load i32, i32* %18
%162 = call i32 @close(i32 %161)
store i32 -4, i32* %9
br label %166
163: ; preds = %151
br label %164
164: ; preds = %163, %148
%165 = load i32, i32* %18
store i32 %165, i32* %9
br label %166
166: ; preds = %164, %158, %140, %122, %104, %91, %76, %59, %47, %33
%167 = load i32, i32* %9
ret i32 %167
}

LLVM IR (-O2):
%struct.sockaddr = type { i32 }
%struct.addrinfo = type { i32, i32, i32 }
@.str = [29 x i8] c"problem creating socket (%s)\00"
@errno = global i32 0
@SOL_SOCKET = global i32 0
@SO_REUSEADDR = global i32 0
@.str.1 = [40 x i8] c"error setting sockopt to interface (%s)\00"
@.str.2 = [32 x i8] c"error binding to interface (%s)\00"
@IPPROTO_TCP = global i32 0
@TCP_MAXSEG = global i32 0
@.str.3 = [28 x i8] c"error setting MTU size (%s)\00"
@SO_SNDBUF = global i32 0
@.str.4 = [40 x i8] c"error setting transmit buffer size (%s)\00"
@SO_RCVBUF = global i32 0
@.str.5 = [39 x i8] c"error setting receive buffer size (%s)\00"
@SO_PRIORITY = global i32 0
@.str.6 = [28 x i8] c"error setting priority (%s)\00"
@IPPROTO_IP = global i32 0
@IP_TOS = global i32 0
@.str.7 = [23 x i8] c"failed to set TOS info\00"
define i32 @create_socket(%struct.sockaddr* %0, %struct.addrinfo* nocapture %1, i32 %2, i32 %3, i32 %4, i8 signext %5, i32 %6, i32 %7) {
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
store i32 %2, i32* %9
store i32 %3, i32* %10
store i32 %4, i32* %11
store i32 %6, i32* %12
store i32 %7, i32* %13
%15 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %1, i64 0, i32 2
%16 = load i32, i32* %15
%17 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %1, i64 0, i32 1
%18 = load i32, i32* %17
%19 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %1, i64 0, i32 0
%20 = load i32, i32* %19
%21 = tail call i32 @socket(i32 %16, i32 %18, i32 %20)
%22 = icmp eq i32 %21, -1
br i1 %22, label %23, label %28
23: ; preds = %8
%24 = tail call i32 @gettext(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
%25 = load i32, i32* @errno
%26 = tail call i32 @strerror(i32 %25)
%27 = tail call i32 (i32, ...) @set_error(i32 %24, i32 %26)
br label %120
28: ; preds = %8
%29 = icmp eq %struct.sockaddr* %0, null
br i1 %29, label %52, label %30
30: ; preds = %28
%31 = bitcast i32* %14 to i8*
store i32 1, i32* %14
%32 = load i32, i32* @SOL_SOCKET
%33 = load i32, i32* @SO_REUSEADDR
%34 = call i32 (i32, i32, i32, ...) @setsockopt(i32 %21, i32 %32, i32 %33, i32* %14, i64 4)
%35 = icmp eq i32 %34, -1
br i1 %35, label %36, label %42
36: ; preds = %30
%37 = call i32 @gettext(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0))
%38 = load i32, i32* @errno
%39 = call i32 @strerror(i32 %38)
%40 = call i32 (i32, ...) @set_error(i32 %37, i32 %39)
%41 = call i32 @close(i32 %21)
br label %120
42: ; preds = %30
%43 = call i32 @bind(i32 %21, %struct.sockaddr* %0, i32 4)
%44 = icmp eq i32 %43, -1
br i1 %44, label %45, label %51
45: ; preds = %42
%46 = call i32 @gettext(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0))
%47 = load i32, i32* @errno
%48 = call i32 @strerror(i32 %47)
%49 = call i32 (i32, ...) @set_error(i32 %46, i32 %48)
%50 = call i32 @close(i32 %21)
br label %120
51: ; preds = %42
br label %52
52: ; preds = %51, %28
%53 = icmp sgt i32 %4, -1
br i1 %53, label %54, label %65
54: ; preds = %52
%55 = load i32, i32* @IPPROTO_TCP
%56 = load i32, i32* @TCP_MAXSEG
%57 = call i32 (i32, i32, i32, ...) @setsockopt(i32 %21, i32 %55, i32 %56, i32* %11, i64 4)
%58 = icmp eq i32 %57, -1
br i1 %58, label %59, label %65
59: ; preds = %54
%60 = call i32 @gettext(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0))
%61 = load i32, i32* @errno
%62 = call i32 @strerror(i32 %61)
%63 = call i32 (i32, ...) @set_error(i32 %60, i32 %62)
%64 = call i32 @close(i32 %21)
br label %120
65: ; preds = %54, %52
%66 = icmp eq i8 %5, 0
br i1 %66, label %70, label %67
67: ; preds = %65
%68 = call i32 @set_no_delay(i32 %21)
%69 = icmp eq i32 %68, 0
br i1 %69, label %70, label %120
70: ; preds = %67, %65
%71 = icmp sgt i32 %3, 0
br i1 %71, label %72, label %83
72: ; preds = %70
%73 = load i32, i32* @SOL_SOCKET
%74 = load i32, i32* @SO_SNDBUF
%75 = call i32 (i32, i32, i32, ...) @setsockopt(i32 %21, i32 %73, i32 %74, i32* %10, i64 4)
%76 = icmp eq i32 %75, -1
br i1 %76, label %77, label %83
77: ; preds = %72
%78 = call i32 @gettext(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.4, i64 0, i64 0))
%79 = load i32, i32* @errno
%80 = call i32 @strerror(i32 %79)
%81 = call i32 (i32, ...) @set_error(i32 %78, i32 %80)
%82 = call i32 @close(i32 %21)
br label %120
83: ; preds = %72, %70
%84 = icmp sgt i32 %2, 0
br i1 %84, label %85, label %96
85: ; preds = %83
%86 = load i32, i32* @SOL_SOCKET
%87 = load i32, i32* @SO_RCVBUF
%88 = call i32 (i32, i32, i32, ...) @setsockopt(i32 %21, i32 %86, i32 %87, i32* %9, i64 4)
%89 = icmp eq i32 %88, -1
br i1 %89, label %90, label %96
90: ; preds = %85
%91 = call i32 @gettext(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.5, i64 0, i64 0))
%92 = load i32, i32* @errno
%93 = call i32 @strerror(i32 %92)
%94 = call i32 (i32, ...) @set_error(i32 %91, i32 %93)
%95 = call i32 @close(i32 %21)
br label %120
96: ; preds = %85, %83
%97 = icmp sgt i32 %6, -1
br i1 %97, label %98, label %109
98: ; preds = %96
%99 = load i32, i32* @SOL_SOCKET
%100 = load i32, i32* @SO_PRIORITY
%101 = call i32 (i32, i32, i32, ...) @setsockopt(i32 %21, i32 %99, i32 %100, i32* %12, i64 4)
%102 = icmp eq i32 %101, -1
br i1 %102, label %103, label %109
103: ; preds = %98
%104 = call i32 @gettext(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.6, i64 0, i64 0))
%105 = load i32, i32* @errno
%106 = call i32 @strerror(i32 %105)
%107 = call i32 (i32, ...) @set_error(i32 %104, i32 %106)
%108 = call i32 @close(i32 %21)
br label %120
109: ; preds = %98, %96
%110 = icmp sgt i32 %7, -1
br i1 %110, label %111, label %120
111: ; preds = %109
%112 = load i32, i32* @IPPROTO_IP
%113 = load i32, i32* @IP_TOS
%114 = call i32 (i32, i32, i32, ...) @setsockopt(i32 %21, i32 %112, i32 %113, i32* %13, i64 4)
%115 = icmp eq i32 %114, -1
br i1 %115, label %116, label %120
116: ; preds = %111
%117 = call i32 @gettext(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.7, i64 0, i64 0))
%118 = call i32 (i32, ...) @set_error(i32 %117)
%119 = call i32 @close(i32 %21)
br label %120
120: ; preds = %109, %111, %36, %45, %67, %116, %103, %90, %77, %59, %23
%121 = phi i32 [ -4, %23 ], [ -4, %59 ], [ -4, %77 ], [ -4, %90 ], [ -4, %103 ], [ -4, %116 ], [ %68, %67 ], [ -4, %45 ], [ -4, %36 ], [ %21, %111 ], [ %21, %109 ]
ret i32 %121
}