#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 */

/* Variables and functions */
int /*<<< orphan*/ LOG_ERR;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ free(char *);
scalar_t__ malloc(scalar_t__);
int smbftpd_auth_is_user_in_group(char const *, char *);
int /*<<< orphan*/ str_trim_space(char *);
scalar_t__ strcmp(char const *, char *);
int /*<<< orphan*/ strcpy(char *, char const *);
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
scalar_t__ strlen(char const *);
char *strtok(char *, char *);
int /*<<< orphan*/ syslog(int /*<<< orphan*/, char *, char *, int,
                          int /*<<< orphan*/, int /*<<< orphan*/);
int is_user_in_list(const char *user, const char *list) {
  char *tmplist = NULL, *token;
  int err = 0;
  if (!user || !list) {
    return err;
  }
  tmplist = (char *)malloc(strlen(list) + 1);
  if (tmplist == NULL) {
    syslog(LOG_ERR, "%s (%d) failed to allocate memory, errno:%d(%s)",
           "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
           "2022-01-22/02-19-57/repos/jchuang1977/smbftpd-2.2/refs/heads/"
           "master/misc.c",
           175, errno, strerror(errno));
    return err;
  }
  strcpy(tmplist, list);
  for (token = strtok(tmplist, ","); token; token = strtok(NULL, ",")) {
    str_trim_space(token);
    if (*token != '@') {
      if (0 == strcmp(user, token)) {
        err = 1;
        break;
      }
    } else {
      if (1 == smbftpd_auth_is_user_in_group(user, token + 1)) {
        err = 1;
        goto Error;
      }
    }
  }
Error:
  if (tmplist != NULL) {
    free(tmplist);
  }
  return err;
}


x86 assembly (clang, -O0):
<is_user_in_list>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movl   $0x0,-0x2c(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11d5 <is_user_in_list+0x35>
cmpq   $0x0,-0x18(%rbp)
jne    11e0 <is_user_in_list+0x40>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1336 <is_user_in_list+0x196>
mov    -0x18(%rbp),%rdi
call   1060 <strlen@plt>
mov    %rax,%rdi
add    $0x1,%rdi
call   1090 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1257 <is_user_in_list+0xb7>
mov    0x2dc5(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
mov    0x2dc9(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x30(%rbp)
mov    0x2dbd(%rip),%rax
mov    (%rax),%edi
call   10c0 <strerror@plt>
mov    -0x34(%rbp),%edi
mov    -0x30(%rbp),%r8d
mov    %eax,%r9d
lea    0xdc5(%rip),%rsi
lea    0xdee(%rip),%rdx
mov    $0xaf,%ecx
call   10a0 <syslog@plt>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1336 <is_user_in_list+0x196>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x20(%rbp),%rdi
lea    0xe4c(%rip),%rsi
call   10b0 <strtok@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     1317 <is_user_in_list+0x177>
mov    -0x28(%rbp),%rdi
call   1070 <str_trim_space@plt>
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x40,%eax
je     12c8 <is_user_in_list+0x128>
mov    -0x10(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1080 <strcmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jne    12c3 <is_user_in_list+0x123>
movl   $0x1,-0x2c(%rbp)
jmp    1317 <is_user_in_list+0x177>
jmp    12f9 <is_user_in_list+0x159>
mov    -0x10(%rbp),%rdi
mov    -0x28(%rbp),%rsi
add    $0x1,%rsi
call   1050 <smbftpd_auth_is_user_in_group@plt>
mov    %eax,%ecx
mov    $0x1,%eax
cmp    %ecx,%eax
jne    12f4 <is_user_in_list+0x154>
movl   $0x1,-0x2c(%rbp)
jmp    131c <is_user_in_list+0x17c>
jmp    12f9 <is_user_in_list+0x159>
jmp    12fe <is_user_in_list+0x15e>
xor    %eax,%eax
mov    %eax,%edi
lea    0xdb2(%rip),%rsi
call   10b0 <strtok@plt>
mov    %rax,-0x28(%rbp)
jmp    1278 <is_user_in_list+0xd8>
jmp    131c <is_user_in_list+0x17c>
cmpq   $0x0,-0x20(%rbp)
je     1330 <is_user_in_list+0x190>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<is_user_in_list>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
xor    %r13d,%r13d
test   %rdi,%rdi
je     12b4 <is_user_in_list+0x114>
mov    %rsi,%rbx
test   %rsi,%rsi
je     12b4 <is_user_in_list+0x114>
mov    %rdi,%r15
mov    %rbx,%rdi
call   1060 <strlen@plt>
lea    0x1(%rax),%rdi
call   1090 <malloc@plt>
test   %rax,%rax
je     126e <is_user_in_list+0xce>
mov    %rax,%r14
mov    %rax,%rdi
mov    %rbx,%rsi
call   1040 <strcpy@plt>
lea    0xec6(%rip),%rsi
mov    %r14,%rdi
call   10b0 <strtok@plt>
test   %rax,%rax
je     12a9 <is_user_in_list+0x109>
mov    %rax,%rbx
lea    0xeab(%rip),%r12
jmp    1245 <is_user_in_list+0xa5>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r15,%rdi
mov    %rbx,%rsi
call   1080 <strcmp@plt>
test   %rax,%rax
je     1266 <is_user_in_list+0xc6>
xor    %r13d,%r13d
xor    %edi,%edi
mov    %r12,%rsi
call   10b0 <strtok@plt>
mov    %rax,%rbx
test   %rax,%rax
je     12ac <is_user_in_list+0x10c>
mov    %rbx,%rdi
call   1070 <str_trim_space@plt>
cmpb   $0x40,(%rbx)
jne    1220 <is_user_in_list+0x80>
add    $0x1,%rbx
mov    %r15,%rdi
mov    %rbx,%rsi
call   1050 <smbftpd_auth_is_user_in_group@plt>
cmp    $0x1,%eax
jne    1230 <is_user_in_list+0x90>
mov    $0x1,%r13d
jmp    12ac <is_user_in_list+0x10c>
mov    0x2d5b(%rip),%rax
mov    (%rax),%ebx
mov    0x2d62(%rip),%rax
mov    (%rax),%ebp
mov    %ebp,%edi
call   10c0 <strerror@plt>
lea    0xd72(%rip),%rsi
lea    0xd9b(%rip),%rdx
mov    %ebx,%edi
mov    $0xaf,%ecx
mov    %ebp,%r8d
mov    %eax,%r9d
call   10a0 <syslog@plt>
jmp    12b4 <is_user_in_list+0x114>
xor    %r13d,%r13d
mov    %r14,%rdi
call   1030 <free@plt>
mov    %r13d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@LOG_ERR = global i32 0
@.str = [48 x i8] c"%s (%d) failed to allocate memory, errno:%d(%s)\00"
@.str.1 = [139 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/jchuang1977/smbftpd-2.2/refs/heads/master/misc.c\00"
@errno = global i32 0
@.str.2 = [2 x i8] c",\00"
define i32 @is_user_in_list(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i8* null, i8** %6
store i32 0, i32* %8
%9 = load i8*, i8** %4
%10 = icmp ne i8* %9, null
br i1 %10, label %11, label %14
11: ; preds = %2
%12 = load i8*, i8** %5
%13 = icmp ne i8* %12, null
br i1 %13, label %16, label %14
14: ; preds = %11, %2
%15 = load i32, i32* %8
store i32 %15, i32* %3
br label %74
16: ; preds = %11
%17 = load i8*, i8** %5
%18 = call i64 @strlen(i8* %17)
%19 = add nsw i64 %18, 1
%20 = call i64 @malloc(i64 %19)
%21 = inttoptr i64 %20 to i8*
store i8* %21, i8** %6
%22 = load i8*, i8** %6
%23 = icmp eq i8* %22, null
br i1 %23, label %24, label %31
24: ; preds = %16
%25 = load i32, i32* @LOG_ERR
%26 = load i32, i32* @errno
%27 = load i32, i32* @errno
%28 = call i32 @strerror(i32 %27)
%29 = call i32 @syslog(i32 %25, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([139 x i8], [139 x i8]* @.str.1, i64 0, i64 0), i32 175, i32 %26, i32 %28)
%30 = load i32, i32* %8
store i32 %30, i32* %3
br label %74
31: ; preds = %16
%32 = load i8*, i8** %6
%33 = load i8*, i8** %5
%34 = call i32 @strcpy(i8* %32, i8* %33)
%35 = load i8*, i8** %6
%36 = call i8* @strtok(i8* %35, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i8* %36, i8** %7
br label %37
37: ; preds = %63, %31
%38 = load i8*, i8** %7
%39 = icmp ne i8* %38, null
br i1 %39, label %40, label %65
40: ; preds = %37
%41 = load i8*, i8** %7
%42 = call i32 @str_trim_space(i8* %41)
%43 = load i8*, i8** %7
%44 = load i8, i8* %43
%45 = sext i8 %44 to i32
%46 = icmp ne i32 %45, 64
br i1 %46, label %47, label %54
47: ; preds = %40
%48 = load i8*, i8** %4
%49 = load i8*, i8** %7
%50 = call i64 @strcmp(i8* %48, i8* %49)
%51 = icmp eq i64 0, %50
br i1 %51, label %52, label %53
52: ; preds = %47
store i32 1, i32* %8
br label %65
53: ; preds = %47
br label %62
54: ; preds = %40
%55 = load i8*, i8** %4
%56 = load i8*, i8** %7
%57 = getelementptr inbounds i8, i8* %56, i64 1
%58 = call i32 @smbftpd_auth_is_user_in_group(i8* %55, i8* %57)
%59 = icmp eq i32 1, %58
br i1 %59, label %60, label %61
60: ; preds = %54
store i32 1, i32* %8
br label %66
61: ; preds = %54
br label %62
62: ; preds = %61, %53
br label %63
63: ; preds = %62
%64 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i8* %64, i8** %7
br label %37
65: ; preds = %52, %37
br label %66
66: ; preds = %65, %60
%67 = load i8*, i8** %6
%68 = icmp ne i8* %67, null
br i1 %68, label %69, label %72
69: ; preds = %66
%70 = load i8*, i8** %6
%71 = call i32 @free(i8* %70)
br label %72
72: ; preds = %69, %66
%73 = load i32, i32* %8
store i32 %73, i32* %3
br label %74
74: ; preds = %72, %24, %14
%75 = load i32, i32* %3
ret i32 %75
}

LLVM IR (-O2):
@LOG_ERR = global i32 0
@.str = [48 x i8] c"%s (%d) failed to allocate memory, errno:%d(%s)\00"
@.str.1 = [139 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/jchuang1977/smbftpd-2.2/refs/heads/master/misc.c\00"
@errno = global i32 0
@.str.2 = [2 x i8] c",\00"
define i32 @is_user_in_list(i8* %0, i8* %1) {
%3 = icmp ne i8* %0, null
%4 = icmp ne i8* %1, null
%5 = and i1 %3, %4
br i1 %5, label %6, label %39
6: ; preds = %2
%7 = tail call i64 @strlen(i8* %1)
%8 = add nsw i64 %7, 1
%9 = tail call i64 @malloc(i64 %8)
%10 = inttoptr i64 %9 to i8*
%11 = icmp eq i64 %9, 0
br i1 %11, label %12, label %17
12: ; preds = %6
%13 = load i32, i32* @LOG_ERR
%14 = load i32, i32* @errno
%15 = tail call i32 @strerror(i32 %14)
%16 = tail call i32 @syslog(i32 %13, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([139 x i8], [139 x i8]* @.str.1, i64 0, i64 0), i32 175, i32 %14, i32 %15)
br label %39
17: ; preds = %6
%18 = tail call i32 @strcpy(i8* %10, i8* %1)
%19 = tail call i8* @strtok(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%20 = icmp eq i8* %19, null
br i1 %20, label %36, label %21
21: ; preds = %17, %33
%22 = phi i8* [ %34, %33 ], [ %19, %17 ]
%23 = tail call i32 @str_trim_space(i8* %22)
%24 = load i8, i8* %22
%25 = icmp eq i8 %24, 64
br i1 %25, label %29, label %26
26: ; preds = %21
%27 = tail call i64 @strcmp(i8* %0, i8* %22)
%28 = icmp eq i64 %27, 0
br i1 %28, label %36, label %33
29: ; preds = %21
%30 = getelementptr inbounds i8, i8* %22, i64 1
%31 = tail call i32 @smbftpd_auth_is_user_in_group(i8* %0, i8* %30)
%32 = icmp eq i32 %31, 1
br i1 %32, label %36, label %33
33: ; preds = %26, %29
%34 = tail call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%35 = icmp eq i8* %34, null
br i1 %35, label %36, label %21
36: ; preds = %29, %26, %33, %17
%37 = phi i32 [ 0, %17 ], [ 0, %33 ], [ 1, %26 ], [ 1, %29 ]
%38 = tail call i32 @free(i8* %10)
br label %39
39: ; preds = %2, %36, %12
%40 = phi i32 [ 0, %12 ], [ %37, %36 ], [ 0, %2 ]
ret i32 %40
}