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

/* Variables and functions */
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ decrypt(char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sscanf(char *, char *, char *, char *, char *);
scalar_t__ strcmp(char *, char *);
int verify(int argc, char *argv[], int menu) {
  if (argc < 4) {
    printf("Error. The %s switch requires at least 2 parameters: username and "
           "password. Please use the following syntax.\n $./passweb %s "
           "<username> <password>\n",
           argv[1], argv[1]);
    return 0;
  }
  FILE *file = fopen("password.csv", "r");
  fseek(file, 0, SEEK_SET);
  if (file == NULL) {
    printf(
        "Error. Database does not exist, please add users before verifying.\n");
    return 0;
  }
  char line[50];
  char userTemp[50];
  char passTemp[50];
  char typeTemp[50];
  while (fgets(line, sizeof(line), file)) {
    decrypt(line);
    sscanf(line, "%[^, ], %[^, ], %[^\n]\n", userTemp, passTemp, typeTemp);
    if (strcmp(userTemp, argv[2]) == 0 && strcmp(passTemp, argv[3]) == 0) {
      if (menu) {
        printf("VALID\n");
      } else {
        printf("EXIST_SUCCESS\n");
      }
      fclose(file);
      return 1;
    }
    if (strcmp(userTemp, argv[2]) == 0) {
      printf("Error, user found, but password does not match.\n");
    }
  }
  if (menu) {
    printf("INVALID\n");
  } else {
    printf("EXIT_FAILURE\n");
  }
  fclose(file);
  return 0;
}


x86 assembly (clang, -O0):
<verify>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
cmpl   $0x4,-0x8(%rbp)
jge    11c9 <verify+0x49>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xe4a(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1350 <verify+0x1d0>
lea    0xec3(%rip),%rdi
lea    0xec9(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    0x2df5(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1090 <fseek@plt>
cmpq   $0x0,-0x20(%rbp)
jne    1219 <verify+0x99>
lea    0xe9c(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1350 <verify+0x1d0>
jmp    121e <verify+0x9e>
lea    -0x60(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    $0x32,%esi
call   1060 <fgets@plt>
cmp    $0x0,%rax
je     1315 <verify+0x195>
lea    -0x60(%rbp),%rdi
call   1030 <decrypt@plt>
lea    -0x60(%rbp),%rdi
lea    -0xa0(%rbp),%rdx
lea    -0xe0(%rbp),%rcx
lea    -0x120(%rbp),%r8
lea    0xe83(%rip),%rsi
call   1080 <sscanf@plt>
lea    -0xa0(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
jne    12e4 <verify+0x164>
lea    -0xe0(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
jne    12e4 <verify+0x164>
cmpl   $0x0,-0x14(%rbp)
je     12c1 <verify+0x141>
lea    0xe8a(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    12cf <verify+0x14f>
lea    0xe35(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x1,-0x4(%rbp)
jmp    1350 <verify+0x1d0>
lea    -0xa0(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
jne    1310 <verify+0x190>
lea    0xe03(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    121e <verify+0x9e>
cmpl   $0x0,-0x14(%rbp)
je     1332 <verify+0x1b2>
lea    0xe17(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1340 <verify+0x1c0>
lea    0xe0d(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<verify>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x108,%rsp
mov    %rsi,%rbp
cmp    $0x3,%edi
jg     11c5 <verify+0x35>
mov    0x8(%rbp),%rdx
lea    0xe4c(%rip),%rdi
xor    %ebx,%ebx
mov    %rdx,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
jmp    12ea <verify+0x15a>
mov    %edx,%r14d
lea    0xec4(%rip),%rdi
lea    0xeca(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,%r15
mov    0x2dfb(%rip),%rax
mov    (%rax),%edx
xor    %ebx,%ebx
mov    %r15,%rdi
xor    %esi,%esi
call   10a0 <fseek@plt>
test   %r15,%r15
je     12de <verify+0x14e>
mov    %r14d,0xc(%rsp)
lea    0x10(%rsp),%rdi
mov    $0x32,%esi
mov    %r15,%rdx
call   1070 <fgets@plt>
test   %rax,%rax
je     12b6 <verify+0x126>
lea    0x10(%rsp),%r13
lea    0xd0(%rsp),%rbx
lea    0x90(%rsp),%r14
lea    0x50(%rsp),%r12
jmp    1255 <verify+0xc5>
nopl   0x0(%rax,%rax,1)
mov    %r13,%rdi
mov    $0x32,%esi
mov    %r15,%rdx
call   1070 <fgets@plt>
test   %rax,%rax
je     12b6 <verify+0x126>
mov    %r13,%rdi
call   1030 <decrypt@plt>
mov    %r13,%rdi
lea    0xe3b(%rip),%rsi
mov    %rbx,%rdx
mov    %r14,%rcx
mov    %r12,%r8
call   1090 <sscanf@plt>
mov    0x10(%rbp),%rsi
mov    %rbx,%rdi
call   1080 <strcmp@plt>
test   %rax,%rax
jne    1297 <verify+0x107>
mov    0x18(%rbp),%rsi
mov    %r14,%rdi
call   1080 <strcmp@plt>
test   %rax,%rax
je     12fe <verify+0x16e>
mov    0x10(%rbp),%rsi
mov    %rbx,%rdi
call   1080 <strcmp@plt>
test   %rax,%rax
jne    1240 <verify+0xb0>
lea    0xe1f(%rip),%rdi
call   1040 <puts@plt>
jmp    1240 <verify+0xb0>
cmpl   $0x0,0xc(%rsp)
lea    0xdf7(%rip),%rax
lea    0xdfd(%rip),%rdi
cmove  %rax,%rdi
xor    %ebx,%ebx
call   1040 <puts@plt>
mov    %r15,%rdi
call   1050 <fclose@plt>
jmp    12ea <verify+0x15a>
lea    0xe27(%rip),%rdi
call   1040 <puts@plt>
mov    %ebx,%eax
add    $0x108,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
cmpl   $0x0,0xc(%rsp)
lea    0xdf4(%rip),%rax
lea    0xdb7(%rip),%rdi
cmove  %rax,%rdi
mov    $0x1,%ebx
jmp    12cf <verify+0x13f>

LLVM IR (-O0):
@.str = [147 x i8] c"Error. The %s switch requires at least 2 parameters: username and password. Please use the following syntax.\0A $./passweb %s <username> <password>\0A\00"
@.str.1 = [13 x i8] c"password.csv\00"
@.str.2 = [2 x i8] c"r\00"
@SEEK_SET = global i32 0
@.str.3 = [68 x i8] c"Error. Database does not exist, please add users before verifying.\0A\00"
@.str.4 = [23 x i8] c"%[^, ], %[^, ], %[^\0A]\0A\00"
@.str.5 = [7 x i8] c"VALID\0A\00"
@.str.6 = [15 x i8] c"EXIST_SUCCESS\0A\00"
@.str.7 = [49 x i8] c"Error, user found, but password does not match.\0A\00"
@.str.8 = [9 x i8] c"INVALID\0A\00"
@.str.9 = [14 x i8] c"EXIT_FAILURE\0A\00"
define i32 @verify(i32 %0, i8** %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8**
%7 = alloca i32
%8 = alloca i32*
%9 = alloca [50 x i8]
%10 = alloca [50 x i8]
%11 = alloca [50 x i8]
%12 = alloca [50 x i8]
store i32 %0, i32* %5
store i8** %1, i8*** %6
store i32 %2, i32* %7
%13 = load i32, i32* %5
%14 = icmp slt i32 %13, 4
br i1 %14, label %15, label %23
15: ; preds = %3
%16 = load i8**, i8*** %6
%17 = getelementptr inbounds i8*, i8** %16, i64 1
%18 = load i8*, i8** %17
%19 = load i8**, i8*** %6
%20 = getelementptr inbounds i8*, i8** %19, i64 1
%21 = load i8*, i8** %20
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([147 x i8], [147 x i8]* @.str, i64 0, i64 0), i8* %18, i8* %21)
store i32 0, i32* %4
br label %89
23: ; preds = %3
%24 = call i32* @fopen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %24, i32** %8
%25 = load i32*, i32** %8
%26 = load i32, i32* @SEEK_SET
%27 = call i32 @fseek(i32* %25, i32 0, i32 %26)
%28 = load i32*, i32** %8
%29 = icmp eq i32* %28, null
br i1 %29, label %30, label %32
30: ; preds = %23
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([68 x i8], [68 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %4
br label %89
32: ; preds = %23
br label %33
33: ; preds = %78, %32
%34 = getelementptr inbounds [50 x i8], [50 x i8]* %9, i64 0, i64 0
%35 = load i32*, i32** %8
%36 = call i64 @fgets(i8* %34, i32 50, i32* %35)
%37 = icmp ne i64 %36, 0
br i1 %37, label %38, label %79
38: ; preds = %33
%39 = getelementptr inbounds [50 x i8], [50 x i8]* %9, i64 0, i64 0
%40 = call i32 @decrypt(i8* %39)
%41 = getelementptr inbounds [50 x i8], [50 x i8]* %9, i64 0, i64 0
%42 = getelementptr inbounds [50 x i8], [50 x i8]* %10, i64 0, i64 0
%43 = getelementptr inbounds [50 x i8], [50 x i8]* %11, i64 0, i64 0
%44 = getelementptr inbounds [50 x i8], [50 x i8]* %12, i64 0, i64 0
%45 = call i32 @sscanf(i8* %41, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0), i8* %42, i8* %43, i8* %44)
%46 = getelementptr inbounds [50 x i8], [50 x i8]* %10, i64 0, i64 0
%47 = load i8**, i8*** %6
%48 = getelementptr inbounds i8*, i8** %47, i64 2
%49 = load i8*, i8** %48
%50 = call i64 @strcmp(i8* %46, i8* %49)
%51 = icmp eq i64 %50, 0
br i1 %51, label %52, label %69
52: ; preds = %38
%53 = getelementptr inbounds [50 x i8], [50 x i8]* %11, i64 0, i64 0
%54 = load i8**, i8*** %6
%55 = getelementptr inbounds i8*, i8** %54, i64 3
%56 = load i8*, i8** %55
%57 = call i64 @strcmp(i8* %53, i8* %56)
%58 = icmp eq i64 %57, 0
br i1 %58, label %59, label %69
59: ; preds = %52
%60 = load i32, i32* %7
%61 = icmp ne i32 %60, 0
br i1 %61, label %62, label %64
62: ; preds = %59
%63 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0))
br label %66
64: ; preds = %59
%65 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0))
br label %66
66: ; preds = %64, %62
%67 = load i32*, i32** %8
%68 = call i32 @fclose(i32* %67)
store i32 1, i32* %4
br label %89
69: ; preds = %52, %38
%70 = getelementptr inbounds [50 x i8], [50 x i8]* %10, i64 0, i64 0
%71 = load i8**, i8*** %6
%72 = getelementptr inbounds i8*, i8** %71, i64 2
%73 = load i8*, i8** %72
%74 = call i64 @strcmp(i8* %70, i8* %73)
%75 = icmp eq i64 %74, 0
br i1 %75, label %76, label %78
76: ; preds = %69
%77 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.7, i64 0, i64 0))
br label %78
78: ; preds = %76, %69
br label %33
79: ; preds = %33
%80 = load i32, i32* %7
%81 = icmp ne i32 %80, 0
br i1 %81, label %82, label %84
82: ; preds = %79
%83 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.8, i64 0, i64 0))
br label %86
84: ; preds = %79
%85 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.9, i64 0, i64 0))
br label %86
86: ; preds = %84, %82
%87 = load i32*, i32** %8
%88 = call i32 @fclose(i32* %87)
store i32 0, i32* %4
br label %89
89: ; preds = %86, %66, %30, %15
%90 = load i32, i32* %4
ret i32 %90
}

LLVM IR (-O2):
@.str = [147 x i8] c"Error. The %s switch requires at least 2 parameters: username and password. Please use the following syntax.\0A $./passweb %s <username> <password>\0A\00"
@.str.1 = [13 x i8] c"password.csv\00"
@.str.2 = [2 x i8] c"r\00"
@SEEK_SET = global i32 0
@.str.4 = [23 x i8] c"%[^, ], %[^, ], %[^\0A]\0A\00"
@str = [13 x i8] c"EXIT_FAILURE\00"
@str.10 = [8 x i8] c"INVALID\00"
@str.11 = [48 x i8] c"Error, user found, but password does not match.\00"
@str.12 = [14 x i8] c"EXIST_SUCCESS\00"
@str.13 = [6 x i8] c"VALID\00"
@str.14 = [67 x i8] c"Error. Database does not exist, please add users before verifying.\00"
define i32 @verify(i32 %0, i8** nocapture %1, i32 %2) {
%4 = alloca [50 x i8]
%5 = alloca [50 x i8]
%6 = alloca [50 x i8]
%7 = alloca [50 x i8]
%8 = icmp slt i32 %0, 4
br i1 %8, label %9, label %13
9: ; preds = %3
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([147 x i8], [147 x i8]* @.str, i64 0, i64 0), i8* %11, i8* %11)
br label %60
13: ; preds = %3
%14 = tail call i32* @fopen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%15 = load i32, i32* @SEEK_SET
%16 = tail call i32 @fseek(i32* %14, i32 0, i32 %15)
%17 = icmp eq i32* %14, null
br i1 %17, label %18, label %20
18: ; preds = %13
%19 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([67 x i8], [67 x i8]* @str.14, i64 0, i64 0))
br label %60
20: ; preds = %13
%21 = getelementptr inbounds [50 x i8], [50 x i8]* %4, i64 0, i64 0
%22 = getelementptr inbounds [50 x i8], [50 x i8]* %5, i64 0, i64 0
%23 = getelementptr inbounds [50 x i8], [50 x i8]* %6, i64 0, i64 0
%24 = getelementptr inbounds [50 x i8], [50 x i8]* %7, i64 0, i64 0
%25 = call i64 @fgets(i8* %21, i32 50, i32* %14)
%26 = icmp eq i64 %25, 0
br i1 %26, label %52, label %27
27: ; preds = %20
%28 = getelementptr inbounds i8*, i8** %1, i64 2
%29 = getelementptr inbounds i8*, i8** %1, i64 3
br label %30
30: ; preds = %27, %49
%31 = call i32 @decrypt(i8* %21)
%32 = call i32 @sscanf(i8* %21, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0), i8* %22, i8* %23, i8* %24)
%33 = load i8*, i8** %28
%34 = call i64 @strcmp(i8* %22, i8* %33)
%35 = icmp eq i64 %34, 0
br i1 %35, label %36, label %43
36: ; preds = %30
%37 = load i8*, i8** %29
%38 = call i64 @strcmp(i8* %23, i8* %37)
%39 = icmp eq i64 %38, 0
br i1 %39, label %40, label %43
40: ; preds = %36
%41 = icmp eq i32 %2, 0
%42 = select i1 %41, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @str.12, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @str.13, i64 0, i64 0)
br label %55
43: ; preds = %36, %30
%44 = load i8*, i8** %28
%45 = call i64 @strcmp(i8* %22, i8* %44)
%46 = icmp eq i64 %45, 0
br i1 %46, label %47, label %49
47: ; preds = %43
%48 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([48 x i8], [48 x i8]* @str.11, i64 0, i64 0))
br label %49
49: ; preds = %47, %43
%50 = call i64 @fgets(i8* %21, i32 50, i32* %14)
%51 = icmp eq i64 %50, 0
br i1 %51, label %52, label %30
52: ; preds = %49, %20
%53 = icmp eq i32 %2, 0
%54 = select i1 %53, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @str, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @str.10, i64 0, i64 0)
br label %55
55: ; preds = %52, %40
%56 = phi i8* [ %54, %52 ], [ %42, %40 ]
%57 = phi i32 [ 0, %52 ], [ 1, %40 ]
%58 = call i32 @puts(i8* dereferenceable(1) %56)
%59 = call i32 @fclose(i32* %14)
br label %60
60: ; preds = %18, %55, %9
%61 = phi i32 [ 0, %9 ], [ 0, %18 ], [ %57, %55 ]
ret i32 %61
}