#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 string_character_position(char *, char);
int /*<<< orphan*/ string_strcpy(char *, char *, int /*<<< orphan*/);
char *string_trim_character(char *data, char character) {
  int position;
  int offset;
  while (1) {
    if (!(position = string_character_position(data, character))) {
      return data;
    }
    offset = position - 1;
    string_strcpy(data + offset, data + position, 0);
  }
}


x86 assembly (clang, -O0):
<string_trim_character>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %sil,%al
mov    %rdi,-0x8(%rbp)
mov    %al,-0x9(%rbp)
mov    -0x8(%rbp),%rdi
movsbl -0x9(%rbp),%esi
call   1040 <string_character_position@plt>
mov    %eax,-0x10(%rbp)
cmp    $0x0,%eax
jne    1155 <string_trim_character+0x35>
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret
mov    -0x10(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
movslq -0x14(%rbp),%rax
add    %rax,%rdi
mov    -0x8(%rbp),%rsi
movslq -0x10(%rbp),%rax
add    %rax,%rsi
xor    %edx,%edx
call   1030 <string_strcpy@plt>
jmp    1132 <string_trim_character+0x12>

x86 assembly (clang, -O2):
<string_trim_character>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %rdi,%rbx
call   1040 <string_character_position@plt>
test   %eax,%eax
je     1163 <string_trim_character+0x43>
movsbl %bpl,%ebp
cs nopw 0x0(%rax,%rax,1)
nop
movslq %eax,%rsi
lea    (%rbx,%rsi,1),%rdi
add    $0xffffffffffffffff,%rdi
add    %rbx,%rsi
xor    %edx,%edx
call   1030 <string_strcpy@plt>
mov    %rbx,%rdi
mov    %ebp,%esi
call   1040 <string_character_position@plt>
test   %eax,%eax
jne    1140 <string_trim_character+0x20>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i8* @string_trim_character(i8* %0, i8 signext %1) {
%3 = alloca i8*
%4 = alloca i8
%5 = alloca i32
%6 = alloca i32
store i8* %0, i8** %3
store i8 %1, i8* %4
br label %7
7: ; preds = %2, %14
%8 = load i8*, i8** %3
%9 = load i8, i8* %4
%10 = call i32 @string_character_position(i8* %8, i8 signext %9)
store i32 %10, i32* %5
%11 = icmp ne i32 %10, 0
br i1 %11, label %14, label %12
12: ; preds = %7
%13 = load i8*, i8** %3
ret i8* %13
14: ; preds = %7
%15 = load i32, i32* %5
%16 = sub nsw i32 %15, 1
store i32 %16, i32* %6
%17 = load i8*, i8** %3
%18 = load i32, i32* %6
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i8, i8* %17, i64 %19
%21 = load i8*, i8** %3
%22 = load i32, i32* %5
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8, i8* %21, i64 %23
%25 = call i32 @string_strcpy(i8* %20, i8* %24, i32 0)
br label %7
}

LLVM IR (-O2):
define i8* @string_trim_character(i8* returned %0, i8 signext %1) {
%3 = tail call i32 @string_character_position(i8* %0, i8 signext %1)
%4 = icmp eq i32 %3, 0
br i1 %4, label %5, label %6
5: ; preds = %6, %2
ret i8* %0
6: ; preds = %2, %6
%7 = phi i32 [ %14, %6 ], [ %3, %2 ]
%8 = add nsw i32 %7, -1
%9 = sext i32 %8 to i64
%10 = getelementptr inbounds i8, i8* %0, i64 %9
%11 = sext i32 %7 to i64
%12 = getelementptr inbounds i8, i8* %0, i64 %11
%13 = tail call i32 @string_strcpy(i8* %10, i8* %12, i32 0)
%14 = tail call i32 @string_character_position(i8* %0, i8 signext %1)
%15 = icmp eq i32 %14, 0
br i1 %15, label %5, label %6
}