#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 test {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ EPERM;
int /*<<< orphan*/ PF_INET;
int /*<<< orphan*/ SOCK_RAW;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ expect(char *, int, int, int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
void priv_netinet_raw(int asroot, int injail, struct test *test) {
  int error, fd;
  fd = socket(PF_INET, SOCK_RAW, 0);
  if (fd < 0)
    error = -1;
  else
    error = 0;
  if (asroot && injail)
    expect("priv_netinet_raw(asroot, injail)", error, -1, EPERM);
  if (asroot && !injail)
    expect("priv_netinet_raw(asroot, !injail)", error, 0, 0);
  if (!asroot && injail)
    expect("priv_netinet_raw(!asroot, injail)", error, -1, EPERM);
  if (!asroot && !injail)
    expect("priv_netinet_raw(!asroot, !injail)", error, -1, EPERM);
  if (fd >= 0)
    (void)close(fd);
}


x86 assembly (clang, -O0):
<priv_netinet_raw>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
mov    0x2e8f(%rip),%rax
mov    (%rax),%edi
mov    0x2e96(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1050 <socket@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    1174 <priv_netinet_raw+0x44>
movl   $0xffffffff,-0x14(%rbp)
jmp    117b <priv_netinet_raw+0x4b>
movl   $0x0,-0x14(%rbp)
cmpl   $0x0,-0x4(%rbp)
je     11ac <priv_netinet_raw+0x7c>
cmpl   $0x0,-0x8(%rbp)
je     11ac <priv_netinet_raw+0x7c>
mov    -0x14(%rbp),%esi
mov    0x2e2f(%rip),%rax
mov    (%rax),%ecx
lea    0xe5e(%rip),%rdi
mov    $0xffffffff,%edx
call   1030 <expect@plt>
cmpl   $0x0,-0x4(%rbp)
je     11d3 <priv_netinet_raw+0xa3>
cmpl   $0x0,-0x8(%rbp)
jne    11d3 <priv_netinet_raw+0xa3>
mov    -0x14(%rbp),%esi
lea    0xe57(%rip),%rdi
xor    %ecx,%ecx
mov    %ecx,%edx
call   1030 <expect@plt>
cmpl   $0x0,-0x4(%rbp)
jne    1204 <priv_netinet_raw+0xd4>
cmpl   $0x0,-0x8(%rbp)
je     1204 <priv_netinet_raw+0xd4>
mov    -0x14(%rbp),%esi
mov    0x2dd7(%rip),%rax
mov    (%rax),%ecx
lea    0xe49(%rip),%rdi
mov    $0xffffffff,%edx
call   1030 <expect@plt>
cmpl   $0x0,-0x4(%rbp)
jne    1235 <priv_netinet_raw+0x105>
cmpl   $0x0,-0x8(%rbp)
jne    1235 <priv_netinet_raw+0x105>
mov    -0x14(%rbp),%esi
mov    0x2da6(%rip),%rax
mov    (%rax),%ecx
lea    0xe3a(%rip),%rdi
mov    $0xffffffff,%edx
call   1030 <expect@plt>
cmpl   $0x0,-0x18(%rbp)
jl     1247 <priv_netinet_raw+0x117>
mov    -0x18(%rbp),%edi
call   1040 <close@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<priv_netinet_raw>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %edi,%ebx
mov    0x2e96(%rip),%rax
mov    (%rax),%edi
mov    0x2e9d(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1050 <socket@plt>
mov    %eax,%r14d
mov    %eax,%r15d
sar    $0x1f,%r15d
test   %ebx,%ebx
je     1183 <priv_netinet_raw+0x53>
test   %ebp,%ebp
je     1183 <priv_netinet_raw+0x53>
mov    0x2e5b(%rip),%rax
mov    (%rax),%ecx
lea    0xe8a(%rip),%rdi
mov    %r15d,%esi
mov    $0xffffffff,%edx
call   1030 <expect@plt>
test   %ebx,%ebx
je     119e <priv_netinet_raw+0x6e>
test   %ebp,%ebp
jne    119e <priv_netinet_raw+0x6e>
lea    0xe8f(%rip),%rdi
mov    %r15d,%esi
xor    %edx,%edx
xor    %ecx,%ecx
call   1030 <expect@plt>
test   %ebx,%ebx
jne    11c3 <priv_netinet_raw+0x93>
test   %ebp,%ebp
je     11c3 <priv_netinet_raw+0x93>
mov    0x2e1b(%rip),%rax
mov    (%rax),%ecx
lea    0xe8d(%rip),%rdi
mov    %r15d,%esi
mov    $0xffffffff,%edx
call   1030 <expect@plt>
or     %ebx,%ebp
je     11de <priv_netinet_raw+0xae>
test   %r14d,%r14d
js     1200 <priv_netinet_raw+0xd0>
mov    %r14d,%edi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <close@plt>
mov    0x2de3(%rip),%rax
mov    (%rax),%ecx
lea    0xe77(%rip),%rdi
mov    %r15d,%esi
mov    $0xffffffff,%edx
call   1030 <expect@plt>
test   %r14d,%r14d
jns    11cc <priv_netinet_raw+0x9c>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.test = type { i32 }
@PF_INET = global i32 0
@SOCK_RAW = global i32 0
@.str = [33 x i8] c"priv_netinet_raw(asroot, injail)\00"
@EPERM = global i32 0
@.str.1 = [34 x i8] c"priv_netinet_raw(asroot, !injail)\00"
@.str.2 = [34 x i8] c"priv_netinet_raw(!asroot, injail)\00"
@.str.3 = [35 x i8] c"priv_netinet_raw(!asroot, !injail)\00"
define void @priv_netinet_raw(i32 %0, i32 %1, %struct.test* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca %struct.test*
%7 = alloca i32
%8 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
store %struct.test* %2, %struct.test** %6
%9 = load i32, i32* @PF_INET
%10 = load i32, i32* @SOCK_RAW
%11 = call i32 @socket(i32 %9, i32 %10, i32 0)
store i32 %11, i32* %8
%12 = load i32, i32* %8
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %15
14: ; preds = %3
store i32 -1, i32* %7
br label %16
15: ; preds = %3
store i32 0, i32* %7
br label %16
16: ; preds = %15, %14
%17 = load i32, i32* %4
%18 = icmp ne i32 %17, 0
br i1 %18, label %19, label %26
19: ; preds = %16
%20 = load i32, i32* %5
%21 = icmp ne i32 %20, 0
br i1 %21, label %22, label %26
22: ; preds = %19
%23 = load i32, i32* %7
%24 = load i32, i32* @EPERM
%25 = call i32 @expect(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i32 %23, i32 -1, i32 %24)
br label %26
26: ; preds = %22, %19, %16
%27 = load i32, i32* %4
%28 = icmp ne i32 %27, 0
br i1 %28, label %29, label %35
29: ; preds = %26
%30 = load i32, i32* %5
%31 = icmp ne i32 %30, 0
br i1 %31, label %35, label %32
32: ; preds = %29
%33 = load i32, i32* %7
%34 = call i32 @expect(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), i32 %33, i32 0, i32 0)
br label %35
35: ; preds = %32, %29, %26
%36 = load i32, i32* %4
%37 = icmp ne i32 %36, 0
br i1 %37, label %45, label %38
38: ; preds = %35
%39 = load i32, i32* %5
%40 = icmp ne i32 %39, 0
br i1 %40, label %41, label %45
41: ; preds = %38
%42 = load i32, i32* %7
%43 = load i32, i32* @EPERM
%44 = call i32 @expect(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0), i32 %42, i32 -1, i32 %43)
br label %45
45: ; preds = %41, %38, %35
%46 = load i32, i32* %4
%47 = icmp ne i32 %46, 0
br i1 %47, label %55, label %48
48: ; preds = %45
%49 = load i32, i32* %5
%50 = icmp ne i32 %49, 0
br i1 %50, label %55, label %51
51: ; preds = %48
%52 = load i32, i32* %7
%53 = load i32, i32* @EPERM
%54 = call i32 @expect(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.3, i64 0, i64 0), i32 %52, i32 -1, i32 %53)
br label %55
55: ; preds = %51, %48, %45
%56 = load i32, i32* %8
%57 = icmp sge i32 %56, 0
br i1 %57, label %58, label %61
58: ; preds = %55
%59 = load i32, i32* %8
%60 = call i32 @close(i32 %59)
br label %61
61: ; preds = %58, %55
ret void
}

LLVM IR (-O2):
%struct.test = type { i32 }
@PF_INET = global i32 0
@SOCK_RAW = global i32 0
@.str = [33 x i8] c"priv_netinet_raw(asroot, injail)\00"
@EPERM = global i32 0
@.str.1 = [34 x i8] c"priv_netinet_raw(asroot, !injail)\00"
@.str.2 = [34 x i8] c"priv_netinet_raw(!asroot, injail)\00"
@.str.3 = [35 x i8] c"priv_netinet_raw(!asroot, !injail)\00"
define void @priv_netinet_raw(i32 %0, i32 %1, %struct.test* nocapture readnone %2) {
%4 = load i32, i32* @PF_INET
%5 = load i32, i32* @SOCK_RAW
%6 = tail call i32 @socket(i32 %4, i32 %5, i32 0)
%7 = ashr i32 %6, 31
%8 = icmp ne i32 %0, 0
%9 = icmp ne i32 %1, 0
%10 = and i1 %8, %9
br i1 %10, label %11, label %14
11: ; preds = %3
%12 = load i32, i32* @EPERM
%13 = tail call i32 @expect(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i32 %7, i32 -1, i32 %12)
br label %14
14: ; preds = %11, %3
%15 = icmp eq i32 %0, 0
%16 = or i1 %15, %9
br i1 %16, label %19, label %17
17: ; preds = %14
%18 = tail call i32 @expect(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), i32 %7, i32 0, i32 0)
br label %19
19: ; preds = %17, %14
%20 = and i1 %15, %9
br i1 %20, label %21, label %24
21: ; preds = %19
%22 = load i32, i32* @EPERM
%23 = tail call i32 @expect(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0), i32 %7, i32 -1, i32 %22)
br label %24
24: ; preds = %21, %19
%25 = or i32 %1, %0
%26 = icmp eq i32 %25, 0
br i1 %26, label %27, label %30
27: ; preds = %24
%28 = load i32, i32* @EPERM
%29 = tail call i32 @expect(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.3, i64 0, i64 0), i32 %7, i32 -1, i32 %28)
br label %30
30: ; preds = %27, %24
%31 = icmp sgt i32 %6, -1
br i1 %31, label %32, label %34
32: ; preds = %30
%33 = tail call i32 @close(i32 %6)
br label %34
34: ; preds = %32, %30
ret void
}