#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 */
int /*<<< orphan*/ free(char *);
char *malloc(int);
scalar_t__ prefix(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
char *filter_substr(char *string, char *substr) {
  char *p_copy;
  p_copy = malloc(strlen(string) + 1);
  char *p = p_copy;
  while (*string != ('\0')) {
    if (prefix(string, substr)) {
      int c = 0;
      while (c < strlen(substr)) {
        c++;
        string++;
      }
    } else {
      *p = *string;
      p++;
      string++;
    }
  }
  *p = ('\0');
  p = malloc(strlen(p_copy) + 1);
  strcpy(p, p_copy);
  free(p_copy);
  return p;
}


x86 assembly (clang, -O0):
<filter_substr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%edi
add    $0x1,%edi
call   1060 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1211 <filter_substr+0xc1>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1070 <prefix@plt>
cmp    $0x0,%rax
je     11e8 <filter_substr+0x98>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%eax
cmp    %ecx,%eax
jge    11e3 <filter_substr+0x93>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    11ad <filter_substr+0x5d>
jmp    120c <filter_substr+0xbc>
mov    -0x8(%rbp),%rax
mov    (%rax),%cl
mov    -0x20(%rbp),%rax
mov    %cl,(%rax)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    117f <filter_substr+0x2f>
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%edi
add    $0x1,%edi
call   1060 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<filter_substr>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rsi,%r13
mov    %rdi,%r15
call   1050 <strlen@plt>
lea    0x1(%rax),%edi
call   1060 <malloc@plt>
mov    %rax,%r14
cmpb   $0x0,(%r15)
mov    %rax,%r12
je     11d5 <filter_substr+0x85>
mov    %r14,%r12
jmp    1195 <filter_substr+0x45>
nopl   (%rax)
mov    (%r15),%al
mov    %al,(%r12)
add    $0x1,%r12
add    $0x1,%r15
cmpb   $0x0,(%r15)
je     11d5 <filter_substr+0x85>
mov    %r15,%rdi
mov    %r13,%rsi
call   1070 <prefix@plt>
test   %rax,%rax
je     1180 <filter_substr+0x30>
mov    %r13,%rdi
call   1050 <strlen@plt>
test   %eax,%eax
jle    118f <filter_substr+0x3f>
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r13,%rdi
call   1050 <strlen@plt>
add    $0x1,%rbx
cmp    %eax,%ebx
jl     11c0 <filter_substr+0x70>
add    %rbx,%r15
jmp    118f <filter_substr+0x3f>
movb   $0x0,(%r12)
mov    %r14,%rdi
call   1050 <strlen@plt>
lea    0x1(%rax),%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r14,%rsi
call   1040 <strcpy@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    %rbx,%rax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8* @filter_substr(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
%8 = load i8*, i8** %3
%9 = call i32 @strlen(i8* %8)
%10 = add nsw i32 %9, 1
%11 = call i8* @malloc(i32 %10)
store i8* %11, i8** %5
%12 = load i8*, i8** %5
store i8* %12, i8** %6
br label %13
13: ; preds = %43, %2
%14 = load i8*, i8** %3
%15 = load i8, i8* %14
%16 = sext i8 %15 to i32
%17 = icmp ne i32 %16, 0
br i1 %17, label %18, label %44
18: ; preds = %13
%19 = load i8*, i8** %3
%20 = load i8*, i8** %4
%21 = call i64 @prefix(i8* %19, i8* %20)
%22 = icmp ne i64 %21, 0
br i1 %22, label %23, label %35
23: ; preds = %18
store i32 0, i32* %7
br label %24
24: ; preds = %29, %23
%25 = load i32, i32* %7
%26 = load i8*, i8** %4
%27 = call i32 @strlen(i8* %26)
%28 = icmp slt i32 %25, %27
br i1 %28, label %29, label %34
29: ; preds = %24
%30 = load i32, i32* %7
%31 = add nsw i32 %30, 1
store i32 %31, i32* %7
%32 = load i8*, i8** %3
%33 = getelementptr inbounds i8, i8* %32, i32 1
store i8* %33, i8** %3
br label %24
34: ; preds = %24
br label %43
35: ; preds = %18
%36 = load i8*, i8** %3
%37 = load i8, i8* %36
%38 = load i8*, i8** %6
store i8 %37, i8* %38
%39 = load i8*, i8** %6
%40 = getelementptr inbounds i8, i8* %39, i32 1
store i8* %40, i8** %6
%41 = load i8*, i8** %3
%42 = getelementptr inbounds i8, i8* %41, i32 1
store i8* %42, i8** %3
br label %43
43: ; preds = %35, %34
br label %13
44: ; preds = %13
%45 = load i8*, i8** %6
store i8 0, i8* %45
%46 = load i8*, i8** %5
%47 = call i32 @strlen(i8* %46)
%48 = add nsw i32 %47, 1
%49 = call i8* @malloc(i32 %48)
store i8* %49, i8** %6
%50 = load i8*, i8** %6
%51 = load i8*, i8** %5
%52 = call i32 @strcpy(i8* %50, i8* %51)
%53 = load i8*, i8** %5
%54 = call i32 @free(i8* %53)
%55 = load i8*, i8** %6
ret i8* %55
}

LLVM IR (-O2):
define i8* @filter_substr(i8* %0, i8* %1) {
%3 = tail call i32 @strlen(i8* %0)
%4 = add nsw i32 %3, 1
%5 = tail call i8* @malloc(i32 %4)
%6 = load i8, i8* %0
%7 = icmp eq i8 %6, 0
br i1 %7, label %32, label %8
8: ; preds = %2, %27
%9 = phi i8* [ %29, %27 ], [ %5, %2 ]
%10 = phi i8* [ %28, %27 ], [ %0, %2 ]
%11 = tail call i64 @prefix(i8* %10, i8* %1)
%12 = icmp eq i64 %11, 0
br i1 %12, label %23, label %13
13: ; preds = %8
%14 = tail call i32 @strlen(i8* %1)
%15 = icmp sgt i32 %14, 0
br i1 %15, label %16, label %27
16: ; preds = %13, %16
%17 = phi i32 [ %19, %16 ], [ 0, %13 ]
%18 = phi i8* [ %20, %16 ], [ %10, %13 ]
%19 = add nuw nsw i32 %17, 1
%20 = getelementptr inbounds i8, i8* %18, i64 1
%21 = tail call i32 @strlen(i8* %1)
%22 = icmp slt i32 %19, %21
br i1 %22, label %16, label %27
23: ; preds = %8
%24 = load i8, i8* %10
store i8 %24, i8* %9
%25 = getelementptr inbounds i8, i8* %9, i64 1
%26 = getelementptr inbounds i8, i8* %10, i64 1
br label %27
27: ; preds = %16, %13, %23
%28 = phi i8* [ %26, %23 ], [ %10, %13 ], [ %20, %16 ]
%29 = phi i8* [ %25, %23 ], [ %9, %13 ], [ %9, %16 ]
%30 = load i8, i8* %28
%31 = icmp eq i8 %30, 0
br i1 %31, label %32, label %8
32: ; preds = %27, %2
%33 = phi i8* [ %5, %2 ], [ %29, %27 ]
store i8 0, i8* %33
%34 = tail call i32 @strlen(i8* %5)
%35 = add nsw i32 %34, 1
%36 = tail call i8* @malloc(i32 %35)
%37 = tail call i32 @strcpy(i8* %36, i8* %5)
%38 = tail call i32 @free(i8* %5)
ret i8* %36
}