#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 atoi(char *);
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(int argn, char *argc[]) {
  int run_mode = 0;
  int test_status = 1;
  int progNum = atoi(argc[2]);
  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    $0x1a0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x1,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1080 <atoi@plt>
mov    %eax,-0x1c(%rbp)
movq   $0x0,-0x28(%rbp)
lea    -0x180(%rbp),%rax
mov    %rax,-0x188(%rbp)
mov    $0x0,%al
call   1040 <geteuid@plt>
mov    %eax,-0x18c(%rbp)
mov    $0x0,%al
call   1070 <getegid@plt>
mov    %eax,-0x190(%rbp)
lea    -0x180(%rbp),%rsi
mov    $0x10,%edi
call   1060 <getgroups@plt>
mov    %eax,-0x194(%rbp)
cmpl   $0xffffffff,-0x194(%rbp)
jne    1234 <main+0xb4>
mov    0x2dce(%rip),%rax
mov    (%rax),%edi
mov    -0x18c(%rbp),%edx
lea    0xddf(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12ce <main+0x14e>
lea    -0x130(%rbp),%rdi
mov    $0x100,%esi
call   1090 <gethostname@plt>
mov    %eax,-0x134(%rbp)
cmpl   $0xffffffff,-0x134(%rbp)
jne    127b <main+0xfb>
mov    0x2d81(%rip),%rax
mov    (%rax),%edi
lea    0xdb3(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12ce <main+0x14e>
lea    -0x130(%rbp),%rdi
mov    -0x18c(%rbp),%esi
mov    -0x190(%rbp),%edx
mov    -0x194(%rbp),%ecx
mov    -0x188(%rbp),%r8
call   10a0 <authunix_create@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdx
mov    $0x1,%eax
xor    %ecx,%ecx
cmp    $0x0,%rdx
cmovne %ecx,%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%esi
lea    0xd54(%rip),%rdi
call   1030 <printf@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1a0,%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(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32*
%10 = alloca [256 x i8]
%11 = alloca i32
%12 = alloca [16 x i32]
%13 = alloca i32*
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
store i32 1, i32* %7
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 2
%19 = load i8*, i8** %18
%20 = call i32 @atoi(i8* %19)
store i32 %20, i32* %8
store i32* null, i32** %9
%21 = getelementptr inbounds [16 x i32], [16 x i32]* %12, i64 0, i64 0
store i32* %21, i32** %13
%22 = call i32 (...) @geteuid()
store i32 %22, i32* %14
%23 = call i32 (...) @getegid()
store i32 %23, i32* %15
%24 = getelementptr inbounds [16 x i32], [16 x i32]* %12, i64 0, i64 0
%25 = call i32 @getgroups(i32 16, i32* %24)
store i32 %25, i32* %16
%26 = load i32, i32* %16
%27 = icmp eq i32 %26, -1
br i1 %27, label %28, label %32
28: ; preds = %2
%29 = load i32, i32* @stderr
%30 = load i32, i32* %14
%31 = call i32 (i32, i8*, ...) @fprintf(i32 %29, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i32 %30)
store i32 1, i32* %3
br label %54
32: ; preds = %2
%33 = getelementptr inbounds [256 x i8], [256 x i8]* %10, i64 0, i64 0
%34 = call i32 @gethostname(i8* %33, i32 256)
store i32 %34, i32* %11
%35 = load i32, i32* %11
%36 = icmp eq i32 %35, -1
br i1 %36, label %37, label %40
37: ; preds = %32
%38 = load i32, i32* @stderr
%39 = call i32 (i32, i8*, ...) @fprintf(i32 %38, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %3
br label %54
40: ; preds = %32
%41 = getelementptr inbounds [256 x i8], [256 x i8]* %10, i64 0, i64 0
%42 = load i32, i32* %14
%43 = load i32, i32* %15
%44 = load i32, i32* %16
%45 = load i32*, i32** %13
%46 = call i32* @authunix_create(i8* %41, i32 %42, i32 %43, i32 %44, i32* %45)
store i32* %46, i32** %9
%47 = load i32*, i32** %9
%48 = icmp ne i32* %47, null
%49 = zext i1 %48 to i64
%50 = select i1 %48, i32 0, i32 1
store i32 %50, i32* %7
%51 = load i32, i32* %7
%52 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %51)
%53 = load i32, i32* %7
store i32 %53, i32* %3
br label %54
54: ; preds = %40, %37, %28
%55 = load i32, i32* %3
ret i32 %55
}

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(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [256 x i8]
%4 = alloca [16 x i32]
%5 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%6 = bitcast [16 x i32]* %4 to i8*
%7 = getelementptr inbounds [16 x i32], [16 x i32]* %4, i64 0, i64 0
%8 = tail call i32 (...) @geteuid()
%9 = tail call i32 (...) @getegid()
%10 = call i32 @getgroups(i32 16, i32* %7)
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %15
12: ; preds = %2
%13 = load i32, i32* @stderr
%14 = call i32 (i32, i8*, ...) @fprintf(i32 %13, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i32 %8)
br label %26
15: ; preds = %2
%16 = call i32 @gethostname(i8* %5, i32 256)
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %21
18: ; preds = %15
%19 = load i32, i32* @stderr
%20 = call i32 (i32, i8*, ...) @fprintf(i32 %19, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
br label %26
21: ; preds = %15
%22 = call i32* @authunix_create(i8* %5, i32 %8, i32 %9, i32 %10, i32* %7)
%23 = icmp eq i32* %22, null
%24 = zext i1 %23 to i32
%25 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %24)
br label %26
26: ; preds = %21, %18, %12
%27 = phi i32 [ 1, %12 ], [ 1, %18 ], [ %24, %21 ]
ret i32 %27
}