#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*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ free(char *);
char *get_status_file_tmp_path();
int /*<<< orphan*/ remove(char *);
int /*<<< orphan*/ rename(char *, char *);
int /*<<< orphan*/ rewind(int /*<<< orphan*/ *);
int status_count_file_lines(int /*<<< orphan*/ *);
char *status_get_file_path();
int /*<<< orphan*/ *status_get_file_ptr(char *);
char *status_read_file_line(int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
scalar_t__ strcmp(char *, char const *);
int status_del_tracking(const char *path) {
  FILE *fp = NULL;
  FILE *tmp = NULL;
  int count;
  char *line = NULL;
  int linefound = 0;
  int current = 0;
  char *tmppath = NULL;
  fp = status_get_file_ptr("r");
  if (fp == NULL)
    return -1;
  count = status_count_file_lines(fp);
  if (count == -2) {
    fclose(fp);
    return -1;
  }
  rewind(fp);
  tmppath = get_status_file_tmp_path();
  if (tmppath == NULL) {
    fclose(fp);
    return -1;
  }
  tmp = fopen(tmppath, "w+");
  while (count >= 0) {
    line = status_read_file_line(fp);
    if (line == NULL) {
      fprintf(stderr, "Error reading line.\n");
      fclose(fp);
      free(tmppath);
      return -1;
    }
    if (strcmp(line, path) != 0)
      fprintf(tmp, "%s\n", line);
    else
      linefound = current;
    current++;
    count--;
    free(line);
  }
  fclose(fp);
  fclose(tmp);
  char *p = status_get_file_path();
  remove(p);
  rename(tmppath, p);
  free(p);
  free(tmppath);
  return linefound;
}


x86 assembly (clang, -O0):
<status_del_tracking>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
movl   $0x0,-0x38(%rbp)
movq   $0x0,-0x40(%rbp)
lea    0xdef(%rip),%rdi
call   10a0 <status_get_file_ptr@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1231 <status_del_tracking+0x61>
movl   $0xffffffff,-0x4(%rbp)
jmp    139f <status_del_tracking+0x1cf>
mov    -0x18(%rbp),%rdi
call   10f0 <status_count_file_lines@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0xfffffffe,-0x24(%rbp)
jne    125c <status_del_tracking+0x8c>
mov    -0x18(%rbp),%rdi
call   1050 <fclose@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    139f <status_del_tracking+0x1cf>
mov    -0x18(%rbp),%rdi
call   1060 <rewind@plt>
mov    $0x0,%al
call   10b0 <get_status_file_tmp_path@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
jne    1290 <status_del_tracking+0xc0>
mov    -0x18(%rbp),%rdi
call   1050 <fclose@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    139f <status_del_tracking+0x1cf>
mov    -0x40(%rbp),%rdi
lea    0xd67(%rip),%rsi
call   10d0 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpl   $0x0,-0x24(%rbp)
jl     1354 <status_del_tracking+0x184>
mov    -0x18(%rbp),%rdi
call   1080 <status_read_file_line@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    12fc <status_del_tracking+0x12c>
mov    0x2d13(%rip),%rax
movslq (%rax),%rdi
lea    0xd2e(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    -0x18(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    139f <status_del_tracking+0x1cf>
mov    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
je     132e <status_del_tracking+0x15e>
mov    -0x20(%rbp),%rdi
mov    -0x30(%rbp),%rdx
lea    0xcf8(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
jmp    1334 <status_del_tracking+0x164>
mov    -0x38(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
mov    -0x24(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x24(%rbp)
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
jmp    12a4 <status_del_tracking+0xd4>
mov    -0x18(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x20(%rbp),%rdi
call   1050 <fclose@plt>
mov    $0x0,%al
call   10c0 <status_get_file_path@plt>
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rdi
call   1040 <remove@plt>
mov    -0x40(%rbp),%rdi
mov    -0x48(%rbp),%rsi
call   10e0 <rename@plt>
mov    -0x48(%rbp),%rdi
call   1030 <free@plt>
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
mov    -0x34(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<status_del_tracking>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdi,0x10(%rsp)
lea    0xe06(%rip),%rdi
call   10a0 <status_get_file_ptr@plt>
mov    $0xffffffff,%r14d
test   %rax,%rax
je     1351 <status_del_tracking+0x171>
mov    %rax,%rbx
mov    %rax,%rdi
call   10f0 <status_count_file_lines@plt>
cmp    $0xfffffffe,%eax
je     12c8 <status_del_tracking+0xe8>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1060 <rewind@plt>
xor    %r12d,%r12d
xor    %eax,%eax
call   10b0 <get_status_file_tmp_path@plt>
test   %rax,%rax
je     12c8 <status_del_tracking+0xe8>
lea    0xdbc(%rip),%rsi
mov    %rax,(%rsp)
mov    %rax,%rdi
call   10d0 <fopen@plt>
mov    %rax,0x8(%rsp)
test   %ebp,%ebp
js     12d2 <status_del_tracking+0xf2>
add    $0x1,%ebp
xor    %r15d,%r15d
xor    %r13d,%r13d
jmp    1284 <status_del_tracking+0xa4>
cs nopw 0x0(%rax,%rax,1)
add    $0x1,%r15d
mov    %r14,%rdi
call   1030 <free@plt>
mov    %r12d,%r13d
cmp    %r15d,%ebp
je     12d2 <status_del_tracking+0xf2>
mov    %rbx,%rdi
call   1080 <status_read_file_line@plt>
test   %rax,%rax
je     131a <status_del_tracking+0x13a>
mov    %rax,%r14
mov    %rax,%rdi
mov    0x10(%rsp),%rsi
call   1070 <strcmp@plt>
mov    %r15d,%r12d
test   %rax,%rax
je     1270 <status_del_tracking+0x90>
mov    0x8(%rsp),%rdi
lea    0xd61(%rip),%rsi
mov    %r14,%rdx
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    %r13d,%r12d
jmp    1270 <status_del_tracking+0x90>
mov    %rbx,%rdi
call   1050 <fclose@plt>
jmp    1351 <status_del_tracking+0x171>
mov    %rbx,%rdi
call   1050 <fclose@plt>
mov    0x8(%rsp),%rdi
call   1050 <fclose@plt>
xor    %eax,%eax
call   10c0 <status_get_file_path@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1040 <remove@plt>
mov    (%rsp),%rbp
mov    %rbp,%rdi
mov    %rbx,%rsi
call   10e0 <rename@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %rbp,%rdi
call   1030 <free@plt>
mov    %r12d,%r14d
jmp    1351 <status_del_tracking+0x171>
mov    0x2cbf(%rip),%rax
movslq (%rax),%rcx
lea    0xcda(%rip),%rdi
mov    $0x14,%esi
mov    $0x1,%edx
call   1100 <fwrite@plt>
mov    %rbx,%rdi
call   1050 <fclose@plt>
mov    (%rsp),%rdi
call   1030 <free@plt>
mov    $0xffffffff,%r14d
mov    %r14d,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [3 x i8] c"w+\00"
@stderr = global i32 0
@.str.2 = [21 x i8] c"Error reading line.\0A\00"
@.str.3 = [4 x i8] c"%s\0A\00"
define i32 @status_del_tracking(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i8*
store i8* %0, i8** %3
store i32* null, i32** %4
store i32* null, i32** %5
store i8* null, i8** %7
store i32 0, i32* %8
store i32 0, i32* %9
store i8* null, i8** %10
%12 = call i32* @status_get_file_ptr(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %12, i32** %4
%13 = load i32*, i32** %4
%14 = icmp eq i32* %13, null
br i1 %14, label %15, label %16
15: ; preds = %1
store i32 -1, i32* %2
br label %87
16: ; preds = %1
%17 = load i32*, i32** %4
%18 = call i32 @status_count_file_lines(i32* %17)
store i32 %18, i32* %6
%19 = load i32, i32* %6
%20 = icmp eq i32 %19, -2
br i1 %20, label %21, label %24
21: ; preds = %16
%22 = load i32*, i32** %4
%23 = call i32 @fclose(i32* %22)
store i32 -1, i32* %2
br label %87
24: ; preds = %16
%25 = load i32*, i32** %4
%26 = call i32 @rewind(i32* %25)
%27 = call i8* (...) @get_status_file_tmp_path()
store i8* %27, i8** %10
%28 = load i8*, i8** %10
%29 = icmp eq i8* %28, null
br i1 %29, label %30, label %33
30: ; preds = %24
%31 = load i32*, i32** %4
%32 = call i32 @fclose(i32* %31)
store i32 -1, i32* %2
br label %87
33: ; preds = %24
%34 = load i8*, i8** %10
%35 = call i32* @fopen(i8* %34, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %35, i32** %5
br label %36
36: ; preds = %64, %33
%37 = load i32, i32* %6
%38 = icmp sge i32 %37, 0
br i1 %38, label %39, label %71
39: ; preds = %36
%40 = load i32*, i32** %4
%41 = call i8* @status_read_file_line(i32* %40)
store i8* %41, i8** %7
%42 = load i8*, i8** %7
%43 = icmp eq i8* %42, null
br i1 %43, label %44, label %53
44: ; preds = %39
%45 = load i32, i32* @stderr
%46 = sext i32 %45 to i64
%47 = inttoptr i64 %46 to i32*
%48 = call i32 (i32*, i8*, ...) @fprintf(i32* %47, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
%49 = load i32*, i32** %4
%50 = call i32 @fclose(i32* %49)
%51 = load i8*, i8** %10
%52 = call i32 @free(i8* %51)
store i32 -1, i32* %2
br label %87
53: ; preds = %39
%54 = load i8*, i8** %7
%55 = load i8*, i8** %3
%56 = call i64 @strcmp(i8* %54, i8* %55)
%57 = icmp ne i64 %56, 0
br i1 %57, label %58, label %62
58: ; preds = %53
%59 = load i32*, i32** %5
%60 = load i8*, i8** %7
%61 = call i32 (i32*, i8*, ...) @fprintf(i32* %59, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %60)
br label %64
62: ; preds = %53
%63 = load i32, i32* %9
store i32 %63, i32* %8
br label %64
64: ; preds = %62, %58
%65 = load i32, i32* %9
%66 = add nsw i32 %65, 1
store i32 %66, i32* %9
%67 = load i32, i32* %6
%68 = add nsw i32 %67, -1
store i32 %68, i32* %6
%69 = load i8*, i8** %7
%70 = call i32 @free(i8* %69)
br label %36
71: ; preds = %36
%72 = load i32*, i32** %4
%73 = call i32 @fclose(i32* %72)
%74 = load i32*, i32** %5
%75 = call i32 @fclose(i32* %74)
%76 = call i8* (...) @status_get_file_path()
store i8* %76, i8** %11
%77 = load i8*, i8** %11
%78 = call i32 @remove(i8* %77)
%79 = load i8*, i8** %10
%80 = load i8*, i8** %11
%81 = call i32 @rename(i8* %79, i8* %80)
%82 = load i8*, i8** %11
%83 = call i32 @free(i8* %82)
%84 = load i8*, i8** %10
%85 = call i32 @free(i8* %84)
%86 = load i32, i32* %8
store i32 %86, i32* %2
br label %87
87: ; preds = %71, %44, %30, %21, %15
%88 = load i32, i32* %2
ret i32 %88
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [3 x i8] c"w+\00"
@stderr = global i32 0
@.str.2 = [21 x i8] c"Error reading line.\0A\00"
@.str.3 = [4 x i8] c"%s\0A\00"
define i32 @status_del_tracking(i8* %0) {
%2 = tail call i32* @status_get_file_ptr(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%3 = icmp eq i32* %2, null
br i1 %3, label %49, label %4
4: ; preds = %1
%5 = tail call i32 @status_count_file_lines(i32* %2)
%6 = icmp eq i32 %5, -2
br i1 %6, label %7, label %9
7: ; preds = %4
%8 = tail call i32 @fclose(i32* %2)
br label %49
9: ; preds = %4
%10 = tail call i32 @rewind(i32* %2)
%11 = tail call i8* (...) @get_status_file_tmp_path()
%12 = icmp eq i8* %11, null
br i1 %12, label %13, label %15
13: ; preds = %9
%14 = tail call i32 @fclose(i32* %2)
br label %49
15: ; preds = %9
%16 = tail call i32* @fopen(i8* %11, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%17 = icmp sgt i32 %5, -1
br i1 %17, label %18, label %40
18: ; preds = %15, %35
%19 = phi i32 [ %37, %35 ], [ 0, %15 ]
%20 = phi i32 [ %36, %35 ], [ 0, %15 ]
%21 = tail call i8* @status_read_file_line(i32* %2)
%22 = icmp eq i8* %21, null
br i1 %22, label %23, label %30
23: ; preds = %18
%24 = load i32, i32* @stderr
%25 = sext i32 %24 to i64
%26 = inttoptr i64 %25 to i32*
%27 = tail call i64 @fwrite(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i64 20, i64 1, i32* %26)
%28 = tail call i32 @fclose(i32* %2)
%29 = tail call i32 @free(i8* %11)
br label %49
30: ; preds = %18
%31 = tail call i64 @strcmp(i8* %21, i8* %0)
%32 = icmp eq i64 %31, 0
br i1 %32, label %35, label %33
33: ; preds = %30
%34 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %16, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %21)
br label %35
35: ; preds = %30, %33
%36 = phi i32 [ %20, %33 ], [ %19, %30 ]
%37 = add nuw i32 %19, 1
%38 = tail call i32 @free(i8* %21)
%39 = icmp eq i32 %19, %5
br i1 %39, label %40, label %18
40: ; preds = %35, %15
%41 = phi i32 [ 0, %15 ], [ %36, %35 ]
%42 = tail call i32 @fclose(i32* %2)
%43 = tail call i32 @fclose(i32* %16)
%44 = tail call i8* (...) @status_get_file_path()
%45 = tail call i32 @remove(i8* %44)
%46 = tail call i32 @rename(i8* %11, i8* %44)
%47 = tail call i32 @free(i8* %44)
%48 = tail call i32 @free(i8* %11)
br label %49
49: ; preds = %1, %40, %23, %13, %7
%50 = phi i32 [ -1, %7 ], [ -1, %13 ], [ -1, %23 ], [ %41, %40 ], [ -1, %1 ]
ret i32 %50
}