#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 /*<<< orphan*/ logSysExit(char *);
scalar_t__ setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/, int *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
void openRawSocket(int *s, u_short type) {
  int optval = 1;
  if ((*s = socket(AF_INET, SOCK_PACKET, htons(type))) < 0) {
    logSysExit("socket (openRawSocket)");
  }
  if (setsockopt(*s, SOL_SOCKET, SO_BROADCAST, &optval, sizeof(optval)) < 0) {
    logSysExit("setsockopt (openRawSocket)");
  }
}


x86 assembly (clang, -O0):
<openRawSocket>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x1,-0x10(%rbp)
mov    0x2e7b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    0x2e77(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    -0xc(%rbp),%edi
call   1050 <htons@plt>
mov    -0x18(%rbp),%edi
mov    -0x14(%rbp),%esi
mov    %eax,%edx
call   1060 <socket@plt>
mov    -0x8(%rbp),%rcx
mov    %eax,(%rcx)
cmp    $0x0,%eax
jge    119e <openRawSocket+0x5e>
lea    0xe67(%rip),%rdi
call   1040 <logSysExit@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%edi
mov    0x2e3d(%rip),%rax
mov    (%rax),%esi
mov    0x2e1c(%rip),%rax
mov    (%rax),%edx
lea    -0x10(%rbp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
cmp    $0x0,%rax
jge    11db <openRawSocket+0x9b>
lea    0xe41(%rip),%rdi
call   1040 <logSysExit@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<openRawSocket>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%r14
movl   $0x1,0xc(%rsp)
mov    0x2e7e(%rip),%rax
mov    (%rax),%ebp
mov    0x2e7d(%rip),%rax
mov    (%rax),%ebx
mov    %esi,%edi
call   1050 <htons@plt>
mov    %ebp,%edi
mov    %ebx,%esi
mov    %eax,%edx
call   1060 <socket@plt>
mov    %eax,(%r14)
test   %eax,%eax
jns    118d <openRawSocket+0x4d>
lea    0xe7b(%rip),%rdi
call   1040 <logSysExit@plt>
mov    (%r14),%eax
mov    0x2e54(%rip),%rcx
mov    (%rcx),%esi
mov    0x2e33(%rip),%rcx
mov    (%rcx),%edx
lea    0xc(%rsp),%rcx
mov    %eax,%edi
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
test   %rax,%rax
jns    11c2 <openRawSocket+0x82>
lea    0xe5a(%rip),%rdi
call   1040 <logSysExit@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@AF_INET = global i32 0
@SOCK_PACKET = global i32 0
@.str = [23 x i8] c"socket (openRawSocket)\00"
@SOL_SOCKET = global i32 0
@SO_BROADCAST = global i32 0
@.str.1 = [27 x i8] c"setsockopt (openRawSocket)\00"
define void @openRawSocket(i32* %0, i32 %1) {
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
store i32* %0, i32** %3
store i32 %1, i32* %4
store i32 1, i32* %5
%6 = load i32, i32* @AF_INET
%7 = load i32, i32* @SOCK_PACKET
%8 = load i32, i32* %4
%9 = call i32 @htons(i32 %8)
%10 = call i32 @socket(i32 %6, i32 %7, i32 %9)
%11 = load i32*, i32** %3
store i32 %10, i32* %11
%12 = icmp slt i32 %10, 0
br i1 %12, label %13, label %15
13: ; preds = %2
%14 = call i32 @logSysExit(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
br label %15
15: ; preds = %13, %2
%16 = load i32*, i32** %3
%17 = load i32, i32* %16
%18 = load i32, i32* @SOL_SOCKET
%19 = load i32, i32* @SO_BROADCAST
%20 = call i64 @setsockopt(i32 %17, i32 %18, i32 %19, i32* %5, i32 4)
%21 = icmp slt i64 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %15
%23 = call i32 @logSysExit(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
br label %24
24: ; preds = %22, %15
ret void
}

LLVM IR (-O2):
@AF_INET = global i32 0
@SOCK_PACKET = global i32 0
@.str = [23 x i8] c"socket (openRawSocket)\00"
@SOL_SOCKET = global i32 0
@SO_BROADCAST = global i32 0
@.str.1 = [27 x i8] c"setsockopt (openRawSocket)\00"
define void @openRawSocket(i32* nocapture %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 slt i32 %8, 0
br i1 %9, label %10, label %13
10: ; preds = %2
%11 = tail call i32 @logSysExit(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%12 = load i32, i32* %0
br label %13
13: ; preds = %10, %2
%14 = phi i32 [ %12, %10 ], [ %8, %2 ]
%15 = load i32, i32* @SOL_SOCKET
%16 = load i32, i32* @SO_BROADCAST
%17 = call i64 @setsockopt(i32 %14, i32 %15, i32 %16, i32* %3, i32 4)
%18 = icmp slt i64 %17, 0
br i1 %18, label %19, label %21
19: ; preds = %13
%20 = call i32 @logSysExit(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
br label %21
21: ; preds = %19, %13
ret void
}