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

/* Variables and functions */
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(char *);
char *malloc(int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ sscanf(char *, char *, char *, char *);
scalar_t__ strcmp(char *, char const *);
char *strtok(char *, char *);
int check_user_auth(const char *from_user, const char *to_user, FILE *fp) {
  int ret = 0;
  char buf[4096];
  char user[13];
  char *user_list;
  char *token;
  user_list = malloc(101);
  if (!user_list) {
    perror("malloc user_list");
    goto out;
  }
  memset(user_list, 0, 101);
  while (fgets(buf, 4096, fp) && !ret) {
    sscanf(buf, "%12s\t%100s[^\n]", user, user_list);
    if (strcmp(user, from_user) == 0) {
      token = strtok(user_list, ",");
      while (token != NULL) {
        if (strcmp(token, to_user) == 0) {
          ret = 1;
          break;
        }
        token = strtok(NULL, ",");
      }
    }
  }
  free(user_list);
out:
  return ret;
}


x86 assembly (clang, -O0):
<check_user_auth>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1050,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    $0x65,%edi
call   1070 <malloc@plt>
mov    %rax,-0x1038(%rbp)
cmpq   $0x0,-0x1038(%rbp)
jne    11ce <check_user_auth+0x4e>
lea    0xe3c(%rip),%rdi
call   1090 <perror@plt>
jmp    12e8 <check_user_auth+0x168>
mov    -0x1038(%rbp),%rdi
xor    %esi,%esi
mov    $0x65,%edx
call   1040 <memset@plt>
lea    -0x1020(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x1000,%esi
call   1050 <fgets@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x1041(%rbp)
je     121a <check_user_auth+0x9a>
cmpl   $0x0,-0x1c(%rbp)
setne  %al
xor    $0xff,%al
mov    %al,-0x1041(%rbp)
mov    -0x1041(%rbp),%al
test   $0x1,%al
jne    122d <check_user_auth+0xad>
jmp    12dc <check_user_auth+0x15c>
lea    -0x1020(%rbp),%rdi
lea    -0x102d(%rbp),%rdx
mov    -0x1038(%rbp),%rcx
lea    0xdc8(%rip),%rsi
call   1080 <sscanf@plt>
lea    -0x102d(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    12d7 <check_user_auth+0x157>
mov    -0x1038(%rbp),%rdi
lea    0xdaa(%rip),%rsi
call   10a0 <strtok@plt>
mov    %rax,-0x1040(%rbp)
cmpq   $0x0,-0x1040(%rbp)
je     12d2 <check_user_auth+0x152>
mov    -0x1040(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    12b6 <check_user_auth+0x136>
movl   $0x1,-0x1c(%rbp)
jmp    12d2 <check_user_auth+0x152>
xor    %eax,%eax
mov    %eax,%edi
lea    0xd5f(%rip),%rsi
call   10a0 <strtok@plt>
mov    %rax,-0x1040(%rbp)
jmp    1282 <check_user_auth+0x102>
jmp    12d7 <check_user_auth+0x157>
jmp    11e1 <check_user_auth+0x61>
mov    -0x1038(%rbp),%rdi
call   1030 <free@plt>
mov    -0x1c(%rbp),%eax
add    $0x1050,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_user_auth>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1028,%rsp
mov    %rdx,%r13
mov    %rsi,%r12
mov    %rdi,0x8(%rsp)
mov    $0x65,%edi
call   1070 <malloc@plt>
test   %rax,%rax
je     12b0 <check_user_auth+0x130>
mov    %rax,%r15
xor    %ebp,%ebp
mov    %rax,%rdi
xor    %esi,%esi
mov    $0x65,%edx
call   1040 <memset@plt>
lea    0x20(%rsp),%rdi
mov    $0x1000,%esi
mov    %r13,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     1294 <check_user_auth+0x114>
lea    0xe3b(%rip),%r14
mov    %r13,(%rsp)
nopl   0x0(%rax)
lea    0x20(%rsp),%rdi
lea    0xe15(%rip),%rsi
lea    0x13(%rsp),%rbx
mov    %rbx,%rdx
mov    %r15,%rcx
call   1080 <sscanf@plt>
mov    %rbx,%rdi
mov    0x8(%rsp),%rsi
call   1060 <strcmp@plt>
xor    %ebp,%ebp
mov    $0x1,%bl
test   %rax,%rax
jne    1275 <check_user_auth+0xf5>
mov    %r15,%rdi
mov    %r14,%rsi
call   10a0 <strtok@plt>
test   %rax,%rax
je     1275 <check_user_auth+0xf5>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rax,%rdi
mov    %r12,%rsi
call   1060 <strcmp@plt>
mov    %rax,%r13
test   %rax,%rax
je     1266 <check_user_auth+0xe6>
xor    %ebp,%ebp
xor    %edi,%edi
mov    %r14,%rsi
call   10a0 <strtok@plt>
test   %rax,%rax
jne    1240 <check_user_auth+0xc0>
jmp    126b <check_user_auth+0xeb>
mov    $0x1,%ebp
test   %r13,%r13
setne  %bl
mov    (%rsp),%r13
lea    0x20(%rsp),%rdi
mov    $0x1000,%esi
mov    %r13,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     1294 <check_user_auth+0x114>
test   %bl,%bl
jne    11f0 <check_user_auth+0x70>
mov    %r15,%rdi
call   1030 <free@plt>
mov    %ebp,%eax
add    $0x1028,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd49(%rip),%rdi
call   1090 <perror@plt>
xor    %ebp,%ebp
jmp    129c <check_user_auth+0x11c>

LLVM IR (-O0):
@.str = [17 x i8] c"malloc user_list\00"
@.str.1 = [15 x i8] c"%12s\09%100s[^\0A]\00"
@.str.2 = [2 x i8] c",\00"
define i32 @check_user_auth(i8* %0, i8* %1, i32* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca i32
%8 = alloca [4096 x i8]
%9 = alloca [13 x i8]
%10 = alloca i8*
%11 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32* %2, i32** %6
store i32 0, i32* %7
%12 = call i8* @malloc(i32 101)
store i8* %12, i8** %10
%13 = load i8*, i8** %10
%14 = icmp ne i8* %13, null
br i1 %14, label %17, label %15
15: ; preds = %3
%16 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
br label %59
17: ; preds = %3
%18 = load i8*, i8** %10
%19 = call i32 @memset(i8* %18, i32 0, i32 101)
br label %20
20: ; preds = %55, %17
%21 = getelementptr inbounds [4096 x i8], [4096 x i8]* %8, i64 0, i64 0
%22 = load i32*, i32** %6
%23 = call i64 @fgets(i8* %21, i32 4096, i32* %22)
%24 = icmp ne i64 %23, 0
br i1 %24, label %25, label %29
25: ; preds = %20
%26 = load i32, i32* %7
%27 = icmp ne i32 %26, 0
%28 = xor i1 %27, true
br label %29
29: ; preds = %25, %20
%30 = phi i1 [ false, %20 ], [ %28, %25 ]
br i1 %30, label %31, label %56
31: ; preds = %29
%32 = getelementptr inbounds [4096 x i8], [4096 x i8]* %8, i64 0, i64 0
%33 = getelementptr inbounds [13 x i8], [13 x i8]* %9, i64 0, i64 0
%34 = load i8*, i8** %10
%35 = call i32 @sscanf(i8* %32, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8* %33, i8* %34)
%36 = getelementptr inbounds [13 x i8], [13 x i8]* %9, i64 0, i64 0
%37 = load i8*, i8** %4
%38 = call i64 @strcmp(i8* %36, i8* %37)
%39 = icmp eq i64 %38, 0
br i1 %39, label %40, label %55
40: ; preds = %31
%41 = load i8*, i8** %10
%42 = call i8* @strtok(i8* %41, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i8* %42, i8** %11
br label %43
43: ; preds = %52, %40
%44 = load i8*, i8** %11
%45 = icmp ne i8* %44, null
br i1 %45, label %46, label %54
46: ; preds = %43
%47 = load i8*, i8** %11
%48 = load i8*, i8** %5
%49 = call i64 @strcmp(i8* %47, i8* %48)
%50 = icmp eq i64 %49, 0
br i1 %50, label %51, label %52
51: ; preds = %46
store i32 1, i32* %7
br label %54
52: ; preds = %46
%53 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i8* %53, i8** %11
br label %43
54: ; preds = %51, %43
br label %55
55: ; preds = %54, %31
br label %20
56: ; preds = %29
%57 = load i8*, i8** %10
%58 = call i32 @free(i8* %57)
br label %59
59: ; preds = %56, %15
%60 = load i32, i32* %7
ret i32 %60
}

LLVM IR (-O2):
@.str = [17 x i8] c"malloc user_list\00"
@.str.1 = [15 x i8] c"%12s\09%100s[^\0A]\00"
@.str.2 = [2 x i8] c",\00"
define i32 @check_user_auth(i8* %0, i8* %1, i32* nocapture %2) {
%4 = alloca [4096 x i8]
%5 = alloca [13 x i8]
%6 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 0
%7 = getelementptr inbounds [13 x i8], [13 x i8]* %5, i64 0, i64 0
%8 = tail call dereferenceable_or_null(101) i8* @malloc(i32 101)
%9 = icmp eq i8* %8, null
br i1 %9, label %10, label %12
10: ; preds = %3
%11 = tail call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
br label %42
12: ; preds = %3
%13 = tail call i32 @memset(i8* %8, i32 0, i32 101)
%14 = call i64 @fgets(i8* %6, i32 4096, i32* %2)
%15 = icmp eq i64 %14, 0
br i1 %15, label %39, label %16
16: ; preds = %12, %33
%17 = call i32 @sscanf(i8* %6, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8* %7, i8* %8)
%18 = call i64 @strcmp(i8* %7, i8* %0)
%19 = icmp eq i64 %18, 0
br i1 %19, label %20, label %33
20: ; preds = %16
%21 = call i8* @strtok(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%22 = icmp eq i8* %21, null
br i1 %22, label %33, label %23
23: ; preds = %20, %27
%24 = phi i8* [ %28, %27 ], [ %21, %20 ]
%25 = call i64 @strcmp(i8* %24, i8* %1)
%26 = icmp eq i64 %25, 0
br i1 %26, label %30, label %27
27: ; preds = %23
%28 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%29 = icmp eq i8* %28, null
br i1 %29, label %30, label %23
30: ; preds = %23, %27
%31 = phi i32 [ 1, %23 ], [ 0, %27 ]
%32 = xor i1 %26, true
br label %33
33: ; preds = %30, %20, %16
%34 = phi i1 [ true, %20 ], [ true, %16 ], [ %32, %30 ]
%35 = phi i32 [ 0, %20 ], [ 0, %16 ], [ %31, %30 ]
%36 = call i64 @fgets(i8* %6, i32 4096, i32* %2)
%37 = icmp ne i64 %36, 0
%38 = and i1 %37, %34
br i1 %38, label %16, label %39
39: ; preds = %33, %12
%40 = phi i32 [ 0, %12 ], [ %35, %33 ]
%41 = call i32 @free(i8* %8)
br label %42
42: ; preds = %39, %10
%43 = phi i32 [ %40, %39 ], [ 0, %10 ]
ret i32 %43
}