#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 CTL_MAXNAME;
int __sysctl(int *, size_t, void *, size_t *, void *, size_t);
scalar_t__ __sysctlnametomib(char const *, int *, size_t *);
int __sysctlbyname(const char *name, void *oldval, size_t *oldlenp,
                   const void *newval, size_t newlen) {
  int request[CTL_MAXNAME + 2];
  size_t requestlen = CTL_MAXNAME + 2;
  if (__sysctlnametomib(name, request, &requestlen) < 0)
    return -1;
  return __sysctl(request, requestlen, oldval, oldlenp, (void *)newval, 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)
mov    0x2e6d(%rip),%rax
mov    (%rax),%eax
add    $0x2,%eax
cltq
mov    %rax,-0x48(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x48(%rbp),%rdx
call   1030 <__sysctlnametomib@plt>
cmp    $0x0,%rax
jge    11a8 <__sysctlbyname+0x88>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x4c(%rbp)
jmp    11cf <__sysctlbyname+0xaf>
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
movslq (%rax),%rax
add    $0x2,%rax
mov    %eax,%ecx
mov    %rsp,%rbx
lea    0xf(,%rcx,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     118e <__sysctlbyname+0x6e>
mov    -0x30(%rbp),%rsi
mov    %rbx,%rdi
mov    %r13,%rdx
mov    %r12,%rcx
mov    %r15,%r8
mov    %r14,%r9
call   1040 <__sysctl@plt>
jmp    1193 <__sysctlbyname+0x73>
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 = load i32, i32* @CTL_MAXNAME
%22 = add nsw i32 %21, 2
%23 = sext i32 %22 to i64
store i64 %23, i64* %14
%24 = load i8*, i8** %7
%25 = call i64 @__sysctlnametomib(i8* %24, i32* %20, i64* %14)
%26 = icmp slt i64 %25, 0
br i1 %26, label %27, label %28
27: ; preds = %5
store i32 -1, i32* %6
store i32 1, i32* %15
br label %35
28: ; preds = %5
%29 = load i64, i64* %14
%30 = load i8*, i8** %8
%31 = load i64*, i64** %9
%32 = load i8*, i8** %10
%33 = load i64, i64* %11
%34 = call i32 @__sysctl(i32* %20, i64 %29, i8* %30, i64* %31, i8* %32, i64 %33)
store i32 %34, i32* %6
store i32 1, i32* %15
br label %35
35: ; preds = %28, %27
%36 = load i8*, i8** %12
%37 = load i32, i32* %6
ret i32 %37
}

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*
%12 = sext i32 %8 to i64
store i64 %12, i64* %6
%13 = call i64 @__sysctlnametomib(i8* %0, i32* %10, i64* %6)
%14 = icmp slt i64 %13, 0
br i1 %14, label %18, label %15
15: ; preds = %5
%16 = load i64, i64* %6
%17 = call i32 @__sysctl(i32* %10, i64 %16, i8* %1, i64* %2, i8* %3, i64 %4)
br label %18
18: ; preds = %5, %15
%19 = phi i32 [ %17, %15 ], [ -1, %5 ]
ret i32 %19
}