#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;
};

/* Variables and functions */
struct group *getgrnam(char const *);
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 *group;
  int i;
  if (tok[0] == '@') {
    return (netgroup_match(tok + 1, (char *)0, string));
  } else if (string_match(tok, string)) {
    return (1);
  } else if ((group = getgrnam(tok)) != 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    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x40,%eax
jne    117d <user_match+0x3d>
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    122b <user_match+0xeb>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1060 <string_match@plt>
cmp    $0x0,%rax
je     11a0 <user_match+0x60>
movl   $0x1,-0x4(%rbp)
jmp    122b <user_match+0xeb>
mov    -0x10(%rbp),%rdi
call   1050 <getgrnam@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     121a <user_match+0xda>
movl   $0x0,-0x24(%rbp)
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
movslq -0x24(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
je     1215 <user_match+0xd5>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
call   1030 <strcasecmp@plt>
cmp    $0x0,%rax
jne    1202 <user_match+0xc2>
movl   $0x1,-0x4(%rbp)
jmp    122b <user_match+0xeb>
jmp    1207 <user_match+0xc7>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11be <user_match+0x7e>
jmp    121a <user_match+0xda>
jmp    121f <user_match+0xdf>
jmp    1224 <user_match+0xe4>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<user_match>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%rbp
cmpb   $0x40,(%rdi)
jne    116d <user_match+0x2d>
add    $0x1,%rbp
mov    %rbp,%rdi
xor    %esi,%esi
mov    %rbx,%rdx
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
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    11d0 <user_match+0x90>
mov    %rbp,%rdi
call   1050 <getgrnam@plt>
test   %rax,%rax
je     11cd <user_match+0x8d>
mov    %rax,%r15
mov    (%rax),%rax
mov    (%rax),%rsi
test   %rsi,%rsi
je     11cd <user_match+0x8d>
mov    $0x8,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rbx,%rdi
call   1030 <strcasecmp@plt>
test   %rax,%rax
je     11d0 <user_match+0x90>
mov    (%r15),%rax
mov    (%rax,%rbp,1),%rsi
add    $0x8,%rbp
test   %rsi,%rsi
jne    11b0 <user_match+0x70>
xor    %r14d,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
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 i32
store i8* %0, i8** %4
store i8* %1, i8** %5
%8 = load i8*, i8** %4
%9 = getelementptr inbounds i8, i8* %8, i64 0
%10 = load i8, i8* %9
%11 = sext i8 %10 to i32
%12 = icmp eq i32 %11, 64
br i1 %12, label %13, label %18
13: ; preds = %2
%14 = load i8*, i8** %4
%15 = getelementptr inbounds i8, i8* %14, i64 1
%16 = load i8*, i8** %5
%17 = call i32 @netgroup_match(i8* %15, i8* null, i8* %16)
store i32 %17, i32* %3
br label %58
18: ; preds = %2
%19 = load i8*, i8** %4
%20 = load i8*, i8** %5
%21 = call i64 @string_match(i8* %19, i8* %20)
%22 = icmp ne i64 %21, 0
br i1 %22, label %23, label %24
23: ; preds = %18
store i32 1, i32* %3
br label %58
24: ; preds = %18
%25 = load i8*, i8** %4
%26 = call %struct.group* @getgrnam(i8* %25)
store %struct.group* %26, %struct.group** %6
%27 = icmp ne %struct.group* %26, null
br i1 %27, label %28, label %55
28: ; preds = %24
store i32 0, i32* %7
br label %29
29: ; preds = %51, %28
%30 = load %struct.group*, %struct.group** %6
%31 = getelementptr inbounds %struct.group, %struct.group* %30, i32 0, i32 0
%32 = load i64*, i64** %31
%33 = load i32, i32* %7
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i64, i64* %32, i64 %34
%36 = load i64, i64* %35
%37 = icmp ne i64 %36, 0
br i1 %37, label %38, label %54
38: ; preds = %29
%39 = load i8*, i8** %5
%40 = load %struct.group*, %struct.group** %6
%41 = getelementptr inbounds %struct.group, %struct.group* %40, i32 0, i32 0
%42 = load i64*, i64** %41
%43 = load i32, i32* %7
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds i64, i64* %42, i64 %44
%46 = load i64, i64* %45
%47 = call i64 @strcasecmp(i8* %39, i64 %46)
%48 = icmp eq i64 %47, 0
br i1 %48, label %49, label %50
49: ; preds = %38
store i32 1, i32* %3
br label %58
50: ; preds = %38
br label %51
51: ; preds = %50
%52 = load i32, i32* %7
%53 = add nsw i32 %52, 1
store i32 %53, i32* %7
br label %29
54: ; preds = %29
br label %55
55: ; preds = %54, %24
br label %56
56: ; preds = %55
br label %57
57: ; preds = %56
store i32 0, i32* %3
br label %58
58: ; preds = %57, %49, %23, %13
%59 = load i32, i32* %3
ret i32 %59
}

LLVM IR (-O2):
%struct.group = type { i64* }
define i32 @user_match(i8* %0, i8* %1) {
%3 = load i8, i8* %0
%4 = icmp eq i8 %3, 64
br i1 %4, label %5, label %8
5: ; preds = %2
%6 = getelementptr inbounds i8, i8* %0, i64 1
%7 = tail call i32 @netgroup_match(i8* %6, i8* null, i8* %1)
br label %30
8: ; preds = %2
%9 = tail call i64 @string_match(i8* %0, i8* %1)
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %30
11: ; preds = %8
%12 = tail call %struct.group* @getgrnam(i8* %0)
%13 = icmp eq %struct.group* %12, null
br i1 %13, label %30, label %14
14: ; preds = %11
%15 = getelementptr inbounds %struct.group, %struct.group* %12, i64 0, i32 0
%16 = load i64*, i64** %15
%17 = load i64, i64* %16
%18 = icmp eq i64 %17, 0
br i1 %18, label %30, label %24
19: ; preds = %24
%20 = load i64*, i64** %15
%21 = getelementptr inbounds i64, i64* %20, i64 %29
%22 = load i64, i64* %21
%23 = icmp eq i64 %22, 0
br i1 %23, label %30, label %24
24: ; preds = %14, %19
%25 = phi i64 [ %29, %19 ], [ 0, %14 ]
%26 = phi i64 [ %22, %19 ], [ %17, %14 ]
%27 = tail call i64 @strcasecmp(i8* %1, i64 %26)
%28 = icmp eq i64 %27, 0
%29 = add nuw i64 %25, 1
br i1 %28, label %30, label %19
30: ; preds = %24, %19, %14, %11, %8, %5
%31 = phi i32 [ %7, %5 ], [ 1, %8 ], [ 0, %11 ], [ 0, %14 ], [ 1, %24 ], [ 0, %19 ]
ret i32 %31
}