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

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, char *);
int /*<<< orphan*/ printf(char *, char *);
scalar_t__ strstr(char *, char const *);
void removeFromFile(const char *text) {
  FILE *fp = fopen("todo", "r");
  FILE *wp = fopen("todo_temp", "w");
  char buffer[100];
  while (fgets(buffer, sizeof(buffer) / sizeof(char), fp) != NULL) {
    if (strstr(buffer, text))
      printf("%s removed from file\n", buffer);
    else
      fprintf(wp, "%s", buffer);
  }
  fclose(fp);
  fclose(wp);
}


x86 assembly (clang, -O0):
<removeFromFile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x8(%rbp)
lea    0xe8a(%rip),%rdi
lea    0xe88(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x10(%rbp)
lea    0xe7a(%rip),%rdi
lea    0xe7d(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
lea    -0x80(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x64,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     11fe <removeFromFile+0x9e>
lea    -0x80(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1080 <strstr@plt>
cmp    $0x0,%rax
je     11e5 <removeFromFile+0x85>
lea    -0x80(%rbp),%rsi
lea    0xe38(%rip),%rdi
call   1040 <printf@plt>
jmp    11f9 <removeFromFile+0x99>
mov    -0x18(%rbp),%rdi
lea    -0x80(%rbp),%rdx
lea    0xe35(%rip),%rsi
call   1060 <fprintf@plt>
jmp    119d <removeFromFile+0x3d>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<removeFromFile>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x70,%rsp
mov    %rdi,%r14
lea    0xe89(%rip),%rdi
lea    0xe87(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%r12
lea    0xe7a(%rip),%rdi
lea    0xe7d(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%r15
mov    %rsp,%rdi
mov    $0x64,%esi
mov    %r12,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     11fd <removeFromFile+0x9d>
mov    %rsp,%rbx
lea    0xe58(%rip),%r13
jmp    11e0 <removeFromFile+0x80>
nopl   (%rax)
mov    %rbx,%rdi
mov    %r15,%rsi
call   1050 <fputs@plt>
mov    %rbx,%rdi
mov    $0x64,%esi
mov    %r12,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     11fd <removeFromFile+0x9d>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1080 <strstr@plt>
test   %rax,%rax
je     11c0 <removeFromFile+0x60>
mov    %r13,%rdi
mov    %rbx,%rsi
call   1040 <printf@plt>
jmp    11cb <removeFromFile+0x6b>
mov    %r12,%rdi
call   1030 <fclose@plt>
mov    %r15,%rdi
call   1030 <fclose@plt>
add    $0x70,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [5 x i8] c"todo\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [10 x i8] c"todo_temp\00"
@.str.3 = [2 x i8] c"w\00"
@.str.4 = [22 x i8] c"%s removed from file\0A\00"
@.str.5 = [3 x i8] c"%s\00"
define void @removeFromFile(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca i32*
%5 = alloca [100 x i8]
store i8* %0, i8** %2
%6 = call i32* @fopen(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %6, i32** %3
%7 = call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %7, i32** %4
br label %8
8: ; preds = %25, %1
%9 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%10 = load i32*, i32** %3
%11 = call i32* @fgets(i8* %9, i32 100, i32* %10)
%12 = icmp ne i32* %11, null
br i1 %12, label %13, label %26
13: ; preds = %8
%14 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%15 = load i8*, i8** %2
%16 = call i64 @strstr(i8* %14, i8* %15)
%17 = icmp ne i64 %16, 0
br i1 %17, label %18, label %21
18: ; preds = %13
%19 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%20 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0), i8* %19)
br label %25
21: ; preds = %13
%22 = load i32*, i32** %4
%23 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%24 = call i32 @fprintf(i32* %22, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i8* %23)
br label %25
25: ; preds = %21, %18
br label %8
26: ; preds = %8
%27 = load i32*, i32** %3
%28 = call i32 @fclose(i32* %27)
%29 = load i32*, i32** %4
%30 = call i32 @fclose(i32* %29)
ret void
}

LLVM IR (-O2):
@.str = [5 x i8] c"todo\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [10 x i8] c"todo_temp\00"
@.str.3 = [2 x i8] c"w\00"
@.str.4 = [22 x i8] c"%s removed from file\0A\00"
define void @removeFromFile(i8* %0) {
%2 = alloca [100 x i8]
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%4 = tail call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%5 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%6 = call i32* @fgets(i8* %5, i32 100, i32* %3)
%7 = icmp eq i32* %6, null
br i1 %7, label %18, label %8
8: ; preds = %1, %15
%9 = call i64 @strstr(i8* %5, i8* %0)
%10 = icmp eq i64 %9, 0
br i1 %10, label %13, label %11
11: ; preds = %8
%12 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0), i8* %5)
br label %15
13: ; preds = %8
%14 = call i32 @fputs(i8* %5, i32* %4)
br label %15
15: ; preds = %13, %11
%16 = call i32* @fgets(i8* %5, i32 100, i32* %3)
%17 = icmp eq i32* %16, null
br i1 %17, label %18, label %8
18: ; preds = %15, %1
%19 = call i32 @fclose(i32* %3)
%20 = call i32 @fclose(i32* %4)
ret void
}