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

/* Variables and functions */
size_t strlen(int /*<<< orphan*/ *);
size_t str_backspace(char *str, char c) {
  size_t i = strlen((uint8_t *)str);
  i--;
  while (i) {
    i--;
    if (str[i] == c) {
      str[i + 1] = 0;
      return 1;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<str_backspace>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %sil,%al
mov    %rdi,-0x10(%rbp)
mov    %al,-0x11(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1189 <str_backspace+0x79>
mov    -0x20(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
movsbl -0x11(%rbp),%ecx
cmp    %ecx,%eax
jne    1184 <str_backspace+0x74>
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%rcx
movb   $0x0,0x1(%rax,%rcx,1)
movq   $0x1,-0x8(%rbp)
jmp    1191 <str_backspace+0x81>
jmp    113b <str_backspace+0x2b>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<str_backspace>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %rdi,%rbx
call   1030 <strlen@plt>
mov    %rax,%rcx
xor    %eax,%eax
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
cmp    $0x1,%rcx
je     114d <str_backspace+0x3d>
lea    -0x1(%rcx),%rdx
cmp    %bpl,-0x2(%rbx,%rcx,1)
mov    %rdx,%rcx
jne    1130 <str_backspace+0x20>
movb   $0x0,(%rbx,%rdx,1)
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

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

LLVM IR (-O2):
define i64 @str_backspace(i8* nocapture %0, i8 signext %1) {
%3 = bitcast i8* %0 to i32*
%4 = tail call i64 @strlen(i32* dereferenceable(1) %3)
%5 = add i64 %4, -1
br label %6
6: ; preds = %9, %2
%7 = phi i64 [ %5, %2 ], [ %10, %9 ]
%8 = icmp eq i64 %7, 0
br i1 %8, label %16, label %9
9: ; preds = %6
%10 = add i64 %7, -1
%11 = getelementptr inbounds i8, i8* %0, i64 %10
%12 = load i8, i8* %11
%13 = icmp eq i8 %12, %1
br i1 %13, label %14, label %6
14: ; preds = %9
%15 = getelementptr inbounds i8, i8* %0, i64 %7
store i8 0, i8* %15
br label %16
16: ; preds = %6, %14
%17 = phi i64 [ 1, %14 ], [ 0, %6 ]
ret i64 %17
}