#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);
int /*<<< orphan*/ strcpy(char *, char *);
char *filter_ch_ptr(char *string, char ch) {
  char *p_copy;
  p_copy = malloc(sizeof(*string) + 1);
  char *p = p_copy;
  while (*string != ('\0')) {
    if (*string != ch) {
      *p = *string;
      p++;
    }
    string++;
  }
  *p = ('\0');
  p = malloc(sizeof(*p_copy));
  strcpy(p, p_copy);
  free(p_copy);
  return p;
}


x86 assembly (clang, -O0):
<filter_ch_ptr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %sil,%al
mov    %rdi,-0x8(%rbp)
mov    %al,-0x9(%rbp)
mov    $0x2,%edi
call   1050 <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     11a4 <filter_ch_ptr+0x74>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
movsbl -0x9(%rbp),%ecx
cmp    %ecx,%eax
je     1193 <filter_ch_ptr+0x63>
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    1158 <filter_ch_ptr+0x28>
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
mov    $0x1,%edi
call   1050 <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    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<filter_ch_ptr>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%ebp
mov    %rdi,%rbx
mov    $0x2,%edi
call   1050 <malloc@plt>
mov    %rax,%r14
mov    (%rbx),%cl
test   %cl,%cl
je     1178 <filter_ch_ptr+0x48>
add    $0x1,%rbx
mov    %r14,%rax
jmp    116b <filter_ch_ptr+0x3b>
cs nopw 0x0(%rax,%rax,1)
nop
movzbl (%rbx),%ecx
add    $0x1,%rbx
test   %cl,%cl
je     1178 <filter_ch_ptr+0x48>
cmp    %bpl,%cl
je     1160 <filter_ch_ptr+0x30>
mov    %cl,(%rax)
add    $0x1,%rax
jmp    1160 <filter_ch_ptr+0x30>
movb   $0x0,(%rax)
mov    $0x1,%edi
call   1050 <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    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i8* @filter_ch_ptr(i8* %0, i8 signext %1) {
%3 = alloca i8*
%4 = alloca i8
%5 = alloca i8*
%6 = alloca i8*
store i8* %0, i8** %3
store i8 %1, i8* %4
%7 = call i8* @malloc(i32 2)
store i8* %7, i8** %5
%8 = load i8*, i8** %5
store i8* %8, i8** %6
br label %9
9: ; preds = %27, %2
%10 = load i8*, i8** %3
%11 = load i8, i8* %10
%12 = sext i8 %11 to i32
%13 = icmp ne i32 %12, 0
br i1 %13, label %14, label %30
14: ; preds = %9
%15 = load i8*, i8** %3
%16 = load i8, i8* %15
%17 = sext i8 %16 to i32
%18 = load i8, i8* %4
%19 = sext i8 %18 to i32
%20 = icmp ne i32 %17, %19
br i1 %20, label %21, label %27
21: ; preds = %14
%22 = load i8*, i8** %3
%23 = load i8, i8* %22
%24 = load i8*, i8** %6
store i8 %23, i8* %24
%25 = load i8*, i8** %6
%26 = getelementptr inbounds i8, i8* %25, i32 1
store i8* %26, i8** %6
br label %27
27: ; preds = %21, %14
%28 = load i8*, i8** %3
%29 = getelementptr inbounds i8, i8* %28, i32 1
store i8* %29, i8** %3
br label %9
30: ; preds = %9
%31 = load i8*, i8** %6
store i8 0, i8* %31
%32 = call i8* @malloc(i32 1)
store i8* %32, i8** %6
%33 = load i8*, i8** %6
%34 = load i8*, i8** %5
%35 = call i32 @strcpy(i8* %33, i8* %34)
%36 = load i8*, i8** %5
%37 = call i32 @free(i8* %36)
%38 = load i8*, i8** %6
ret i8* %38
}

LLVM IR (-O2):
define i8* @filter_ch_ptr(i8* nocapture %0, i8 signext %1) {
%3 = tail call dereferenceable_or_null(2) i8* @malloc(i32 2)
%4 = load i8, i8* %0
%5 = icmp eq i8 %4, 0
br i1 %5, label %18, label %6
6: ; preds = %2, %13
%7 = phi i8 [ %16, %13 ], [ %4, %2 ]
%8 = phi i8* [ %14, %13 ], [ %3, %2 ]
%9 = phi i8* [ %15, %13 ], [ %0, %2 ]
%10 = icmp eq i8 %7, %1
br i1 %10, label %13, label %11
11: ; preds = %6
store i8 %7, i8* %8
%12 = getelementptr inbounds i8, i8* %8, i64 1
br label %13
13: ; preds = %11, %6
%14 = phi i8* [ %12, %11 ], [ %8, %6 ]
%15 = getelementptr inbounds i8, i8* %9, i64 1
%16 = load i8, i8* %15
%17 = icmp eq i8 %16, 0
br i1 %17, label %18, label %6
18: ; preds = %13, %2
%19 = phi i8* [ %3, %2 ], [ %14, %13 ]
store i8 0, i8* %19
%20 = tail call dereferenceable_or_null(1) i8* @malloc(i32 1)
%21 = tail call i32 @strcpy(i8* %20, i8* %3)
%22 = tail call i32 @free(i8* %3)
ret i8* %20
}