#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 */

/* Variables and functions */
int /*<<< orphan*/ ETH_P_IP;
int /*<<< orphan*/ PF_PACKET;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ htons(int /*<<< orphan*/);
char *init_packetsock_ring(int, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int init_packetsock(char **ring, int ringtype) {
  int fd;
  fd = socket(PF_PACKET, SOCK_DGRAM, htons(ETH_P_IP));
  if (fd < 0)
    do {
      fprintf(stderr, "Root priliveges are required\nsocket() rx. \n");
      return -1;
    } while (0);
  ;
  if (ring) {
    *ring = init_packetsock_ring(fd, ringtype);
    if (!*ring) {
      close(fd);
      return -1;
    }
  }
  return fd;
}


x86 assembly (clang, -O0):
<init_packetsock>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    0x2e8a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    0x2e6e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    0x2e4a(%rip),%rax
mov    (%rax),%edi
call   1030 <htons@plt>
mov    -0x20(%rbp),%edi
mov    -0x1c(%rbp),%esi
mov    %eax,%edx
call   1070 <socket@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    11c5 <init_packetsock+0x75>
jmp    11a4 <init_packetsock+0x54>
mov    0x2e25(%rip),%rax
mov    (%rax),%edi
lea    0xe4c(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1212 <init_packetsock+0xc2>
cmpq   $0x0,-0x10(%rbp)
je     120c <init_packetsock+0xbc>
mov    -0x18(%rbp),%edi
mov    -0x14(%rbp),%esi
call   1060 <init_packetsock_ring@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x10(%rbp),%rax
cmpq   $0x0,(%rax)
jne    1207 <init_packetsock+0xb7>
mov    -0x18(%rbp),%edi
call   1040 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1212 <init_packetsock+0xc2>
jmp    120c <init_packetsock+0xbc>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<init_packetsock>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%r14d
mov    %rdi,%r15
mov    0x2e8c(%rip),%rax
mov    (%rax),%ebp
mov    0x2e73(%rip),%rax
mov    (%rax),%ebx
mov    0x2e52(%rip),%rax
mov    (%rax),%edi
call   1030 <htons@plt>
mov    %ebp,%edi
mov    %ebx,%esi
mov    %eax,%edx
call   1070 <socket@plt>
test   %eax,%eax
js     11ae <init_packetsock+0x5e>
mov    %eax,%ebp
test   %r15,%r15
je     11c8 <init_packetsock+0x78>
mov    %ebp,%edi
mov    %r14d,%esi
call   1060 <init_packetsock_ring@plt>
mov    %rax,(%r15)
test   %rax,%rax
jne    11c8 <init_packetsock+0x78>
mov    %ebp,%edi
call   1040 <close@plt>
jmp    11c3 <init_packetsock+0x73>
mov    0x2e1b(%rip),%rax
mov    (%rax),%edi
lea    0xe42(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@PF_PACKET = global i32 0
@SOCK_DGRAM = global i32 0
@ETH_P_IP = global i32 0
@stderr = global i32 0
@.str = [44 x i8] c"Root priliveges are required\0Asocket() rx. \0A\00"
define i32 @init_packetsock(i8** %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i32
%6 = alloca i32
store i8** %0, i8*** %4
store i32 %1, i32* %5
%7 = load i32, i32* @PF_PACKET
%8 = load i32, i32* @SOCK_DGRAM
%9 = load i32, i32* @ETH_P_IP
%10 = call i32 @htons(i32 %9)
%11 = call i32 @socket(i32 %7, i32 %8, i32 %10)
store i32 %11, i32* %6
%12 = load i32, i32* %6
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %19
14: ; preds = %2
br label %15
15: ; preds = %14
%16 = load i32, i32* @stderr
%17 = call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %36
18: ; No predecessors!
br label %19
19: ; preds = %18, %2
%20 = load i8**, i8*** %4
%21 = icmp ne i8** %20, null
br i1 %21, label %22, label %34
22: ; preds = %19
%23 = load i32, i32* %6
%24 = load i32, i32* %5
%25 = call i8* @init_packetsock_ring(i32 %23, i32 %24)
%26 = load i8**, i8*** %4
store i8* %25, i8** %26
%27 = load i8**, i8*** %4
%28 = load i8*, i8** %27
%29 = icmp ne i8* %28, null
br i1 %29, label %33, label %30
30: ; preds = %22
%31 = load i32, i32* %6
%32 = call i32 @close(i32 %31)
store i32 -1, i32* %3
br label %36
33: ; preds = %22
br label %34
34: ; preds = %33, %19
%35 = load i32, i32* %6
store i32 %35, i32* %3
br label %36
36: ; preds = %34, %30, %15
%37 = load i32, i32* %3
ret i32 %37
}

LLVM IR (-O2):
@PF_PACKET = global i32 0
@SOCK_DGRAM = global i32 0
@ETH_P_IP = global i32 0
@stderr = global i32 0
@.str = [44 x i8] c"Root priliveges are required\0Asocket() rx. \0A\00"
define i32 @init_packetsock(i8** writeonly %0, i32 %1) {
%3 = load i32, i32* @PF_PACKET
%4 = load i32, i32* @SOCK_DGRAM
%5 = load i32, i32* @ETH_P_IP
%6 = tail call i32 @htons(i32 %5)
%7 = tail call i32 @socket(i32 %3, i32 %4, i32 %6)
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %12
9: ; preds = %2
%10 = load i32, i32* @stderr
%11 = tail call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0))
br label %19
12: ; preds = %2
%13 = icmp eq i8** %0, null
br i1 %13, label %19, label %14
14: ; preds = %12
%15 = tail call i8* @init_packetsock_ring(i32 %7, i32 %1)
store i8* %15, i8** %0
%16 = icmp eq i8* %15, null
br i1 %16, label %17, label %19
17: ; preds = %14
%18 = tail call i32 @close(i32 %7)
br label %19
19: ; preds = %12, %14, %17, %9
%20 = phi i32 [ -1, %9 ], [ -1, %17 ], [ %7, %14 ], [ %7, %12 ]
ret i32 %20
}