#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 __sysctl_args {
  int *name;
  int nlen;
  int *oldval;
  size_t *oldlenp;
};
typedef int /*<<< orphan*/ ret;
typedef int /*<<< orphan*/ name;
typedef int /*<<< orphan*/ args;

/* Variables and functions */
int CTL_VM;
int /*<<< orphan*/ SYS__sysctl;
int VM_MAX_MAP_COUNT;
int /*<<< orphan*/ memset(struct __sysctl_args *, int /*<<< orphan*/, int);
int syscall(int /*<<< orphan*/, struct __sysctl_args *);
int get_max_map_count() {
  int ret = 0;
  struct __sysctl_args args;
  int name[] = {CTL_VM, VM_MAX_MAP_COUNT};
  size_t len = sizeof(ret);
  memset(&args, 0, sizeof(args));
  args.name = name;
  args.nlen = sizeof(name) / sizeof(name[0]);
  args.oldval = &ret;
  args.oldlenp = &len;
  if (syscall(SYS__sysctl, &args) == -1)
    return -1;
  else
    return ret;
}


x86 assembly (clang, -O0):
<get_max_map_count>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x8(%rbp)
mov    0x2eaa(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x30(%rbp)
mov    0x2ea6(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
movq   $0x4,-0x38(%rbp)
lea    -0x28(%rbp),%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1030 <memset@plt>
lea    -0x30(%rbp),%rax
mov    %rax,-0x28(%rbp)
movl   $0x2,-0x20(%rbp)
lea    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
lea    -0x38(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    0x2e4b(%rip),%rax
mov    (%rax),%edi
lea    -0x28(%rbp),%rsi
call   1040 <syscall@plt>
cmp    $0xffffffff,%eax
jne    11a5 <get_max_map_count+0x85>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ab <get_max_map_count+0x8b>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_max_map_count>:
push   %rbx
sub    $0x40,%rsp
movl   $0x0,0xc(%rsp)
mov    0x2eac(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x10(%rsp)
mov    0x2ea7(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x14(%rsp)
movq   $0x4,0x18(%rsp)
lea    0x20(%rsp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1030 <memset@plt>
lea    0x10(%rsp),%rax
mov    %rax,0x20(%rsp)
movl   $0x2,0x28(%rsp)
lea    0xc(%rsp),%rax
mov    %rax,0x30(%rsp)
lea    0x18(%rsp),%rax
mov    %rax,0x38(%rsp)
mov    0x2e3f(%rip),%rax
mov    (%rax),%edi
mov    %rbx,%rsi
call   1040 <syscall@plt>
cmp    $0xffffffff,%eax
je     11a4 <get_max_map_count+0x84>
mov    0xc(%rsp),%eax
add    $0x40,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.__sysctl_args = type { i32*, i32, i32*, i64* }
@CTL_VM = global i32 0
@VM_MAX_MAP_COUNT = global i32 0
@SYS__sysctl = global i32 0
define i32 @get_max_map_count() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca %struct.__sysctl_args
%4 = alloca [2 x i32]
%5 = alloca i64
store i32 0, i32* %2
%6 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 0
%7 = load i32, i32* @CTL_VM
store i32 %7, i32* %6
%8 = getelementptr inbounds i32, i32* %6, i64 1
%9 = load i32, i32* @VM_MAX_MAP_COUNT
store i32 %9, i32* %8
store i64 4, i64* %5
%10 = call i32 @memset(%struct.__sysctl_args* %3, i32 0, i32 32)
%11 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 0
%12 = getelementptr inbounds %struct.__sysctl_args, %struct.__sysctl_args* %3, i32 0, i32 0
store i32* %11, i32** %12
%13 = getelementptr inbounds %struct.__sysctl_args, %struct.__sysctl_args* %3, i32 0, i32 1
store i32 2, i32* %13
%14 = getelementptr inbounds %struct.__sysctl_args, %struct.__sysctl_args* %3, i32 0, i32 2
store i32* %2, i32** %14
%15 = getelementptr inbounds %struct.__sysctl_args, %struct.__sysctl_args* %3, i32 0, i32 3
store i64* %5, i64** %15
%16 = load i32, i32* @SYS__sysctl
%17 = call i32 @syscall(i32 %16, %struct.__sysctl_args* %3)
%18 = icmp eq i32 %17, -1
br i1 %18, label %19, label %20
19: ; preds = %0
store i32 -1, i32* %1
br label %22
20: ; preds = %0
%21 = load i32, i32* %2
store i32 %21, i32* %1
br label %22
22: ; preds = %20, %19
%23 = load i32, i32* %1
ret i32 %23
}

LLVM IR (-O2):
%struct.__sysctl_args = type { i32*, i32, i32*, i64* }
@CTL_VM = global i32 0
@VM_MAX_MAP_COUNT = global i32 0
@SYS__sysctl = global i32 0
define i32 @get_max_map_count() {
%1 = alloca i32
%2 = alloca %struct.__sysctl_args
%3 = alloca [2 x i32]
%4 = alloca i64
%5 = bitcast i32* %1 to i8*
store i32 0, i32* %1
%6 = bitcast %struct.__sysctl_args* %2 to i8*
%7 = bitcast [2 x i32]* %3 to i8*
%8 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 0
%9 = load i32, i32* @CTL_VM
store i32 %9, i32* %8
%10 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
%11 = load i32, i32* @VM_MAX_MAP_COUNT
store i32 %11, i32* %10
%12 = bitcast i64* %4 to i8*
store i64 4, i64* %4
%13 = call i32 @memset(%struct.__sysctl_args* %2, i32 0, i32 32)
%14 = getelementptr inbounds %struct.__sysctl_args, %struct.__sysctl_args* %2, i64 0, i32 0
store i32* %8, i32** %14
%15 = getelementptr inbounds %struct.__sysctl_args, %struct.__sysctl_args* %2, i64 0, i32 1
store i32 2, i32* %15
%16 = getelementptr inbounds %struct.__sysctl_args, %struct.__sysctl_args* %2, i64 0, i32 2
store i32* %1, i32** %16
%17 = getelementptr inbounds %struct.__sysctl_args, %struct.__sysctl_args* %2, i64 0, i32 3
store i64* %4, i64** %17
%18 = load i32, i32* @SYS__sysctl
%19 = call i32 @syscall(i32 %18, %struct.__sysctl_args* %2)
%20 = icmp eq i32 %19, -1
%21 = load i32, i32* %1
%22 = select i1 %20, i32 -1, i32 %21
ret i32 %22
}