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

/* Variables and functions */
int /*<<< orphan*/ *authunix_create(char *, int, int /*<<< orphan*/, int,
                                    int /*<<< orphan*/ *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ getegid();
int geteuid();
int getgroups(int, int /*<<< orphan*/ *);
int gethostname(char *, int);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ stderr;
int main(void) {
  int test_status = 1;
  AUTH *authUnx = NULL;
  char hostname[256];
  int rslt;
  gid_t groups[16];
  gid_t *aup_gids;
  uid_t uid;
  gid_t gid;
  int num_groups;
  aup_gids = groups;
  uid = geteuid();
  gid = getegid();
  num_groups = getgroups(16, groups);
  if (num_groups == -1) {
    fprintf(stderr, "getgroups() failed for %d\n", uid);
    return 1;
  }
  rslt = gethostname(hostname, 256);
  if (rslt == -1) {
    fprintf(stderr, "gethostname() failed\n");
    return 1;
  }
  authUnx = authunix_create(hostname, uid, gid, num_groups, aup_gids);
  test_status = ((AUTH *)authUnx != NULL) ? 0 : 1;
  printf("%d\n", test_status);
  return test_status;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x180,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
lea    -0x160(%rbp),%rax
mov    %rax,-0x168(%rbp)
mov    $0x0,%al
call   1040 <geteuid@plt>
mov    %eax,-0x16c(%rbp)
mov    $0x0,%al
call   1070 <getegid@plt>
mov    %eax,-0x170(%rbp)
lea    -0x160(%rbp),%rsi
mov    $0x10,%edi
call   1060 <getgroups@plt>
mov    %eax,-0x174(%rbp)
cmpl   $0xffffffff,-0x174(%rbp)
jne    1206 <main+0x96>
mov    0x2dfc(%rip),%rax
mov    (%rax),%edi
mov    -0x16c(%rbp),%edx
lea    0xe0d(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12a0 <main+0x130>
lea    -0x110(%rbp),%rdi
mov    $0x100,%esi
call   1080 <gethostname@plt>
mov    %eax,-0x114(%rbp)
cmpl   $0xffffffff,-0x114(%rbp)
jne    124d <main+0xdd>
mov    0x2daf(%rip),%rax
mov    (%rax),%edi
lea    0xde1(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12a0 <main+0x130>
lea    -0x110(%rbp),%rdi
mov    -0x16c(%rbp),%esi
mov    -0x170(%rbp),%edx
mov    -0x174(%rbp),%ecx
mov    -0x168(%rbp),%r8
call   1090 <authunix_create@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdx
mov    $0x1,%eax
xor    %ecx,%ecx
cmp    $0x0,%rdx
cmovne %ecx,%eax
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%esi
lea    0xd82(%rip),%rdi
call   1030 <printf@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x180,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x140,%rsp
xor    %eax,%eax
call   1040 <geteuid@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1070 <getegid@plt>
mov    %eax,%r14d
mov    %rsp,%rsi
mov    $0x10,%edi
call   1060 <getgroups@plt>
cmp    $0xffffffff,%eax
je     11e2 <main+0x72>
mov    %eax,%ebp
lea    0x40(%rsp),%rdi
mov    $0x100,%esi
call   1080 <gethostname@plt>
cmp    $0xffffffff,%eax
je     11fd <main+0x8d>
lea    0x40(%rsp),%rdi
mov    %rsp,%r8
mov    %ebx,%esi
mov    %r14d,%edx
mov    %ebp,%ecx
call   1090 <authunix_create@plt>
xor    %ebx,%ebx
test   %rax,%rax
sete   %bl
lea    0xe3e(%rip),%rdi
mov    %ebx,%esi
call   1030 <printf@plt>
jmp    1219 <main+0xa9>
mov    0x2df7(%rip),%rax
mov    (%rax),%edi
lea    0xe0e(%rip),%rsi
mov    %ebx,%edx
xor    %eax,%eax
call   1050 <fprintf@plt>
jmp    1214 <main+0xa4>
mov    0x2ddc(%rip),%rax
mov    (%rax),%edi
lea    0xe0e(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0x1,%ebx
mov    %ebx,%eax
add    $0x140,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [27 x i8] c"getgroups() failed for %d\0A\00"
@.str.1 = [22 x i8] c"gethostname() failed\0A\00"
@.str.2 = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32*
%4 = alloca [256 x i8]
%5 = alloca i32
%6 = alloca [16 x i32]
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i32 0, i32* %1
store i32 1, i32* %2
store i32* null, i32** %3
%11 = getelementptr inbounds [16 x i32], [16 x i32]* %6, i64 0, i64 0
store i32* %11, i32** %7
%12 = call i32 (...) @geteuid()
store i32 %12, i32* %8
%13 = call i32 (...) @getegid()
store i32 %13, i32* %9
%14 = getelementptr inbounds [16 x i32], [16 x i32]* %6, i64 0, i64 0
%15 = call i32 @getgroups(i32 16, i32* %14)
store i32 %15, i32* %10
%16 = load i32, i32* %10
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %22
18: ; preds = %0
%19 = load i32, i32* @stderr
%20 = load i32, i32* %8
%21 = call i32 (i32, i8*, ...) @fprintf(i32 %19, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i32 %20)
store i32 1, i32* %1
br label %44
22: ; preds = %0
%23 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%24 = call i32 @gethostname(i8* %23, i32 256)
store i32 %24, i32* %5
%25 = load i32, i32* %5
%26 = icmp eq i32 %25, -1
br i1 %26, label %27, label %30
27: ; preds = %22
%28 = load i32, i32* @stderr
%29 = call i32 (i32, i8*, ...) @fprintf(i32 %28, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %1
br label %44
30: ; preds = %22
%31 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%32 = load i32, i32* %8
%33 = load i32, i32* %9
%34 = load i32, i32* %10
%35 = load i32*, i32** %7
%36 = call i32* @authunix_create(i8* %31, i32 %32, i32 %33, i32 %34, i32* %35)
store i32* %36, i32** %3
%37 = load i32*, i32** %3
%38 = icmp ne i32* %37, null
%39 = zext i1 %38 to i64
%40 = select i1 %38, i32 0, i32 1
store i32 %40, i32* %2
%41 = load i32, i32* %2
%42 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %41)
%43 = load i32, i32* %2
store i32 %43, i32* %1
br label %44
44: ; preds = %30, %27, %18
%45 = load i32, i32* %1
ret i32 %45
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [27 x i8] c"getgroups() failed for %d\0A\00"
@.str.1 = [22 x i8] c"gethostname() failed\0A\00"
@.str.2 = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = alloca [256 x i8]
%2 = alloca [16 x i32]
%3 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 0
%4 = bitcast [16 x i32]* %2 to i8*
%5 = getelementptr inbounds [16 x i32], [16 x i32]* %2, i64 0, i64 0
%6 = tail call i32 (...) @geteuid()
%7 = tail call i32 (...) @getegid()
%8 = call i32 @getgroups(i32 16, i32* %5)
%9 = icmp eq i32 %8, -1
br i1 %9, label %10, label %13
10: ; preds = %0
%11 = load i32, i32* @stderr
%12 = call i32 (i32, i8*, ...) @fprintf(i32 %11, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i32 %6)
br label %24
13: ; preds = %0
%14 = call i32 @gethostname(i8* %3, i32 256)
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %19
16: ; preds = %13
%17 = load i32, i32* @stderr
%18 = call i32 (i32, i8*, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
br label %24
19: ; preds = %13
%20 = call i32* @authunix_create(i8* %3, i32 %6, i32 %7, i32 %8, i32* %5)
%21 = icmp eq i32* %20, null
%22 = zext i1 %21 to i32
%23 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %22)
br label %24
24: ; preds = %19, %16, %10
%25 = phi i32 [ 1, %10 ], [ 1, %16 ], [ %22, %19 ]
ret i32 %25
}