#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*/ uid_t;
typedef int /*<<< orphan*/ gid_t;
typedef int /*<<< orphan*/ AUTH;

/* Variables and functions */
int MAX_MACHINE_NAME;
int /*<<< orphan*/ MIN(int /*<<< orphan*/, int);
int /*<<< orphan*/ NGRPS;
int /*<<< orphan*/ _SC_NGROUPS_MAX;
int /*<<< orphan*/ abort();
int /*<<< orphan*/ *authunix_create(char *, int /*<<< orphan*/,
                                    int /*<<< orphan*/, int /*<<< orphan*/,
                                    int /*<<< orphan*/ *);
int /*<<< orphan*/ getegid();
int /*<<< orphan*/ geteuid();
int getgroups(int, int /*<<< orphan*/ *);
int gethostname(char *, int);
int sysconf(int /*<<< orphan*/);
AUTH *authunix_create_default(void) {
  int len;
  char machname[MAX_MACHINE_NAME + 1];
  uid_t uid;
  gid_t gid;
  int max_nr_groups = sysconf(_SC_NGROUPS_MAX);
  gid_t gids[max_nr_groups];
  if (gethostname(machname, MAX_MACHINE_NAME) == -1)
    abort();
  machname[MAX_MACHINE_NAME] = 0;
  uid = geteuid();
  gid = getegid();
  if ((len = getgroups(max_nr_groups, gids)) < 0)
    abort();
  return authunix_create(machname, uid, gid, MIN(NGRPS, len), gids);
}


x86 assembly (clang, -O0):
<authunix_create_default>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    0x2e51(%rip),%rax
mov    (%rax),%eax
add    $0x1,%eax
mov    %rsp,%rcx
mov    %rcx,-0x10(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x40(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x18(%rbp)
mov    0x2e2a(%rip),%rax
mov    (%rax),%edi
call   1080 <sysconf@plt>
mov    -0x40(%rbp),%rdi
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
lea    0xf(,%rax,4),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x38(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x30(%rbp)
mov    0x2ded(%rip),%rax
mov    (%rax),%esi
call   1090 <gethostname@plt>
cmp    $0xffffffff,%eax
jne    120a <authunix_create_default+0x8a>
mov    $0x0,%al
call   1030 <abort@plt>
mov    -0x40(%rbp),%rax
mov    0x2dcb(%rip),%rcx
movslq (%rcx),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    $0x0,%al
call   1050 <geteuid@plt>
mov    %eax,-0x1c(%rbp)
mov    $0x0,%al
call   1070 <getegid@plt>
mov    -0x38(%rbp),%rsi
mov    %eax,-0x20(%rbp)
mov    -0x24(%rbp),%edi
call   1060 <getgroups@plt>
mov    %eax,-0x4(%rbp)
cmp    $0x0,%eax
jge    124f <authunix_create_default+0xcf>
mov    $0x0,%al
call   1030 <abort@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x48(%rbp)
mov    -0x20(%rbp),%eax
mov    %eax,-0x44(%rbp)
mov    0x2d6e(%rip),%rax
mov    (%rax),%edi
mov    -0x4(%rbp),%esi
call   1040 <MIN@plt>
mov    -0x40(%rbp),%rdi
mov    -0x48(%rbp),%esi
mov    -0x44(%rbp),%edx
mov    -0x38(%rbp),%r8
mov    %eax,%ecx
call   10a0 <authunix_create@plt>
mov    -0x10(%rbp),%rcx
mov    %rcx,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<authunix_create_default>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    0x2e4b(%rip),%r12
mov    (%r12),%eax
add    $0x1,%eax
mov    %rsp,%r14
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r14
mov    %r14,%rsp
mov    0x2e34(%rip),%rax
mov    (%rax),%edi
call   1080 <sysconf@plt>
mov    %eax,%r15d
mov    %eax,%eax
mov    %rsp,%rbx
lea    0xf(,%rax,4),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    (%r12),%esi
mov    %r14,%rdi
call   1090 <gethostname@plt>
cmp    $0xffffffff,%eax
je     1244 <authunix_create_default+0xc4>
movslq (%r12),%rax
movb   $0x0,(%r14,%rax,1)
xor    %eax,%eax
call   1050 <geteuid@plt>
mov    %eax,%r12d
xor    %eax,%eax
call   1070 <getegid@plt>
mov    %eax,%r13d
mov    %r15d,%edi
mov    %rbx,%rsi
call   1060 <getgroups@plt>
test   %eax,%eax
js     1244 <authunix_create_default+0xc4>
mov    0x2db7(%rip),%rcx
mov    (%rcx),%edi
mov    %eax,%esi
call   1040 <MIN@plt>
mov    %r14,%rdi
mov    %r12d,%esi
mov    %r13d,%edx
mov    %eax,%ecx
mov    %rbx,%r8
call   10a0 <authunix_create@plt>
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %eax,%eax
call   1030 <abort@plt>

LLVM IR (-O0):
@MAX_MACHINE_NAME = global i32 0
@_SC_NGROUPS_MAX = global i32 0
@NGRPS = global i32 0
define i32* @authunix_create_default() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i64
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i64
%8 = load i32, i32* @MAX_MACHINE_NAME
%9 = add nsw i32 %8, 1
%10 = zext i32 %9 to i64
%11 = call i8* @llvm.stacksave()
store i8* %11, i8** %2
%12 = alloca i8, i64 %10
store i64 %10, i64* %3
%13 = load i32, i32* @_SC_NGROUPS_MAX
%14 = call i32 @sysconf(i32 %13)
store i32 %14, i32* %6
%15 = load i32, i32* %6
%16 = zext i32 %15 to i64
%17 = alloca i32, i64 %16
store i64 %16, i64* %7
%18 = load i32, i32* @MAX_MACHINE_NAME
%19 = call i32 @gethostname(i8* %12, i32 %18)
%20 = icmp eq i32 %19, -1
br i1 %20, label %21, label %23
21: ; preds = %0
%22 = call i32 (...) @abort()
unreachable
23: ; preds = %0
%24 = load i32, i32* @MAX_MACHINE_NAME
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i8, i8* %12, i64 %25
store i8 0, i8* %26
%27 = call i32 (...) @geteuid()
store i32 %27, i32* %4
%28 = call i32 (...) @getegid()
store i32 %28, i32* %5
%29 = load i32, i32* %6
%30 = call i32 @getgroups(i32 %29, i32* %17)
store i32 %30, i32* %1
%31 = icmp slt i32 %30, 0
br i1 %31, label %32, label %34
32: ; preds = %23
%33 = call i32 (...) @abort()
unreachable
34: ; preds = %23
%35 = load i32, i32* %4
%36 = load i32, i32* %5
%37 = load i32, i32* @NGRPS
%38 = load i32, i32* %1
%39 = call i32 @MIN(i32 %37, i32 %38)
%40 = call i32* @authunix_create(i8* %12, i32 %35, i32 %36, i32 %39, i32* %17)
%41 = load i8*, i8** %2
ret i32* %40
}

LLVM IR (-O2):
@MAX_MACHINE_NAME = global i32 0
@_SC_NGROUPS_MAX = global i32 0
@NGRPS = global i32 0
define i32* @authunix_create_default() {
%1 = load i32, i32* @MAX_MACHINE_NAME
%2 = add nsw i32 %1, 1
%3 = zext i32 %2 to i64
%4 = alloca i8, i64 %3
%5 = load i32, i32* @_SC_NGROUPS_MAX
%6 = tail call i32 @sysconf(i32 %5)
%7 = zext i32 %6 to i64
%8 = alloca i32, i64 %7
%9 = load i32, i32* @MAX_MACHINE_NAME
%10 = call i32 @gethostname(i8* %4, i32 %9)
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %14
12: ; preds = %0
%13 = call i32 (...) @abort()
unreachable
14: ; preds = %0
%15 = load i32, i32* @MAX_MACHINE_NAME
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i8, i8* %4, i64 %16
store i8 0, i8* %17
%18 = call i32 (...) @geteuid()
%19 = call i32 (...) @getegid()
%20 = call i32 @getgroups(i32 %6, i32* %8)
%21 = icmp slt i32 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %14
%23 = call i32 (...) @abort()
unreachable
24: ; preds = %14
%25 = load i32, i32* @NGRPS
%26 = call i32 @MIN(i32 %25, i32 %20)
%27 = call i32* @authunix_create(i8* %4, i32 %18, i32 %19, i32 %26, i32* %8)
ret i32* %27
}