#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 addrinfo {
  int /*<<< orphan*/ ai_addrlen;
  int /*<<< orphan*/ ai_addr;
};

/* Variables and functions */
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ SO_REUSEADDR;
int bind(int, int /*<<< orphan*/, int /*<<< orphan*/);
int setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/, int *, int);
int sockutil_cfg_bind_sock(int sock, struct addrinfo *arp) {
  int reuse_addr = 1;
  if (-1 ==
      setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &reuse_addr, sizeof(int))) {
    return -1;
  }
  return bind(sock, arp->ai_addr, arp->ai_addrlen);
}


x86 assembly (clang, -O0):
<sockutil_cfg_bind_sock>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x1,-0x14(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2ea8(%rip),%rax
mov    (%rax),%esi
mov    0x2e8f(%rip),%rax
mov    (%rax),%edx
lea    -0x14(%rbp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    %ecx,%eax
jne    1175 <sockutil_cfg_bind_sock+0x55>
movl   $0xffffffff,-0x4(%rbp)
jmp    118d <sockutil_cfg_bind_sock+0x6d>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%esi
mov    -0x10(%rbp),%rax
mov    (%rax),%edx
call   1040 <bind@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sockutil_cfg_bind_sock>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %edi,%ebx
movl   $0x1,0x4(%rsp)
mov    0x2eb0(%rip),%rax
mov    (%rax),%esi
mov    0x2e97(%rip),%rax
mov    (%rax),%edx
lea    0x4(%rsp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
cmp    $0xffffffff,%eax
je     1168 <sockutil_cfg_bind_sock+0x48>
mov    (%r14),%edx
mov    0x4(%r14),%esi
mov    %ebx,%edi
call   1040 <bind@plt>
jmp    116d <sockutil_cfg_bind_sock+0x4d>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.addrinfo = type { i32, i32 }
@SOL_SOCKET = global i32 0
@SO_REUSEADDR = global i32 0
define i32 @sockutil_cfg_bind_sock(i32 %0, %struct.addrinfo* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca %struct.addrinfo*
%6 = alloca i32
store i32 %0, i32* %4
store %struct.addrinfo* %1, %struct.addrinfo** %5
store i32 1, i32* %6
%7 = load i32, i32* %4
%8 = load i32, i32* @SOL_SOCKET
%9 = load i32, i32* @SO_REUSEADDR
%10 = call i32 @setsockopt(i32 %7, i32 %8, i32 %9, i32* %6, i32 4)
%11 = icmp eq i32 -1, %10
br i1 %11, label %12, label %13
12: ; preds = %2
store i32 -1, i32* %3
br label %22
13: ; preds = %2
%14 = load i32, i32* %4
%15 = load %struct.addrinfo*, %struct.addrinfo** %5
%16 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %15, i32 0, i32 1
%17 = load i32, i32* %16
%18 = load %struct.addrinfo*, %struct.addrinfo** %5
%19 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %18, i32 0, i32 0
%20 = load i32, i32* %19
%21 = call i32 @bind(i32 %14, i32 %17, i32 %20)
store i32 %21, i32* %3
br label %22
22: ; preds = %13, %12
%23 = load i32, i32* %3
ret i32 %23
}

LLVM IR (-O2):
%struct.addrinfo = type { i32, i32 }
@SOL_SOCKET = global i32 0
@SO_REUSEADDR = global i32 0
define i32 @sockutil_cfg_bind_sock(i32 %0, %struct.addrinfo* nocapture %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
store i32 1, i32* %3
%5 = load i32, i32* @SOL_SOCKET
%6 = load i32, i32* @SO_REUSEADDR
%7 = call i32 @setsockopt(i32 %0, i32 %5, i32 %6, i32* %3, i32 4)
%8 = icmp eq i32 %7, -1
br i1 %8, label %15, label %9
9: ; preds = %2
%10 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %1, i64 0, i32 1
%11 = load i32, i32* %10
%12 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %1, i64 0, i32 0
%13 = load i32, i32* %12
%14 = call i32 @bind(i32 %0, i32 %11, i32 %13)
br label %15
15: ; preds = %2, %9
%16 = phi i32 [ %14, %9 ], [ -1, %2 ]
ret i32 %16
}