#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 */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ free(char *);
char *readFromFile(int /*<<< orphan*/ *);
scalar_t__ strcmp(char *, char *);
char *strtok_r(char *, char *, char **);
int checkIfUserExists(char *userName) {
  FILE *fp = fopen("login_file", "r");
  char delim[] = ", \n";
  char *str = readFromFile(fp);
  fclose(fp);
  char *save_ptr;
  char *tok = strtok_r(str, delim, &save_ptr);
  do {
    int check = 0;
    if (tok != NULL && strcmp(tok, userName) == 0) {
      check = 1;
    }
    tok = strtok_r(NULL, delim, &save_ptr);
    tok = strtok_r(NULL, delim, &save_ptr);
    if (strcmp(tok, "U") == 0 && check == 1)
      return 1;
    tok = NULL;
  } while ((tok = strtok_r(NULL, delim, &save_ptr)) != NULL);
  if (str != NULL)
    free(str);
  return 0;
}


x86 assembly (clang, -O0):
<checkIfUserExists>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
lea    0xe8d(%rip),%rdi
lea    0xe91(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x18(%rbp)
mov    0xe84(%rip),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
call   1060 <readFromFile@plt>
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x28(%rbp),%rdi
lea    -0x1c(%rbp),%rsi
lea    -0x30(%rbp),%rdx
call   1050 <strtok_r@plt>
mov    %rax,-0x38(%rbp)
movl   $0x0,-0x3c(%rbp)
cmpq   $0x0,-0x38(%rbp)
je     11e7 <checkIfUserExists+0x87>
mov    -0x38(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
jne    11e7 <checkIfUserExists+0x87>
movl   $0x1,-0x3c(%rbp)
lea    -0x1c(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edi
lea    -0x30(%rbp),%rdx
call   1050 <strtok_r@plt>
mov    %rax,-0x38(%rbp)
lea    -0x1c(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edi
lea    -0x30(%rbp),%rdx
call   1050 <strtok_r@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
lea    0xdf5(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
jne    1241 <checkIfUserExists+0xe1>
cmpl   $0x1,-0x3c(%rbp)
jne    1241 <checkIfUserExists+0xe1>
movl   $0x1,-0x4(%rbp)
jmp    1283 <checkIfUserExists+0x123>
movq   $0x0,-0x38(%rbp)
lea    -0x1c(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edi
lea    -0x30(%rbp),%rdx
call   1050 <strtok_r@plt>
mov    %rax,-0x38(%rbp)
cmp    $0x0,%rax
jne    11b7 <checkIfUserExists+0x57>
cmpq   $0x0,-0x28(%rbp)
je     127c <checkIfUserExists+0x11c>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<checkIfUserExists>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%r15
lea    0xe88(%rip),%rdi
lea    0xe8c(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,%rbx
movl   $0xa202c,0xc(%rsp)
mov    %rax,%rdi
call   1060 <readFromFile@plt>
mov    %rax,%r14
mov    %rbx,%rdi
call   1040 <fclose@plt>
lea    0xc(%rsp),%r12
lea    0x10(%rsp),%rbx
mov    %r14,%rdi
mov    %r12,%rsi
mov    %rbx,%rdx
call   1050 <strtok_r@plt>
lea    0xe4c(%rip),%r13
jmp    11e2 <checkIfUserExists+0x82>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
xor    %edi,%edi
mov    %r12,%rsi
mov    %rbx,%rdx
call   1050 <strtok_r@plt>
test   %rax,%rax
je     1238 <checkIfUserExists+0xd8>
test   %rax,%rax
je     1200 <checkIfUserExists+0xa0>
mov    %rax,%rdi
mov    %r15,%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
sete   %bpl
jmp    1202 <checkIfUserExists+0xa2>
nopl   0x0(%rax,%rax,1)
xor    %ebp,%ebp
xor    %edi,%edi
mov    %r12,%rsi
mov    %rbx,%rdx
call   1050 <strtok_r@plt>
xor    %edi,%edi
mov    %r12,%rsi
mov    %rbx,%rdx
call   1050 <strtok_r@plt>
mov    %rax,%rdi
mov    %r13,%rsi
call   1070 <strcmp@plt>
test   %bpl,%bpl
je     11d0 <checkIfUserExists+0x70>
test   %rax,%rax
jne    11d0 <checkIfUserExists+0x70>
mov    $0x1,%ebx
jmp    1247 <checkIfUserExists+0xe7>
xor    %ebx,%ebx
test   %r14,%r14
je     1247 <checkIfUserExists+0xe7>
mov    %r14,%rdi
call   1030 <free@plt>
mov    %ebx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [11 x i8] c"login_file\00"
@.str.1 = [2 x i8] c"r\00"
@__const.checkIfUserExists.delim = [4 x i8] c", \0A\00"
@.str.2 = [2 x i8] c"U\00"
define i32 @checkIfUserExists(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca [4 x i8]
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32
store i8* %0, i8** %3
%10 = call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %10, i32** %4
%11 = bitcast [4 x i8]* %5 to i8*
%12 = load i32*, i32** %4
%13 = call i8* @readFromFile(i32* %12)
store i8* %13, i8** %6
%14 = load i32*, i32** %4
%15 = call i32 @fclose(i32* %14)
%16 = load i8*, i8** %6
%17 = getelementptr inbounds [4 x i8], [4 x i8]* %5, i64 0, i64 0
%18 = call i8* @strtok_r(i8* %16, i8* %17, i8** %7)
store i8* %18, i8** %8
br label %19
19: ; preds = %41, %1
store i32 0, i32* %9
%20 = load i8*, i8** %8
%21 = icmp ne i8* %20, null
br i1 %21, label %22, label %28
22: ; preds = %19
%23 = load i8*, i8** %8
%24 = load i8*, i8** %3
%25 = call i64 @strcmp(i8* %23, i8* %24)
%26 = icmp eq i64 %25, 0
br i1 %26, label %27, label %28
27: ; preds = %22
store i32 1, i32* %9
br label %28
28: ; preds = %27, %22, %19
%29 = getelementptr inbounds [4 x i8], [4 x i8]* %5, i64 0, i64 0
%30 = call i8* @strtok_r(i8* null, i8* %29, i8** %7)
store i8* %30, i8** %8
%31 = getelementptr inbounds [4 x i8], [4 x i8]* %5, i64 0, i64 0
%32 = call i8* @strtok_r(i8* null, i8* %31, i8** %7)
store i8* %32, i8** %8
%33 = load i8*, i8** %8
%34 = call i64 @strcmp(i8* %33, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%35 = icmp eq i64 %34, 0
br i1 %35, label %36, label %40
36: ; preds = %28
%37 = load i32, i32* %9
%38 = icmp eq i32 %37, 1
br i1 %38, label %39, label %40
39: ; preds = %36
store i32 1, i32* %2
br label %52
40: ; preds = %36, %28
store i8* null, i8** %8
br label %41
41: ; preds = %40
%42 = getelementptr inbounds [4 x i8], [4 x i8]* %5, i64 0, i64 0
%43 = call i8* @strtok_r(i8* null, i8* %42, i8** %7)
store i8* %43, i8** %8
%44 = icmp ne i8* %43, null
br i1 %44, label %19, label %45
45: ; preds = %41
%46 = load i8*, i8** %6
%47 = icmp ne i8* %46, null
br i1 %47, label %48, label %51
48: ; preds = %45
%49 = load i8*, i8** %6
%50 = call i32 @free(i8* %49)
br label %51
51: ; preds = %48, %45
store i32 0, i32* %2
br label %52
52: ; preds = %51, %39
%53 = load i32, i32* %2
ret i32 %53
}

LLVM IR (-O2):
@.str = [11 x i8] c"login_file\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [2 x i8] c"U\00"
define i32 @checkIfUserExists(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = tail call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%5 = bitcast i32* %2 to i8*
store i32 663596, i32* %2
%6 = tail call i8* @readFromFile(i32* %4)
%7 = tail call i32 @fclose(i32* %4)
%8 = bitcast i8** %3 to i8*
%9 = call i8* @strtok_r(i8* %6, i8* %5, i8** %3)
br label %10
10: ; preds = %23, %1
%11 = phi i8* [ %9, %1 ], [ %24, %23 ]
%12 = icmp eq i8* %11, null
br i1 %12, label %16, label %13
13: ; preds = %10
%14 = call i64 @strcmp(i8* %11, i8* %0)
%15 = icmp eq i64 %14, 0
br label %16
16: ; preds = %13, %10
%17 = phi i1 [ false, %10 ], [ %15, %13 ]
%18 = call i8* @strtok_r(i8* null, i8* %5, i8** %3)
%19 = call i8* @strtok_r(i8* null, i8* %5, i8** %3)
%20 = call i64 @strcmp(i8* %19, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%21 = icmp eq i64 %20, 0
%22 = and i1 %17, %21
br i1 %22, label %30, label %23
23: ; preds = %16
%24 = call i8* @strtok_r(i8* null, i8* %5, i8** %3)
%25 = icmp eq i8* %24, null
br i1 %25, label %26, label %10
26: ; preds = %23
%27 = icmp eq i8* %6, null
br i1 %27, label %30, label %28
28: ; preds = %26
%29 = call i32 @free(i8* %6)
br label %30
30: ; preds = %16, %26, %28
%31 = phi i32 [ 0, %28 ], [ 0, %26 ], [ 1, %16 ]
ret i32 %31
}