#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 */
unsigned int strlen(char *);
char *remove_character(char *string, const char remove) {
  char *s = string;
  char *t;
  unsigned int count = 0;
  unsigned int length = strlen(string);
  while ((length--) > 1) {
    if (*s == remove) {
      count++;
      t = s;
      while (*(t + 1)) {
        *t = *(t + 1);
        t++;
      }
    }
    s++;
  }
  while (count--) {
    *s-- = 0;
  }
  return string;
}


x86 assembly (clang, -O0):
<remove_character>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %sil,%al
mov    %rdi,-0x8(%rbp)
mov    %al,-0x9(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x28(%rbp)
cmp    $0x1,%eax
jbe    11b7 <remove_character+0xa7>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
movsbl -0x9(%rbp),%ecx
cmp    %ecx,%eax
jne    11a6 <remove_character+0x96>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmpb   $0x0,0x1(%rax)
je     11a1 <remove_character+0x91>
mov    -0x20(%rbp),%rax
mov    0x1(%rax),%cl
mov    -0x20(%rbp),%rax
mov    %cl,(%rax)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1175 <remove_character+0x65>
jmp    11a6 <remove_character+0x96>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    113d <remove_character+0x2d>
jmp    11bc <remove_character+0xac>
mov    -0x24(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x24(%rbp)
cmp    $0x0,%eax
je     11e7 <remove_character+0xd7>
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x18(%rbp)
movb   $0x0,(%rax)
jmp    11bc <remove_character+0xac>
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<remove_character>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%ebp
mov    %rdi,%r14
call   1030 <strlen@plt>
cmp    $0x2,%eax
jb     1193 <remove_character+0x73>
lea    0x2(%r14),%rdx
xor    %ecx,%ecx
mov    %r14,%rdi
jmp    114d <remove_character+0x2d>
xchg   %ax,%ax
add    $0x1,%rdi
add    $0x1,%rdx
cmp    $0x1,%eax
jbe    1180 <remove_character+0x60>
add    $0xffffffff,%eax
cmp    %bpl,(%rdi)
jne    1140 <remove_character+0x20>
add    $0x1,%ecx
mov    0x1(%rdi),%bl
test   %bl,%bl
je     1140 <remove_character+0x20>
mov    %rdx,%rsi
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %bl,-0x2(%rsi)
movzbl (%rsi),%ebx
add    $0x1,%rsi
test   %bl,%bl
jne    1170 <remove_character+0x50>
jmp    1140 <remove_character+0x20>
test   %ecx,%ecx
je     1193 <remove_character+0x73>
lea    -0x1(%rcx),%eax
sub    %rax,%rdi
mov    %ecx,%edx
xor    %esi,%esi
call   1040 <memset@plt>
mov    %r14,%rax
pop    %rbx
pop    %r14
pop    %rbp
ret

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

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