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

/* Variables and functions */
int /*<<< orphan*/ SEEK_END;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ decrypt(char *);
int /*<<< orphan*/ encrypt(char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, char *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char *, ...);
int /*<<< orphan*/ snprintf(char *, int, char *, char *, char *, char *);
int /*<<< orphan*/ sscanf(char *, char *, char *, char *, char *);
scalar_t__ strcmp(char *, char *);
void add(int argc, char *argv[]) {
  if (argc < 5) {
    printf("Error. The %s switch requires at least 3 parameters: username "
           "password and type. Please use the following syntax.\n $./passweb "
           "%s <username> <password> <type>\n",
           argv[1], argv[1]);
    return;
  }
  FILE *file = fopen("password.csv", "a+");
  fseek(file, 0, SEEK_SET);
  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) {
      printf("The username %s already exists in the database. Nothing will be "
             "added.\n",
             userTemp);
      fclose(file);
      return;
    }
  }
  char lineInsert[50];
  snprintf(lineInsert, sizeof(lineInsert), "%s, %s, %s\n", argv[2], argv[3],
           argv[4]);
  encrypt(lineInsert);
  fseek(file, 0, SEEK_END);
  fprintf(file, "%s", lineInsert);
  printf("The user %s has been created in the database.\n", argv[2]);
  fclose(file);
}


x86 assembly (clang, -O0):
<add>:
push   %rbp
mov    %rsp,%rbp
sub    $0x150,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x5,-0x4(%rbp)
jge    11ef <add+0x3f>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xe1d(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1330 <add+0x180>
lea    0xea9(%rip),%rdi
lea    0xeaf(%rip),%rsi
call   10d0 <fopen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    0x2dc7(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   10c0 <fseek@plt>
lea    -0x50(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x32,%esi
call   1080 <fgets@plt>
cmp    $0x0,%rax
je     12aa <add+0xfa>
lea    -0x50(%rbp),%rdi
call   1030 <decrypt@plt>
lea    -0x50(%rbp),%rdi
lea    -0x90(%rbp),%rdx
lea    -0xd0(%rbp),%rcx
lea    -0x110(%rbp),%r8
lea    0xe50(%rip),%rsi
call   10b0 <sscanf@plt>
lea    -0x90(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
call   1090 <strcmp@plt>
cmp    $0x0,%rax
jne    12a5 <add+0xf5>
lea    -0x90(%rbp),%rsi
lea    0xe36(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
jmp    1330 <add+0x180>
jmp    121a <add+0x6a>
lea    -0x150(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rcx
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%r8
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%r9
mov    $0x32,%esi
lea    0xe39(%rip),%rdx
call   1070 <snprintf@plt>
lea    -0x150(%rbp),%rdi
call   1060 <encrypt@plt>
mov    -0x18(%rbp),%rdi
mov    0x2cf7(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   10c0 <fseek@plt>
mov    -0x18(%rbp),%rdi
lea    -0x150(%rbp),%rdx
lea    0xe0e(%rip),%rsi
call   10a0 <fprintf@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
lea    0xdfd(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
add    $0x150,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<add>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x138,%rsp
mov    %rsi,%r15
cmp    $0x4,%edi
jg     11ef <add+0x3f>
mov    0x8(%r15),%rdx
lea    0xe2c(%rip),%rdi
mov    %rdx,%rsi
xor    %eax,%eax
add    $0x138,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <printf@plt>
lea    0xea9(%rip),%rdi
lea    0xeaf(%rip),%rsi
call   10d0 <fopen@plt>
mov    %rax,%r14
mov    0x2dcc(%rip),%rax
mov    (%rax),%edx
mov    %r14,%rdi
xor    %esi,%esi
call   10c0 <fseek@plt>
lea    0x100(%rsp),%rbx
mov    %rsp,%r13
lea    0xc0(%rsp),%rbp
lea    0x80(%rsp),%r12
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rbx,%rdi
mov    $0x32,%esi
mov    %r14,%rdx
call   1090 <fgets@plt>
test   %rax,%rax
je     1292 <add+0xe2>
mov    %rbx,%rdi
call   1030 <decrypt@plt>
mov    %rbx,%rdi
lea    0xe48(%rip),%rsi
mov    %r13,%rdx
mov    %rbp,%rcx
mov    %r12,%r8
call   10b0 <sscanf@plt>
mov    0x10(%r15),%rsi
mov    %r13,%rdi
call   10a0 <strcmp@plt>
test   %rax,%rax
jne    1240 <add+0x90>
lea    0xe39(%rip),%rdi
mov    %rsp,%rsi
jmp    12e8 <add+0x138>
mov    0x10(%r15),%rcx
mov    0x18(%r15),%r8
mov    0x20(%r15),%r9
lea    0xe69(%rip),%rdx
lea    0x40(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x32,%esi
call   1070 <snprintf@plt>
mov    %rbx,%rdi
call   1060 <encrypt@plt>
mov    0x2d22(%rip),%rax
mov    (%rax),%edx
mov    %r14,%rdi
xor    %esi,%esi
call   10c0 <fseek@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1080 <fputs@plt>
mov    0x10(%r15),%rsi
lea    0xe32(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r14,%rdi
call   1040 <fclose@plt>
add    $0x138,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [159 x i8] c"Error. The %s switch requires at least 3 parameters: username password and type. Please use the following syntax.\0A $./passweb %s <username> <password> <type>\0A\00"
@.str.1 = [13 x i8] c"password.csv\00"
@.str.2 = [3 x i8] c"a+\00"
@SEEK_SET = global i32 0
@.str.3 = [23 x i8] c"%[^, ], %[^, ], %[^\0A]\0A\00"
@.str.4 = [72 x i8] c"The username %s already exists in the database. Nothing will be added.\0A\00"
@.str.5 = [12 x i8] c"%s, %s, %s\0A\00"
@SEEK_END = global i32 0
@.str.6 = [3 x i8] c"%s\00"
@.str.7 = [47 x i8] c"The user %s has been created in the database.\0A\00"
define void @add(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i32*
%6 = alloca [50 x i8]
%7 = alloca [50 x i8]
%8 = alloca [50 x i8]
%9 = alloca [50 x i8]
%10 = alloca [50 x i8]
store i32 %0, i32* %3
store i8** %1, i8*** %4
%11 = load i32, i32* %3
%12 = icmp slt i32 %11, 5
br i1 %12, label %13, label %21
13: ; preds = %2
%14 = load i8**, i8*** %4
%15 = getelementptr inbounds i8*, i8** %14, i64 1
%16 = load i8*, i8** %15
%17 = load i8**, i8*** %4
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = load i8*, i8** %18
%20 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([159 x i8], [159 x i8]* @.str, i64 0, i64 0), i8* %16, i8* %19)
br label %77
21: ; preds = %2
%22 = call i32* @fopen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
store i32* %22, i32** %5
%23 = load i32*, i32** %5
%24 = load i32, i32* @SEEK_SET
%25 = call i32 @fseek(i32* %23, i32 0, i32 %24)
br label %26
26: ; preds = %50, %21
%27 = getelementptr inbounds [50 x i8], [50 x i8]* %6, i64 0, i64 0
%28 = load i32*, i32** %5
%29 = call i64 @fgets(i8* %27, i32 50, i32* %28)
%30 = icmp ne i64 %29, 0
br i1 %30, label %31, label %51
31: ; preds = %26
%32 = getelementptr inbounds [50 x i8], [50 x i8]* %6, i64 0, i64 0
%33 = call i32 @decrypt(i8* %32)
%34 = getelementptr inbounds [50 x i8], [50 x i8]* %6, i64 0, i64 0
%35 = getelementptr inbounds [50 x i8], [50 x i8]* %7, i64 0, i64 0
%36 = getelementptr inbounds [50 x i8], [50 x i8]* %8, i64 0, i64 0
%37 = getelementptr inbounds [50 x i8], [50 x i8]* %9, i64 0, i64 0
%38 = call i32 @sscanf(i8* %34, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), i8* %35, i8* %36, i8* %37)
%39 = getelementptr inbounds [50 x i8], [50 x i8]* %7, i64 0, i64 0
%40 = load i8**, i8*** %4
%41 = getelementptr inbounds i8*, i8** %40, i64 2
%42 = load i8*, i8** %41
%43 = call i64 @strcmp(i8* %39, i8* %42)
%44 = icmp eq i64 %43, 0
br i1 %44, label %45, label %50
45: ; preds = %31
%46 = getelementptr inbounds [50 x i8], [50 x i8]* %7, i64 0, i64 0
%47 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([72 x i8], [72 x i8]* @.str.4, i64 0, i64 0), i8* %46)
%48 = load i32*, i32** %5
%49 = call i32 @fclose(i32* %48)
br label %77
50: ; preds = %31
br label %26
51: ; preds = %26
%52 = getelementptr inbounds [50 x i8], [50 x i8]* %10, i64 0, i64 0
%53 = load i8**, i8*** %4
%54 = getelementptr inbounds i8*, i8** %53, i64 2
%55 = load i8*, i8** %54
%56 = load i8**, i8*** %4
%57 = getelementptr inbounds i8*, i8** %56, i64 3
%58 = load i8*, i8** %57
%59 = load i8**, i8*** %4
%60 = getelementptr inbounds i8*, i8** %59, i64 4
%61 = load i8*, i8** %60
%62 = call i32 @snprintf(i8* %52, i32 50, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0), i8* %55, i8* %58, i8* %61)
%63 = getelementptr inbounds [50 x i8], [50 x i8]* %10, i64 0, i64 0
%64 = call i32 @encrypt(i8* %63)
%65 = load i32*, i32** %5
%66 = load i32, i32* @SEEK_END
%67 = call i32 @fseek(i32* %65, i32 0, i32 %66)
%68 = load i32*, i32** %5
%69 = getelementptr inbounds [50 x i8], [50 x i8]* %10, i64 0, i64 0
%70 = call i32 @fprintf(i32* %68, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i8* %69)
%71 = load i8**, i8*** %4
%72 = getelementptr inbounds i8*, i8** %71, i64 2
%73 = load i8*, i8** %72
%74 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.7, i64 0, i64 0), i8* %73)
%75 = load i32*, i32** %5
%76 = call i32 @fclose(i32* %75)
br label %77
77: ; preds = %51, %45, %13
ret void
}

LLVM IR (-O2):
@.str = [159 x i8] c"Error. The %s switch requires at least 3 parameters: username password and type. Please use the following syntax.\0A $./passweb %s <username> <password> <type>\0A\00"
@.str.1 = [13 x i8] c"password.csv\00"
@.str.2 = [3 x i8] c"a+\00"
@SEEK_SET = global i32 0
@.str.3 = [23 x i8] c"%[^, ], %[^, ], %[^\0A]\0A\00"
@.str.4 = [72 x i8] c"The username %s already exists in the database. Nothing will be added.\0A\00"
@.str.5 = [12 x i8] c"%s, %s, %s\0A\00"
@SEEK_END = global i32 0
@.str.7 = [47 x i8] c"The user %s has been created in the database.\0A\00"
define void @add(i32 %0, i8** nocapture %1) {
%3 = alloca [50 x i8]
%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, 5
br i1 %8, label %9, label %13
9: ; preds = %2
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([159 x i8], [159 x i8]* @.str, i64 0, i64 0), i8* %11, i8* %11)
br label %50
13: ; preds = %2
%14 = tail call i32* @fopen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 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 = getelementptr inbounds [50 x i8], [50 x i8]* %3, i64 0, i64 0
%18 = getelementptr inbounds [50 x i8], [50 x i8]* %4, i64 0, i64 0
%19 = getelementptr inbounds [50 x i8], [50 x i8]* %5, i64 0, i64 0
%20 = getelementptr inbounds [50 x i8], [50 x i8]* %6, i64 0, i64 0
%21 = getelementptr inbounds i8*, i8** %1, i64 2
br label %22
22: ; preds = %25, %13
%23 = call i64 @fgets(i8* %17, i32 50, i32* %14)
%24 = icmp eq i64 %23, 0
br i1 %24, label %34, label %25
25: ; preds = %22
%26 = call i32 @decrypt(i8* %17)
%27 = call i32 @sscanf(i8* %17, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), i8* %18, i8* %19, i8* %20)
%28 = load i8*, i8** %21
%29 = call i64 @strcmp(i8* %18, i8* %28)
%30 = icmp eq i64 %29, 0
br i1 %30, label %31, label %22
31: ; preds = %25
%32 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([72 x i8], [72 x i8]* @.str.4, i64 0, i64 0), i8* %18)
%33 = call i32 @fclose(i32* %14)
br label %49
34: ; preds = %22
%35 = getelementptr inbounds [50 x i8], [50 x i8]* %7, i64 0, i64 0
%36 = load i8*, i8** %21
%37 = getelementptr inbounds i8*, i8** %1, i64 3
%38 = load i8*, i8** %37
%39 = getelementptr inbounds i8*, i8** %1, i64 4
%40 = load i8*, i8** %39
%41 = call i32 @snprintf(i8* %35, i32 50, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0), i8* %36, i8* %38, i8* %40)
%42 = call i32 @encrypt(i8* %35)
%43 = load i32, i32* @SEEK_END
%44 = call i32 @fseek(i32* %14, i32 0, i32 %43)
%45 = call i32 @fputs(i8* %35, i32* %14)
%46 = load i8*, i8** %21
%47 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.7, i64 0, i64 0), i8* %46)
%48 = call i32 @fclose(i32* %14)
br label %49
49: ; preds = %34, %31
br label %50
50: ; preds = %49, %9
ret void
}