#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 */
typedef int /*<<< orphan*/ val;
struct sockaddr_in {
  int dummy;
};
struct sockaddr {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ SO_REUSEADDR;
int bind(int, struct sockaddr *, int);
int setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/, char *, int);
int BasSockUdpOpenPassive(int sock, const struct sockaddr_in *local) {
  int val;
  int res;
  val = 1;
  res = setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (char *)&val, sizeof(val));
  res = bind(sock, (struct sockaddr *)local, sizeof(*local));
  if (res)
    return -1;
  return 0;
}


x86 assembly (clang, -O0):
<BasSockUdpOpenPassive>:
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,-0x18(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    $0x4,%edx
call   1040 <bind@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
je     1187 <BasSockUdpOpenPassive+0x67>
movl   $0xffffffff,-0x4(%rbp)
jmp    118e <BasSockUdpOpenPassive+0x6e>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<BasSockUdpOpenPassive>:
push   %rbp
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %edi,%ebp
movl   $0x1,0x4(%rsp)
mov    0x2eb1(%rip),%rax
mov    (%rax),%esi
mov    0x2e98(%rip),%rax
mov    (%rax),%edx
lea    0x4(%rsp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x4,%edx
call   1040 <bind@plt>
neg    %eax
sbb    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

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

LLVM IR (-O2):
%struct.sockaddr_in = type { i32 }
%struct.sockaddr = type { i32 }
@SOL_SOCKET = global i32 0
@SO_REUSEADDR = global i32 0
define i32 @BasSockUdpOpenPassive(i32 %0, %struct.sockaddr_in* %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, i8* %4, i32 4)
%8 = bitcast %struct.sockaddr_in* %1 to %struct.sockaddr*
%9 = call i32 @bind(i32 %0, %struct.sockaddr* %8, i32 4)
%10 = icmp ne i32 %9, 0
%11 = sext i1 %10 to i32
ret i32 %11
}