#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*/ expect(char *, int, int, int /*<<< orphan*/);
int sysctlbyname(char *, int /*<<< orphan*/ *, size_t *, int /*<<< orphan*/ *,
                 int /*<<< orphan*/);
void priv_msgbuf_privonly(int asroot, int injail, struct test *test) {
  size_t len;
  int error;
  error = sysctlbyname("kern.msgbuf", NULL, &len, NULL, 0);
  if (asroot && injail)
    expect("priv_msgbuf_privonly(asroot, injail)", error, -1, EPERM);
  if (asroot && !injail)
    expect("priv_msgbuf_privonly(asroot, !injail)", error, 0, 0);
  if (!asroot && injail)
    expect("priv_msgbuf_privonly(!asroot, injail)", error, -1, EPERM);
  if (!asroot && !injail)
    expect("priv_msgbuf_privonly(!asroot, !injail)", error, -1, EPERM);
}


x86 assembly (clang, -O0):
<priv_msgbuf_privonly>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
lea    0xec7(%rip),%rdi
xor    %eax,%eax
mov    %eax,%ecx
lea    -0x18(%rbp),%rdx
xor    %r8d,%r8d
mov    %rcx,%rsi
call   1040 <sysctlbyname@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x4(%rbp)
je     1180 <priv_msgbuf_privonly+0x60>
cmpl   $0x0,-0x8(%rbp)
je     1180 <priv_msgbuf_privonly+0x60>
mov    -0x1c(%rbp),%esi
mov    0x2e6b(%rip),%rax
mov    (%rax),%ecx
lea    0xe96(%rip),%rdi
mov    $0xffffffff,%edx
call   1030 <expect@plt>
cmpl   $0x0,-0x4(%rbp)
je     11a7 <priv_msgbuf_privonly+0x87>
cmpl   $0x0,-0x8(%rbp)
jne    11a7 <priv_msgbuf_privonly+0x87>
mov    -0x1c(%rbp),%esi
lea    0xe93(%rip),%rdi
xor    %ecx,%ecx
mov    %ecx,%edx
call   1030 <expect@plt>
cmpl   $0x0,-0x4(%rbp)
jne    11d8 <priv_msgbuf_privonly+0xb8>
cmpl   $0x0,-0x8(%rbp)
je     11d8 <priv_msgbuf_privonly+0xb8>
mov    -0x1c(%rbp),%esi
mov    0x2e13(%rip),%rax
mov    (%rax),%ecx
lea    0xe89(%rip),%rdi
mov    $0xffffffff,%edx
call   1030 <expect@plt>
cmpl   $0x0,-0x4(%rbp)
jne    1209 <priv_msgbuf_privonly+0xe9>
cmpl   $0x0,-0x8(%rbp)
jne    1209 <priv_msgbuf_privonly+0xe9>
mov    -0x1c(%rbp),%esi
mov    0x2de2(%rip),%rax
mov    (%rax),%ecx
lea    0xe7e(%rip),%rdi
mov    $0xffffffff,%edx
call   1030 <expect@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<priv_msgbuf_privonly>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %esi,%ebx
mov    %edi,%ebp
lea    0xecd(%rip),%rdi
lea    0x8(%rsp),%rdx
xor    %esi,%esi
xor    %ecx,%ecx
xor    %r8d,%r8d
call   1040 <sysctlbyname@plt>
mov    %eax,%r14d
test   %ebp,%ebp
je     116c <priv_msgbuf_privonly+0x4c>
test   %ebx,%ebx
je     116c <priv_msgbuf_privonly+0x4c>
mov    0x2e82(%rip),%rax
mov    (%rax),%ecx
lea    0xead(%rip),%rdi
mov    %r14d,%esi
mov    $0xffffffff,%edx
call   1030 <expect@plt>
test   %ebp,%ebp
je     1187 <priv_msgbuf_privonly+0x67>
test   %ebx,%ebx
jne    1187 <priv_msgbuf_privonly+0x67>
lea    0xeb6(%rip),%rdi
mov    %r14d,%esi
xor    %edx,%edx
xor    %ecx,%ecx
call   1030 <expect@plt>
test   %ebp,%ebp
jne    11ac <priv_msgbuf_privonly+0x8c>
test   %ebx,%ebx
je     11ac <priv_msgbuf_privonly+0x8c>
mov    0x2e42(%rip),%rax
mov    (%rax),%ecx
lea    0xeb8(%rip),%rdi
mov    %r14d,%esi
mov    $0xffffffff,%edx
call   1030 <expect@plt>
or     %ebp,%ebx
jne    11cd <priv_msgbuf_privonly+0xad>
mov    0x2e21(%rip),%rax
mov    (%rax),%ecx
lea    0xebd(%rip),%rdi
mov    %r14d,%esi
mov    $0xffffffff,%edx
call   1030 <expect@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
%struct.test = type { i32 }
@.str = [12 x i8] c"kern.msgbuf\00"
@.str.1 = [37 x i8] c"priv_msgbuf_privonly(asroot, injail)\00"
@EPERM = global i32 0
@.str.2 = [38 x i8] c"priv_msgbuf_privonly(asroot, !injail)\00"
@.str.3 = [38 x i8] c"priv_msgbuf_privonly(!asroot, injail)\00"
@.str.4 = [39 x i8] c"priv_msgbuf_privonly(!asroot, !injail)\00"
define void @priv_msgbuf_privonly(i32 %0, i32 %1, %struct.test* nocapture readnone %2) {
%4 = alloca i64
%5 = bitcast i64* %4 to i8*
%6 = call i32 @sysctlbyname(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32* null, i64* %4, i32* null, i32 0)
%7 = icmp ne i32 %0, 0
%8 = icmp ne i32 %1, 0
%9 = and i1 %7, %8
br i1 %9, label %10, label %13
10: ; preds = %3
%11 = load i32, i32* @EPERM
%12 = call i32 @expect(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), i32 %6, i32 -1, i32 %11)
br label %13
13: ; preds = %10, %3
%14 = icmp eq i32 %0, 0
%15 = or i1 %14, %8
br i1 %15, label %18, label %16
16: ; preds = %13
%17 = call i32 @expect(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0), i32 %6, i32 0, i32 0)
br label %18
18: ; preds = %16, %13
%19 = and i1 %14, %8
br i1 %19, label %20, label %23
20: ; preds = %18
%21 = load i32, i32* @EPERM
%22 = call i32 @expect(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.3, i64 0, i64 0), i32 %6, i32 -1, i32 %21)
br label %23
23: ; preds = %20, %18
%24 = or i32 %1, %0
%25 = icmp eq i32 %24, 0
br i1 %25, label %26, label %29
26: ; preds = %23
%27 = load i32, i32* @EPERM
%28 = call i32 @expect(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.4, i64 0, i64 0), i32 %6, i32 -1, i32 %27)
br label %29
29: ; preds = %26, %23
ret void
}