#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*/ fclose(int /*<<< orphan*/ *);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, char const *);
int /*<<< orphan*/ fs_mv(char *, char *);
int /*<<< orphan*/ *stderr;
scalar_t__ strcmp(char *, char const *);
int /*<<< orphan*/ strtok(char *, char *);
int beargit_rm(const char *filename) {
  FILE *findex = fopen(".beargit/.index", "r");
  FILE *fnewindex = fopen(".beargit/.newindex", "w");
  char line[512];
  int checker;
  checker = 0;
  while (fgets(line, sizeof(line), findex)) {
    strtok(line, "\n");
    if (strcmp(line, filename) != 0) {
      fprintf(fnewindex, "%s\n", line);
    } else {
      checker = 5;
    }
  }
  if (checker == 5) {
    fclose(findex);
    fclose(fnewindex);
    fs_mv(".beargit/.newindex", ".beargit/.index");
    return 0;
  } else {
    fprintf(stderr, "ERROR: File %s not tracked\n", filename);
    fclose(findex);
    fclose(fnewindex);
    return 1;
  }
}


x86 assembly (clang, -O0):
<beargit_rm>:
push   %rbp
mov    %rsp,%rbp
sub    $0x230,%rsp
mov    %rdi,-0x10(%rbp)
lea    0xe7a(%rip),%rdi
lea    0xe83(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x18(%rbp)
lea    0xe75(%rip),%rdi
lea    0xe81(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x224(%rbp)
lea    -0x220(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x200,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     122e <beargit_rm+0xbe>
lea    -0x220(%rbp),%rdi
lea    0xe61(%rip),%rsi
call   1090 <strtok@plt>
lea    -0x220(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
je     121f <beargit_rm+0xaf>
mov    -0x20(%rbp),%rdi
lea    -0x220(%rbp),%rdx
lea    0xe12(%rip),%rsi
call   1070 <fprintf@plt>
jmp    1229 <beargit_rm+0xb9>
movl   $0x5,-0x224(%rbp)
jmp    11b7 <beargit_rm+0x47>
cmpl   $0x5,-0x224(%rbp)
jne    126c <beargit_rm+0xfc>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
lea    0xdbe(%rip),%rdi
lea    0xda5(%rip),%rsi
call   1030 <fs_mv@plt>
movl   $0x0,-0x4(%rbp)
jmp    129f <beargit_rm+0x12f>
mov    0x2d6d(%rip),%rax
mov    (%rax),%rdi
mov    -0x10(%rbp),%rdx
lea    0xdaa(%rip),%rsi
call   1070 <fprintf@plt>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x230,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<beargit_rm>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x208,%rsp
mov    %rdi,%r14
lea    0xe75(%rip),%rdi
lea    0xe7e(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,%r13
lea    0xe71(%rip),%rdi
lea    0xe7d(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,%r15
mov    %rsp,%rdi
mov    $0x200,%esi
mov    %r13,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     1255 <beargit_rm+0xe5>
xor    %ebp,%ebp
lea    0xe73(%rip),%r12
mov    %rsp,%rbx
jmp    1207 <beargit_rm+0x97>
nopw   0x0(%rax,%rax,1)
mov    %r15,%rdi
lea    0xe3d(%rip),%rsi
mov    %rbx,%rdx
call   1070 <fprintf@plt>
mov    %rbx,%rdi
mov    $0x200,%esi
mov    %r13,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     1229 <beargit_rm+0xb9>
mov    %rbx,%rdi
mov    %r12,%rsi
call   1090 <strtok@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
jne    11e0 <beargit_rm+0x70>
mov    $0x5,%ebp
jmp    11f2 <beargit_rm+0x82>
cmp    $0x5,%ebp
jne    1255 <beargit_rm+0xe5>
mov    %r13,%rdi
call   1040 <fclose@plt>
mov    %r15,%rdi
call   1040 <fclose@plt>
lea    0xdcd(%rip),%rdi
lea    0xdb4(%rip),%rsi
call   1030 <fs_mv@plt>
xor    %eax,%eax
jmp    1283 <beargit_rm+0x113>
mov    0x2d84(%rip),%rax
mov    (%rax),%rdi
lea    0xdc5(%rip),%rsi
mov    %r14,%rdx
call   1070 <fprintf@plt>
mov    %r13,%rdi
call   1040 <fclose@plt>
mov    %r15,%rdi
call   1040 <fclose@plt>
mov    $0x1,%eax
add    $0x208,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [16 x i8] c".beargit/.index\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [19 x i8] c".beargit/.newindex\00"
@.str.3 = [2 x i8] c"w\00"
@.str.4 = [2 x i8] c"\0A\00"
@.str.5 = [4 x i8] c"%s\0A\00"
@stderr = global i32* null
@.str.6 = [28 x i8] c"ERROR: File %s not tracked\0A\00"
define i32 @beargit_rm(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca [512 x i8]
%7 = alloca i32
store i8* %0, i8** %3
%8 = call i32* @fopen(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %8, i32** %4
%9 = call i32* @fopen(i8* getelementptr inbounds ([19 x i8], [19 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* %9, i32** %5
store i32 0, i32* %7
br label %10
10: ; preds = %27, %1
%11 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%12 = load i32*, i32** %4
%13 = call i64 @fgets(i8* %11, i32 512, i32* %12)
%14 = icmp ne i64 %13, 0
br i1 %14, label %15, label %28
15: ; preds = %10
%16 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%17 = call i32 @strtok(i8* %16, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%18 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%19 = load i8*, i8** %3
%20 = call i64 @strcmp(i8* %18, i8* %19)
%21 = icmp ne i64 %20, 0
br i1 %21, label %22, label %26
22: ; preds = %15
%23 = load i32*, i32** %5
%24 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%25 = call i32 @fprintf(i32* %23, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i8* %24)
br label %27
26: ; preds = %15
store i32 5, i32* %7
br label %27
27: ; preds = %26, %22
br label %10
28: ; preds = %10
%29 = load i32, i32* %7
%30 = icmp eq i32 %29, 5
br i1 %30, label %31, label %37
31: ; preds = %28
%32 = load i32*, i32** %4
%33 = call i32 @fclose(i32* %32)
%34 = load i32*, i32** %5
%35 = call i32 @fclose(i32* %34)
%36 = call i32 @fs_mv(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %2
br label %45
37: ; preds = %28
%38 = load i32*, i32** @stderr
%39 = load i8*, i8** %3
%40 = call i32 @fprintf(i32* %38, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.6, i64 0, i64 0), i8* %39)
%41 = load i32*, i32** %4
%42 = call i32 @fclose(i32* %41)
%43 = load i32*, i32** %5
%44 = call i32 @fclose(i32* %43)
store i32 1, i32* %2
br label %45
45: ; preds = %37, %31
%46 = load i32, i32* %2
ret i32 %46
}

LLVM IR (-O2):
@.str = [16 x i8] c".beargit/.index\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [19 x i8] c".beargit/.newindex\00"
@.str.3 = [2 x i8] c"w\00"
@.str.4 = [2 x i8] c"\0A\00"
@.str.5 = [4 x i8] c"%s\0A\00"
@stderr = global i32* null
@.str.6 = [28 x i8] c"ERROR: File %s not tracked\0A\00"
define i32 @beargit_rm(i8* %0) {
%2 = alloca [512 x i8]
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([16 x i8], [16 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 ([19 x i8], [19 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 [512 x i8], [512 x i8]* %2, i64 0, i64 0
%6 = call i64 @fgets(i8* %5, i32 512, i32* %3)
%7 = icmp eq i64 %6, 0
br i1 %7, label %25, label %8
8: ; preds = %1, %15
%9 = phi i32 [ %16, %15 ], [ 0, %1 ]
%10 = call i32 @strtok(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%11 = call i64 @strcmp(i8* %5, i8* %0)
%12 = icmp eq i64 %11, 0
br i1 %12, label %15, label %13
13: ; preds = %8
%14 = call i32 @fprintf(i32* %4, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i8* %5)
br label %15
15: ; preds = %8, %13
%16 = phi i32 [ %9, %13 ], [ 5, %8 ]
%17 = call i64 @fgets(i8* %5, i32 512, i32* %3)
%18 = icmp eq i64 %17, 0
br i1 %18, label %19, label %8
19: ; preds = %15
%20 = icmp eq i32 %16, 5
br i1 %20, label %21, label %25
21: ; preds = %19
%22 = call i32 @fclose(i32* %3)
%23 = call i32 @fclose(i32* %4)
%24 = call i32 @fs_mv(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
br label %30
25: ; preds = %1, %19
%26 = load i32*, i32** @stderr
%27 = call i32 @fprintf(i32* %26, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.6, i64 0, i64 0), i8* %0)
%28 = call i32 @fclose(i32* %3)
%29 = call i32 @fclose(i32* %4)
br label %30
30: ; preds = %25, %21
%31 = phi i32 [ 0, %21 ], [ 1, %25 ]
ret i32 %31
}