#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_protocol;
  int /*<<< orphan*/ ai_socktype;
  int /*<<< orphan*/ ai_family;
};

/* Variables and functions */
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ SO_REUSEADDR;
int /*<<< orphan*/ setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/,
                              int *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int __socket(struct addrinfo *info, int set_reuse_addr, int set_reuse_port) {
  int s;
  if ((s = socket(info->ai_family, info->ai_socktype, info->ai_protocol)) < 0)
    return (s);
  if (set_reuse_addr) {
    int yep = 1;
    setsockopt(s, SOL_SOCKET, SO_REUSEADDR, &yep, sizeof(int));
  }
  if (set_reuse_port) {
  }
  return (s);
}


x86 assembly (clang, -O0):
<__socket>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%esi
mov    -0x10(%rbp),%rax
mov    (%rax),%edx
call   1040 <socket@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
jge    1162 <__socket+0x42>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11ac <__socket+0x8c>
cmpl   $0x0,-0x14(%rbp)
je     1197 <__socket+0x77>
movl   $0x1,-0x20(%rbp)
mov    -0x1c(%rbp),%edi
mov    0x2e6b(%rip),%rax
mov    (%rax),%esi
mov    0x2e52(%rip),%rax
mov    (%rax),%edx
lea    -0x20(%rbp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
cmpl   $0x0,-0x18(%rbp)
je     11a6 <__socket+0x86>
jmp    11a6 <__socket+0x86>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<__socket>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
mov    0x8(%rdi),%eax
mov    (%rdi),%edx
mov    0x4(%rdi),%esi
mov    %eax,%edi
call   1040 <socket@plt>
mov    %eax,%ebx
test   %ebp,%ebp
je     116a <__socket+0x4a>
test   %ebx,%ebx
js     116a <__socket+0x4a>
movl   $0x1,0x4(%rsp)
mov    0x2e9b(%rip),%rax
mov    (%rax),%esi
mov    0x2e82(%rip),%rax
mov    (%rax),%edx
lea    0x4(%rsp),%rcx
mov    %ebx,%edi
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.addrinfo = type { i32, i32, i32 }
@SOL_SOCKET = global i32 0
@SO_REUSEADDR = global i32 0
define i32 @__socket(%struct.addrinfo* %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca %struct.addrinfo*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store %struct.addrinfo* %0, %struct.addrinfo** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
%10 = load %struct.addrinfo*, %struct.addrinfo** %5
%11 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %10, i32 0, i32 2
%12 = load i32, i32* %11
%13 = load %struct.addrinfo*, %struct.addrinfo** %5
%14 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %13, i32 0, i32 1
%15 = load i32, i32* %14
%16 = load %struct.addrinfo*, %struct.addrinfo** %5
%17 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %16, i32 0, i32 0
%18 = load i32, i32* %17
%19 = call i32 @socket(i32 %12, i32 %15, i32 %18)
store i32 %19, i32* %8
%20 = icmp slt i32 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %3
%22 = load i32, i32* %8
store i32 %22, i32* %4
br label %37
23: ; preds = %3
%24 = load i32, i32* %6
%25 = icmp ne i32 %24, 0
br i1 %25, label %26, label %31
26: ; preds = %23
store i32 1, i32* %9
%27 = load i32, i32* %8
%28 = load i32, i32* @SOL_SOCKET
%29 = load i32, i32* @SO_REUSEADDR
%30 = call i32 @setsockopt(i32 %27, i32 %28, i32 %29, i32* %9, i32 4)
br label %31
31: ; preds = %26, %23
%32 = load i32, i32* %7
%33 = icmp ne i32 %32, 0
br i1 %33, label %34, label %35
34: ; preds = %31
br label %35
35: ; preds = %34, %31
%36 = load i32, i32* %8
store i32 %36, i32* %4
br label %37
37: ; preds = %35, %21
%38 = load i32, i32* %4
ret i32 %38
}

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