#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 passwd {
  int /*<<< orphan*/ pw_name;
};
struct group {
  char **gr_mem;
};
typedef int /*<<< orphan*/ gid_t;

/* Variables and functions */
int /*<<< orphan*/ geteuid();
struct group *getgrgid(int /*<<< orphan*/);
struct passwd *getpwuid(int /*<<< orphan*/);
scalar_t__ strcmp(int /*<<< orphan*/, char *);
int _file_rwx_g(gid_t gid) {
  struct passwd *passwd;
  struct group *group;
  char **p;
  if ((passwd = getpwuid(geteuid())) == NULL)
    return 0;
  if ((group = getgrgid(gid)) == NULL)
    return 0;
  for (p = group->gr_mem; *p != NULL; p++)
    if (strcmp(passwd->pw_name, *p) == 0)
      return 1;
  return 0;
}


x86 assembly (clang, -O0):
<_file_rwx_g>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    $0x0,%al
call   1050 <geteuid@plt>
mov    %eax,%edi
call   1030 <getpwuid@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    1173 <_file_rwx_g+0x33>
movl   $0x0,-0x4(%rbp)
jmp    11f3 <_file_rwx_g+0xb3>
mov    -0x8(%rbp),%edi
call   1040 <getgrgid@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    1195 <_file_rwx_g+0x55>
movl   $0x0,-0x4(%rbp)
jmp    11f3 <_file_rwx_g+0xb3>
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmpq   $0x0,(%rax)
je     11ec <_file_rwx_g+0xac>
mov    -0x10(%rbp),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rax
mov    (%rax),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    11d6 <_file_rwx_g+0x96>
movl   $0x1,-0x4(%rbp)
jmp    11f3 <_file_rwx_g+0xb3>
jmp    11db <_file_rwx_g+0x9b>
mov    -0x20(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x20(%rbp)
jmp    11a0 <_file_rwx_g+0x60>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_file_rwx_g>:
push   %rbp
push   %r14
push   %rbx
mov    %edi,%ebp
xor    %r14d,%r14d
xor    %eax,%eax
call   1050 <geteuid@plt>
mov    %eax,%edi
call   1030 <getpwuid@plt>
test   %rax,%rax
je     11a1 <_file_rwx_g+0x61>
mov    %rax,%rbx
mov    %ebp,%edi
call   1040 <getgrgid@plt>
test   %rax,%rax
je     11a1 <_file_rwx_g+0x61>
mov    (%rax),%rbp
mov    0x0(%rbp),%rsi
test   %rsi,%rsi
je     11a1 <_file_rwx_g+0x61>
add    $0x8,%rbp
nopl   0x0(%rax,%rax,1)
mov    (%rbx),%edi
call   1060 <strcmp@plt>
test   %rax,%rax
je     119b <_file_rwx_g+0x5b>
mov    0x0(%rbp),%rsi
add    $0x8,%rbp
test   %rsi,%rsi
jne    1180 <_file_rwx_g+0x40>
jmp    11a1 <_file_rwx_g+0x61>
mov    $0x1,%r14d
mov    %r14d,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.passwd = type { i32 }
%struct.group = type { i8** }
define i32 @_file_rwx_g(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca %struct.passwd*
%5 = alloca %struct.group*
%6 = alloca i8**
store i32 %0, i32* %3
%7 = call i32 (...) @geteuid()
%8 = call %struct.passwd* @getpwuid(i32 %7)
store %struct.passwd* %8, %struct.passwd** %4
%9 = icmp eq %struct.passwd* %8, null
br i1 %9, label %10, label %11
10: ; preds = %1
store i32 0, i32* %2
br label %38
11: ; preds = %1
%12 = load i32, i32* %3
%13 = call %struct.group* @getgrgid(i32 %12)
store %struct.group* %13, %struct.group** %5
%14 = icmp eq %struct.group* %13, null
br i1 %14, label %15, label %16
15: ; preds = %11
store i32 0, i32* %2
br label %38
16: ; preds = %11
%17 = load %struct.group*, %struct.group** %5
%18 = getelementptr inbounds %struct.group, %struct.group* %17, i32 0, i32 0
%19 = load i8**, i8*** %18
store i8** %19, i8*** %6
br label %20
20: ; preds = %34, %16
%21 = load i8**, i8*** %6
%22 = load i8*, i8** %21
%23 = icmp ne i8* %22, null
br i1 %23, label %24, label %37
24: ; preds = %20
%25 = load %struct.passwd*, %struct.passwd** %4
%26 = getelementptr inbounds %struct.passwd, %struct.passwd* %25, i32 0, i32 0
%27 = load i32, i32* %26
%28 = load i8**, i8*** %6
%29 = load i8*, i8** %28
%30 = call i64 @strcmp(i32 %27, i8* %29)
%31 = icmp eq i64 %30, 0
br i1 %31, label %32, label %33
32: ; preds = %24
store i32 1, i32* %2
br label %38
33: ; preds = %24
br label %34
34: ; preds = %33
%35 = load i8**, i8*** %6
%36 = getelementptr inbounds i8*, i8** %35, i32 1
store i8** %36, i8*** %6
br label %20
37: ; preds = %20
store i32 0, i32* %2
br label %38
38: ; preds = %37, %32, %15, %10
%39 = load i32, i32* %2
ret i32 %39
}

LLVM IR (-O2):
%struct.passwd = type { i32 }
%struct.group = type { i8** }
define i32 @_file_rwx_g(i32 %0) {
%2 = tail call i32 (...) @geteuid()
%3 = tail call %struct.passwd* @getpwuid(i32 %2)
%4 = icmp eq %struct.passwd* %3, null
br i1 %4, label %24, label %5
5: ; preds = %1
%6 = tail call %struct.group* @getgrgid(i32 %0)
%7 = icmp eq %struct.group* %6, null
br i1 %7, label %24, label %8
8: ; preds = %5
%9 = getelementptr inbounds %struct.group, %struct.group* %6, i64 0, i32 0
%10 = load i8**, i8*** %9
%11 = getelementptr inbounds %struct.passwd, %struct.passwd* %3, i64 0, i32 0
%12 = load i8*, i8** %10
%13 = icmp eq i8* %12, null
br i1 %13, label %24, label %17
14: ; preds = %17
%15 = load i8*, i8** %23
%16 = icmp eq i8* %15, null
br i1 %16, label %24, label %17
17: ; preds = %8, %14
%18 = phi i8* [ %15, %14 ], [ %12, %8 ]
%19 = phi i8** [ %23, %14 ], [ %10, %8 ]
%20 = load i32, i32* %11
%21 = tail call i64 @strcmp(i32 %20, i8* %18)
%22 = icmp eq i64 %21, 0
%23 = getelementptr inbounds i8*, i8** %19, i64 1
br i1 %22, label %24, label %14
24: ; preds = %17, %14, %8, %5, %1
%25 = phi i32 [ 0, %1 ], [ 0, %5 ], [ 0, %8 ], [ 1, %17 ], [ 0, %14 ]
ret i32 %25
}