#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 unsigned int gid_t;

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ free(unsigned int *);
unsigned int get_group_by_name(char *);
int getgroups(int, unsigned int *);
scalar_t__ malloc(int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stderr;
int system_user_in_audiogroup() {
  gid_t *list = (gid_t *)malloc(100 * sizeof(gid_t));
  int num_groups, i = 0, found = 0;
  unsigned int gid;
  if (NULL == list) {
    perror("Cannot allocate group list structure");
    exit(EXIT_FAILURE);
  }
  gid = get_group_by_name("audio");
  if (0 == gid) {
    fprintf(stderr, "No audio group found\n");
    exit(EXIT_FAILURE);
  }
  num_groups = getgroups(100, list);
  while (i < num_groups) {
    if (list[i] == gid) {
      found = 1;
      i = num_groups;
    }
    i++;
  }
  free(list);
  return found;
}


x86 assembly (clang, -O0):
<system_user_in_audiogroup>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    $0x190,%edi
call   1070 <malloc@plt>
mov    %rax,-0x8(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
xor    %eax,%eax
cmp    -0x8(%rbp),%rax
jne    11ba <system_user_in_audiogroup+0x4a>
lea    0xe59(%rip),%rdi
call   1080 <perror@plt>
mov    0x2e25(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
lea    0xe64(%rip),%rdi
call   1060 <get_group_by_name@plt>
mov    %eax,-0x18(%rbp)
xor    %eax,%eax
cmp    -0x18(%rbp),%eax
jne    11f7 <system_user_in_audiogroup+0x87>
mov    0x2e05(%rip),%rax
mov    (%rax),%edi
lea    0xe47(%rip),%rsi
call   1040 <fprintf@plt>
mov    0x2de8(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
mov    -0x8(%rbp),%rsi
mov    $0x64,%edi
call   1050 <getgroups@plt>
mov    %eax,-0xc(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1243 <system_user_in_audiogroup+0xd3>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
cmp    -0x18(%rbp),%eax
jne    1235 <system_user_in_audiogroup+0xc5>
movl   $0x1,-0x14(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1208 <system_user_in_audiogroup+0x98>
mov    -0x8(%rbp),%rdi
call   1030 <free@plt>
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<system_user_in_audiogroup>:
push   %rbp
push   %r14
push   %rbx
mov    $0x190,%edi
call   1070 <malloc@plt>
test   %rax,%rax
je     11e2 <system_user_in_audiogroup+0x72>
mov    %rax,%r14
lea    0xe98(%rip),%rdi
call   1060 <get_group_by_name@plt>
test   %eax,%eax
je     11f0 <system_user_in_audiogroup+0x80>
mov    %eax,%ebp
mov    $0x64,%edi
mov    %r14,%rsi
call   1050 <getgroups@plt>
test   %eax,%eax
jle    11d1 <system_user_in_audiogroup+0x61>
xor    %ecx,%ecx
xor    %edx,%edx
jmp    11bb <system_user_in_audiogroup+0x4b>
nop
add    $0x1,%esi
mov    %esi,%ecx
mov    %ebx,%edx
cmp    %eax,%esi
jge    11d3 <system_user_in_audiogroup+0x63>
movslq %ecx,%rdi
mov    $0x1,%ebx
mov    %eax,%esi
cmp    %ebp,(%r14,%rdi,4)
je     11b0 <system_user_in_audiogroup+0x40>
mov    %edx,%ebx
mov    %ecx,%esi
jmp    11b0 <system_user_in_audiogroup+0x40>
xor    %ebx,%ebx
mov    %r14,%rdi
call   1030 <free@plt>
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xe17(%rip),%rdi
call   1080 <perror@plt>
jmp    1205 <system_user_in_audiogroup+0x95>
mov    0x2de9(%rip),%rax
mov    (%rax),%edi
lea    0xe2b(%rip),%rsi
call   1040 <fprintf@plt>
mov    0x2dcc(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [37 x i8] c"Cannot allocate group list structure\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [6 x i8] c"audio\00"
@stderr = global i32 0
@.str.2 = [22 x i8] c"No audio group found\0A\00"
define i32 @system_user_in_audiogroup() {
%1 = alloca i32*
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = call i64 @malloc(i32 400)
%7 = inttoptr i64 %6 to i32*
store i32* %7, i32** %1
store i32 0, i32* %3
store i32 0, i32* %4
%8 = load i32*, i32** %1
%9 = icmp eq i32* null, %8
br i1 %9, label %10, label %14
10: ; preds = %0
%11 = call i32 @perror(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0))
%12 = load i32, i32* @EXIT_FAILURE
%13 = call i32 @exit(i32 %12)
unreachable
14: ; preds = %0
%15 = call i32 @get_group_by_name(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
store i32 %15, i32* %5
%16 = load i32, i32* %5
%17 = icmp eq i32 0, %16
br i1 %17, label %18, label %23
18: ; preds = %14
%19 = load i32, i32* @stderr
%20 = call i32 @fprintf(i32 %19, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0))
%21 = load i32, i32* @EXIT_FAILURE
%22 = call i32 @exit(i32 %21)
unreachable
23: ; preds = %14
%24 = load i32*, i32** %1
%25 = call i32 @getgroups(i32 100, i32* %24)
store i32 %25, i32* %2
br label %26
26: ; preds = %40, %23
%27 = load i32, i32* %3
%28 = load i32, i32* %2
%29 = icmp slt i32 %27, %28
br i1 %29, label %30, label %43
30: ; preds = %26
%31 = load i32*, i32** %1
%32 = load i32, i32* %3
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i32, i32* %31, i64 %33
%35 = load i32, i32* %34
%36 = load i32, i32* %5
%37 = icmp eq i32 %35, %36
br i1 %37, label %38, label %40
38: ; preds = %30
store i32 1, i32* %4
%39 = load i32, i32* %2
store i32 %39, i32* %3
br label %40
40: ; preds = %38, %30
%41 = load i32, i32* %3
%42 = add nsw i32 %41, 1
store i32 %42, i32* %3
br label %26
43: ; preds = %26
%44 = load i32*, i32** %1
%45 = call i32 @free(i32* %44)
%46 = load i32, i32* %4
ret i32 %46
}

LLVM IR (-O2):
@.str = [37 x i8] c"Cannot allocate group list structure\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [6 x i8] c"audio\00"
@stderr = global i32 0
@.str.2 = [22 x i8] c"No audio group found\0A\00"
define i32 @system_user_in_audiogroup() {
%1 = tail call i64 @malloc(i32 400)
%2 = inttoptr i64 %1 to i32*
%3 = icmp eq i64 %1, 0
br i1 %3, label %4, label %8
4: ; preds = %0
%5 = tail call i32 @perror(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0))
%6 = load i32, i32* @EXIT_FAILURE
%7 = tail call i32 @exit(i32 %6)
unreachable
8: ; preds = %0
%9 = tail call i32 @get_group_by_name(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %16
11: ; preds = %8
%12 = load i32, i32* @stderr
%13 = tail call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0))
%14 = load i32, i32* @EXIT_FAILURE
%15 = tail call i32 @exit(i32 %14)
unreachable
16: ; preds = %8
%17 = tail call i32 @getgroups(i32 100, i32* %2)
%18 = icmp sgt i32 %17, 0
br i1 %18, label %19, label %30
19: ; preds = %16, %19
%20 = phi i32 [ %28, %19 ], [ 0, %16 ]
%21 = phi i32 [ %26, %19 ], [ 0, %16 ]
%22 = sext i32 %20 to i64
%23 = getelementptr inbounds i32, i32* %2, i64 %22
%24 = load i32, i32* %23
%25 = icmp eq i32 %24, %9
%26 = select i1 %25, i32 1, i32 %21
%27 = select i1 %25, i32 %17, i32 %20
%28 = add nsw i32 %27, 1
%29 = icmp slt i32 %28, %17
br i1 %29, label %19, label %30
30: ; preds = %19, %16
%31 = phi i32 [ 0, %16 ], [ %26, %19 ]
%32 = tail call i32 @free(i32* %2)
ret i32 %31
}