#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 */

/* Variables and functions */
char *realloc(char *, int);
scalar_t__ strchr(char const *, char);
int strlen(char *);
char *bf_minimize_file(char *file_string) {
  const char *valid_chars = "<>.,+-[]";
  int i;
  int insert_pos = 0;
  int code_length = strlen(file_string);
  for (i = 0; i < code_length; i++) {
    char current_char = file_string[i];
    if (strchr(valid_chars, current_char)) {
      file_string[insert_pos] = current_char;
      insert_pos++;
    }
  }
  file_string[insert_pos] = '\0';
  file_string = realloc(file_string, insert_pos + 1);
  return file_string;
}


x86 assembly (clang, -O0):
<bf_minimize_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
lea    0xebd(%rip),%rax
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x1c(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    11bc <bf_minimize_file+0x8c>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x1d(%rbp)
mov    -0x10(%rbp),%rdi
movsbl -0x1d(%rbp),%esi
call   1040 <strchr@plt>
cmp    $0x0,%rax
je     11a9 <bf_minimize_file+0x79>
mov    -0x1d(%rbp),%dl
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11ae <bf_minimize_file+0x7e>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1161 <bf_minimize_file+0x31>
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%esi
add    $0x1,%esi
call   1050 <realloc@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bf_minimize_file>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r12
call   1030 <strlen@plt>
test   %eax,%eax
jle    118c <bf_minimize_file+0x5c>
mov    %eax,%r15d
xor    %ebx,%ebx
lea    0xead(%rip),%r14
xor    %r13d,%r13d
jmp    1169 <bf_minimize_file+0x39>
nopl   0x0(%rax,%rax,1)
add    $0x1,%rbx
cmp    %rbx,%r15
je     118f <bf_minimize_file+0x5f>
movzbl (%r12,%rbx,1),%ebp
movsbl %bpl,%esi
mov    %r14,%rdi
call   1040 <strchr@plt>
test   %rax,%rax
je     1160 <bf_minimize_file+0x30>
movslq %r13d,%r13
mov    %bpl,(%r12,%r13,1)
add    $0x1,%r13d
jmp    1160 <bf_minimize_file+0x30>
xor    %r13d,%r13d
movslq %r13d,%rsi
movb   $0x0,(%r12,%rsi,1)
add    $0x1,%esi
mov    %r12,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <realloc@plt>

LLVM IR (-O0):
@.str = [9 x i8] c"<>.,+-[]\00"
define i8* @bf_minimize_file(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8
store i8* %0, i8** %2
store i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8** %3
store i32 0, i32* %5
%8 = load i8*, i8** %2
%9 = call i32 @strlen(i8* %8)
store i32 %9, i32* %6
store i32 0, i32* %4
br label %10
10: ; preds = %33, %1
%11 = load i32, i32* %4
%12 = load i32, i32* %6
%13 = icmp slt i32 %11, %12
br i1 %13, label %14, label %36
14: ; preds = %10
%15 = load i8*, i8** %2
%16 = load i32, i32* %4
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i8, i8* %15, i64 %17
%19 = load i8, i8* %18
store i8 %19, i8* %7
%20 = load i8*, i8** %3
%21 = load i8, i8* %7
%22 = call i64 @strchr(i8* %20, i8 signext %21)
%23 = icmp ne i64 %22, 0
br i1 %23, label %24, label %32
24: ; preds = %14
%25 = load i8, i8* %7
%26 = load i8*, i8** %2
%27 = load i32, i32* %5
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i8, i8* %26, i64 %28
store i8 %25, i8* %29
%30 = load i32, i32* %5
%31 = add nsw i32 %30, 1
store i32 %31, i32* %5
br label %32
32: ; preds = %24, %14
br label %33
33: ; preds = %32
%34 = load i32, i32* %4
%35 = add nsw i32 %34, 1
store i32 %35, i32* %4
br label %10
36: ; preds = %10
%37 = load i8*, i8** %2
%38 = load i32, i32* %5
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i8, i8* %37, i64 %39
store i8 0, i8* %40
%41 = load i8*, i8** %2
%42 = load i32, i32* %5
%43 = add nsw i32 %42, 1
%44 = call i8* @realloc(i8* %41, i32 %43)
store i8* %44, i8** %2
%45 = load i8*, i8** %2
ret i8* %45
}

LLVM IR (-O2):
@.str = [9 x i8] c"<>.,+-[]\00"
define i8* @bf_minimize_file(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = icmp sgt i32 %2, 0
br i1 %3, label %4, label %21
4: ; preds = %1
%5 = zext i32 %2 to i64
br label %6
6: ; preds = %4, %17
%7 = phi i64 [ 0, %4 ], [ %19, %17 ]
%8 = phi i32 [ 0, %4 ], [ %18, %17 ]
%9 = getelementptr inbounds i8, i8* %0, i64 %7
%10 = load i8, i8* %9
%11 = tail call i64 @strchr(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8 signext %10)
%12 = icmp eq i64 %11, 0
br i1 %12, label %17, label %13
13: ; preds = %6
%14 = sext i32 %8 to i64
%15 = getelementptr inbounds i8, i8* %0, i64 %14
store i8 %10, i8* %15
%16 = add nsw i32 %8, 1
br label %17
17: ; preds = %13, %6
%18 = phi i32 [ %16, %13 ], [ %8, %6 ]
%19 = add nuw nsw i64 %7, 1
%20 = icmp eq i64 %19, %5
br i1 %20, label %21, label %6
21: ; preds = %17, %1
%22 = phi i32 [ 0, %1 ], [ %18, %17 ]
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8, i8* %0, i64 %23
store i8 0, i8* %24
%25 = add nsw i32 %22, 1
%26 = tail call i8* @realloc(i8* %0, i32 %25)
ret i8* %26
}