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

/* Variables and functions */
int /*<<< orphan*/ CTL_MAXNAME;
int sysctl(int *, size_t, void *, size_t *, void const *, size_t);
scalar_t__ sysctlnametomib(char const *, int *, size_t *);
int sysctlbyname(const char *name, void *oldp, size_t *oldlenp,
                 const void *newp, size_t newlen) {
  int real_oid[CTL_MAXNAME + 2];
  size_t oidlen;
  oidlen = sizeof(real_oid) / sizeof(int);
  if (sysctlnametomib(name, real_oid, &oidlen) < 0)
    return (-1);
  return (sysctl(real_oid, oidlen, oldp, oldlenp, newp, newlen));
}


x86 assembly (clang, -O0):
<sysctlbyname>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8,-0x30(%rbp)
mov    0x2e9d(%rip),%rax
mov    (%rax),%eax
add    $0x2,%eax
mov    %rsp,%rcx
mov    %rcx,-0x38(%rbp)
lea    0xf(,%rax,4),%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rsi
sub    %rcx,%rsi
mov    %rsi,-0x58(%rbp)
mov    %rsi,%rsp
mov    %rax,-0x40(%rbp)
shl    $0x2,%rax
shr    $0x2,%rax
mov    %rax,-0x48(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x48(%rbp),%rdx
call   1030 <sysctlnametomib@plt>
cmp    $0x0,%rax
jge    11a2 <sysctlbyname+0x82>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x4c(%rbp)
jmp    11c9 <sysctlbyname+0xa9>
mov    -0x58(%rbp),%rdi
mov    -0x48(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
mov    -0x28(%rbp),%r8
mov    -0x30(%rbp),%r9
call   1040 <sysctl@plt>
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x4c(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sysctlbyname>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r8,%r14
mov    %rcx,%r15
mov    %rdx,%r12
mov    %rsi,%r13
mov    0x2e9f(%rip),%rax
mov    (%rax),%eax
add    $0x2,%eax
mov    %rsp,%rbx
lea    0xf(,%rax,4),%rcx
and    $0xfffffffffffffff0,%rcx
sub    %rcx,%rbx
mov    %rbx,%rsp
mov    %rax,-0x30(%rbp)
lea    -0x30(%rbp),%rdx
mov    %rbx,%rsi
call   1030 <sysctlnametomib@plt>
test   %rax,%rax
js     118a <sysctlbyname+0x6a>
mov    -0x30(%rbp),%rsi
mov    %rbx,%rdi
mov    %r13,%rdx
mov    %r12,%rcx
mov    %r15,%r8
mov    %r14,%r9
call   1040 <sysctl@plt>
jmp    118f <sysctlbyname+0x6f>
mov    $0xffffffff,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@CTL_MAXNAME = global i32 0
define i32 @sysctlbyname(i8* %0, i8* %1, i64* %2, i8* %3, i64 %4) {
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i64*
%10 = alloca i8*
%11 = alloca i64
%12 = alloca i8*
%13 = alloca i64
%14 = alloca i64
%15 = alloca i32
store i8* %0, i8** %7
store i8* %1, i8** %8
store i64* %2, i64** %9
store i8* %3, i8** %10
store i64 %4, i64* %11
%16 = load i32, i32* @CTL_MAXNAME
%17 = add nsw i32 %16, 2
%18 = zext i32 %17 to i64
%19 = call i8* @llvm.stacksave()
store i8* %19, i8** %12
%20 = alloca i32, i64 %18
store i64 %18, i64* %13
%21 = mul nuw i64 4, %18
%22 = udiv i64 %21, 4
store i64 %22, i64* %14
%23 = load i8*, i8** %7
%24 = call i64 @sysctlnametomib(i8* %23, i32* %20, i64* %14)
%25 = icmp slt i64 %24, 0
br i1 %25, label %26, label %27
26: ; preds = %5
store i32 -1, i32* %6
store i32 1, i32* %15
br label %34
27: ; preds = %5
%28 = load i64, i64* %14
%29 = load i8*, i8** %8
%30 = load i64*, i64** %9
%31 = load i8*, i8** %10
%32 = load i64, i64* %11
%33 = call i32 @sysctl(i32* %20, i64 %28, i8* %29, i64* %30, i8* %31, i64 %32)
store i32 %33, i32* %6
store i32 1, i32* %15
br label %34
34: ; preds = %27, %26
%35 = load i8*, i8** %12
%36 = load i32, i32* %6
ret i32 %36
}

LLVM IR (-O2):
@CTL_MAXNAME = global i32 0
define i32 @sysctlbyname(i8* %0, i8* %1, i64* %2, i8* %3, i64 %4) {
%6 = alloca i64
%7 = load i32, i32* @CTL_MAXNAME
%8 = add nsw i32 %7, 2
%9 = zext i32 %8 to i64
%10 = alloca i32, i64 %9
%11 = bitcast i64* %6 to i8*
store i64 %9, i64* %6
%12 = call i64 @sysctlnametomib(i8* %0, i32* %10, i64* %6)
%13 = icmp slt i64 %12, 0
br i1 %13, label %17, label %14
14: ; preds = %5
%15 = load i64, i64* %6
%16 = call i32 @sysctl(i32* %10, i64 %15, i8* %1, i64* %2, i8* %3, i64 %4)
br label %17
17: ; preds = %5, %14
%18 = phi i32 [ %16, %14 ], [ -1, %5 ]
ret i32 %18
}