#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 *);
int /*<<< orphan*/ parseElements(char *, char **, int);
char *readLine(int /*<<< orphan*/ *);
scalar_t__ strcmp(char *, char *);
char validatePassword(char *name, char *pass) {
  FILE *members = fopen("database/Members.csv", "r");
  char *line;
  char valid = 0;
  while (!valid) {
    line = readLine(members);
    if (!line) {
      break;
    }
    char *elements[3];
    parseElements(line, elements, 3);
    if (strcmp(elements[1], name) == 0) {
      valid = strcmp(elements[2], pass) == 0;
    }
    free(line);
    free(elements[0]);
    free(elements[1]);
    free(elements[2]);
  }
  fclose(members);
  return valid;
}


x86 assembly (clang, -O0):
<validatePassword>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe89(%rip),%rdi
lea    0xe97(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x18(%rbp)
movb   $0x0,-0x21(%rbp)
cmpb   $0x0,-0x21(%rbp)
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11a1 <validatePassword+0x41>
jmp    122c <validatePassword+0xcc>
mov    -0x18(%rbp),%rdi
call   1070 <readLine@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11be <validatePassword+0x5e>
jmp    122c <validatePassword+0xcc>
mov    -0x20(%rbp),%rdi
lea    -0x40(%rbp),%rsi
mov    $0x3,%edx
call   1050 <parseElements@plt>
mov    -0x38(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    1203 <validatePassword+0xa3>
mov    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%eax
mov    %al,-0x21(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
jmp    118b <validatePassword+0x2b>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
movsbl -0x21(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<validatePassword>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%r14
mov    %rdi,%r15
lea    0xe85(%rip),%rdi
lea    0xe93(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,%r13
mov    %rsp,%r12
jmp    11ce <validatePassword+0x6e>
nop
mov    0x10(%rsp),%rdi
mov    %r14,%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
sete   %bpl
mov    %rbx,%rdi
call   1030 <free@plt>
mov    (%rsp),%rdi
call   1030 <free@plt>
mov    0x8(%rsp),%rdi
call   1030 <free@plt>
mov    0x10(%rsp),%rdi
call   1030 <free@plt>
test   %bpl,%bpl
jne    1204 <validatePassword+0xa4>
mov    %r13,%rdi
call   1070 <readLine@plt>
test   %rax,%rax
je     1208 <validatePassword+0xa8>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r12,%rsi
mov    $0x3,%edx
call   1050 <parseElements@plt>
mov    0x8(%rsp),%rdi
mov    %r15,%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
je     1190 <validatePassword+0x30>
xor    %ebp,%ebp
jmp    11a4 <validatePassword+0x44>
mov    $0x1,%bl
jmp    120a <validatePassword+0xaa>
xor    %ebx,%ebx
mov    %r13,%rdi
call   1040 <fclose@plt>
mov    %ebx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [21 x i8] c"database/Members.csv\00"
@.str.1 = [2 x i8] c"r\00"
define signext i8 @validatePassword(i8* %0, i8* %1) {
%3 = alloca [3 x i8*]
%4 = tail call i32* @fopen(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%5 = bitcast [3 x i8*]* %3 to i8*
%6 = getelementptr inbounds [3 x i8*], [3 x i8*]* %3, i64 0, i64 0
%7 = getelementptr inbounds [3 x i8*], [3 x i8*]* %3, i64 0, i64 1
%8 = getelementptr inbounds [3 x i8*], [3 x i8*]* %3, i64 0, i64 2
br label %9
9: ; preds = %2, %22
%10 = call i8* @readLine(i32* %4)
%11 = icmp eq i8* %10, null
br i1 %11, label %32, label %12
12: ; preds = %9
%13 = call i32 @parseElements(i8* %10, i8** %6, i32 3)
%14 = load i8*, i8** %7
%15 = call i64 @strcmp(i8* %14, i8* %0)
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %22
17: ; preds = %12
%18 = load i8*, i8** %8
%19 = call i64 @strcmp(i8* %18, i8* %1)
%20 = icmp eq i64 %19, 0
%21 = zext i1 %20 to i8
br label %22
22: ; preds = %17, %12
%23 = phi i8 [ %21, %17 ], [ 0, %12 ]
%24 = call i32 @free(i8* %10)
%25 = load i8*, i8** %6
%26 = call i32 @free(i8* %25)
%27 = load i8*, i8** %7
%28 = call i32 @free(i8* %27)
%29 = load i8*, i8** %8
%30 = call i32 @free(i8* %29)
%31 = icmp eq i8 %23, 0
br i1 %31, label %9, label %32
32: ; preds = %9, %22
%33 = phi i8 [ 0, %9 ], [ 1, %22 ]
%34 = call i32 @fclose(i32* %4)
ret i8 %33
}