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

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
struct group *getgrnam(char *);
int /*<<< orphan*/ stderr;
scalar_t__ strcmp(int /*<<< orphan*/, char *);
int validate_user_gr(char *username, char *groupname) {
  struct group *g;
  if ((g = getgrnam(groupname)) == NULL) {
    fprintf(stderr, "helper: Group does not exist '%s'\n", groupname);
    return 0;
  } else {
    while (*(g->gr_mem) != NULL) {
      if (strcmp(*((g->gr_mem)++), username) == 0) {
        return 1;
      }
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<validate_user_gr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <getgrnam@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    117c <validate_user_gr+0x4c>
mov    0x2e82(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
lea    0xe95(%rip),%rsi
call   1040 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    11d8 <validate_user_gr+0xa8>
jmp    1181 <validate_user_gr+0x51>
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
cmpq   $0x0,(%rax)
je     11cc <validate_user_gr+0x9c>
mov    -0x20(%rbp),%rcx
mov    (%rcx),%rax
mov    %rax,%rdx
add    $0x8,%rdx
mov    %rdx,(%rcx)
mov    (%rax),%rax
mov    %eax,%edi
mov    -0x10(%rbp),%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%rax
jne    11c7 <validate_user_gr+0x97>
movl   $0x1,-0x4(%rbp)
jmp    11d8 <validate_user_gr+0xa8>
jmp    1181 <validate_user_gr+0x51>
jmp    11d1 <validate_user_gr+0xa1>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<validate_user_gr>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r15
mov    %rdi,%r14
mov    %rsi,%rdi
call   1050 <getgrnam@plt>
test   %rax,%rax
je     1176 <validate_user_gr+0x46>
mov    %rax,%rbx
nopl   0x0(%rax,%rax,1)
mov    (%rbx),%rax
cmpq   $0x0,(%rax)
je     118e <validate_user_gr+0x5e>
lea    0x8(%rax),%rcx
mov    %rcx,(%rbx)
mov    (%rax),%edi
mov    %r14,%rsi
call   1030 <strcmp@plt>
test   %rax,%rax
jne    1150 <validate_user_gr+0x20>
mov    $0x1,%eax
jmp    1190 <validate_user_gr+0x60>
mov    0x2e63(%rip),%rax
mov    (%rax),%edi
lea    0xe7a(%rip),%rsi
mov    %r15,%rdx
call   1040 <fprintf@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.group = type { i32** }
@stderr = global i32 0
@.str = [35 x i8] c"helper: Group does not exist '%s'\0A\00"
define i32 @validate_user_gr(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca %struct.group*
store i8* %0, i8** %4
store i8* %1, i8** %5
%7 = load i8*, i8** %5
%8 = call %struct.group* @getgrnam(i8* %7)
store %struct.group* %8, %struct.group** %6
%9 = icmp eq %struct.group* %8, null
br i1 %9, label %10, label %14
10: ; preds = %2
%11 = load i32, i32* @stderr
%12 = load i8*, i8** %5
%13 = call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i8* %12)
store i32 0, i32* %3
br label %35
14: ; preds = %2
br label %15
15: ; preds = %32, %14
%16 = load %struct.group*, %struct.group** %6
%17 = getelementptr inbounds %struct.group, %struct.group* %16, i32 0, i32 0
%18 = load i32**, i32*** %17
%19 = load i32*, i32** %18
%20 = icmp ne i32* %19, null
br i1 %20, label %21, label %33
21: ; preds = %15
%22 = load %struct.group*, %struct.group** %6
%23 = getelementptr inbounds %struct.group, %struct.group* %22, i32 0, i32 0
%24 = load i32**, i32*** %23
%25 = getelementptr inbounds i32*, i32** %24, i32 1
store i32** %25, i32*** %23
%26 = load i32*, i32** %24
%27 = ptrtoint i32* %26 to i32
%28 = load i8*, i8** %4
%29 = call i64 @strcmp(i32 %27, i8* %28)
%30 = icmp eq i64 %29, 0
br i1 %30, label %31, label %32
31: ; preds = %21
store i32 1, i32* %3
br label %35
32: ; preds = %21
br label %15
33: ; preds = %15
br label %34
34: ; preds = %33
store i32 0, i32* %3
br label %35
35: ; preds = %34, %31, %10
%36 = load i32, i32* %3
ret i32 %36
}

LLVM IR (-O2):
%struct.group = type { i32** }
@stderr = global i32 0
@.str = [35 x i8] c"helper: Group does not exist '%s'\0A\00"
define i32 @validate_user_gr(i8* %0, i8* %1) {
%3 = tail call %struct.group* @getgrnam(i8* %1)
%4 = icmp eq %struct.group* %3, null
br i1 %4, label %7, label %5
5: ; preds = %2
%6 = getelementptr inbounds %struct.group, %struct.group* %3, i64 0, i32 0
br label %10
7: ; preds = %2
%8 = load i32, i32* @stderr
%9 = tail call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i8* %1)
br label %21
10: ; preds = %5, %14
%11 = load i32**, i32*** %6
%12 = load i32*, i32** %11
%13 = icmp eq i32* %12, null
br i1 %13, label %21, label %14
14: ; preds = %10
%15 = getelementptr inbounds i32*, i32** %11, i64 1
store i32** %15, i32*** %6
%16 = load i32*, i32** %11
%17 = ptrtoint i32* %16 to i64
%18 = trunc i64 %17 to i32
%19 = tail call i64 @strcmp(i32 %18, i8* %0)
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %10
21: ; preds = %10, %14, %7
%22 = phi i32 [ 0, %7 ], [ 0, %10 ], [ 1, %14 ]
ret i32 %22
}