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

/* Variables and functions */
scalar_t__ asprintf(char **, char *, char const *);
int /*<<< orphan*/ free(char *);
scalar_t__ sysctlbyname(char *, int *, size_t *, int /*<<< orphan*/ *,
                        int /*<<< orphan*/);
int feature_present(const char *feature) {
  char *mib;
  size_t len;
  int i;
  if (asprintf(&mib, "kern.features.%s", feature) < 0)
    return (0);
  len = sizeof(i);
  if (sysctlbyname(mib, &i, &len, NULL, 0) < 0) {
    free(mib);
    return (0);
  }
  free(mib);
  if (len != sizeof(i))
    return (0);
  return (i != 0);
}


x86 assembly (clang, -O0):
<feature_present>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdx
lea    -0x18(%rbp),%rdi
lea    0xeb5(%rip),%rsi
call   1040 <asprintf@plt>
cmp    $0x0,%rax
jge    1166 <feature_present+0x36>
movl   $0x0,-0x4(%rbp)
jmp    11d4 <feature_present+0xa4>
movq   $0x4,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
lea    -0x24(%rbp),%rsi
lea    -0x20(%rbp),%rdx
xor    %eax,%eax
mov    %eax,%ecx
xor    %r8d,%r8d
call   1050 <sysctlbyname@plt>
cmp    $0x0,%rax
jge    11a5 <feature_present+0x75>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
jmp    11d4 <feature_present+0xa4>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
cmpq   $0x4,-0x20(%rbp)
je     11c5 <feature_present+0x95>
movl   $0x0,-0x4(%rbp)
jmp    11d4 <feature_present+0xa4>
cmpl   $0x0,-0x24(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<feature_present>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%rdx
lea    0xebf(%rip),%rsi
lea    0x10(%rsp),%rdi
call   1040 <asprintf@plt>
test   %rax,%rax
js     119a <feature_present+0x6a>
movq   $0x4,0x8(%rsp)
mov    0x10(%rsp),%rdi
xor    %ebx,%ebx
lea    0x4(%rsp),%rsi
lea    0x8(%rsp),%rdx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   1050 <sysctlbyname@plt>
mov    %rax,%r14
mov    0x10(%rsp),%rdi
call   1030 <free@plt>
test   %r14,%r14
js     119c <feature_present+0x6c>
cmpq   $0x4,0x8(%rsp)
jne    119c <feature_present+0x6c>
xor    %ebx,%ebx
cmpl   $0x0,0x4(%rsp)
setne  %bl
jmp    119c <feature_present+0x6c>
xor    %ebx,%ebx
mov    %ebx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [17 x i8] c"kern.features.%s\00"
define i32 @feature_present(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i32
store i8* %0, i8** %3
%7 = load i8*, i8** %3
%8 = call i64 @asprintf(i8** %4, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* %7)
%9 = icmp slt i64 %8, 0
br i1 %9, label %10, label %11
10: ; preds = %1
store i32 0, i32* %2
br label %28
11: ; preds = %1
store i64 4, i64* %5
%12 = load i8*, i8** %4
%13 = call i64 @sysctlbyname(i8* %12, i32* %6, i64* %5, i32* null, i32 0)
%14 = icmp slt i64 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %11
%16 = load i8*, i8** %4
%17 = call i32 @free(i8* %16)
store i32 0, i32* %2
br label %28
18: ; preds = %11
%19 = load i8*, i8** %4
%20 = call i32 @free(i8* %19)
%21 = load i64, i64* %5
%22 = icmp ne i64 %21, 4
br i1 %22, label %23, label %24
23: ; preds = %18
store i32 0, i32* %2
br label %28
24: ; preds = %18
%25 = load i32, i32* %6
%26 = icmp ne i32 %25, 0
%27 = zext i1 %26 to i32
store i32 %27, i32* %2
br label %28
28: ; preds = %24, %23, %15, %10
%29 = load i32, i32* %2
ret i32 %29
}

LLVM IR (-O2):
@.str = [17 x i8] c"kern.features.%s\00"
define i32 @feature_present(i8* %0) {
%2 = alloca i8*
%3 = alloca i64
%4 = alloca i32
%5 = bitcast i8** %2 to i8*
%6 = bitcast i64* %3 to i8*
%7 = bitcast i32* %4 to i8*
%8 = call i64 @asprintf(i8** %2, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* %0)
%9 = icmp slt i64 %8, 0
br i1 %9, label %23, label %10
10: ; preds = %1
store i64 4, i64* %3
%11 = load i8*, i8** %2
%12 = call i64 @sysctlbyname(i8* %11, i32* %4, i64* %3, i32* null, i32 0)
%13 = icmp sgt i64 %12, -1
%14 = load i8*, i8** %2
%15 = call i32 @free(i8* %14)
%16 = load i64, i64* %3
%17 = icmp eq i64 %16, 4
%18 = select i1 %13, i1 %17, i1 false
br i1 %18, label %19, label %23
19: ; preds = %10
%20 = load i32, i32* %4
%21 = icmp ne i32 %20, 0
%22 = zext i1 %21 to i32
br label %23
23: ; preds = %10, %1, %19
%24 = phi i32 [ %22, %19 ], [ 0, %1 ], [ 0, %10 ]
ret i32 %24
}