#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 int /*<<< orphan*/ buf;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ LOG_ERR;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
scalar_t__ is_user_in_group(char const *, char *);
char *str_trim_space(char *);
scalar_t__ strcmp(char *, char const *);
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
int /*<<< orphan*/ syslog(int /*<<< orphan*/, char *, char *, int, char const *,
                          int /*<<< orphan*/);
int is_user_in_file(const char *fname, const char *user) {
  FILE *pf;
  char buf[1024], *p;
  int found = 0;
  pf = fopen(fname, "r");
  if (pf == NULL) {
    syslog(LOG_ERR, "%s (%d) Failed to open no login list %s. (%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/restrict/nologin.c",
           59, fname, strerror(errno));
    return 0;
  }
  while (fgets(buf, sizeof(buf), pf)) {
    p = str_trim_space(buf);
    if (*p == '#' || *p == 0) {
      continue;
    }
    if (*p == '@') {
      p++;
      if (is_user_in_group(user, p)) {
        found = 1;
        break;
      }
    } else {
      if (strcmp(p, user) == 0) {
        found = 1;
        break;
      }
    }
  }
  fclose(pf);
  return found;
}


x86 assembly (clang, -O0):
<is_user_in_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x440,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x0,-0x42c(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe58(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1218 <is_user_in_file+0x98>
mov    0x2e0d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x43c(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x438(%rbp)
mov    0x2e03(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
mov    -0x43c(%rbp),%edi
mov    -0x438(%rbp),%r8
mov    %eax,%r9d
lea    0xe07(%rip),%rsi
lea    0xe2e(%rip),%rdx
mov    $0x3b,%ecx
call   1080 <syslog@plt>
movl   $0x0,-0x4(%rbp)
jmp    1312 <is_user_in_file+0x192>
jmp    121d <is_user_in_file+0x9d>
lea    -0x420(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    $0x400,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     1300 <is_user_in_file+0x180>
lea    -0x420(%rbp),%rdi
call   1040 <str_trim_space@plt>
mov    %rax,-0x428(%rbp)
mov    -0x428(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x23,%eax
je     1275 <is_user_in_file+0xf5>
mov    -0x428(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    127a <is_user_in_file+0xfa>
jmp    121d <is_user_in_file+0x9d>
mov    -0x428(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x40,%eax
jne    12cd <is_user_in_file+0x14d>
mov    -0x428(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x428(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x428(%rbp),%rsi
call   1070 <is_user_in_group@plt>
cmp    $0x0,%rax
je     12c8 <is_user_in_file+0x148>
movl   $0x1,-0x42c(%rbp)
jmp    1300 <is_user_in_file+0x180>
jmp    12fb <is_user_in_file+0x17b>
mov    -0x428(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    12f6 <is_user_in_file+0x176>
movl   $0x1,-0x42c(%rbp)
jmp    1300 <is_user_in_file+0x180>
jmp    12fb <is_user_in_file+0x17b>
jmp    121d <is_user_in_file+0x9d>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x42c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x440,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<is_user_in_file>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x408,%rsp
mov    %rsi,%r14
mov    %rdi,%rbp
lea    0xe66(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     1232 <is_user_in_file+0xb2>
mov    %rax,%rbx
mov    %rsp,%rdi
mov    $0x400,%esi
mov    %rax,%rdx
call   1050 <fgets@plt>
xor    %r15d,%r15d
test   %rax,%rax
je     1228 <is_user_in_file+0xa8>
mov    %rsp,%rbp
jmp    11f9 <is_user_in_file+0x79>
nopl   0x0(%rax,%rax,1)
add    $0x1,%rax
mov    %r14,%rdi
mov    %rax,%rsi
call   1070 <is_user_in_group@plt>
test   %rax,%rax
jne    1222 <is_user_in_file+0xa2>
mov    %rbp,%rdi
mov    $0x400,%esi
mov    %rbx,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     1228 <is_user_in_file+0xa8>
mov    %rbp,%rdi
call   1040 <str_trim_space@plt>
movzbl (%rax),%ecx
test   %cl,%cl
je     11e4 <is_user_in_file+0x64>
cmp    $0x40,%cl
je     11d0 <is_user_in_file+0x50>
cmp    $0x23,%cl
je     11e4 <is_user_in_file+0x64>
mov    %rax,%rdi
mov    %r14,%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
jne    11e4 <is_user_in_file+0x64>
mov    $0x1,%r15d
mov    %rbx,%rdi
call   1030 <fclose@plt>
jmp    126c <is_user_in_file+0xec>
mov    0x2d97(%rip),%rax
mov    (%rax),%ebx
mov    0x2d9e(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
lea    0xdb2(%rip),%rsi
lea    0xdd9(%rip),%rdx
mov    %ebx,%edi
mov    $0x3b,%ecx
mov    %rbp,%r8
mov    %eax,%r9d
call   1080 <syslog@plt>
xor    %r15d,%r15d
mov    %r15d,%eax
add    $0x408,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@LOG_ERR = global i32 0
@.str.1 = [46 x i8] c"%s (%d) Failed to open no login list %s. (%s)\00"
@.str.2 = [151 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/restrict/nologin.c\00"
@errno = global i32 0
define i32 @is_user_in_file(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca [1024 x i8]
%8 = alloca i8*
%9 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 0, i32* %9
%10 = load i8*, i8** %4
%11 = call i32* @fopen(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %11, i32** %6
%12 = load i32*, i32** %6
%13 = icmp eq i32* %12, null
br i1 %13, label %14, label %20
14: ; preds = %2
%15 = load i32, i32* @LOG_ERR
%16 = load i8*, i8** %4
%17 = load i32, i32* @errno
%18 = call i32 @strerror(i32 %17)
%19 = call i32 @syslog(i32 %15, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([151 x i8], [151 x i8]* @.str.2, i64 0, i64 0), i32 59, i8* %16, i32 %18)
store i32 0, i32* %3
br label %65
20: ; preds = %2
br label %21
21: ; preds = %60, %38, %20
%22 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%23 = load i32*, i32** %6
%24 = call i64 @fgets(i8* %22, i32 1024, i32* %23)
%25 = icmp ne i64 %24, 0
br i1 %25, label %26, label %61
26: ; preds = %21
%27 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%28 = call i8* @str_trim_space(i8* %27)
store i8* %28, i8** %8
%29 = load i8*, i8** %8
%30 = load i8, i8* %29
%31 = sext i8 %30 to i32
%32 = icmp eq i32 %31, 35
br i1 %32, label %38, label %33
33: ; preds = %26
%34 = load i8*, i8** %8
%35 = load i8, i8* %34
%36 = sext i8 %35 to i32
%37 = icmp eq i32 %36, 0
br i1 %37, label %38, label %39
38: ; preds = %33, %26
br label %21
39: ; preds = %33
%40 = load i8*, i8** %8
%41 = load i8, i8* %40
%42 = sext i8 %41 to i32
%43 = icmp eq i32 %42, 64
br i1 %43, label %44, label %53
44: ; preds = %39
%45 = load i8*, i8** %8
%46 = getelementptr inbounds i8, i8* %45, i32 1
store i8* %46, i8** %8
%47 = load i8*, i8** %5
%48 = load i8*, i8** %8
%49 = call i64 @is_user_in_group(i8* %47, i8* %48)
%50 = icmp ne i64 %49, 0
br i1 %50, label %51, label %52
51: ; preds = %44
store i32 1, i32* %9
br label %61
52: ; preds = %44
br label %60
53: ; preds = %39
%54 = load i8*, i8** %8
%55 = load i8*, i8** %5
%56 = call i64 @strcmp(i8* %54, i8* %55)
%57 = icmp eq i64 %56, 0
br i1 %57, label %58, label %59
58: ; preds = %53
store i32 1, i32* %9
br label %61
59: ; preds = %53
br label %60
60: ; preds = %59, %52
br label %21
61: ; preds = %58, %51, %21
%62 = load i32*, i32** %6
%63 = call i32 @fclose(i32* %62)
%64 = load i32, i32* %9
store i32 %64, i32* %3
br label %65
65: ; preds = %61, %14
%66 = load i32, i32* %3
ret i32 %66
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@LOG_ERR = global i32 0
@.str.1 = [46 x i8] c"%s (%d) Failed to open no login list %s. (%s)\00"
@.str.2 = [151 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/restrict/nologin.c\00"
@errno = global i32 0
define i32 @is_user_in_file(i8* %0, i8* %1) {
%3 = alloca [1024 x i8]
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%5 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %10, label %7
7: ; preds = %2
%8 = call i64 @fgets(i8* %4, i32 1024, i32* %5)
%9 = icmp eq i64 %8, 0
br i1 %9, label %28, label %15
10: ; preds = %2
%11 = load i32, i32* @LOG_ERR
%12 = load i32, i32* @errno
%13 = tail call i32 @strerror(i32 %12)
%14 = tail call i32 @syslog(i32 %11, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([151 x i8], [151 x i8]* @.str.2, i64 0, i64 0), i32 59, i8* %0, i32 %13)
br label %31
15: ; preds = %7, %18
%16 = call i8* @str_trim_space(i8* %4)
%17 = load i8, i8* %16
switch i8 %17, label %25 [
i8 35, label %18
i8 0, label %18
i8 64, label %21
]
18: ; preds = %21, %25, %15, %15
%19 = call i64 @fgets(i8* %4, i32 1024, i32* %5)
%20 = icmp eq i64 %19, 0
br i1 %20, label %28, label %15
21: ; preds = %15
%22 = getelementptr inbounds i8, i8* %16, i64 1
%23 = call i64 @is_user_in_group(i8* %1, i8* %22)
%24 = icmp eq i64 %23, 0
br i1 %24, label %18, label %28
25: ; preds = %15
%26 = call i64 @strcmp(i8* %16, i8* %1)
%27 = icmp eq i64 %26, 0
br i1 %27, label %28, label %18
28: ; preds = %18, %21, %25, %7
%29 = phi i32 [ 0, %7 ], [ 1, %25 ], [ 1, %21 ], [ 0, %18 ]
%30 = call i32 @fclose(i32* %5)
br label %31
31: ; preds = %28, %10
%32 = phi i32 [ 0, %10 ], [ %29, %28 ]
ret i32 %32
}