#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 doesFileExist(char const *, char const *);
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*/ free(char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ realloc(char *, int);
int /*<<< orphan*/ remove(char *);
int /*<<< orphan*/ strncat(char *, char const *, int);
scalar_t__ strncmp(char *, char const *, int);
char *strtok(char *, char *);
void removeFile(const char *path, const char *filename) {
  if (path == NULL || filename == NULL) {
    printf("ERROR: Could not read filesystem\n");
    return;
  }
  printf("Removing file at %s%s\n", path, filename);
  if (doesFileExist(path, filename) == 1) {
    char name[255];
    name[0] = 0;
    strncat(name, path, 255);
    strncat(name, ".list", 6);
    int multiplier = 1;
    char *listFileContents = (char *)malloc(sizeof(char) * 255);
    listFileContents[0] = 0;
    FILE *listFile = fopen(name, "r");
    char line[255];
    while (fgets(line, 255, listFile)) {
      char *l = strtok(line, "\n");
      if (strncmp(l, filename, 255) != 0) {
        multiplier++;
        listFileContents =
            (char *)realloc(listFileContents, sizeof(char) * 255 * multiplier);
        strncat(listFileContents, l, 255);
        strncat(listFileContents, "\n", 1);
      }
    }
    fclose(listFile);
    FILE *newListFile = fopen(name, "w");
    fprintf(newListFile, "%s", listFileContents);
    fclose(newListFile);
    free(listFileContents);
    char filePath[255];
    filePath[0] = 0;
    strncat(filePath, path, 255);
    strncat(filePath, filename, 255);
    remove(filePath);
  } else {
    printf("ERROR: Cannot remove a file that does not exist\n");
    return;
  }
}


x86 assembly (clang, -O0):
<removeFile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x340,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     11f9 <removeFile+0x29>
cmpq   $0x0,-0x10(%rbp)
jne    120c <removeFile+0x3c>
lea    0xe00(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
jmp    1415 <removeFile+0x245>
mov    -0x8(%rbp),%rsi
mov    -0x10(%rbp),%rdx
lea    0xe07(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1060 <doesFileExist@plt>
cmp    $0x1,%eax
jne    1407 <removeFile+0x237>
movb   $0x0,-0x110(%rbp)
lea    -0x110(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    $0xff,%edx
call   1090 <strncat@plt>
lea    -0x110(%rbp),%rdi
lea    0xdd7(%rip),%rsi
mov    $0x6,%edx
call   1090 <strncat@plt>
movl   $0x1,-0x114(%rbp)
mov    $0xff,%edi
call   10c0 <malloc@plt>
mov    %rax,-0x120(%rbp)
mov    -0x120(%rbp),%rax
movb   $0x0,(%rax)
lea    -0x110(%rbp),%rdi
lea    0xda0(%rip),%rsi
call   10e0 <fopen@plt>
mov    %rax,-0x128(%rbp)
lea    -0x230(%rbp),%rdi
mov    -0x128(%rbp),%rdx
mov    $0xff,%esi
call   10a0 <fgets@plt>
cmp    $0x0,%rax
je     136d <removeFile+0x19d>
lea    -0x230(%rbp),%rdi
lea    0xd45(%rip),%rsi
call   10f0 <strtok@plt>
mov    %rax,-0x238(%rbp)
mov    -0x238(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    $0xff,%edx
call   1050 <strncmp@plt>
cmp    $0x0,%rax
je     1368 <removeFile+0x198>
mov    -0x114(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x114(%rbp)
mov    -0x120(%rbp),%rdi
movslq -0x114(%rbp),%rax
imul   $0xff,%rax,%rax
mov    %eax,%esi
call   10d0 <realloc@plt>
mov    %rax,-0x120(%rbp)
mov    -0x120(%rbp),%rdi
mov    -0x238(%rbp),%rsi
mov    $0xff,%edx
call   1090 <strncat@plt>
mov    -0x120(%rbp),%rdi
lea    0xcc2(%rip),%rsi
mov    $0x1,%edx
call   1090 <strncat@plt>
jmp    12ab <removeFile+0xdb>
mov    -0x128(%rbp),%rdi
call   1070 <fclose@plt>
lea    -0x110(%rbp),%rdi
lea    0xcba(%rip),%rsi
call   10e0 <fopen@plt>
mov    %rax,-0x240(%rbp)
mov    -0x240(%rbp),%rdi
mov    -0x120(%rbp),%rdx
lea    0xc9b(%rip),%rsi
call   10b0 <fprintf@plt>
mov    -0x240(%rbp),%rdi
call   1070 <fclose@plt>
mov    -0x120(%rbp),%rdi
call   1030 <free@plt>
movb   $0x0,-0x340(%rbp)
lea    -0x340(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    $0xff,%edx
call   1090 <strncat@plt>
lea    -0x340(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    $0xff,%edx
call   1090 <strncat@plt>
lea    -0x340(%rbp),%rdi
call   1040 <remove@plt>
jmp    1415 <removeFile+0x245>
lea    0xc38(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
add    $0x340,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<removeFile>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x318,%rsp
test   %rdi,%rdi
je     1337 <removeFile+0x157>
mov    %rsi,%rbx
test   %rsi,%rsi
je     1337 <removeFile+0x157>
mov    %rdi,%rbp
lea    0xdf0(%rip),%rdi
mov    %rbp,%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1090 <printf@plt>
mov    %rbp,%rdi
mov    %rbx,%rsi
call   1060 <doesFileExist@plt>
cmp    $0x1,%eax
jne    1340 <removeFile+0x160>
mov    %rbx,(%rsp)
movb   $0x0,0x10(%rsp)
lea    0x10(%rsp),%r14
mov    %r14,%rdi
mov    %rbp,0x8(%rsp)
mov    %rbp,%rsi
mov    $0xff,%edx
call   10b0 <strncat@plt>
lea    0xdbc(%rip),%rsi
mov    %r14,%rdi
mov    $0x6,%edx
call   10b0 <strncat@plt>
mov    $0xff,%edi
call   10d0 <malloc@plt>
mov    %rax,%rbx
movb   $0x0,(%rax)
lea    0xd9e(%rip),%rsi
mov    %r14,%rdi
call   10f0 <fopen@plt>
mov    %rax,%r12
lea    0x210(%rsp),%rdi
mov    $0xff,%esi
mov    %rax,%rdx
call   10c0 <fgets@plt>
test   %rax,%rax
je     135d <removeFile+0x17d>
mov    $0x1,%r15d
lea    0xd60(%rip),%r13
lea    0x210(%rsp),%rbp
jmp    12d9 <removeFile+0xf9>
nop
mov    %rbp,%rdi
mov    $0xff,%esi
mov    %r12,%rdx
call   10c0 <fgets@plt>
test   %rax,%rax
je     135d <removeFile+0x17d>
mov    %rbp,%rdi
mov    %r13,%rsi
call   1100 <strtok@plt>
mov    %rax,%r14
mov    %rax,%rdi
mov    (%rsp),%rsi
mov    $0xff,%edx
call   1050 <strncmp@plt>
test   %rax,%rax
je     12c0 <removeFile+0xe0>
add    $0x1,%r15d
mov    %r15d,%esi
shl    $0x8,%esi
sub    %r15d,%esi
mov    %rbx,%rdi
call   10e0 <realloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r14,%rsi
mov    $0xff,%edx
call   10b0 <strncat@plt>
mov    %rbx,%rdi
mov    %r13,%rsi
mov    $0x1,%edx
call   10b0 <strncat@plt>
jmp    12c0 <removeFile+0xe0>
lea    0xd13(%rip),%rdi
jmp    1347 <removeFile+0x167>
lea    0xcda(%rip),%rdi
add    $0x318,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1070 <puts@plt>
mov    %r12,%rdi
call   1080 <fclose@plt>
lea    0xcb3(%rip),%rsi
lea    0x10(%rsp),%rdi
call   10f0 <fopen@plt>
mov    %rax,%rbp
mov    %rbx,%rdi
mov    %rax,%rsi
call   10a0 <fputs@plt>
mov    %rbp,%rdi
call   1080 <fclose@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
movb   $0x0,0x110(%rsp)
lea    0x110(%rsp),%rbx
mov    %rbx,%rdi
mov    0x8(%rsp),%rsi
mov    $0xff,%edx
call   10b0 <strncat@plt>
mov    %rbx,%rdi
mov    (%rsp),%rsi
mov    $0xff,%edx
call   10b0 <strncat@plt>
mov    %rbx,%rdi
call   1040 <remove@plt>
add    $0x318,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [34 x i8] c"ERROR: Could not read filesystem\0A\00"
@.str.1 = [23 x i8] c"Removing file at %s%s\0A\00"
@.str.2 = [6 x i8] c".list\00"
@.str.3 = [2 x i8] c"r\00"
@.str.4 = [2 x i8] c"\0A\00"
@.str.5 = [2 x i8] c"w\00"
@.str.6 = [3 x i8] c"%s\00"
@.str.7 = [49 x i8] c"ERROR: Cannot remove a file that does not exist\0A\00"
define void @removeFile(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca [255 x i8]
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32*
%9 = alloca [255 x i8]
%10 = alloca i8*
%11 = alloca i32*
%12 = alloca [255 x i8]
store i8* %0, i8** %3
store i8* %1, i8** %4
%13 = load i8*, i8** %3
%14 = icmp eq i8* %13, null
br i1 %14, label %18, label %15
15: ; preds = %2
%16 = load i8*, i8** %4
%17 = icmp eq i8* %16, null
br i1 %17, label %18, label %20
18: ; preds = %15, %2
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0))
br label %92
20: ; preds = %15
%21 = load i8*, i8** %3
%22 = load i8*, i8** %4
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* %21, i8* %22)
%24 = load i8*, i8** %3
%25 = load i8*, i8** %4
%26 = call i32 @doesFileExist(i8* %24, i8* %25)
%27 = icmp eq i32 %26, 1
br i1 %27, label %28, label %90
28: ; preds = %20
%29 = getelementptr inbounds [255 x i8], [255 x i8]* %5, i64 0, i64 0
store i8 0, i8* %29
%30 = getelementptr inbounds [255 x i8], [255 x i8]* %5, i64 0, i64 0
%31 = load i8*, i8** %3
%32 = call i32 @strncat(i8* %30, i8* %31, i32 255)
%33 = getelementptr inbounds [255 x i8], [255 x i8]* %5, i64 0, i64 0
%34 = call i32 @strncat(i8* %33, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 6)
store i32 1, i32* %6
%35 = call i64 @malloc(i32 255)
%36 = inttoptr i64 %35 to i8*
store i8* %36, i8** %7
%37 = load i8*, i8** %7
%38 = getelementptr inbounds i8, i8* %37, i64 0
store i8 0, i8* %38
%39 = getelementptr inbounds [255 x i8], [255 x i8]* %5, i64 0, i64 0
%40 = call i32* @fopen(i8* %39, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %40, i32** %8
br label %41
41: ; preds = %68, %28
%42 = getelementptr inbounds [255 x i8], [255 x i8]* %9, i64 0, i64 0
%43 = load i32*, i32** %8
%44 = call i64 @fgets(i8* %42, i32 255, i32* %43)
%45 = icmp ne i64 %44, 0
br i1 %45, label %46, label %69
46: ; preds = %41
%47 = getelementptr inbounds [255 x i8], [255 x i8]* %9, i64 0, i64 0
%48 = call i8* @strtok(i8* %47, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i8* %48, i8** %10
%49 = load i8*, i8** %10
%50 = load i8*, i8** %4
%51 = call i64 @strncmp(i8* %49, i8* %50, i32 255)
%52 = icmp ne i64 %51, 0
br i1 %52, label %53, label %68
53: ; preds = %46
%54 = load i32, i32* %6
%55 = add nsw i32 %54, 1
store i32 %55, i32* %6
%56 = load i8*, i8** %7
%57 = load i32, i32* %6
%58 = sext i32 %57 to i64
%59 = mul i64 255, %58
%60 = trunc i64 %59 to i32
%61 = call i64 @realloc(i8* %56, i32 %60)
%62 = inttoptr i64 %61 to i8*
store i8* %62, i8** %7
%63 = load i8*, i8** %7
%64 = load i8*, i8** %10
%65 = call i32 @strncat(i8* %63, i8* %64, i32 255)
%66 = load i8*, i8** %7
%67 = call i32 @strncat(i8* %66, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0), i32 1)
br label %68
68: ; preds = %53, %46
br label %41
69: ; preds = %41
%70 = load i32*, i32** %8
%71 = call i32 @fclose(i32* %70)
%72 = getelementptr inbounds [255 x i8], [255 x i8]* %5, i64 0, i64 0
%73 = call i32* @fopen(i8* %72, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
store i32* %73, i32** %11
%74 = load i32*, i32** %11
%75 = load i8*, i8** %7
%76 = call i32 @fprintf(i32* %74, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i8* %75)
%77 = load i32*, i32** %11
%78 = call i32 @fclose(i32* %77)
%79 = load i8*, i8** %7
%80 = call i32 @free(i8* %79)
%81 = getelementptr inbounds [255 x i8], [255 x i8]* %12, i64 0, i64 0
store i8 0, i8* %81
%82 = getelementptr inbounds [255 x i8], [255 x i8]* %12, i64 0, i64 0
%83 = load i8*, i8** %3
%84 = call i32 @strncat(i8* %82, i8* %83, i32 255)
%85 = getelementptr inbounds [255 x i8], [255 x i8]* %12, i64 0, i64 0
%86 = load i8*, i8** %4
%87 = call i32 @strncat(i8* %85, i8* %86, i32 255)
%88 = getelementptr inbounds [255 x i8], [255 x i8]* %12, i64 0, i64 0
%89 = call i32 @remove(i8* %88)
br label %92
90: ; preds = %20
%91 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.7, i64 0, i64 0))
br label %92
92: ; preds = %18, %90, %69
ret void
}

LLVM IR (-O2):
@.str.1 = [23 x i8] c"Removing file at %s%s\0A\00"
@.str.2 = [6 x i8] c".list\00"
@.str.3 = [2 x i8] c"r\00"
@.str.4 = [2 x i8] c"\0A\00"
@.str.5 = [2 x i8] c"w\00"
@str = [48 x i8] c"ERROR: Cannot remove a file that does not exist\00"
@str.8 = [33 x i8] c"ERROR: Could not read filesystem\00"
define void @removeFile(i8* %0, i8* %1) {
%3 = alloca [255 x i8]
%4 = alloca [255 x i8]
%5 = alloca [255 x i8]
%6 = icmp eq i8* %0, null
%7 = icmp eq i8* %1, null
%8 = or i1 %6, %7
br i1 %8, label %9, label %11
9: ; preds = %2
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @str.8, i64 0, i64 0))
br label %56
11: ; preds = %2
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* %0, i8* %1)
%13 = tail call i32 @doesFileExist(i8* %0, i8* %1)
%14 = icmp eq i32 %13, 1
br i1 %14, label %15, label %54
15: ; preds = %11
%16 = getelementptr inbounds [255 x i8], [255 x i8]* %3, i64 0, i64 0
store i8 0, i8* %16
%17 = call i32 @strncat(i8* %16, i8* %0, i32 255)
%18 = call i32 @strncat(i8* %16, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 6)
%19 = call i64 @malloc(i32 255)
%20 = inttoptr i64 %19 to i8*
store i8 0, i8* %20
%21 = call i32* @fopen(i8* %16, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%22 = getelementptr inbounds [255 x i8], [255 x i8]* %4, i64 0, i64 0
%23 = call i64 @fgets(i8* %22, i32 255, i32* %21)
%24 = icmp eq i64 %23, 0
br i1 %24, label %43, label %25
25: ; preds = %15, %38
%26 = phi i32 [ %40, %38 ], [ 1, %15 ]
%27 = phi i8* [ %39, %38 ], [ %20, %15 ]
%28 = call i8* @strtok(i8* %22, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%29 = call i64 @strncmp(i8* %28, i8* %1, i32 255)
%30 = icmp eq i64 %29, 0
br i1 %30, label %38, label %31
31: ; preds = %25
%32 = add nsw i32 %26, 1
%33 = mul i32 %32, 255
%34 = call i64 @realloc(i8* %27, i32 %33)
%35 = inttoptr i64 %34 to i8*
%36 = call i32 @strncat(i8* %35, i8* %28, i32 255)
%37 = call i32 @strncat(i8* %35, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0), i32 1)
br label %38
38: ; preds = %31, %25
%39 = phi i8* [ %35, %31 ], [ %27, %25 ]
%40 = phi i32 [ %32, %31 ], [ %26, %25 ]
%41 = call i64 @fgets(i8* %22, i32 255, i32* %21)
%42 = icmp eq i64 %41, 0
br i1 %42, label %43, label %25
43: ; preds = %38, %15
%44 = phi i8* [ %20, %15 ], [ %39, %38 ]
%45 = call i32 @fclose(i32* %21)
%46 = call i32* @fopen(i8* %16, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%47 = call i32 @fputs(i8* %44, i32* %46)
%48 = call i32 @fclose(i32* %46)
%49 = call i32 @free(i8* %44)
%50 = getelementptr inbounds [255 x i8], [255 x i8]* %5, i64 0, i64 0
store i8 0, i8* %50
%51 = call i32 @strncat(i8* %50, i8* %0, i32 255)
%52 = call i32 @strncat(i8* %50, i8* %1, i32 255)
%53 = call i32 @remove(i8* %50)
br label %56
54: ; preds = %11
%55 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([48 x i8], [48 x i8]* @str, i64 0, i64 0))
br label %56
56: ; preds = %9, %54, %43
ret void
}