#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_END;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, char *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, long, int /*<<< orphan*/);
int ftell(int /*<<< orphan*/ *);
char *malloc(int);
int /*<<< orphan*/ *open_list(char *);
int /*<<< orphan*/ print_line_colored(char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ sprintf(char *, char *, char *, ...);
int /*<<< orphan*/ strstr(char *, char *);
void remove_todo(char *id) {
  FILE *fp;
  char *list_buffer;
  fp = open_list("r");
  fseek(fp, 0L, SEEK_END);
  list_buffer = malloc(ftell(fp) * sizeof(char));
  fseek(fp, 0L, SEEK_SET);
  char line[4096];
  while (fgets(line, sizeof(line), fp)) {
    if (!strstr(line, id)) {
      if (list_buffer[0] == '\0') {
        sprintf(list_buffer, "%s", line);
      } else {
        sprintf(list_buffer, "%s%s", list_buffer, line);
      }
    } else {
      printf("Removed task ");
      print_line_colored(line);
    }
  }
  fclose(fp);
  fp = open_list("w");
  fprintf(fp, "%s", list_buffer);
  fclose(fp);
  free(list_buffer);
}


x86 assembly (clang, -O0):
<remove_todo>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1020,%rsp
mov    %rdi,-0x8(%rbp)
lea    0xe2a(%rip),%rdi
call   10c0 <open_list@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2dfe(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%esi
call   10b0 <fseek@plt>
mov    -0x10(%rbp),%rdi
call   1080 <ftell@plt>
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1090 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2dbe(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%esi
call   10b0 <fseek@plt>
lea    -0x1020(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x1000,%esi
call   1060 <fgets@plt>
cmp    $0x0,%rax
je     12ca <remove_todo+0x10a>
lea    -0x1020(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   10e0 <strstr@plt>
cmp    $0x0,%eax
jne    12ad <remove_todo+0xed>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    128b <remove_todo+0xcb>
mov    -0x18(%rbp),%rdi
lea    -0x1020(%rbp),%rdx
lea    0xd85(%rip),%rsi
mov    $0x0,%al
call   10d0 <sprintf@plt>
jmp    12a8 <remove_todo+0xe8>
mov    -0x18(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    -0x1020(%rbp),%rcx
lea    0xd61(%rip),%rsi
mov    $0x0,%al
call   10d0 <sprintf@plt>
jmp    12c5 <remove_todo+0x105>
lea    0xd53(%rip),%rdi
call   1050 <printf@plt>
lea    -0x1020(%rbp),%rdi
call   10a0 <print_line_colored@plt>
jmp    1225 <remove_todo+0x65>
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
lea    0xd3b(%rip),%rdi
call   10c0 <open_list@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xd12(%rip),%rsi
call   1070 <fprintf@plt>
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
add    $0x1020,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<remove_todo>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1008,%rsp
mov    %rdi,%r14
lea    0xe15(%rip),%rdi
call   10d0 <open_list@plt>
mov    %rax,%r12
mov    0x2dee(%rip),%rax
mov    (%rax),%edx
mov    %r12,%rdi
xor    %esi,%esi
call   10c0 <fseek@plt>
mov    %r12,%rdi
call   1090 <ftell@plt>
mov    %eax,%edi
call   10a0 <malloc@plt>
mov    %rax,%r15
mov    0x2db9(%rip),%rax
mov    (%rax),%edx
mov    %r12,%rdi
xor    %esi,%esi
call   10c0 <fseek@plt>
mov    %rsp,%rdi
mov    $0x1000,%esi
mov    %r12,%rdx
call   1080 <fgets@plt>
test   %rax,%rax
je     12bc <remove_todo+0xec>
mov    %rsp,%rbx
lea    0xdb8(%rip),%r13
lea    0xdb6(%rip),%rbp
jmp    1285 <remove_todo+0xb5>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rbp,%rdi
call   1060 <printf@plt>
mov    %rbx,%rdi
call   10b0 <print_line_colored@plt>
mov    %rbx,%rdi
mov    $0x1000,%esi
mov    %r12,%rdx
call   1080 <fgets@plt>
test   %rax,%rax
je     12bc <remove_todo+0xec>
mov    %rbx,%rdi
mov    %r14,%rsi
call   10f0 <strstr@plt>
test   %eax,%eax
jne    1260 <remove_todo+0x90>
cmpb   $0x0,(%r15)
je     12af <remove_todo+0xdf>
mov    %r15,%rdi
mov    %r13,%rsi
mov    %r15,%rdx
mov    %rbx,%rcx
xor    %eax,%eax
call   10e0 <sprintf@plt>
jmp    1270 <remove_todo+0xa0>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1040 <strcpy@plt>
jmp    1270 <remove_todo+0xa0>
mov    %r12,%rdi
call   1050 <fclose@plt>
lea    0xd4a(%rip),%rdi
call   10d0 <open_list@plt>
mov    %rax,%rbx
mov    %r15,%rdi
mov    %rax,%rsi
call   1070 <fputs@plt>
mov    %rbx,%rdi
call   1050 <fclose@plt>
mov    %r15,%rdi
call   1030 <free@plt>
add    $0x1008,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [5 x i8] c"%s%s\00"
@.str.3 = [14 x i8] c"Removed task \00"
@.str.4 = [2 x i8] c"w\00"
define void @remove_todo(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca i8*
%5 = alloca [4096 x i8]
store i8* %0, i8** %2
%6 = call i32* @open_list(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %6, i32** %3
%7 = load i32*, i32** %3
%8 = load i32, i32* @SEEK_END
%9 = call i32 @fseek(i32* %7, i64 0, i32 %8)
%10 = load i32*, i32** %3
%11 = call i32 @ftell(i32* %10)
%12 = sext i32 %11 to i64
%13 = mul i64 %12, 1
%14 = trunc i64 %13 to i32
%15 = call i8* @malloc(i32 %14)
store i8* %15, i8** %4
%16 = load i32*, i32** %3
%17 = load i32, i32* @SEEK_SET
%18 = call i32 @fseek(i32* %16, i64 0, i32 %17)
br label %19
19: ; preds = %49, %1
%20 = getelementptr inbounds [4096 x i8], [4096 x i8]* %5, i64 0, i64 0
%21 = load i32*, i32** %3
%22 = call i64 @fgets(i8* %20, i32 4096, i32* %21)
%23 = icmp ne i64 %22, 0
br i1 %23, label %24, label %50
24: ; preds = %19
%25 = getelementptr inbounds [4096 x i8], [4096 x i8]* %5, i64 0, i64 0
%26 = load i8*, i8** %2
%27 = call i32 @strstr(i8* %25, i8* %26)
%28 = icmp ne i32 %27, 0
br i1 %28, label %45, label %29
29: ; preds = %24
%30 = load i8*, i8** %4
%31 = getelementptr inbounds i8, i8* %30, i64 0
%32 = load i8, i8* %31
%33 = sext i8 %32 to i32
%34 = icmp eq i32 %33, 0
br i1 %34, label %35, label %39
35: ; preds = %29
%36 = load i8*, i8** %4
%37 = getelementptr inbounds [4096 x i8], [4096 x i8]* %5, i64 0, i64 0
%38 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %36, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %37)
br label %44
39: ; preds = %29
%40 = load i8*, i8** %4
%41 = load i8*, i8** %4
%42 = getelementptr inbounds [4096 x i8], [4096 x i8]* %5, i64 0, i64 0
%43 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %40, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* %41, i8* %42)
br label %44
44: ; preds = %39, %35
br label %49
45: ; preds = %24
%46 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0))
%47 = getelementptr inbounds [4096 x i8], [4096 x i8]* %5, i64 0, i64 0
%48 = call i32 @print_line_colored(i8* %47)
br label %49
49: ; preds = %45, %44
br label %19
50: ; preds = %19
%51 = load i32*, i32** %3
%52 = call i32 @fclose(i32* %51)
%53 = call i32* @open_list(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i32* %53, i32** %3
%54 = load i32*, i32** %3
%55 = load i8*, i8** %4
%56 = call i32 @fprintf(i32* %54, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %55)
%57 = load i32*, i32** %3
%58 = call i32 @fclose(i32* %57)
%59 = load i8*, i8** %4
%60 = call i32 @free(i8* %59)
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
@.str.2 = [5 x i8] c"%s%s\00"
@.str.3 = [14 x i8] c"Removed task \00"
@.str.4 = [2 x i8] c"w\00"
define void @remove_todo(i8* %0) {
%2 = alloca [4096 x i8]
%3 = tail call i32* @open_list(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%4 = load i32, i32* @SEEK_END
%5 = tail call i32 @fseek(i32* %3, i64 0, i32 %4)
%6 = tail call i32 @ftell(i32* %3)
%7 = tail call i8* @malloc(i32 %6)
%8 = load i32, i32* @SEEK_SET
%9 = tail call i32 @fseek(i32* %3, i64 0, i32 %8)
%10 = getelementptr inbounds [4096 x i8], [4096 x i8]* %2, i64 0, i64 0
%11 = call i64 @fgets(i8* %10, i32 4096, i32* %3)
%12 = icmp eq i64 %11, 0
br i1 %12, label %29, label %13
13: ; preds = %1, %26
%14 = call i32 @strstr(i8* %10, i8* %0)
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %23
16: ; preds = %13
%17 = load i8, i8* %7
%18 = icmp eq i8 %17, 0
br i1 %18, label %19, label %21
19: ; preds = %16
%20 = call i8* @strcpy(i8* %7, i8* %10)
br label %26
21: ; preds = %16
%22 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %7, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* %7, i8* %10)
br label %26
23: ; preds = %13
%24 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0))
%25 = call i32 @print_line_colored(i8* %10)
br label %26
26: ; preds = %19, %21, %23
%27 = call i64 @fgets(i8* %10, i32 4096, i32* %3)
%28 = icmp eq i64 %27, 0
br i1 %28, label %29, label %13
29: ; preds = %26, %1
%30 = call i32 @fclose(i32* %3)
%31 = call i32* @open_list(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%32 = call i32 @fputs(i8* %7, i32* %31)
%33 = call i32 @fclose(i32* %31)
%34 = call i32 @free(i8* %7)
ret void
}