#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*/ memmove(char *, char *, int);
int /*<<< orphan*/ *strchr(char *, char);
int strlen(char *);
void remove_dup(char *str) {
  int length = strlen(str);
  if (length < 2) {
    return;
  }
  for (int i = length - 1; i > 0; i--) {
    if (strchr(str + i, str[i - 1]) != NULL) {
      memmove(str + i - 1, str + i, strlen(str + 1) + 1);
    }
  }
}


x86 assembly (clang, -O0):
<remove_dup>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x2,-0xc(%rbp)
jge    1157 <remove_dup+0x27>
jmp    11e9 <remove_dup+0xb9>
mov    -0xc(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jle    11e9 <remove_dup+0xb9>
mov    -0x8(%rbp),%rdi
movslq -0x10(%rbp),%rax
add    %rax,%rdi
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%esi
call   1040 <strchr@plt>
cmp    $0x0,%rax
je     11d6 <remove_dup+0xa6>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
add    %rcx,%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
add    $0x1,%rdi
call   1030 <strlen@plt>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    %eax,%edx
add    $0x1,%edx
call   1050 <memmove@plt>
jmp    11db <remove_dup+0xab>
mov    -0x10(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x10(%rbp)
jmp    1160 <remove_dup+0x30>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<remove_dup>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r15
call   1030 <strlen@plt>
cmp    $0x2,%eax
jge    1157 <remove_dup+0x27>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0x1(%r15),%r14
mov    %eax,%ebx
mov    $0xfffffffe,%ebp
add    %rbx,%rbp
add    $0xffffffffffffffff,%rbx
jmp    1185 <remove_dup+0x55>
nopl   0x0(%rax,%rax,1)
add    $0xffffffffffffffff,%rbp
lea    -0x1(%rbx),%rax
add    $0x1,%rbx
cmp    $0x2,%rbx
mov    %rax,%rbx
jbe    1148 <remove_dup+0x18>
mov    %ebx,%r13d
add    %r15,%r13
mov    %ebp,%eax
movsbl (%r15,%rax,1),%esi
mov    %r13,%rdi
call   1040 <strchr@plt>
test   %rax,%rax
je     1170 <remove_dup+0x40>
lea    -0x1(%r13),%r12
mov    %r14,%rdi
call   1030 <strlen@plt>
lea    0x1(%rax),%edx
mov    %r12,%rdi
mov    %r13,%rsi
call   1050 <memmove@plt>
jmp    1170 <remove_dup+0x40>

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

LLVM IR (-O2):
define void @remove_dup(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = icmp slt i32 %2, 2
br i1 %3, label %25, label %4
4: ; preds = %1
%5 = getelementptr inbounds i8, i8* %0, i64 1
%6 = zext i32 %2 to i64
br label %7
7: ; preds = %4, %23
%8 = phi i64 [ %6, %4 ], [ %9, %23 ]
%9 = add nsw i64 %8, -1
%10 = and i64 %9, 4294967295
%11 = getelementptr inbounds i8, i8* %0, i64 %10
%12 = add nuw i64 %8, 4294967294
%13 = and i64 %12, 4294967295
%14 = getelementptr inbounds i8, i8* %0, i64 %13
%15 = load i8, i8* %14
%16 = tail call i32* @strchr(i8* %11, i8 signext %15)
%17 = icmp eq i32* %16, null
br i1 %17, label %23, label %18
18: ; preds = %7
%19 = getelementptr inbounds i8, i8* %11, i64 -1
%20 = tail call i32 @strlen(i8* %5)
%21 = add nsw i32 %20, 1
%22 = tail call i32 @memmove(i8* %19, i8* %11, i32 %21)
br label %23
23: ; preds = %7, %18
%24 = icmp ugt i64 %8, 2
br i1 %24, label %7, label %25
25: ; preds = %23, %1
ret void
}