#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 */
char *calloc(long, int);
char getc(int /*<<< orphan*/ *);
char *realloc(char *, long long);
char *strip_source(FILE *source, long length) {
  char *buf = calloc(length, sizeof(char));
  char *buf_iter = buf;
  char c;
  if (length <= 0) {
    return NULL;
  }
  for (int i = 0; i < length; i++) {
    c = getc(source);
    switch (c) {
    case '>':
    case '<':
    case '+':
    case '-':
    case '.':
    case ',':
    case '[':
    case ']':
      *buf_iter++ = c;
    }
  }
  long long result_length = buf_iter - buf + 1;
  buf = realloc(buf, result_length + 1);
  buf[result_length] = '\0';
  return buf;
}


x86 assembly (clang, -O0):
<strip_source>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    $0x1,%esi
call   1030 <calloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x18(%rbp)
jg     1172 <strip_source+0x42>
movq   $0x0,-0x8(%rbp)
jmp    1252 <strip_source+0x122>
movl   $0x0,-0x30(%rbp)
movslq -0x30(%rbp),%rax
cmp    -0x18(%rbp),%rax
jge    1216 <strip_source+0xe6>
mov    -0x10(%rbp),%rdi
call   1050 <getc@plt>
mov    %al,-0x29(%rbp)
movsbl -0x29(%rbp),%eax
mov    %eax,-0x3c(%rbp)
add    $0xffffffd5,%eax
sub    $0x4,%eax
jb     11ef <strip_source+0xbf>
jmp    11ab <strip_source+0x7b>
mov    -0x3c(%rbp),%eax
sub    $0x3c,%eax
je     11ef <strip_source+0xbf>
jmp    11bc <strip_source+0x8c>
mov    -0x3c(%rbp),%eax
sub    $0x3e,%eax
je     11ef <strip_source+0xbf>
jmp    11cd <strip_source+0x9d>
mov    -0x3c(%rbp),%eax
sub    $0x5b,%eax
je     11ef <strip_source+0xbf>
jmp    11de <strip_source+0xae>
mov    -0x3c(%rbp),%eax
sub    $0x5d,%eax
jne    1203 <strip_source+0xd3>
jmp    11ef <strip_source+0xbf>
mov    -0x29(%rbp),%cl
mov    -0x28(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x28(%rbp)
mov    %cl,(%rax)
jmp    1208 <strip_source+0xd8>
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    1179 <strip_source+0x49>
mov    -0x28(%rbp),%rax
mov    -0x20(%rbp),%rcx
sub    %rcx,%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x38(%rbp),%rsi
add    $0x1,%rsi
call   1040 <realloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    -0x38(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strip_source>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rsi,%rbx
mov    %rdi,%r14
mov    %rsi,%rdi
mov    $0x1,%esi
call   1030 <calloc@plt>
test   %rbx,%rbx
jle    11b1 <strip_source+0x81>
mov    %rax,%r15
movabs $0x50000000a000f,%r13
mov    %rax,%r12
jmp    1176 <strip_source+0x46>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
add    $0xffffffffffffffff,%rbx
je     1199 <strip_source+0x69>
mov    %r14,%rdi
call   1050 <getc@plt>
movsbl %al,%ecx
add    $0xffffffd5,%ecx
cmp    $0x32,%ecx
ja     1170 <strip_source+0x40>
bt     %rcx,%r13
jae    1170 <strip_source+0x40>
mov    %al,(%r12)
add    $0x1,%r12
jmp    1170 <strip_source+0x40>
sub    %r15,%r12
lea    0x2(%r12),%rsi
mov    %r15,%rdi
call   1040 <realloc@plt>
movb   $0x0,0x1(%r12,%rax,1)
jmp    11b3 <strip_source+0x83>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8* @strip_source(i32* %0, i64 %1) {
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca i64
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8
%9 = alloca i32
%10 = alloca i64
store i32* %0, i32** %4
store i64 %1, i64* %5
%11 = load i64, i64* %5
%12 = call i8* @calloc(i64 %11, i32 1)
store i8* %12, i8** %6
%13 = load i8*, i8** %6
store i8* %13, i8** %7
%14 = load i64, i64* %5
%15 = icmp sle i64 %14, 0
br i1 %15, label %16, label %17
16: ; preds = %2
store i8* null, i8** %3
br label %51
17: ; preds = %2
store i32 0, i32* %9
br label %18
18: ; preds = %33, %17
%19 = load i32, i32* %9
%20 = sext i32 %19 to i64
%21 = load i64, i64* %5
%22 = icmp slt i64 %20, %21
br i1 %22, label %23, label %36
23: ; preds = %18
%24 = load i32*, i32** %4
%25 = call signext i8 @getc(i32* %24)
store i8 %25, i8* %8
%26 = load i8, i8* %8
%27 = sext i8 %26 to i32
switch i32 %27, label %32 [
i32 62, label %28
i32 60, label %28
i32 43, label %28
i32 45, label %28
i32 46, label %28
i32 44, label %28
i32 91, label %28
i32 93, label %28
]
28: ; preds = %23, %23, %23, %23, %23, %23, %23, %23
%29 = load i8, i8* %8
%30 = load i8*, i8** %7
%31 = getelementptr inbounds i8, i8* %30, i32 1
store i8* %31, i8** %7
store i8 %29, i8* %30
br label %32
32: ; preds = %28, %23
br label %33
33: ; preds = %32
%34 = load i32, i32* %9
%35 = add nsw i32 %34, 1
store i32 %35, i32* %9
br label %18
36: ; preds = %18
%37 = load i8*, i8** %7
%38 = load i8*, i8** %6
%39 = ptrtoint i8* %37 to i64
%40 = ptrtoint i8* %38 to i64
%41 = sub i64 %39, %40
%42 = add nsw i64 %41, 1
store i64 %42, i64* %10
%43 = load i8*, i8** %6
%44 = load i64, i64* %10
%45 = add nsw i64 %44, 1
%46 = call i8* @realloc(i8* %43, i64 %45)
store i8* %46, i8** %6
%47 = load i8*, i8** %6
%48 = load i64, i64* %10
%49 = getelementptr inbounds i8, i8* %47, i64 %48
store i8 0, i8* %49
%50 = load i8*, i8** %6
store i8* %50, i8** %3
br label %51
51: ; preds = %36, %16
%52 = load i8*, i8** %3
ret i8* %52
}

LLVM IR (-O2):
define noalias i8* @strip_source(i32* nocapture %0, i64 %1) {
%3 = tail call i8* @calloc(i64 %1, i32 1)
%4 = icmp slt i64 %1, 1
br i1 %4, label %24, label %13
5: ; preds = %20
%6 = ptrtoint i8* %21 to i64
%7 = ptrtoint i8* %3 to i64
%8 = sub i64 %6, %7
%9 = add nsw i64 %8, 1
%10 = add nsw i64 %8, 2
%11 = tail call i8* @realloc(i8* %3, i64 %10)
%12 = getelementptr inbounds i8, i8* %11, i64 %9
store i8 0, i8* %12
br label %24
13: ; preds = %2, %20
%14 = phi i64 [ %22, %20 ], [ 0, %2 ]
%15 = phi i8* [ %21, %20 ], [ %3, %2 ]
%16 = tail call signext i8 @getc(i32* %0)
%17 = sext i8 %16 to i32
switch i32 %17, label %20 [
i32 62, label %18
i32 60, label %18
i32 43, label %18
i32 45, label %18
i32 46, label %18
i32 44, label %18
i32 91, label %18
i32 93, label %18
]
18: ; preds = %13, %13, %13, %13, %13, %13, %13, %13
%19 = getelementptr inbounds i8, i8* %15, i64 1
store i8 %16, i8* %15
br label %20
20: ; preds = %13, %18
%21 = phi i8* [ %15, %13 ], [ %19, %18 ]
%22 = add nuw nsw i64 %14, 1
%23 = icmp eq i64 %22, %1
br i1 %23, label %5, label %13
24: ; preds = %2, %5
%25 = phi i8* [ %11, %5 ], [ null, %2 ]
ret i8* %25
}