#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 /*<<< orphan*/ perror(char *);
int setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/, int *, int);
int doBind(int socketDescriptor, struct addrinfo *servinfo) {
  int yes = 1;
  if (setsockopt(socketDescriptor, SOL_SOCKET, SO_REUSEADDR, &yes,
                 sizeof(int)) == -1) {
    perror("setsockopt");
    return -1;
  }
  if (bind(socketDescriptor, servinfo->ai_addr, servinfo->ai_addrlen) == -1) {
    perror("server: bind");
    return -1;
  }
  return 1;
}


x86 assembly (clang, -O0):
<doBind>:
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    0x2e98(%rip),%rax
mov    (%rax),%esi
mov    0x2e7f(%rip),%rax
mov    (%rax),%edx
lea    -0x14(%rbp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
cmp    $0xffffffff,%eax
jne    118b <doBind+0x5b>
lea    0xe86(%rip),%rdi
call   1050 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11c8 <doBind+0x98>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%esi
mov    -0x10(%rbp),%rax
mov    (%rax),%edx
call   1040 <bind@plt>
cmp    $0xffffffff,%eax
jne    11c1 <doBind+0x91>
lea    0xe5b(%rip),%rdi
call   1050 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11c8 <doBind+0x98>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<doBind>:
push   %rbp
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %edi,%ebp
movl   $0x1,0x4(%rsp)
mov    0x2ea1(%rip),%rax
mov    (%rax),%esi
mov    0x2e88(%rip),%rax
mov    (%rax),%edx
lea    0x4(%rsp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
cmp    $0xffffffff,%eax
je     1186 <doBind+0x56>
mov    (%rbx),%edx
mov    0x4(%rbx),%esi
mov    %ebp,%edi
call   1040 <bind@plt>
mov    %eax,%ecx
mov    $0x1,%eax
cmp    $0xffffffff,%ecx
je     118f <doBind+0x5f>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xe73(%rip),%rdi
jmp    1196 <doBind+0x66>
lea    0xe75(%rip),%rdi
call   1050 <perror@plt>
mov    $0xffffffff,%eax
jmp    117f <doBind+0x4f>

LLVM IR (-O0):
%struct.addrinfo = type { i32, i32 }
@SOL_SOCKET = global i32 0
@SO_REUSEADDR = global i32 0
@.str = [11 x i8] c"setsockopt\00"
@.str.1 = [13 x i8] c"server: bind\00"
define i32 @doBind(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 %10, -1
br i1 %11, label %12, label %14
12: ; preds = %2
%13 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %27
14: ; preds = %2
%15 = load i32, i32* %4
%16 = load %struct.addrinfo*, %struct.addrinfo** %5
%17 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %16, i32 0, i32 1
%18 = load i32, i32* %17
%19 = load %struct.addrinfo*, %struct.addrinfo** %5
%20 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %19, i32 0, i32 0
%21 = load i32, i32* %20
%22 = call i32 @bind(i32 %15, i32 %18, i32 %21)
%23 = icmp eq i32 %22, -1
br i1 %23, label %24, label %26
24: ; preds = %14
%25 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %3
br label %27
26: ; preds = %14
store i32 1, i32* %3
br label %27
27: ; preds = %26, %24, %12
%28 = load i32, i32* %3
ret i32 %28
}

LLVM IR (-O2):
%struct.addrinfo = type { i32, i32 }
@SOL_SOCKET = global i32 0
@SO_REUSEADDR = global i32 0
@.str = [11 x i8] c"setsockopt\00"
@.str.1 = [13 x i8] c"server: bind\00"
define i32 @doBind(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 %16, 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)
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %19
16: ; preds = %9, %2
%17 = phi i8* [ getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), %2 ], [ getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), %9 ]
%18 = call i32 @perror(i8* %17)
br label %19
19: ; preds = %16, %9
%20 = phi i32 [ 1, %9 ], [ -1, %16 ]
ret i32 %20
}