#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 group {
  scalar_t__ *gr_mem;
};
typedef int /*<<< orphan*/ grbuf;

/* Variables and functions */
scalar_t__ getgrnam_r(char const *, struct group *, char *, int,
                      struct group **);
int netgroup_match(char const *, char *, char const *);
scalar_t__ strcasecmp(char const *, scalar_t__);
scalar_t__ string_match(char const *, char const *);
int user_match(const char *tok, const char *string) {
  struct group grres, *group;
  char grbuf[1024];
  int i;
  if (tok[0] == '@') {
    return (netgroup_match(tok + 1, (char *)0, string));
  } else if (string_match(tok, string)) {
    return (1);
  } else if (getgrnam_r(tok, &grres, grbuf, sizeof(grbuf), &group) == 0 &&
             group != NULL) {
    for (i = 0; group->gr_mem[i]; i++)
      if (strcasecmp(string, group->gr_mem[i]) == 0)
        return (1);
  }
  return (0);
}


x86 assembly (clang, -O0):
<user_match>:
push   %rbp
mov    %rsp,%rbp
sub    $0x440,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x40,%eax
jne    1180 <user_match+0x40>
mov    -0x10(%rbp),%rdi
add    $0x1,%rdi
mov    -0x18(%rbp),%rdx
xor    %eax,%eax
mov    %eax,%esi
call   1040 <netgroup_match@plt>
mov    %eax,-0x4(%rbp)
jmp    1258 <user_match+0x118>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1060 <string_match@plt>
cmp    $0x0,%rax
je     11a3 <user_match+0x63>
movl   $0x1,-0x4(%rbp)
jmp    1258 <user_match+0x118>
mov    -0x10(%rbp),%rdi
lea    -0x430(%rbp),%rdx
lea    -0x20(%rbp),%rsi
mov    $0x400,%ecx
lea    -0x28(%rbp),%r8
call   1050 <getgrnam_r@plt>
cmp    $0x0,%rax
jne    1247 <user_match+0x107>
cmpq   $0x0,-0x28(%rbp)
je     1247 <user_match+0x107>
movl   $0x0,-0x434(%rbp)
mov    -0x28(%rbp),%rax
mov    (%rax),%rax
movslq -0x434(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
je     1242 <user_match+0x102>
mov    -0x18(%rbp),%rdi
mov    -0x28(%rbp),%rax
mov    (%rax),%rax
movslq -0x434(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
call   1030 <strcasecmp@plt>
cmp    $0x0,%rax
jne    1229 <user_match+0xe9>
movl   $0x1,-0x4(%rbp)
jmp    1258 <user_match+0x118>
jmp    122e <user_match+0xee>
mov    -0x434(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x434(%rbp)
jmp    11df <user_match+0x9f>
jmp    1247 <user_match+0x107>
jmp    124c <user_match+0x10c>
jmp    1251 <user_match+0x111>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x440,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<user_match>:
push   %rbp
push   %r14
push   %rbx
sub    $0x410,%rsp
mov    %rsi,%rbx
mov    %rdi,%rbp
cmpb   $0x40,(%rdi)
jne    1172 <user_match+0x32>
add    $0x1,%rbp
mov    %rbp,%rdi
xor    %esi,%esi
mov    %rbx,%rdx
add    $0x410,%rsp
pop    %rbx
pop    %r14
pop    %rbp
jmp    1040 <netgroup_match@plt>
mov    %rbp,%rdi
mov    %rbx,%rsi
call   1060 <string_match@plt>
mov    $0x1,%r14d
test   %rax,%rax
jne    11e4 <user_match+0xa4>
lea    0x8(%rsp),%rsi
lea    0x10(%rsp),%rdx
mov    %rsp,%r8
mov    %rbp,%rdi
mov    $0x400,%ecx
call   1050 <getgrnam_r@plt>
test   %rax,%rax
jne    11e1 <user_match+0xa1>
mov    (%rsp),%rax
test   %rax,%rax
je     11e1 <user_match+0xa1>
mov    (%rax),%rax
mov    (%rax),%rsi
test   %rsi,%rsi
je     11e1 <user_match+0xa1>
mov    $0x8,%ebp
mov    %rbx,%rdi
call   1030 <strcasecmp@plt>
test   %rax,%rax
je     11e4 <user_match+0xa4>
mov    (%rsp),%rax
mov    (%rax),%rax
mov    (%rax,%rbp,1),%rsi
add    $0x8,%rbp
test   %rsi,%rsi
jne    11c0 <user_match+0x80>
xor    %r14d,%r14d
mov    %r14d,%eax
add    $0x410,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.group = type { i64* }
define i32 @user_match(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca %struct.group
%7 = alloca %struct.group*
%8 = alloca [1024 x i8]
%9 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
%10 = load i8*, i8** %4
%11 = getelementptr inbounds i8, i8* %10, i64 0
%12 = load i8, i8* %11
%13 = sext i8 %12 to i32
%14 = icmp eq i32 %13, 64
br i1 %14, label %15, label %20
15: ; preds = %2
%16 = load i8*, i8** %4
%17 = getelementptr inbounds i8, i8* %16, i64 1
%18 = load i8*, i8** %5
%19 = call i32 @netgroup_match(i8* %17, i8* null, i8* %18)
store i32 %19, i32* %3
br label %64
20: ; preds = %2
%21 = load i8*, i8** %4
%22 = load i8*, i8** %5
%23 = call i64 @string_match(i8* %21, i8* %22)
%24 = icmp ne i64 %23, 0
br i1 %24, label %25, label %26
25: ; preds = %20
store i32 1, i32* %3
br label %64
26: ; preds = %20
%27 = load i8*, i8** %4
%28 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%29 = call i64 @getgrnam_r(i8* %27, %struct.group* %6, i8* %28, i32 1024, %struct.group** %7)
%30 = icmp eq i64 %29, 0
br i1 %30, label %31, label %61
31: ; preds = %26
%32 = load %struct.group*, %struct.group** %7
%33 = icmp ne %struct.group* %32, null
br i1 %33, label %34, label %61
34: ; preds = %31
store i32 0, i32* %9
br label %35
35: ; preds = %57, %34
%36 = load %struct.group*, %struct.group** %7
%37 = getelementptr inbounds %struct.group, %struct.group* %36, i32 0, i32 0
%38 = load i64*, i64** %37
%39 = load i32, i32* %9
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i64, i64* %38, i64 %40
%42 = load i64, i64* %41
%43 = icmp ne i64 %42, 0
br i1 %43, label %44, label %60
44: ; preds = %35
%45 = load i8*, i8** %5
%46 = load %struct.group*, %struct.group** %7
%47 = getelementptr inbounds %struct.group, %struct.group* %46, i32 0, i32 0
%48 = load i64*, i64** %47
%49 = load i32, i32* %9
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds i64, i64* %48, i64 %50
%52 = load i64, i64* %51
%53 = call i64 @strcasecmp(i8* %45, i64 %52)
%54 = icmp eq i64 %53, 0
br i1 %54, label %55, label %56
55: ; preds = %44
store i32 1, i32* %3
br label %64
56: ; preds = %44
br label %57
57: ; preds = %56
%58 = load i32, i32* %9
%59 = add nsw i32 %58, 1
store i32 %59, i32* %9
br label %35
60: ; preds = %35
br label %61
61: ; preds = %60, %31, %26
br label %62
62: ; preds = %61
br label %63
63: ; preds = %62
store i32 0, i32* %3
br label %64
64: ; preds = %63, %55, %25, %15
%65 = load i32, i32* %3
ret i32 %65
}

LLVM IR (-O2):
%struct.group = type { i64* }
define i32 @user_match(i8* %0, i8* %1) {
%3 = alloca %struct.group
%4 = alloca %struct.group*
%5 = alloca [1024 x i8]
%6 = bitcast %struct.group* %3 to i8*
%7 = bitcast %struct.group** %4 to i8*
%8 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%9 = load i8, i8* %0
%10 = icmp eq i8 %9, 64
br i1 %10, label %11, label %14
11: ; preds = %2
%12 = getelementptr inbounds i8, i8* %0, i64 1
%13 = tail call i32 @netgroup_match(i8* %12, i8* null, i8* %1)
br label %41
14: ; preds = %2
%15 = tail call i64 @string_match(i8* %0, i8* %1)
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %41
17: ; preds = %14
%18 = call i64 @getgrnam_r(i8* %0, %struct.group* %3, i8* %8, i32 1024, %struct.group** %4)
%19 = icmp eq i64 %18, 0
%20 = load %struct.group*, %struct.group** %4
%21 = icmp ne %struct.group* %20, null
%22 = select i1 %19, i1 %21, i1 false
br i1 %22, label %23, label %41
23: ; preds = %17
%24 = getelementptr inbounds %struct.group, %struct.group* %20, i64 0, i32 0
%25 = load i64*, i64** %24
%26 = load i64, i64* %25
%27 = icmp eq i64 %26, 0
br i1 %27, label %41, label %35
28: ; preds = %35
%29 = load %struct.group*, %struct.group** %4
%30 = getelementptr inbounds %struct.group, %struct.group* %29, i64 0, i32 0
%31 = load i64*, i64** %30
%32 = getelementptr inbounds i64, i64* %31, i64 %40
%33 = load i64, i64* %32
%34 = icmp eq i64 %33, 0
br i1 %34, label %41, label %35
35: ; preds = %23, %28
%36 = phi i64 [ %40, %28 ], [ 0, %23 ]
%37 = phi i64 [ %33, %28 ], [ %26, %23 ]
%38 = call i64 @strcasecmp(i8* %1, i64 %37)
%39 = icmp eq i64 %38, 0
%40 = add nuw i64 %36, 1
br i1 %39, label %41, label %28
41: ; preds = %35, %28, %23, %17, %14, %11
%42 = phi i32 [ %13, %11 ], [ 1, %14 ], [ 0, %17 ], [ 0, %23 ], [ 1, %35 ], [ 0, %28 ]
ret i32 %42
}