#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*/ u_short;
typedef int /*<<< orphan*/ optval;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SOCK_PACKET;
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ SO_BROADCAST;
int /*<<< orphan*/ htons(int /*<<< orphan*/);
int setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/, int *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int llip_openRawSocket(int *s, u_short type) {
  int optval = 1;
  if ((*s = socket(AF_INET, SOCK_PACKET, htons(type))) == -1) {
    return -1;
  }
  if (setsockopt(*s, SOL_SOCKET, SO_BROADCAST, &optval, sizeof(optval)) == -1) {
    return -1;
  }
}


x86 assembly (clang, -O0):
<llip_openRawSocket>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
movl   $0x1,-0x18(%rbp)
mov    0x2e8b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    0x2e87(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x14(%rbp),%edi
call   1040 <htons@plt>
mov    -0x20(%rbp),%edi
mov    -0x1c(%rbp),%esi
mov    %eax,%edx
call   1050 <socket@plt>
mov    -0x10(%rbp),%rcx
mov    %eax,(%rcx)
cmp    $0xffffffff,%eax
jne    118e <llip_openRawSocket+0x5e>
movl   $0xffffffff,-0x4(%rbp)
jmp    11c5 <llip_openRawSocket+0x95>
mov    -0x10(%rbp),%rax
mov    (%rax),%edi
mov    0x2e4d(%rip),%rax
mov    (%rax),%esi
mov    0x2e2c(%rip),%rax
mov    (%rax),%edx
lea    -0x18(%rbp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
cmp    $0xffffffff,%eax
jne    11c5 <llip_openRawSocket+0x95>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<llip_openRawSocket>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%r14
movl   $0x1,0xc(%rsp)
mov    0x2e8e(%rip),%rax
mov    (%rax),%ebp
mov    0x2e8d(%rip),%rax
mov    (%rax),%ebx
mov    %esi,%edi
call   1040 <htons@plt>
mov    %ebp,%edi
mov    %ebx,%esi
mov    %eax,%edx
call   1050 <socket@plt>
mov    %eax,(%r14)
cmp    $0xffffffff,%eax
je     1193 <llip_openRawSocket+0x63>
mov    0x2e72(%rip),%rcx
mov    (%rcx),%esi
mov    0x2e51(%rip),%rcx
mov    (%rcx),%edx
lea    0xc(%rsp),%rcx
mov    %eax,%edi
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
mov    $0xffffffff,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@AF_INET = global i32 0
@SOCK_PACKET = global i32 0
@SOL_SOCKET = global i32 0
@SO_BROADCAST = global i32 0
define i32 @llip_openRawSocket(i32* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
store i32* %0, i32** %4
store i32 %1, i32* %5
store i32 1, i32* %6
%7 = load i32, i32* @AF_INET
%8 = load i32, i32* @SOCK_PACKET
%9 = load i32, i32* %5
%10 = call i32 @htons(i32 %9)
%11 = call i32 @socket(i32 %7, i32 %8, i32 %10)
%12 = load i32*, i32** %4
store i32 %11, i32* %12
%13 = icmp eq i32 %11, -1
br i1 %13, label %14, label %15
14: ; preds = %2
store i32 -1, i32* %3
br label %23
15: ; preds = %2
%16 = load i32*, i32** %4
%17 = load i32, i32* %16
%18 = load i32, i32* @SOL_SOCKET
%19 = load i32, i32* @SO_BROADCAST
%20 = call i32 @setsockopt(i32 %17, i32 %18, i32 %19, i32* %6, i32 4)
%21 = icmp eq i32 %20, -1
br i1 %21, label %22, label %23
22: ; preds = %15
store i32 -1, i32* %3
br label %23
23: ; preds = %14, %22, %15
%24 = load i32, i32* %3
ret i32 %24
}

LLVM IR (-O2):
@AF_INET = global i32 0
@SOCK_PACKET = global i32 0
@SOL_SOCKET = global i32 0
@SO_BROADCAST = global i32 0
define i32 @llip_openRawSocket(i32* nocapture writeonly %0, i32 %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
store i32 1, i32* %3
%5 = load i32, i32* @AF_INET
%6 = load i32, i32* @SOCK_PACKET
%7 = tail call i32 @htons(i32 %1)
%8 = tail call i32 @socket(i32 %5, i32 %6, i32 %7)
store i32 %8, i32* %0
%9 = icmp eq i32 %8, -1
br i1 %9, label %14, label %10
10: ; preds = %2
%11 = load i32, i32* @SOL_SOCKET
%12 = load i32, i32* @SO_BROADCAST
%13 = call i32 @setsockopt(i32 %8, i32 %11, i32 %12, i32* %3, i32 4)
br label %14
14: ; preds = %10, %2
ret i32 -1
}